source: trunk/MagicSoft/Cosy/Starguider.cc@ 1642

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