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

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

modifs Fenetre de fit et gestion repertoire /func Reza 9/8/99

  • Property svn:executable set to *
File size: 32.1 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/* --Methode-- */
770bool PIStdImgApp::CheckWRsId(int k)
771{
772if (k > 0) { // C'est un BaseWidget
773 BWMList::iterator it;
774 it = mBWList.find(k);
775 if (it == mBWList.end()) return(false);
776 else return(true);
777 }
778else { // C'est un drawer
779 DrwMList::iterator it;
780 it = mDrwList.find(-k);
781 if (it == mDrwList.end()) return(false);
782 else return(true);
783 }
784}
785
786
787/* --Methode-- */
788void PIStdImgApp::RedirectStdOutErr(bool fg)
789{
790if (fg) {
791 RedirectOutStream(mCons);
792 RedirectErrStream(mCons);
793 m[5]->SetStateMsg(10602, true);
794 redirecout = true;
795 }
796else {
797 RedirectOutStream(NULL);
798 RedirectErrStream(NULL);
799 m[5]->SetStateMsg(10602, false);
800 redirecout = false;
801 }
802return;
803}
804
805/* --Methode-- */
806void PIStdImgApp::CatchSignals(bool fg)
807{
808PeidaConfigureSignalhandling(fg, fg, true, true);
809m[5]->SetStateMsg(10603, fg);
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_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 CatchSignals(*((bool*)data));
1211 break;
1212 default:
1213 cerr << "PIStdImgApp::MBProcess6() BUG?? Msg= " << msg << endl;
1214 break;
1215 }
1216return;
1217}
1218
1219
1220/* --Methode-- */
1221void PIStdImgApp::SetColAtt(PIColors fg, PIColors bg)
1222{
1223 mFCol = fg;
1224 mBCol = bg;
1225}
1226/* --Methode-- */
1227void PIStdImgApp::SetLineAtt(PILineAtt lat)
1228{
1229 mLAtt = lat;
1230}
1231/* --Methode-- */
1232void PIStdImgApp::SetFontAtt(PIFontSize fsz, PIFontAtt fat)
1233{
1234 mFSz = fsz;
1235 mFAtt = fat;
1236}
1237/* --Methode-- */
1238void PIStdImgApp::SetMarkerAtt(int sz, PIMarker mrk)
1239{
1240 mMSz = sz;
1241 mMrk = mrk;
1242}
1243/* --Methode-- */
1244void PIStdImgApp::SetColMapId(CMapId cid)
1245{
1246 mCmapid = cid;
1247}
1248/* --Methode-- */
1249void PIStdImgApp::SetZoomAtt(int zoom)
1250{
1251 if ( (zoom > 10) || (zoom < -10) ) zoom = 0;
1252 mZoom = zoom;
1253}
1254/* --Methode-- */
1255void PIStdImgApp::SetAxesAtt(unsigned int axfl)
1256{
1257 mAxesFlags = axfl;
1258}
1259/* --Methode-- */
1260void PIStdImgApp::SetXYLimits(double xmin, double xmax, double ymin, double ymax)
1261{
1262 mXmin = xmin; mXmax= xmax;
1263 mYmin = ymin; mYmax= ymax;
1264}
1265
1266/* --Methode-- */
1267void PIStdImgApp::SaveGraphicAtt()
1268{
1269 mSFCol = mFCol;
1270 mSBCol = mBCol;
1271 mSLAtt = mLAtt;
1272 mSFSz = mFSz;
1273 mSFAtt = mFAtt;
1274 mSMSz = mMSz;
1275 mSMrk = mMrk;
1276 mSCmapid = mCmapid;
1277 mSZoom = mZoom;
1278 mSAxesFlags = mAxesFlags;
1279 mSXmin = mXmin; mSXmax = mXmax;
1280 mSYmin = mYmin; mSYmax = mYmax;
1281 mSFXYlim = mFXYlim;
1282}
1283
1284/* --Methode-- */
1285void PIStdImgApp::RestoreGraphicAtt()
1286{
1287 mFCol = mSFCol;
1288 mBCol = mSBCol;
1289 mLAtt = mSLAtt;
1290 mFSz = mSFSz;
1291 mFAtt = mSFAtt;
1292 mMSz = mSMSz;
1293 mMrk = mSMrk;
1294 mCmapid = mSCmapid;
1295 mZoom = mSZoom;
1296 mAxesFlags = mSAxesFlags;
1297 mXmin = mSXmin; mXmax = mSXmax;
1298 mYmin = mSYmin; mYmax = mSYmax;
1299 mFXYlim = mSFXYlim;
1300}
Note: See TracBrowser for help on using the repository browser.