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

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

Ajout de l option nodisp ds les affichages des NamedObjMgr, prise en compte de <Cntrl C> (Msg_Cancel) pour arreter l'execution de l'interpreteur ds PIStdImgApp et remplacement commande breakexe par stop ds PIACmd - Reza 19/4/2005

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