source: trunk/MagicSoft/Cosy/gui/MGTPoint.cc@ 9517

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