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

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

1/ Prise en charge de DataTable et SwPPFDataTable pour piapp (NObjMgrAdapter) :
nomhistadapter.cc et piiinit.cc
2/ Lecture de tous les objets ds un fichier PPF par NamedObjMgr::ReadAll() pour
fichier PPF sans nametag.
3/ Ajout bloc try/catch ds PIStdImgApp::Run() (boucle d'evenements)

Reza , 27 Avril 2005

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