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

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

Adaptation pour redirection stdout/err a travers un fichier ds PIATmpxxx/, Reza 31/10/2007

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