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

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

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