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

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

Suite debug piapp multithread : on ne peut pas utiliser ZSync() ds un if (destructeur appele de suite) - Reza 06/01/2004

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