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

Last change on this file since 2669 was 2651, checked in by ansari, 21 years ago

Modifications pour l'utilisation viewer PIImageNavigator (ajout commande imagnav) - Reza 18 Fev 2005

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