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

Last change on this file since 2904 was 2904, checked in by ansari, 20 years ago

Appel readfits (nouveau FITS) pour menu OpenFits ds PIStdImagApp - Reza 16/01/2006

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