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

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

A/ ajout des blocs foreach et ameliorations gestion des variables ($x)
pour l'interpreteur piacmd.
B/ Ajout PIStdImgApp::AddText et corrections diverses

Reza 05/08/99

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