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

Last change on this file since 854 was 808, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.4 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 "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, kTRUE,
126 "Right Ascension [\xb0]:", "Declination [\xb0]:");
127 fCRaDec->Move(1, fMenu->GetDefaultHeight()+584);
128 AddFrame(fCRaDec);
129 fList.Add(fCRaDec);
130
131 fCZdAz = new MGCoordinates(this, kFALSE,
132 "Zenith Dist. [\xb0]:", "Azimuth [\xb0]:");
133 fCZdAz->Move(240+12, fMenu->GetDefaultHeight()+584);
134 AddFrame(fCZdAz);
135 fList.Add(fCZdAz);
136
137 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
138 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
139 // fList.Add(fLineSep);
140
141 //
142 // Create Image Display
143 //
144 fImage = new MGImage(this, 768, 576);
145 fImage->Move(0, fMenu->GetDefaultHeight());
146 AddFrame(fImage);
147 fList.Add(fImage);
148
149 //
150 // Make everything visible
151 //
152 SetWindowName("Starguider Main Window");
153 SetIconName("Starguider");
154
155 MapSubwindows();
156 MapWindow();
157
158 fSao.SetPixSize(0.006);
159}
160
161Starguider::~Starguider()
162{
163 cout << "Camera Display destroyed." << endl;
164}
165
166void Starguider::Layout()
167{
168 // Resize(GetDefaultSize());
169}
170
171void Starguider::CloseWindow()
172{
173 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
174
175 ExitLoop();
176
177 gSystem->ExitLoop();
178}
179
180Bool_t Starguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
181{
182 switch (GET_MSG(msg))
183 {
184 case kC_COMMAND:
185 switch (GET_SUBMSG(msg))
186 {
187 case kCM_MENU:
188 switch (mp1)
189 {
190 case IDM_kCatalog:
191 if (fDisplay->IsEntryChecked(IDM_kCatalog))
192 fDisplay->UnCheckEntry(IDM_kCatalog);
193 else
194 fDisplay->CheckEntry(IDM_kCatalog);
195 return kTRUE;
196
197 case IDM_kFilter:
198 if (fDisplay->IsEntryChecked(IDM_kFilter))
199 fDisplay->UnCheckEntry(IDM_kFilter);
200 else
201 fDisplay->CheckEntry(IDM_kFilter);
202 return kTRUE;
203
204 case IDM_kStart:
205 fWrite->DisableEntry(IDM_kStart);
206 fWrite->EnableEntry(IDM_kStop);
207 return kTRUE;
208
209 case IDM_kStop:
210 fWrite->DisableEntry(IDM_kStop);
211 fWrite->EnableEntry(IDM_kStart);
212 return kTRUE;
213
214 case IDM_kPNG:
215 fFileType->CheckEntry(IDM_kPNG);
216 fFileType->UnCheckEntry(IDM_kPPM);
217 return kTRUE;
218
219 case IDM_kPPM:
220 fFileType->CheckEntry(IDM_kPPM);
221 fFileType->UnCheckEntry(IDM_kPNG);
222 return kTRUE;
223
224 case IDM_kOnce:
225 fWriteType->CheckEntry(IDM_kOnce);
226 fWriteType->UnCheckEntry(IDM_kContinous);
227 return kTRUE;
228
229 case IDM_kContinous:
230 fWriteType->CheckEntry(IDM_kContinous);
231 fWriteType->UnCheckEntry(IDM_kOnce);
232 return kTRUE;
233
234 case IDM_kRate25ps:
235 case IDM_kRate5ps:
236 case IDM_kRate1s:
237 case IDM_kRate5s:
238 case IDM_kRate30s:
239 case IDM_kRate1m:
240 case IDM_kRate5m:
241 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
242 if (mp1==i)
243 fWriteRate->CheckEntry(i);
244 else
245 fWriteRate->UnCheckEntry(i);
246 switch (mp1)
247 {
248 case IDM_kRate25ps:
249 fWrtRate = 1;
250 return kTRUE;
251 case IDM_kRate5ps:
252 fWrtRate = 5;
253 return kTRUE;
254 case IDM_kRate1s:
255 fWrtRate = 25;
256 return kTRUE;
257 case IDM_kRate5s:
258 fWrtRate = 5*25;
259 return kTRUE;
260 case IDM_kRate30s:
261 fWrtRate = 30*25;
262 return kTRUE;
263 case IDM_kRate1m:
264 fWrtRate = 60*25;
265 return kTRUE;
266 case IDM_kRate5m:
267 fWrtRate = 5*60*25;
268 return kTRUE;
269 }
270 return kTRUE;
271
272 case IDM_kLimMag3:
273 case IDM_kLimMag4:
274 case IDM_kLimMag5:
275 case IDM_kLimMag6:
276 case IDM_kLimMag7:
277 case IDM_kLimMag8:
278 case IDM_kLimMag9:
279 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
280 if (mp1==i)
281 fLimMag->CheckEntry(i);
282 else
283 fLimMag->UnCheckEntry(i);
284
285 fSao.SetLimitMag(mp1-IDM_kLimMag3+3);
286 return kTRUE;
287 }
288 break;
289 }
290 break;
291 }
292 return kTRUE;
293}
294
295void Starguider::Execute(const unsigned long n, byte *img, struct timeval *tm)
296{
297
298 if (!fWrite->IsEntryEnabled(IDM_kStart) &&
299 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
300 {
301 if (fFileType->IsEntryChecked(IDM_kPNG))
302 {
303 static int num = 0;
304
305 char name[80];
306 sprintf(name, "pix/file%04d.png", num);
307 Writer::Png(name, img, tm);
308 }
309
310 if (fFileType->IsEntryChecked(IDM_kPPM))
311 {
312 static int num = 0;
313 char name[80];
314 sprintf(name, "pix/file%04d.ppm", num);
315 Writer::Ppm(name, img);
316 }
317
318 if (fWriteType->IsEntryChecked(IDM_kOnce))
319 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
320 }
321
322 if (!(n%25))
323 {
324 cout << "Img: " << n << endl;
325
326 if (fDisplay->IsEntryChecked(IDM_kFilter))
327 Filter::Execute(img);
328
329 if (fDisplay->IsEntryChecked(IDM_kCatalog))
330 {
331 byte cimg[768*576];
332
333 XY xy = fCRaDec->GetCoordinates();
334
335 fRaDec.Set(xy.X(), xy.Y());
336
337 Timer time(tm);
338 fSao.GetImg(img, cimg, time.GetMjd(), fRaDec);
339 fImage->DrawColImg(img, cimg);
340
341 fCZdAz->SetCoordinates(fSao.GetZdAz());
342 }
343 else
344 fImage->DrawImg(img);
345 }
346
347}
Note: See TracBrowser for help on using the repository browser.