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

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

Mise aux "normes" version DPC/Planck - Gestion des objets a travers

un adaptateur/interface NTuple par NamedObjMgr.
Enregistrement d'objets et de l'adaptateur (I/O PPersist, display, ...)
par ServNobjMgr .... Reza 13/05/99

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