source: Sophya/trunk/SophyaPI/PIext/pistdimgapp.cc@ 2490

Last change on this file since 2490 was 2490, checked in by ansari, 22 years ago

Suite modifs pour piapp multi-thread - introduction de lock lors de la mise a jour de la fenetre ObjMgr par NamedObjMgr - Reza 1 Jan 2004

  • Property svn:executable set to *
File size: 56.9 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5
6#include <typeinfo>
7
8#include <string>
9#include <vector>
10
11#include "strutil.h"
12#include "timing.h"
13#include "perrors.h"
14#include "ctimer.h"
15
16#include "psighand.h"
17
18#include "cimage.h" // pour pouvoir faire extract
19
20#include "pistdimgapp.h"
21#include "servnobjm.h"
22// #include "pihisto2d.h"
23#include "psfile.h"
24#include "piimgtools.h"
25#include "pidrwtools.h"
26#include "piaxestools.h"
27
28#include "pistzwin.h"
29
30#include "piinit.h"
31#include "piversion.h"
32#include "piaversion.h"
33
34
35static char ImgDir[256];
36static char WorkDir[256];
37// Initialiseur
38static PIAppInitiator * glst_piai = NULL;
39
40// Pour la creation de fenetre info (about piapp)
41static void createInfoWindow(PIStdImgApp* app);
42static void deleteInfoWindow();
43static void showInfoWindow(PIStdImgApp* app);
44static void hideInfoWindow(PIStdImgApp* app);
45
46// Pour compter le nombre de display same a la suite
47static int nb_disp_same = 0;
48
49/* ........................................................... */
50/* Classe SIA_RU__Periodic : mise a jour periodique de */
51/* la fenetre Stat/Ressource info */
52/* + execution de commande soumis de l'exterieur */
53/* ........................................................... */
54
55class SIA_RU__Periodic : public PIPeriodic
56{
57public:
58 SIA_RU__Periodic(PIStdImgApp* app);
59 virtual ~SIA_RU__Periodic();
60 virtual void DoPeriodic();
61private:
62 PIStdImgApp* _app;
63};
64
65SIA_RU__Periodic::SIA_RU__Periodic(PIStdImgApp* app)
66 : PIPeriodX(1)
67{
68 _app = app;
69}
70
71SIA_RU__Periodic::~SIA_RU__Periodic()
72{
73}
74
75void SIA_RU__Periodic::DoPeriodic()
76{
77 if (_app) {
78 // RZDEL: Normalement, il ne devrait plus y avoir besoin de cette
79 // methode avec le thread separe de l'interpreteur - Reza 27/12/2003
80 // _app->ExecuteExtCommand();
81 _app->UpdateStatResourceInfo();
82 }
83}
84
85/* ............................................................. */
86
87
88/* ........................................................... */
89/* Classe PIStdImgApp */
90/* ........................................................... */
91
92/* --Methode-- */
93PIStdImgApp::PIStdImgApp(int narg, char* arg[])
94 : PIApplication(420, 320, narg, arg) , resusg(ResourceUsage::RU_All)
95{
96
97// Les menus
98m[0] = new PIMenu(Menubar(),"Fichier");
99m[0]->AppendItem("About piapp", 10150);
100m[0]->AppendItem("Open-Fits", 10120);
101m[0]->AppendItem("Open-PPF", 10130);
102#ifndef SANS_EVOLPLANCK
103m[0]->AppendItem("Open-ASCII", 10140);
104#endif
105// m[0]->AppendItem("Options", 10101);
106m[0]->AppendItem("Help", 10100);
107m[0]->AppendSeparator();
108m[0]->AppendItem("Exit", 10105);
109
110m[1] = new PIMenu(Menubar(),"Objets");
111m[1]->AppendItem("ObjectManager", 10201);
112m[1]->AppendItem("OpenOutPPF", 10220);
113m[1]->AppendItem("CloseOutPPF", 10230);
114m[1]->AppendItem("Delete CurWdg", 10270);
115
116m[2] = new PIMenu(Menubar(),"Tools");
117m[2]->AppendItem("Show ImageTools", 10301);
118m[2]->AppendItem("Show DrawerTools", 10302);
119m[2]->AppendItem("Show AxesTools", 10303);
120m[2]->AppendItem("CxxExecutorWindow", 10304);
121m[2]->AppendItem("Ext.Pave", 10311);
122m[2]->SetSensitivityMsg(10311, false);
123m[2]->AppendItem("Ext.Pave+Org", 10312);
124m[2]->SetSensitivityMsg(10312, false);
125m[2]->AppendItem("Cuts X,Y", 10313);
126m[2]->SetSensitivityMsg(10313, false);
127mc = new PIMenu(m[2], "StackTools");
128mc->AppendItem("DispNext", 10320);
129mc->AppendItem("Blink 0.5s", 10321);
130mc->AppendItem("Blink 1s", 10322);
131mc->AppendItem("Blink 2s", 10324);
132mc->AppendItem("Stop Blink", 10329);
133mc->AppendItem("RemoveCurrent", 10330);
134m[2]->AppendPDMenu(mc);
135m[2]->SetSensitivity("StackTools", false);
136
137m[3] = new PIMenu(Menubar(),"Window");
138m[3]->AppendItem("StackWindow", 10400);
139m[3]->AppendItem("Window", 10411);
140m[3]->AppendItem("Window 2x1", 10421);
141// m[3]->AppendItem("Window 1x2", 10412);
142m[3]->AppendItem("Window 2x2", 10422);
143// m[3]->AppendItem("Window 3x1", 10431);
144m[3]->AppendItem("Window 3x3", 10433);
145m[3]->AppendItem("Cur->LastWdg", 10441);
146m[3]->AppendItem("Close CurWin", 10460);
147m[3]->AppendCheckItem("StatZoomWin", 10470);
148m[3]->SetStateMsg(10470, true);
149
150m[4] = new PIMenu(Menubar(),"PostScript");
151m[4]->AppendItem("OpenPS", 10501);
152m[4]->AppendItem("ClosePS", 10505);
153m[4]->AppendItem("Window->PS", 10511);
154m[4]->AppendItem("Image->PS", 10515);
155m[4]->AppendItem("Window->EPS", 10512);
156m[4]->AppendItem("Image->EPS", 10516);
157m[4]->SetSensitivityMsg(10515, false);
158m[4]->SetSensitivityMsg(10516, false);
159
160m[5] = new PIMenu(Menubar(),"Special");
161m[5]->AppendItem("CloseAll", 10601);
162m[5]->AppendCheckItem("Red.Out/Err", 10602);
163m[5]->AppendCheckItem("Catch SigFPE", 10603);
164m[5]->AppendCheckItem("Catch SigSEGV", 10604);
165m[5]->AppendCheckItem("ObjMgr Verb", 10605);
166m[5]->AppendItem("CxxExecOption", 10606);
167
168m[6] = new PIMenu(Menubar(),"Modules");
169
170AppendMenu(m[0]);
171AppendMenu(m[1]);
172AppendMenu(m[2]);
173AppendMenu(m[3]);
174AppendMenu(m[4]);
175AppendMenu(m[5]);
176// AppendMenu(m[6]); Menu Modules vide pour le moment
177
178int scsx, scsy;
179ScreenSize(scsx, scsy);
180if (scsy <= 600) mFgScSz = 0;
181else if (scsy <= 800) mFgScSz = 1;
182else if (scsy <= 1024) mFgScSz = 2;
183else mFgScSz = 3;
184int msx = 420+mFgScSz*60;
185int msy = 320+mFgScSz*40;
186MainWin()->SetSize(msx, msy);
187
188//------------------------------------------------------
189// On cree un container intermediaire permettant de gerer
190// le widget zoom, colormap, stats, ...
191
192int bss = 105+mFgScSz*15;
193
194int statc_szy = bss+10+14+mFgScSz*2+5;
195statcont = new PIContainer(MainWin(), "ZGCSCont", msx, statc_szy, 0, 0);
196statcont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
197
198gimv = new PIPixmap(statcont, "GloV", bss, bss, 5, 5);
199gimv->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_free, PIBK_free);
200zoom = new PIPixmap(statcont, "Zoom", bss, bss, bss+10, 5);
201zoom->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_free, PIBK_free);
202cmapv = new PICMapView(statcont, "CMapView", msx-10, 14+mFgScSz*2, 5, bss+10);
203cmapv->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
204
205// Widget pour affichage des stats / ressources
206lab_mem = new PILabel(statcont, "memlab", msx-2*(bss+20), 20, 2*bss+20, 5);
207lab_mem->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
208lab_mem->SetLabel("MemoryUsage");
209lab_mem->SetForegroundColor(PI_Red);
210lab_mem->SetBorderWidth(1);
211therm_mem = new PIThermometer(statcont, "memtherm", msx-2*(bss+20), 15, 2*bss+20, 30);
212therm_mem->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
213therm_mem->SetThreshold(0.5, 0.75);
214
215lab_cpu = new PILabel(statcont, "cpulab", msx-2*(bss+20), 20, 2*bss+20, 50);
216lab_cpu->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
217lab_cpu->SetLabel("CPUUsage");
218lab_cpu->SetForegroundColor(PI_Black);
219lab_cpu->SetBorderWidth(1);
220therm_cpu = new PIThermometer(statcont, "cputherm", msx-2*(bss+20), 15, 2*bss+20, 75);
221therm_cpu->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
222therm_cpu->SetThreshold(0.75, 0.90);
223lab_thrcmd = new PILabel(statcont, "thrcmdlab", msx-2*(bss+20), 20, 2*bss+20, 95);
224lab_thrcmd->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
225lab_thrcmd->SetLabel("CommandThread");
226lab_thrcmd->SetForegroundColor(PI_Green);
227lab_thrcmd->SetBorderWidth(1);
228
229fg_exc_cmd = false;
230mCmd = NULL; // Avant d'appeler UpdateStatResource() si PIACmd non cree
231UpdateStatResourceInfo();
232resupd_periodic = new SIA_RU__Periodic(this);
233//resupd_periodic->SetIntervalms(500);
234resupd_periodic->Start();
235
236statcont->Show();
237// StatZoomWindowSetVisible(true);
238//------------------------------------------------------
239
240//int cpy = bss+10+14+mFgScSz*2+5;
241int cpy = statc_szy;
242
243// Creation d'une console avec gestion des commandes
244consolecont = new PIContainer(MainWin(), "ConsoleCont", msx, msy-cpy, 0, cpy );
245consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
246mCons = new PIConsole(consolecont, "Console", 30200, 512, 132, msx, msy-cpy, 0, 0 );
247mCons->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
248mCons->AcceptCmd(true, 50);
249consolecont->Show();
250redirecout = false;
251// RedirectStdOutErr(true); pas par defaut
252
253mObjMgr = new NamedObjMgr(true);
254mCmd = new PIACmd(this);
255
256// Pas trop de message de la part de NamedObjMgr
257m[5]->SetStateMsg(10605, false);
258mObjMgr->SetVerbose(false);
259
260char* varenv;
261ImgDir[0] = WorkDir[0] = '\0';
262if ( (varenv=getenv("PEIDA_IMAGES")) != NULL ) strncpy(ImgDir, varenv, 256);
263if ( (varenv=getenv("PEIDA_WORK")) != NULL ) strncpy(WorkDir, varenv, 256);
264
265pfc_fits = new PIFileChooser(this,"FITS-FileChooser", 10125);
266pfc_ppf = new PIFileChooser(this,"PPF-FileChooser", 10135);
267pfc_ascii = new PIFileChooser(this,"ASCII-FileChooser", 10145);
268pfc_ps = new PIFileChooser(this,"PS-FileChooser", 10525);
269
270mObjmgrw = new ObjMgrWind(this);
271mPpinmgrw = new PPInMgrWind(this);
272
273// Attention : A faire apres creation de ObjMgrWind !!!
274mObjMgr->SetImgApp(this);
275
276// Gestion des feneteres widgets et drawers
277mWId = mDId = mBWId = 0;
278mCurWin = NULL;
279mCurWdg = NULL;
280mLastWdg = NULL;
281mGrW = NULL;
282mStW = NULL;
283mGrIdx = mStIdx = -1;
284
285mFCMsg = 0;
286mFgCWImg = false;
287
288// Gestion fichiers PS
289num_eps = 0;
290name_ps = "";
291name_ps = "pia.ps";
292mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
293
294// Gestion OUT-PPF
295mPpfout = NULL;
296name_outppf = "";
297
298// Attributs graphiques courants
299mAxesFlags = kAxesDflt;
300SetInsetLimits(0.4, 0.6, 0.4, 0.6);
301mAddTitle = true;
302
303// Initialisation
304glst_piai = new PIAppInitiator(this);
305
306char buff[128];
307mCons->AddStr(" ............ starting piapp .............\n", PIVA_Blue );
308#ifdef SANS_EVOLPLANCK
309sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
310 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
311#else
312sprintf(buff, "Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
313 (double)PI_VERSIONNUMBER, glst_piai->Version());
314#endif
315mCons->AddStr(buff, PIVA_Blue );
316mCons->AddStr(" ..........................................\n", PIVA_Blue );
317// PrintPeidaVersion();
318
319pfc_fits->SetPath(ImgDir);
320pfc_ppf->SetPath(WorkDir);
321pfc_ps->SetPath(WorkDir);
322
323SetReady();
324fg_glsynlock = false;
325}
326
327/* --Methode-- */
328PIStdImgApp::~PIStdImgApp()
329{
330int i;
331
332// On inactive la fenetre principale
333// Sinon, ca peut provoquer un SEGV ds delete de console ?? - Reza 07/2000
334MainWin()->Hide();
335
336// Destrucion de tous les objets de NameObjMgr
337string patt = "/*/*";
338mObjMgr->DelObjects(patt, true);
339
340delete mc;
341for(i=0; i<7; i++)
342 if (m[i]) delete m[i];
343
344WindMList::iterator it;
345for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
346
347delete mObjMgr;
348delete mCmd;
349
350delete zoom;
351delete gimv;
352delete cmapv;
353
354delete lab_mem;
355delete therm_mem;
356delete lab_cpu;
357delete therm_cpu;
358delete lab_thrcmd;
359
360delete statcont;
361
362delete pfc_fits;
363delete pfc_ppf;
364delete pfc_ascii;
365delete pfc_ps;
366
367delete mCons;
368delete consolecont;
369
370delete mObjmgrw;
371delete mPpinmgrw;
372
373deleteInfoWindow();
374
375// Les fichiers
376if (mpsfile) delete mpsfile;
377if (mPpfout) delete mPpfout;
378
379if (resupd_periodic) delete resupd_periodic;
380
381if (glst_piai) delete glst_piai; glst_piai = NULL;
382
383}
384
385class RunAlarm : public Periodic {
386public:
387 RunAlarm(PIStdImgApp* app) :
388 Periodic(1)
389 { _app = app; SetIntervalms(1); }
390 ~RunAlarm() { }
391 virtual void DoPeriodic()
392 { _app->getMutex().broadcast(); }
393 PIStdImgApp* _app;
394};
395
396/* --Methode-- */
397void PIStdImgApp::Run()
398{
399XEvent evt;
400int szx, szy, szf;
401XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
402// Pour appeler FinishCreate() des objets dans la fenetre principale
403if (mStop) { // C'est la premiere fois
404 topcont->SetSize(topcont->XSize(), topcont->YSize());
405 MBCont()->FinishCreate();
406 }
407else mStop = true; // On rerentre apres un stop
408
409// Creation et demarrage de l'objet de reveil periodique
410// de la boucle d'evts
411RunAlarm * mru = new RunAlarm(this);
412//mru->Start();
413// Demarrage du thread de l'interpreteur
414CmdInterpreter()->start();
415
416// Soumission de la commande exterieur a executer
417if (fg_exc_cmd) {
418 fg_exc_cmd = false;
419}
420
421
422while (mStop) {
423 thr_glsyn.lock(); // <ZThread>
424 fg_glsynlock = true;
425 while (XtAppPending(*appctx) != 0) {
426 XtAppNextEvent(*appctx, &evt);
427 XtDispatchEvent(&evt);
428 }
429 fg_glsynlock = false;
430 thr_glsyn.unlock(); // <ZThread>
431 // thr_glsyn.wait();
432 usleep(1000);
433}
434
435delete mru;
436return;
437}
438
439/* --Methode-- */
440void PIStdImgApp::Process(PIMessage msg, PIMsgHandler* sender, void* data)
441{
442PIWdg *sndw;
443PIMessage tmsg, smm;
444
445tmsg = msg;
446msg = UserMsg(msg);
447smm = ModMsg(tmsg);
448
449//printf("SuperDebug: msg=%d Mod=%d State=%d\n", (int)msg, (int)smm, (int)GetState());
450if ((GetState()) && (msg != mFCMsg)) { PIBeep(); return; }
451
452// Messages active-window
453if (smm == PIMsg_Active)
454 {
455 sndw = dynamic_cast<PIWdg *>(sender);
456 switch(sndw->kind())
457 {
458 case PIWindow::ClassId :
459 mCurWin = dynamic_cast<PIWindow *>(sndw);
460 break;
461
462 case PIScDrawWdg::ClassId :
463 case PIDraw3DWdg::ClassId :
464 mCurWdg = dynamic_cast<PIBaseWdg *>(sender);
465// cerr << "*DBG11* ImgTools -> NonSensitive " << sndw->kind() << endl;
466 if (mFgCWImg) {
467// cerr << "*DBG* ImgTools -> NonSensitive " << endl;
468 m[2]->SetSensitivityMsg(10311, false);
469 m[2]->SetSensitivityMsg(10312, false);
470 m[2]->SetSensitivityMsg(10313, false);
471 m[4]->SetSensitivityMsg(10515, false);
472 m[4]->SetSensitivityMsg(10516, false);
473 mFgCWImg = false;
474 }
475 break;
476 case PIImage::ClassId :
477 mCurWdg = dynamic_cast<PIBaseWdg *>(sender);
478 if (!mFgCWImg) {
479// cerr << "*DBG* ImgTools -> Sensitive " << endl;
480 m[2]->SetSensitivityMsg(10311, true);
481 m[2]->SetSensitivityMsg(10312, true);
482 m[2]->SetSensitivityMsg(10313, true);
483 m[4]->SetSensitivityMsg(10515, true);
484 m[4]->SetSensitivityMsg(10516, true);
485 mFgCWImg = true;
486 }
487 break;
488 /*
489 default :
490 mCurWdg = NULL;
491 if (mFgCWImg) {
492 m[2]->SetSensitivityMsg(10311, false);
493 m[2]->SetSensitivityMsg(10312, false);
494 m[2]->SetSensitivityMsg(10313, false);
495 m[4]->SetSensitivityMsg(10515, false);
496 m[4]->SetSensitivityMsg(10516, false);
497 mFgCWImg = false;
498 }
499 break;
500 */
501 }
502 }
503// Message window-close
504else if (smm == PIMsg_Close)
505 {
506 sndw = (PIWdg *)sender;
507 if(sndw->kind() == PIWindow::ClassId)
508 {
509 mCurWin = (PIWindow *)sender;
510 if (mCurWin == mStW) m[2]->SetSensitivity("StackTools", false);
511 DeleteWindow(mCurWin);
512 }
513 else
514 printf("PIStdImgApp/Bug ? CloseMsd received from NonWindow (%d %d %lx) \n",
515 (int)tmsg, (int)sndw->kind(), (long)sender);
516 }
517
518// Traitement des messages des menus
519else if ( (msg >= 10100) && (msg < 10200) ) MBProcess1(msg, sender, data);
520else if ( (msg >= 10200) && (msg < 10300) ) MBProcess2(msg, sender, data);
521else if ( (msg >= 10300) && (msg < 10400) ) MBProcess3(msg, sender, data);
522else if ( (msg >= 10400) && (msg < 10500) ) MBProcess4(msg, sender, data);
523else if ( (msg >= 10500) && (msg < 10600) ) MBProcess5(msg, sender, data);
524else if ( (msg >= 10600) && (msg < 10700) ) MBProcess6(msg, sender, data);
525else if ( msg == 30200 ) { // Objet PIConsole
526 string s = mCons->GetCmdString();
527 // string s2 = "\nExecuting " + s + "\n";
528 mCons->AddStr("Cmd> ", PIVA_Blue, false);
529 // s2 = s + "\n";
530 mCons->AddStr(s.c_str(), PIVA_Blue|PIVA_Bold, false);
531 mCons->AddChar('\n', PIVA_Def, true);
532 SetBusy();
533#ifdef SANS_EVOLPLANCK
534 TRY {
535 mCmd->Interpret(s);
536 } CATCH(merr) {
537 fflush(stdout);
538 cout << endl;
539 cerr << endl;
540 string es = PeidaExc(merr);
541 cerr << "PIStdImgApp::Process()/ Cmd->Do() Exception :" << es << " (" << merr << ")" << endl ;
542 }
543#else
544 try {
545 // mCmd->Interpret(s);
546 CmdInterpreter()->AddInputLine(s);
547 }
548 catch ( PThrowable & exc ) {
549 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
550 << (string)typeid(exc).name() << " Msg= "
551 << exc.Msg() << endl;
552 cout << endl;
553 }
554 catch ( ... ) {
555 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ..."
556 << endl;
557 cout << endl;
558 }
559
560#endif
561 SetReady();
562 }
563
564else printf("PIStdImgApp::Process() BUG?? Msg %d (%d-%d) \n",
565 (int)tmsg,(int)msg,(int)smm);
566
567
568return;
569}
570
571/* --Methode-- */
572void PIStdImgApp::SetReady()
573{
574mCons->SetSensitive();
575gimv->SetSensitive();
576PIApplication::SetReady();
577}
578
579/* --Methode-- */
580void PIStdImgApp::SetBusy()
581{
582mCons->SetUnSensitive();
583gimv->SetUnSensitive();
584PIApplication::SetBusy();
585// Attention : Appel XSync specifique X11 - en attendant multi-thread
586XSync(PIXDisplay(), False);
587}
588
589/* --Methode-- */
590void PIStdImgApp::SetBlocked()
591{
592mCons->SetUnSensitive();
593gimv->SetUnSensitive();
594PIApplication::SetBlocked();
595// Attention : Appel XSync specifique X11 - en attendant multi-thread
596XSync(PIXDisplay(), False);
597}
598
599
600/* --Methode-- */
601int PIStdImgApp::DispImage(P2DArrayAdapter* nouv, string const & name, string const& sop, int oid)
602{
603PIImage* pii;
604PIWindow* win;
605int sx, sy, px, py, flag;
606
607if (nouv == NULL)
608 {
609 printf("PIStdImgApp::DispImage_Error Cannot Display NULL image \n");
610 return(-1);
611 }
612
613if ( (nouv->XSize() <= 0) || (nouv->YSize() <= 0))
614 {
615 printf("PIStdImgApp::DispImage_Error Pb Size Sz=%d*%d \n",
616 nouv->XSize(), nouv->YSize());
617 return(-1);
618 }
619
620// On decode les options graphiques
621vector<string> opts;
622DispWinEnum dwopt = ParseDisplayOption(sop, opts);
623
624// Pas de same ou inset pour DispImage
625if ((dwopt == Disp_Same) || (dwopt == Disp_Inset) ) dwopt = Disp_Next;
626
627// <ZThread> global PIApplication event loop synchronisation
628ZSync zs(thr_glsyn, 2);
629
630// Choix de la taille de fenetre
631#define MINPIIMGSIZE 100
632sx = (nouv->XSize() > MINPIIMGSIZE) ? nouv->XSize() : MINPIIMGSIZE;
633sy = (nouv->YSize() > MINPIIMGSIZE) ? nouv->XSize() : MINPIIMGSIZE;
634if (sx > 400+mFgScSz*100) sx = 400+mFgScSz*100;
635if (sy > 400+mFgScSz*100) sy = 400+mFgScSz*100;
636px = py = 0;
637win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
638pii = new PIImage(win, (char *)name.c_str(), sx, sy, px,py);
639pii->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
640pii->SetZoomWin(zoom, false);
641pii->SetGloVWin(gimv, false);
642pii->SetCMapWin(cmapv, false);
643pii->ShowCursor(true);
644pii->SetUserData(NULL, oid);
645
646
647// On recalcule la taille de la fenetre si Disp_Win
648if (dwopt == Disp_Win) {
649 int sx2 = (int)((float)nouv->XSize()*pii->GetZoomF());
650 int sy2 = (int)((float)nouv->YSize()*pii->GetZoomF());
651
652 if (sx2 > 400+mFgScSz*100) sx2 = 400+mFgScSz*100;
653 if (sy2 > 400+mFgScSz*100) sy2 = 400+mFgScSz*100;
654 if (sx2 < MINPIIMGSIZE) sx = MINPIIMGSIZE;
655 if (sy2 < MINPIIMGSIZE) sy = MINPIIMGSIZE;
656 if ((sx2 != sx) || (sy2 != sy)) win->SetSize(sx2, sy2);
657}
658
659pii->SetImage(nouv, true, false);
660
661// decode des options en chaine de caracteres
662if (mAxesAtt.size() > 0)
663 pii->DecodeOptionString(mAxesAtt, false); // Les options d'axe
664if (mDefaultAtt.size() > 0)
665 pii->DecodeOptionString(mDefaultAtt, false); // d'abord les options par defaut
666if (opts.size() > 0)
667 pii->DecodeOptionString(opts); // ensuite, les options specifies en argument
668
669// printf("!!DBG!! PIImage Pos= %d %d Size= %d %d \n", pii->XPos(), pii->YPos(), pii->XSize(), pii->YSize() );
670mCurWin = win;
671mCurWdg = pii;
672mLastWdg = pii;
673mBWId++;
674mBWList[mBWId] = pii;
675// pii->Refresh();
676pii->Apply();
677cmapv->Refresh();
678return(mBWId);
679}
680
681
682/* --Methode-- */
683int PIStdImgApp::DispScDrawer(PIDrawer* scd, string const & name, string const& sop,
684 string title, int oid)
685{
686if (scd == NULL)
687 {
688 printf("PIStdImgApp::DispScDrawer_Error Cannot Add NULL ScDrawer \n");
689 return(-1);
690 }
691
692// On decode les options graphiques
693vector<string> opts;
694DispWinEnum dwopt = ParseDisplayOption(sop, opts);
695if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
696
697// <ZThread> global PIApplication event loop synchronisation
698ZSync zs(thr_glsyn, 2);
699
700// Trace en superpoistion
701if ( (dwopt == Disp_Same) && (mLastWdg) ) {
702 // Les options
703 scd->DecodeOptionString(mDefaultAtt, false);
704 if (nb_disp_same > 0) {
705 vector<string> ostatpos;
706 int spo = nb_disp_same%4;
707 if (spo == 1) ostatpos.push_back("statposoff=-0.01,-0.26");
708 else if (spo == 2) ostatpos.push_back("statposoff=-0.36,-0.01");
709 else ostatpos.push_back("statposoff=-0.36,-0.26");
710 scd->DecodeOptionString(ostatpos, true);
711 }
712 scd->DecodeOptionString(opts, true);
713
714 if (mLastWdg->kind() == PIScDrawWdg::ClassId) ((PIScDrawWdg*)mLastWdg)->AddScDrawer(scd, true);
715 else mLastWdg->AddDrawer(scd, true, true, true);
716 scd->Refresh();
717 mDId++;
718 mDrwList[mDId] = scd;
719 return(-mDId);
720}
721// Trace en medaillon
722else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
723 PIGrCoord x1, x2, y1, y2;
724 x1 = mIXmin; x2 = mIXmax;
725 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
726 // Les options
727 scd->DecodeOptionString(mDefaultAtt, false);
728 scd->DecodeOptionString(opts, true);
729
730 scd->SetAxesFlags(mAxesFlags);
731 scd->UpdateLimits();
732 mLastWdg->AddDrawer(scd, x1, y1, x2, y2, true, false, true);
733 scd->Refresh();
734 mDId++;
735 mDrwList[mDId] = scd;
736 return(-mDId);
737}
738
739// Creation d'un nouveau PIScDrawWdg
740PIWindow* win;
741PIScDrawWdg* scw;
742int sx, sy, px, py, flag;
743sx = 200+mFgScSz*100;
744sy = 200+mFgScSz*100;
745win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
746
747scw = new PIScDrawWdg(win, (char *)name.c_str(), sx, sy, px, py);
748scw->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
749scw->SetUserData(NULL, oid);
750
751// Decodage des options :
752vector<string> scwatt;
753scw->SetAxesFlags(mAxesFlags);
754if ( mDefaultAtt.size() > 0) {
755 scwatt = mDefaultAtt;
756 scd->DecodeOptionString(scwatt, true);
757 scw->DecodeOptionString(scwatt, true);
758}
759if ( mAxesAtt.size() > 0) {
760 scwatt = mAxesAtt;
761 scw->DecodeOptionString(scwatt, true);
762}
763if (opts.size() > 0)
764 scd->DecodeOptionString(opts, true);
765if (opts.size() > 0)
766 scw->DecodeOptionString(opts, false);
767
768// Titre du plot
769if (mAddTitle) {
770 if (title.length() <= 0) title = name; string t2="";
771 scw->SetTitles(title, t2);
772}
773
774scw->AddScDrawer(scd, true);
775// scw->Refresh(); ? Pas necessaire Reza 19/08/98, 05/05/99 $CHECK$
776
777mCurWin = win;
778mCurWdg = scw;
779mLastWdg = scw;
780mBWId++;
781mBWList[mBWId] = scw;
782return(mBWId);
783}
784
785/* --Methode-- */
786int PIStdImgApp::Disp3DDrawer(PIDrawer3D* dr3, string const & name, string const& sop,
787 string title, int oid)
788{
789if (dr3 == NULL)
790 {
791 printf("PIStdImgApp::Disp3DDrawer_Error Cannot Add NULL 3DDrawer \n");
792 return(-1);
793 }
794
795// On decode les options graphiques
796vector<string> opts;
797DispWinEnum dwopt = ParseDisplayOption(sop, opts);
798
799if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
800
801// <ZThread> global PIApplication event loop synchronisation
802ZSync zs(thr_glsyn, 2);
803
804// Trace en superpoistion
805if ( (dwopt == Disp_Same) && (mLastWdg) ) {
806 // Les options
807 dr3->DecodeOptionString(mDefaultAtt, false);
808 if (nb_disp_same > 1) {
809 vector<string> ostatpos;
810 int spo = nb_disp_same%4;
811 if (spo == 1) ostatpos.push_back("statposoff=-0.01,-0.26");
812 else if (spo == 2) ostatpos.push_back("statposoff=-0.36,-0.01");
813 else ostatpos.push_back("statposoff=-0.36,-0.26");
814 dr3->DecodeOptionString(ostatpos, true);
815 }
816
817 dr3->DecodeOptionString(opts, true);
818
819 if (mLastWdg->kind() == PIDraw3DWdg::ClassId) ((PIDraw3DWdg*)mLastWdg)->AddDrawer3D(dr3, true);
820 else mLastWdg->AddDrawer(dr3, true, true, true);
821 dr3->Refresh();
822 mDId++;
823 mDrwList[mDId] = dr3;
824 return(-mDId);
825}
826// Trace en medaillon
827else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
828 PIGrCoord x1, x2, y1, y2;
829 x1 = mIXmin; x2 = mIXmax;
830 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
831 // Les options
832 dr3->DecodeOptionString(mDefaultAtt, false);
833 dr3->DecodeOptionString(opts, true);
834
835 dr3->SetAxesFlags(mAxesFlags);
836 dr3->UpdateLimits();
837 mLastWdg->AddDrawer(dr3, x1, y1, x2, y2, true, false, true);
838 dr3->Refresh();
839 mDId++;
840 mDrwList[mDId] = dr3;
841 return(-mDId);
842}
843
844
845PIWindow* win;
846int sx, sy, px, py, flag;
847sx = 200+mFgScSz*100;
848sy = 200+mFgScSz*100;
849win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
850PIDraw3DWdg* wd3 = new PIDraw3DWdg(win, (char *)name.c_str(), sx, sy, px, py);
851wd3->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
852wd3->SetUserData(NULL, oid);
853
854// Decodage des options :
855vector<string> scwatt;
856// wd3->SetAxesFlags(mAxesFlags); Attributs d'axes 3D a faire
857if ( mDefaultAtt.size() > 0) {
858 scwatt = mDefaultAtt;
859 dr3->DecodeOptionString(scwatt, true);
860 wd3->DecodeOptionString(scwatt, true);
861}
862if ( mAxesAtt.size() > 0) {
863 scwatt = mAxesAtt;
864 wd3->DecodeOptionString(scwatt, true);
865}
866if (opts.size() > 0)
867 dr3->DecodeOptionString(opts, true);
868if (opts.size() > 0)
869 wd3->DecodeOptionString(opts, false);
870
871// Titre du plot
872if (mAddTitle) {
873 if (title.length() <= 0) title = name; string t2="";
874 wd3->SetTitles(title, t2);
875}
876
877wd3->AddDrawer3D(dr3, true);
878// wd3->Refresh(); ?Pas necessaire $CHECK$ 05/05/99
879
880mCurWin = win;
881mCurWdg = wd3;
882mLastWdg = wd3;
883mBWId++;
884mBWList[mBWId] = wd3;
885return(mBWId);
886}
887
888// RZDEL: Normalement, il ne devrait plus y avoir besoin de cette
889// methode avec le thread separe de l'interpreteur - Reza 27/12/2003
890/* --Methode-- */
891int PIStdImgApp::ExecuteExtCommand()
892{
893if (!fg_exc_cmd) return(0);
894else {
895 fg_exc_cmd = false;
896 return CmdInterpreter()->Interpret(exc_command);
897 }
898}
899
900/* --Methode-- */
901void PIStdImgApp::AddText(string const & txt, double xp, double yp, string const& sop, bool fgcn)
902{
903// <ZThread> global PIApplication event loop synchronisation
904ZSync zs(thr_glsyn, 2);
905
906PIDrawer *eld=CurrentElDrawer();
907if (eld == NULL) return;
908PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
909PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
910if ((eld2 == NULL) && (eld3 == NULL)) return;
911PIElDrwMgr* elmgr;
912if (eld2) elmgr = &(eld2->ElDrwMgr());
913else if (eld3) elmgr = &(eld3->ElDrwMgr());
914if (elmgr == NULL) return;
915
916vector<string> opts;
917ParseDisplayOption(sop, opts);
918PIGraphicAtt gratt(opts);
919unsigned long tpd = 0;
920gratt.DecodeTextPosDirAtt(opts, tpd, false);
921elmgr->ElAddText(xp,yp,txt.c_str(), gratt, tpd, fgcn);
922eld->Refresh();
923}
924
925/* --Methode-- */
926void PIStdImgApp::AddCompText(string const & txt, string const & txtup, string const & txtdn,
927 double xp, double yp, string const& sop,
928 string const& optss, bool fgcn)
929{
930// <ZThread> global PIApplication event loop synchronisation
931ZSync zs(thr_glsyn, 2);
932
933PIDrawer *eld=CurrentElDrawer();
934if (eld == NULL) return;
935PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
936PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
937if ((eld2 == NULL) && (eld3 == NULL)) return;
938PIElDrwMgr* elmgr;
939if (eld2) elmgr = &(eld2->ElDrwMgr());
940else if (eld3) elmgr = &(eld3->ElDrwMgr());
941if (elmgr == NULL) return;
942
943vector<string> opts;
944ParseDisplayOption(sop, opts);
945PIGraphicAtt gratt(opts);
946unsigned long tpd = 0;
947gratt.DecodeTextPosDirAtt(opts, tpd, false);
948ParseDisplayOption(optss, opts);
949PIGraphicAtt grattss(opts);
950elmgr->ElAddCompText(xp,yp,txt.c_str(), gratt, txtup, txtdn, grattss, tpd, fgcn);
951eld->Refresh();
952}
953
954/* --Methode-- */
955void PIStdImgApp::AddLine(double xp1, double yp1, double xp2, double yp2,
956 string const& sop, bool fgarrow, bool fgcn)
957{
958// <ZThread> global PIApplication event loop synchronisation
959ZSync zs(thr_glsyn, 2);
960
961PIDrawer *eld=CurrentElDrawer();
962if (eld == NULL) return;
963PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
964PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
965if ((eld2 == NULL) && (eld3 == NULL)) return;
966PIElDrwMgr* elmgr = NULL;
967if (eld2) elmgr = &(eld2->ElDrwMgr());
968else if (eld3) elmgr = &(eld3->ElDrwMgr());
969if (elmgr == NULL) return;
970
971vector<string> opts;
972ParseDisplayOption(sop, opts);
973PIGraphicAtt gratt(opts);
974if (fgarrow)
975 elmgr->ElAddArrow(xp1, yp1, xp2, yp2, gratt, fgcn);
976else elmgr->ElAddLine(xp1, yp1, xp2, yp2, gratt, fgcn);
977eld->Refresh();
978}
979
980/* --Methode-- */
981void PIStdImgApp::AddRectangle(double xp1, double yp1, double xp2, double yp2,
982 string const& sop, bool fgfill, bool fgcn)
983{
984// <ZThread> global PIApplication event loop synchronisation
985ZSync zs(thr_glsyn, 2);
986
987PIDrawer *eld=CurrentElDrawer();
988if (eld == NULL) return;
989PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
990PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
991if ((eld2 == NULL) && (eld3 == NULL)) return;
992PIElDrwMgr* elmgr = NULL;
993if (eld2) elmgr = &(eld2->ElDrwMgr());
994else if (eld3) elmgr = &(eld3->ElDrwMgr());
995
996double xp,yp;
997double dx, dy;
998if (xp1 < xp2) {
999 xp = xp1; dx = xp2-xp1;
1000}
1001else {
1002 xp = xp2; dx = xp1-xp2;
1003}
1004if (yp1 < yp2) {
1005 yp = yp1; dy = yp2-yp1;
1006}
1007else {
1008 yp = yp2; dy = yp1-yp2;
1009}
1010
1011vector<string> opts;
1012ParseDisplayOption(sop, opts);
1013PIGraphicAtt gratt(opts);
1014
1015if (fgfill) elmgr->ElAddFRect(xp, yp, dx, dy, gratt, fgcn);
1016else elmgr->ElAddRect(xp, yp, dx, dy, gratt, fgcn);
1017eld->Refresh();
1018}
1019
1020/* --Methode-- */
1021void PIStdImgApp::AddCircle(double xc, double yc, double r, string const& sop,
1022 bool fgfill, bool fgcn)
1023{
1024// <ZThread> global PIApplication event loop synchronisation
1025ZSync zs(thr_glsyn, 2);
1026
1027PIDrawer *eld=CurrentElDrawer();
1028if (eld == NULL) return;
1029PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1030PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1031if ((eld2 == NULL) && (eld3 == NULL)) return;
1032PIElDrwMgr* elmgr = NULL;
1033if (eld2) elmgr = &(eld2->ElDrwMgr());
1034else if (eld3) elmgr = &(eld3->ElDrwMgr());
1035
1036vector<string> opts;
1037ParseDisplayOption(sop, opts);
1038PIGraphicAtt gratt(opts);
1039if (r < -0.5)
1040 elmgr->ElAddMarker(xc, yc, gratt);
1041else {
1042 if (fgfill) elmgr->ElAddFCirc(xc, yc, r, gratt, fgcn);
1043 else elmgr->ElAddCirc(xc, yc, r, gratt, fgcn);
1044}
1045eld->Refresh();
1046}
1047/* --Methode-- */
1048void PIStdImgApp::AddArc(double xc, double yc, double r, double a, double da,
1049 string const& sop, bool fgfill, bool fgcn)
1050{
1051// <ZThread> global PIApplication event loop synchronisation
1052ZSync zs(thr_glsyn, 2);
1053
1054PIDrawer *eld=CurrentElDrawer();
1055if (eld == NULL) return;
1056PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1057PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1058if ((eld2 == NULL) && (eld3 == NULL)) return;
1059PIElDrwMgr* elmgr = NULL;
1060if (eld2) elmgr = &(eld2->ElDrwMgr());
1061else if (eld3) elmgr = &(eld3->ElDrwMgr());
1062
1063vector<string> opts;
1064ParseDisplayOption(sop, opts);
1065PIGraphicAtt gratt(opts);
1066if (fgfill) elmgr->ElAddFArc(xc, yc, r, a, da, gratt, fgcn);
1067else elmgr->ElAddArc(xc, yc, r, a, da, gratt, fgcn);
1068eld->Refresh();
1069}
1070
1071/* --Methode-- */
1072void PIStdImgApp::AddArc(double x1, double y1, double x2, double y2,
1073 double x3, double y3, string const& sop, bool fgfill, bool fgcn)
1074{
1075// <ZThread> global PIApplication event loop synchronisation
1076ZSync zs(thr_glsyn, 2);
1077
1078PIDrawer *eld=CurrentElDrawer();
1079if (eld == NULL) return;
1080PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1081PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1082if ((eld2 == NULL) && (eld3 == NULL)) return;
1083PIElDrwMgr* elmgr = NULL;
1084if (eld2) elmgr = &(eld2->ElDrwMgr());
1085else if (eld3) elmgr = &(eld3->ElDrwMgr());
1086if (elmgr == NULL) return;
1087
1088vector<string> opts;
1089ParseDisplayOption(sop, opts);
1090PIGraphicAtt gratt(opts);
1091if (fgfill)
1092 elmgr->ElAddFArc(x1, y1, x2, y2, x3, y3, gratt, fgcn);
1093else elmgr->ElAddArc(x1, y1, x2, y2, x3, y3, gratt, fgcn);
1094eld->Refresh();
1095}
1096
1097/* --Methode-- */
1098void PIStdImgApp::AddPoly(vector<double>& xpol, vector<double>& ypol,
1099 string const& sop, bool fgfill, bool fgcn)
1100{
1101// <ZThread> global PIApplication event loop synchronisation
1102ZSync zs(thr_glsyn, 2);
1103
1104PIDrawer *eld=CurrentElDrawer();
1105if (eld == NULL) return;
1106PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1107PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1108if ((eld2 == NULL) && (eld3 == NULL)) return;
1109PIElDrwMgr* elmgr = NULL;
1110if (eld2) elmgr = &(eld2->ElDrwMgr());
1111else if (eld3) elmgr = &(eld3->ElDrwMgr());
1112if (elmgr == NULL) return;
1113
1114vector<string> opts;
1115ParseDisplayOption(sop, opts);
1116PIGraphicAtt gratt(opts);
1117if (fgfill)
1118 elmgr->ElAddFPoly(xpol, ypol, gratt, fgcn);
1119else elmgr->ElAddPoly(xpol, ypol, gratt, fgcn);
1120eld->Refresh();
1121
1122}
1123
1124
1125/* --Methode-- */
1126void PIStdImgApp::SetTitle(string const & titletop, string const & titlebottom, string const& sop)
1127{
1128// <ZThread> global PIApplication event loop synchronisation
1129ZSync zs(thr_glsyn, 2);
1130
1131PIDrawer *eld=CurrentElDrawer();
1132if (eld == NULL) return;
1133PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1134PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1135if ((eld2 == NULL) && (eld3 == NULL)) return;
1136
1137vector<string> opts;
1138ParseDisplayOption(sop, opts);
1139PIGraphicAtt gratt(opts);
1140
1141if (eld2) {
1142 eld2->SetTitles(titletop, titlebottom, gratt);
1143 eld2->ShowTitles(true);
1144}
1145else if (eld3) {
1146 eld3->SetTitles(titletop, titlebottom, gratt);
1147 eld3->ShowTitles(true);
1148}
1149eld->Refresh();
1150}
1151/* --Methode-- */
1152void PIStdImgApp::SetAxeLabels(string const & xLabel, string const & yLabel, string const& sop)
1153{
1154// <ZThread> global PIApplication event loop synchronisation
1155ZSync zs(thr_glsyn, 2);
1156
1157PIDrawer *eld=CurrentElDrawer();
1158if (eld == NULL) return;
1159PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1160if (eld2 == NULL) return;
1161
1162vector<string> opts;
1163ParseDisplayOption(sop, opts);
1164PIGraphicAtt gratt(opts);
1165
1166eld2->SetAxesLabels(xLabel, yLabel, gratt);
1167eld2->ShowAxesLabels(true);
1168
1169eld->Refresh();
1170}
1171
1172/* --Methode-- */
1173PIDrawer* PIStdImgApp::CurrentElDrawer()
1174{
1175PIDrawer *eld=NULL;
1176if (!mLastWdg) return(eld);
1177PIScDrawWdg* sdw=NULL;
1178PIDraw3DWdg* w3d=NULL;
1179PIImage* imgw;
1180switch(mLastWdg->kind()) {
1181 case PIScDrawWdg::ClassId :
1182 sdw = dynamic_cast<PIScDrawWdg *>(mLastWdg);
1183 if (sdw) eld = sdw->BaseDrawer();
1184 break;
1185 case PIDraw3DWdg::ClassId :
1186 w3d = dynamic_cast<PIDraw3DWdg *>(mLastWdg);
1187 if (w3d) eld = w3d->BaseDrawer();
1188 break;
1189 case PIImage::ClassId :
1190 imgw = dynamic_cast<PIImage *>(mLastWdg);
1191 if (imgw) eld = imgw->BaseDrawer();
1192 break;
1193 default :
1194 break;
1195 }
1196return(eld);
1197}
1198
1199/* --Methode-- */
1200void PIStdImgApp::CreateGraphWin(int nx, int ny, int sx, int sy)
1201{
1202if (nx < 1) nx = 1;
1203if (ny < 1) ny = 1;
1204if (nx > 8) nx = 8;
1205if (ny > 8) ny = 8;
1206if ( (sx < 50) && (sy < 50) ) sx = sy = 400+mFgScSz*100;
1207char buff[64];
1208mWId++;
1209int px, py;
1210MainWin()->GetScreenPos(px, py);
1211sprintf(buff, "PI-GraphicWin (%d)",mWId);
1212PIZoneWindow* win = new PIZoneWindow(this, buff, PIWK_normal, nx, ny, sx, sy, px+MainWin()->XSize()+30, 0);
1213win->SetUserData(NULL, ny*10+nx); // UserFlag= nY*10 + nX
1214mWList[mWId*10+1] = (PIWindow*)win;
1215win->SetAutoDelChilds(true);
1216// win->Show();
1217mGrW = win;
1218mGrIdx = 0;
1219}
1220
1221/* --Methode-- */
1222void PIStdImgApp::CreateStackWin(int sx, int sy)
1223{
1224if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
1225char buff[64];
1226mWId++;
1227int px, py;
1228MainWin()->GetScreenPos(px, py);
1229sprintf(buff, "PI-StackWin (%d)",mWId);
1230PIStackWindow* win = new PIStackWindow(this, buff, PIWK_normal, sx, sy, px+MainWin()->XSize()+30, 100);
1231win->SetUserData(NULL, 9999); // UserFlag= 9999
1232mWList[mWId*10+2] = (PIWindow*)win;
1233win->SetAutoDelChilds(true);
1234// win->Show();
1235mStW = win;
1236m[2]->SetSensitivity("StackTools", true);
1237mStIdx = 0;
1238}
1239
1240/* --Methode-- */
1241PIWindow* PIStdImgApp::GetWindow(DispWinEnum typ, int& sx, int& sy, int& px, int& py, int& flag, char * nom)
1242{
1243PIWindow* rw;
1244
1245switch (typ) {
1246 case Disp_Next : // Fenetre graphique courante
1247 case Disp_Default :
1248 {
1249 if (mGrW == NULL) CreateGraphWin();
1250 int nx, ny;
1251 mGrW->NbZone(nx, ny);
1252 PIWdg* nw = mGrW->NextChildPosSize(px, py, sx, sy);
1253// cerr << "**DBG** PIStdImgApp::GetWindow() DispNext : nw = " << (long)nw << endl;
1254 if (nw) DeleteBaseWidget((PIBaseWdg*)nw, false, false);
1255 flag = mGrIdx;
1256 mGrIdx = (mGrIdx+1)%(nx*ny);
1257 rw = mGrW;
1258 break;
1259 }
1260
1261 case Disp_Stack : // Fenetre de type stack (empilement)
1262 {
1263 if (mStW == NULL) CreateStackWin(sx, sy);
1264 px = py = 0;
1265 sx = mStW->XSize();
1266 sy = mStW->YSize();
1267 flag = mStIdx;
1268 mStIdx++;
1269 rw = mStW;
1270 }
1271 break;
1272
1273 default : // Fenetre ordinaire
1274 {
1275 int pwx, pwy;
1276 MainWin()->GetScreenPos(pwx, pwy);
1277 if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
1278 rw = new PIWindow(this, nom, PIWK_normal, sx, sy, pwx+MainWin()->XSize()+30, 300);
1279 rw->SetUserData(NULL, 0); // UserFlag= 0
1280 mWId++;
1281 mWList[mWId*10] = rw;
1282 rw->SetAutoDelChilds(true);
1283 // rw->Show();
1284 px = py = 0;
1285 flag = 0;
1286 break;
1287 }
1288 }
1289
1290rw->Show();
1291mCurWin = rw;
1292return(rw);
1293}
1294
1295/* --Methode-- */
1296void PIStdImgApp::SetZone(int nzx, int nzy)
1297{
1298if (!mGrW) CreateGraphWin(nzx, nzy);
1299else {
1300 int k;
1301 PIWdg* cwd;
1302 for(k=0; k<mGrW->NbChilds(); k++) {
1303 if ((cwd = mGrW->GetChild(k)) == NULL) continue;
1304 DeleteBaseWidget((PIBaseWdg*)cwd, false, false);
1305 }
1306 mGrW->SetZone(nzx, nzy);
1307 }
1308}
1309
1310/* --Methode-- */
1311void PIStdImgApp::StackWinNext()
1312{
1313if (mStW) mStW->DispNext();
1314}
1315
1316/* --Methode-- */
1317void PIStdImgApp::DeleteWindow(PIWindow* w)
1318{
1319if (w == NULL) return;
1320w->Hide();
1321bool ownwindow=false; // To Check if this is one of our windows
1322WindMList::iterator it;
1323for(it = mWList.begin(); it != mWList.end(); it++)
1324 if ((*it).second == w) { mWList.erase(it); ownwindow = true; break; }
1325if (w == mGrW) { mGrW = NULL; mGrIdx = -1; }
1326if (w == mStW) { mStW = NULL; mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
1327if (w == mCurWin) mCurWin = NULL;
1328
1329if (!ownwindow) return; // We do nothing if this is not a window we have created ...
1330
1331int k;
1332PIWdg* cwd;
1333for(k=0; k<w->NbChilds(); k++) {
1334 if ((cwd = w->GetChild(k)) == NULL) continue;
1335 DeleteBaseWidget((PIBaseWdg*)cwd,false,false);
1336 }
1337delete w;
1338return;
1339}
1340
1341/* --Methode-- */
1342void PIStdImgApp::DeleteBaseWidget(PIBaseWdg* w, bool dw, bool dwin)
1343{
1344if (w == NULL) return;
1345BWMList::iterator it;
1346for(it = mBWList.begin(); it != mBWList.end(); it++)
1347 if ((*it).second == w) { mBWList.erase(it); break; }
1348int k;
1349PIDrawer* drw;
1350for(k=0; k<w->NbDrawers(); k++) {
1351 if ((drw = w->GetDrawer(k)) == NULL) continue;
1352 DrwMList::iterator itt;
1353 for(itt = mDrwList.begin(); itt != mDrwList.end(); itt++)
1354 if ((*itt).second == drw) { mDrwList.erase(itt); break; }
1355 }
1356
1357if (w == mCurWdg) {
1358 mCurWdg = NULL;
1359 if (mFgCWImg) {
1360 m[4]->SetSensitivityMsg(10515, false);
1361 m[4]->SetSensitivityMsg(10516, false);
1362 mFgCWImg = false;
1363 }
1364 }
1365
1366if (w == mLastWdg) mLastWdg = NULL;
1367
1368PIWdg* pw=NULL;
1369if (dwin) pw = (PIWdg*)(w->Parent());
1370//DBG printf("DeleteBaseWidget(%lx)-DBG kind = %d - %d %d \n", (long)w, w->kind(), (int)dw, (int)dwin);
1371if (dw) delete w;
1372if (pw && (pw->kind() == PIWindow::ClassId )) {
1373 PIWindow* pww = (PIWindow*) pw;
1374 if ((pww != (PIWindow*)mGrW) && (pww != (PIWindow*)mStW) && (pww->NbChilds()==0))
1375 DeleteWindow((PIWindow*)pw);
1376 }
1377return;
1378}
1379
1380
1381
1382/* --Methode-- */
1383void PIStdImgApp::DelWRsId(int k)
1384{
1385//DBG cerr << "-DBG- PIStdImgApp::DelWRsId(" << k << ")" << endl;
1386if (k > 0) { // C'est un BaseWidget
1387 BWMList::iterator it;
1388 it = mBWList.find(k);
1389 if (it == mBWList.end()) return;
1390 PIBaseWdg* wd = (*it).second;
1391//DBG cerr << "-DBG- PIStdImgApp::DelWRsId Deleting BaseWidget " << (long)(wd) << endl ;
1392 DeleteBaseWidget(wd, true, true);
1393 }
1394else { // C'est un drawer
1395 DrwMList::iterator it;
1396 it = mDrwList.find(-k);
1397 if (it == mDrwList.end()) return;
1398 (*it).second->SetAutoRefreshOnDelete(true);
1399 delete (*it).second;
1400 mDrwList.erase(it);
1401 //DBG cerr << "+DBG+ PIStdImgApp::DelWRsId Deleting Drawer " << (long)((*it).second) << endl ;
1402 }
1403}
1404/* --Methode-- */
1405bool PIStdImgApp::CheckWRsId(int k)
1406{
1407if (k > 0) { // C'est un BaseWidget
1408 BWMList::iterator it;
1409 it = mBWList.find(k);
1410 if (it == mBWList.end()) return(false);
1411 else return(true);
1412 }
1413else { // C'est un drawer
1414 DrwMList::iterator it;
1415 it = mDrwList.find(-k);
1416 if (it == mDrwList.end()) return(false);
1417 else return(true);
1418 }
1419}
1420
1421/* --Methode-- */
1422void PIStdImgApp::StatZoomWindowSetVisible(bool fg)
1423{
1424
1425 if (fg) {
1426 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1427 int szy = MainWin()->YSize();
1428 MainWin()->SetSize(MainWin()->XSize(), szy+statcont->YSize());
1429 consolecont->SetPos(0, statcont->YSize());
1430 consolecont->SetSize(MainWin()->XSize(), szy);
1431 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
1432 statcont->Show();
1433 m[3]->SetStateMsg(10470, true);
1434 }
1435 else {
1436 statcont->Hide();
1437 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1438 MainWin()->SetSize(MainWin()->XSize(), MainWin()->YSize()-statcont->YSize());
1439 consolecont->SetPos(0, 0);
1440 consolecont->SetSize(MainWin()->XSize(), MainWin()->YSize());
1441 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
1442 m[3]->SetStateMsg(10470, false);
1443 }
1444
1445}
1446
1447/* --Methode-- */
1448void PIStdImgApp::UpdateStatResourceInfo()
1449{
1450 resusg.Update();
1451 char buff[256];
1452 string lab;
1453 double frac;
1454 sprintf(buff, "Mem: %ld/Max= %ld kb" , (long)resusg.getMemorySize(),
1455 (long)resusg.getMaxMemorySize());
1456 lab = buff;
1457 lab_mem->SetLabel(lab);
1458 frac = (double)resusg.getMemorySize()/(double)resusg.getMaxMemorySize();
1459 therm_mem->SetValue(frac);
1460
1461 sprintf(buff, "CPU: %ld/elap= %ld ms" , (long)resusg.getCPUTime(),
1462 (long)resusg.getElapsedTime());
1463 lab = buff;
1464 lab_cpu->SetLabel(lab);
1465 if (resusg.getCPULoad() > resusg.getAverageCPULoad())
1466 therm_cpu->SetValue(resusg.getCPULoad());
1467 else
1468 therm_cpu->SetValue(resusg.getAverageCPULoad());
1469 int nlx = 0;
1470 bool fgx = false;
1471 if ( CmdInterpreter() ) fgx = CmdInterpreter()->isRunning(nlx);
1472 if (!fgx) {
1473 lab = "PIACmdThread Idle";
1474 lab_thrcmd->SetLabel(lab);
1475 lab_thrcmd->SetForegroundColor(PI_Green);
1476 }
1477 else {
1478 sprintf(buff, "PIACmdThread Running - NL=%d" , nlx);
1479 lab = buff;
1480 lab_thrcmd->SetLabel(lab);
1481 if (nlx < 3) lab_thrcmd->SetForegroundColor(PI_Yellow);
1482 else lab_thrcmd->SetForegroundColor(PI_Red);
1483 }
1484}
1485
1486/* --Methode-- */
1487void PIStdImgApp::RedirectStdOutErr(bool fg)
1488{
1489if (fg) {
1490 RedirectOutStream(mCons);
1491 RedirectErrStream(mCons);
1492 m[5]->SetStateMsg(10602, true);
1493 redirecout = true;
1494 }
1495else {
1496 RedirectOutStream(NULL);
1497 RedirectErrStream(NULL);
1498 m[5]->SetStateMsg(10602, false);
1499 redirecout = false;
1500 }
1501return;
1502}
1503
1504/* --Methode-- */
1505void PIStdImgApp::CatchSignals(bool fgfpe, bool fgsegv)
1506{
1507#ifdef SANS_EVOLPLANCK
1508PeidaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1509#else
1510SophyaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1511#endif
1512m[5]->SetStateMsg(10603, fgfpe);
1513m[5]->SetStateMsg(10604, fgsegv);
1514}
1515
1516/* --Methode-- */
1517void PIStdImgApp::CloseAllWindows()
1518{
1519WindMList::iterator it;
1520for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
1521mWList.clear();
1522mBWList.clear();
1523mDrwList.clear();
1524mGrW = NULL;
1525mStW = NULL;
1526mCurWin = NULL;
1527mCurWdg = NULL;
1528mLastWdg = NULL;
1529m[4]->SetSensitivityMsg(10515, false);
1530m[4]->SetSensitivityMsg(10516, false);
1531}
1532
1533//---------------------------------------------------------------------------
1534//--------- Gestion des attributs graphiques et autres options de trace -----
1535
1536/* --Methode-- */
1537void PIStdImgApp::SetInsetLimits(double xmin, double xmax, double ymin, double ymax)
1538{
1539 mIXmin = xmin; mIXmax= xmax;
1540 mIYmin = ymin; mIYmax= ymax;
1541}
1542
1543/* --Methode-- */
1544void PIStdImgApp::SetDefaultGraphicAttributes(string const & opt)
1545{
1546 ParseDisplayOption(opt, mDefaultAtt);
1547}
1548
1549/* --Methode-- */
1550void PIStdImgApp::SetDefaultAxesAttributes(string const & opt)
1551{
1552 ParseDisplayOption(opt, mAxesAtt);
1553}
1554
1555/* --Methode-- */
1556DispWinEnum PIStdImgApp::ParseDisplayOption(string const & sop, vector<string>& opts)
1557{
1558 DispWinEnum rc = Disp_Next;
1559 //DBG cerr << " DBG-Parse-A sop=" << sop << " sop.length()= " << sop.length() << endl;
1560 if (opts.size() > 0) opts.erase(opts.begin(), opts.end());
1561 if (sop.length() < 1) return(rc);
1562 string gratt = sop;
1563 for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1564 if ( (gratt == "def") || (gratt == "default") ) return(rc);
1565// On separe en mots espaces par des blancs ou tabulation
1566 size_t p = 0;
1567 size_t q = 0;
1568 size_t l = gratt.length();
1569 string token;
1570 while (q < l) {
1571 p = gratt.find_first_not_of(" \t",q); // au debut d'un token
1572 if (p >= l) break;
1573 q = gratt.find_first_of(" \t",p); // Premier blanc ou tab suivant
1574 if (q<l) token = gratt.substr(p,q-p);
1575 else token = gratt.substr(p);
1576 if (token == "") continue;
1577 // Decodage option fenetre d'affichage (win, next, ...)
1578 if (token == "win") rc = Disp_Win;
1579 else if (token == "same") rc = Disp_Same;
1580 else if (token == "inset") rc = Disp_Inset;
1581 else if (token == "stack") rc = Disp_Stack;
1582 else if (token == "next") rc = Disp_Next;
1583 // Option a etre decode par les drawers, etc ...
1584 else opts.push_back(token);
1585 }
1586
1587 //DBG cerr << " DBG-Parse-B opts.size()=" << opts.size() << endl;
1588 if (rc == Disp_Same) nb_disp_same++;
1589 else nb_disp_same = 0;
1590 return (rc);
1591}
1592
1593//---------------------------------------------------------------------------
1594//------------ Methodes privees (MBProcessx, ...) ----------
1595
1596/* --Methode-- */
1597void PIStdImgApp::MBProcess1(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1598{
1599
1600 switch(msg)
1601 {
1602 case 10150 :
1603 showInfoWindow(this);
1604 break;
1605
1606 case 10155 :
1607 hideInfoWindow(this);
1608 break;
1609
1610 case 10100 :
1611 CmdInterpreter()->ShowHelpWindow();
1612 break;
1613
1614 case 10120 :
1615 pfc_fits->AcceptNewFile(false);
1616 mFCMsg = 10125;
1617 pfc_fits->SetMsg(mFCMsg);
1618 SetBlocked();
1619 pfc_fits->Show();
1620 break;
1621
1622 case 10125 :
1623 SetBusy();
1624 if (data) {
1625 string nomobj="";
1626 ObjMgr()->ReadFits(pfc_fits->GetFileName(), nomobj);
1627 ObjMgr()->DisplayObj(nomobj, "win");
1628 }
1629 mFCMsg = 0;
1630 SetReady();
1631 break;
1632
1633 case 10130 :
1634 pfc_ppf->AcceptNewFile(false);
1635 mFCMsg = 10135;
1636 pfc_ppf->SetMsg(mFCMsg);
1637 SetBlocked();
1638 pfc_ppf->Show();
1639 break;
1640
1641 case 10135 :
1642 mFCMsg = 0;
1643 if (data) {
1644 PPInMgrW()->SetFile(pfc_ppf->GetFileName());
1645 PPInMgrW()->Show();
1646 }
1647 SetReady();
1648 break;
1649
1650#ifndef SANS_EVOLPLANCK
1651 case 10140 :
1652 pfc_ascii->AcceptNewFile(false);
1653 mFCMsg = 10145;
1654 pfc_ascii->SetMsg(mFCMsg);
1655 SetBlocked();
1656 pfc_ascii->Show();
1657 break;
1658
1659 case 10145 :
1660 SetBusy();
1661 if (data) {
1662 string afname = pfc_ascii->GetFileName();
1663 string nomobj = ObjMgr()->GetServiceObj()->FileName2Name(afname);
1664 string cmd = "mtxfrascii ";
1665 cmd += nomobj; cmd += " "; cmd += afname;
1666 try {
1667 CmdInterpreter()->AddInputLine(cmd);
1668 // mCmd->Interpret(cmd);
1669 }
1670 catch ( PThrowable & exc ) {
1671 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
1672 << (string)typeid(exc).name() << " Msg= "
1673 << exc.Msg() << endl;
1674 cout << endl;
1675 }
1676 catch ( ... ) {
1677 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ... " << endl;
1678 cout << endl;
1679 }
1680
1681 }
1682 mFCMsg = 0;
1683 SetReady();
1684 break;
1685#endif
1686
1687 case 10105:
1688 Stop();
1689 break;
1690
1691 }
1692return;
1693}
1694
1695
1696
1697/* --Methode-- */
1698void PIStdImgApp::MBProcess2(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1699{
1700
1701switch (msg) {
1702 case 10201 :
1703 ObjMgrW()->Show();
1704 break;
1705
1706 case 10220 :
1707 pfc_ppf->AcceptNewFile(true);
1708 mFCMsg = 10225;
1709 pfc_ppf->SetMsg(mFCMsg);
1710 SetBlocked();
1711 pfc_ppf->Show();
1712 break;
1713
1714 case 10225 :
1715 SetBusy();
1716 if (data) {
1717 if (mPpfout) {
1718 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1719 delete mPpfout;
1720 }
1721 name_outppf = pfc_ppf->GetFileName();
1722 mPpfout = NULL;
1723 printf("PIStdImg/Info: Opening POutPersist-File %s \n", name_outppf.c_str());
1724 mPpfout = new POutPersist(name_outppf);
1725 }
1726 mFCMsg = 0;
1727 SetReady();
1728 break;
1729
1730 case 10230 :
1731 if (!mPpfout) break;
1732 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1733 delete mPpfout;
1734 name_outppf = "";
1735 mPpfout = NULL;
1736 break;
1737
1738 case 10270 :
1739 if (mCurWdg) {
1740 int oid = mCurWdg->UserFlag();
1741 DeleteBaseWidget(mCurWdg);
1742 mObjMgr->DelObj_Id(oid);
1743 }
1744 break;
1745
1746 default:
1747 cerr << "PIStdImgApp::MBProcess2() BUG?? Msg= " << msg << endl;
1748 break;
1749}
1750
1751return;
1752}
1753
1754/* --Methode-- */
1755void PIStdImgApp::MBProcess3(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1756{
1757
1758switch (msg) {
1759 case 10301 :
1760 PIImgTools::ShowPIImgTools();
1761 break;
1762 case 10302 :
1763 PIDrwTools::ShowPIDrwTools();
1764 break;
1765 case 10303 :
1766 PIAxesTools::ShowPIAxesTools();
1767 break;
1768
1769 case 10304 :
1770 CmdInterpreter()->ShowCxxExecWindow();
1771 break;
1772
1773 case 10311 :
1774 case 10312 :
1775 {
1776 PIImage* curpimg = NULL;
1777 if (!mCurWdg) return;
1778 if (mCurWdg->kind() != PIImage::ClassId) return;
1779 curpimg = (PIImage*)mCurWdg;
1780 if (curpimg == NULL) return;
1781 P2DArrayAdapter* img = curpimg->Image();
1782 if (img == NULL) return;
1783 int dx = curpimg->XSzPave();
1784 int dy = curpimg->YSzPave();
1785 int x0 = curpimg->XPave()-dx/2;
1786 int y0 = curpimg->YPave()-dy/2;
1787 if (x0 < 0) x0 = 0;
1788 if (y0 < 0) y0 = 0;
1789 int x1 = x0+dx;
1790 int y1 = y0+dy;
1791 if (x1 > img->XSize()) x1 = img->XSize();
1792 if (y1 > img->YSize()) y1 = img->YSize();
1793 dx = x1-x0; dy = y1-y0;
1794 ImageR4* pim = new ImageR4(dx, dy);
1795 int ii, jj;
1796 for(jj=0; jj<dy; jj++)
1797 for(ii=0; ii<dx; ii++) (*pim)(ii,jj) = (*img)(ii+x0, jj+y0);
1798 if (msg == 10305) { // Calcul des coordonnees du sous-pave
1799 double xc1, yc1;
1800 img->Coord(x0, y0, xc1, yc1);
1801 pim->SetOrg((int)xc1, (int)yc1);
1802 }
1803 string nom = mCurWdg->Nom() + "_pave";
1804 ObjMgr()->AddObj(pim, nom);
1805 ObjMgr()->DisplayObj(nom, "w");
1806 break;
1807 }
1808
1809 case 10313 :
1810 {
1811 PIImage* curpimg = NULL;
1812 if (!mCurWdg) return;
1813 if (mCurWdg->kind() != PIImage::ClassId) return;
1814 curpimg = (PIImage*)mCurWdg;
1815 if (curpimg == NULL) return;
1816 curpimg->ShowCuts(true);
1817 break;
1818 }
1819
1820 case 10320 :
1821 if (mStW) mStW->DispNext();
1822 break;
1823
1824 case 10321 :
1825 case 10322 :
1826 case 10324 :
1827// case 10328 :
1828 if (mStW) mStW->StartAutoDisp((msg-10320)*500);
1829 break;
1830
1831 case 10329 :
1832 if (mStW) mStW->StopAutoDisp();
1833 break;
1834
1835 case 103330 :
1836 if (mStW) {
1837 PIWdg* cw = mStW->CurrentWdg();
1838 if (cw) DeleteBaseWidget((PIBaseWdg*)cw);
1839 }
1840 break;
1841
1842 default:
1843 cerr << "PIStdImgApp::MBProcess3() BUG?? Msg= " << msg << endl;
1844 break;
1845 }
1846return;
1847}
1848
1849/* --Methode-- */
1850void PIStdImgApp::MBProcess4(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1851{
1852
1853switch (msg) {
1854
1855 case 10400 :
1856 CreateStackWin();
1857 break;
1858
1859 case 10411 :
1860 CreateGraphWin(1,1);
1861 break;
1862 case 10421 :
1863 CreateGraphWin(1,2);
1864 break;
1865 case 10412 :
1866 CreateGraphWin(2,1);
1867 break;
1868 case 10422 :
1869 CreateGraphWin(2,2);
1870 break;
1871 case 10431 :
1872 CreateGraphWin(1,3);
1873 break;
1874 case 10433 :
1875 CreateGraphWin(3,3);
1876 break;
1877 case 10441 :
1878 if (mCurWdg) {
1879 mLastWdg = mCurWdg;
1880 cout << " Using current widget as last-widget (display same) " << endl;
1881 }
1882 else cout << " No current widget - select widget with mouse " << endl;
1883 break;
1884 case 10460 :
1885 DeleteWindow(mCurWin);
1886 break;
1887 case 10470 :
1888 StatZoomWindowSetVisible(m[3]->GetStateMsg(10470));
1889 break;
1890 default:
1891 cerr << "PIStdImgApp::MBProcess4() BUG?? Msg= " << msg << endl;
1892 break;
1893 }
1894return;
1895}
1896
1897
1898/* --Methode-- */
1899void PIStdImgApp::MBProcess5(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1900{
1901char nomps[64],strg[512];
1902PSFile *mps;
1903int sxt, syt, syo, syo1, sx[4], sy[4];
1904
1905switch (msg)
1906 {
1907 case 10501 :
1908 pfc_ps->AcceptNewFile(true);
1909 mFCMsg = 10525;
1910 pfc_ps->SetMsg(mFCMsg);
1911 SetBlocked();
1912 pfc_ps->Show();
1913 break;
1914
1915 case 10525 :
1916 SetBusy();
1917 if (data) {
1918 if (mpsfile) {
1919 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1920 delete mpsfile;
1921 }
1922 name_ps = pfc_ps->GetFileName();
1923 printf("PIStdImg/Info: Opening PS-File %s \n", name_ps.c_str());
1924 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 2., 2.);
1925 }
1926 mFCMsg = 0;
1927 SetReady();
1928 break;
1929
1930 case 10505 :
1931 if (!mpsfile) break;
1932 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1933 delete mpsfile;
1934 mpsfile = NULL;
1935 name_ps = "";
1936 break;
1937
1938 case 10511 : // Window -> PS
1939 case 10512 : // Window -> EPS
1940 if (CurrentWindow() == NULL) break;
1941 if (msg == 10512)
1942 {
1943 num_eps++;
1944 sprintf(nomps,"pia%d.eps", num_eps);
1945 printf("PIStdImg/Info: Creating EPSFile %s (CurWin-> EPS) \n", nomps);
1946 mps = new PSFile(nomps);
1947 }
1948 else {
1949 if (mpsfile == NULL) {
1950 name_ps = "pia.ps";
1951 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 0., 0.);
1952 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1953 }
1954 printf("PIStdImg/Info: CurWin-> PSFile %s\n", name_ps.c_str());
1955 mps = mpsfile;
1956 }
1957 CurrentWindow()->PSPrint(mps,0,0);
1958
1959 if (msg == 10512) delete mps; // fichier eps
1960 break;
1961
1962 case 10515 : // Image -> PS
1963 case 10516 : // Image -> EPS
1964 {
1965 PIImage* curpimg = NULL;
1966 if (!mCurWdg) return;
1967 if (mCurWdg->kind() != PIImage::ClassId) return;
1968 curpimg = (PIImage*)mCurWdg;
1969 if (curpimg == NULL) return;
1970 if (msg == 10516)
1971 {
1972 num_eps++;
1973 sprintf(nomps,"pia%d.eps", num_eps);
1974 printf("PIStdImg/Info: Creating EPSFile %s (CurImage-> EPS)\n", nomps);
1975 mps = new PSFile(nomps);
1976 }
1977 else {
1978 if (mpsfile == NULL) {
1979 name_ps = "pia.ps";
1980 mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
1981 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1982 }
1983 printf("PIStdImg/Info: CurImage-> PSFile %s\n", name_ps.c_str());
1984 mps = mpsfile;
1985 }
1986
1987 sx[0] = gimv->XSize();
1988 sy[0] = gimv->YSize();
1989 sx[1] = zoom->XSize();
1990 sy[1] = zoom->YSize();
1991 sx[2] = cmapv->XSize();
1992 sy[2] = cmapv->YSize();
1993 sx[3] = curpimg->XSize();
1994 sy[3] = curpimg->YSize();
1995 if (sy[1] > sy[0]) { syo1 = sy[1]+50; syo = sy[1]+sy[2]+60; }
1996 else { syo1 = sy[0]+50; syo = sy[0]+sy[2]+60; }
1997 syt = sy[3]+syo;
1998 sxt = sx[3];
1999 if (sxt < (sx[0]+sx[1]+20)) sxt = sx[0]+sx[1]+20;
2000 if (sxt < sx[2]) sxt = sx[2];
2001
2002 // Pour ecrire le titre
2003 mps->NewPage((float)sxt, (float)syt, PI_Portrait);
2004 mps->NewBloc(0,0, (float)sxt, 30., (float)sxt, 30.);
2005 sprintf(strg,"Image: %s - Pave %d %d \n", curpimg->Nom().c_str(),
2006 curpimg->XPave(), curpimg->YPave());
2007 mps->DrawString(10., 25., strg, PI_Black, PI_DefaultFont, PI_BoldFont, 20);
2008 mps->EndBloc();
2009
2010 // Les quatre fenetres glovimage, zoom, cmap, image
2011 gimv->PSPrint(mps, -gimv->XPos(), -gimv->YPos()+40);
2012 zoom->PSPrint(mps, -zoom->XPos()+sx[0]+20, -zoom->YPos()+40);
2013 cmapv->PSPrint(mps, -cmapv->XPos(), -cmapv->YPos()+syo1);
2014 curpimg->PSPrint(mps, -curpimg->XPos(), -curpimg->YPos()+syo);
2015
2016 if (msg == 10516) delete mps; // fichier eps
2017 break;
2018 }
2019
2020 default:
2021 cerr << "PIStdImgApp::MBProcess5() BUG?? Msg= " << msg << endl;
2022 break;
2023 }
2024
2025}
2026
2027
2028/* --Methode-- */
2029void PIStdImgApp::MBProcess6(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
2030{
2031switch (msg) {
2032 case 10601:
2033 CloseAllWindows();
2034 break;
2035 case 10602:
2036 RedirectStdOutErr(*((bool*)data));
2037 break;
2038 case 10603:
2039 case 10604:
2040 CatchSignals(m[5]->GetStateMsg(10603), m[5]->GetStateMsg(10604));
2041 break;
2042 case 10605:
2043 mObjMgr->SetVerbose(m[5]->GetStateMsg(10605));
2044 break;
2045 case 10606:
2046 CmdInterpreter()->ShowCxxOptionWindow();
2047 break;
2048 default:
2049 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
2050 break;
2051 }
2052return;
2053}
2054
2055
2056
2057// -------------------------------------------------
2058// Fenetre info piapp (About piapp)
2059// -------------------------------------------------
2060static PIWindow* infow_win = NULL;
2061static PIText* infow_txt = NULL;
2062static PICMapView* infow_cmap = NULL;
2063static PIButton* infow_but = NULL;
2064
2065/* Nouvelle-Fonction */
2066static void createInfoWindow(PIStdImgApp* app)
2067{
2068if (infow_win) return;
2069
2070int bsx, bsy;
2071PIApplicationPrefCompSize(bsx, bsy);
2072int spx, spy;
2073spx = bsx/6; spy = bsy/6;
2074
2075infow_win = new PIWindow((PIMsgHandler *)app, "About piapp",
2076 PIWK_dialog, bsx*5+3*spx, bsy*4+spy*3, 200, 200);
2077infow_win->SetAutoDelChilds(true);
2078infow_txt = new PIText(infow_win,"about_piapp_text", bsx*5+spx, bsy*3, spx, spy);
2079infow_txt->SetMutiLineMode(true);
2080infow_txt->SetTextEditable(false);
2081infow_txt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2082infow_cmap = new PICMapView(infow_win, "about_piapp_cmap", bsx*4, bsy*0.7, spx, 2*spy+bsy*3.15);
2083infow_cmap->SetColMapId(CMAP_COLBR32, 1., -1., false);
2084infow_cmap->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2085infow_but = new PIButton(infow_win,"OK", 10155, bsx, bsy, bsx*4+2*spx, 2*spy+bsy*3);
2086infow_but->SetMsgParent((PIMsgHandler *)app);
2087infow_but->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2088char buff[128];
2089#ifdef SANS_EVOLPLANCK
2090sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
2091 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
2092#else
2093{
2094sprintf(buff, "Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
2095 (double)PI_VERSIONNUMBER, glst_piai->Version());
2096}
2097#endif
2098string info = "piapp : Interactive analysis program\n";
2099info += buff;
2100info += "(C) LAL-IN2P3/CNRS 1996-2003\n";
2101info += "(C) SPP-DAPNIA/CEA 1996-2003\n";
2102#ifndef SANS_EVOLPLANCK
2103 info += "Check http://www.sophya.org for more information";
2104#endif
2105infow_txt->SetText(info);
2106}
2107
2108/* Nouvelle-Fonction */
2109static void showInfoWindow(PIStdImgApp* app)
2110{
2111if (!infow_win) createInfoWindow(app);
2112if (infow_win) infow_win->Show();
2113}
2114/* Nouvelle-Fonction */
2115static void hideInfoWindow(PIStdImgApp* app)
2116{
2117if (infow_win) infow_win->Hide();
2118}
2119
2120/* Nouvelle-Fonction */
2121static void deleteInfoWindow()
2122{
2123if (!infow_win) return;
2124delete infow_win;
2125infow_win = NULL;
2126infow_txt = NULL;
2127infow_cmap = NULL;
2128infow_but = NULL;
2129}
2130
2131
Note: See TracBrowser for help on using the repository browser.