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

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

Petites erreurs Reza 11/02/99

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