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

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

ajout decodage attributs graphiques samew=WdgName wname=Nom inset=fx1,fx2,fy1,fy2 - Reza 22/10/2007

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