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

Last change on this file since 2489 was 2489, checked in by ansari, 22 years ago

Tentatives pour regler les conflits/plantage ds spiapp multi-thread/pb en particulier avec PIACmd::ShowMessage() appele lorsque traceon - Reza 29/12/2003

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