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