source: Sophya/trunk/Poubelle/PIext/pistdimgapp.cc@ 654

Last change on this file since 654 was 249, checked in by ansari, 26 years ago

modif rz+cmv 22/4/99

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