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

Last change on this file since 1646 was 1642, checked in by ansari, 24 years ago

1/ Definition d'attributs graphiques texte pour les nouvelles couleurs violettes
2/ Ajout commandes addline addrect addfrect addfcircle ....

Reza 16/8/2001

  • Property svn:executable set to *
File size: 41.8 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5
6#include <typeinfo>
7
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"
21#include "pihisto2d.h"
22#include "psfile.h"
23#include "piimgtools.h"
24#include "pidrwtools.h"
25#include "piaxestools.h"
26
27#include "pistzwin.h"
28
29#include "piinit.h"
30#include "piversion.h"
31#include "piaversion.h"
32
33
34static char ImgDir[256];
35static char WorkDir[256];
36// Initialiseur
37static PIAppInitiator * glst_piai = NULL;
38
39// Pour la creation de fenetre info (about piapp)
40static void createInfoWindow(PIStdImgApp* app);
41static void deleteInfoWindow();
42static void showInfoWindow(PIStdImgApp* app);
43static void hideInfoWindow(PIStdImgApp* app);
44
45/* ........................................................... */
46/* Classe PIStdImgApp */
47/* ........................................................... */
48
49/* --Methode-- */
50PIStdImgApp::PIStdImgApp(int narg, char* arg[])
51: PIApplication(420, 320, narg, arg)
52{
53
54// Les menus
55m[0] = new PIMenu(Menubar(),"Fichier");
56m[0]->AppendItem("About piapp", 10150);
57m[0]->AppendItem("Open-Fits", 10120);
58m[0]->AppendItem("Open-PPF", 10130);
59// m[0]->AppendItem("Options", 10101);
60m[0]->AppendItem("Help", 10100);
61m[0]->AppendSeparator();
62m[0]->AppendItem("Exit", 10105);
63
64m[1] = new PIMenu(Menubar(),"Objets");
65m[1]->AppendItem("ObjectManager", 10201);
66m[1]->AppendItem("OpenOutPPF", 10220);
67m[1]->AppendItem("CloseOutPPF", 10230);
68m[1]->AppendItem("Delete CurWdg", 10270);
69
70m[2] = new PIMenu(Menubar(),"Tools");
71m[2]->AppendItem("Show ImageTools", 10301);
72m[2]->AppendItem("Show DrawerTools", 10302);
73m[2]->AppendItem("Show AxesTools", 10303);
74m[2]->AppendItem("CxxExecutorWindow", 10304);
75m[2]->AppendItem("Ext.Pave", 10311);
76m[2]->SetSensitivityMsg(10311, false);
77m[2]->AppendItem("Ext.Pave+Org", 10312);
78m[2]->SetSensitivityMsg(10312, false);
79m[2]->AppendItem("Cuts X,Y", 10313);
80m[2]->SetSensitivityMsg(10313, false);
81mc = new PIMenu(m[2], "StackTools");
82mc->AppendItem("DispNext", 10320);
83mc->AppendItem("Blink 0.5s", 10321);
84mc->AppendItem("Blink 1s", 10322);
85mc->AppendItem("Blink 2s", 10324);
86mc->AppendItem("Stop Blink", 10329);
87mc->AppendItem("RemoveCurrent", 10330);
88m[2]->AppendPDMenu(mc);
89m[2]->SetSensitivity("StackTools", false);
90
91m[3] = new PIMenu(Menubar(),"Window");
92m[3]->AppendItem("StackWindow", 10400);
93m[3]->AppendItem("Window", 10411);
94m[3]->AppendItem("Window 2x1", 10421);
95m[3]->AppendItem("Window 1x2", 10412);
96m[3]->AppendItem("Window 2x2", 10422);
97m[3]->AppendItem("Window 3x1", 10431);
98m[3]->AppendItem("Window 3x3", 10433);
99m[3]->AppendItem("Cur->LastWdg", 10441);
100m[3]->AppendItem("Close CurWin", 10460);
101
102m[4] = new PIMenu(Menubar(),"PostScript");
103m[4]->AppendItem("OpenPS", 10501);
104m[4]->AppendItem("ClosePS", 10505);
105m[4]->AppendItem("Window->PS", 10511);
106m[4]->AppendItem("Image->PS", 10515);
107m[4]->AppendItem("Window->EPS", 10512);
108m[4]->AppendItem("Image->EPS", 10516);
109m[4]->SetSensitivityMsg(10515, false);
110m[4]->SetSensitivityMsg(10516, false);
111
112m[5] = new PIMenu(Menubar(),"Special");
113m[5]->AppendItem("CloseAll", 10601);
114m[5]->AppendCheckItem("Red.Out/Err", 10602);
115m[5]->AppendCheckItem("Catch SigFPE", 10603);
116m[5]->AppendCheckItem("Catch SigSEGV", 10604);
117m[5]->AppendCheckItem("ObjMgr Verb", 10605);
118m[5]->AppendItem("CxxExecOption", 10606);
119
120m[6] = new PIMenu(Menubar(),"Modules");
121
122AppendMenu(m[0]);
123AppendMenu(m[1]);
124AppendMenu(m[2]);
125AppendMenu(m[3]);
126AppendMenu(m[4]);
127AppendMenu(m[5]);
128// AppendMenu(m[6]); Menu Modules vide pour le moment
129
130int scsx, scsy;
131ScreenSize(scsx, scsy);
132if (scsy <= 600) mFgScSz = 0;
133else if (scsy <= 800) mFgScSz = 1;
134else if (scsy <= 1024) mFgScSz = 2;
135else mFgScSz = 3;
136int msx = 420+mFgScSz*60;
137int msy = 320+mFgScSz*40;
138MainWin()->SetSize(msx, msy);
139
140int bss = 100+mFgScSz*15;
141gimv = new PIPixmap(MainWin(), "GloV", bss, bss, 5, 5);
142gimv->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_free, PIBK_free);
143zoom = new PIPixmap(MainWin(), "Zoom", bss, bss, bss+10, 5);
144zoom->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_free, PIBK_free);
145cmapv = new PICMapView(MainWin(), "CMapView", msx-10, 14+mFgScSz*2, 5, bss+10);
146cmapv->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
147
148int cpy = bss+10+14+mFgScSz*2+5;
149
150// Creation d'une console avec gestion des commandes
151mCons = new PIConsole(MainWin(), "Console", 30200, 512, 132, msx, msy-cpy, 0, cpy );
152mCons->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
153mCons->AcceptCmd(true, 50);
154redirecout = false;
155// RedirectStdOutErr(true); pas par defaut
156
157mObjMgr = new NamedObjMgr;
158mCmd = new PIACmd(mObjMgr, this);
159
160// Pas trop de message de la part de NamedObjMgr
161m[5]->SetStateMsg(10605, false);
162mObjMgr->SetVerbose(false);
163
164char* varenv;
165ImgDir[0] = WorkDir[0] = '\0';
166if ( (varenv=getenv("PEIDA_IMAGES")) != NULL ) strncpy(ImgDir, varenv, 256);
167if ( (varenv=getenv("PEIDA_WORK")) != NULL ) strncpy(WorkDir, varenv, 256);
168
169pfc_fits = new PIFileChooser(this,"FITS-FileChooser", 10125);
170pfc_ppf = new PIFileChooser(this,"PPF-FileChooser", 10135);
171pfc_ps = new PIFileChooser(this,"PS-FileChooser", 10525);
172
173mObjmgrw = new ObjMgrWind(this);
174mPpinmgrw = new PPInMgrWind(this);
175
176// Attention : A faire apres creation de ObjMgrWind !!!
177mObjMgr->SetImgApp(this);
178
179// Gestion des feneteres widgets et drawers
180mWId = mDId = mBWId = 0;
181mCurWin = NULL;
182mCurWdg = NULL;
183mLastWdg = NULL;
184mGrW = NULL;
185mStW = NULL;
186mGrIdx = mStIdx = -1;
187
188mFCMsg = 0;
189mFgCWImg = false;
190
191// Gestion fichiers PS
192num_eps = 0;
193name_ps = "";
194name_ps = "pia.ps";
195mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
196
197// Gestion OUT-PPF
198mPpfout = NULL;
199name_outppf = "";
200
201// Attributs graphiques courants
202mFCol = mBCol = PI_NotDefColor;
203mLAtt = PI_NotDefLineAtt;
204mFName = PI_DefaultFont;
205mFSz = PI_NotDefFontSize;
206mFAtt = PI_NotDefFontAtt;
207mMSz = -1;
208mMrk = PI_NotDefMarker;
209mCmapid = CMAP_OTHER;
210mRevCmap = false;
211mZoom = 0;
212mAxesFlags = kBoxAxes | kExtTicks | kLabels;
213SetXYLimits(-1, 1., -1., 1.);
214mFXYlim = false;
215SetInsetLimits(0.4, 0.6, 0.4, 0.6);
216SetImageCenterPosition(-1,-1);
217mFImgCenter = false;
218maXlog = maYlog = false;
219mAddTitle = true;
220SaveGraphicAtt();
221
222// Initialisation
223glst_piai = new PIAppInitiator(this);
224
225char buff[128];
226mCons->AddStr(" ............ starting piapp .............\n", PIVA_Blue );
227#ifdef SANS_EVOLPLANCK
228sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
229 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
230#else
231sprintf(buff, "Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
232 (double)PI_VERSIONNUMBER, glst_piai->Version());
233#endif
234mCons->AddStr(buff, PIVA_Blue );
235mCons->AddStr(" ..........................................\n", PIVA_Blue );
236// PrintPeidaVersion();
237
238pfc_fits->SetPath(ImgDir);
239pfc_ppf->SetPath(WorkDir);
240pfc_ps->SetPath(WorkDir);
241
242SetReady();
243}
244
245/* --Methode-- */
246PIStdImgApp::~PIStdImgApp()
247{
248int i;
249
250// On inactive la fenetre principale
251// Sinon, ca peut provoquer un SEGV ds delete de console ?? - Reza 07/2000
252MainWin()->Hide();
253
254// Destrucion de tous les objets de NameObjMgr
255string patt = "/*/*";
256mObjMgr->DelObjects(patt, true);
257
258delete mc;
259for(i=0; i<7; i++)
260 if (m[i]) delete m[i];
261
262WindMList::iterator it;
263for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
264
265delete mObjMgr;
266delete mCmd;
267
268delete zoom;
269delete gimv;
270delete cmapv;
271
272delete pfc_fits;
273delete pfc_ppf;
274delete pfc_ps;
275
276delete mCons;
277
278delete mObjmgrw;
279delete mPpinmgrw;
280
281deleteInfoWindow();
282
283// Les fichiers
284if (mpsfile) delete mpsfile;
285if (mPpfout) delete mPpfout;
286
287if (glst_piai) delete glst_piai; glst_piai = NULL;
288}
289
290/* --Methode-- */
291void PIStdImgApp::Process(PIMessage msg, PIMsgHandler* sender, void* data)
292{
293PIWdg *sndw;
294PIMessage tmsg, smm;
295
296tmsg = msg;
297msg = UserMsg(msg);
298smm = ModMsg(tmsg);
299
300//printf("SuperDebug: msg=%d Mod=%d State=%d\n", (int)msg, (int)smm, (int)GetState());
301if ((GetState()) && (msg != mFCMsg)) { PIBeep(); return; }
302
303// Messages active-window
304if (smm == PIMsg_Active)
305 {
306 sndw = dynamic_cast<PIWdg *>(sender);
307 switch(sndw->kind())
308 {
309 case PIWindow::ClassId :
310 mCurWin = dynamic_cast<PIWindow *>(sndw);
311 break;
312
313 case PIScDrawWdg::ClassId :
314 case PIDraw3DWdg::ClassId :
315 mCurWdg = dynamic_cast<PIBaseWdg *>(sender);
316// cerr << "*DBG11* ImgTools -> NonSensitive " << sndw->kind() << endl;
317 if (mFgCWImg) {
318// cerr << "*DBG* ImgTools -> NonSensitive " << endl;
319 m[2]->SetSensitivityMsg(10311, false);
320 m[2]->SetSensitivityMsg(10312, false);
321 m[2]->SetSensitivityMsg(10313, false);
322 m[4]->SetSensitivityMsg(10515, false);
323 m[4]->SetSensitivityMsg(10516, false);
324 mFgCWImg = false;
325 }
326 break;
327 case PIImage::ClassId :
328 mCurWdg = dynamic_cast<PIBaseWdg *>(sender);
329 if (!mFgCWImg) {
330// cerr << "*DBG* ImgTools -> Sensitive " << endl;
331 m[2]->SetSensitivityMsg(10311, true);
332 m[2]->SetSensitivityMsg(10312, true);
333 m[2]->SetSensitivityMsg(10313, true);
334 m[4]->SetSensitivityMsg(10515, true);
335 m[4]->SetSensitivityMsg(10516, true);
336 mFgCWImg = true;
337 }
338 break;
339 /*
340 default :
341 mCurWdg = NULL;
342 if (mFgCWImg) {
343 m[2]->SetSensitivityMsg(10311, false);
344 m[2]->SetSensitivityMsg(10312, false);
345 m[2]->SetSensitivityMsg(10313, false);
346 m[4]->SetSensitivityMsg(10515, false);
347 m[4]->SetSensitivityMsg(10516, false);
348 mFgCWImg = false;
349 }
350 break;
351 */
352 }
353 }
354// Message window-close
355else if (smm == PIMsg_Close)
356 {
357 sndw = (PIWdg *)sender;
358 if(sndw->kind() == PIWindow::ClassId)
359 {
360 mCurWin = (PIWindow *)sender;
361 if (mCurWin == mStW) m[2]->SetSensitivity("StackTools", false);
362 DeleteWindow(mCurWin);
363 }
364 else
365 printf("PIStdImgApp/Bug ? CloseMsd received from NonWindow (%d %d %lx) \n",
366 (int)tmsg, (int)sndw->kind(), (long)sender);
367 }
368
369// Traitement des messages des menus
370else if ( (msg >= 10100) && (msg < 10200) ) MBProcess1(msg, sender, data);
371else if ( (msg >= 10200) && (msg < 10300) ) MBProcess2(msg, sender, data);
372else if ( (msg >= 10300) && (msg < 10400) ) MBProcess3(msg, sender, data);
373else if ( (msg >= 10400) && (msg < 10500) ) MBProcess4(msg, sender, data);
374else if ( (msg >= 10500) && (msg < 10600) ) MBProcess5(msg, sender, data);
375else if ( (msg >= 10600) && (msg < 10700) ) MBProcess6(msg, sender, data);
376else if ( msg == 30200 ) { // Objet PIConsole
377 string s = mCons->GetCmdString();
378 // string s2 = "\nExecuting " + s + "\n";
379 mCons->AddStr("Cmd> ", PIVA_Blue, false);
380 // s2 = s + "\n";
381 mCons->AddStr(s.c_str(), PIVA_Blue|PIVA_Bold, false);
382 mCons->AddChar('\n', PIVA_Def, true);
383 SetBusy();
384#ifdef SANS_EVOLPLANCK
385 TRY {
386 mCmd->Interpret(s);
387 } CATCH(merr) {
388 fflush(stdout);
389 cout << endl;
390 cerr << endl;
391 string es = PeidaExc(merr);
392 cerr << "PIStdImgApp::Process()/ Cmd->Do() Exception :" << es << " (" << merr << ")" << endl ;
393 }
394#else
395 try {
396 mCmd->Interpret(s);
397 }
398 catch ( PThrowable & exc ) {
399 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
400 << (string)typeid(exc).name() << " Msg= "
401 << exc.Msg() << endl;
402 cout << endl;
403 }
404 catch ( ... ) {
405 cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ..."
406 << endl;
407 cout << endl;
408 }
409
410#endif
411 SetReady();
412 }
413
414else printf("PIStdImgApp::Process() BUG?? Msg %d (%d-%d) \n",
415 (int)tmsg,(int)msg,(int)smm);
416
417
418return;
419}
420
421/* --Methode-- */
422void PIStdImgApp::SetReady()
423{
424mCons->SetSensitive();
425gimv->SetSensitive();
426PIApplication::SetReady();
427}
428
429/* --Methode-- */
430void PIStdImgApp::SetBusy()
431{
432mCons->SetUnSensitive();
433gimv->SetUnSensitive();
434PIApplication::SetBusy();
435// Attention : Appel XSync specifique X11 - en attendant multi-thread
436XSync(PIXDisplay(), False);
437}
438
439/* --Methode-- */
440void PIStdImgApp::SetBlocked()
441{
442mCons->SetUnSensitive();
443gimv->SetUnSensitive();
444PIApplication::SetBlocked();
445// Attention : Appel XSync specifique X11 - en attendant multi-thread
446XSync(PIXDisplay(), False);
447}
448
449
450/* --Methode-- */
451int PIStdImgApp::DispImage(P2DArrayAdapter* nouv, string const & name, int opt, int oid)
452{
453PIImage* pii;
454PIWindow* win;
455int sx, sy, px, py, flag;
456
457if (nouv == NULL)
458 {
459 printf("PIStdImgApp::DispImage_Error Cannot Display NULL image \n");
460 return(-1);
461 }
462
463if ( (nouv->XSize() <= 0) || (nouv->YSize() <= 0))
464 {
465 printf("PIStdImgApp::DispImage_Error Pb Size Sz=%d*%d \n",
466 nouv->XSize(), nouv->YSize());
467 return(-1);
468 }
469
470int zm = 1;
471if (mZoom == 0) { // Facteur de zoom auto
472 zm = (nouv->XSize() > nouv->YSize()) ? nouv->XSize() : nouv->YSize();
473 zm = (zm >= 250) ? 250/zm : 1;
474 }
475else zm = mZoom;
476
477if (zm == 0) zm = 1;
478if (zm < -10) zm = -10;
479if (zm > 10) zm = 10;
480
481if (zm > 0) { sx = nouv->XSize()*zm; sy = nouv->YSize()*zm; }
482else {
483 sx = (int)((float)nouv->XSize()*(-1./float(zm)));
484 sy = (int)((float)nouv->YSize()*(-1./float(zm)));
485 }
486if (sx > 400+mFgScSz*100) sx = 400+mFgScSz*100;
487if (sy > 400+mFgScSz*100) sy = 400+mFgScSz*100;
488px = py = 0;
489win = GetWindow(opt, sx, sy, px, py, flag, (char *)name.c_str());
490pii = new PIImage(win, (char *)name.c_str(), sx, sy, px,py);
491pii->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
492pii->SetZoomWin(zoom, false);
493pii->SetGloVWin(gimv, false);
494pii->SetCMapWin(cmapv, false);
495pii->SetZoom(zm, false);
496if ( mCmapid != CMAP_OTHER ) pii->SetColMapId(mCmapid, mRevCmap, false);
497pii->ShowCursor(true);
498pii->SetUserData(NULL, oid);
499// Centrage eventuel du pave
500if (mFImgCenter && (mXImgCenter > 0) && (mYImgCenter > 0)) {
501 pii->SetImage(nouv, false);
502 pii->SetPave(mXImgCenter, mYImgCenter, true, true);
503 }
504else pii->SetImage(nouv, true);
505// printf("!!DBG!! PIImage Pos= %d %d Size= %d %d \n", pii->XPos(), pii->YPos(), pii->XSize(), pii->YSize() );
506mCurWin = win;
507mCurWdg = pii;
508mLastWdg = pii;
509mBWId++;
510mBWList[mBWId] = pii;
511return(mBWId);
512}
513
514
515/* --Methode-- */
516int PIStdImgApp::DispScDrawer(PIDrawer* scd, string const & name, int opt, string title, int oid)
517{
518if (scd == NULL)
519 {
520 printf("PIStdImgApp::DispScDrawer_Error Cannot Add NULL ScDrawer \n");
521 return(-1);
522 }
523
524// Changement d'attributs graphiques courants du drawer
525if (mFCol != PI_NotDefColor) scd->SetColAtt(mFCol, mBCol);
526if (mLAtt != PI_NotDefLineAtt) scd->SetLineAtt(mLAtt);
527if ( (mFSz != PI_NotDefFontSize) && (mFAtt != PI_NotDefFontAtt) ) scd->SetFontAtt(mFSz, mFAtt);
528if ( mFName != PI_DefaultFont ) scd->SetFont(mFName, scd->GetFontSz(), scd->GetFontAtt());
529if ( (mMrk != PI_NotDefMarker) && (mMSz >= 0) ) scd->SetMarkerAtt(mMSz, mMrk);
530if ( mCmapid != CMAP_OTHER ) scd->SetColMapId(mCmapid);
531
532
533if ( (!mLastWdg) && ( (opt == Disp_Same) || (opt == Disp_Inset) ) ) opt = Disp_Next;
534// Trace en superpoistion
535if ( (opt == Disp_Same) && (mLastWdg) ) {
536 if (mLastWdg->kind() == PIScDrawWdg::ClassId) ((PIScDrawWdg*)mLastWdg)->AddScDrawer(scd, true);
537 else mLastWdg->AddDrawer(scd, true, true, true);
538 scd->Refresh();
539 mDId++;
540 mDrwList[mDId] = scd;
541 return(-mDId);
542}
543// Trace en medaillon
544else if ( (opt == Disp_Inset) && (mLastWdg) ) {
545 PIGrCoord x1, x2, y1, y2;
546 x1 = mIXmin; x2 = mIXmax;
547 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
548 scd->SetAxesFlags(mAxesFlags);
549 if (maXlog || maYlog) scd->SetLogScale(maXlog, maYlog); // Echelle log
550 if (mFXYlim) // Forcage limites XY
551 scd->SetLimits(mXmin, mXmax, mYmin, mYmax);
552 else scd->UpdateLimits();
553 mLastWdg->AddDrawer(scd, x1, y1, x2, y2, true, false, true);
554 scd->Refresh();
555 mDId++;
556 mDrwList[mDId] = scd;
557 return(-mDId);
558}
559
560PIWindow* win;
561PIScDrawWdg* scw;
562int sx, sy, px, py, flag;
563sx = 200+mFgScSz*100;
564sy = 200+mFgScSz*100;
565win = GetWindow(opt, sx, sy, px, py, flag, (char *)name.c_str());
566if (typeid(*scd) != typeid(PIHisto2D))
567 scw = new PIScDrawWdg(win, (char *)name.c_str(), sx, sy, px, py);
568else scw = new PIH2DWdg(win, (char *)name.c_str(), sx, sy, px, py);
569scw->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
570scw->SetUserData(NULL, oid);
571if (maXlog || maYlog) scw->SetLogScale(maXlog, maYlog); // Echelle log
572if (mFXYlim) // Forcage limites XY
573 scw->SetLimits(mXmin, mXmax, mYmin, mYmax);
574scw->SetAxesFlags(mAxesFlags);
575// Fonte de trace d'axe
576scw->BaseDrawer()->SetFont(mFName, mFSz, mFAtt);
577
578if (typeid(*scd) != typeid(PIHisto2D)) scw->AddScDrawer(scd, true);
579else ((PIH2DWdg*)scw)->SetPIHisto((PIHisto2D*)scd);
580// Titre du plot
581if (mAddTitle) {
582 if (title.length() <= 0) title = name; string t2="";
583 scw->SetTitles(title, t2);
584}
585
586// scw->Refresh(); ? Pas necessaire Reza 19/08/98, 05/05/99 $CHECK$
587mCurWin = win;
588mCurWdg = scw;
589mLastWdg = scw;
590mBWId++;
591mBWList[mBWId] = scw;
592return(mBWId);
593}
594
595/* --Methode-- */
596int PIStdImgApp::Disp3DDrawer(PIDrawer3D* dr3, string const & name, int opt, string title, int oid)
597{
598if (dr3 == NULL)
599 {
600 printf("PIStdImgApp::Disp3DDrawer_Error Cannot Add NULL 3DDrawer \n");
601 return(-1);
602 }
603
604// Changement d'attributs graphiques courants du drawer
605if (mFCol != PI_NotDefColor) dr3->SetColAtt(mFCol, mBCol);
606if (mLAtt != PI_NotDefLineAtt) dr3->SetLineAtt(mLAtt);
607if ( (mFSz != PI_NotDefFontSize) && (mFAtt != PI_NotDefFontAtt) ) dr3->SetFontAtt(mFSz, mFAtt);
608if ( mFName != PI_DefaultFont ) dr3->SetFont(mFName, dr3->GetFontSz(), dr3->GetFontAtt());
609if ( (mMrk != PI_NotDefMarker) && (mMSz >= 0) ) dr3->SetMarkerAtt(mMSz, mMrk);
610if ( mCmapid != CMAP_OTHER ) dr3->SetColMapId(mCmapid);
611
612if ( (!mLastWdg) && ( (opt == Disp_Same) || (opt == Disp_Inset) ) ) opt = Disp_Next;
613// Trace en superpoistion
614if ( (opt == Disp_Same) && (mLastWdg) ) {
615 if (mLastWdg->kind() == PIDraw3DWdg::ClassId) ((PIDraw3DWdg*)mLastWdg)->AddDrawer3D(dr3, true);
616 else mLastWdg->AddDrawer(dr3, true, true, true);
617 dr3->Refresh();
618 mDId++;
619 mDrwList[mDId] = dr3;
620 return(-mDId);
621}
622// Trace en medaillon
623else if ( (opt == Disp_Inset) && (mLastWdg) ) {
624 PIGrCoord x1, x2, y1, y2;
625 x1 = mIXmin; x2 = mIXmax;
626 y2 = 1.-mIYmin; y1 = 1.-mIYmax;
627 dr3->SetAxesFlags(mAxesFlags);
628 dr3->UpdateLimits();
629 mLastWdg->AddDrawer(dr3, x1, y1, x2, y2, true, false, true);
630 dr3->Refresh();
631 mDId++;
632 mDrwList[mDId] = dr3;
633 return(-mDId);
634}
635
636
637PIWindow* win;
638int sx, sy, px, py, flag;
639sx = 200+mFgScSz*100;
640sy = 200+mFgScSz*100;
641win = GetWindow(opt, sx, sy, px, py, flag, (char *)name.c_str());
642PIDraw3DWdg* wd3 = new PIDraw3DWdg(win, (char *)name.c_str(), sx, sy, px, py);
643wd3->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic, PIBK_elastic);
644wd3->SetUserData(NULL, oid);
645wd3->AddDrawer3D(dr3, true);
646// Titre du plot
647if (mAddTitle) {
648 if (title.length() <= 0) title = name; string t2="";
649 wd3->SetTitles(title, t2);
650}
651// wd3->Refresh(); ?Pas necessaire $CHECK$ 05/05/99
652mCurWin = win;
653mCurWdg = wd3;
654mLastWdg = wd3;
655mBWId++;
656mBWList[mBWId] = wd3;
657return(mBWId);
658}
659
660/* --Methode-- */
661void PIStdImgApp::AddText(string const & txt, double xp, double yp)
662{
663PIElDrawer *eld=CurrentElDrawer();
664if (eld == NULL) return;
665
666if ( (mFSz != PI_NotDefFontSize) && (mFAtt != PI_NotDefFontAtt) )
667 eld->SetFontAtt(mFSz, mFAtt);
668if ( mFName != PI_DefaultFont )
669 eld->SetFont(mFName, eld->GetFontSz(), eld->GetFontAtt());
670eld->ElAddText(xp,yp,txt.c_str(),mFCol);
671eld->Refresh();
672}
673
674/* --Methode-- */
675void PIStdImgApp::AddLine(double xp1, double yp1, double xp2, double yp2)
676{
677PIElDrawer *eld=CurrentElDrawer();
678if (eld == NULL) return;
679
680eld->ElAddLine(xp1, yp1, xp2, yp2, mFCol);
681eld->Refresh();
682}
683
684/* --Methode-- */
685void PIStdImgApp::AddRectangle(double xp1, double yp1, double xp2, double yp2, bool fgfill)
686{
687PIElDrawer *eld=CurrentElDrawer();
688if (eld == NULL) return;
689
690double xp,yp;
691double dx, dy;
692if (xp1 < xp2) {
693 xp = xp1; dx = xp2-xp1;
694}
695else {
696 xp = xp2; dx = xp1-xp2;
697}
698if (yp1 < yp2) {
699 yp = yp1; dy = yp2-yp1;
700}
701else {
702 yp = yp2; dy = yp1-yp2;
703}
704if (fgfill) eld->ElAddFRect(xp, yp, dx, dy, mFCol);
705else eld->ElAddRect(xp, yp, dx, dy, mFCol);
706eld->Refresh();
707}
708
709/* --Methode-- */
710void PIStdImgApp::AddCircle(double xc, double yc, double r, bool fgfill)
711{
712PIElDrawer *eld=CurrentElDrawer();
713if (eld == NULL) return;
714
715if (fgfill) eld->ElAddFCirc(xc, yc, r, mFCol);
716else eld->ElAddCirc(xc, yc, r, mFCol);
717eld->Refresh();
718}
719
720/* --Methode-- */
721void PIStdImgApp::SetTitle(string const & titletop, string const & titlebottom)
722{
723PIElDrawer *eld=CurrentElDrawer();
724if (eld == NULL) return;
725
726if ( (mFSz != PI_NotDefFontSize) && (mFAtt != PI_NotDefFontAtt) )
727 eld->SetFontAtt(mFSz, mFAtt);
728if ( mFName != PI_DefaultFont )
729 eld->SetFont(mFName, eld->GetFontSz(), eld->GetFontAtt());
730eld->SetTitles(titletop, titlebottom);
731eld->Refresh();
732}
733
734/* --Methode-- */
735PIElDrawer* PIStdImgApp::CurrentElDrawer()
736{
737PIElDrawer *eld=NULL;
738if (!mLastWdg) return(eld);
739PIScDrawWdg* sdw=NULL;
740PIDraw3DWdg* w3d=NULL;
741PIImage* imgw;
742switch(mLastWdg->kind()) {
743 case PIScDrawWdg::ClassId :
744 sdw = dynamic_cast<PIScDrawWdg *>(mLastWdg);
745 if (sdw) eld = sdw->BaseDrawer();
746 break;
747 case PIDraw3DWdg::ClassId :
748 w3d = dynamic_cast<PIDraw3DWdg *>(mLastWdg);
749 if (w3d) eld = w3d->BaseDrawer();
750 break;
751 case PIImage::ClassId :
752 imgw = dynamic_cast<PIImage *>(mLastWdg);
753 if (imgw) eld = imgw->BaseDrawer();
754 break;
755 default :
756 break;
757 }
758return(eld);
759}
760
761/* --Methode-- */
762void PIStdImgApp::CreateGraphWin(int nx, int ny, int sx, int sy)
763{
764if (nx < 1) nx = 1;
765if (ny < 1) ny = 1;
766if (nx > 8) nx = 8;
767if (ny > 8) ny = 8;
768if ( (sx < 50) && (sy < 50) ) sx = sy = 400+mFgScSz*100;
769char buff[64];
770mWId++;
771int px, py;
772MainWin()->GetScreenPos(px, py);
773sprintf(buff, "PI-GraphicWin (%d)",mWId);
774PIZoneWindow* win = new PIZoneWindow(this, buff, PIWK_normal, nx, ny, sx, sy, px+MainWin()->XSize()+30, 0);
775win->SetUserData(NULL, ny*10+nx); // UserFlag= nY*10 + nX
776mWList[mWId*10+1] = (PIWindow*)win;
777win->SetAutoDelChilds(true);
778// win->Show();
779mGrW = win;
780mGrIdx = 0;
781}
782
783/* --Methode-- */
784void PIStdImgApp::CreateStackWin(int sx, int sy)
785{
786if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
787char buff[64];
788mWId++;
789int px, py;
790MainWin()->GetScreenPos(px, py);
791sprintf(buff, "PI-StackWin (%d)",mWId);
792PIStackWindow* win = new PIStackWindow(this, buff, PIWK_normal, sx, sy, px+MainWin()->XSize()+30, 100);
793win->SetUserData(NULL, 9999); // UserFlag= 9999
794mWList[mWId*10+2] = (PIWindow*)win;
795win->SetAutoDelChilds(true);
796// win->Show();
797mStW = win;
798m[2]->SetSensitivity("StackTools", true);
799mStIdx = 0;
800}
801
802/* --Methode-- */
803PIWindow* PIStdImgApp::GetWindow(int typ, int& sx, int& sy, int& px, int& py, int& flag, char * nom)
804{
805PIWindow* rw;
806
807switch (typ) {
808 case Disp_Next : // Fenetre graphique courante
809 {
810 if (mGrW == NULL) CreateGraphWin();
811 int nx, ny;
812 mGrW->NbZone(nx, ny);
813 PIWdg* nw = mGrW->NextChildPosSize(px, py, sx, sy);
814// cerr << "**DBG** PIStdImgApp::GetWindow() DispNext : nw = " << (long)nw << endl;
815 if (nw) DeleteBaseWidget((PIBaseWdg*)nw, false, false);
816 flag = mGrIdx;
817 mGrIdx = (mGrIdx+1)%(nx*ny);
818 rw = mGrW;
819 break;
820 }
821
822 case Disp_Stack : // Fenetre de type stack (empilement)
823 {
824 if (mStW == NULL) CreateStackWin(sx, sy);
825 px = py = 0;
826 sx = mStW->XSize();
827 sy = mStW->YSize();
828 flag = mStIdx;
829 mStIdx++;
830 rw = mStW;
831 }
832 break;
833
834 default : // Fenetre ordinaire
835 {
836 int pwx, pwy;
837 MainWin()->GetScreenPos(pwx, pwy);
838 if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
839 rw = new PIWindow(this, nom, PIWK_normal, sx, sy, pwx+MainWin()->XSize()+30, 300);
840 rw->SetUserData(NULL, 0); // UserFlag= 0
841 mWId++;
842 mWList[mWId*10] = rw;
843 rw->SetAutoDelChilds(true);
844 // rw->Show();
845 px = py = 0;
846 flag = 0;
847 break;
848 }
849 }
850
851rw->Show();
852mCurWin = rw;
853return(rw);
854}
855
856/* --Methode-- */
857void PIStdImgApp::SetZone(int nzx, int nzy)
858{
859if (!mGrW) CreateGraphWin(nzx, nzy);
860else {
861 int k;
862 PIWdg* cwd;
863 for(k=0; k<mGrW->NbChilds(); k++) {
864 if ((cwd = mGrW->GetChild(k)) == NULL) continue;
865 DeleteBaseWidget((PIBaseWdg*)cwd, false, false);
866 }
867 mGrW->SetZone(nzx, nzy);
868 }
869}
870
871/* --Methode-- */
872void PIStdImgApp::StackWinNext()
873{
874if (mStW) mStW->DispNext();
875}
876
877/* --Methode-- */
878void PIStdImgApp::DeleteWindow(PIWindow* w)
879{
880if (w == NULL) return;
881w->Hide();
882bool ownwindow=false; // To Check if this is one of our windows
883WindMList::iterator it;
884for(it = mWList.begin(); it != mWList.end(); it++)
885 if ((*it).second == w) { mWList.erase(it); ownwindow = true; break; }
886if (w == mGrW) { mGrW = NULL; mGrIdx = -1; }
887if (w == mStW) { mStW = NULL; mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
888if (w == mCurWin) mCurWin = NULL;
889
890if (!ownwindow) return; // We do nothing if this is not a window we have created ...
891
892int k;
893PIWdg* cwd;
894for(k=0; k<w->NbChilds(); k++) {
895 if ((cwd = w->GetChild(k)) == NULL) continue;
896 DeleteBaseWidget((PIBaseWdg*)cwd,false,false);
897 }
898delete w;
899return;
900}
901
902/* --Methode-- */
903void PIStdImgApp::DeleteBaseWidget(PIBaseWdg* w, bool dw, bool dwin)
904{
905if (w == NULL) return;
906BWMList::iterator it;
907for(it = mBWList.begin(); it != mBWList.end(); it++)
908 if ((*it).second == w) { mBWList.erase(it); break; }
909int k;
910PIDrawer* drw;
911for(k=0; k<w->NbDrawers(); k++) {
912 if ((drw = w->GetDrawer(k)) == NULL) continue;
913 DrwMList::iterator itt;
914 for(itt = mDrwList.begin(); itt != mDrwList.end(); itt++)
915 if ((*itt).second == drw) { mDrwList.erase(itt); break; }
916 }
917
918if (w == mCurWdg) {
919 mCurWdg = NULL;
920 if (mFgCWImg) {
921 m[4]->SetSensitivityMsg(10515, false);
922 m[4]->SetSensitivityMsg(10516, false);
923 mFgCWImg = false;
924 }
925 }
926
927if (w == mLastWdg) mLastWdg = NULL;
928
929PIWdg* pw=NULL;
930if (dwin) pw = (PIWdg*)(w->Parent());
931//DBG printf("DeleteBaseWidget(%lx)-DBG kind = %d - %d %d \n", (long)w, w->kind(), (int)dw, (int)dwin);
932if (dw) delete w;
933if (pw && (pw->kind() == PIWindow::ClassId )) {
934 PIWindow* pww = (PIWindow*) pw;
935 if ((pww != (PIWindow*)mGrW) && (pww != (PIWindow*)mStW) && (pww->NbChilds()==0))
936 DeleteWindow((PIWindow*)pw);
937 }
938return;
939}
940
941
942
943/* --Methode-- */
944void PIStdImgApp::DelWRsId(int k)
945{
946//DBG cerr << "-DBG- PIStdImgApp::DelWRsId(" << k << ")" << endl;
947if (k > 0) { // C'est un BaseWidget
948 BWMList::iterator it;
949 it = mBWList.find(k);
950 if (it == mBWList.end()) return;
951 PIBaseWdg* wd = (*it).second;
952//DBG cerr << "-DBG- PIStdImgApp::DelWRsId Deleting BaseWidget " << (long)(wd) << endl ;
953 DeleteBaseWidget(wd, true, true);
954 }
955else { // C'est un drawer
956 DrwMList::iterator it;
957 it = mDrwList.find(-k);
958 if (it == mDrwList.end()) return;
959 delete (*it).second;
960 mDrwList.erase(it);
961// cerr << "+DBG+ PIStdImgApp::DelWRsId Deleting Drawer " << (long)((*it).second) << endl ;
962 }
963}
964/* --Methode-- */
965bool PIStdImgApp::CheckWRsId(int k)
966{
967if (k > 0) { // C'est un BaseWidget
968 BWMList::iterator it;
969 it = mBWList.find(k);
970 if (it == mBWList.end()) return(false);
971 else return(true);
972 }
973else { // C'est un drawer
974 DrwMList::iterator it;
975 it = mDrwList.find(-k);
976 if (it == mDrwList.end()) return(false);
977 else return(true);
978 }
979}
980
981
982/* --Methode-- */
983void PIStdImgApp::RedirectStdOutErr(bool fg)
984{
985if (fg) {
986 RedirectOutStream(mCons);
987 RedirectErrStream(mCons);
988 m[5]->SetStateMsg(10602, true);
989 redirecout = true;
990 }
991else {
992 RedirectOutStream(NULL);
993 RedirectErrStream(NULL);
994 m[5]->SetStateMsg(10602, false);
995 redirecout = false;
996 }
997return;
998}
999
1000/* --Methode-- */
1001void PIStdImgApp::CatchSignals(bool fgfpe, bool fgsegv)
1002{
1003#ifdef SANS_EVOLPLANCK
1004PeidaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1005#else
1006SophyaConfigureSignalhandling(fgfpe, fgsegv, true, true);
1007#endif
1008m[5]->SetStateMsg(10603, fgfpe);
1009m[5]->SetStateMsg(10604, fgsegv);
1010}
1011
1012/* --Methode-- */
1013void PIStdImgApp::CloseAllWindows()
1014{
1015WindMList::iterator it;
1016for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
1017mWList.clear();
1018mBWList.clear();
1019mDrwList.clear();
1020mGrW = NULL;
1021mStW = NULL;
1022mCurWin = NULL;
1023mCurWdg = NULL;
1024mLastWdg = NULL;
1025m[4]->SetSensitivityMsg(10515, false);
1026m[4]->SetSensitivityMsg(10516, false);
1027}
1028
1029/* --Methode-- */
1030void PIStdImgApp::MBProcess1(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1031{
1032
1033 switch(msg)
1034 {
1035 case 10150 :
1036 showInfoWindow(this);
1037 break;
1038
1039 case 10155 :
1040 hideInfoWindow(this);
1041 break;
1042
1043 case 10100 :
1044 mCmd->ShowHelpWindow();
1045 break;
1046
1047 case 10120 :
1048 pfc_fits->AcceptNewFile(false);
1049 mFCMsg = 10125;
1050 pfc_fits->SetMsg(mFCMsg);
1051 SetBlocked();
1052 pfc_fits->Show();
1053 break;
1054
1055 case 10125 :
1056 SetBusy();
1057 if (data) {
1058 string nomobj="";
1059 ObjMgr()->ReadFits(pfc_fits->GetFileName(), nomobj);
1060 ObjMgr()->DisplayObj(nomobj, "win");
1061 }
1062 mFCMsg = 0;
1063 SetReady();
1064 break;
1065
1066 case 10130 :
1067 pfc_ppf->AcceptNewFile(false);
1068 mFCMsg = 10135;
1069 pfc_ppf->SetMsg(mFCMsg);
1070 SetBlocked();
1071 pfc_ppf->Show();
1072 break;
1073
1074 case 10135 :
1075 mFCMsg = 0;
1076 if (data) {
1077 PPInMgrW()->SetFile(pfc_ppf->GetFileName());
1078 PPInMgrW()->Show();
1079 }
1080 SetReady();
1081 break;
1082
1083 case 10105:
1084 Stop();
1085 break;
1086
1087 }
1088return;
1089}
1090
1091
1092
1093/* --Methode-- */
1094void PIStdImgApp::MBProcess2(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1095{
1096
1097switch (msg) {
1098 case 10201 :
1099 ObjMgrW()->Show();
1100 break;
1101
1102 case 10220 :
1103 pfc_ppf->AcceptNewFile(true);
1104 mFCMsg = 10225;
1105 pfc_ppf->SetMsg(mFCMsg);
1106 SetBlocked();
1107 pfc_ppf->Show();
1108 break;
1109
1110 case 10225 :
1111 SetBusy();
1112 if (data) {
1113 if (mPpfout) {
1114 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1115 delete mPpfout;
1116 }
1117 name_outppf = pfc_ppf->GetFileName();
1118 mPpfout = NULL;
1119 printf("PIStdImg/Info: Opening POutPersist-File %s \n", name_outppf.c_str());
1120 mPpfout = new POutPersist(name_outppf);
1121 }
1122 mFCMsg = 0;
1123 SetReady();
1124 break;
1125
1126 case 10230 :
1127 if (!mPpfout) break;
1128 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
1129 delete mPpfout;
1130 name_outppf = "";
1131 mPpfout = NULL;
1132 break;
1133
1134 case 10270 :
1135 if (mCurWdg) {
1136 int oid = mCurWdg->UserFlag();
1137 DeleteBaseWidget(mCurWdg);
1138 mObjMgr->DelObj_Id(oid);
1139 }
1140 break;
1141
1142 default:
1143 cerr << "PIStdImgApp::MBProcess2() BUG?? Msg= " << msg << endl;
1144 break;
1145}
1146
1147return;
1148}
1149
1150/* --Methode-- */
1151void PIStdImgApp::MBProcess3(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1152{
1153
1154switch (msg) {
1155 case 10301 :
1156 PIImgTools::ShowPIImgTools();
1157 break;
1158 case 10302 :
1159 PIDrwTools::ShowPIDrwTools();
1160 break;
1161 case 10303 :
1162 PIAxesTools::ShowPIAxesTools();
1163 break;
1164
1165 case 10304 :
1166 mCmd->ShowCxxExecWindow();
1167 break;
1168
1169 case 10311 :
1170 case 10312 :
1171 {
1172 PIImage* curpimg = NULL;
1173 if (!mCurWdg) return;
1174 if (mCurWdg->kind() != PIImage::ClassId) return;
1175 curpimg = (PIImage*)mCurWdg;
1176 if (curpimg == NULL) return;
1177 P2DArrayAdapter* img = curpimg->Image();
1178 if (img == NULL) return;
1179 int dx = curpimg->XSzPave();
1180 int dy = curpimg->YSzPave();
1181 int x0 = curpimg->XPave()-dx/2;
1182 int y0 = curpimg->YPave()-dy/2;
1183 if (x0 < 0) x0 = 0;
1184 if (y0 < 0) y0 = 0;
1185 int x1 = x0+dx;
1186 int y1 = y0+dy;
1187 if (x1 > img->XSize()) x1 = img->XSize();
1188 if (y1 > img->YSize()) y1 = img->YSize();
1189 dx = x1-x0; dy = y1-y0;
1190 ImageR4* pim = new ImageR4(dx, dy);
1191 int ii, jj;
1192 for(jj=0; jj<dy; jj++)
1193 for(ii=0; ii<dx; ii++) (*pim)(ii,jj) = (*img)(ii+x0, jj+y0);
1194 if (msg == 10305) { // Calcul des coordonnees du sous-pave
1195 double xc1, yc1;
1196 img->Coord(x0, y0, xc1, yc1);
1197 pim->SetOrg((int)xc1, (int)yc1);
1198 }
1199 string nom = mCurWdg->Nom() + "_pave";
1200 ObjMgr()->AddObj(pim, nom);
1201 ObjMgr()->DisplayObj(nom, "w");
1202 break;
1203 }
1204
1205 case 10313 :
1206 {
1207 PIImage* curpimg = NULL;
1208 if (!mCurWdg) return;
1209 if (mCurWdg->kind() != PIImage::ClassId) return;
1210 curpimg = (PIImage*)mCurWdg;
1211 if (curpimg == NULL) return;
1212 curpimg->ShowCuts(true);
1213 break;
1214 }
1215
1216 case 10320 :
1217 if (mStW) mStW->DispNext();
1218 break;
1219
1220 case 10321 :
1221 case 10322 :
1222 case 10324 :
1223// case 10328 :
1224 if (mStW) mStW->StartAutoDisp((msg-10320)*500);
1225 break;
1226
1227 case 10329 :
1228 if (mStW) mStW->StopAutoDisp();
1229 break;
1230
1231 case 103330 :
1232 if (mStW) {
1233 PIWdg* cw = mStW->CurrentWdg();
1234 if (cw) DeleteBaseWidget((PIBaseWdg*)cw);
1235 }
1236 break;
1237
1238 default:
1239 cerr << "PIStdImgApp::MBProcess3() BUG?? Msg= " << msg << endl;
1240 break;
1241 }
1242return;
1243}
1244
1245/* --Methode-- */
1246void PIStdImgApp::MBProcess4(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
1247{
1248
1249switch (msg) {
1250
1251 case 10400 :
1252 CreateStackWin();
1253 break;
1254
1255 case 10411 :
1256 CreateGraphWin(1,1);
1257 break;
1258 case 10421 :
1259 CreateGraphWin(1,2);
1260 break;
1261 case 10412 :
1262 CreateGraphWin(2,1);
1263 break;
1264 case 10422 :
1265 CreateGraphWin(2,2);
1266 break;
1267 case 10431 :
1268 CreateGraphWin(1,3);
1269 break;
1270 case 10433 :
1271 CreateGraphWin(3,3);
1272 break;
1273 case 10441 :
1274 if (mCurWdg) {
1275 mLastWdg = mCurWdg;
1276 cout << " Using current widget as last-widget (display same) " << endl;
1277 }
1278 else cout << " No current widget - select widget with mouse " << endl;
1279 break;
1280 case 10460 :
1281 DeleteWindow(mCurWin);
1282 break;
1283 default:
1284 cerr << "PIStdImgApp::MBProcess4() BUG?? Msg= " << msg << endl;
1285 break;
1286 }
1287return;
1288}
1289
1290
1291/* --Methode-- */
1292void PIStdImgApp::MBProcess5(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1293{
1294char nomps[64],strg[512];
1295PSFile *mps;
1296int sxt, syt, syo, syo1, sx[4], sy[4];
1297
1298switch (msg)
1299 {
1300 case 10501 :
1301 pfc_ps->AcceptNewFile(true);
1302 mFCMsg = 10525;
1303 pfc_ps->SetMsg(mFCMsg);
1304 SetBlocked();
1305 pfc_ps->Show();
1306 break;
1307
1308 case 10525 :
1309 SetBusy();
1310 if (data) {
1311 if (mpsfile) {
1312 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1313 delete mpsfile;
1314 }
1315 name_ps = pfc_ps->GetFileName();
1316 printf("PIStdImg/Info: Opening PS-File %s \n", name_ps.c_str());
1317 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 2., 2.);
1318 }
1319 mFCMsg = 0;
1320 SetReady();
1321 break;
1322
1323 case 10505 :
1324 if (!mpsfile) break;
1325 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1326 delete mpsfile;
1327 mpsfile = NULL;
1328 name_ps = "";
1329 break;
1330
1331 case 10511 : // Window -> PS
1332 case 10512 : // Window -> EPS
1333 if (CurrentWindow() == NULL) break;
1334 if (msg == 10512)
1335 {
1336 num_eps++;
1337 sprintf(nomps,"pia%d.eps", num_eps);
1338 printf("PIStdImg/Info: Creating EPSFile %s (CurWin-> EPS) \n", nomps);
1339 mps = new PSFile(nomps);
1340 }
1341 else {
1342 if (mpsfile == NULL) {
1343 name_ps = "pia.ps";
1344 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 0., 0.);
1345 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1346 }
1347 printf("PIStdImg/Info: CurWin-> PSFile %s\n", name_ps.c_str());
1348 mps = mpsfile;
1349 }
1350 CurrentWindow()->PSPrint(mps,0,0);
1351
1352 if (msg == 10512) delete mps; // fichier eps
1353 break;
1354
1355 case 10515 : // Image -> PS
1356 case 10516 : // Image -> EPS
1357 {
1358 PIImage* curpimg = NULL;
1359 if (!mCurWdg) return;
1360 if (mCurWdg->kind() != PIImage::ClassId) return;
1361 curpimg = (PIImage*)mCurWdg;
1362 if (curpimg == NULL) return;
1363 if (msg == 10516)
1364 {
1365 num_eps++;
1366 sprintf(nomps,"pia%d.eps", num_eps);
1367 printf("PIStdImg/Info: Creating EPSFile %s (CurImage-> EPS)\n", nomps);
1368 mps = new PSFile(nomps);
1369 }
1370 else {
1371 if (mpsfile == NULL) {
1372 name_ps = "pia.ps";
1373 mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
1374 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1375 }
1376 printf("PIStdImg/Info: CurImage-> PSFile %s\n", name_ps.c_str());
1377 mps = mpsfile;
1378 }
1379
1380 sx[0] = gimv->XSize();
1381 sy[0] = gimv->YSize();
1382 sx[1] = zoom->XSize();
1383 sy[1] = zoom->YSize();
1384 sx[2] = cmapv->XSize();
1385 sy[2] = cmapv->YSize();
1386 sx[3] = curpimg->XSize();
1387 sy[3] = curpimg->YSize();
1388 if (sy[1] > sy[0]) { syo1 = sy[1]+50; syo = sy[1]+sy[2]+60; }
1389 else { syo1 = sy[0]+50; syo = sy[0]+sy[2]+60; }
1390 syt = sy[3]+syo;
1391 sxt = sx[3];
1392 if (sxt < (sx[0]+sx[1]+20)) sxt = sx[0]+sx[1]+20;
1393 if (sxt < sx[2]) sxt = sx[2];
1394
1395 // Pour ecrire le titre
1396 mps->NewPage((float)sxt, (float)syt, PI_Portrait);
1397 mps->NewBloc(0,0, (float)sxt, 30., (float)sxt, 30.);
1398 sprintf(strg,"Image: %s - Pave %d %d \n", curpimg->Nom().c_str(),
1399 curpimg->XPave(), curpimg->YPave());
1400 mps->DrawString(10., 25., strg, PI_Black, PI_DefaultFont, PI_BoldFont, 20);
1401 mps->EndBloc();
1402
1403 // Les quatre fenetres glovimage, zoom, cmap, image
1404 gimv->PSPrint(mps, -gimv->XPos(), -gimv->YPos()+40);
1405 zoom->PSPrint(mps, -zoom->XPos()+sx[0]+20, -zoom->YPos()+40);
1406 cmapv->PSPrint(mps, -cmapv->XPos(), -cmapv->YPos()+syo1);
1407 curpimg->PSPrint(mps, -curpimg->XPos(), -curpimg->YPos()+syo);
1408
1409 if (msg == 10516) delete mps; // fichier eps
1410 break;
1411 }
1412
1413 default:
1414 cerr << "PIStdImgApp::MBProcess5() BUG?? Msg= " << msg << endl;
1415 break;
1416 }
1417
1418}
1419
1420
1421/* --Methode-- */
1422void PIStdImgApp::MBProcess6(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1423{
1424switch (msg) {
1425 case 10601:
1426 CloseAllWindows();
1427 break;
1428 case 10602:
1429 RedirectStdOutErr(*((bool*)data));
1430 break;
1431 case 10603:
1432 case 10604:
1433 CatchSignals(m[5]->GetStateMsg(10603), m[5]->GetStateMsg(10604));
1434 break;
1435 case 10605:
1436 mObjMgr->SetVerbose(m[5]->GetStateMsg(10605));
1437 break;
1438 case 10606:
1439 mCmd->ShowCxxOptionWindow();
1440 break;
1441 default:
1442 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
1443 break;
1444 }
1445return;
1446}
1447
1448
1449/* --Methode-- */
1450void PIStdImgApp::SetColAtt(PIColors fg, PIColors bg)
1451{
1452 mFCol = fg;
1453 mBCol = bg;
1454}
1455/* --Methode-- */
1456void PIStdImgApp::SetLineAtt(PILineAtt lat)
1457{
1458 mLAtt = lat;
1459}
1460
1461/* --Methode-- */
1462void PIStdImgApp::SetFontName(PIFontName fn)
1463{
1464 mFName = fn;
1465}
1466
1467/* --Methode-- */
1468void PIStdImgApp::SetFontAtt(PIFontSize fsz, PIFontAtt fat)
1469{
1470 mFSz = fsz;
1471 mFAtt = fat;
1472}
1473/* --Methode-- */
1474void PIStdImgApp::SetMarkerAtt(int sz, PIMarker mrk)
1475{
1476 mMSz = sz;
1477 mMrk = mrk;
1478}
1479
1480/* --Methode-- */
1481void PIStdImgApp::SetZoomAtt(int zoom)
1482{
1483 if ( (zoom > 10) || (zoom < -10) ) zoom = 0;
1484 mZoom = zoom;
1485}
1486/* --Methode-- */
1487void PIStdImgApp::SetAxesAtt(unsigned int axfl)
1488{
1489 mAxesFlags = axfl;
1490}
1491/* --Methode-- */
1492void PIStdImgApp::SetXYLimits(double xmin, double xmax, double ymin, double ymax)
1493{
1494 mXmin = xmin; mXmax= xmax;
1495 mYmin = ymin; mYmax= ymax;
1496}
1497/* --Methode-- */
1498void PIStdImgApp::SetInsetLimits(double xmin, double xmax, double ymin, double ymax)
1499{
1500 mIXmin = xmin; mIXmax= xmax;
1501 mIYmin = ymin; mIYmax= ymax;
1502}
1503/* --Methode-- */
1504void PIStdImgApp::SetImageCenterPosition(int x, int y)
1505{
1506 mXImgCenter = x; mYImgCenter = y;
1507}
1508
1509/* --Methode-- */
1510void PIStdImgApp::SaveGraphicAtt()
1511{
1512 mSFCol = mFCol;
1513 mSBCol = mBCol;
1514 mSLAtt = mLAtt;
1515 mSFName = mFName;
1516 mSFSz = mFSz;
1517 mSFAtt = mFAtt;
1518 mSMSz = mMSz;
1519 mSMrk = mMrk;
1520 mSCmapid = mCmapid;
1521 mSRevCmap = mRevCmap;
1522 mSZoom = mZoom;
1523 mSAxesFlags = mAxesFlags;
1524 mSXmin = mXmin; mSXmax = mXmax;
1525 mSYmin = mYmin; mSYmax = mYmax;
1526 mSIXmin = mIXmin; mSIXmax = mIXmax;
1527 mSIYmin = mIYmin; mSIYmax = mIYmax;
1528 mSFXYlim = mFXYlim;
1529 mSXImgCenter = mXImgCenter;
1530 mSYImgCenter = mYImgCenter;
1531 mSFImgCenter = mFImgCenter;
1532 mSaXlog = maXlog;
1533 mSaYlog = maYlog;
1534 mSAddTitle = mAddTitle;
1535}
1536
1537/* --Methode-- */
1538void PIStdImgApp::RestoreGraphicAtt()
1539{
1540 mFCol = mSFCol;
1541 mBCol = mSBCol;
1542 mLAtt = mSLAtt;
1543 mFName = mSFName;
1544 mFSz = mSFSz;
1545 mFAtt = mSFAtt;
1546 mMSz = mSMSz;
1547 mMrk = mSMrk;
1548 mCmapid = mSCmapid;
1549 mRevCmap = mSRevCmap;
1550 mZoom = mSZoom;
1551 mAxesFlags = mSAxesFlags;
1552 mXmin = mSXmin; mXmax = mSXmax;
1553 mYmin = mSYmin; mYmax = mSYmax;
1554 mIXmin = mSIXmin; mIXmax = mSIXmax;
1555 mIYmin = mSIYmin; mIYmax = mSIYmax;
1556 mFXYlim = mSFXYlim;
1557 mXImgCenter = mSXImgCenter;
1558 mYImgCenter = mSYImgCenter;
1559 mFImgCenter = mSFImgCenter;
1560 maXlog = mSaXlog;
1561 maYlog = mSaYlog;
1562 mAddTitle = mSAddTitle;
1563}
1564
1565// -------------------------------------------------
1566// Fenetre info piapp (About piapp)
1567// -------------------------------------------------
1568static PIWindow* infow_win = NULL;
1569static PIText* infow_txt = NULL;
1570static PICMapView* infow_cmap = NULL;
1571static PIButton* infow_but = NULL;
1572
1573/* Nouvelle-Fonction */
1574static void createInfoWindow(PIStdImgApp* app)
1575{
1576if (infow_win) return;
1577
1578int bsx, bsy;
1579PIApplicationPrefCompSize(bsx, bsy);
1580int spx, spy;
1581spx = bsx/6; spy = bsy/6;
1582
1583infow_win = new PIWindow((PIMsgHandler *)app, "About piapp",
1584 PIWK_dialog, bsx*5+3*spx, bsy*4+spy*3, 200, 200);
1585infow_win->SetAutoDelChilds(true);
1586infow_txt = new PIText(infow_win,"about_piapp_text", bsx*5+spx, bsy*3, spx, spy);
1587infow_txt->SetMutiLineMode(true);
1588infow_txt->SetTextEditable(false);
1589infow_txt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
1590infow_cmap = new PICMapView(infow_win, "about_piapp_cmap", bsx*4, bsy*0.7, spx, 2*spy+bsy*3.15);
1591infow_cmap->SetColMapId(CMAP_COLBR32, 1., -1., false);
1592infow_cmap->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
1593infow_but = new PIButton(infow_win,"OK", 10155, bsx, bsy, bsx*4+2*spx, 2*spy+bsy*3);
1594infow_but->SetMsgParent((PIMsgHandler *)app);
1595infow_but->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
1596char buff[128];
1597#ifdef SANS_EVOLPLANCK
1598sprintf(buff, "Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
1599 (double)PI_VERSIONNUMBER, (float)PeidaVersion());
1600#else
1601{
1602sprintf(buff, "Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
1603 (double)PI_VERSIONNUMBER, glst_piai->Version());
1604}
1605#endif
1606string info = "piapp : Interactive analysis program\n";
1607info += buff;
1608info += "(C) LAL-IN2P3/CNRS 1996-2000\n";
1609info += "(C) SPP-DAPNIA/CEA 1996-2000\n";
1610infow_txt->SetText(info);
1611}
1612
1613/* Nouvelle-Fonction */
1614static void showInfoWindow(PIStdImgApp* app)
1615{
1616if (!infow_win) createInfoWindow(app);
1617if (infow_win) infow_win->Show();
1618}
1619/* Nouvelle-Fonction */
1620static void hideInfoWindow(PIStdImgApp* app)
1621{
1622if (infow_win) infow_win->Hide();
1623}
1624
1625/* Nouvelle-Fonction */
1626static void deleteInfoWindow()
1627{
1628if (!infow_win) return;
1629delete infow_win;
1630infow_win = NULL;
1631infow_txt = NULL;
1632infow_cmap = NULL;
1633infow_but = NULL;
1634}
1635
Note: See TracBrowser for help on using the repository browser.