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

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

Suite des modifs pour piapp multi-threads
1) Ajout Mutex de synchronisation ds ls classe NamedObjMgr
2) Suite controle de gestion d'appel aux methodes de PIStdImgApp depuis
la classe elle-meme, a travers le NamedObjMgr
3) Modification de la boucle d'evenements, avec un thread de reveil
periodique

Reza, 4 Janvier 2004

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