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

Last change on this file since 2673 was 2673, checked in by ansari, 20 years ago

Remis en marche la possibilite d'execution d'un .pic au lancement de piapp - Reza 19/4/2005

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