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

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

Trace de NTuple en 2D avec Marker de taille proportionnelle a Weight
Introduction des repertoires dans la gestion d'objets NameObjMgr
Reorganisation NamedObjMgr et Services2NObjMgr, ajout de commandes , ...
Reza 12/7/99

  • Property svn:executable set to *
File size: 30.6 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#if defined(__KCC__)
11using std::string ;
12#include <vector.h>
13#endif
14
15
16#include "strutil.h"
17#include "timing.h"
18#include "perrors.h"
19#include "ctimer.h"
20
21#include "psighand.h"
22
23#include "cimage.h" // pour pouvoir faire extract
24
25#include "pistdimgapp.h"
26#include "pihisto2d.h"
27#include "psfile.h"
28#include "piimgtools.h"
29#include "pidrwtools.h"
30
31#include "pistzwin.h"
32
33#include "piinit.h"
34
35
36static char ImgDir[256];
37static char WorkDir[256];
38
39
40/* ........................................................... */
41/* Classe PIStdImgApp */
42/* ........................................................... */
43
44/* --Methode-- */
45PIStdImgApp::PIStdImgApp(int narg, char* arg[])
46: PIApplication(420, 320, narg, arg)
47{
48
49// Les menus
50m[0] = new PIMenu(Menubar(),"Fichier");
51m[0]->AppendItem("Help", 10100);
52m[0]->AppendItem("Open-Fits", 10120);
53m[0]->AppendItem("Open-PPF", 10130);
54m[0]->AppendItem("Close", 10110);
55m[0]->AppendItem("delete", 10111);
56// m[0]->AppendItem("Options", 10101);
57m[0]->AppendItem("Exit", 10105);
58
59m[1] = new PIMenu(Menubar(),"Objets");
60m[1]->AppendItem("ObjectManager", 10201);
61m[1]->AppendItem("OpenOutPPF", 10220);
62m[1]->AppendItem("CloseOutPPF", 10230);
63
64m[2] = new PIMenu(Menubar(),"Tools");
65m[2]->AppendItem("Show ImageTools", 10301);
66m[2]->AppendItem("Show DrawerTools", 10302);
67m[2]->AppendItem("Extract Pave", 10305);
68m[2]->SetSensitivityMsg(10305, false);
69m[2]->AppendItem("Cuts X,Y", 10306);
70m[2]->SetSensitivityMsg(10306, false);
71mc = new PIMenu(m[2], "StackTools");
72mc->AppendItem("DispNext", 10320);
73mc->AppendItem("Blink 0.5s", 10321);
74mc->AppendItem("Blink 1s", 10322);
75mc->AppendItem("Blink 2s", 10324);
76mc->AppendItem("Stop Blink", 10329);
77mc->AppendItem("RemoveCurrent", 10330);
78m[2]->AppendPDMenu(mc);
79m[2]->SetSensitivity("StackTools", false);
80
81m[3] = new PIMenu(Menubar(),"Window");
82m[3]->AppendItem("StackWindow", 10400);
83m[3]->AppendItem("Window", 10411);
84m[3]->AppendItem("Window 2x1", 10421);
85m[3]->AppendItem("Window 1x2", 10412);
86m[3]->AppendItem("Window 2x2", 10422);
87m[3]->AppendItem("Window 3x1", 10431);
88m[3]->AppendItem("Window 3x3", 10433);
89
90m[4] = new PIMenu(Menubar(),"PostScript");
91m[4]->AppendItem("OpenPS", 10501);
92m[4]->AppendItem("ClosePS", 10505);
93m[4]->AppendItem("Window->PS", 10511);
94m[4]->AppendItem("Image->PS", 10515);
95m[4]->AppendItem("Window->EPS", 10512);
96m[4]->AppendItem("Image->EPS", 10516);
97m[4]->SetSensitivityMsg(10515, false);
98m[4]->SetSensitivityMsg(10516, false);
99
100m[5] = new PIMenu(Menubar(),"Special");
101m[5]->AppendItem("CloseAll", 10601);
102m[5]->AppendCheckItem("Red.Out/Err", 10602);
103m[5]->AppendCheckItem("Catch SigFPE/SEGV", 10603);
104
105m[6] = new PIMenu(Menubar(),"Modules");
106
107AppendMenu(m[0]);
108AppendMenu(m[1]);
109AppendMenu(m[2]);
110AppendMenu(m[3]);
111AppendMenu(m[4]);
112AppendMenu(m[5]);
113AppendMenu(m[6]);
114
115int scsx, scsy;
116ScreenSz(scsx, scsy);
117if (scsy <= 600) mFgScSz = 0;
118else if (scsy <= 800) mFgScSz = 1;
119else if (scsy <= 1024) mFgScSz = 2;
120else mFgScSz = 3;
121int msx = 420+mFgScSz*60;
122int msy = 320+mFgScSz*40;
123MainWin()->SetSize(msx, msy);
124
125int bss = 100+mFgScSz*15;
126gimv = new PIPixmap(MainWin(), "GloV", bss, bss, 5, 5);
127gimv->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_free, PIBK_free);
128zoom = new PIPixmap(MainWin(), "Zoom", bss, bss, bss+10, 5);
129zoom->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_free, PIBK_free);
130cmapv = new PICMapView(MainWin(), "CMapView", msx-10, 14+mFgScSz*2, 5, bss+10);
131cmapv->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
132
133int cpy = bss+10+14+mFgScSz*2+5;
134
135// Creation d'une console avec gestion des commandes
136mCons = new PIConsole(MainWin(), "Console", 30200, 512, 132, msx, msy-cpy, 0, cpy );
137mCons->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
138mCons->AcceptCmd(true, 50);
139redirecout = false;
140// RedirectStdOutErr(true); pas par defaut
141
142char buff[128];
143sprintf(buff, "piapp V2.0 --- PEIDA++ Version %5.3f \n", (float)PeidaVersion());
144mCons->AddStr(" ............ starting piapp .............\n", PIVA_Blue );
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
535/* --Methode-- */
536void PIStdImgApp::CreateGraphWin(int nx, int ny, int sx, int sy)
537{
538if (nx < 1) nx = 1;
539if (ny < 1) ny = 1;
540if (nx > 8) nx = 8;
541if (ny > 8) ny = 8;
542if ( (sx < 50) && (sy < 50) ) sx = sy = 400+mFgScSz*100;
543char buff[64];
544mWId++;
545int px, py;
546MainWin()->GetScreenPos(px, py);
547sprintf(buff, "PI-GraphicWin (%d)",mWId);
548PIZoneWindow* win = new PIZoneWindow(this, buff, PIWK_normal, nx, ny, sx, sy, px+MainWin()->XSize()+30, 0);
549win->SetUserData(NULL, ny*10+nx); // UserFlag= nY*10 + nX
550mWList[mWId*10+1] = (PIWindow*)win;
551win->SetAutoDelChilds(true);
552// win->Show();
553mGrW = win;
554mGrIdx = 0;
555}
556
557/* --Methode-- */
558void PIStdImgApp::CreateStackWin(int sx, int sy)
559{
560if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
561char buff[64];
562mWId++;
563int px, py;
564MainWin()->GetScreenPos(px, py);
565sprintf(buff, "PI-StackWin (%d)",mWId);
566PIStackWindow* win = new PIStackWindow(this, buff, PIWK_normal, sx, sy, px+MainWin()->XSize()+30, 100);
567win->SetUserData(NULL, 9999); // UserFlag= 9999
568mWList[mWId*10+2] = (PIWindow*)win;
569win->SetAutoDelChilds(true);
570// win->Show();
571mStW = win;
572m[2]->SetSensitivity("StackTools", true);
573mStIdx = 0;
574}
575
576/* --Methode-- */
577PIWindow* PIStdImgApp::GetWindow(int typ, int& sx, int& sy, int& px, int& py, int& flag, char * nom)
578{
579PIWindow* rw;
580
581switch (typ) {
582 case Disp_Next : // Fenetre graphique courante
583 {
584 if (mGrW == NULL) CreateGraphWin();
585 int nx, ny;
586 mGrW->NbZone(nx, ny);
587 PIWdg* nw = mGrW->NextChildPosSize(px, py, sx, sy);
588// cerr << "**DBG** PIStdImgApp::GetWindow() DispNext : nw = " << (long)nw << endl;
589 if (nw) DeleteBaseWidget((PIBaseWdg*)nw, false, false);
590 flag = mGrIdx;
591 mGrIdx = (mGrIdx+1)%(nx*ny);
592 rw = mGrW;
593 break;
594 }
595
596 case Disp_Stack : // Fenetre de type stack (empilement)
597 {
598 if (mStW == NULL) CreateStackWin(sx, sy);
599 px = py = 0;
600 sx = mStW->XSize();
601 sy = mStW->YSize();
602 flag = mStIdx;
603 mStIdx++;
604 rw = mStW;
605 }
606 break;
607
608 default : // Fenetre ordinaire
609 {
610 int pwx, pwy;
611 MainWin()->GetScreenPos(pwx, pwy);
612 if ( (sx < 50) && (sy < 50) ) sx = sy = 300+mFgScSz*100;
613 rw = new PIWindow(this, nom, PIWK_normal, sx, sy, pwx+MainWin()->XSize()+30, 300);
614 rw->SetUserData(NULL, 0); // UserFlag= 0
615 mWId++;
616 mWList[mWId*10] = rw;
617 rw->SetAutoDelChilds(true);
618 // rw->Show();
619 px = py = 0;
620 flag = 0;
621 break;
622 }
623 }
624
625rw->Show();
626mCurWin = rw;
627return(rw);
628}
629
630/* --Methode-- */
631void PIStdImgApp::SetZone(int nzx, int nzy)
632{
633if (!mGrW) CreateGraphWin(nzx, nzy);
634else {
635 int k;
636 PIWdg* cwd;
637 for(k=0; k<mGrW->NbChilds(); k++) {
638 if ((cwd = mGrW->GetChild(k)) == NULL) continue;
639 DeleteBaseWidget((PIBaseWdg*)cwd, false, false);
640 }
641 mGrW->SetZone(nzx, nzy);
642 }
643}
644
645/* --Methode-- */
646void PIStdImgApp::StackWinNext()
647{
648if (mStW) mStW->DispNext();
649}
650
651/* --Methode-- */
652void PIStdImgApp::DeleteWindow(PIWindow* w)
653{
654if (w == NULL) return;
655w->Hide();
656WindMList::iterator it;
657for(it = mWList.begin(); it != mWList.end(); it++)
658 if ((*it).second == w) { mWList.erase(it); break; }
659if (w == mGrW) { mGrW = NULL; mGrIdx = -1; }
660if (w == mStW) { mStW = NULL; mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
661if (w == mCurWin) mCurWin = NULL;
662int k;
663PIWdg* cwd;
664for(k=0; k<w->NbChilds(); k++) {
665 if ((cwd = w->GetChild(k)) == NULL) continue;
666 DeleteBaseWidget((PIBaseWdg*)cwd,false,false);
667 }
668delete w;
669return;
670}
671
672/* --Methode-- */
673void PIStdImgApp::DeleteBaseWidget(PIBaseWdg* w, bool dw, bool dwin)
674{
675if (w == NULL) return;
676BWMList::iterator it;
677for(it = mBWList.begin(); it != mBWList.end(); it++)
678 if ((*it).second == w) { mBWList.erase(it); break; }
679int k;
680PIDrawer* drw;
681for(k=0; k<w->NbDrawers(); k++) {
682 if ((drw = w->GetDrawer(k)) == NULL) continue;
683 DrwMList::iterator itt;
684 for(itt = mDrwList.begin(); itt != mDrwList.end(); itt++)
685 if ((*itt).second == drw) { mDrwList.erase(itt); break; }
686 }
687
688if (w == mCurWdg) {
689 mCurWdg = NULL;
690 if (mFgCWImg) {
691 m[4]->SetSensitivityMsg(10515, false);
692 m[4]->SetSensitivityMsg(10516, false);
693 mFgCWImg = false;
694 }
695 }
696
697if (w == mLastWdg) mLastWdg = NULL;
698
699PIWdg* pw=NULL;
700if (dwin) pw = (PIWdg*)(w->Parent());
701//DBG printf("DeleteBaseWidget(%lx)-DBG kind = %d - %d %d \n", (long)w, w->kind(), (int)dw, (int)dwin);
702if (dw) delete w;
703if (pw && (pw->kind() == PIWindow::ClassId )) {
704 PIWindow* pww = (PIWindow*) pw;
705 if ((pww != (PIWindow*)mGrW) && (pww != (PIWindow*)mStW) && (pww->NbChilds()==0))
706 DeleteWindow((PIWindow*)pw);
707 }
708return;
709}
710
711
712
713/* --Methode-- */
714void PIStdImgApp::DelWRsId(int k)
715{
716//DBG cerr << "-DBG- PIStdImgApp::DelWRsId(" << k << ")" << endl;
717if (k > 0) { // C'est un BaseWidget
718 BWMList::iterator it;
719 it = mBWList.find(k);
720 if (it == mBWList.end()) return;
721 PIBaseWdg* wd = (*it).second;
722//DBG cerr << "-DBG- PIStdImgApp::DelWRsId Deleting BaseWidget " << (long)(wd) << endl ;
723 DeleteBaseWidget(wd, true, true);
724 }
725else { // C'est un drawer
726 DrwMList::iterator it;
727 it = mDrwList.find(-k);
728 if (it == mDrwList.end()) return;
729 delete (*it).second;
730 mDrwList.erase(it);
731// cerr << "+DBG+ PIStdImgApp::DelWRsId Deleting Drawer " << (long)((*it).second) << endl ;
732 }
733}
734
735
736/* --Methode-- */
737void PIStdImgApp::RedirectStdOutErr(bool fg)
738{
739if (fg) {
740 RedirectOutStream(mCons);
741 RedirectErrStream(mCons);
742 m[5]->SetStateMsg(10602, true);
743 redirecout = true;
744 }
745else {
746 RedirectOutStream(NULL);
747 RedirectErrStream(NULL);
748 m[5]->SetStateMsg(10602, false);
749 redirecout = false;
750 }
751return;
752}
753
754/* --Methode-- */
755void PIStdImgApp::CatchSignals(bool fg)
756{
757PeidaConfigureSignalhandling(fg, fg);
758m[5]->SetStateMsg(10603, fg);
759}
760
761/* --Methode-- */
762void PIStdImgApp::CloseAllWindows()
763{
764WindMList::iterator it;
765for(it = mWList.begin(); it != mWList.end(); it++) delete (*it).second;
766mWList.clear();
767mBWList.clear();
768mDrwList.clear();
769}
770
771/* --Methode-- */
772void PIStdImgApp::MBProcess1(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
773{
774
775 switch(msg)
776 {
777 case 10100 :
778 mCmd->ShowHelpWindow();
779 break;
780
781 case 10120 :
782 pfc->SetPath(ImgDir);
783 pfc->AcceptNewFile(false);
784 mFCMsg = 10125;
785 pfc->SetMsg(mFCMsg);
786 SetBlocked();
787 pfc->Show();
788 break;
789
790 case 10125 :
791 SetBusy();
792 if (data) {
793 string nomobj="";
794 ObjMgr()->ReadFits(pfc->GetFileName(), nomobj);
795 ObjMgr()->DisplayObj(nomobj, "win");
796 }
797 mFCMsg = 0;
798 SetReady();
799 break;
800
801 case 10130 :
802 pfc->SetPath(WorkDir);
803 pfc->AcceptNewFile(false);
804 mFCMsg = 10135;
805 pfc->SetMsg(mFCMsg);
806 SetBlocked();
807 pfc->Show();
808 break;
809
810 case 10135 :
811 mFCMsg = 0;
812 if (data) {
813 PPInMgrW()->SetFile(pfc->GetFileName());
814 PPInMgrW()->Show();
815 }
816 SetReady();
817 break;
818
819 case 10110 :
820 DeleteWindow(mCurWin);
821 break;
822
823 case 10111 :
824 if (mCurWdg) {
825 int oid = mCurWdg->UserFlag();
826 DeleteBaseWidget(mCurWdg);
827 mObjMgr->DelObj_Id(oid);
828 }
829 break;
830
831 case 10105:
832 Stop();
833 break;
834
835 }
836return;
837}
838
839
840
841/* --Methode-- */
842void PIStdImgApp::MBProcess2(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
843{
844
845switch (msg) {
846 case 10201 :
847 ObjMgrW()->Show();
848 break;
849
850 case 10220 :
851 pfc->SetPath(WorkDir);
852 pfc->AcceptNewFile(true);
853 mFCMsg = 10225;
854 pfc->SetMsg(mFCMsg);
855 SetBlocked();
856 pfc->Show();
857 break;
858
859 case 10225 :
860 SetBusy();
861 if (data) {
862 if (mPpfout) {
863 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
864 delete mPpfout;
865 }
866 name_outppf = pfc->GetFileName();
867 mPpfout = NULL;
868 printf("PIStdImg/Info: Opening POutPersist-File %s \n", name_outppf.c_str());
869 mPpfout = new POutPersist(name_outppf);
870 }
871 mFCMsg = 0;
872 SetReady();
873 break;
874
875 case 10230 :
876 if (!mPpfout) break;
877 printf("PIStdImg/Info: Closing POutPersist-File %s \n", name_outppf.c_str());
878 delete mPpfout;
879 name_outppf = "";
880 mPpfout = NULL;
881 break;
882
883
884 default:
885 cerr << "PIStdImgApp::MBProcess2() BUG?? Msg= " << msg << endl;
886 break;
887}
888
889return;
890}
891
892/* --Methode-- */
893void PIStdImgApp::MBProcess3(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
894{
895
896switch (msg) {
897 case 10301 :
898 PIImgTools::ShowPIImgTools();
899 break;
900 case 10302 :
901 PIDrwTools::ShowPIDrwTools();
902 break;
903
904 case 10305 :
905 {
906 PIImage* curpimg = NULL;
907 if (!mCurWdg) return;
908 if (mCurWdg->kind() != PIImage::ClassId) return;
909 curpimg = (PIImage*)mCurWdg;
910 if (curpimg == NULL) return;
911 P2DArrayAdapter* img = curpimg->Image();
912 if (img == NULL) return;
913 int dx = curpimg->XSzPave();
914 int dy = curpimg->YSzPave();
915 int x0 = curpimg->XPave()-dx/2;
916 int y0 = curpimg->YPave()-dy/2;
917 if (x0 < 0) x0 = 0;
918 if (y0 < 0) y0 = 0;
919 int x1 = x0+dx;
920 int y1 = y0+dy;
921 if (x1 > img->XSize()) x1 = img->XSize();
922 if (y1 > img->YSize()) y1 = img->YSize();
923 dx = x1-x0; dy = y1-y0;
924 ImageR4* pim = new ImageR4(dx, dy);
925 int ii, jj;
926 for(jj=0; jj<dy; jj++)
927 for(ii=0; ii<dx; ii++) (*pim)(ii,jj) = (*img)(ii+x0, jj+y0);
928 string nom = mCurWdg->Nom() + "_pave";
929 ObjMgr()->AddObj(pim, nom);
930 ObjMgr()->DisplayObj(nom, "w");
931 break;
932 }
933
934 case 10306 :
935 {
936 PIImage* curpimg = NULL;
937 if (!mCurWdg) return;
938 if (mCurWdg->kind() != PIImage::ClassId) return;
939 curpimg = (PIImage*)mCurWdg;
940 if (curpimg == NULL) return;
941 curpimg->ShowCuts(true);
942 break;
943 }
944
945 case 10320 :
946 if (mStW) mStW->DispNext();
947 break;
948
949 case 10321 :
950 case 10322 :
951 case 10324 :
952// case 10328 :
953 if (mStW) mStW->StartAutoDisp((msg-10320)*500);
954 break;
955
956 case 10329 :
957 if (mStW) mStW->StopAutoDisp();
958 break;
959
960 case 103330 :
961 if (mStW) {
962 PIWdg* cw = mStW->CurrentWdg();
963 if (cw) DeleteBaseWidget((PIBaseWdg*)cw);
964 }
965 break;
966
967 default:
968 cerr << "PIStdImgApp::MBProcess3() BUG?? Msg= " << msg << endl;
969 break;
970 }
971return;
972}
973
974/* --Methode-- */
975void PIStdImgApp::MBProcess4(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
976{
977
978switch (msg) {
979
980 case 10400 :
981 CreateStackWin();
982 break;
983
984 case 10411 :
985 CreateGraphWin(1,1);
986 break;
987 case 10421 :
988 CreateGraphWin(1,2);
989 break;
990 case 10412 :
991 CreateGraphWin(2,1);
992 break;
993 case 10422 :
994 CreateGraphWin(2,2);
995 break;
996 case 10431 :
997 CreateGraphWin(1,3);
998 break;
999 case 10433 :
1000 CreateGraphWin(3,3);
1001 break;
1002
1003 default:
1004 cerr << "PIStdImgApp::MBProcess4() BUG?? Msg= " << msg << endl;
1005 break;
1006 }
1007return;
1008}
1009
1010
1011/* --Methode-- */
1012void PIStdImgApp::MBProcess5(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1013{
1014char nomps[64],strg[512];
1015PSFile *mps;
1016int sxt, syt, syo, syo1, sx[4], sy[4];
1017
1018switch (msg)
1019 {
1020 case 10501 :
1021 pfc->SetPath(WorkDir);
1022 pfc->AcceptNewFile(true);
1023 mFCMsg = 10525;
1024 pfc->SetMsg(mFCMsg);
1025 SetBlocked();
1026 pfc->Show();
1027 break;
1028
1029 case 10525 :
1030 SetBusy();
1031 if (data) {
1032 if (mpsfile) {
1033 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1034 delete mpsfile;
1035 }
1036 name_ps = pfc->GetFileName();
1037 printf("PIStdImg/Info: Opening PS-File %s \n", name_ps.c_str());
1038 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 2., 2.);
1039 }
1040 mFCMsg = 0;
1041 SetReady();
1042 break;
1043
1044 case 10505 :
1045 if (!mpsfile) break;
1046 printf("PIStdImg/Info: Closing PS-File %s \n", name_ps.c_str());
1047 delete mpsfile;
1048 mpsfile = NULL;
1049 name_ps = "";
1050 break;
1051
1052 case 10511 : // Window -> PS
1053 case 10512 : // Window -> EPS
1054 if (CurrentWindow() == NULL) break;
1055 if (msg == 10512)
1056 {
1057 num_eps++;
1058 sprintf(nomps,"pia%d.eps", num_eps);
1059 printf("PIStdImg/Info: Creating EPSFile %s (CurWin-> EPS) \n", nomps);
1060 mps = new PSFile(nomps);
1061 }
1062 else {
1063 if (mpsfile == NULL) {
1064 name_ps = "pia.ps";
1065 mpsfile = new PSFile(name_ps.c_str(), PI_Portrait, PI_A4, 0., 0.);
1066 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1067 }
1068 printf("PIStdImg/Info: CurWin-> PSFile %s\n", name_ps.c_str());
1069 mps = mpsfile;
1070 }
1071 CurrentWindow()->PSPrint(mps,0,0);
1072
1073 if (msg == 10512) delete mps; // fichier eps
1074 break;
1075
1076 case 10515 : // Image -> PS
1077 case 10516 : // Image -> EPS
1078 {
1079 PIImage* curpimg = NULL;
1080 if (!mCurWdg) return;
1081 if (mCurWdg->kind() != PIImage::ClassId) return;
1082 curpimg = (PIImage*)mCurWdg;
1083 if (curpimg == NULL) return;
1084 if (msg == 10516)
1085 {
1086 num_eps++;
1087 sprintf(nomps,"pia%d.eps", num_eps);
1088 printf("PIStdImg/Info: Creating EPSFile %s (CurImage-> EPS)\n", nomps);
1089 mps = new PSFile(nomps);
1090 }
1091 else {
1092 if (mpsfile == NULL) {
1093 name_ps = "pia.ps";
1094 mpsfile = new PSFile(name_ps.c_str(),PI_Portrait, PI_A4, 2., 2.);
1095 printf("PIStdImg/Info: File PS %s opened \n", name_ps.c_str());
1096 }
1097 printf("PIStdImg/Info: CurImage-> PSFile %s\n", name_ps.c_str());
1098 mps = mpsfile;
1099 }
1100
1101 sx[0] = gimv->XSize();
1102 sy[0] = gimv->YSize();
1103 sx[1] = zoom->XSize();
1104 sy[1] = zoom->YSize();
1105 sx[2] = cmapv->XSize();
1106 sy[2] = cmapv->YSize();
1107 sx[3] = curpimg->XSize();
1108 sy[3] = curpimg->YSize();
1109 if (sy[1] > sy[0]) { syo1 = sy[1]+50; syo = sy[1]+sy[2]+60; }
1110 else { syo1 = sy[0]+50; syo = sy[0]+sy[2]+60; }
1111 syt = sy[3]+syo;
1112 sxt = sx[3];
1113 if (sxt < (sx[0]+sx[1]+20)) sxt = sx[0]+sx[1]+20;
1114 if (sxt < sx[2]) sxt = sx[2];
1115
1116 // Pour ecrire le titre
1117 mps->NewPage((float)sxt, (float)syt, PI_Portrait);
1118 mps->NewBloc(0,0, (float)sxt, 30., (float)sxt, 30.);
1119 sprintf(strg,"Image: %s - Pave %d %d \n", curpimg->Nom().c_str(),
1120 curpimg->XPave(), curpimg->YPave());
1121 mps->DrawString(10., 25., strg, PI_Black, PI_BoldFont, 20);
1122 mps->EndBloc();
1123
1124 // Les quatre fenetres glovimage, zoom, cmap, image
1125 gimv->PSPrint(mps, -gimv->XPos(), -gimv->YPos()+40);
1126 zoom->PSPrint(mps, -zoom->XPos()+sx[0]+20, -zoom->YPos()+40);
1127 cmapv->PSPrint(mps, -cmapv->XPos(), -cmapv->YPos()+syo1);
1128 curpimg->PSPrint(mps, -curpimg->XPos(), -curpimg->YPos()+syo);
1129
1130 if (msg == 10516) delete mps; // fichier eps
1131 break;
1132 }
1133
1134 default:
1135 cerr << "PIStdImgApp::MBProcess5() BUG?? Msg= " << msg << endl;
1136 break;
1137 }
1138
1139}
1140
1141
1142/* --Methode-- */
1143void PIStdImgApp::MBProcess6(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
1144{
1145switch (msg) {
1146 case 10601:
1147 CloseAllWindows();
1148 break;
1149 case 10602:
1150 RedirectStdOutErr(*((bool*)data));
1151 break;
1152 case 10603:
1153 CatchSignals(*((bool*)data));
1154 break;
1155 default:
1156 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
1157 break;
1158 }
1159return;
1160}
1161
1162
1163/* --Methode-- */
1164void PIStdImgApp::SetColAtt(PIColors fg, PIColors bg)
1165{
1166 mFCol = fg;
1167 mBCol = bg;
1168}
1169/* --Methode-- */
1170void PIStdImgApp::SetLineAtt(PILineAtt lat)
1171{
1172 mLAtt = lat;
1173}
1174/* --Methode-- */
1175void PIStdImgApp::SetFontAtt(PIFontSize fsz, PIFontAtt fat)
1176{
1177 mFSz = fsz;
1178 mFAtt = fat;
1179}
1180/* --Methode-- */
1181void PIStdImgApp::SetMarkerAtt(int sz, PIMarker mrk)
1182{
1183 mMSz = sz;
1184 mMrk = mrk;
1185}
1186/* --Methode-- */
1187void PIStdImgApp::SetColMapId(CMapId cid)
1188{
1189 mCmapid = cid;
1190}
1191/* --Methode-- */
1192void PIStdImgApp::SetZoomAtt(int zoom)
1193{
1194 if ( (zoom > 10) || (zoom < -10) ) zoom = 0;
1195 mZoom = zoom;
1196}
1197/* --Methode-- */
1198void PIStdImgApp::SetAxesAtt(unsigned int axfl)
1199{
1200 mAxesFlags = axfl;
1201}
1202/* --Methode-- */
1203void PIStdImgApp::SetXYLimits(double xmin, double xmax, double ymin, double ymax)
1204{
1205 mXmin = xmin; mXmax= xmax;
1206 mYmin = ymin; mYmax= ymax;
1207}
1208
1209/* --Methode-- */
1210void PIStdImgApp::SaveGraphicAtt()
1211{
1212 mSFCol = mFCol;
1213 mSBCol = mBCol;
1214 mSLAtt = mLAtt;
1215 mSFSz = mFSz;
1216 mSFAtt = mFAtt;
1217 mSMSz = mMSz;
1218 mSMrk = mMrk;
1219 mSCmapid = mCmapid;
1220 mSZoom = mZoom;
1221 mSAxesFlags = mAxesFlags;
1222 mSXmin = mXmin; mSXmax = mXmax;
1223 mSYmin = mYmin; mSYmax = mYmax;
1224 mSFXYlim = mFXYlim;
1225}
1226
1227/* --Methode-- */
1228void PIStdImgApp::RestoreGraphicAtt()
1229{
1230 mFCol = mSFCol;
1231 mBCol = mSBCol;
1232 mLAtt = mSLAtt;
1233 mFSz = mSFSz;
1234 mFAtt = mSFAtt;
1235 mMSz = mSMSz;
1236 mMrk = mSMrk;
1237 mCmapid = mSCmapid;
1238 mZoom = mSZoom;
1239 mAxesFlags = mSAxesFlags;
1240 mXmin = mSXmin; mXmax = mSXmax;
1241 mYmin = mSYmin; mYmax = mSYmax;
1242 mFXYlim = mSFXYlim;
1243}
Note: See TracBrowser for help on using the repository browser.