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

Last change on this file since 2616 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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