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

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

Ajout commande setaxelabels, adaptations aux modifs PIElDrwMgr et
PIDrawer3D - Reza 7/8/2002

  • Property svn:executable set to *
File size: 47.6 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
566// On recalcule la taille de la fenetre si Disp_Win
567if (dwopt == Disp_Win) {
568 int sx2 = (int)((float)nouv->XSize()*pii->GetZoomF());
569 int sy2 = (int)((float)nouv->YSize()*pii->GetZoomF());
570
571 if (sx2 > 400+mFgScSz*100) sx2 = 400+mFgScSz*100;
572 if (sy2 > 400+mFgScSz*100) sy2 = 400+mFgScSz*100;
573 if (sx2 < MINPIIMGSIZE) sx = MINPIIMGSIZE;
574 if (sy2 < MINPIIMGSIZE) sy = MINPIIMGSIZE;
575 if ((sx2 != sx) || (sy2 != sy)) win->SetSize(sx2, sy2);
576}
577
578pii->SetImage(nouv, true, false);
579
580// decode des options en chaine de caracteres
581pii->DecodeOptionString(mDefaultAtt, false); // d'abord les options par defaut
582pii->DecodeOptionString(opts); // ensuite, les options specifies en argument
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;
590// pii->Refresh();
591pii->Apply();
592cmapv->Refresh();
593return(mBWId);
594}
595
596
597/* --Methode-- */
598int PIStdImgApp::DispScDrawer(PIDrawer* scd, string const & name, string const& sop,
599 string title, int oid)
600{
601if (scd == NULL)
602 {
603 printf("PIStdImgApp::DispScDrawer_Error Cannot Add NULL ScDrawer \n");
604 return(-1);
605 }
606
607// On decode les options graphiques
608vector<string> opts;
609DispWinEnum dwopt = ParseDisplayOption(sop, opts);
610if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
611// Trace en superpoistion
612if ( (dwopt == Disp_Same) && (mLastWdg) ) {
613 // Les options
614 scd->DecodeOptionString(mDefaultAtt, false);
615 scd->DecodeOptionString(opts, true);
616
617 if (mLastWdg->kind() == PIScDrawWdg::ClassId) ((PIScDrawWdg*)mLastWdg)->AddScDrawer(scd, true);
618 else mLastWdg->AddDrawer(scd, true, true, true);
619 scd->Refresh();
620 mDId++;
621 mDrwList[mDId] = scd;
622 return(-mDId);
623}
624// Trace en medaillon
625else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
626 PIGrCoord x1, x2, y1, y2;
627 x1 = mIXmin; x2 = mIXmax;
628 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
629 // Les options
630 scd->DecodeOptionString(mDefaultAtt, false);
631 scd->DecodeOptionString(opts, true);
632
633 scd->SetAxesFlags(mAxesFlags);
634 scd->UpdateLimits();
635 mLastWdg->AddDrawer(scd, x1, y1, x2, y2, true, false, true);
636 scd->Refresh();
637 mDId++;
638 mDrwList[mDId] = scd;
639 return(-mDId);
640}
641
642// Creation d'un nouveau PIScDrawWdg
643PIWindow* win;
644PIScDrawWdg* scw;
645int sx, sy, px, py, flag;
646sx = 200+mFgScSz*100;
647sy = 200+mFgScSz*100;
648win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
649
650scw = new PIScDrawWdg(win, (char *)name.c_str(), sx, sy, px, py);
651scw->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
652scw->SetUserData(NULL, oid);
653
654// Decodage des options :
655vector<string> scwatt;
656scw->SetAxesFlags(mAxesFlags);
657if ( mDefaultAtt.size() > 0) {
658 scwatt = mDefaultAtt;
659 scw->DecodeOptionString(scwatt, true);
660}
661if ( mAxesAtt.size() > 0) {
662 scwatt = mAxesAtt;
663 scw->DecodeOptionString(scwatt, true);
664}
665if (opts.size() > 0)
666 scd->DecodeOptionString(opts, true);
667if (opts.size() > 0)
668 scw->DecodeOptionString(opts, false);
669
670// Titre du plot
671if (mAddTitle) {
672 if (title.length() <= 0) title = name; string t2="";
673 scw->SetTitles(title, t2);
674}
675
676scw->AddScDrawer(scd, true);
677// scw->Refresh(); ? Pas necessaire Reza 19/08/98, 05/05/99 $CHECK$
678
679mCurWin = win;
680mCurWdg = scw;
681mLastWdg = scw;
682mBWId++;
683mBWList[mBWId] = scw;
684return(mBWId);
685}
686
687/* --Methode-- */
688int PIStdImgApp::Disp3DDrawer(PIDrawer3D* dr3, string const & name, string const& sop,
689 string title, int oid)
690{
691if (dr3 == NULL)
692 {
693 printf("PIStdImgApp::Disp3DDrawer_Error Cannot Add NULL 3DDrawer \n");
694 return(-1);
695 }
696
697// On decode les options graphiques
698vector<string> opts;
699DispWinEnum dwopt = ParseDisplayOption(sop, opts);
700
701if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
702// Trace en superpoistion
703if ( (dwopt == Disp_Same) && (mLastWdg) ) {
704 // Les options
705 dr3->DecodeOptionString(mDefaultAtt, false);
706 dr3->DecodeOptionString(opts, true);
707
708 if (mLastWdg->kind() == PIDraw3DWdg::ClassId) ((PIDraw3DWdg*)mLastWdg)->AddDrawer3D(dr3, true);
709 else mLastWdg->AddDrawer(dr3, true, true, true);
710 dr3->Refresh();
711 mDId++;
712 mDrwList[mDId] = dr3;
713 return(-mDId);
714}
715// Trace en medaillon
716else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
717 PIGrCoord x1, x2, y1, y2;
718 x1 = mIXmin; x2 = mIXmax;
719 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
720 // Les options
721 dr3->DecodeOptionString(mDefaultAtt, false);
722 dr3->DecodeOptionString(opts, true);
723
724 dr3->SetAxesFlags(mAxesFlags);
725 dr3->UpdateLimits();
726 mLastWdg->AddDrawer(dr3, x1, y1, x2, y2, true, false, true);
727 dr3->Refresh();
728 mDId++;
729 mDrwList[mDId] = dr3;
730 return(-mDId);
731}
732
733
734PIWindow* win;
735int sx, sy, px, py, flag;
736sx = 200+mFgScSz*100;
737sy = 200+mFgScSz*100;
738win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
739PIDraw3DWdg* wd3 = new PIDraw3DWdg(win, (char *)name.c_str(), sx, sy, px, py);
740wd3->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
741wd3->SetUserData(NULL, oid);
742
743// Decodage des options :
744vector<string> scwatt;
745// wd3->SetAxesFlags(mAxesFlags); Attributs d'axes 3D a faire
746if ( mDefaultAtt.size() > 0) {
747 scwatt = mDefaultAtt;
748 wd3->DecodeOptionString(scwatt, true);
749}
750if ( mAxesAtt.size() > 0) {
751 scwatt = mAxesAtt;
752 wd3->DecodeOptionString(scwatt, true);
753}
754if (opts.size() > 0)
755 dr3->DecodeOptionString(opts, true);
756if (opts.size() > 0)
757 wd3->DecodeOptionString(opts, false);
758
759// Titre du plot
760if (mAddTitle) {
761 if (title.length() <= 0) title = name; string t2="";
762 wd3->SetTitles(title, t2);
763}
764
765wd3->AddDrawer3D(dr3, true);
766// wd3->Refresh(); ?Pas necessaire $CHECK$ 05/05/99
767
768mCurWin = win;
769mCurWdg = wd3;
770mLastWdg = wd3;
771mBWId++;
772mBWList[mBWId] = wd3;
773return(mBWId);
774}
775
776/* --Methode-- */
777void PIStdImgApp::AddText(string const & txt, double xp, double yp, string const& sop)
778{
779PIDrawer *eld=CurrentElDrawer();
780if (eld == NULL) return;
781PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
782PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
783if ((eld2 == NULL) && (eld3 == NULL)) return;
784PIElDrwMgr* elmgr;
785if (eld2) elmgr = &(eld2->ElDrwMgr());
786else if (eld3) elmgr = &(eld3->ElDrwMgr());
787if (elmgr == NULL) return;
788
789vector<string> opts;
790ParseDisplayOption(sop, opts);
791PIGraphicAtt gratt(opts);
792elmgr->ElAddText(xp,yp,txt.c_str(), gratt);
793eld->Refresh();
794}
795
796/* --Methode-- */
797void PIStdImgApp::AddLine(double xp1, double yp1, double xp2, double yp2, string const& sop)
798{
799PIDrawer *eld=CurrentElDrawer();
800if (eld == NULL) return;
801PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
802PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
803if ((eld2 == NULL) && (eld3 == NULL)) return;
804PIElDrwMgr* elmgr = NULL;
805if (eld2) elmgr = &(eld2->ElDrwMgr());
806else if (eld3) elmgr = &(eld3->ElDrwMgr());
807if (elmgr == NULL) return;
808
809vector<string> opts;
810ParseDisplayOption(sop, opts);
811PIGraphicAtt gratt(opts);
812elmgr->ElAddLine(xp1, yp1, xp2, yp2, gratt);
813eld->Refresh();
814}
815
816/* --Methode-- */
817void PIStdImgApp::AddRectangle(double xp1, double yp1, double xp2, double yp2,
818 string const& sop, bool fgfill)
819{
820PIDrawer *eld=CurrentElDrawer();
821if (eld == NULL) return;
822PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
823PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
824if ((eld2 == NULL) && (eld3 == NULL)) return;
825PIElDrwMgr* elmgr = NULL;
826if (eld2) elmgr = &(eld2->ElDrwMgr());
827else if (eld3) elmgr = &(eld3->ElDrwMgr());
828
829double xp,yp;
830double dx, dy;
831if (xp1 < xp2) {
832 xp = xp1; dx = xp2-xp1;
833}
834else {
835 xp = xp2; dx = xp1-xp2;
836}
837if (yp1 < yp2) {
838 yp = yp1; dy = yp2-yp1;
839}
840else {
841 yp = yp2; dy = yp1-yp2;
842}
843
844vector<string> opts;
845ParseDisplayOption(sop, opts);
846PIGraphicAtt gratt(opts);
847
848if (fgfill) elmgr->ElAddFRect(xp, yp, dx, dy, gratt);
849else elmgr->ElAddRect(xp, yp, dx, dy, gratt);
850eld->Refresh();
851}
852
853/* --Methode-- */
854void PIStdImgApp::AddCircle(double xc, double yc, double r, string const& sop, bool fgfill)
855{
856PIDrawer *eld=CurrentElDrawer();
857if (eld == NULL) return;
858PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
859PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
860if ((eld2 == NULL) && (eld3 == NULL)) return;
861PIElDrwMgr* elmgr = NULL;
862if (eld2) elmgr = &(eld2->ElDrwMgr());
863else if (eld3) elmgr = &(eld3->ElDrwMgr());
864
865vector<string> opts;
866ParseDisplayOption(sop, opts);
867PIGraphicAtt gratt(opts);
868
869if (fgfill) elmgr->ElAddFCirc(xc, yc, r, gratt);
870else elmgr->ElAddCirc(xc, yc, r, gratt);
871eld->Refresh();
872}
873
874/* --Methode-- */
875void PIStdImgApp::SetTitle(string const & titletop, string const & titlebottom, string const& sop)
876{
877PIDrawer *eld=CurrentElDrawer();
878if (eld == NULL) return;
879PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
880PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
881if ((eld2 == NULL) && (eld3 == NULL)) return;
882
883vector<string> opts;
884ParseDisplayOption(sop, opts);
885PIGraphicAtt gratt(opts);
886
887if (eld2) {
888 eld2->SetTitles(titletop, titlebottom, gratt);
889 eld2->ShowTitles(true);
890}
891else if (eld3) {
892 eld3->SetTitles(titletop, titlebottom, gratt);
893 eld3->ShowTitles(true);
894}
895eld->Refresh();
896}
897/* --Methode-- */
898void PIStdImgApp::SetAxeLabels(string const & xLabel, string const & yLabel, string const& sop)
899{
900PIDrawer *eld=CurrentElDrawer();
901if (eld == NULL) return;
902PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
903if (eld2 == NULL) return;
904
905vector<string> opts;
906ParseDisplayOption(sop, opts);
907PIGraphicAtt gratt(opts);
908
909eld2->SetAxesLabels(xLabel, yLabel, gratt);
910eld2->ShowAxesLabels(true);
911
912eld->Refresh();
913}
914
915/* --Methode-- */
916PIDrawer* PIStdImgApp::CurrentElDrawer()
917{
918PIDrawer *eld=NULL;
919if (!mLastWdg) return(eld);
920PIScDrawWdg* sdw=NULL;
921PIDraw3DWdg* w3d=NULL;
922PIImage* imgw;
923switch(mLastWdg->kind()) {
924 case PIScDrawWdg::ClassId :
925 sdw = dynamic_cast<PIScDrawWdg *>(mLastWdg);
926 if (sdw) eld = sdw->BaseDrawer();
927 break;
928 case PIDraw3DWdg::ClassId :
929 w3d = dynamic_cast<PIDraw3DWdg *>(mLastWdg);
930 if (w3d) eld = w3d->BaseDrawer();
931 break;
932 case PIImage::ClassId :
933 imgw = dynamic_cast<PIImage *>(mLastWdg);
934 if (imgw) eld = imgw->BaseDrawer();
935 break;
936 default :
937 break;
938 }
939return(eld);
940}
941
942/* --Methode-- */
943void PIStdImgApp::CreateGraphWin(int nx, int ny, int sx, int sy)
944{
945if (nx < 1) nx = 1;
946if (ny < 1) ny = 1;
947if (nx > 8) nx = 8;
948if (ny > 8) ny = 8;
949if ( (sx < 50) && (sy < 50) ) sx = sy = 400+mFgScSz*100;
950char buff[64];
951mWId++;
952int px, py;
953MainWin()->GetScreenPos(px, py);
954sprintf(buff, "PI-GraphicWin (%d)",mWId);
955PIZoneWindow* win = new PIZoneWindow(this, buff, PIWK_normal, nx, ny, sx, sy, px+MainWin()->XSize()+30, 0);
956win->SetUserData(NULL, ny*10+nx); // UserFlag= nY*10 + nX
957mWList[mWId*10+1] = (PIWindow*)win;
958win->SetAutoDelChilds(true);
959// win->Show();
960mGrW = win;
961mGrIdx = 0;
962}
963
964/* --Methode-- */
965void PIStdImgApp::CreateStackWin(int sx, int sy)
966{
967if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
968char buff[64];
969mWId++;
970int px, py;
971MainWin()->GetScreenPos(px, py);
972sprintf(buff, "PI-StackWin (%d)",mWId);
973PIStackWindow* win = new PIStackWindow(this, buff, PIWK_normal, sx, sy, px+MainWin()->XSize()+30, 100);
974win->SetUserData(NULL, 9999); // UserFlag= 9999
975mWList[mWId*10+2] = (PIWindow*)win;
976win->SetAutoDelChilds(true);
977// win->Show();
978mStW = win;
979m[2]->SetSensitivity("StackTools", true);
980mStIdx = 0;
981}
982
983/* --Methode-- */
984PIWindow* PIStdImgApp::GetWindow(DispWinEnum typ, int& sx, int& sy, int& px, int& py, int& flag, char * nom)
985{
986PIWindow* rw;
987
988switch (typ) {
989 case Disp_Next : // Fenetre graphique courante
990 case Disp_Default :
991 {
992 if (mGrW == NULL) CreateGraphWin();
993 int nx, ny;
994 mGrW->NbZone(nx, ny);
995 PIWdg* nw = mGrW->NextChildPosSize(px, py, sx, sy);
996// cerr << "**DBG** PIStdImgApp::GetWindow() DispNext : nw = " << (long)nw << endl;
997 if (nw) DeleteBaseWidget((PIBaseWdg*)nw, false, false);
998 flag = mGrIdx;
999 mGrIdx = (mGrIdx+1)%(nx*ny);
1000 rw = mGrW;
1001 break;
1002 }
1003
1004 case Disp_Stack : // Fenetre de type stack (empilement)
1005 {
1006 if (mStW == NULL) CreateStackWin(sx, sy);
1007 px = py = 0;
1008 sx = mStW->XSize();
1009 sy = mStW->YSize();
1010 flag = mStIdx;
1011 mStIdx++;
1012 rw = mStW;
1013 }
1014 break;
1015
1016 default : // Fenetre ordinaire
1017 {
1018 int pwx, pwy;
1019 MainWin()->GetScreenPos(pwx, pwy);
1020 if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
1021 rw = new PIWindow(this, nom, PIWK_normal, sx, sy, pwx+MainWin()->XSize()+30, 300);
1022 rw->SetUserData(NULL, 0); // UserFlag= 0
1023 mWId++;
1024 mWList[mWId*10] = rw;
1025 rw->SetAutoDelChilds(true);
1026 // rw->Show();
1027 px = py = 0;
1028 flag = 0;
1029 break;
1030 }
1031 }
1032
1033rw->Show();
1034mCurWin = rw;
1035return(rw);
1036}
1037
1038/* --Methode-- */
1039void PIStdImgApp::SetZone(int nzx, int nzy)
1040{
1041if (!mGrW) CreateGraphWin(nzx, nzy);
1042else {
1043 int k;
1044 PIWdg* cwd;
1045 for(k=0; k<mGrW->NbChilds(); k++) {
1046 if ((cwd = mGrW->GetChild(k)) == NULL) continue;
1047 DeleteBaseWidget((PIBaseWdg*)cwd, false, false);
1048 }
1049 mGrW->SetZone(nzx, nzy);
1050 }
1051}
1052
1053/* --Methode-- */
1054void PIStdImgApp::StackWinNext()
1055{
1056if (mStW) mStW->DispNext();
1057}
1058
1059/* --Methode-- */
1060void PIStdImgApp::DeleteWindow(PIWindow* w)
1061{
1062if (w == NULL) return;
1063w->Hide();
1064bool ownwindow=false; // To Check if this is one of our windows
1065WindMList::iterator it;
1066for(it = mWList.begin(); it != mWList.end(); it++)
1067 if ((*it).second == w) { mWList.erase(it); ownwindow = true; break; }
1068if (w == mGrW) { mGrW = NULL; mGrIdx = -1; }
1069if (w == mStW) { mStW = NULL; mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
1070if (w == mCurWin) mCurWin = NULL;
1071
1072if (!ownwindow) return; // We do nothing if this is not a window we have created ...
1073
1074int k;
1075PIWdg* cwd;
1076for(k=0; k<w->NbChilds(); k++) {
1077 if ((cwd = w->GetChild(k)) == NULL) continue;
1078 DeleteBaseWidget((PIBaseWdg*)cwd,false,false);
1079 }
1080delete w;
1081return;
1082}
1083
1084/* --Methode-- */
1085void PIStdImgApp::DeleteBaseWidget(PIBaseWdg* w, bool dw, bool dwin)
1086{
1087if (w == NULL) return;
1088BWMList::iterator it;
1089for(it = mBWList.begin(); it != mBWList.end(); it++)
1090 if ((*it).second == w) { mBWList.erase(it); break; }
1091int k;
1092PIDrawer* drw;
1093for(k=0; k<w->NbDrawers(); k++) {
1094 if ((drw = w->GetDrawer(k)) == NULL) continue;
1095 DrwMList::iterator itt;
1096 for(itt = mDrwList.begin(); itt != mDrwList.end(); itt++)
1097 if ((*itt).second == drw) { mDrwList.erase(itt); break; }
1098 }
1099
1100if (w == mCurWdg) {
1101 mCurWdg = NULL;
1102 if (mFgCWImg) {
1103 m[4]->SetSensitivityMsg(10515, false);
1104 m[4]->SetSensitivityMsg(10516, false);
1105 mFgCWImg = false;
1106 }
1107 }
1108
1109if (w == mLastWdg) mLastWdg = NULL;
1110
1111PIWdg* pw=NULL;
1112if (dwin) pw = (PIWdg*)(w->Parent());
1113//DBG printf("DeleteBaseWidget(%lx)-DBG kind = %d - %d %d \n", (long)w, w->kind(), (int)dw, (int)dwin);
1114if (dw) delete w;
1115if (pw && (pw->kind() == PIWindow::ClassId )) {
1116 PIWindow* pww = (PIWindow*) pw;
1117 if ((pww != (PIWindow*)mGrW) && (pww != (PIWindow*)mStW) && (pww->NbChilds()==0))
1118 DeleteWindow((PIWindow*)pw);
1119 }
1120return;
1121}
1122
1123
1124
1125/* --Methode-- */
1126void PIStdImgApp::DelWRsId(int k)
1127{
1128//DBG cerr << "-DBG- PIStdImgApp::DelWRsId(" << k << ")" << endl;
1129if (k > 0) { // C'est un BaseWidget
1130 BWMList::iterator it;
1131 it = mBWList.find(k);
1132 if (it == mBWList.end()) return;
1133 PIBaseWdg* wd = (*it).second;
1134//DBG cerr << "-DBG- PIStdImgApp::DelWRsId Deleting BaseWidget " << (long)(wd) << endl ;
1135 DeleteBaseWidget(wd, true, true);
1136 }
1137else { // C'est un drawer
1138 DrwMList::iterator it;
1139 it = mDrwList.find(-k);
1140 if (it == mDrwList.end()) return;
1141 delete (*it).second;
1142 mDrwList.erase(it);
1143// cerr << "+DBG+ PIStdImgApp::DelWRsId Deleting Drawer " << (long)((*it).second) << endl ;
1144 }
1145}
1146/* --Methode-- */
1147bool PIStdImgApp::CheckWRsId(int k)
1148{
1149if (k > 0) { // C'est un BaseWidget
1150 BWMList::iterator it;
1151 it = mBWList.find(k);
1152 if (it == mBWList.end()) return(false);
1153 else return(true);
1154 }
1155else { // C'est un drawer
1156 DrwMList::iterator it;
1157 it = mDrwList.find(-k);
1158 if (it == mDrwList.end()) return(false);
1159 else return(true);
1160 }
1161}
1162
1163/* --Methode-- */
1164void PIStdImgApp::StatZoomWindowSetVisible(bool fg)
1165{
1166
1167 if (fg) {
1168 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1169 int szy = MainWin()->YSize();
1170 MainWin()->SetSize(MainWin()->XSize(), szy+statcont->YSize());
1171 consolecont->SetPos(0, statcont->YSize());
1172 consolecont->SetSize(MainWin()->XSize(), szy);
1173 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
1174 statcont->Show();
1175 m[3]->SetStateMsg(10470, true);
1176 }
1177 else {
1178 statcont->Hide();
1179 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1180 MainWin()->SetSize(MainWin()->XSize(), MainWin()->YSize()-statcont->YSize());
1181 consolecont->SetPos(0, 0);
1182 consolecont->SetSize(MainWin()->XSize(), MainWin()->YSize());
1183 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
1184 m[3]->SetStateMsg(10470, false);
1185 }
1186
1187}
1188
1189/* --Methode-- */
1190void PIStdImgApp::UpdateStatResourceInfo()
1191{
1192 resusg.Update();
1193 char buff[256];
1194 string lab;
1195 double frac;
1196 sprintf(buff, "Mem: %ld/Max= %ld kb" , (long)resusg.getMemorySize(),
1197 (long)resusg.getMaxMemorySize());
1198 lab = buff;
1199 lab_mem->SetLabel(lab);
1200 frac = (double)resusg.getMemorySize()/(double)resusg.getMaxMemorySize();
1201 therm_mem->SetValue(frac);
1202
1203 sprintf(buff, "CPU: %ld/elap= %ld ms" , (long)resusg.getCPUTime(),
1204 (long)resusg.getElapsedTime());
1205 lab = buff;
1206 lab_cpu->SetLabel(lab);
1207 therm_cpu->SetValue(resusg.getCPULoad());
1208
1209}
1210
1211/* --Methode-- */
1212void PIStdImgApp::RedirectStdOutErr(bool fg)
1213{
1214if (fg) {
1215 RedirectOutStream(mCons);
1216 RedirectErrStream(mCons);
1217 m[5]->SetStateMsg(10602, true);
1218 redirecout = true;
1219 }
1220else {
1221 RedirectOutStream(NULL);
1222 RedirectErrStream(NULL);
1223 m[5]->SetStateMsg(10602, false);
1224 redirecout = false;
1225 }
1226return;
1227}
1228
1229/* --Methode-- */
1230void PIStdImgApp::CatchSignals(bool fgfpe, bool fgsegv)
1231{
1232#ifdef SANS_EVOLPLANCK
1233PeidaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1234#else
1235SophyaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1236#endif
1237m[5]->SetStateMsg(10603, fgfpe);
1238m[5]->SetStateMsg(10604, fgsegv);
1239}
1240
1241/* --Methode-- */
1242void PIStdImgApp::CloseAllWindows()
1243{
1244WindMList::iterator it;
1245for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
1246mWList.clear();
1247mBWList.clear();
1248mDrwList.clear();
1249mGrW = NULL;
1250mStW = NULL;
1251mCurWin = NULL;
1252mCurWdg = NULL;
1253mLastWdg = NULL;
1254m[4]->SetSensitivityMsg(10515, false);
1255m[4]->SetSensitivityMsg(10516, false);
1256}
1257
1258//---------------------------------------------------------------------------
1259//--------- Gestion des attributs graphiques et autres options de trace -----
1260
1261/* --Methode-- */
1262void PIStdImgApp::SetInsetLimits(double xmin, double xmax, double ymin, double ymax)
1263{
1264 mIXmin = xmin; mIXmax= xmax;
1265 mIYmin = ymin; mIYmax= ymax;
1266}
1267
1268/* --Methode-- */
1269void PIStdImgApp::SetDefaultGraphicAttributes(string const & opt)
1270{
1271 ParseDisplayOption(opt, mDefaultAtt);
1272}
1273
1274/* --Methode-- */
1275void PIStdImgApp::SetDefaultAxesAttributes(string const & opt)
1276{
1277 ParseDisplayOption(opt, mAxesAtt);
1278}
1279
1280/* --Methode-- */
1281DispWinEnum PIStdImgApp::ParseDisplayOption(string const & sop, vector<string>& opts)
1282{
1283 DispWinEnum rc = Disp_Next;
1284 //DBG cerr << " DBG-Parse-A sop=" << sop << " sop.length()= " << sop.length() << endl;
1285 if (opts.size() > 0) opts.erase(opts.begin(), opts.end());
1286 if (sop.length() < 1) return(rc);
1287 string gratt = sop;
1288 for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1289 if ( (gratt == "def") || (gratt == "default") ) return(rc);
1290// On separe en mots espaces par des blancs ou tabulation
1291 size_t p = 0;
1292 size_t q = 0;
1293 size_t l = gratt.length();
1294 string token;
1295 while (q < l) {
1296 p = gratt.find_first_not_of(" \t",q); // au debut d'un token
1297 if (p >= l) break;
1298 q = gratt.find_first_of(" \t",p); // Premier blanc ou tab suivant
1299 if (q<l) token = gratt.substr(p,q-p);
1300 else token = gratt.substr(p);
1301 if (token == "") continue;
1302 // Decodage option fenetre d'affichage (win, next, ...)
1303 if (token == "win") rc = Disp_Win;
1304 else if (token == "same") rc = Disp_Same;
1305 else if (token == "inset") rc = Disp_Inset;
1306 else if (token == "stack") rc = Disp_Stack;
1307 else if (token == "next") rc = Disp_Next;
1308 // Option a etre decode par les drawers, etc ...
1309 else opts.push_back(token);
1310 }
1311
1312 //DBG cerr << " DBG-Parse-B opts.size()=" << opts.size() << endl;
1313 return (rc);
1314}
1315
1316//---------------------------------------------------------------------------
1317//------------ Methodes privees (MBProcessx, ...) ----------
1318
1319/* --Methode-- */
1320void PIStdImgApp::MBProcess1(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1321{
1322
1323 switch(msg)
1324 {
1325 case 10150 :
1326 showInfoWindow(this);
1327 break;
1328
1329 case 10155 :
1330 hideInfoWindow(this);
1331 break;
1332
1333 case 10100 :
1334 mCmd->ShowHelpWindow();
1335 break;
1336
1337 case 10120 :
1338 pfc_fits->AcceptNewFile(false);
1339 mFCMsg = 10125;
1340 pfc_fits->SetMsg(mFCMsg);
1341 SetBlocked();
1342 pfc_fits->Show();
1343 break;
1344
1345 case 10125 :
1346 SetBusy();
1347 if (data) {
1348 string nomobj="";
1349 ObjMgr()->ReadFits(pfc_fits->GetFileName(), nomobj);
1350 ObjMgr()->DisplayObj(nomobj, "win");
1351 }
1352 mFCMsg = 0;
1353 SetReady();
1354 break;
1355
1356 case 10130 :
1357 pfc_ppf->AcceptNewFile(false);
1358 mFCMsg = 10135;
1359 pfc_ppf->SetMsg(mFCMsg);
1360 SetBlocked();
1361 pfc_ppf->Show();
1362 break;
1363
1364 case 10135 :
1365 mFCMsg = 0;
1366 if (data) {
1367 PPInMgrW()->SetFile(pfc_ppf->GetFileName());
1368 PPInMgrW()->Show();
1369 }
1370 SetReady();
1371 break;
1372
1373 case 10105:
1374 Stop();
1375 break;
1376
1377 }
1378return;
1379}
1380
1381
1382
1383/* --Methode-- */
1384void PIStdImgApp::MBProcess2(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1385{
1386
1387switch (msg) {
1388 case 10201 :
1389 ObjMgrW()->Show();
1390 break;
1391
1392 case 10220 :
1393 pfc_ppf->AcceptNewFile(true);
1394 mFCMsg = 10225;
1395 pfc_ppf->SetMsg(mFCMsg);
1396 SetBlocked();
1397 pfc_ppf->Show();
1398 break;
1399
1400 case 10225 :
1401 SetBusy();
1402 if (data) {
1403 if (mPpfout) {
1404 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1405 delete mPpfout;
1406 }
1407 name_outppf = pfc_ppf->GetFileName();
1408 mPpfout = NULL;
1409 printf("PIStdImg/Info: Opening POutPersist-File %s \n", name_outppf.c_str());
1410 mPpfout = new POutPersist(name_outppf);
1411 }
1412 mFCMsg = 0;
1413 SetReady();
1414 break;
1415
1416 case 10230 :
1417 if (!mPpfout) break;
1418 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1419 delete mPpfout;
1420 name_outppf = "";
1421 mPpfout = NULL;
1422 break;
1423
1424 case 10270 :
1425 if (mCurWdg) {
1426 int oid = mCurWdg->UserFlag();
1427 DeleteBaseWidget(mCurWdg);
1428 mObjMgr->DelObj_Id(oid);
1429 }
1430 break;
1431
1432 default:
1433 cerr << "PIStdImgApp::MBProcess2() BUG?? Msg= " << msg << endl;
1434 break;
1435}
1436
1437return;
1438}
1439
1440/* --Methode-- */
1441void PIStdImgApp::MBProcess3(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1442{
1443
1444switch (msg) {
1445 case 10301 :
1446 PIImgTools::ShowPIImgTools();
1447 break;
1448 case 10302 :
1449 PIDrwTools::ShowPIDrwTools();
1450 break;
1451 case 10303 :
1452 PIAxesTools::ShowPIAxesTools();
1453 break;
1454
1455 case 10304 :
1456 mCmd->ShowCxxExecWindow();
1457 break;
1458
1459 case 10311 :
1460 case 10312 :
1461 {
1462 PIImage* curpimg = NULL;
1463 if (!mCurWdg) return;
1464 if (mCurWdg->kind() != PIImage::ClassId) return;
1465 curpimg = (PIImage*)mCurWdg;
1466 if (curpimg == NULL) return;
1467 P2DArrayAdapter* img = curpimg->Image();
1468 if (img == NULL) return;
1469 int dx = curpimg->XSzPave();
1470 int dy = curpimg->YSzPave();
1471 int x0 = curpimg->XPave()-dx/2;
1472 int y0 = curpimg->YPave()-dy/2;
1473 if (x0 < 0) x0 = 0;
1474 if (y0 < 0) y0 = 0;
1475 int x1 = x0+dx;
1476 int y1 = y0+dy;
1477 if (x1 > img->XSize()) x1 = img->XSize();
1478 if (y1 > img->YSize()) y1 = img->YSize();
1479 dx = x1-x0; dy = y1-y0;
1480 ImageR4* pim = new ImageR4(dx, dy);
1481 int ii, jj;
1482 for(jj=0; jj<dy; jj++)
1483 for(ii=0; ii<dx; ii++) (*pim)(ii,jj) = (*img)(ii+x0, jj+y0);
1484 if (msg == 10305) { // Calcul des coordonnees du sous-pave
1485 double xc1, yc1;
1486 img->Coord(x0, y0, xc1, yc1);
1487 pim->SetOrg((int)xc1, (int)yc1);
1488 }
1489 string nom = mCurWdg->Nom() + "_pave";
1490 ObjMgr()->AddObj(pim, nom);
1491 ObjMgr()->DisplayObj(nom, "w");
1492 break;
1493 }
1494
1495 case 10313 :
1496 {
1497 PIImage* curpimg = NULL;
1498 if (!mCurWdg) return;
1499 if (mCurWdg->kind() != PIImage::ClassId) return;
1500 curpimg = (PIImage*)mCurWdg;
1501 if (curpimg == NULL) return;
1502 curpimg->ShowCuts(true);
1503 break;
1504 }
1505
1506 case 10320 :
1507 if (mStW) mStW->DispNext();
1508 break;
1509
1510 case 10321 :
1511 case 10322 :
1512 case 10324 :
1513// case 10328 :
1514 if (mStW) mStW->StartAutoDisp((msg-10320)*500);
1515 break;
1516
1517 case 10329 :
1518 if (mStW) mStW->StopAutoDisp();
1519 break;
1520
1521 case 103330 :
1522 if (mStW) {
1523 PIWdg* cw = mStW->CurrentWdg();
1524 if (cw) DeleteBaseWidget((PIBaseWdg*)cw);
1525 }
1526 break;
1527
1528 default:
1529 cerr << "PIStdImgApp::MBProcess3() BUG?? Msg= " << msg << endl;
1530 break;
1531 }
1532return;
1533}
1534
1535/* --Methode-- */
1536void PIStdImgApp::MBProcess4(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1537{
1538
1539switch (msg) {
1540
1541 case 10400 :
1542 CreateStackWin();
1543 break;
1544
1545 case 10411 :
1546 CreateGraphWin(1,1);
1547 break;
1548 case 10421 :
1549 CreateGraphWin(1,2);
1550 break;
1551 case 10412 :
1552 CreateGraphWin(2,1);
1553 break;
1554 case 10422 :
1555 CreateGraphWin(2,2);
1556 break;
1557 case 10431 :
1558 CreateGraphWin(1,3);
1559 break;
1560 case 10433 :
1561 CreateGraphWin(3,3);
1562 break;
1563 case 10441 :
1564 if (mCurWdg) {
1565 mLastWdg = mCurWdg;
1566 cout << " Using current widget as last-widget (display same) " << endl;
1567 }
1568 else cout << " No current widget - select widget with mouse " << endl;
1569 break;
1570 case 10460 :
1571 DeleteWindow(mCurWin);
1572 break;
1573 case 10470 :
1574 StatZoomWindowSetVisible(m[3]->GetStateMsg(10470));
1575 break;
1576 default:
1577 cerr << "PIStdImgApp::MBProcess4() BUG?? Msg= " << msg << endl;
1578 break;
1579 }
1580return;
1581}
1582
1583
1584/* --Methode-- */
1585void PIStdImgApp::MBProcess5(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1586{
1587char nomps[64],strg[512];
1588PSFile *mps;
1589int sxt, syt, syo, syo1, sx[4], sy[4];
1590
1591switch (msg)
1592 {
1593 case 10501 :
1594 pfc_ps->AcceptNewFile(true);
1595 mFCMsg = 10525;
1596 pfc_ps->SetMsg(mFCMsg);
1597 SetBlocked();
1598 pfc_ps->Show();
1599 break;
1600
1601 case 10525 :
1602 SetBusy();
1603 if (data) {
1604 if (mpsfile) {
1605 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1606 delete mpsfile;
1607 }
1608 name_ps = pfc_ps->GetFileName();
1609 printf("PIStdImg/Info: Opening PS-File %s \n", name_ps.c_str());
1610 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 2., 2.);
1611 }
1612 mFCMsg = 0;
1613 SetReady();
1614 break;
1615
1616 case 10505 :
1617 if (!mpsfile) break;
1618 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1619 delete mpsfile;
1620 mpsfile = NULL;
1621 name_ps = "";
1622 break;
1623
1624 case 10511 : // Window -> PS
1625 case 10512 : // Window -> EPS
1626 if (CurrentWindow() == NULL) break;
1627 if (msg == 10512)
1628 {
1629 num_eps++;
1630 sprintf(nomps,"pia%d.eps", num_eps);
1631 printf("PIStdImg/Info: Creating EPSFile %s (CurWin-> EPS) \n", nomps);
1632 mps = new PSFile(nomps);
1633 }
1634 else {
1635 if (mpsfile == NULL) {
1636 name_ps = "pia.ps";
1637 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 0., 0.);
1638 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1639 }
1640 printf("PIStdImg/Info: CurWin-> PSFile %s\n", name_ps.c_str());
1641 mps = mpsfile;
1642 }
1643 CurrentWindow()->PSPrint(mps,0,0);
1644
1645 if (msg == 10512) delete mps; // fichier eps
1646 break;
1647
1648 case 10515 : // Image -> PS
1649 case 10516 : // Image -> EPS
1650 {
1651 PIImage* curpimg = NULL;
1652 if (!mCurWdg) return;
1653 if (mCurWdg->kind() != PIImage::ClassId) return;
1654 curpimg = (PIImage*)mCurWdg;
1655 if (curpimg == NULL) return;
1656 if (msg == 10516)
1657 {
1658 num_eps++;
1659 sprintf(nomps,"pia%d.eps", num_eps);
1660 printf("PIStdImg/Info: Creating EPSFile %s (CurImage-> EPS)\n", nomps);
1661 mps = new PSFile(nomps);
1662 }
1663 else {
1664 if (mpsfile == NULL) {
1665 name_ps = "pia.ps";
1666 mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
1667 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1668 }
1669 printf("PIStdImg/Info: CurImage-> PSFile %s\n", name_ps.c_str());
1670 mps = mpsfile;
1671 }
1672
1673 sx[0] = gimv->XSize();
1674 sy[0] = gimv->YSize();
1675 sx[1] = zoom->XSize();
1676 sy[1] = zoom->YSize();
1677 sx[2] = cmapv->XSize();
1678 sy[2] = cmapv->YSize();
1679 sx[3] = curpimg->XSize();
1680 sy[3] = curpimg->YSize();
1681 if (sy[1] > sy[0]) { syo1 = sy[1]+50; syo = sy[1]+sy[2]+60; }
1682 else { syo1 = sy[0]+50; syo = sy[0]+sy[2]+60; }
1683 syt = sy[3]+syo;
1684 sxt = sx[3];
1685 if (sxt < (sx[0]+sx[1]+20)) sxt = sx[0]+sx[1]+20;
1686 if (sxt < sx[2]) sxt = sx[2];
1687
1688 // Pour ecrire le titre
1689 mps->NewPage((float)sxt, (float)syt, PI_Portrait);
1690 mps->NewBloc(0,0, (float)sxt, 30., (float)sxt, 30.);
1691 sprintf(strg,"Image: %s - Pave %d %d \n", curpimg->Nom().c_str(),
1692 curpimg->XPave(), curpimg->YPave());
1693 mps->DrawString(10., 25., strg, PI_Black, PI_DefaultFont, PI_BoldFont, 20);
1694 mps->EndBloc();
1695
1696 // Les quatre fenetres glovimage, zoom, cmap, image
1697 gimv->PSPrint(mps, -gimv->XPos(), -gimv->YPos()+40);
1698 zoom->PSPrint(mps, -zoom->XPos()+sx[0]+20, -zoom->YPos()+40);
1699 cmapv->PSPrint(mps, -cmapv->XPos(), -cmapv->YPos()+syo1);
1700 curpimg->PSPrint(mps, -curpimg->XPos(), -curpimg->YPos()+syo);
1701
1702 if (msg == 10516) delete mps; // fichier eps
1703 break;
1704 }
1705
1706 default:
1707 cerr << "PIStdImgApp::MBProcess5() BUG?? Msg= " << msg << endl;
1708 break;
1709 }
1710
1711}
1712
1713
1714/* --Methode-- */
1715void PIStdImgApp::MBProcess6(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1716{
1717switch (msg) {
1718 case 10601:
1719 CloseAllWindows();
1720 break;
1721 case 10602:
1722 RedirectStdOutErr(*((bool*)data));
1723 break;
1724 case 10603:
1725 case 10604:
1726 CatchSignals(m[5]->GetStateMsg(10603), m[5]->GetStateMsg(10604));
1727 break;
1728 case 10605:
1729 mObjMgr->SetVerbose(m[5]->GetStateMsg(10605));
1730 break;
1731 case 10606:
1732 mCmd->ShowCxxOptionWindow();
1733 break;
1734 default:
1735 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
1736 break;
1737 }
1738return;
1739}
1740
1741
1742
1743// -------------------------------------------------
1744// Fenetre info piapp (About piapp)
1745// -------------------------------------------------
1746static PIWindow* infow_win = NULL;
1747static PIText* infow_txt = NULL;
1748static PICMapView* infow_cmap = NULL;
1749static PIButton* infow_but = NULL;
1750
1751/* Nouvelle-Fonction */
1752static void createInfoWindow(PIStdImgApp* app)
1753{
1754if (infow_win) return;
1755
1756int bsx, bsy;
1757PIApplicationPrefCompSize(bsx, bsy);
1758int spx, spy;
1759spx = bsx/6; spy = bsy/6;
1760
1761infow_win = new PIWindow((PIMsgHandler *)app, "About piapp",
1762 PIWK_dialog, bsx*5+3*spx, bsy*4+spy*3, 200, 200);
1763infow_win->SetAutoDelChilds(true);
1764infow_txt = new PIText(infow_win,"about_piapp_text", bsx*5+spx, bsy*3, spx, spy);
1765infow_txt->SetMutiLineMode(true);
1766infow_txt->SetTextEditable(false);
1767infow_txt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
1768infow_cmap = new PICMapView(infow_win, "about_piapp_cmap", bsx*4, bsy*0.7, spx, 2*spy+bsy*3.15);
1769infow_cmap->SetColMapId(CMAP_COLBR32, 1., -1., false);
1770infow_cmap->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
1771infow_but = new PIButton(infow_win,"OK", 10155, bsx, bsy, bsx*4+2*spx, 2*spy+bsy*3);
1772infow_but->SetMsgParent((PIMsgHandler *)app);
1773infow_but->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
1774char buff[128];
1775#ifdef SANS_EVOLPLANCK
1776sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
1777 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
1778#else
1779{
1780sprintf(buff, "Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
1781 (double)PI_VERSIONNUMBER, glst_piai->Version());
1782}
1783#endif
1784string info = "piapp : Interactive analysis program\n";
1785info += buff;
1786info += "(C) LAL-IN2P3/CNRS 1996-2002\n";
1787info += "(C) SPP-DAPNIA/CEA 1996-2002\n";
1788infow_txt->SetText(info);
1789}
1790
1791/* Nouvelle-Fonction */
1792static void showInfoWindow(PIStdImgApp* app)
1793{
1794if (!infow_win) createInfoWindow(app);
1795if (infow_win) infow_win->Show();
1796}
1797/* Nouvelle-Fonction */
1798static void hideInfoWindow(PIStdImgApp* app)
1799{
1800if (infow_win) infow_win->Hide();
1801}
1802
1803/* Nouvelle-Fonction */
1804static void deleteInfoWindow()
1805{
1806if (!infow_win) return;
1807delete infow_win;
1808infow_win = NULL;
1809infow_txt = NULL;
1810infow_cmap = NULL;
1811infow_but = NULL;
1812}
1813
1814
Note: See TracBrowser for help on using the repository browser.