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

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

Debut d'implementation piapp multi-thread - (avec des pb lors de l'execution de demo.pic) Reza 26 Dec 2003

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