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

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

Adaptation aux "normes DPC", introduction des classes CmdExecutor, ...
Fenetre d'aide en lignes, gestion de modules, ... Reza 11/05/99

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