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

Last change on this file since 3071 was 3024, checked in by ansari, 19 years ago

Adaptation modification SophyaInitiator::RegisterModule()/PrintVersion() - pret pour tag V2 Reza 17/7/2006

  • Property svn:executable set to *
File size: 62.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// On decode les options graphiques
764vector<string> opts;
765DispWinEnum dwopt = ParseDisplayOption(sop, opts);
766
767// Pas de same ou inset pour DispImage
768if ((dwopt == Disp_Same) || (dwopt == Disp_Inset) ) dwopt = Disp_Next;
769
770// <ZThread> global PIApplication event loop synchronisation
771SyncPIS zs(getMutex(), fglock, 2);
772
773// Choix de la taille de fenetre
774#define MINPIIMGSIZE 100
775sx = (nouv->XSize() > MINPIIMGSIZE) ? nouv->XSize() : MINPIIMGSIZE;
776sy = (nouv->YSize() > MINPIIMGSIZE) ? nouv->XSize() : MINPIIMGSIZE;
777if (sx > 400+mFgScSz*100) sx = 400+mFgScSz*100;
778if (sy > 400+mFgScSz*100) sy = 400+mFgScSz*100;
779px = py = 0;
780win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
781if (fgimagnav) { // Creation de naviguateur d'image
782 piin = new PIImageNavigator(win, (char *)name.c_str(), sx, sy, px,py);
783 piin->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
784 piin->Show();
785 piin->ImageWdg()->ShowCursor(true);
786 pii = piin->ImageWdg();
787 piin->SetUserData(NULL, oid);
788 pii->SetUserData(NULL, oid);
789}
790else { // Creation de widget PIImage normal
791 pii = new PIImage(win, (char *)name.c_str(), sx, sy, px,py);
792 pii->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
793 pii->SetZoomWin(zoom, false);
794 pii->SetGloVWin(gimv, false);
795 pii->SetCMapWin(cmapv, false);
796 pii->ShowCursor(true);
797 pii->SetUserData(NULL, oid);
798}
799
800
801pii->SetImage(nouv, true, false);
802
803// decode des options en chaine de caracteres
804if (mAxesAtt.size() > 0)
805 pii->DecodeOptionString(mAxesAtt, false); // Les options d'axe
806if (mDefaultAtt.size() > 0)
807 pii->DecodeOptionString(mDefaultAtt, false); // d'abord les options par defaut
808if (opts.size() > 0)
809 pii->DecodeOptionString(opts); // ensuite, les options specifies en argument
810
811// On recalcule la taille de la fenetre si Disp_Win
812if (dwopt == Disp_Win) {
813 int sx2 = (int)((float)nouv->XSize()*pii->GetZoomF());
814 int sy2 = (int)((float)nouv->YSize()*pii->GetZoomF());
815
816 if (sx2 > 400+mFgScSz*100) sx2 = 400+mFgScSz*100;
817 if (sy2 > 400+mFgScSz*100) sy2 = 400+mFgScSz*100;
818 if (sx2 < MINPIIMGSIZE) sx = MINPIIMGSIZE;
819 if (sy2 < MINPIIMGSIZE) sy = MINPIIMGSIZE;
820 if ((sx2 != sx) || (sy2 != sy)) win->SetSize(sx2, sy2);
821}
822
823// printf("!!DBG!! PIImage Pos= %d %d Size= %d %d \n", pii->XPos(), pii->YPos(), pii->XSize(), pii->YSize() );
824mCurWin = win;
825mCurWdg = pii;
826mLastWdg = pii;
827mBWId++;
828if (fgimagnav) mBWList[mBWId] = piin;
829else mBWList[mBWId] = pii;
830// pii->Refresh();
831 pii->Apply(true);
832 // cmapv->Refresh(); Pas besoin ? , Reza Fev 2005
833return(mBWId);
834}
835
836
837/* --Methode-- */
838int PIStdImgApp::DispScDrawer(PIDrawer* scd, string const & name, string const& sop,
839 string title, int oid, bool fglock)
840{
841if (scd == NULL)
842 {
843 printf("PIStdImgApp::DispScDrawer_Error Cannot Add NULL ScDrawer \n");
844 return(-1);
845 }
846
847// On decode les options graphiques
848vector<string> opts;
849DispWinEnum dwopt = ParseDisplayOption(sop, opts);
850if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
851
852// <ZThread> global PIApplication event loop synchronisation
853SyncPIS zs(getMutex(), fglock, 2);
854
855// Trace en superpoistion
856if ( (dwopt == Disp_Same) && (mLastWdg) ) {
857 // Les options
858 scd->DecodeOptionString(mDefaultAtt, false);
859 if (nb_disp_same > 0) {
860 vector<string> ostatpos;
861 int spo = nb_disp_same%4;
862 if (spo == 1) ostatpos.push_back("statposoff=-0.01,-0.26");
863 else if (spo == 2) ostatpos.push_back("statposoff=-0.36,-0.01");
864 else ostatpos.push_back("statposoff=-0.36,-0.26");
865 scd->DecodeOptionString(ostatpos, true);
866 }
867 scd->DecodeOptionString(opts, true);
868
869 if (mLastWdg->kind() == PIScDrawWdg::ClassId) ((PIScDrawWdg*)mLastWdg)->AddScDrawer(scd, true);
870 else mLastWdg->AddDrawer(scd, true, true, true);
871 scd->Refresh();
872 mDId++;
873 mDrwList[mDId] = scd;
874 return(-mDId);
875}
876// Trace en medaillon
877else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
878 PIGrCoord x1, x2, y1, y2;
879 x1 = mIXmin; x2 = mIXmax;
880 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
881 // Les options
882 scd->DecodeOptionString(mDefaultAtt, false);
883 scd->DecodeOptionString(opts, true);
884
885 scd->SetAxesFlags(mAxesFlags);
886 scd->UpdateLimits();
887 mLastWdg->AddDrawer(scd, x1, y1, x2, y2, true, false, true);
888 scd->Refresh();
889 mDId++;
890 mDrwList[mDId] = scd;
891 return(-mDId);
892}
893
894// Creation d'un nouveau PIScDrawWdg
895PIWindow* win;
896PIScDrawWdg* scw;
897int sx, sy, px, py, flag;
898sx = 200+mFgScSz*100;
899sy = 200+mFgScSz*100;
900win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
901
902scw = new PIScDrawWdg(win, (char *)name.c_str(), sx, sy, px, py);
903scw->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
904scw->SetUserData(NULL, oid);
905
906// Decodage des options :
907vector<string> scwatt;
908scw->SetAxesFlags(mAxesFlags);
909if ( mDefaultAtt.size() > 0) {
910 scwatt = mDefaultAtt;
911 scd->DecodeOptionString(scwatt, true);
912 scw->DecodeOptionString(scwatt, true);
913}
914if ( mAxesAtt.size() > 0) {
915 scwatt = mAxesAtt;
916 scw->DecodeOptionString(scwatt, true);
917}
918if (opts.size() > 0)
919 scd->DecodeOptionString(opts, true);
920if (opts.size() > 0)
921 scw->DecodeOptionString(opts, false);
922
923// Titre du plot
924if (mAddTitle) {
925 if (title.length() <= 0) title = name; string t2="";
926 scw->SetTitles(title, t2);
927}
928
929scw->AddScDrawer(scd, true);
930// scw->Refresh(); ? Pas necessaire Reza 19/08/98, 05/05/99 $CHECK$
931
932mCurWin = win;
933mCurWdg = scw;
934mLastWdg = scw;
935mBWId++;
936mBWList[mBWId] = scw;
937return(mBWId);
938}
939
940/* --Methode-- */
941int PIStdImgApp::Disp3DDrawer(PIDrawer3D* dr3, string const & name, string const& sop,
942 string title, int oid, bool fglock)
943{
944if (dr3 == NULL)
945 {
946 printf("PIStdImgApp::Disp3DDrawer_Error Cannot Add NULL 3DDrawer \n");
947 return(-1);
948 }
949
950// On decode les options graphiques
951vector<string> opts;
952DispWinEnum dwopt = ParseDisplayOption(sop, opts);
953
954if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
955
956// <ZThread> global PIApplication event loop synchronisation
957SyncPIS zs(getMutex(), fglock, 2);
958
959// Trace en superpoistion
960if ( (dwopt == Disp_Same) && (mLastWdg) ) {
961 // Les options
962 dr3->DecodeOptionString(mDefaultAtt, false);
963 if (nb_disp_same > 1) {
964 vector<string> ostatpos;
965 int spo = nb_disp_same%4;
966 if (spo == 1) ostatpos.push_back("statposoff=-0.01,-0.26");
967 else if (spo == 2) ostatpos.push_back("statposoff=-0.36,-0.01");
968 else ostatpos.push_back("statposoff=-0.36,-0.26");
969 dr3->DecodeOptionString(ostatpos, true);
970 }
971
972 dr3->DecodeOptionString(opts, true);
973
974 if (mLastWdg->kind() == PIDraw3DWdg::ClassId) ((PIDraw3DWdg*)mLastWdg)->AddDrawer3D(dr3, true);
975 else mLastWdg->AddDrawer(dr3, true, true, true);
976 dr3->Refresh();
977 mDId++;
978 mDrwList[mDId] = dr3;
979 return(-mDId);
980}
981// Trace en medaillon
982else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
983 PIGrCoord x1, x2, y1, y2;
984 x1 = mIXmin; x2 = mIXmax;
985 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
986 // Les options
987 dr3->DecodeOptionString(mDefaultAtt, false);
988 dr3->DecodeOptionString(opts, true);
989
990 dr3->SetAxesFlags(mAxesFlags);
991 dr3->UpdateLimits();
992 mLastWdg->AddDrawer(dr3, x1, y1, x2, y2, true, false, true);
993 dr3->Refresh();
994 mDId++;
995 mDrwList[mDId] = dr3;
996 return(-mDId);
997}
998
999
1000PIWindow* win;
1001int sx, sy, px, py, flag;
1002sx = 200+mFgScSz*100;
1003sy = 200+mFgScSz*100;
1004win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
1005PIDraw3DWdg* wd3 = new PIDraw3DWdg(win, (char *)name.c_str(), sx, sy, px, py);
1006wd3->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
1007wd3->SetUserData(NULL, oid);
1008
1009// Decodage des options :
1010vector<string> scwatt;
1011// wd3->SetAxesFlags(mAxesFlags); Attributs d'axes 3D a faire
1012if ( mDefaultAtt.size() > 0) {
1013 scwatt = mDefaultAtt;
1014 dr3->DecodeOptionString(scwatt, true);
1015 wd3->DecodeOptionString(scwatt, true);
1016}
1017if ( mAxesAtt.size() > 0) {
1018 scwatt = mAxesAtt;
1019 wd3->DecodeOptionString(scwatt, true);
1020}
1021if (opts.size() > 0)
1022 dr3->DecodeOptionString(opts, true);
1023if (opts.size() > 0)
1024 wd3->DecodeOptionString(opts, false);
1025
1026// Titre du plot
1027if (mAddTitle) {
1028 if (title.length() <= 0) title = name; string t2="";
1029 wd3->SetTitles(title, t2);
1030}
1031
1032wd3->AddDrawer3D(dr3, true);
1033// wd3->Refresh(); ?Pas necessaire $CHECK$ 05/05/99
1034
1035mCurWin = win;
1036mCurWdg = wd3;
1037mLastWdg = wd3;
1038mBWId++;
1039mBWList[mBWId] = wd3;
1040return(mBWId);
1041}
1042
1043// RZDEL: Normalement, il ne devrait plus y avoir besoin de cette
1044// methode avec le thread separe de l'interpreteur - Reza 27/12/2003
1045/* --Methode-- */
1046int PIStdImgApp::ExecuteExtCommand()
1047{
1048if (!fg_exc_cmd) return(0);
1049else {
1050 fg_exc_cmd = false;
1051 return CmdInterpreter()->Interpret(exc_command);
1052 }
1053}
1054
1055/* --Methode-- */
1056void PIStdImgApp::AddText(string const & txt, double xp, double yp, string const& sop, bool fgcn)
1057{
1058// <ZThread> global PIApplication event loop synchronisation
1059ZSync zs(thr_glsyn, 2); zs.NOp();
1060
1061PIDrawer *eld=CurrentElDrawer();
1062if (eld == NULL) return;
1063PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1064PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1065if ((eld2 == NULL) && (eld3 == NULL)) return;
1066PIElDrwMgr* elmgr;
1067if (eld2) elmgr = &(eld2->ElDrwMgr());
1068else if (eld3) elmgr = &(eld3->ElDrwMgr());
1069if (elmgr == NULL) return;
1070
1071vector<string> opts;
1072ParseDisplayOption(sop, opts);
1073PIGraphicAtt gratt(opts);
1074unsigned long tpd = 0;
1075gratt.DecodeTextPosDirAtt(opts, tpd, false);
1076elmgr->ElAddText(xp,yp,txt.c_str(), gratt, tpd, fgcn);
1077eld->Refresh();
1078}
1079
1080/* --Methode-- */
1081void PIStdImgApp::AddCompText(string const & txt, string const & txtup, string const & txtdn,
1082 double xp, double yp, string const& sop,
1083 string const& optss, bool fgcn)
1084{
1085// <ZThread> global PIApplication event loop synchronisation
1086ZSync zs(thr_glsyn, 2); zs.NOp();
1087
1088PIDrawer *eld=CurrentElDrawer();
1089if (eld == NULL) return;
1090PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1091PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1092if ((eld2 == NULL) && (eld3 == NULL)) return;
1093PIElDrwMgr* elmgr;
1094if (eld2) elmgr = &(eld2->ElDrwMgr());
1095else if (eld3) elmgr = &(eld3->ElDrwMgr());
1096if (elmgr == NULL) return;
1097
1098vector<string> opts;
1099ParseDisplayOption(sop, opts);
1100PIGraphicAtt gratt(opts);
1101unsigned long tpd = 0;
1102gratt.DecodeTextPosDirAtt(opts, tpd, false);
1103ParseDisplayOption(optss, opts);
1104PIGraphicAtt grattss(opts);
1105elmgr->ElAddCompText(xp,yp,txt.c_str(), gratt, txtup, txtdn, grattss, tpd, fgcn);
1106eld->Refresh();
1107}
1108
1109/* --Methode-- */
1110void PIStdImgApp::AddLine(double xp1, double yp1, double xp2, double yp2,
1111 string const& sop, bool fgarrow, bool fgcn)
1112{
1113// <ZThread> global PIApplication event loop synchronisation
1114ZSync zs(thr_glsyn, 2); zs.NOp();
1115
1116PIDrawer *eld=CurrentElDrawer();
1117if (eld == NULL) return;
1118PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1119PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1120if ((eld2 == NULL) && (eld3 == NULL)) return;
1121PIElDrwMgr* elmgr = NULL;
1122if (eld2) elmgr = &(eld2->ElDrwMgr());
1123else if (eld3) elmgr = &(eld3->ElDrwMgr());
1124if (elmgr == NULL) return;
1125
1126vector<string> opts;
1127ParseDisplayOption(sop, opts);
1128PIGraphicAtt gratt(opts);
1129if (fgarrow)
1130 elmgr->ElAddArrow(xp1, yp1, xp2, yp2, gratt, fgcn);
1131else elmgr->ElAddLine(xp1, yp1, xp2, yp2, gratt, fgcn);
1132eld->Refresh();
1133}
1134
1135/* --Methode-- */
1136void PIStdImgApp::AddRectangle(double xp1, double yp1, double xp2, double yp2,
1137 string const& sop, bool fgfill, bool fgcn)
1138{
1139// <ZThread> global PIApplication event loop synchronisation
1140ZSync zs(thr_glsyn, 2); zs.NOp();
1141
1142PIDrawer *eld=CurrentElDrawer();
1143if (eld == NULL) return;
1144PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1145PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1146if ((eld2 == NULL) && (eld3 == NULL)) return;
1147PIElDrwMgr* elmgr = NULL;
1148if (eld2) elmgr = &(eld2->ElDrwMgr());
1149else if (eld3) elmgr = &(eld3->ElDrwMgr());
1150
1151double xp,yp;
1152double dx, dy;
1153if (xp1 < xp2) {
1154 xp = xp1; dx = xp2-xp1;
1155}
1156else {
1157 xp = xp2; dx = xp1-xp2;
1158}
1159if (yp1 < yp2) {
1160 yp = yp1; dy = yp2-yp1;
1161}
1162else {
1163 yp = yp2; dy = yp1-yp2;
1164}
1165
1166vector<string> opts;
1167ParseDisplayOption(sop, opts);
1168PIGraphicAtt gratt(opts);
1169
1170if (fgfill) elmgr->ElAddFRect(xp, yp, dx, dy, gratt, fgcn);
1171else elmgr->ElAddRect(xp, yp, dx, dy, gratt, fgcn);
1172eld->Refresh();
1173}
1174
1175/* --Methode-- */
1176void PIStdImgApp::AddCircle(double xc, double yc, double r, string const& sop,
1177 bool fgfill, bool fgcn)
1178{
1179// <ZThread> global PIApplication event loop synchronisation
1180ZSync zs(thr_glsyn, 2); zs.NOp();
1181
1182PIDrawer *eld=CurrentElDrawer();
1183if (eld == NULL) return;
1184PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1185PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1186if ((eld2 == NULL) && (eld3 == NULL)) return;
1187PIElDrwMgr* elmgr = NULL;
1188if (eld2) elmgr = &(eld2->ElDrwMgr());
1189else if (eld3) elmgr = &(eld3->ElDrwMgr());
1190
1191vector<string> opts;
1192ParseDisplayOption(sop, opts);
1193PIGraphicAtt gratt(opts);
1194if (r < -0.5)
1195 elmgr->ElAddMarker(xc, yc, gratt);
1196else {
1197 if (fgfill) elmgr->ElAddFCirc(xc, yc, r, gratt, fgcn);
1198 else elmgr->ElAddCirc(xc, yc, r, gratt, fgcn);
1199}
1200eld->Refresh();
1201}
1202/* --Methode-- */
1203void PIStdImgApp::AddOval(double xp, double yp, double dx, double dy,
1204 string const& sop, bool fgfill, bool fgcn)
1205{
1206// <ZThread> global PIApplication event loop synchronisation
1207ZSync zs(thr_glsyn, 2); zs.NOp();
1208
1209PIDrawer *eld=CurrentElDrawer();
1210if (eld == NULL) return;
1211PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1212PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1213if ((eld2 == NULL) && (eld3 == NULL)) return;
1214PIElDrwMgr* elmgr = NULL;
1215if (eld2) elmgr = &(eld2->ElDrwMgr());
1216else if (eld3) elmgr = &(eld3->ElDrwMgr());
1217
1218
1219vector<string> opts;
1220ParseDisplayOption(sop, opts);
1221PIGraphicAtt gratt(opts);
1222
1223if (fgfill) elmgr->ElAddFOval(xp, yp, dx, dy, gratt, fgcn);
1224else elmgr->ElAddOval(xp, yp, dx, dy, gratt, fgcn);
1225eld->Refresh();
1226}
1227
1228/* --Methode-- */
1229void PIStdImgApp::AddArc(double xc, double yc, double r, double a, double da,
1230 string const& sop, bool fgfill, bool fgcn)
1231{
1232// <ZThread> global PIApplication event loop synchronisation
1233ZSync zs(thr_glsyn, 2); zs.NOp();
1234
1235PIDrawer *eld=CurrentElDrawer();
1236if (eld == NULL) return;
1237PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1238PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1239if ((eld2 == NULL) && (eld3 == NULL)) return;
1240PIElDrwMgr* elmgr = NULL;
1241if (eld2) elmgr = &(eld2->ElDrwMgr());
1242else if (eld3) elmgr = &(eld3->ElDrwMgr());
1243
1244vector<string> opts;
1245ParseDisplayOption(sop, opts);
1246PIGraphicAtt gratt(opts);
1247if (fgfill) elmgr->ElAddFArc(xc, yc, r, a, da, gratt, fgcn);
1248else elmgr->ElAddArc(xc, yc, r, a, da, gratt, fgcn);
1249eld->Refresh();
1250}
1251
1252/* --Methode-- */
1253void PIStdImgApp::AddArc(double x1, double y1, double x2, double y2,
1254 double x3, double y3, string const& sop, bool fgfill, bool fgcn)
1255{
1256// <ZThread> global PIApplication event loop synchronisation
1257ZSync zs(thr_glsyn, 2); zs.NOp();
1258
1259PIDrawer *eld=CurrentElDrawer();
1260if (eld == NULL) return;
1261PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1262PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1263if ((eld2 == NULL) && (eld3 == NULL)) return;
1264PIElDrwMgr* elmgr = NULL;
1265if (eld2) elmgr = &(eld2->ElDrwMgr());
1266else if (eld3) elmgr = &(eld3->ElDrwMgr());
1267if (elmgr == NULL) return;
1268
1269vector<string> opts;
1270ParseDisplayOption(sop, opts);
1271PIGraphicAtt gratt(opts);
1272if (fgfill)
1273 elmgr->ElAddFArc(x1, y1, x2, y2, x3, y3, gratt, fgcn);
1274else elmgr->ElAddArc(x1, y1, x2, y2, x3, y3, gratt, fgcn);
1275eld->Refresh();
1276}
1277
1278/* --Methode-- */
1279void PIStdImgApp::AddPoly(vector<double>& xpol, vector<double>& ypol,
1280 string const& sop, bool fgfill, bool fgcn)
1281{
1282// <ZThread> global PIApplication event loop synchronisation
1283ZSync zs(thr_glsyn, 2); zs.NOp();
1284
1285PIDrawer *eld=CurrentElDrawer();
1286if (eld == NULL) return;
1287PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1288PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1289if ((eld2 == NULL) && (eld3 == NULL)) return;
1290PIElDrwMgr* elmgr = NULL;
1291if (eld2) elmgr = &(eld2->ElDrwMgr());
1292else if (eld3) elmgr = &(eld3->ElDrwMgr());
1293if (elmgr == NULL) return;
1294
1295vector<string> opts;
1296ParseDisplayOption(sop, opts);
1297PIGraphicAtt gratt(opts);
1298if (fgfill)
1299 elmgr->ElAddFPoly(xpol, ypol, gratt, fgcn);
1300else elmgr->ElAddPoly(xpol, ypol, gratt, fgcn);
1301eld->Refresh();
1302
1303}
1304
1305
1306/* --Methode-- */
1307void PIStdImgApp::SetTitle(string const & titletop, string const & titlebottom, string const& sop)
1308{
1309// <ZThread> global PIApplication event loop synchronisation
1310ZSync zs(thr_glsyn, 2); zs.NOp();
1311
1312PIDrawer *eld=CurrentElDrawer();
1313if (eld == NULL) return;
1314PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1315PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1316if ((eld2 == NULL) && (eld3 == NULL)) return;
1317
1318vector<string> opts;
1319ParseDisplayOption(sop, opts);
1320PIGraphicAtt gratt(opts);
1321
1322if (eld2) {
1323 eld2->SetTitles(titletop, titlebottom, gratt);
1324 eld2->ShowTitles(true);
1325}
1326else if (eld3) {
1327 eld3->SetTitles(titletop, titlebottom, gratt);
1328 eld3->ShowTitles(true);
1329}
1330eld->Refresh();
1331}
1332/* --Methode-- */
1333void PIStdImgApp::SetAxeLabels(string const & xLabel, string const & yLabel, string const& sop)
1334{
1335// <ZThread> global PIApplication event loop synchronisation
1336ZSync zs(thr_glsyn, 2); zs.NOp();
1337
1338PIDrawer *eld=CurrentElDrawer();
1339if (eld == NULL) return;
1340PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1341if (eld2 == NULL) return;
1342
1343vector<string> opts;
1344ParseDisplayOption(sop, opts);
1345PIGraphicAtt gratt(opts);
1346
1347eld2->SetAxesLabels(xLabel, yLabel, gratt);
1348eld2->ShowAxesLabels(true);
1349
1350eld->Refresh();
1351}
1352
1353/* --Methode-- */
1354PIDrawer* PIStdImgApp::CurrentElDrawer()
1355{
1356PIDrawer *eld=NULL;
1357if (!mLastWdg) return(eld);
1358PIScDrawWdg* sdw=NULL;
1359PIDraw3DWdg* w3d=NULL;
1360PIImage* imgw;
1361switch(mLastWdg->kind()) {
1362 case PIScDrawWdg::ClassId :
1363 sdw = dynamic_cast<PIScDrawWdg *>(mLastWdg);
1364 if (sdw) eld = sdw->BaseDrawer();
1365 break;
1366 case PIDraw3DWdg::ClassId :
1367 w3d = dynamic_cast<PIDraw3DWdg *>(mLastWdg);
1368 if (w3d) eld = w3d->BaseDrawer();
1369 break;
1370 case PIImage::ClassId :
1371 imgw = dynamic_cast<PIImage *>(mLastWdg);
1372 if (imgw) eld = imgw->BaseDrawer();
1373 break;
1374 default :
1375 break;
1376 }
1377return(eld);
1378}
1379
1380/* --Methode-- */
1381void PIStdImgApp::CreateGraphWin(int nx, int ny, int sx, int sy)
1382{
1383if (nx < 1) nx = 1;
1384if (ny < 1) ny = 1;
1385if (nx > 8) nx = 8;
1386if (ny > 8) ny = 8;
1387if ( (sx < 50) && (sy < 50) ) sx = sy = 400+mFgScSz*100;
1388char buff[64];
1389mWId++;
1390int px, py;
1391MainWin()->GetScreenPos(px, py);
1392sprintf(buff, "PI-GraphicWin (%d)",mWId);
1393PIZoneWindow* win = new PIZoneWindow(this, buff, PIWK_normal, nx, ny, sx, sy, px+MainWin()->XSize()+30, 0);
1394win->SetUserData(NULL, ny*10+nx); // UserFlag= nY*10 + nX
1395mWList[mWId*10+1] = (PIWindow*)win;
1396win->SetAutoDelChilds(true);
1397// win->Show();
1398mGrW = win;
1399mGrIdx = 0;
1400}
1401
1402/* --Methode-- */
1403void PIStdImgApp::CreateStackWin(int sx, int sy)
1404{
1405if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
1406char buff[64];
1407mWId++;
1408int px, py;
1409MainWin()->GetScreenPos(px, py);
1410sprintf(buff, "PI-StackWin (%d)",mWId);
1411PIStackWindow* win = new PIStackWindow(this, buff, PIWK_normal, sx, sy, px+MainWin()->XSize()+30, 100);
1412win->SetUserData(NULL, 9999); // UserFlag= 9999
1413mWList[mWId*10+2] = (PIWindow*)win;
1414win->SetAutoDelChilds(true);
1415// win->Show();
1416mStW = win;
1417m[2]->SetSensitivity("StackTools", true);
1418mStIdx = 0;
1419}
1420
1421/* --Methode-- */
1422PIWindow* PIStdImgApp::GetWindow(DispWinEnum typ, int& sx, int& sy, int& px, int& py, int& flag, char * nom)
1423{
1424PIWindow* rw;
1425
1426switch (typ) {
1427 case Disp_Next : // Fenetre graphique courante
1428 case Disp_Default :
1429 {
1430 if (mGrW == NULL) CreateGraphWin();
1431 int nx, ny;
1432 mGrW->NbZone(nx, ny);
1433 PIWdg* nw = mGrW->NextChildPosSize(px, py, sx, sy);
1434// cerr << "**DBG** PIStdImgApp::GetWindow() DispNext : nw = " << (long)nw << endl;
1435 if (nw) DeleteWidget(nw, false, false);
1436 flag = mGrIdx;
1437 mGrIdx = (mGrIdx+1)%(nx*ny);
1438 rw = mGrW;
1439 break;
1440 }
1441
1442 case Disp_Stack : // Fenetre de type stack (empilement)
1443 {
1444 if (mStW == NULL) CreateStackWin(sx, sy);
1445 px = py = 0;
1446 sx = mStW->XSize();
1447 sy = mStW->YSize();
1448 flag = mStIdx;
1449 mStIdx++;
1450 rw = mStW;
1451 }
1452 break;
1453
1454 default : // Fenetre ordinaire
1455 {
1456 int pwx, pwy;
1457 MainWin()->GetScreenPos(pwx, pwy);
1458 if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
1459 rw = new PIWindow(this, nom, PIWK_normal, sx, sy, pwx+MainWin()->XSize()+30, 300);
1460 rw->SetUserData(NULL, 0); // UserFlag= 0
1461 mWId++;
1462 mWList[mWId*10] = rw;
1463 rw->SetAutoDelChilds(true);
1464 // rw->Show();
1465 px = py = 0;
1466 flag = 0;
1467 break;
1468 }
1469 }
1470
1471rw->Show();
1472mCurWin = rw;
1473return(rw);
1474}
1475
1476/* --Methode-- */
1477void PIStdImgApp::SetZone(int nzx, int nzy)
1478{
1479if (!mGrW) CreateGraphWin(nzx, nzy);
1480else {
1481 int k;
1482 PIWdg* cwd;
1483 for(k=0; k<mGrW->NbChilds(); k++) {
1484 if ((cwd = mGrW->GetChild(k)) == NULL) continue;
1485 DeleteWidget(cwd, false, false);
1486 }
1487 mGrW->SetZone(nzx, nzy);
1488 }
1489}
1490
1491/* --Methode-- */
1492void PIStdImgApp::StackWinNext()
1493{
1494if (mStW) mStW->DispNext();
1495}
1496
1497/* --Methode-- */
1498void PIStdImgApp::DeleteWindow(PIWindow* w)
1499{
1500if (w == NULL) return;
1501w->Hide();
1502bool ownwindow=false; // To Check if this is one of our windows
1503WindMList::iterator it;
1504for(it = mWList.begin(); it != mWList.end(); it++)
1505 if ((*it).second == w) { mWList.erase(it); ownwindow = true; break; }
1506if (w == mGrW) { mGrW = NULL; mGrIdx = -1; }
1507if (w == mStW) { mStW = NULL; mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
1508if (w == mCurWin) mCurWin = NULL;
1509
1510if (!ownwindow) return; // We do nothing if this is not a window we have created ...
1511
1512int k;
1513PIWdg* cwd;
1514for(k=0; k<w->NbChilds(); k++) {
1515 if ((cwd = w->GetChild(k)) == NULL) continue;
1516 DeleteWidget(cwd,false,false);
1517 }
1518delete w;
1519return;
1520}
1521
1522/* --Methode-- */
1523void PIStdImgApp::DeleteWidget(PIWdg* w, bool dw, bool dwin)
1524{
1525if (w == NULL) return;
1526BWMList::iterator it;
1527for(it = mBWList.begin(); it != mBWList.end(); it++)
1528 if ((*it).second == w) { mBWList.erase(it); break; }
1529PIBaseWdg* bw = NULL;
1530if (w->kind() == PIImageNavigator::ClassId) {
1531 PIImageNavigator* piin = dynamic_cast<PIImageNavigator *>(w);
1532 if (piin) bw = piin->ImageWdg();
1533}
1534else bw = dynamic_cast<PIBaseWdg *>(w);
1535if (bw != NULL) {
1536 PIDrawer* drw;
1537 int k;
1538 for(k=0; k<bw->NbDrawers(); k++) {
1539 if ((drw = bw->GetDrawer(k)) == NULL) continue;
1540 DrwMList::iterator itt;
1541 for(itt = mDrwList.begin(); itt != mDrwList.end(); itt++)
1542 if ((*itt).second == drw) { mDrwList.erase(itt); break; }
1543 }
1544}
1545
1546if ( (w == mCurWdg) || (bw == mCurWdg) ) {
1547 mCurWdg = NULL;
1548 if (mFgCWImg) {
1549 m[4]->SetSensitivityMsg(10515, false);
1550 m[4]->SetSensitivityMsg(10516, false);
1551 mFgCWImg = false;
1552 }
1553 }
1554
1555if ( (w == mLastWdg) || (bw == mLastWdg) ) mLastWdg = NULL;
1556
1557PIWdg* pw=NULL;
1558pw = (PIWdg*)(w->Parent());
1559//DBG printf("DeleteWidget(%lx)-DBG kind = %d - %d %d \n", (long)w, w->kind(), (int)dw, (int)dwin);
1560if (dw) delete w;
1561
1562if (dwin && pw) {
1563 PIWindow* pww = dynamic_cast<PIWindow *>(pw);
1564 if (pww && (pww != (PIWindow*)mGrW) && (pww != (PIWindow*)mStW) && (pww->NbChilds()==0))
1565 DeleteWindow((PIWindow*)pw);
1566 }
1567return;
1568}
1569
1570
1571
1572/* --Methode-- */
1573void PIStdImgApp::DelWRsId(int k)
1574{
1575//DBG cerr << "-DBG- PIStdImgApp::DelWRsId(" << k << ")" << endl;
1576if (k > 0) { // C'est un BaseWidget
1577 BWMList::iterator it;
1578 it = mBWList.find(k);
1579 if (it == mBWList.end()) return;
1580 PIWdg* wd = (*it).second;
1581//DBG cerr << "-DBG- PIStdImgApp::DelWRsId Deleting BaseWidget " << (long)(wd) << endl ;
1582 DeleteWidget(wd, true, true);
1583 }
1584else { // C'est un drawer
1585 DrwMList::iterator it;
1586 it = mDrwList.find(-k);
1587 if (it == mDrwList.end()) return;
1588 (*it).second->SetAutoRefreshOnDelete(true);
1589 delete (*it).second;
1590 mDrwList.erase(it);
1591 //DBG cerr << "+DBG+ PIStdImgApp::DelWRsId Deleting Drawer " << (long)((*it).second) << endl ;
1592 }
1593}
1594/* --Methode-- */
1595bool PIStdImgApp::CheckWRsId(int k)
1596{
1597if (k > 0) { // C'est un BaseWidget
1598 BWMList::iterator it;
1599 it = mBWList.find(k);
1600 if (it == mBWList.end()) return(false);
1601 else return(true);
1602 }
1603else { // C'est un drawer
1604 DrwMList::iterator it;
1605 it = mDrwList.find(-k);
1606 if (it == mDrwList.end()) return(false);
1607 else return(true);
1608 }
1609}
1610
1611/* --Methode-- */
1612void PIStdImgApp::StatZoomWindowSetVisible(bool fg)
1613{
1614
1615 if (fg) {
1616 consolecont->Hide();
1617 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1618 int szy = MainWin()->YSize();
1619 MainWin()->SetSize(MainWin()->XSize(), szy+statcont->YSize());
1620 consolecont->SetPos(0, statcont->YSize());
1621 consolecont->SetSize(MainWin()->XSize(), szy);
1622 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
1623 consolecont->Show();
1624 statcont->Show();
1625 m[3]->SetStateMsg(10470, true);
1626 }
1627 else {
1628 statcont->Hide();
1629 consolecont->Hide();
1630 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1631 MainWin()->SetSize(MainWin()->XSize(), MainWin()->YSize()-statcont->YSize());
1632 consolecont->SetPos(0, 0);
1633 consolecont->SetSize(MainWin()->XSize(), MainWin()->YSize());
1634 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
1635 consolecont->Show();
1636 m[3]->SetStateMsg(10470, false);
1637 }
1638
1639}
1640
1641/* --Methode-- */
1642void PIStdImgApp::UpdateStatResourceInfo()
1643{
1644 resusg.Update();
1645 char buff[256];
1646 string lab;
1647 double frac;
1648 sprintf(buff, "Mem: %ld/Max= %ld kb" , (long)resusg.getMemorySize(),
1649 (long)resusg.getMaxMemorySize());
1650 lab = buff;
1651 lab_mem->SetLabel(lab);
1652 frac = (double)resusg.getMemorySize()/(double)resusg.getMaxMemorySize();
1653 therm_mem->SetValue(frac);
1654
1655 sprintf(buff, "CPU: %ld/elap= %ld ms" , (long)resusg.getCPUTime(),
1656 (long)resusg.getElapsedTime());
1657 lab = buff;
1658 lab_cpu->SetLabel(lab);
1659 if (resusg.getCPULoad() > resusg.getAverageCPULoad())
1660 therm_cpu->SetValue(resusg.getCPULoad());
1661 else
1662 therm_cpu->SetValue(resusg.getAverageCPULoad());
1663 int nlx = 0;
1664 bool fgx = false;
1665 if ( CmdInterpreter() ) fgx = CmdInterpreter()->isRunning(nlx);
1666 if (!fgx) {
1667 lab = "PIACmdThread Idle";
1668 lab_thrcmd->SetLabel(lab);
1669 lab_thrcmd->SetForegroundColor(PI_Green);
1670 }
1671 else {
1672 sprintf(buff, "PIACmdThread Running - NL=%d" , nlx);
1673 lab = buff;
1674 lab_thrcmd->SetLabel(lab);
1675 if (nlx < 3) lab_thrcmd->SetForegroundColor(PI_Yellow);
1676 else lab_thrcmd->SetForegroundColor(PI_Red);
1677 }
1678}
1679
1680/* --Methode-- */
1681void PIStdImgApp::RedirectStdOutErr(bool fg)
1682{
1683if (fg) {
1684 RedirectOutStream(mCons);
1685 RedirectErrStream(mCons);
1686 m[5]->SetStateMsg(10602, true);
1687 redirecout = true;
1688 }
1689else {
1690 RedirectOutStream(NULL);
1691 RedirectErrStream(NULL);
1692 m[5]->SetStateMsg(10602, false);
1693 redirecout = false;
1694 }
1695return;
1696}
1697
1698/* --Methode-- */
1699void PIStdImgApp::CatchSignals(bool fgfpe, bool fgsegv)
1700{
1701#ifdef SANS_EVOLPLANCK
1702PeidaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1703#else
1704// On active aussi SIGUSR1 pour stopthr
1705SophyaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1706#endif
1707m[5]->SetStateMsg(10603, fgfpe);
1708m[5]->SetStateMsg(10604, fgsegv);
1709}
1710
1711/* --Methode-- */
1712void PIStdImgApp::CloseAllWindows()
1713{
1714WindMList::iterator it;
1715for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
1716mWList.clear();
1717mBWList.clear();
1718mDrwList.clear();
1719mGrW = NULL;
1720mStW = NULL;
1721mCurWin = NULL;
1722mCurWdg = NULL;
1723mLastWdg = NULL;
1724m[4]->SetSensitivityMsg(10515, false);
1725m[4]->SetSensitivityMsg(10516, false);
1726}
1727
1728//---------------------------------------------------------------------------
1729//--------- Gestion des attributs graphiques et autres options de trace -----
1730
1731/* --Methode-- */
1732void PIStdImgApp::SetInsetLimits(double xmin, double xmax, double ymin, double ymax)
1733{
1734 mIXmin = xmin; mIXmax= xmax;
1735 mIYmin = ymin; mIYmax= ymax;
1736}
1737
1738/* --Methode-- */
1739void PIStdImgApp::SetDefaultGraphicAttributes(string const & opt)
1740{
1741 ParseDisplayOption(opt, mDefaultAtt);
1742}
1743
1744/* --Methode-- */
1745void PIStdImgApp::SetDefaultAxesAttributes(string const & opt)
1746{
1747 ParseDisplayOption(opt, mAxesAtt);
1748}
1749
1750/* --Methode-- */
1751DispWinEnum PIStdImgApp::ParseDisplayOption(string const & sop, vector<string>& opts)
1752{
1753 DispWinEnum rc = Disp_Next;
1754 //DBG cerr << " DBG-Parse-A sop=" << sop << " sop.length()= " << sop.length() << endl;
1755 if (opts.size() > 0) opts.erase(opts.begin(), opts.end());
1756 if (sop.length() < 1) return(rc);
1757 string gratt = sop;
1758 for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1759 if ( (gratt == "def") || (gratt == "default") ) return(rc);
1760// On separe en mots espaces par des blancs ou tabulation
1761 size_t p = 0;
1762 size_t q = 0;
1763 size_t l = gratt.length();
1764 string token;
1765 while (q < l) {
1766 p = gratt.find_first_not_of(" \t",q); // au debut d'un token
1767 if (p >= l) break;
1768 q = gratt.find_first_of(" \t",p); // Premier blanc ou tab suivant
1769 if (q<l) token = gratt.substr(p,q-p);
1770 else token = gratt.substr(p);
1771 if (token == "") continue;
1772 // Decodage option fenetre d'affichage (win, next, ...)
1773 if (token == "win") rc = Disp_Win;
1774 else if (token == "same") rc = Disp_Same;
1775 else if (token == "inset") rc = Disp_Inset;
1776 else if (token == "stack") rc = Disp_Stack;
1777 else if (token == "next") rc = Disp_Next;
1778 // Option a etre decode par les drawers, etc ...
1779 else opts.push_back(token);
1780 }
1781
1782 //DBG cerr << " DBG-Parse-B opts.size()=" << opts.size() << endl;
1783 if (rc == Disp_Same) nb_disp_same++;
1784 else nb_disp_same = 0;
1785 return (rc);
1786}
1787
1788//---------------------------------------------------------------------------
1789//------------ Methodes privees (MBProcessx, ...) ----------
1790
1791/* --Methode-- */
1792void PIStdImgApp::MBProcess1(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1793{
1794
1795 switch(msg)
1796 {
1797 case 10150 :
1798 showInfoWindow(this);
1799 break;
1800
1801 case 10155 :
1802 hideInfoWindow(this);
1803 break;
1804
1805 case 10100 :
1806 CmdInterpreter()->ShowHelpWindow();
1807 break;
1808
1809 case 10120 :
1810 pfc_fits->AcceptNewFile(false);
1811 mFCMsg = 10125;
1812 pfc_fits->SetMsg(mFCMsg);
1813 SetBlocked();
1814 pfc_fits->Show();
1815 break;
1816
1817 case 10125 :
1818 SetBusy();
1819 if (data) {
1820 string cmd = "readfits ";
1821 cmd += pfc_fits->GetFileName();
1822 try {
1823 CmdInterpreter()->AddInputLine(cmd);
1824 // CmdInterpreter()->ExecuteCommand(kw, args, toks);
1825 }
1826 catch ( PThrowable & exc ) {
1827 cerr << "\n PIStdImgApp::Process()/ Cmd->ExecuteCommand(readfits) Exception :"
1828 << (string)typeid(exc).name() << " Msg= "
1829 << exc.Msg() << endl;
1830 cout << endl;
1831 }
1832 catch ( ... ) {
1833 cerr << "\n PIStdImgApp::Process()/ Cmd->ExecuteCommand(readfits) Catched Exception ... " << endl;
1834 cout << endl;
1835 }
1836 }
1837 mFCMsg = 0;
1838 SetReady();
1839 break;
1840
1841 case 10130 :
1842 pfc_ppf->AcceptNewFile(false);
1843 mFCMsg = 10135;
1844 pfc_ppf->SetMsg(mFCMsg);
1845 SetBlocked();
1846 pfc_ppf->Show();
1847 break;
1848
1849 case 10135 :
1850 mFCMsg = 0;
1851 if (data) {
1852 PPInMgrW()->SetFile(pfc_ppf->GetFileName());
1853 PPInMgrW()->Show();
1854 }
1855 SetReady();
1856 break;
1857
1858#ifndef SANS_EVOLPLANCK
1859 case 10140 :
1860 pfc_ascii->AcceptNewFile(false);
1861 mFCMsg = 10145;
1862 pfc_ascii->SetMsg(mFCMsg);
1863 SetBlocked();
1864 pfc_ascii->Show();
1865 break;
1866
1867 case 10145 :
1868 SetBusy();
1869 if (data) {
1870 string afname = pfc_ascii->GetFileName();
1871 string nomobj = ObjMgr()->GetServiceObj()->FileName2Name(afname);
1872 string cmd = "mtxfrascii ";
1873 cmd += nomobj; cmd += " "; cmd += afname;
1874 try {
1875 CmdInterpreter()->AddInputLine(cmd);
1876 // mCmd->Interpret(cmd);
1877 }
1878 catch ( PThrowable & exc ) {
1879 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
1880 << (string)typeid(exc).name() << " Msg= "
1881 << exc.Msg() << endl;
1882 cout << endl;
1883 }
1884 catch ( ... ) {
1885 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ... " << endl;
1886 cout << endl;
1887 }
1888
1889 }
1890 mFCMsg = 0;
1891 SetReady();
1892 break;
1893#endif
1894
1895 case 10105:
1896 Stop();
1897 break;
1898
1899 }
1900return;
1901}
1902
1903
1904
1905/* --Methode-- */
1906void PIStdImgApp::MBProcess2(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1907{
1908
1909switch (msg) {
1910 case 10201 :
1911 ObjMgrW()->Show();
1912 break;
1913
1914 case 10220 :
1915 pfc_ppf->AcceptNewFile(true);
1916 mFCMsg = 10225;
1917 pfc_ppf->SetMsg(mFCMsg);
1918 SetBlocked();
1919 pfc_ppf->Show();
1920 break;
1921
1922 case 10225 :
1923 SetBusy();
1924 if (data) {
1925 if (mPpfout) {
1926 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1927 delete mPpfout;
1928 }
1929 name_outppf = pfc_ppf->GetFileName();
1930 mPpfout = NULL;
1931 printf("PIStdImg/Info: Opening POutPersist-File %s \n", name_outppf.c_str());
1932 mPpfout = new POutPersist(name_outppf);
1933 }
1934 mFCMsg = 0;
1935 SetReady();
1936 break;
1937
1938 case 10230 :
1939 if (!mPpfout) break;
1940 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1941 delete mPpfout;
1942 name_outppf = "";
1943 mPpfout = NULL;
1944 break;
1945
1946 case 10270 :
1947 if (mCurWdg) {
1948 int oid = mCurWdg->UserFlag();
1949 //RZDEL-Mai2005 DeleteWidget(mCurWdg);
1950 mObjMgr->DelObj_Id(oid);
1951 }
1952 break;
1953
1954 default:
1955 cerr << "PIStdImgApp::MBProcess2() BUG?? Msg= " << msg << endl;
1956 break;
1957}
1958
1959return;
1960}
1961
1962/* --Methode-- */
1963void PIStdImgApp::MBProcess3(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1964{
1965
1966switch (msg) {
1967 case 10301 :
1968 PIImgTools::ShowPIImgTools();
1969 break;
1970 case 10302 :
1971 PIDrwTools::ShowPIDrwTools();
1972 break;
1973 case 10303 :
1974 PIAxesTools::ShowPIAxesTools();
1975 break;
1976
1977 case 10304 :
1978 CmdInterpreter()->ShowCxxExecWindow();
1979 break;
1980
1981 case 10311 :
1982 case 10312 :
1983 {
1984 PIImage* curpimg = NULL;
1985 if (!mCurWdg) return;
1986 if (mCurWdg->kind() != PIImage::ClassId) return;
1987 curpimg = (PIImage*)mCurWdg;
1988 if (curpimg == NULL) return;
1989 P2DArrayAdapter* img = curpimg->Image();
1990 if (img == NULL) return;
1991 int dx = curpimg->XSzPave();
1992 int dy = curpimg->YSzPave();
1993 int x0 = curpimg->XPave()-dx/2;
1994 int y0 = curpimg->YPave()-dy/2;
1995 if (x0 < 0) x0 = 0;
1996 if (y0 < 0) y0 = 0;
1997 int x1 = x0+dx;
1998 int y1 = y0+dy;
1999 if (x1 > img->XSize()) x1 = img->XSize();
2000 if (y1 > img->YSize()) y1 = img->YSize();
2001 dx = x1-x0; dy = y1-y0;
2002 ImageR4* pim = new ImageR4(dx, dy);
2003 int ii, jj;
2004 for(jj=0; jj<dy; jj++)
2005 for(ii=0; ii<dx; ii++) (*pim)(ii,jj) = (*img)(ii+x0, jj+y0);
2006 if (msg == 10305) { // Calcul des coordonnees du sous-pave
2007 double xc1, yc1;
2008 img->Coord(x0, y0, xc1, yc1);
2009 pim->SetOrg((int)xc1, (int)yc1);
2010 }
2011 string nom = mCurWdg->Nom() + "_pave";
2012 ObjMgr()->AddObj(pim, nom);
2013 ObjMgr()->DisplayObj(nom, "w");
2014 break;
2015 }
2016
2017 case 10313 :
2018 {
2019 PIImage* curpimg = NULL;
2020 if (!mCurWdg) return;
2021 if (mCurWdg->kind() != PIImage::ClassId) return;
2022 curpimg = (PIImage*)mCurWdg;
2023 if (curpimg == NULL) return;
2024 curpimg->ShowCuts(true);
2025 break;
2026 }
2027
2028 case 10320 :
2029 if (mStW) mStW->DispNext();
2030 break;
2031
2032 case 10321 :
2033 case 10322 :
2034 case 10324 :
2035// case 10328 :
2036 if (mStW) mStW->StartAutoDisp((msg-10320)*500);
2037 break;
2038
2039 case 10329 :
2040 if (mStW) mStW->StopAutoDisp();
2041 break;
2042
2043 case 103330 :
2044 if (mStW) {
2045 PIWdg* cw = mStW->CurrentWdg();
2046 if (cw) DeleteWidget(cw);
2047 }
2048 break;
2049
2050 default:
2051 cerr << "PIStdImgApp::MBProcess3() BUG?? Msg= " << msg << endl;
2052 break;
2053 }
2054return;
2055}
2056
2057/* --Methode-- */
2058void PIStdImgApp::MBProcess4(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
2059{
2060
2061switch (msg) {
2062
2063 case 10400 :
2064 CreateStackWin();
2065 break;
2066
2067 case 10411 :
2068 CreateGraphWin(1,1);
2069 break;
2070 case 10421 :
2071 CreateGraphWin(1,2);
2072 break;
2073 case 10412 :
2074 CreateGraphWin(2,1);
2075 break;
2076 case 10422 :
2077 CreateGraphWin(2,2);
2078 break;
2079 case 10431 :
2080 CreateGraphWin(1,3);
2081 break;
2082 case 10433 :
2083 CreateGraphWin(3,3);
2084 break;
2085 case 10441 :
2086 if (mCurWdg) {
2087 mLastWdg = mCurWdg;
2088 cout << " Using current widget as last-widget (display same) " << endl;
2089 }
2090 else cout << " No current widget - select widget with mouse " << endl;
2091 break;
2092 case 10460 :
2093 DeleteWindow(mCurWin);
2094 break;
2095 case 10470 :
2096 StatZoomWindowSetVisible(m[3]->GetStateMsg(10470));
2097 break;
2098 default:
2099 cerr << "PIStdImgApp::MBProcess4() BUG?? Msg= " << msg << endl;
2100 break;
2101 }
2102return;
2103}
2104
2105
2106/* --Methode-- */
2107void PIStdImgApp::MBProcess5(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
2108{
2109char nomps[64],strg[512];
2110PSFile *mps;
2111int sxt, syt, syo, syo1, sx[4], sy[4];
2112
2113switch (msg)
2114 {
2115 case 10501 :
2116 pfc_ps->AcceptNewFile(true);
2117 mFCMsg = 10525;
2118 pfc_ps->SetMsg(mFCMsg);
2119 SetBlocked();
2120 pfc_ps->Show();
2121 break;
2122
2123 case 10525 :
2124 SetBusy();
2125 if (data) {
2126 if (mpsfile) {
2127 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
2128 delete mpsfile;
2129 }
2130 name_ps = pfc_ps->GetFileName();
2131 printf("PIStdImg/Info: Opening PS-File %s \n", name_ps.c_str());
2132 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 2., 2.);
2133 }
2134 mFCMsg = 0;
2135 SetReady();
2136 break;
2137
2138 case 10505 :
2139 if (!mpsfile) break;
2140 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
2141 delete mpsfile;
2142 mpsfile = NULL;
2143 name_ps = "";
2144 break;
2145
2146 case 10511 : // Window -> PS
2147 case 10512 : // Window -> EPS
2148 if (CurrentWindow() == NULL) break;
2149 if (msg == 10512)
2150 {
2151 num_eps++;
2152 sprintf(nomps,"pia%d.eps", num_eps);
2153 printf("PIStdImg/Info: Creating EPSFile %s (CurWin-> EPS) \n", nomps);
2154 mps = new PSFile(nomps);
2155 }
2156 else {
2157 if (mpsfile == NULL) {
2158 name_ps = "pia.ps";
2159 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 0., 0.);
2160 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
2161 }
2162 printf("PIStdImg/Info: CurWin-> PSFile %s\n", name_ps.c_str());
2163 mps = mpsfile;
2164 }
2165 CurrentWindow()->PSPrint(mps,0,0);
2166
2167 if (msg == 10512) delete mps; // fichier eps
2168 break;
2169
2170 case 10515 : // Image -> PS
2171 case 10516 : // Image -> EPS
2172 {
2173 PIImage* curpimg = NULL;
2174 if (!mCurWdg) return;
2175 if (mCurWdg->kind() != PIImage::ClassId) return;
2176 curpimg = (PIImage*)mCurWdg;
2177 if (curpimg == NULL) return;
2178 if (msg == 10516)
2179 {
2180 num_eps++;
2181 sprintf(nomps,"pia%d.eps", num_eps);
2182 printf("PIStdImg/Info: Creating EPSFile %s (CurImage-> EPS)\n", nomps);
2183 mps = new PSFile(nomps);
2184 }
2185 else {
2186 if (mpsfile == NULL) {
2187 name_ps = "pia.ps";
2188 mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
2189 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
2190 }
2191 printf("PIStdImg/Info: CurImage-> PSFile %s\n", name_ps.c_str());
2192 mps = mpsfile;
2193 }
2194
2195 sx[0] = gimv->XSize();
2196 sy[0] = gimv->YSize();
2197 sx[1] = zoom->XSize();
2198 sy[1] = zoom->YSize();
2199 sx[2] = cmapv->XSize();
2200 sy[2] = cmapv->YSize();
2201 sx[3] = curpimg->XSize();
2202 sy[3] = curpimg->YSize();
2203 if (sy[1] > sy[0]) { syo1 = sy[1]+50; syo = sy[1]+sy[2]+60; }
2204 else { syo1 = sy[0]+50; syo = sy[0]+sy[2]+60; }
2205 syt = sy[3]+syo;
2206 sxt = sx[3];
2207 if (sxt < (sx[0]+sx[1]+20)) sxt = sx[0]+sx[1]+20;
2208 if (sxt < sx[2]) sxt = sx[2];
2209
2210 // Pour ecrire le titre
2211 mps->NewPage((float)sxt, (float)syt, PI_Portrait);
2212 mps->NewBloc(0,0, (float)sxt, 30., (float)sxt, 30.);
2213 sprintf(strg,"Image: %s - Pave %d %d \n", curpimg->Nom().c_str(),
2214 curpimg->XPave(), curpimg->YPave());
2215 mps->DrawString(10., 25., strg, PI_Black, PI_DefaultFont, PI_BoldFont, 20);
2216 mps->EndBloc();
2217
2218 // Les quatre fenetres glovimage, zoom, cmap, image
2219 gimv->PSPrint(mps, -gimv->XPos(), -gimv->YPos()+40);
2220 zoom->PSPrint(mps, -zoom->XPos()+sx[0]+20, -zoom->YPos()+40);
2221 cmapv->PSPrint(mps, -cmapv->XPos(), -cmapv->YPos()+syo1);
2222 curpimg->PSPrint(mps, -curpimg->XPos(), -curpimg->YPos()+syo);
2223
2224 if (msg == 10516) delete mps; // fichier eps
2225 break;
2226 }
2227
2228 default:
2229 cerr << "PIStdImgApp::MBProcess5() BUG?? Msg= " << msg << endl;
2230 break;
2231 }
2232
2233}
2234
2235
2236/* --Methode-- */
2237void PIStdImgApp::MBProcess6(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
2238{
2239switch (msg) {
2240 case 10601:
2241 CloseAllWindows();
2242 break;
2243 case 10602:
2244 RedirectStdOutErr(*((bool*)data));
2245 break;
2246 case 10603:
2247 case 10604:
2248 CatchSignals(m[5]->GetStateMsg(10603), m[5]->GetStateMsg(10604));
2249 break;
2250 case 10605:
2251 mObjMgr->SetVerbose(m[5]->GetStateMsg(10605));
2252 break;
2253 case 10606:
2254 CmdInterpreter()->ShowCxxOptionWindow();
2255 break;
2256 default:
2257 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
2258 break;
2259 }
2260return;
2261}
2262
2263
2264
2265// -------------------------------------------------
2266// Fenetre info piapp (About piapp)
2267// -------------------------------------------------
2268static PIWindow* infow_win = NULL;
2269static PIText* infow_txt = NULL;
2270static PICMapView* infow_cmap = NULL;
2271static PIButton* infow_but = NULL;
2272
2273/* Nouvelle-Fonction */
2274static void createInfoWindow(PIStdImgApp* app)
2275{
2276if (infow_win) return;
2277
2278int bsx, bsy;
2279PIApplicationPrefCompSize(bsx, bsy);
2280int spx, spy;
2281spx = bsx/6; spy = bsy/6;
2282
2283infow_win = new PIWindow((PIMsgHandler *)app, "About piapp",
2284 PIWK_dialog, bsx*5+3*spx, bsy*4+spy*3, 200, 200);
2285infow_win->SetAutoDelChilds(true);
2286infow_txt = new PIText(infow_win,"about_piapp_text", true, false, bsx*5+spx, bsy*3, spx, spy);
2287infow_txt->SetMutiLineMode(true);
2288infow_txt->SetTextEditable(false);
2289infow_txt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2290infow_cmap = new PICMapView(infow_win, "about_piapp_cmap", bsx*4, bsy*0.7, spx, 2*spy+bsy*3.15);
2291infow_cmap->SetColMapId(CMAP_COLBR32, 1., -1., false);
2292infow_cmap->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2293infow_but = new PIButton(infow_win,"OK", 10155, bsx, bsy, bsx*4+2*spx, 2*spy+bsy*3);
2294infow_but->SetMsgParent((PIMsgHandler *)app);
2295infow_but->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2296
2297string info = "piapp : Interactive analysis program\n";
2298char buff[128];
2299#ifdef SANS_EVOLPLANCK
2300sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
2301 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
2302info += buff;
2303#else
2304string svers;
2305SophyaInitiator::GetVersion(svers);
2306info += svers;
2307sprintf(buff, "\n Version: PI=%g -- PIext/piapp= %g \n", (double)PI_VERSIONNUMBER,
2308 (double)PIAPP_VERSIONNUMBER);
2309info += buff;
2310#endif
2311info += "(C) LAL-IN2P3/CNRS 1996-2006\n";
2312info += "(C) SPP-DAPNIA/CEA 1996-2006\n";
2313#ifndef SANS_EVOLPLANCK
2314 info += "Check http://www.sophya.org for more information";
2315#endif
2316infow_txt->SetText(info);
2317}
2318
2319/* Nouvelle-Fonction */
2320static void showInfoWindow(PIStdImgApp* app)
2321{
2322if (!infow_win) createInfoWindow(app);
2323if (infow_win) infow_win->Show();
2324}
2325/* Nouvelle-Fonction */
2326static void hideInfoWindow(PIStdImgApp* app)
2327{
2328if (infow_win) infow_win->Hide();
2329}
2330
2331/* Nouvelle-Fonction */
2332static void deleteInfoWindow()
2333{
2334if (!infow_win) return;
2335delete infow_win;
2336infow_win = NULL;
2337infow_txt = NULL;
2338infow_cmap = NULL;
2339infow_but = NULL;
2340}
2341
2342
Note: See TracBrowser for help on using the repository browser.