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

Last change on this file since 2642 was 2638, checked in by ansari, 21 years ago

Ajout commandes addoval addfoval pour trace d'ellipse - Reza 19/11/2004

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