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

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