source: trunk/MagicSoft/Cosy/gui/MGStarguider.cc@ 1213

Last change on this file since 1213 was 1111, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.5 KB
Line 
1#include "MGStarguider.h"
2
3#include <iostream.h> // cout
4
5#include <TGMenu.h>
6#include <TSystem.h>
7#include <TGSplitter.h> // TGHorizontal3DLine
8
9#include "MGImage.h"
10#include "MGCoordinates.h"
11
12#include "coord.h"
13
14#include "StarCatalog.h"
15
16#include "Filter.h"
17#include "Writer.h"
18#include "base/timer.h"
19
20ClassImp(MGStarguider);
21
22enum {
23 IDM_kFilter,
24 IDM_kCatalog,
25 IDM_kStart,
26 IDM_kStop,
27 IDM_kFileType,
28 IDM_kPPM,
29 IDM_kPNG,
30 IDM_kOnce,
31 IDM_kContinous,
32 IDM_kRate25ps,
33 IDM_kRate5ps,
34 IDM_kRate1s,
35 IDM_kRate5s,
36 IDM_kRate30s,
37 IDM_kRate1m,
38 IDM_kRate5m,
39 IDM_kSetup,
40 IDM_kLimMag3,
41 IDM_kLimMag4,
42 IDM_kLimMag5,
43 IDM_kLimMag6,
44 IDM_kLimMag7,
45 IDM_kLimMag8,
46 IDM_kLimMag9
47};
48
49MGStarguider::MGStarguider()
50: Camera(), TGMainFrame(gClient->GetRoot(), 768, 700)
51{
52 fList = new MGList;
53
54 fSao = new StarCatalog;
55 fRaDec = new RaDec(180, 40);
56
57 // p = pointer to MainFrame (not owner)
58
59 const TGWindow *p=gClient->GetRoot();
60
61 //
62 // Create Menu for MGStarguider Display
63 //
64 fDisplay = new TGPopupMenu(p);
65 fDisplay->AddEntry("&Filter", IDM_kFilter);
66 fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
67 fDisplay->Associate(this);
68 fList->Add(fDisplay);
69
70 fFileType = new TGPopupMenu(p);
71 fFileType->AddEntry("PP&M", IDM_kPPM);
72 fFileType->AddEntry("&PNG", IDM_kPNG);
73 fFileType->CheckEntry(IDM_kPNG);
74 fFileType->Associate(this);
75 fList->Add(fFileType);
76
77 fWriteType = new TGPopupMenu(p);
78 fWriteType->AddEntry("Once", IDM_kOnce);
79 fWriteType->AddEntry("Continous", IDM_kContinous);
80 fWriteType->CheckEntry(IDM_kOnce);
81 fWriteType->Associate(this);
82 fList->Add(fWriteType);
83
84 fWriteRate = new TGPopupMenu(p);
85 fWriteRate->AddEntry("25/s", IDM_kRate25ps);
86 fWriteRate->AddEntry("5/s", IDM_kRate5ps);
87 fWriteRate->AddEntry("1s", IDM_kRate1s);
88 fWriteRate->AddEntry("5s", IDM_kRate5s);
89 fWriteRate->AddEntry("30s", IDM_kRate30s);
90 fWriteRate->AddEntry("1min", IDM_kRate1m);
91 fWriteRate->AddEntry("5min", IDM_kRate5m);
92 fWriteRate->CheckEntry(IDM_kRate1m);
93 fWriteRate->Associate(this);
94 fList->Add(fWriteRate);
95
96 fWrtRate = 25*60;
97
98 fWrite = new TGPopupMenu(p);
99 fWrite->AddEntry("&Start", IDM_kStart);
100 fWrite->AddEntry("Sto&p", IDM_kStop);
101 fWrite->AddSeparator();
102 fWrite->AddPopup("File &Type", fFileType);
103 fWrite->AddPopup("&Write Type", fWriteType);
104 fWrite->AddPopup("Write &Rate", fWriteRate);
105 fWrite->DisableEntry(IDM_kStop);
106 fWrite->Associate(this);
107 fList->Add(fWrite);
108
109 fLimMag = new TGPopupMenu(p);
110 fLimMag->AddEntry("3", IDM_kLimMag3);
111 fLimMag->AddEntry("4", IDM_kLimMag4);
112 fLimMag->AddEntry("5", IDM_kLimMag5);
113 fLimMag->AddEntry("6", IDM_kLimMag6);
114 fLimMag->AddEntry("7", IDM_kLimMag7);
115 fLimMag->AddEntry("8", IDM_kLimMag8);
116 fLimMag->AddEntry("9", IDM_kLimMag9);
117 fLimMag->CheckEntry(IDM_kLimMag8);
118 fLimMag->Associate(this);
119 fList->Add(fLimMag);
120
121 fSao->SetLimitMag(8.0);
122
123 fSetup = new TGPopupMenu(p);
124 fSetup->AddPopup("Lim. &Magnitude", fLimMag);
125 fSetup->Associate(this);
126 fList->Add(fSetup);
127
128 fMenu = new TGMenuBar(this, 0, 0, kHorizontalFrame);
129 fMenu->AddPopup("&Display", fDisplay, NULL);
130 fMenu->AddPopup("&Write", fWrite, NULL);
131 fMenu->AddPopup("&Setup", fSetup, NULL);
132 fMenu->Resize(fMenu->GetDefaultSize());
133 AddFrame(fMenu); //, new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0));
134 fList->Add(fMenu);
135
136 fCRaDec = new MGCoordinates(this, kETypeRaDec);
137 fCRaDec->Move(1, fMenu->GetDefaultHeight()+584);
138 AddFrame(fCRaDec);
139 fList->Add(fCRaDec);
140
141 fCZdAz = new MGCoordinates(this, kETypeZdAz);
142 fCZdAz->Move(240+12, fMenu->GetDefaultHeight()+584);
143 AddFrame(fCZdAz);
144 fList->Add(fCZdAz);
145
146 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
147 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
148 // fList->Add(fLineSep);
149
150 //
151 // Create Image Display
152 //
153 fImage = new MGImage(this, 768, 576);
154 fImage->Move(0, fMenu->GetDefaultHeight());
155 AddFrame(fImage);
156 fList->Add(fImage);
157
158 //
159 // Make everything visible
160 //
161 SetWindowName("MGStarguider Main Window");
162 SetIconName("MGStarguider");
163
164 MapSubwindows();
165 MapWindow();
166
167 fSao->SetPixSize(0.006);
168}
169
170MGStarguider::~MGStarguider()
171{
172 delete fSao;
173 delete fRaDec;
174
175 delete fList;
176 cout << "Camera Display destroyed." << endl;
177}
178
179void MGStarguider::Layout()
180{
181 // Resize(GetDefaultSize());
182}
183
184void MGStarguider::CloseWindow()
185{
186 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
187
188 ExitLoop();
189
190 gSystem->ExitLoop();
191}
192
193Bool_t MGStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
194{
195 switch (GET_MSG(msg))
196 {
197 case kC_COMMAND:
198 switch (GET_SUBMSG(msg))
199 {
200 case kCM_MENU:
201 switch (mp1)
202 {
203 case IDM_kCatalog:
204 if (fDisplay->IsEntryChecked(IDM_kCatalog))
205 fDisplay->UnCheckEntry(IDM_kCatalog);
206 else
207 fDisplay->CheckEntry(IDM_kCatalog);
208 return kTRUE;
209
210 case IDM_kFilter:
211 if (fDisplay->IsEntryChecked(IDM_kFilter))
212 fDisplay->UnCheckEntry(IDM_kFilter);
213 else
214 fDisplay->CheckEntry(IDM_kFilter);
215 return kTRUE;
216
217 case IDM_kStart:
218 fWrite->DisableEntry(IDM_kStart);
219 fWrite->EnableEntry(IDM_kStop);
220 return kTRUE;
221
222 case IDM_kStop:
223 fWrite->DisableEntry(IDM_kStop);
224 fWrite->EnableEntry(IDM_kStart);
225 return kTRUE;
226
227 case IDM_kPNG:
228 fFileType->CheckEntry(IDM_kPNG);
229 fFileType->UnCheckEntry(IDM_kPPM);
230 return kTRUE;
231
232 case IDM_kPPM:
233 fFileType->CheckEntry(IDM_kPPM);
234 fFileType->UnCheckEntry(IDM_kPNG);
235 return kTRUE;
236
237 case IDM_kOnce:
238 fWriteType->CheckEntry(IDM_kOnce);
239 fWriteType->UnCheckEntry(IDM_kContinous);
240 return kTRUE;
241
242 case IDM_kContinous:
243 fWriteType->CheckEntry(IDM_kContinous);
244 fWriteType->UnCheckEntry(IDM_kOnce);
245 return kTRUE;
246
247 case IDM_kRate25ps:
248 case IDM_kRate5ps:
249 case IDM_kRate1s:
250 case IDM_kRate5s:
251 case IDM_kRate30s:
252 case IDM_kRate1m:
253 case IDM_kRate5m:
254 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
255 if (mp1==i)
256 fWriteRate->CheckEntry(i);
257 else
258 fWriteRate->UnCheckEntry(i);
259 switch (mp1)
260 {
261 case IDM_kRate25ps:
262 fWrtRate = 1;
263 return kTRUE;
264 case IDM_kRate5ps:
265 fWrtRate = 5;
266 return kTRUE;
267 case IDM_kRate1s:
268 fWrtRate = 25;
269 return kTRUE;
270 case IDM_kRate5s:
271 fWrtRate = 5*25;
272 return kTRUE;
273 case IDM_kRate30s:
274 fWrtRate = 30*25;
275 return kTRUE;
276 case IDM_kRate1m:
277 fWrtRate = 60*25;
278 return kTRUE;
279 case IDM_kRate5m:
280 fWrtRate = 5*60*25;
281 return kTRUE;
282 }
283 return kTRUE;
284
285 case IDM_kLimMag3:
286 case IDM_kLimMag4:
287 case IDM_kLimMag5:
288 case IDM_kLimMag6:
289 case IDM_kLimMag7:
290 case IDM_kLimMag8:
291 case IDM_kLimMag9:
292 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
293 if (mp1==i)
294 fLimMag->CheckEntry(i);
295 else
296 fLimMag->UnCheckEntry(i);
297
298 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
299 return kTRUE;
300 }
301 break;
302 }
303 break;
304 }
305 return kTRUE;
306}
307
308void MGStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
309{
310
311 if (!fWrite->IsEntryEnabled(IDM_kStart) &&
312 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
313 {
314 if (fFileType->IsEntryChecked(IDM_kPNG))
315 {
316 static int num = 0;
317
318 char name[80];
319 sprintf(name, "pix/file%04d.png", num);
320 Writer::Png(name, img, tm);
321 }
322
323 if (fFileType->IsEntryChecked(IDM_kPPM))
324 {
325 static int num = 0;
326 char name[80];
327 sprintf(name, "pix/file%04d.ppm", num);
328 Writer::Ppm(name, img);
329 }
330
331 if (fWriteType->IsEntryChecked(IDM_kOnce))
332 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
333 }
334
335 if (!(n%25))
336 {
337 cout << "Img: " << n << endl;
338
339 if (fDisplay->IsEntryChecked(IDM_kFilter))
340 Filter::Execute(img);
341
342 if (fDisplay->IsEntryChecked(IDM_kCatalog))
343 {
344 byte cimg[768*576];
345
346 XY xy = fCRaDec->GetCoordinates();
347
348 fRaDec->Set(xy.X(), xy.Y());
349
350 Timer time(tm);
351 fSao->GetImg(img, cimg, time.CalcMjd(), *fRaDec);
352 fImage->DrawColImg(img, cimg);
353
354 fCZdAz->SetCoordinates(fSao->GetZdAz());
355 }
356 else
357 fImage->DrawImg(img);
358 }
359
360}
Note: See TracBrowser for help on using the repository browser.