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

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

Ajout indicateur memoire consommee/CPU ds fenetre piapp - Reza 17/7/2002

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