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

Last change on this file since 2259 was 2259, checked in by ansari, 23 years ago

Amelioration mineure affichage CPULoad() - Reza 12/11/2002

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