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

Last change on this file since 3431 was 3431, checked in by ansari, 18 years ago

Ajout protection attente fin de thread, avant delete objet thread lors de sortie piapp (exitpiapp) - Reza 11/12/2007

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