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

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

Ajout SetXYLimits et debut d'introduction de repertoire dans la gestion des objets nommes - Reza 28/6/99

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