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

Last change on this file since 2613 was 2606, checked in by ansari, 21 years ago

Ajout bloc try/catch ds piacmd.cc (thread execution commandes) et ds pistdimgapp.cc (methode process, thread boucle d'evts) - Reza 07/09/2004

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