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

Last change on this file since 4078 was 4071, checked in by ansari, 13 years ago

Trace en coordonnees polaires (2D avec barres d'erreur) classe PINTuple

et introduction des attributs graphiques polarplot, polaraxes ...

Reza, 9 Mai 2012

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