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

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

Suite debugging gestion lock entre threads ds piapp - A l'air de

marcher sur OSF1 et Linux ... Reza 06/01/2004

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