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

Last change on this file since 1570 was 1569, checked in by ansari, 24 years ago

Gestion des attributs de nom de fontes - Reza 6/7/2001

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