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

Last change on this file since 169 was 165, checked in by ercodmgr, 27 years ago

Creation du module PIext en regroupant des fichiers de Drawer/Wdg pour
Objets ds PEIDA/Outils++, Images++, ... et des classes de ProgPI,
lie a piapp (PIStdImgApp, NamedObjMgr, ...) Reza 18/12/98

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