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

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

Extract pave avec conservation origine - Reza 22/7/99

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