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

Last change on this file since 2764 was 2762, checked in by ansari, 20 years ago

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