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

Last change on this file since 440 was 440, checked in by ercodmgr, 26 years ago

flag KCC -> namespace std et CC_HAS_RTTI_SUPPORT Reza 26/9/99

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