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

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

Corrections diveres suite pb imagnav - Reza 27/5/2005

  • Property svn:executable set to *
File size: 61.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;
[2701]457 while (XtAppPending(*appctx) != 0) { // Boucle XtAppPending()
458 try {
459 XtAppNextEvent(*appctx, &evt);
460 XtDispatchEvent(&evt);
461 // Soumission de la commande exterieur a executer
462 if (fg_exc_cmd) {
463 fg_exc_cmd = false;
464 CmdInterpreter()->AddInputLine(exc_command);
465 }
466 nevtproc++;
467 if (nevtproc >= 200) break;
[2673]468 }
[2701]469 catch ( PThrowable & exc ) {
470 cerr << "\nPIStdImgApp::Run()/ Exception catched in event loop: \n "
471 << (string)typeid(exc).name() << " Msg= " << exc.Msg() << endl;
472 cerr << " Trying to continue event loop ... " << endl;
473 }
474 catch ( std::exception & sexc ) {
475 cerr << "\nPIStdImgApp::Run()/ Exception catched in event loop: \n "
476 << (string)typeid(sexc).name() << " what()= " << sexc.what() << endl;
477 cerr << " Trying to continue event loop ... " << endl;
478 }
479 catch ( ... ) {
480 cerr << "\nPIStdImgApp::Run()/ Unknown Exception (...) catched in event loop ! " << endl;
481 cerr << " Trying to continue event loop ... " << endl;
482 }
483 } // FIN Boucle XtAppPending()
[2490]484 fg_glsynlock = false;
[2492]485 //DBG cout << " "DBG-Run:: Going to wait ... " << klp << endl;
[2491]486 thr_glsyn.wait(); // <ZThread>
[2492]487 //DBG cout << "DBG-Run:: Out of wait " << ++klp << endl;
[2491]488 // usleep(1000);
[2486]489}
[2489]490
[2491]491thr_glsyn.unlock(); // <ZThread>
492mrv->Stop();
493delete mrv;
494// delete mru;
[2486]495return;
496}
497
498/* --Methode-- */
[165]499void PIStdImgApp::Process(PIMessage msg, PIMsgHandler* sender, void* data)
500{
501PIWdg *sndw;
502PIMessage tmsg, smm;
503
504tmsg = msg;
505msg = UserMsg(msg);
506smm = ModMsg(tmsg);
507
508//printf("SuperDebug: msg=%d Mod=%d State=%d\n", (int)msg, (int)smm, (int)GetState());
509if ((GetState()) && (msg != mFCMsg)) { PIBeep(); return; }
510
[2606]511#ifdef SANS_EVOLPLANCK
512 TRY {
513#else
514 try {
515#endif
516
[165]517// Messages active-window
518if (smm == PIMsg_Active)
519 {
[293]520 sndw = dynamic_cast<PIWdg *>(sender);
[165]521 switch(sndw->kind())
522 {
523 case PIWindow::ClassId :
[293]524 mCurWin = dynamic_cast<PIWindow *>(sndw);
[165]525 break;
526
527 case PIScDrawWdg::ClassId :
528 case PIDraw3DWdg::ClassId :
[293]529 mCurWdg = dynamic_cast<PIBaseWdg *>(sender);
[165]530// cerr << "*DBG11* ImgTools -> NonSensitive " << sndw->kind() << endl;
531 if (mFgCWImg) {
532// cerr << "*DBG* ImgTools -> NonSensitive " << endl;
[1590]533 m[2]->SetSensitivityMsg(10311, false);
534 m[2]->SetSensitivityMsg(10312, false);
535 m[2]->SetSensitivityMsg(10313, false);
[165]536 m[4]->SetSensitivityMsg(10515, false);
537 m[4]->SetSensitivityMsg(10516, false);
538 mFgCWImg = false;
539 }
540 break;
541 case PIImage::ClassId :
[293]542 mCurWdg = dynamic_cast<PIBaseWdg *>(sender);
[165]543 if (!mFgCWImg) {
544// cerr << "*DBG* ImgTools -> Sensitive " << endl;
[1590]545 m[2]->SetSensitivityMsg(10311, true);
546 m[2]->SetSensitivityMsg(10312, true);
547 m[2]->SetSensitivityMsg(10313, true);
[165]548 m[4]->SetSensitivityMsg(10515, true);
549 m[4]->SetSensitivityMsg(10516, true);
550 mFgCWImg = true;
551 }
552 break;
[293]553 /*
554 default :
555 mCurWdg = NULL;
556 if (mFgCWImg) {
[1590]557 m[2]->SetSensitivityMsg(10311, false);
558 m[2]->SetSensitivityMsg(10312, false);
559 m[2]->SetSensitivityMsg(10313, false);
[293]560 m[4]->SetSensitivityMsg(10515, false);
561 m[4]->SetSensitivityMsg(10516, false);
562 mFgCWImg = false;
563 }
564 break;
565 */
[165]566 }
567 }
568// Message window-close
569else if (smm == PIMsg_Close)
570 {
571 sndw = (PIWdg *)sender;
572 if(sndw->kind() == PIWindow::ClassId)
573 {
574 mCurWin = (PIWindow *)sender;
575 if (mCurWin == mStW) m[2]->SetSensitivity("StackTools", false);
576 DeleteWindow(mCurWin);
577 }
578 else
579 printf("PIStdImgApp/Bug ? CloseMsd received from NonWindow (%d %d %lx) \n",
580 (int)tmsg, (int)sndw->kind(), (long)sender);
581 }
582
583// Traitement des messages des menus
584else if ( (msg >= 10100) && (msg < 10200) ) MBProcess1(msg, sender, data);
585else if ( (msg >= 10200) && (msg < 10300) ) MBProcess2(msg, sender, data);
586else if ( (msg >= 10300) && (msg < 10400) ) MBProcess3(msg, sender, data);
587else if ( (msg >= 10400) && (msg < 10500) ) MBProcess4(msg, sender, data);
588else if ( (msg >= 10500) && (msg < 10600) ) MBProcess5(msg, sender, data);
589else if ( (msg >= 10600) && (msg < 10700) ) MBProcess6(msg, sender, data);
[2677]590else if ( (msg == 30200) && (smm == PIMsg_Cancel) ) // <Cntrl C> appuye sur Console
591 CmdInterpreter()->StopExecution();
592else if ( (msg == 30200 ) && (smm == PIMsg_OK) ){ // Objet PIConsole avec <Return>/<Enter>
[165]593 string s = mCons->GetCmdString();
[1265]594 // string s2 = "\nExecuting " + s + "\n";
595 mCons->AddStr("Cmd> ", PIVA_Blue, false);
596 // s2 = s + "\n";
597 mCons->AddStr(s.c_str(), PIVA_Blue|PIVA_Bold, false);
598 mCons->AddChar('\n', PIVA_Def, true);
[165]599 SetBusy();
[495]600#ifdef SANS_EVOLPLANCK
[165]601 TRY {
[293]602 mCmd->Interpret(s);
[165]603 } CATCH(merr) {
604 fflush(stdout);
605 cout << endl;
606 cerr << endl;
607 string es = PeidaExc(merr);
[495]608 cerr << "PIStdImgApp::Process()/ Cmd->Do() Exception :" << es << " (" << merr << ")" << endl ;
609 }
610#else
611 try {
[2486]612 // mCmd->Interpret(s);
[2489]613 CmdInterpreter()->AddInputLine(s);
[495]614 }
[1276]615 catch ( PThrowable & exc ) {
616 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
617 << (string)typeid(exc).name() << " Msg= "
618 << exc.Msg() << endl;
[495]619 cout << endl;
[165]620 }
[1276]621 catch ( ... ) {
622 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ..."
623 << endl;
624 cout << endl;
625 }
626
[495]627#endif
[165]628 SetReady();
629 }
630
631else printf("PIStdImgApp::Process() BUG?? Msg %d (%d-%d) \n",
632 (int)tmsg,(int)msg,(int)smm);
633
[2606]634#ifdef SANS_EVOLPLANCK
635} CATCH(merr) {
636 fflush(stdout);
637 cout << endl;
638 cerr << endl;
639 string es = PeidaExc(merr);
640 cerr << "PIStdImgApp::Process()/ Exception :" << es << " (" << merr << ")" << endl ;
641 SetReady();
642 }
643#else
644 }
645 catch ( PThrowable & exc ) {
646 cerr << "\n PIStdImgApp::Process() SOPHYA Exception :"
647 << (string)typeid(exc).name() << "\n Msg= "
648 << exc.Msg() << endl;
649 SetReady();
650 }
651 catch ( std::exception & sex ) {
652 cerr << "\n PIStdImgApp::Process() std::exception :"
653 << (string)typeid(sex).name() << "\n msg= "
654 << sex.what() << endl;
655 SetReady();
656 }
657 catch ( ... ) {
658 cerr << "\n PIStdImgApp::Process()/ Catched unknown (...) Exception " << endl;
659 SetReady();
660 }
[165]661
[2606]662#endif
663
[165]664return;
665}
666
[194]667/* --Methode-- */
668void PIStdImgApp::SetReady()
669{
670mCons->SetSensitive();
671gimv->SetSensitive();
672PIApplication::SetReady();
673}
[165]674
[194]675/* --Methode-- */
676void PIStdImgApp::SetBusy()
677{
678mCons->SetUnSensitive();
679gimv->SetUnSensitive();
680PIApplication::SetBusy();
[1321]681// Attention : Appel XSync specifique X11 - en attendant multi-thread
[2651]682// XSync(PIXDisplay(), False); RZDEL
[194]683}
[165]684
[194]685/* --Methode-- */
686void PIStdImgApp::SetBlocked()
687{
688mCons->SetUnSensitive();
689gimv->SetUnSensitive();
690PIApplication::SetBlocked();
[1321]691// Attention : Appel XSync specifique X11 - en attendant multi-thread
[2651]692// XSync(PIXDisplay(), False); RZDEL
[194]693}
[165]694
[2492]695class SyncPIS {
696public:
697 explicit SyncPIS(ZMutex & mtx, bool fglock=true, int sigbr=0)
698 {
699 _mtx = &mtx; _sigbr = sigbr;
700 _fglock = fglock;
701 if (_fglock) mtx.lock();
702 }
703 ~SyncPIS()
704 {
705 if (_fglock && (_mtx != NULL) ) {
706 if (_sigbr == 1) _mtx->signal();
707 else if (_sigbr == 2) _mtx->broadcast();
708 _mtx->unlock();
709 }
710 }
[194]711
[2492]712private:
713 ZMutex * _mtx;
714 int _sigbr;
715 bool _fglock;
716 inline SyncPIS() {_mtx = NULL; _sigbr = 0; _fglock = false; }
717};
718
719
[165]720/* --Methode-- */
[2491]721int PIStdImgApp::DispImage(P2DArrayAdapter* nouv, string const & name, string const& sop,
[2651]722 bool fgimagnav, int oid, bool fglock)
[165]723{
[2651]724PIImage* pii=NULL;
725PIImageNavigator* piin=NULL;
[165]726PIWindow* win;
727int sx, sy, px, py, flag;
728
729if (nouv == NULL)
730 {
731 printf("PIStdImgApp::DispImage_Error Cannot Display NULL image \n");
732 return(-1);
733 }
734
735if ( (nouv->XSize() <= 0) || (nouv->YSize() <= 0))
736 {
737 printf("PIStdImgApp::DispImage_Error Pb Size Sz=%d*%d \n",
738 nouv->XSize(), nouv->YSize());
739 return(-1);
740 }
741
[1971]742// On decode les options graphiques
743vector<string> opts;
744DispWinEnum dwopt = ParseDisplayOption(sop, opts);
[165]745
[1971]746// Pas de same ou inset pour DispImage
747if ((dwopt == Disp_Same) || (dwopt == Disp_Inset) ) dwopt = Disp_Next;
[165]748
[2486]749// <ZThread> global PIApplication event loop synchronisation
[2492]750SyncPIS zs(getMutex(), fglock, 2);
[2486]751
[1971]752// Choix de la taille de fenetre
753#define MINPIIMGSIZE 100
754sx = (nouv->XSize() > MINPIIMGSIZE) ? nouv->XSize() : MINPIIMGSIZE;
755sy = (nouv->YSize() > MINPIIMGSIZE) ? nouv->XSize() : MINPIIMGSIZE;
[165]756if (sx > 400+mFgScSz*100) sx = 400+mFgScSz*100;
757if (sy > 400+mFgScSz*100) sy = 400+mFgScSz*100;
758px = py = 0;
[1971]759win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
[2651]760if (fgimagnav) { // Creation de naviguateur d'image
761 piin = new PIImageNavigator(win, (char *)name.c_str(), sx, sy, px,py);
762 piin->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
[2778]763 piin->Show();
[2651]764 piin->ImageWdg()->ShowCursor(true);
765 pii = piin->ImageWdg();
[2762]766 piin->SetUserData(NULL, oid);
[2651]767 pii->SetUserData(NULL, oid);
768}
769else { // Creation de widget PIImage normal
770 pii = new PIImage(win, (char *)name.c_str(), sx, sy, px,py);
771 pii->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
772 pii->SetZoomWin(zoom, false);
773 pii->SetGloVWin(gimv, false);
774 pii->SetCMapWin(cmapv, false);
775 pii->ShowCursor(true);
776 pii->SetUserData(NULL, oid);
777}
[1971]778
[2778]779
780pii->SetImage(nouv, true, false);
781
782// decode des options en chaine de caracteres
783if (mAxesAtt.size() > 0)
784 pii->DecodeOptionString(mAxesAtt, false); // Les options d'axe
785if (mDefaultAtt.size() > 0)
786 pii->DecodeOptionString(mDefaultAtt, false); // d'abord les options par defaut
787if (opts.size() > 0)
788 pii->DecodeOptionString(opts); // ensuite, les options specifies en argument
789
[1971]790// On recalcule la taille de la fenetre si Disp_Win
791if (dwopt == Disp_Win) {
792 int sx2 = (int)((float)nouv->XSize()*pii->GetZoomF());
793 int sy2 = (int)((float)nouv->YSize()*pii->GetZoomF());
794
795 if (sx2 > 400+mFgScSz*100) sx2 = 400+mFgScSz*100;
796 if (sy2 > 400+mFgScSz*100) sy2 = 400+mFgScSz*100;
797 if (sx2 < MINPIIMGSIZE) sx = MINPIIMGSIZE;
798 if (sy2 < MINPIIMGSIZE) sy = MINPIIMGSIZE;
799 if ((sx2 != sx) || (sy2 != sy)) win->SetSize(sx2, sy2);
800}
801
[165]802// printf("!!DBG!! PIImage Pos= %d %d Size= %d %d \n", pii->XPos(), pii->YPos(), pii->XSize(), pii->YSize() );
803mCurWin = win;
804mCurWdg = pii;
805mLastWdg = pii;
806mBWId++;
[2778]807if (fgimagnav) mBWList[mBWId] = piin;
[2762]808else mBWList[mBWId] = pii;
[2118]809// pii->Refresh();
[2651]810 pii->Apply(true);
811 // cmapv->Refresh(); Pas besoin ? , Reza Fev 2005
[165]812return(mBWId);
813}
814
815
816/* --Methode-- */
[1971]817int PIStdImgApp::DispScDrawer(PIDrawer* scd, string const & name, string const& sop,
[2491]818 string title, int oid, bool fglock)
[165]819{
820if (scd == NULL)
821 {
822 printf("PIStdImgApp::DispScDrawer_Error Cannot Add NULL ScDrawer \n");
823 return(-1);
824 }
825
[1971]826// On decode les options graphiques
827vector<string> opts;
828DispWinEnum dwopt = ParseDisplayOption(sop, opts);
829if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
[2486]830
831// <ZThread> global PIApplication event loop synchronisation
[2492]832SyncPIS zs(getMutex(), fglock, 2);
[2486]833
[1971]834// Trace en superpoistion
835if ( (dwopt == Disp_Same) && (mLastWdg) ) {
836 // Les options
837 scd->DecodeOptionString(mDefaultAtt, false);
[2383]838 if (nb_disp_same > 0) {
839 vector<string> ostatpos;
840 int spo = nb_disp_same%4;
841 if (spo == 1) ostatpos.push_back("statposoff=-0.01,-0.26");
842 else if (spo == 2) ostatpos.push_back("statposoff=-0.36,-0.01");
843 else ostatpos.push_back("statposoff=-0.36,-0.26");
844 scd->DecodeOptionString(ostatpos, true);
845 }
[1971]846 scd->DecodeOptionString(opts, true);
[165]847
848 if (mLastWdg->kind() == PIScDrawWdg::ClassId) ((PIScDrawWdg*)mLastWdg)->AddScDrawer(scd, true);
849 else mLastWdg->AddDrawer(scd, true, true, true);
[548]850 scd->Refresh();
851 mDId++;
852 mDrwList[mDId] = scd;
853 return(-mDId);
854}
855// Trace en medaillon
[1971]856else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
[548]857 PIGrCoord x1, x2, y1, y2;
858 x1 = mIXmin; x2 = mIXmax;
859 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
[1971]860 // Les options
861 scd->DecodeOptionString(mDefaultAtt, false);
862 scd->DecodeOptionString(opts, true);
863
[548]864 scd->SetAxesFlags(mAxesFlags);
[1971]865 scd->UpdateLimits();
[548]866 mLastWdg->AddDrawer(scd, x1, y1, x2, y2, true, false, true);
[165]867 scd->Refresh();
868 mDId++;
869 mDrwList[mDId] = scd;
870 return(-mDId);
871}
872
[1971]873// Creation d'un nouveau PIScDrawWdg
[165]874PIWindow* win;
875PIScDrawWdg* scw;
876int sx, sy, px, py, flag;
877sx = 200+mFgScSz*100;
878sy = 200+mFgScSz*100;
[1971]879win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
880
[1856]881scw = new PIScDrawWdg(win, (char *)name.c_str(), sx, sy, px, py);
[165]882scw->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
[331]883scw->SetUserData(NULL, oid);
[1971]884
885// Decodage des options :
886vector<string> scwatt;
[203]887scw->SetAxesFlags(mAxesFlags);
[1971]888if ( mDefaultAtt.size() > 0) {
889 scwatt = mDefaultAtt;
[2217]890 scd->DecodeOptionString(scwatt, true);
[1971]891 scw->DecodeOptionString(scwatt, true);
892}
893if ( mAxesAtt.size() > 0) {
894 scwatt = mAxesAtt;
895 scw->DecodeOptionString(scwatt, true);
896}
897if (opts.size() > 0)
898 scd->DecodeOptionString(opts, true);
899if (opts.size() > 0)
900 scw->DecodeOptionString(opts, false);
901
[165]902// Titre du plot
[1131]903if (mAddTitle) {
904 if (title.length() <= 0) title = name; string t2="";
905 scw->SetTitles(title, t2);
906}
[1569]907
[1971]908scw->AddScDrawer(scd, true);
[293]909// scw->Refresh(); ? Pas necessaire Reza 19/08/98, 05/05/99 $CHECK$
[1971]910
[165]911mCurWin = win;
912mCurWdg = scw;
913mLastWdg = scw;
914mBWId++;
915mBWList[mBWId] = scw;
916return(mBWId);
917}
918
919/* --Methode-- */
[1971]920int PIStdImgApp::Disp3DDrawer(PIDrawer3D* dr3, string const & name, string const& sop,
[2491]921 string title, int oid, bool fglock)
[165]922{
923if (dr3 == NULL)
924 {
925 printf("PIStdImgApp::Disp3DDrawer_Error Cannot Add NULL 3DDrawer \n");
926 return(-1);
927 }
928
[1971]929// On decode les options graphiques
930vector<string> opts;
931DispWinEnum dwopt = ParseDisplayOption(sop, opts);
[165]932
[1971]933if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) ) dwopt = Disp_Next;
[2486]934
935// <ZThread> global PIApplication event loop synchronisation
[2492]936SyncPIS zs(getMutex(), fglock, 2);
[2486]937
[548]938// Trace en superpoistion
[1971]939if ( (dwopt == Disp_Same) && (mLastWdg) ) {
940 // Les options
941 dr3->DecodeOptionString(mDefaultAtt, false);
[2383]942 if (nb_disp_same > 1) {
943 vector<string> ostatpos;
944 int spo = nb_disp_same%4;
945 if (spo == 1) ostatpos.push_back("statposoff=-0.01,-0.26");
946 else if (spo == 2) ostatpos.push_back("statposoff=-0.36,-0.01");
947 else ostatpos.push_back("statposoff=-0.36,-0.26");
948 dr3->DecodeOptionString(ostatpos, true);
949 }
950
[1971]951 dr3->DecodeOptionString(opts, true);
952
[165]953 if (mLastWdg->kind() == PIDraw3DWdg::ClassId) ((PIDraw3DWdg*)mLastWdg)->AddDrawer3D(dr3, true);
954 else mLastWdg->AddDrawer(dr3, true, true, true);
955 dr3->Refresh();
956 mDId++;
957 mDrwList[mDId] = dr3;
958 return(-mDId);
959}
[548]960// Trace en medaillon
[1971]961else if ( (dwopt == Disp_Inset) && (mLastWdg) ) {
[548]962 PIGrCoord x1, x2, y1, y2;
963 x1 = mIXmin; x2 = mIXmax;
964 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
[1971]965 // Les options
966 dr3->DecodeOptionString(mDefaultAtt, false);
967 dr3->DecodeOptionString(opts, true);
968
[548]969 dr3->SetAxesFlags(mAxesFlags);
970 dr3->UpdateLimits();
971 mLastWdg->AddDrawer(dr3, x1, y1, x2, y2, true, false, true);
972 dr3->Refresh();
973 mDId++;
974 mDrwList[mDId] = dr3;
975 return(-mDId);
976}
[165]977
[548]978
[165]979PIWindow* win;
980int sx, sy, px, py, flag;
981sx = 200+mFgScSz*100;
982sy = 200+mFgScSz*100;
[1971]983win = GetWindow(dwopt, sx, sy, px, py, flag, (char *)name.c_str());
[165]984PIDraw3DWdg* wd3 = new PIDraw3DWdg(win, (char *)name.c_str(), sx, sy, px, py);
985wd3->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
[331]986wd3->SetUserData(NULL, oid);
[1971]987
988// Decodage des options :
989vector<string> scwatt;
990// wd3->SetAxesFlags(mAxesFlags); Attributs d'axes 3D a faire
991if ( mDefaultAtt.size() > 0) {
992 scwatt = mDefaultAtt;
[2217]993 dr3->DecodeOptionString(scwatt, true);
[1971]994 wd3->DecodeOptionString(scwatt, true);
995}
996if ( mAxesAtt.size() > 0) {
997 scwatt = mAxesAtt;
998 wd3->DecodeOptionString(scwatt, true);
999}
1000if (opts.size() > 0)
1001 dr3->DecodeOptionString(opts, true);
1002if (opts.size() > 0)
1003 wd3->DecodeOptionString(opts, false);
1004
[165]1005// Titre du plot
[1131]1006if (mAddTitle) {
1007 if (title.length() <= 0) title = name; string t2="";
1008 wd3->SetTitles(title, t2);
1009}
[1971]1010
1011wd3->AddDrawer3D(dr3, true);
[293]1012// wd3->Refresh(); ?Pas necessaire $CHECK$ 05/05/99
[1971]1013
[165]1014mCurWin = win;
1015mCurWdg = wd3;
1016mLastWdg = wd3;
1017mBWId++;
1018mBWList[mBWId] = wd3;
1019return(mBWId);
1020}
1021
[2489]1022// RZDEL: Normalement, il ne devrait plus y avoir besoin de cette
1023// methode avec le thread separe de l'interpreteur - Reza 27/12/2003
[349]1024/* --Methode-- */
[2188]1025int PIStdImgApp::ExecuteExtCommand()
1026{
1027if (!fg_exc_cmd) return(0);
1028else {
1029 fg_exc_cmd = false;
1030 return CmdInterpreter()->Interpret(exc_command);
1031 }
1032}
1033
1034/* --Methode-- */
[2263]1035void PIStdImgApp::AddText(string const & txt, double xp, double yp, string const& sop, bool fgcn)
[349]1036{
[2489]1037// <ZThread> global PIApplication event loop synchronisation
[2755]1038ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1039
[2165]1040PIDrawer *eld=CurrentElDrawer();
[1642]1041if (eld == NULL) return;
[2165]1042PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1043PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1044if ((eld2 == NULL) && (eld3 == NULL)) return;
1045PIElDrwMgr* elmgr;
1046if (eld2) elmgr = &(eld2->ElDrwMgr());
1047else if (eld3) elmgr = &(eld3->ElDrwMgr());
1048if (elmgr == NULL) return;
[1642]1049
[1971]1050vector<string> opts;
1051ParseDisplayOption(sop, opts);
1052PIGraphicAtt gratt(opts);
[2243]1053unsigned long tpd = 0;
1054gratt.DecodeTextPosDirAtt(opts, tpd, false);
[2263]1055elmgr->ElAddText(xp,yp,txt.c_str(), gratt, tpd, fgcn);
[1642]1056eld->Refresh();
[349]1057}
[1642]1058
[1131]1059/* --Methode-- */
[2263]1060void PIStdImgApp::AddCompText(string const & txt, string const & txtup, string const & txtdn,
1061 double xp, double yp, string const& sop,
1062 string const& optss, bool fgcn)
1063{
[2489]1064// <ZThread> global PIApplication event loop synchronisation
[2755]1065ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1066
[2263]1067PIDrawer *eld=CurrentElDrawer();
1068if (eld == NULL) return;
1069PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1070PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1071if ((eld2 == NULL) && (eld3 == NULL)) return;
1072PIElDrwMgr* elmgr;
1073if (eld2) elmgr = &(eld2->ElDrwMgr());
1074else if (eld3) elmgr = &(eld3->ElDrwMgr());
1075if (elmgr == NULL) return;
1076
1077vector<string> opts;
1078ParseDisplayOption(sop, opts);
1079PIGraphicAtt gratt(opts);
1080unsigned long tpd = 0;
1081gratt.DecodeTextPosDirAtt(opts, tpd, false);
1082ParseDisplayOption(optss, opts);
1083PIGraphicAtt grattss(opts);
1084elmgr->ElAddCompText(xp,yp,txt.c_str(), gratt, txtup, txtdn, grattss, tpd, fgcn);
1085eld->Refresh();
1086}
1087
1088/* --Methode-- */
[2243]1089void PIStdImgApp::AddLine(double xp1, double yp1, double xp2, double yp2,
[2263]1090 string const& sop, bool fgarrow, bool fgcn)
[1642]1091{
[2489]1092// <ZThread> global PIApplication event loop synchronisation
[2755]1093ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1094
[2165]1095PIDrawer *eld=CurrentElDrawer();
[1642]1096if (eld == NULL) return;
[2165]1097PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1098PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1099if ((eld2 == NULL) && (eld3 == NULL)) return;
1100PIElDrwMgr* elmgr = NULL;
1101if (eld2) elmgr = &(eld2->ElDrwMgr());
1102else if (eld3) elmgr = &(eld3->ElDrwMgr());
1103if (elmgr == NULL) return;
[1642]1104
[1971]1105vector<string> opts;
1106ParseDisplayOption(sop, opts);
1107PIGraphicAtt gratt(opts);
[2243]1108if (fgarrow)
[2263]1109 elmgr->ElAddArrow(xp1, yp1, xp2, yp2, gratt, fgcn);
1110else elmgr->ElAddLine(xp1, yp1, xp2, yp2, gratt, fgcn);
[1642]1111eld->Refresh();
1112}
1113
1114/* --Methode-- */
[1971]1115void PIStdImgApp::AddRectangle(double xp1, double yp1, double xp2, double yp2,
[2263]1116 string const& sop, bool fgfill, bool fgcn)
[1642]1117{
[2489]1118// <ZThread> global PIApplication event loop synchronisation
[2755]1119ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1120
[2165]1121PIDrawer *eld=CurrentElDrawer();
[1642]1122if (eld == NULL) return;
[2165]1123PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1124PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1125if ((eld2 == NULL) && (eld3 == NULL)) return;
1126PIElDrwMgr* elmgr = NULL;
1127if (eld2) elmgr = &(eld2->ElDrwMgr());
1128else if (eld3) elmgr = &(eld3->ElDrwMgr());
[1642]1129
1130double xp,yp;
1131double dx, dy;
1132if (xp1 < xp2) {
1133 xp = xp1; dx = xp2-xp1;
1134}
1135else {
1136 xp = xp2; dx = xp1-xp2;
1137}
1138if (yp1 < yp2) {
1139 yp = yp1; dy = yp2-yp1;
1140}
1141else {
1142 yp = yp2; dy = yp1-yp2;
1143}
[1971]1144
1145vector<string> opts;
1146ParseDisplayOption(sop, opts);
1147PIGraphicAtt gratt(opts);
1148
[2263]1149if (fgfill) elmgr->ElAddFRect(xp, yp, dx, dy, gratt, fgcn);
1150else elmgr->ElAddRect(xp, yp, dx, dy, gratt, fgcn);
[1642]1151eld->Refresh();
1152}
1153
1154/* --Methode-- */
[2263]1155void PIStdImgApp::AddCircle(double xc, double yc, double r, string const& sop,
1156 bool fgfill, bool fgcn)
[1642]1157{
[2489]1158// <ZThread> global PIApplication event loop synchronisation
[2755]1159ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1160
[2165]1161PIDrawer *eld=CurrentElDrawer();
[1642]1162if (eld == NULL) return;
[2165]1163PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1164PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1165if ((eld2 == NULL) && (eld3 == NULL)) return;
1166PIElDrwMgr* elmgr = NULL;
1167if (eld2) elmgr = &(eld2->ElDrwMgr());
1168else if (eld3) elmgr = &(eld3->ElDrwMgr());
[1642]1169
[1971]1170vector<string> opts;
1171ParseDisplayOption(sop, opts);
1172PIGraphicAtt gratt(opts);
[2243]1173if (r < -0.5)
1174 elmgr->ElAddMarker(xc, yc, gratt);
1175else {
[2263]1176 if (fgfill) elmgr->ElAddFCirc(xc, yc, r, gratt, fgcn);
1177 else elmgr->ElAddCirc(xc, yc, r, gratt, fgcn);
[2243]1178}
1179eld->Refresh();
1180}
[2265]1181/* --Methode-- */
[2638]1182void PIStdImgApp::AddOval(double xp, double yp, double dx, double dy,
1183 string const& sop, bool fgfill, bool fgcn)
1184{
1185// <ZThread> global PIApplication event loop synchronisation
[2755]1186ZSync zs(thr_glsyn, 2); zs.NOp();
[2638]1187
1188PIDrawer *eld=CurrentElDrawer();
1189if (eld == NULL) return;
1190PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1191PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1192if ((eld2 == NULL) && (eld3 == NULL)) return;
1193PIElDrwMgr* elmgr = NULL;
1194if (eld2) elmgr = &(eld2->ElDrwMgr());
1195else if (eld3) elmgr = &(eld3->ElDrwMgr());
1196
1197
1198vector<string> opts;
1199ParseDisplayOption(sop, opts);
1200PIGraphicAtt gratt(opts);
1201
1202if (fgfill) elmgr->ElAddFOval(xp, yp, dx, dy, gratt, fgcn);
1203else elmgr->ElAddOval(xp, yp, dx, dy, gratt, fgcn);
1204eld->Refresh();
1205}
1206
1207/* --Methode-- */
[2265]1208void PIStdImgApp::AddArc(double xc, double yc, double r, double a, double da,
1209 string const& sop, bool fgfill, bool fgcn)
1210{
[2489]1211// <ZThread> global PIApplication event loop synchronisation
[2755]1212ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1213
[2265]1214PIDrawer *eld=CurrentElDrawer();
1215if (eld == NULL) return;
1216PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1217PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1218if ((eld2 == NULL) && (eld3 == NULL)) return;
1219PIElDrwMgr* elmgr = NULL;
1220if (eld2) elmgr = &(eld2->ElDrwMgr());
1221else if (eld3) elmgr = &(eld3->ElDrwMgr());
[1971]1222
[2265]1223vector<string> opts;
1224ParseDisplayOption(sop, opts);
1225PIGraphicAtt gratt(opts);
1226if (fgfill) elmgr->ElAddFArc(xc, yc, r, a, da, gratt, fgcn);
1227else elmgr->ElAddArc(xc, yc, r, a, da, gratt, fgcn);
1228eld->Refresh();
1229}
1230
[2243]1231/* --Methode-- */
1232void PIStdImgApp::AddArc(double x1, double y1, double x2, double y2,
[2263]1233 double x3, double y3, string const& sop, bool fgfill, bool fgcn)
[2243]1234{
[2489]1235// <ZThread> global PIApplication event loop synchronisation
[2755]1236ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1237
[2243]1238PIDrawer *eld=CurrentElDrawer();
1239if (eld == NULL) return;
1240PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1241PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1242if ((eld2 == NULL) && (eld3 == NULL)) return;
1243PIElDrwMgr* elmgr = NULL;
1244if (eld2) elmgr = &(eld2->ElDrwMgr());
1245else if (eld3) elmgr = &(eld3->ElDrwMgr());
1246if (elmgr == NULL) return;
1247
1248vector<string> opts;
1249ParseDisplayOption(sop, opts);
1250PIGraphicAtt gratt(opts);
1251if (fgfill)
[2263]1252 elmgr->ElAddFArc(x1, y1, x2, y2, x3, y3, gratt, fgcn);
1253else elmgr->ElAddArc(x1, y1, x2, y2, x3, y3, gratt, fgcn);
[1642]1254eld->Refresh();
1255}
1256
1257/* --Methode-- */
[2263]1258void PIStdImgApp::AddPoly(vector<double>& xpol, vector<double>& ypol,
1259 string const& sop, bool fgfill, bool fgcn)
1260{
[2489]1261// <ZThread> global PIApplication event loop synchronisation
[2755]1262ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1263
[2263]1264PIDrawer *eld=CurrentElDrawer();
1265if (eld == NULL) return;
1266PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1267PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1268if ((eld2 == NULL) && (eld3 == NULL)) return;
1269PIElDrwMgr* elmgr = NULL;
1270if (eld2) elmgr = &(eld2->ElDrwMgr());
1271else if (eld3) elmgr = &(eld3->ElDrwMgr());
1272if (elmgr == NULL) return;
1273
1274vector<string> opts;
1275ParseDisplayOption(sop, opts);
1276PIGraphicAtt gratt(opts);
1277if (fgfill)
1278 elmgr->ElAddFPoly(xpol, ypol, gratt, fgcn);
1279else elmgr->ElAddPoly(xpol, ypol, gratt, fgcn);
1280eld->Refresh();
1281
1282}
1283
1284
1285/* --Methode-- */
[2165]1286void PIStdImgApp::SetTitle(string const & titletop, string const & titlebottom, string const& sop)
[1131]1287{
[2489]1288// <ZThread> global PIApplication event loop synchronisation
[2755]1289ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1290
[2165]1291PIDrawer *eld=CurrentElDrawer();
[1642]1292if (eld == NULL) return;
[2165]1293PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1294PIElDrawer3D* eld3 = dynamic_cast<PIElDrawer3D *>(eld);
1295if ((eld2 == NULL) && (eld3 == NULL)) return;
[1642]1296
[2165]1297vector<string> opts;
1298ParseDisplayOption(sop, opts);
1299PIGraphicAtt gratt(opts);
1300
1301if (eld2) {
1302 eld2->SetTitles(titletop, titlebottom, gratt);
1303 eld2->ShowTitles(true);
1304}
1305else if (eld3) {
1306 eld3->SetTitles(titletop, titlebottom, gratt);
1307 eld3->ShowTitles(true);
1308}
[1642]1309eld->Refresh();
1310}
[2165]1311/* --Methode-- */
1312void PIStdImgApp::SetAxeLabels(string const & xLabel, string const & yLabel, string const& sop)
1313{
[2489]1314// <ZThread> global PIApplication event loop synchronisation
[2755]1315ZSync zs(thr_glsyn, 2); zs.NOp();
[2489]1316
[2165]1317PIDrawer *eld=CurrentElDrawer();
1318if (eld == NULL) return;
1319PIElDrawer* eld2 = dynamic_cast<PIElDrawer *>(eld);
1320if (eld2 == NULL) return;
[1642]1321
[2165]1322vector<string> opts;
1323ParseDisplayOption(sop, opts);
1324PIGraphicAtt gratt(opts);
1325
1326eld2->SetAxesLabels(xLabel, yLabel, gratt);
1327eld2->ShowAxesLabels(true);
1328
1329eld->Refresh();
1330}
1331
[1642]1332/* --Methode-- */
[2165]1333PIDrawer* PIStdImgApp::CurrentElDrawer()
[1642]1334{
[2165]1335PIDrawer *eld=NULL;
[1642]1336if (!mLastWdg) return(eld);
[1131]1337PIScDrawWdg* sdw=NULL;
1338PIDraw3DWdg* w3d=NULL;
1339PIImage* imgw;
1340switch(mLastWdg->kind()) {
1341 case PIScDrawWdg::ClassId :
1342 sdw = dynamic_cast<PIScDrawWdg *>(mLastWdg);
1343 if (sdw) eld = sdw->BaseDrawer();
1344 break;
1345 case PIDraw3DWdg::ClassId :
1346 w3d = dynamic_cast<PIDraw3DWdg *>(mLastWdg);
1347 if (w3d) eld = w3d->BaseDrawer();
1348 break;
1349 case PIImage::ClassId :
1350 imgw = dynamic_cast<PIImage *>(mLastWdg);
[1642]1351 if (imgw) eld = imgw->BaseDrawer();
[1131]1352 break;
1353 default :
1354 break;
1355 }
[1642]1356return(eld);
[1131]1357}
[165]1358
1359/* --Methode-- */
1360void PIStdImgApp::CreateGraphWin(int nx, int ny, int sx, int sy)
1361{
1362if (nx < 1) nx = 1;
1363if (ny < 1) ny = 1;
1364if (nx > 8) nx = 8;
1365if (ny > 8) ny = 8;
1366if ( (sx < 50) && (sy < 50) ) sx = sy = 400+mFgScSz*100;
1367char buff[64];
1368mWId++;
[210]1369int px, py;
1370MainWin()->GetScreenPos(px, py);
1371sprintf(buff, "PI-GraphicWin (%d)",mWId);
1372PIZoneWindow* win = new PIZoneWindow(this, buff, PIWK_normal, nx, ny, sx, sy, px+MainWin()->XSize()+30, 0);
[165]1373win->SetUserData(NULL, ny*10+nx); // UserFlag= nY*10 + nX
1374mWList[mWId*10+1] = (PIWindow*)win;
1375win->SetAutoDelChilds(true);
[293]1376// win->Show();
[165]1377mGrW = win;
1378mGrIdx = 0;
1379}
1380
1381/* --Methode-- */
1382void PIStdImgApp::CreateStackWin(int sx, int sy)
1383{
1384if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
1385char buff[64];
1386mWId++;
[210]1387int px, py;
1388MainWin()->GetScreenPos(px, py);
[165]1389sprintf(buff, "PI-StackWin (%d)",mWId);
[210]1390PIStackWindow* win = new PIStackWindow(this, buff, PIWK_normal, sx, sy, px+MainWin()->XSize()+30, 100);
[165]1391win->SetUserData(NULL, 9999); // UserFlag= 9999
1392mWList[mWId*10+2] = (PIWindow*)win;
1393win->SetAutoDelChilds(true);
[293]1394// win->Show();
[165]1395mStW = win;
1396m[2]->SetSensitivity("StackTools", true);
1397mStIdx = 0;
1398}
1399
1400/* --Methode-- */
[1971]1401PIWindow* PIStdImgApp::GetWindow(DispWinEnum typ, int& sx, int& sy, int& px, int& py, int& flag, char * nom)
[165]1402{
1403PIWindow* rw;
1404
1405switch (typ) {
1406 case Disp_Next : // Fenetre graphique courante
[1971]1407 case Disp_Default :
[165]1408 {
1409 if (mGrW == NULL) CreateGraphWin();
1410 int nx, ny;
1411 mGrW->NbZone(nx, ny);
1412 PIWdg* nw = mGrW->NextChildPosSize(px, py, sx, sy);
1413// cerr << "**DBG** PIStdImgApp::GetWindow() DispNext : nw = " << (long)nw << endl;
[2651]1414 if (nw) DeleteWidget(nw, false, false);
[165]1415 flag = mGrIdx;
1416 mGrIdx = (mGrIdx+1)%(nx*ny);
1417 rw = mGrW;
1418 break;
1419 }
1420
1421 case Disp_Stack : // Fenetre de type stack (empilement)
1422 {
1423 if (mStW == NULL) CreateStackWin(sx, sy);
1424 px = py = 0;
1425 sx = mStW->XSize();
1426 sy = mStW->YSize();
1427 flag = mStIdx;
1428 mStIdx++;
1429 rw = mStW;
1430 }
1431 break;
1432
1433 default : // Fenetre ordinaire
1434 {
[210]1435 int pwx, pwy;
1436 MainWin()->GetScreenPos(pwx, pwy);
[165]1437 if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
[210]1438 rw = new PIWindow(this, nom, PIWK_normal, sx, sy, pwx+MainWin()->XSize()+30, 300);
[165]1439 rw->SetUserData(NULL, 0); // UserFlag= 0
1440 mWId++;
1441 mWList[mWId*10] = rw;
1442 rw->SetAutoDelChilds(true);
[293]1443 // rw->Show();
[165]1444 px = py = 0;
1445 flag = 0;
1446 break;
1447 }
1448 }
1449
[293]1450rw->Show();
[165]1451mCurWin = rw;
1452return(rw);
1453}
1454
1455/* --Methode-- */
1456void PIStdImgApp::SetZone(int nzx, int nzy)
1457{
1458if (!mGrW) CreateGraphWin(nzx, nzy);
1459else {
1460 int k;
1461 PIWdg* cwd;
1462 for(k=0; k<mGrW->NbChilds(); k++) {
1463 if ((cwd = mGrW->GetChild(k)) == NULL) continue;
[2651]1464 DeleteWidget(cwd, false, false);
[165]1465 }
1466 mGrW->SetZone(nzx, nzy);
1467 }
1468}
1469
1470/* --Methode-- */
1471void PIStdImgApp::StackWinNext()
1472{
1473if (mStW) mStW->DispNext();
1474}
1475
1476/* --Methode-- */
1477void PIStdImgApp::DeleteWindow(PIWindow* w)
1478{
1479if (w == NULL) return;
1480w->Hide();
[344]1481bool ownwindow=false; // To Check if this is one of our windows
[165]1482WindMList::iterator it;
1483for(it = mWList.begin(); it != mWList.end(); it++)
[344]1484 if ((*it).second == w) { mWList.erase(it); ownwindow = true; break; }
[165]1485if (w == mGrW) { mGrW = NULL; mGrIdx = -1; }
1486if (w == mStW) { mStW = NULL; mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
1487if (w == mCurWin) mCurWin = NULL;
[344]1488
1489if (!ownwindow) return; // We do nothing if this is not a window we have created ...
1490
[165]1491int k;
1492PIWdg* cwd;
1493for(k=0; k<w->NbChilds(); k++) {
1494 if ((cwd = w->GetChild(k)) == NULL) continue;
[2651]1495 DeleteWidget(cwd,false,false);
[165]1496 }
1497delete w;
1498return;
1499}
1500
1501/* --Methode-- */
[2651]1502void PIStdImgApp::DeleteWidget(PIWdg* w, bool dw, bool dwin)
[165]1503{
1504if (w == NULL) return;
1505BWMList::iterator it;
1506for(it = mBWList.begin(); it != mBWList.end(); it++)
1507 if ((*it).second == w) { mBWList.erase(it); break; }
[2762]1508PIBaseWdg* bw = NULL;
1509if (w->kind() == PIImageNavigator::ClassId) {
1510 PIImageNavigator* piin = dynamic_cast<PIImageNavigator *>(w);
1511 if (piin) bw = piin->ImageWdg();
1512}
1513else bw = dynamic_cast<PIBaseWdg *>(w);
[2651]1514if (bw != NULL) {
1515 PIDrawer* drw;
1516 int k;
1517 for(k=0; k<bw->NbDrawers(); k++) {
1518 if ((drw = bw->GetDrawer(k)) == NULL) continue;
1519 DrwMList::iterator itt;
1520 for(itt = mDrwList.begin(); itt != mDrwList.end(); itt++)
1521 if ((*itt).second == drw) { mDrwList.erase(itt); break; }
[165]1522 }
[2651]1523}
[165]1524
[2762]1525if ( (w == mCurWdg) || (bw == mCurWdg) ) {
[165]1526 mCurWdg = NULL;
1527 if (mFgCWImg) {
1528 m[4]->SetSensitivityMsg(10515, false);
1529 m[4]->SetSensitivityMsg(10516, false);
1530 mFgCWImg = false;
1531 }
1532 }
1533
[2762]1534if ( (w == mLastWdg) || (bw == mLastWdg) ) mLastWdg = NULL;
[165]1535
1536PIWdg* pw=NULL;
[2651]1537pw = (PIWdg*)(w->Parent());
1538//DBG printf("DeleteWidget(%lx)-DBG kind = %d - %d %d \n", (long)w, w->kind(), (int)dw, (int)dwin);
[2762]1539if (dw) delete w;
1540
1541if (dwin && pw) {
1542 PIWindow* pww = dynamic_cast<PIWindow *>(pw);
1543 if (pww && (pww != (PIWindow*)mGrW) && (pww != (PIWindow*)mStW) && (pww->NbChilds()==0))
[165]1544 DeleteWindow((PIWindow*)pw);
[2762]1545 }
[165]1546return;
1547}
1548
1549
1550
1551/* --Methode-- */
1552void PIStdImgApp::DelWRsId(int k)
1553{
1554//DBG cerr << "-DBG- PIStdImgApp::DelWRsId(" << k << ")" << endl;
1555if (k > 0) { // C'est un BaseWidget
1556 BWMList::iterator it;
1557 it = mBWList.find(k);
1558 if (it == mBWList.end()) return;
[2651]1559 PIWdg* wd = (*it).second;
[165]1560//DBG cerr << "-DBG- PIStdImgApp::DelWRsId Deleting BaseWidget " << (long)(wd) << endl ;
[2651]1561 DeleteWidget(wd, true, true);
[165]1562 }
1563else { // C'est un drawer
1564 DrwMList::iterator it;
1565 it = mDrwList.find(-k);
1566 if (it == mDrwList.end()) return;
[2231]1567 (*it).second->SetAutoRefreshOnDelete(true);
[165]1568 delete (*it).second;
1569 mDrwList.erase(it);
[2402]1570 //DBG cerr << "+DBG+ PIStdImgApp::DelWRsId Deleting Drawer " << (long)((*it).second) << endl ;
[165]1571 }
1572}
[368]1573/* --Methode-- */
1574bool PIStdImgApp::CheckWRsId(int k)
1575{
1576if (k > 0) { // C'est un BaseWidget
1577 BWMList::iterator it;
1578 it = mBWList.find(k);
1579 if (it == mBWList.end()) return(false);
1580 else return(true);
1581 }
1582else { // C'est un drawer
1583 DrwMList::iterator it;
1584 it = mDrwList.find(-k);
1585 if (it == mDrwList.end()) return(false);
1586 else return(true);
1587 }
1588}
[165]1589
[1971]1590/* --Methode-- */
1591void PIStdImgApp::StatZoomWindowSetVisible(bool fg)
1592{
[165]1593
[1971]1594 if (fg) {
[2778]1595 consolecont->Hide();
[1971]1596 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1597 int szy = MainWin()->YSize();
1598 MainWin()->SetSize(MainWin()->XSize(), szy+statcont->YSize());
1599 consolecont->SetPos(0, statcont->YSize());
1600 consolecont->SetSize(MainWin()->XSize(), szy);
1601 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
[2778]1602 consolecont->Show();
[1971]1603 statcont->Show();
1604 m[3]->SetStateMsg(10470, true);
1605 }
1606 else {
1607 statcont->Hide();
[2778]1608 consolecont->Hide();
[1971]1609 consolecont->SetBinding(PIBK_free,PIBK_free,PIBK_free, PIBK_free);
1610 MainWin()->SetSize(MainWin()->XSize(), MainWin()->YSize()-statcont->YSize());
1611 consolecont->SetPos(0, 0);
1612 consolecont->SetSize(MainWin()->XSize(), MainWin()->YSize());
1613 consolecont->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
[2778]1614 consolecont->Show();
[1971]1615 m[3]->SetStateMsg(10470, false);
1616 }
1617
1618}
1619
[165]1620/* --Methode-- */
[2106]1621void PIStdImgApp::UpdateStatResourceInfo()
1622{
1623 resusg.Update();
1624 char buff[256];
1625 string lab;
1626 double frac;
[2158]1627 sprintf(buff, "Mem: %ld/Max= %ld kb" , (long)resusg.getMemorySize(),
1628 (long)resusg.getMaxMemorySize());
[2106]1629 lab = buff;
1630 lab_mem->SetLabel(lab);
1631 frac = (double)resusg.getMemorySize()/(double)resusg.getMaxMemorySize();
1632 therm_mem->SetValue(frac);
1633
[2158]1634 sprintf(buff, "CPU: %ld/elap= %ld ms" , (long)resusg.getCPUTime(),
1635 (long)resusg.getElapsedTime());
[2106]1636 lab = buff;
1637 lab_cpu->SetLabel(lab);
[2259]1638 if (resusg.getCPULoad() > resusg.getAverageCPULoad())
1639 therm_cpu->SetValue(resusg.getCPULoad());
1640 else
1641 therm_cpu->SetValue(resusg.getAverageCPULoad());
[2486]1642 int nlx = 0;
1643 bool fgx = false;
[2489]1644 if ( CmdInterpreter() ) fgx = CmdInterpreter()->isRunning(nlx);
[2486]1645 if (!fgx) {
1646 lab = "PIACmdThread Idle";
1647 lab_thrcmd->SetLabel(lab);
1648 lab_thrcmd->SetForegroundColor(PI_Green);
1649 }
1650 else {
1651 sprintf(buff, "PIACmdThread Running - NL=%d" , nlx);
1652 lab = buff;
1653 lab_thrcmd->SetLabel(lab);
1654 if (nlx < 3) lab_thrcmd->SetForegroundColor(PI_Yellow);
1655 else lab_thrcmd->SetForegroundColor(PI_Red);
1656 }
[2106]1657}
1658
1659/* --Methode-- */
[165]1660void PIStdImgApp::RedirectStdOutErr(bool fg)
1661{
1662if (fg) {
1663 RedirectOutStream(mCons);
1664 RedirectErrStream(mCons);
1665 m[5]->SetStateMsg(10602, true);
[293]1666 redirecout = true;
[165]1667 }
1668else {
1669 RedirectOutStream(NULL);
1670 RedirectErrStream(NULL);
1671 m[5]->SetStateMsg(10602, false);
[293]1672 redirecout = false;
[165]1673 }
1674return;
1675}
1676
1677/* --Methode-- */
[374]1678void PIStdImgApp::CatchSignals(bool fgfpe, bool fgsegv)
[165]1679{
[912]1680#ifdef SANS_EVOLPLANCK
[374]1681PeidaConfigureSignalhandling(fgfpe, fgsegv, true, true);
[912]1682#else
1683SophyaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1684#endif
[374]1685m[5]->SetStateMsg(10603, fgfpe);
1686m[5]->SetStateMsg(10604, fgsegv);
[165]1687}
1688
1689/* --Methode-- */
1690void PIStdImgApp::CloseAllWindows()
1691{
1692WindMList::iterator it;
1693for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
1694mWList.clear();
1695mBWList.clear();
1696mDrwList.clear();
[454]1697mGrW = NULL;
1698mStW = NULL;
1699mCurWin = NULL;
1700mCurWdg = NULL;
1701mLastWdg = NULL;
1702m[4]->SetSensitivityMsg(10515, false);
1703m[4]->SetSensitivityMsg(10516, false);
[165]1704}
1705
[1971]1706//---------------------------------------------------------------------------
1707//--------- Gestion des attributs graphiques et autres options de trace -----
1708
[165]1709/* --Methode-- */
[1971]1710void PIStdImgApp::SetInsetLimits(double xmin, double xmax, double ymin, double ymax)
1711{
1712 mIXmin = xmin; mIXmax= xmax;
1713 mIYmin = ymin; mIYmax= ymax;
1714}
1715
1716/* --Methode-- */
1717void PIStdImgApp::SetDefaultGraphicAttributes(string const & opt)
1718{
1719 ParseDisplayOption(opt, mDefaultAtt);
1720}
1721
1722/* --Methode-- */
1723void PIStdImgApp::SetDefaultAxesAttributes(string const & opt)
1724{
1725 ParseDisplayOption(opt, mAxesAtt);
1726}
1727
1728/* --Methode-- */
1729DispWinEnum PIStdImgApp::ParseDisplayOption(string const & sop, vector<string>& opts)
1730{
1731 DispWinEnum rc = Disp_Next;
1732 //DBG cerr << " DBG-Parse-A sop=" << sop << " sop.length()= " << sop.length() << endl;
1733 if (opts.size() > 0) opts.erase(opts.begin(), opts.end());
1734 if (sop.length() < 1) return(rc);
1735 string gratt = sop;
1736 for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1737 if ( (gratt == "def") || (gratt == "default") ) return(rc);
1738// On separe en mots espaces par des blancs ou tabulation
1739 size_t p = 0;
1740 size_t q = 0;
1741 size_t l = gratt.length();
1742 string token;
1743 while (q < l) {
1744 p = gratt.find_first_not_of(" \t",q); // au debut d'un token
1745 if (p >= l) break;
1746 q = gratt.find_first_of(" \t",p); // Premier blanc ou tab suivant
1747 if (q<l) token = gratt.substr(p,q-p);
1748 else token = gratt.substr(p);
1749 if (token == "") continue;
1750 // Decodage option fenetre d'affichage (win, next, ...)
1751 if (token == "win") rc = Disp_Win;
1752 else if (token == "same") rc = Disp_Same;
1753 else if (token == "inset") rc = Disp_Inset;
1754 else if (token == "stack") rc = Disp_Stack;
[2118]1755 else if (token == "next") rc = Disp_Next;
[1971]1756 // Option a etre decode par les drawers, etc ...
1757 else opts.push_back(token);
1758 }
1759
1760 //DBG cerr << " DBG-Parse-B opts.size()=" << opts.size() << endl;
[2383]1761 if (rc == Disp_Same) nb_disp_same++;
1762 else nb_disp_same = 0;
[1971]1763 return (rc);
1764}
1765
1766//---------------------------------------------------------------------------
1767//------------ Methodes privees (MBProcessx, ...) ----------
1768
1769/* --Methode-- */
[165]1770void PIStdImgApp::MBProcess1(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1771{
1772
1773 switch(msg)
1774 {
[686]1775 case 10150 :
1776 showInfoWindow(this);
1777 break;
1778
1779 case 10155 :
1780 hideInfoWindow(this);
1781 break;
1782
[293]1783 case 10100 :
[2489]1784 CmdInterpreter()->ShowHelpWindow();
[293]1785 break;
1786
[165]1787 case 10120 :
[685]1788 pfc_fits->AcceptNewFile(false);
[165]1789 mFCMsg = 10125;
[685]1790 pfc_fits->SetMsg(mFCMsg);
[165]1791 SetBlocked();
[685]1792 pfc_fits->Show();
[165]1793 break;
1794
1795 case 10125 :
1796 SetBusy();
1797 if (data) {
[331]1798 string nomobj="";
[685]1799 ObjMgr()->ReadFits(pfc_fits->GetFileName(), nomobj);
[331]1800 ObjMgr()->DisplayObj(nomobj, "win");
[165]1801 }
1802 mFCMsg = 0;
1803 SetReady();
1804 break;
1805
1806 case 10130 :
[685]1807 pfc_ppf->AcceptNewFile(false);
[165]1808 mFCMsg = 10135;
[685]1809 pfc_ppf->SetMsg(mFCMsg);
[165]1810 SetBlocked();
[685]1811 pfc_ppf->Show();
[165]1812 break;
1813
1814 case 10135 :
1815 mFCMsg = 0;
1816 if (data) {
[685]1817 PPInMgrW()->SetFile(pfc_ppf->GetFileName());
[165]1818 PPInMgrW()->Show();
1819 }
1820 SetReady();
1821 break;
1822
[2263]1823#ifndef SANS_EVOLPLANCK
1824 case 10140 :
1825 pfc_ascii->AcceptNewFile(false);
1826 mFCMsg = 10145;
1827 pfc_ascii->SetMsg(mFCMsg);
1828 SetBlocked();
1829 pfc_ascii->Show();
1830 break;
1831
1832 case 10145 :
1833 SetBusy();
1834 if (data) {
1835 string afname = pfc_ascii->GetFileName();
1836 string nomobj = ObjMgr()->GetServiceObj()->FileName2Name(afname);
1837 string cmd = "mtxfrascii ";
1838 cmd += nomobj; cmd += " "; cmd += afname;
1839 try {
[2489]1840 CmdInterpreter()->AddInputLine(cmd);
1841 // mCmd->Interpret(cmd);
[2263]1842 }
1843 catch ( PThrowable & exc ) {
1844 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
1845 << (string)typeid(exc).name() << " Msg= "
1846 << exc.Msg() << endl;
1847 cout << endl;
1848 }
1849 catch ( ... ) {
1850 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ... " << endl;
1851 cout << endl;
1852 }
1853
1854 }
1855 mFCMsg = 0;
1856 SetReady();
1857 break;
1858#endif
1859
[165]1860 case 10105:
1861 Stop();
1862 break;
1863
1864 }
1865return;
1866}
1867
1868
1869
1870/* --Methode-- */
1871void PIStdImgApp::MBProcess2(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1872{
1873
1874switch (msg) {
1875 case 10201 :
1876 ObjMgrW()->Show();
1877 break;
1878
1879 case 10220 :
[685]1880 pfc_ppf->AcceptNewFile(true);
[165]1881 mFCMsg = 10225;
[685]1882 pfc_ppf->SetMsg(mFCMsg);
[165]1883 SetBlocked();
[685]1884 pfc_ppf->Show();
[165]1885 break;
1886
1887 case 10225 :
1888 SetBusy();
1889 if (data) {
1890 if (mPpfout) {
1891 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1892 delete mPpfout;
1893 }
[685]1894 name_outppf = pfc_ppf->GetFileName();
[165]1895 mPpfout = NULL;
1896 printf("PIStdImg/Info: Opening POutPersist-File %s \n", name_outppf.c_str());
1897 mPpfout = new POutPersist(name_outppf);
1898 }
1899 mFCMsg = 0;
1900 SetReady();
1901 break;
1902
1903 case 10230 :
1904 if (!mPpfout) break;
1905 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1906 delete mPpfout;
1907 name_outppf = "";
1908 mPpfout = NULL;
1909 break;
1910
[686]1911 case 10270 :
1912 if (mCurWdg) {
1913 int oid = mCurWdg->UserFlag();
[2762]1914 //RZDEL-Mai2005 DeleteWidget(mCurWdg);
[686]1915 mObjMgr->DelObj_Id(oid);
1916 }
1917 break;
[165]1918
1919 default:
1920 cerr << "PIStdImgApp::MBProcess2() BUG?? Msg= " << msg << endl;
1921 break;
1922}
1923
1924return;
1925}
1926
1927/* --Methode-- */
1928void PIStdImgApp::MBProcess3(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1929{
1930
1931switch (msg) {
1932 case 10301 :
1933 PIImgTools::ShowPIImgTools();
1934 break;
1935 case 10302 :
1936 PIDrwTools::ShowPIDrwTools();
1937 break;
[1590]1938 case 10303 :
1939 PIAxesTools::ShowPIAxesTools();
1940 break;
[165]1941
[1590]1942 case 10304 :
[2489]1943 CmdInterpreter()->ShowCxxExecWindow();
[1251]1944 break;
1945
[1590]1946 case 10311 :
1947 case 10312 :
[165]1948 {
1949 PIImage* curpimg = NULL;
1950 if (!mCurWdg) return;
1951 if (mCurWdg->kind() != PIImage::ClassId) return;
1952 curpimg = (PIImage*)mCurWdg;
1953 if (curpimg == NULL) return;
1954 P2DArrayAdapter* img = curpimg->Image();
1955 if (img == NULL) return;
1956 int dx = curpimg->XSzPave();
1957 int dy = curpimg->YSzPave();
1958 int x0 = curpimg->XPave()-dx/2;
1959 int y0 = curpimg->YPave()-dy/2;
1960 if (x0 < 0) x0 = 0;
1961 if (y0 < 0) y0 = 0;
1962 int x1 = x0+dx;
1963 int y1 = y0+dy;
1964 if (x1 > img->XSize()) x1 = img->XSize();
1965 if (y1 > img->YSize()) y1 = img->YSize();
1966 dx = x1-x0; dy = y1-y0;
1967 ImageR4* pim = new ImageR4(dx, dy);
1968 int ii, jj;
1969 for(jj=0; jj<dy; jj++)
1970 for(ii=0; ii<dx; ii++) (*pim)(ii,jj) = (*img)(ii+x0, jj+y0);
[338]1971 if (msg == 10305) { // Calcul des coordonnees du sous-pave
1972 double xc1, yc1;
1973 img->Coord(x0, y0, xc1, yc1);
1974 pim->SetOrg((int)xc1, (int)yc1);
1975 }
[165]1976 string nom = mCurWdg->Nom() + "_pave";
1977 ObjMgr()->AddObj(pim, nom);
1978 ObjMgr()->DisplayObj(nom, "w");
[293]1979 break;
[165]1980 }
1981
[1590]1982 case 10313 :
[293]1983 {
1984 PIImage* curpimg = NULL;
1985 if (!mCurWdg) return;
1986 if (mCurWdg->kind() != PIImage::ClassId) return;
1987 curpimg = (PIImage*)mCurWdg;
1988 if (curpimg == NULL) return;
1989 curpimg->ShowCuts(true);
1990 break;
1991 }
1992
[165]1993 case 10320 :
1994 if (mStW) mStW->DispNext();
1995 break;
1996
1997 case 10321 :
1998 case 10322 :
1999 case 10324 :
2000// case 10328 :
[191]2001 if (mStW) mStW->StartAutoDisp((msg-10320)*500);
[165]2002 break;
2003
2004 case 10329 :
2005 if (mStW) mStW->StopAutoDisp();
2006 break;
2007
2008 case 103330 :
2009 if (mStW) {
2010 PIWdg* cw = mStW->CurrentWdg();
[2651]2011 if (cw) DeleteWidget(cw);
[165]2012 }
2013 break;
2014
2015 default:
2016 cerr << "PIStdImgApp::MBProcess3() BUG?? Msg= " << msg << endl;
2017 break;
2018 }
2019return;
2020}
2021
2022/* --Methode-- */
2023void PIStdImgApp::MBProcess4(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
2024{
2025
2026switch (msg) {
2027
2028 case 10400 :
2029 CreateStackWin();
2030 break;
2031
2032 case 10411 :
2033 CreateGraphWin(1,1);
2034 break;
2035 case 10421 :
2036 CreateGraphWin(1,2);
2037 break;
2038 case 10412 :
2039 CreateGraphWin(2,1);
2040 break;
2041 case 10422 :
2042 CreateGraphWin(2,2);
2043 break;
2044 case 10431 :
2045 CreateGraphWin(1,3);
2046 break;
2047 case 10433 :
2048 CreateGraphWin(3,3);
2049 break;
[558]2050 case 10441 :
2051 if (mCurWdg) {
2052 mLastWdg = mCurWdg;
2053 cout << " Using current widget as last-widget (display same) " << endl;
2054 }
2055 else cout << " No current widget - select widget with mouse " << endl;
2056 break;
[686]2057 case 10460 :
2058 DeleteWindow(mCurWin);
2059 break;
[1971]2060 case 10470 :
2061 StatZoomWindowSetVisible(m[3]->GetStateMsg(10470));
2062 break;
[165]2063 default:
2064 cerr << "PIStdImgApp::MBProcess4() BUG?? Msg= " << msg << endl;
2065 break;
2066 }
2067return;
2068}
2069
2070
2071/* --Methode-- */
2072void PIStdImgApp::MBProcess5(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
2073{
2074char nomps[64],strg[512];
2075PSFile *mps;
2076int sxt, syt, syo, syo1, sx[4], sy[4];
2077
2078switch (msg)
2079 {
2080 case 10501 :
[685]2081 pfc_ps->AcceptNewFile(true);
[165]2082 mFCMsg = 10525;
[685]2083 pfc_ps->SetMsg(mFCMsg);
[165]2084 SetBlocked();
[685]2085 pfc_ps->Show();
[165]2086 break;
2087
2088 case 10525 :
2089 SetBusy();
2090 if (data) {
2091 if (mpsfile) {
2092 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
2093 delete mpsfile;
2094 }
[685]2095 name_ps = pfc_ps->GetFileName();
[165]2096 printf("PIStdImg/Info: Opening PS-File %s \n", name_ps.c_str());
2097 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 2., 2.);
2098 }
2099 mFCMsg = 0;
2100 SetReady();
2101 break;
2102
2103 case 10505 :
2104 if (!mpsfile) break;
2105 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
2106 delete mpsfile;
2107 mpsfile = NULL;
2108 name_ps = "";
2109 break;
2110
2111 case 10511 : // Window -> PS
2112 case 10512 : // Window -> EPS
2113 if (CurrentWindow() == NULL) break;
2114 if (msg == 10512)
2115 {
2116 num_eps++;
2117 sprintf(nomps,"pia%d.eps", num_eps);
2118 printf("PIStdImg/Info: Creating EPSFile %s (CurWin-> EPS) \n", nomps);
2119 mps = new PSFile(nomps);
2120 }
2121 else {
2122 if (mpsfile == NULL) {
2123 name_ps = "pia.ps";
2124 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 0., 0.);
2125 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
2126 }
2127 printf("PIStdImg/Info: CurWin-> PSFile %s\n", name_ps.c_str());
2128 mps = mpsfile;
2129 }
2130 CurrentWindow()->PSPrint(mps,0,0);
2131
2132 if (msg == 10512) delete mps; // fichier eps
2133 break;
2134
2135 case 10515 : // Image -> PS
2136 case 10516 : // Image -> EPS
2137 {
2138 PIImage* curpimg = NULL;
2139 if (!mCurWdg) return;
2140 if (mCurWdg->kind() != PIImage::ClassId) return;
2141 curpimg = (PIImage*)mCurWdg;
2142 if (curpimg == NULL) return;
2143 if (msg == 10516)
2144 {
2145 num_eps++;
2146 sprintf(nomps,"pia%d.eps", num_eps);
2147 printf("PIStdImg/Info: Creating EPSFile %s (CurImage-> EPS)\n", nomps);
2148 mps = new PSFile(nomps);
2149 }
2150 else {
2151 if (mpsfile == NULL) {
2152 name_ps = "pia.ps";
2153 mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
2154 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
2155 }
2156 printf("PIStdImg/Info: CurImage-> PSFile %s\n", name_ps.c_str());
2157 mps = mpsfile;
2158 }
2159
2160 sx[0] = gimv->XSize();
2161 sy[0] = gimv->YSize();
2162 sx[1] = zoom->XSize();
2163 sy[1] = zoom->YSize();
2164 sx[2] = cmapv->XSize();
2165 sy[2] = cmapv->YSize();
2166 sx[3] = curpimg->XSize();
2167 sy[3] = curpimg->YSize();
2168 if (sy[1] > sy[0]) { syo1 = sy[1]+50; syo = sy[1]+sy[2]+60; }
2169 else { syo1 = sy[0]+50; syo = sy[0]+sy[2]+60; }
2170 syt = sy[3]+syo;
2171 sxt = sx[3];
2172 if (sxt < (sx[0]+sx[1]+20)) sxt = sx[0]+sx[1]+20;
2173 if (sxt < sx[2]) sxt = sx[2];
2174
2175 // Pour ecrire le titre
2176 mps->NewPage((float)sxt, (float)syt, PI_Portrait);
2177 mps->NewBloc(0,0, (float)sxt, 30., (float)sxt, 30.);
2178 sprintf(strg,"Image: %s - Pave %d %d \n", curpimg->Nom().c_str(),
2179 curpimg->XPave(), curpimg->YPave());
[384]2180 mps->DrawString(10., 25., strg, PI_Black, PI_DefaultFont, PI_BoldFont, 20);
[165]2181 mps->EndBloc();
2182
2183 // Les quatre fenetres glovimage, zoom, cmap, image
2184 gimv->PSPrint(mps, -gimv->XPos(), -gimv->YPos()+40);
2185 zoom->PSPrint(mps, -zoom->XPos()+sx[0]+20, -zoom->YPos()+40);
2186 cmapv->PSPrint(mps, -cmapv->XPos(), -cmapv->YPos()+syo1);
2187 curpimg->PSPrint(mps, -curpimg->XPos(), -curpimg->YPos()+syo);
2188
2189 if (msg == 10516) delete mps; // fichier eps
2190 break;
2191 }
2192
2193 default:
2194 cerr << "PIStdImgApp::MBProcess5() BUG?? Msg= " << msg << endl;
2195 break;
2196 }
2197
2198}
2199
2200
2201/* --Methode-- */
2202void PIStdImgApp::MBProcess6(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
2203{
2204switch (msg) {
2205 case 10601:
2206 CloseAllWindows();
2207 break;
2208 case 10602:
2209 RedirectStdOutErr(*((bool*)data));
2210 break;
2211 case 10603:
[374]2212 case 10604:
2213 CatchSignals(m[5]->GetStateMsg(10603), m[5]->GetStateMsg(10604));
[165]2214 break;
[449]2215 case 10605:
2216 mObjMgr->SetVerbose(m[5]->GetStateMsg(10605));
2217 break;
[1251]2218 case 10606:
[2489]2219 CmdInterpreter()->ShowCxxOptionWindow();
[1251]2220 break;
[165]2221 default:
2222 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
2223 break;
2224 }
2225return;
2226}
2227
2228
[1569]2229
[686]2230// -------------------------------------------------
2231// Fenetre info piapp (About piapp)
2232// -------------------------------------------------
2233static PIWindow* infow_win = NULL;
2234static PIText* infow_txt = NULL;
2235static PICMapView* infow_cmap = NULL;
2236static PIButton* infow_but = NULL;
2237
2238/* Nouvelle-Fonction */
2239static void createInfoWindow(PIStdImgApp* app)
2240{
2241if (infow_win) return;
2242
2243int bsx, bsy;
2244PIApplicationPrefCompSize(bsx, bsy);
2245int spx, spy;
2246spx = bsx/6; spy = bsy/6;
2247
2248infow_win = new PIWindow((PIMsgHandler *)app, "About piapp",
2249 PIWK_dialog, bsx*5+3*spx, bsy*4+spy*3, 200, 200);
2250infow_win->SetAutoDelChilds(true);
2251infow_txt = new PIText(infow_win,"about_piapp_text", bsx*5+spx, bsy*3, spx, spy);
2252infow_txt->SetMutiLineMode(true);
2253infow_txt->SetTextEditable(false);
2254infow_txt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2255infow_cmap = new PICMapView(infow_win, "about_piapp_cmap", bsx*4, bsy*0.7, spx, 2*spy+bsy*3.15);
2256infow_cmap->SetColMapId(CMAP_COLBR32, 1., -1., false);
2257infow_cmap->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2258infow_but = new PIButton(infow_win,"OK", 10155, bsx, bsy, bsx*4+2*spx, 2*spy+bsy*3);
2259infow_but->SetMsgParent((PIMsgHandler *)app);
2260infow_but->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
2261char buff[128];
2262#ifdef SANS_EVOLPLANCK
2263sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
2264 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
2265#else
[692]2266{
[686]2267sprintf(buff, "Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
[692]2268 (double)PI_VERSIONNUMBER, glst_piai->Version());
2269}
[686]2270#endif
2271string info = "piapp : Interactive analysis program\n";
2272info += buff;
[2427]2273info += "(C) LAL-IN2P3/CNRS 1996-2003\n";
2274info += "(C) SPP-DAPNIA/CEA 1996-2003\n";
2275#ifndef SANS_EVOLPLANCK
2276 info += "Check http://www.sophya.org for more information";
2277#endif
[686]2278infow_txt->SetText(info);
2279}
2280
2281/* Nouvelle-Fonction */
2282static void showInfoWindow(PIStdImgApp* app)
2283{
[692]2284if (!infow_win) createInfoWindow(app);
2285if (infow_win) infow_win->Show();
[686]2286}
2287/* Nouvelle-Fonction */
2288static void hideInfoWindow(PIStdImgApp* app)
2289{
[692]2290if (infow_win) infow_win->Hide();
[686]2291}
2292
2293/* Nouvelle-Fonction */
2294static void deleteInfoWindow()
2295{
2296if (!infow_win) return;
2297delete infow_win;
2298infow_win = NULL;
2299infow_txt = NULL;
2300infow_cmap = NULL;
2301infow_but = NULL;
2302}
2303
[2106]2304
Note: See TracBrowser for help on using the repository browser.