source: trunk/MagicSoft/Cosy/gui/MGCosy.cc@ 1702

Last change on this file since 1702 was 1702, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 33.2 KB
Line 
1#include "MGCosy.h"
2
3#include <iostream.h>
4
5#include "msgqueue.h"
6#include "coord.h"
7
8#include <TROOT.h>
9
10#include <TGTab.h> // TGTab
11#include <TGMenu.h> // TGPopupMenu
12#include <TGButton.h> // TGButton
13#include <TSystem.h> // gSystem
14#include <TGLabel.h> // TGLabel
15#include <TGListBox.h> // TGListBox
16#include <TG3DLine.h> // TGHorizontal3DLine (TGSplitter)
17#include <TGTextEntry.h> // TGTextEntry
18#include <TGFrame.h> // TGGroupFrame
19#include <TApplication.h> // gApplication
20
21//#include "timer.h" // Timer
22
23#include "MCosy.h"
24#include "MGList.h"
25#include "MGAccuracy.h"
26#include "MGCoordinates.h"
27#include "MGSkyPosition.h"
28#include "MGVelocity.h"
29
30#include "SlaStars.h"
31
32#undef DEBUG
33
34ClassImp(MGCosy);
35
36#define IDM_EXIT 1
37#define IDM_TEXT 2
38#define IDM_ASPECT 3
39
40enum
41{
42 kPB_POSITION,
43 kPB_TRACK,
44 kPB_STOP,
45 kPB_HOME,
46 kPB_CALCALTAZ,
47 kPB_TPOINT,
48 kPB_START,
49 kPB_RAp,
50 kPB_RAm,
51 kPB_DECp,
52 kPB_DECm,
53 kPB_LoadBending,
54 kPB_ResetBending,
55 kPB_CALIBSE
56};
57
58void MGCosy::CreateMenu()
59{
60 fLayMenuBar = new TGLayoutHints (kLHintsNormal | kLHintsExpandX);
61 fLayMenuItem = new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0);
62
63 //
64 // crate the menu bar
65 //
66 TGPopupMenu *fFileMenu = new TGPopupMenu(gClient->GetRoot());
67 fFileMenu->AddEntry("Set Aspect", IDM_ASPECT);
68 fFileMenu->AddEntry("Exit", IDM_EXIT);
69 fFileMenu->Associate(this);
70 fList->Add(fFileMenu);
71
72 //
73 // the button messages are handled by main frame (this)
74 //
75 TGMenuBar *fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
76 fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem);
77 AddFrame(fMenuBar, fLayMenuBar);
78 fList->Add(fMenuBar);
79
80 //
81 // Seperator beyond menubar
82 //
83
84 TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
85 AddFrame(fLineSep, fLayMenuBar);
86 fList->Add(fLineSep);
87}
88
89void MGCosy::CreateLabel(TGCompositeFrame *f)
90{
91 const int x = 180;
92 const int y = 25;
93
94 TGLabel *l;
95
96 l = new TGLabel(f, "UTC:");
97 l->Move(x-60, y);
98 fList->Add(l);
99
100 l = new TGLabel(f, "Mjd:");
101 l->Move(x-60, y+17);
102 fList->Add(l);
103
104 fUtc = new TGLabel(f, "0000/00/00 00:00:00.0");
105 fMjd = new TGLabel(f, "00000.000000");
106 fUtc->Move(x-25, y);
107 fMjd->Move(x-25, y+17);
108 fList->Add(fUtc);
109 fList->Add(fMjd);
110
111 l = new TGLabel(f, "SE-Az:");
112 l->Move(x-60, y+40);
113 fList->Add(l);
114
115 l = new TGLabel(f, "SE-Zd1:");
116 l->Move(x-60, y+57);
117 fList->Add(l);
118
119 l = new TGLabel(f, "SE-Zd2:");
120 l->Move(x-60, y+74);
121 fList->Add(l);
122
123 fLabel1 = new TGLabel*[3];
124 fLabel1[0] = new TGLabel(f, "00000"); // Max: 16384
125 fLabel1[1] = new TGLabel(f, "000"); // Max: 256
126 fLabel1[2] = new TGLabel(f, "000"); // Max: 256
127 fLabel1[0]->SetTextJustify(kTextRight);
128 fLabel1[1]->SetTextJustify(kTextRight);
129 fLabel1[2]->SetTextJustify(kTextRight);
130 fLabel1[0]->Move(x, y+40);
131 fLabel1[1]->Move(x+43, y+40);
132 fLabel1[2]->Move(x+70, y+40);
133 fList->Add(fLabel1[0]);
134 fList->Add(fLabel1[1]);
135 fList->Add(fLabel1[2]);
136 //f->AddFrame(fLabel1[0]);
137 //f->AddFrame(fLabel1[1]);
138 //f->AddFrame(fLabel1[2]);
139
140 fLabel2 = new TGLabel*[3];
141 fLabel2[0] = new TGLabel(f, "00000");
142 fLabel2[1] = new TGLabel(f, "000");
143 fLabel2[2] = new TGLabel(f, "000");
144 fLabel2[0]->SetTextJustify(kTextRight);
145 fLabel2[1]->SetTextJustify(kTextRight);
146 fLabel2[2]->SetTextJustify(kTextRight);
147 fLabel2[0]->Move(x, y+57);
148 fLabel2[1]->Move(x+43, y+57);
149 fLabel2[2]->Move(x+70, y+57);
150 fList->Add(fLabel2[0]);
151 fList->Add(fLabel2[1]);
152 fList->Add(fLabel2[2]);
153 //f->AddFrame(fLabel2[0]);
154 //f->AddFrame(fLabel2[1]);
155 //f->AddFrame(fLabel2[2]);
156
157 fLabel3 = new TGLabel*[3];
158 fLabel3[0] = new TGLabel(f, "00000");
159 fLabel3[1] = new TGLabel(f, "000");
160 fLabel3[2] = new TGLabel(f, "000");
161 fLabel3[0]->SetTextJustify(kTextRight);
162 fLabel3[1]->SetTextJustify(kTextRight);
163 fLabel3[2]->SetTextJustify(kTextRight);
164 fLabel3[0]->Move(x, y+74);
165 fLabel3[1]->Move(x+43, y+74);
166 fLabel3[2]->Move(x+70, y+74);
167 fList->Add(fLabel3[0]);
168 fList->Add(fLabel3[1]);
169 fList->Add(fLabel3[2]);
170 //f->AddFrame(fLabel3[0]);
171 //f->AddFrame(fLabel3[1]);
172 //f->AddFrame(fLabel3[2]);
173
174 l = new TGLabel(f, "Offset-Zd:");
175 l->Move(x-60, y+102);
176 fList->Add(l);
177
178 l = new TGLabel(f, "Offset-Az:");
179 l->Move(x-60, y+119);
180 fList->Add(l);
181
182 fOffsetZd = new TGLabel(f, "0000000");
183 fOffsetAz = new TGLabel(f, "0000000");
184 fOffsetZd->SetTextJustify(kTextRight);
185 fOffsetAz->SetTextJustify(kTextRight);
186 fOffsetZd->Move(x, y+102);
187 fOffsetAz->Move(x, y+119);
188 fList->Add(fOffsetZd);
189 fList->Add(fOffsetAz);
190
191 l = new TGLabel(f, "Ra (estimated):");
192 l->Move(x-60, y+142);
193 fList->Add(l);
194
195 l = new TGLabel(f, "Ra (soll):");
196 l->Move(x-60, y+159);
197 fList->Add(l);
198
199 l = new TGLabel(f, "Dec (estimated):");
200 l->Move(x-60, y+182);
201 fList->Add(l);
202
203 l = new TGLabel(f, "Dec (soll):");
204 l->Move(x-60, y+199);
205 fList->Add(l);
206
207 l = new TGLabel(f, "Zd (soll):");
208 l->Move(x-60, y+222);
209 fList->Add(l);
210
211 l = new TGLabel(f, "Az (soll):");
212 l->Move(x-60, y+239);
213 fList->Add(l);
214
215 fRaEst = new TGLabel(f, "+000h 00.0m");
216 fDecEst = new TGLabel(f, "+000h 00.0m");
217 fRaSoll = new TGLabel(f, "+000h 00.0m");
218 fDecSoll = new TGLabel(f, "+000h 00.0m");
219 fZdSoll = new TGLabel(f, "+000h 00.0m");
220 fAzSoll = new TGLabel(f, "+000h 00.0m");
221 fRaEst->SetTextJustify(kTextRight);
222 fDecEst->SetTextJustify(kTextRight);
223 fRaSoll->SetTextJustify(kTextRight);
224 fDecSoll->SetTextJustify(kTextRight);
225 fZdSoll->SetTextJustify(kTextRight);
226 fAzSoll->SetTextJustify(kTextRight);
227 fRaEst->Move(x+30, y+142);
228 fRaSoll->Move(x+30, y+159);
229 fDecEst->Move(x+30, y+182);
230 fDecSoll->Move(x+30, y+199);
231 fZdSoll->Move(x+30, y+222);
232 fAzSoll->Move(x+30, y+239);
233 fList->Add(fRaEst);
234 fList->Add(fDecEst);
235 fList->Add(fRaSoll);
236 fList->Add(fDecSoll);
237 fList->Add(fZdSoll);
238 fList->Add(fAzSoll);
239
240 fError = new TGLabel(f, "Error");
241 fMoving = new TGLabel(f, "Moving");
242 fTracking = new TGLabel(f, "Tracking");
243 fStopping = new TGLabel(f, "Stopping");
244 fStopped = new TGLabel(f, "Stopped");
245 fAvailMac1 = new TGLabel(f, "- MAC1 -");
246 fAvailMac2 = new TGLabel(f, "- MAC2 -");
247 fAvailMac3 = new TGLabel(f, "- MAC3 -");
248 fAvailSe1 = new TGLabel(f, "-SE/Zd1-");
249 fAvailSe2 = new TGLabel(f, "-SE/Zd2-");
250 fAvailSe3 = new TGLabel(f, "- SE/Az -");
251
252 ULong_t color;
253
254 gClient->GetColorByName("Red", color);
255 fError->SetBackgroundColor(color);
256 fAvailMac1->SetBackgroundColor(color);
257 fAvailMac2->SetBackgroundColor(color);
258 fAvailMac3->SetBackgroundColor(color);
259 fAvailSe1->SetBackgroundColor(color);
260 fAvailSe2->SetBackgroundColor(color);
261 fAvailSe3->SetBackgroundColor(color);
262 gClient->GetColorByName("LightBlue", color);
263 fMoving->SetBackgroundColor(color);
264 gClient->GetColorByName("Blue", color);
265 fTracking->SetBackgroundColor(color);
266 gClient->GetColorByName("Orange", color);
267 fStopping->SetBackgroundColor(color);
268 gClient->GetColorByName("Green", color);
269 fStopped->SetBackgroundColor(color);
270
271 fError ->Move(10, 25);
272 fMoving ->Move(10, 25+20);
273 fTracking->Move(10, 25+40);
274 fStopping->Move(10, 25+60);
275 fStopped ->Move(10, 25+80);
276 fAvailMac1->Move(10, 25+120);
277 fAvailMac2->Move(10, 25+140);
278 fAvailMac3->Move(10, 25+160);
279 fAvailSe1->Move(10, 25+180);
280 fAvailSe2->Move(10, 25+200);
281 fAvailSe3->Move(10, 25+220);
282
283 fError ->Resize(60, 20);
284 fMoving ->Resize(60, 20);
285 fTracking->Resize(60, 20);
286 fStopping->Resize(60, 20);
287 fStopped ->Resize(60, 20);
288 fAvailMac1->Resize(60, 20);
289 fAvailMac2->Resize(60, 20);
290 fAvailMac3->Resize(60, 20);
291 fAvailSe1->Resize(60, 20);
292 fAvailSe2->Resize(60, 20);
293 fAvailSe3->Resize(60, 20);
294
295 fList->Add(fError);
296 fList->Add(fMoving);
297 fList->Add(fTracking);
298 fList->Add(fStopping);
299 fList->Add(fStopped);
300 fList->Add(fAvailMac1);
301 fList->Add(fAvailMac2);
302 fList->Add(fAvailMac3);
303 fList->Add(fAvailSe1);
304 fList->Add(fAvailSe2);
305 fList->Add(fAvailSe3);
306}
307
308void MGCosy::CreateTabs(TGTab *fTab)
309{
310 TGCompositeFrame *tf1 = fTab->AddTab("Position");
311 TGCompositeFrame *tf2 = fTab->AddTab("Track");
312 TGCompositeFrame *tf4 = fTab->AddTab("Calibration");
313 TGCompositeFrame *tf3 = fTab->AddTab("Demo");
314
315 fCZdAz = new MGCoordinates(tf1, kETypeZdAz);
316 fCZdAz->Move(27, 105);
317 fList->Add(fCZdAz);
318
319 fCRaDec = new MGCoordinates(tf2, kETypeRaDec);
320 fCRaDec->Move(27, 105);
321 fList->Add(fCRaDec);
322
323 fCCalib = new MGCoordinates(tf4, kETypeRaDec);
324 fCCalib->Move(27, 105);
325 fList->Add(fCCalib);
326
327 const int x=15;
328 const int y=12;
329 const int h=16;
330
331 TGLabel *l1 = new TGLabel(tf1, "Move the telescope to a position given in");
332 TGLabel *l2 = new TGLabel(tf1, "local coordinates. The given coordinates");
333 TGLabel *l3 = new TGLabel(tf1, "are pointing coordinates, which means that the");
334 TGLabel *l4 = new TGLabel(tf1, "coordinates are corrected for the bending of");
335 TGLabel *l5 = new TGLabel(tf1, "the telescope.");
336 l1->Move(x, y);
337 l2->Move(x, y+h);
338 l3->Move(x, y+2*h);
339 l4->Move(x, y+3*h);
340 l5->Move(x, y+4*h);
341 fList->Add(l1);
342 fList->Add(l2);
343 fList->Add(l3);
344 fList->Add(l4);
345 fList->Add(l5);
346
347 l1 = new TGLabel(tf2, "Track a position given in sky coordinates.");
348 l2 = new TGLabel(tf2, "Right Ascension and declination must be given");
349 l3 = new TGLabel(tf2, "in the FK5, J2000 coordinate system.");
350 l1->Move(x, y);
351 l2->Move(x, y+h);
352 l3->Move(x, y+2*h);
353 fList->Add(l1);
354 fList->Add(l2);
355 fList->Add(l3);
356
357 l1 = new TGLabel(tf4, "Start the calibration using the Start button.");
358 l2 = new TGLabel(tf4, "Write a coordinate pair to a TPoint file using");
359 l3 = new TGLabel(tf4, "the TPoint button. To set the Shaftencoder offset");
360 l4 = new TGLabel(tf4, "use the Calib SE button.");
361 l1->Move(x, y);
362 l2->Move(x, y+h);
363 l3->Move(x, y+2*h);
364 l4->Move(x, y+3*h);
365 fList->Add(l1);
366 fList->Add(l2);
367 fList->Add(l3);
368 fList->Add(l4);
369
370 //
371 // light green: 3 light red: 2 blue?: 2
372 // dark green: 8 dark red: 50 dark blue?: 1
373
374 //
375 // blue: 0-7, 9, 10,11, 14, 15, 18, 19, 22, 23, 27, 31, 33-39, 41-43
376 // 46, 47
377 // green: 8, 12,13, 16, 17, 20, 21, 24, 25, 26, 28, 29, 30, 40, 44
378 // 45, 48
379 // gray: 31, 113-
380 // red: 164, 192, 224, 232
381 //
382 TGTextButton *but;
383
384 but= new TGTextButton(tf2, "Ra -", kPB_RAm);
385 but->Resize(50, 25);
386 but->Move(25, 210);
387 but->SetToolTipText("Right ascension -= 1'");
388 but->Associate(this);
389 fList->Add(but);
390 but= new TGTextButton(tf2, "RA +", kPB_RAp);
391 but->Resize(50, 25);
392 but->Move(90, 210);
393 but->SetToolTipText("Right ascension += 1'");
394 but->Associate(this);
395 fList->Add(but);
396 but= new TGTextButton(tf2, "DEC +", kPB_DECp);
397 but->Resize(50, 25);
398 but->Move(55, 185);
399 but->SetToolTipText("Declination += 1'");
400 but->Associate(this);
401 fList->Add(but);
402 but= new TGTextButton(tf2, "DEC -", kPB_DECm);
403 but->Resize(50, 25);
404 but->Move(55, 235);
405 but->SetToolTipText("Declination -= 1'");
406 but->Associate(this);
407 fList->Add(but);
408
409 but = new TGTextButton(tf1, "Home", kPB_HOME);
410 but->Resize(80, 25);
411 but->Move(160, 197);
412 but->SetToolTipText("Initiate Home Drive.");
413 but->Associate(this);
414 fList->Add(but);
415
416 but= new TGTextButton(tf2, "Calc Zd/Az", kPB_CALCALTAZ);
417 but->Resize(80, 25);
418 but->Move(165, 197);
419 but->SetToolTipText("Calculate Zd/Az corresponding to Ra/Dec.");
420 but->Associate(this);
421 fList->Add(but);
422
423 but = new TGTextButton(tf4, "TPoint", kPB_TPOINT);
424 but->Resize(80, 25);
425 but->Move(25, 190);
426 but->SetToolTipText("Trigger writing a tpoint coordinate pair.");
427 but->Associate(this);
428 fList->Add(but);
429
430 but = new TGTextButton(tf4, "Calib SE", kPB_CALIBSE);
431 but->Resize(80, 25);
432 but->Move(160, 197);
433 but->SetToolTipText("Set SE to given coordinates.");
434 but->Associate(this);
435 fList->Add(but);
436
437 but = new TGTextButton(tf4, "Load", kPB_LoadBending);
438 but->Resize(80, 25);
439 but->Move(25, 220);
440 but->SetToolTipText("Load bending corrections from file 'bending.txt'");
441 but->Associate(this);
442 fList->Add(but);
443
444 but = new TGTextButton(tf4, "Reset", kPB_ResetBending);
445 but->Resize(80, 25);
446 but->Move(25, 250);
447 but->SetToolTipText("Reset bending correction (coefficients=0)");
448 but->Associate(this);
449 fList->Add(but);
450
451 ULong_t color;
452
453 but = new TGTextButton(this, "Start", kPB_START);
454 gClient->GetColorByName("Green", color);
455 but->SetBackgroundColor(color);
456 but->Move(147, 295);
457 but->Resize(62, 25);
458 but->SetToolTipText("Start a telescope movement.");
459 fList->Add(but);
460
461 but = new TGTextButton(this, "Stop", kPB_STOP);
462
463 gClient->GetColorByName("Red", color);
464 but->SetBackgroundColor(color);
465 but->Move(212, 295);
466 but->Resize(62, 25);
467 but->SetToolTipText("Stop any movement of telescope.");
468 fList->Add(but);
469
470 /*
471 const Double_t ca = 0; // Left-Right Collimation Error
472 const Double_t an = 0; // Azimuth Axis Misalignment (N-S)
473 const Double_t aw = 0; // Azimuth Axis Misalignment (E-W)
474 const Double_t npae = 0; // Az-El Nonperpendicularity
475 const Double_t nrx = 0; // Nasmyth rotator displacement, horizontan
476 const Double_t nry = 0; // Nasmyth rotator displacement, vertical
477 const Double_t crx = 0; // Alt/Az Coude Displacement (N-S)
478 const Double_t cry = 0; // Alt/Az Coude Displacement (E-W)
479 l1 = new TGLabel(tf5, "CA");
480 l1->SetTextJustify(kTextLeft);
481 l1->Move(x, y+2*h*1.5);
482 l1->MapWindow();
483 fList->Add(l1);
484 l1 = new TGLabel(tf5, "AN");
485 l1->SetTextJustify(kTextLeft);
486 l1->Move(x, y+3*h*1.5);
487 l1->MapWindow();
488 fList->Add(l1);
489 l1 = new TGLabel(tf5, "AW");
490 l1->SetTextJustify(kTextLeft);
491 l1->Move(x, y+4*h*1.5);
492 l1->MapWindow();
493 fList->Add(l1);
494 l1 = new TGLabel(tf5, "NPAE");
495 l1->SetTextJustify(kTextLeft);
496 l1->Move(x, y+5*h*1.5);
497 l1->MapWindow();
498 fList->Add(l1);
499 l1 = new TGLabel(tf5, "NRX");
500 l1->SetTextJustify(kTextLeft);
501 l1->Move(x, y+6*h*1.5);
502 l1->MapWindow();
503 fList->Add(l1);
504 l1 = new TGLabel(tf5, "NRY");
505 l1->SetTextJustify(kTextLeft);
506 l1->Move(x, y+7*h*1.5);
507 l1->MapWindow();
508 fList->Add(l1);
509 l1 = new TGLabel(tf5, "CRX");
510 l1->SetTextJustify(kTextLeft);
511 l1->Move(x, y+8*h*1.5);
512 l1->MapWindow();
513 fList->Add(l1);
514 l1 = new TGLabel(tf5, "CRY");
515 l1->SetTextJustify(kTextLeft);
516 l1->Move(x, y+9*h*1.5);
517 l1->MapWindow();
518 fList->Add(l1);
519 const Double_t ie = 0; // Index Error in Elevation
520 const Double_t ia = 0; // Index Error in Azimuth
521 const Double_t eces = 0; // Elevation Centering Error (sin)
522 const Double_t ecec = 0; // Elevation Centering Error (cos)
523 const Double_t aces = 0; // Azimuth Centering Error (sin)
524 const Double_t acec = 0; // Azimuth Centering Error (cos)
525 l1 = new TGLabel(tf5, "IE");
526 l1->SetTextJustify(kTextLeft);
527 l1->Move(x+150, y+3*h*1.5);
528 l1->MapWindow();
529 fList->Add(l1);
530 l1 = new TGLabel(tf5, "IA");
531 l1->SetTextJustify(kTextLeft);
532 l1->Move(x+150, y+4*h*1.5);
533 l1->MapWindow();
534 fList->Add(l1);
535 l1 = new TGLabel(tf5, "ECES");
536 l1->SetTextJustify(kTextLeft);
537 l1->Move(x+150, y+5*h*1.5);
538 l1->MapWindow();
539 fList->Add(l1);
540 l1 = new TGLabel(tf5, "ECEC");
541 l1->SetTextJustify(kTextLeft);
542 l1->Move(x+150, y+6*h*1.5);
543 l1->MapWindow();
544 fList->Add(l1);
545 l1 = new TGLabel(tf5, "ACES");
546 l1->SetTextJustify(kTextLeft);
547 l1->Move(x+150, y+4*h*1.5);
548 l1->MapWindow();
549 fList->Add(l1);
550 l1 = new TGLabel(tf5, "IA");
551 l1->SetTextJustify(kTextLeft);
552 l1->Move(x+150, y+4*h*1.5);
553 l1->MapWindow();
554 fList->Add(l1);
555
556
557 TGTextEntry *entry = new TGTextEntry(tf5, "****", kEF_BendIE);
558 entry->Associate(this);
559 entry->Move(x+50, y+2*h*1.5);
560 entry->MapWindow();
561 fList->Add(entry);
562
563 entry = new TGTextEntry(tf5, "*****", kEF_BendIA);
564 entry->Associate(this);
565 entry->Move(x+50, y+3*h*1.5);
566 entry->MapWindow();
567 fList->Add(entry);
568 */
569}
570
571MGCosy::MGCosy(MsgQueue *q, const TGWindow *p, UInt_t w, UInt_t h)
572 : TGMainFrame(p, w, h), fQueue(q)
573{
574 fList = new MGList;
575
576#ifdef DEBUG
577 cout << "MGCosy: Creating Menu" << endl;
578#endif
579 CreateMenu();
580
581#ifdef DEBUG
582 cout << "MGCosy: Creating TGCompositeFrame" << endl;
583#endif
584 TGHorizontalFrame *f1 = new TGHorizontalFrame(this, 0, 0);
585 TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 0, 0);
586 fList->Add(f1);
587 fList->Add(f2);
588
589#ifdef DEBUG
590 cout << "MGCosy: Creating TGTab" << endl;
591#endif
592 fTab = new TGTab(f1, 300, 300);
593 fList->Add(fTab);
594
595#ifdef DEBUG
596 cout << "MGCosy: Creating MGSkyPosition" << endl;
597#endif
598 fSkyPosition = new MGSkyPosition(f1, 300);
599#ifdef DEBUG
600 cout << "MGCosy: Creating MGAccuracy" << endl;
601#endif
602 fAccuracy = new MGAccuracy (f1, 300);
603#ifdef DEBUG
604 cout << "MGCosy: Creating MGVelocity" << endl;
605#endif
606 fVelocity = new MGVelocity (f2, "Velocity [\"/min]", 300);
607// fOffset = new MGVelocity (f, "Offset se-re [']", 300);
608
609 fList->Add(fSkyPosition);
610 fList->Add(fAccuracy);
611 fList->Add(fVelocity);
612// fList->Add(fOffset);
613
614#ifdef DEBUG
615 cout << "MGCosy: Creating TGGroupFrame" << endl;
616#endif
617 TGGroupFrame *frame = new TGGroupFrame(f2, "Status");
618 frame->Resize(300, 300);
619 fList->Add(frame);
620
621#ifdef DEBUG
622 cout << "MGCosy: Creating TGListBox" << endl;
623#endif
624 fLog = new TGListBox(f2, -1, kSunkenFrame); //kSunkenFrame|kDoubleBorder,
625 fLog->Resize(300, 300);
626 fLog->ChangeBackground(TGFrame::GetBlackPixel());
627 fList->Add(fLog);
628
629 TGLayoutHints *hints1 = new TGLayoutHints(kLHintsNormal | kLHintsExpandX|kLHintsExpandY, 6, 6, 6, 3);
630 TGLayoutHints *hints2 = new TGLayoutHints(kLHintsNormal | kLHintsExpandX|kLHintsExpandY, 6, 6, 3, 6);
631 TGLayoutHints *hints1a = new TGLayoutHints(kLHintsLeft | kLHintsTop |kLHintsExpandX|kLHintsExpandY);
632 TGLayoutHints *hints2a = new TGLayoutHints(kLHintsCenterY | kLHintsTop |kLHintsExpandX|kLHintsExpandY, 6, 6);
633 TGLayoutHints *hints3a = new TGLayoutHints(kLHintsRight | kLHintsTop |kLHintsExpandX|kLHintsExpandY);
634 TGLayoutHints *hints1b = new TGLayoutHints(kLHintsLeft | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
635 TGLayoutHints *hints2b = new TGLayoutHints(kLHintsCenterY | kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 6, 6);
636 TGLayoutHints *hints3b = new TGLayoutHints(kLHintsRight | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
637
638 fList->Add(hints1);
639 fList->Add(hints2);
640 fList->Add(hints1a);
641 fList->Add(hints2a);
642 fList->Add(hints3a);
643 fList->Add(hints1b);
644 fList->Add(hints2b);
645 fList->Add(hints3b);
646
647 // Layout upper frame
648 f1->AddFrame(fTab, hints1a);
649 f1->AddFrame(fSkyPosition, hints2a);
650 f1->AddFrame(fAccuracy, hints3a);
651
652 // Layout upper frame
653 f2->AddFrame(frame, hints1b);
654 f2->AddFrame(fVelocity, hints2b);
655 f2->AddFrame(fLog, hints3b);
656
657 // Layout window
658 AddFrame(f1, hints1);
659 AddFrame(f2, hints2);
660
661 //
662 // FIXME!
663 //
664#ifdef DEBUG
665 cout << "MGCosy: Creating Tabs" << endl;
666#endif
667 CreateTabs(fTab);
668#ifdef DEBUG
669 cout << "MGCosy: Creating Label" << endl;
670#endif
671 CreateLabel(frame);
672
673 //
674 // Map the window, set up the layout, etc.
675 //
676#ifdef DEBUG
677 cout << "MGCosy: Setting Size" << endl;
678#endif
679 const Int_t w = 940;
680 const Int_t h = 660;
681 SetWMSizeHints(w, h, 1280, 900, 10, 10); // set the smallest and biggest size of the Main frame
682
683 SetWindowName("Cosy Main Window");
684 SetIconName("Cosy");
685
686#ifdef DEBUG
687 cout << "MGCosy: Map Window" << endl;
688#endif
689 MapSubwindows();
690 Resize(w, h); //GetDefaultSize());
691 MapWindow();
692}
693
694// ======================================================================
695
696MGCosy::~MGCosy()
697{
698 cout << "MGCosy::~MGCosy called." << endl;
699
700 delete fLayMenuBar;
701 delete fLayMenuItem;
702
703 cout << "Deleting MGCosy::fList" << endl;
704
705 delete fList;
706
707 cout << "MGCosy::~MGCosy done." << endl;
708}
709
710void MGCosy::SetLabelColor(TGLabel *label, Bool_t col)
711{
712 ULong_t red, green;
713
714 gClient->GetColorByName("Red", red);
715 gClient->GetColorByName("Green", green);
716
717 if (col && label->TestBit(BIT(14)))
718 return;
719
720 if (!col && !label->TestBit(BIT(14)))
721 return;
722
723 col ? label->SetBit(BIT(14)) : label->ResetBit(BIT(14));
724
725 label->UnmapWindow();
726 label->SetBackgroundColor(col ? green : red);
727 label->MapWindow();
728}
729
730// ======================================================================
731void MGCosy::EnableLabel(TGLabel *label, Bool_t stat)
732{
733 stat ? label->MapWindow() : label->UnmapWindow();
734
735 /*
736 TGGC *fRedTextGC(TGButton::GetDefaultGC())
737 // Set foreground color in graphics context for drawing of
738 // TGlabel and TGButtons with text in red.
739 ULong_t red;
740 gClient->GetColorByName("red", red);
741 fRedTextGC.SetForeground(red);
742 */
743}
744
745void MGCosy::UpdateRaDec(ZdAz &pos, double mjd, RaDec &radec)
746{
747 static Int_t rai=~0;
748 static Int_t deci=~0;
749 static Int_t ras=~0;
750 static Int_t decs=~0;
751
752 static SlaStars sla;
753 sla.SetMjd(mjd);
754
755 RaDec rd = sla.CalcRaDec(pos*2*TMath::Pi()/360);
756
757 char text[64];
758
759 rd.Ra(rd.Ra() * 24/2/TMath::Pi());
760 rd.Dec(rd.Dec()*360/2/TMath::Pi());
761
762 radec.Ra(radec.Ra() * 24/2/TMath::Pi());
763 radec.Dec(radec.Dec()*360/2/TMath::Pi());
764
765 RaDec test = rd*600;
766
767 if (rai!=(int)test.Ra())
768 {
769 rai = (int)test.Ra();
770 sprintf(text, "%c%dh %.1fm", rd.Ra()<0?'-':'+', abs((int)rd.Ra()), 0.1*(abs((int)test.Ra())%600));
771 fRaEst->SetText(new TGString(text));
772 }
773 if (deci!=(int)test.Dec())
774 {
775 deci = (int)test.Dec();
776 sprintf(text, "%c%dd %.1fm", rd.Dec()<0?'-':'+' , abs((int)rd.Dec()), 0.1*(abs((int)test.Dec())%600));
777 fDecEst->SetText(new TGString(text));
778 }
779
780 if (radec.Dec()>90|| radec.Dec()<-90)
781 {
782 radec.Ra(radec.Ra()+12);
783 radec.Dec(180-radec.Dec());
784 }
785 radec.Ra(fmod((radec.Ra()+48), 24));
786
787 test = radec*600;
788
789 if (ras!=(int)test.Ra())
790 {
791 ras = (int)test.Ra();
792 sprintf(text, "%c%dh %.1fm", radec.Ra()<0?'-':'+', abs((int)radec.Ra()), 0.1*(abs((int)test.Ra())%600));
793 fRaSoll->SetText(new TGString(text));
794 }
795 if (decs!=(int)test.Dec())
796 {
797 decs = (int)test.Dec();
798 sprintf(text, "%c%dd %.1fm", radec.Dec()<0?'-':'+' , abs((int)radec.Dec()), 0.1*(abs((int)test.Dec())%600));
799 fDecSoll->SetText(new TGString(text));
800 }
801}
802
803void MGCosy::UpdateOffset(ZdAz &off)
804{
805 static Int_t zd=~0;
806 static Int_t az=~0;
807
808 char text[21];
809
810 if (zd!=(Int_t)off.Zd())
811 {
812 zd = (Int_t)off.Zd();
813 sprintf(text, "%dre", zd);
814 fOffsetZd->SetText(new TGString(text));
815 }
816 if (az!=(Int_t)off.Az())
817 {
818 az = (Int_t)off.Az();
819 sprintf(text, "%dre", az);
820 fOffsetAz->SetText(new TGString(text));
821 }
822}
823
824void MGCosy::UpdateZdAz(ZdAz &soll)
825{
826 soll *= 360/2/TMath::Pi();
827
828 static Int_t zd=~0;
829 static Int_t az=~0;
830
831 char text[21];
832
833 ZdAz test = soll*600;
834
835 if (zd!=(int)test.Zd())
836 {
837 zd = (int)test.Zd();
838 sprintf(text, "%c%dh %.1fm", soll.Zd()<0?'-':'+', abs((int)soll.Zd()), 0.1*(abs((int)test.Zd())%600));
839 fZdSoll->SetText(new TGString(text));
840 }
841 if (az!=(int)test.Az())
842 {
843 az = (int)test.Az();
844 sprintf(text, "%c%dd %.1fm", soll.Az()<0?'-':'+' , abs((int)soll.Az()), 0.1*(abs((int)test.Az())%600));
845 fAzSoll->SetText(new TGString(text));
846 }
847}
848
849double MGCosy::UpdateTime()
850{
851 Timer time;
852 time.Now();
853
854 char text[256];
855
856 strcpy(text, time.GetTimeStr());
857
858 char *dot = strrchr(text, '.');
859
860 if (dot)
861 dot[2] = 0;
862
863 fUtc->SetText(new TGString(text));
864
865 double mjd = time.CalcMjd();
866
867 sprintf(text, "%12.6f", mjd);
868 fMjd->SetText(new TGString(text));
869
870 return mjd;
871}
872
873void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off, RaDec radec,
874 ZdAz soll, UInt_t stat, UInt_t stat2)
875{
876 double mjd = UpdateTime();
877 fSkyPosition->Update(pos, mjd);
878 fAccuracy->Update(pos, acc);
879 fVelocity->Update(vel);
880 UpdateOffset(off);
881 UpdateRaDec(pos, mjd, radec);
882 UpdateZdAz(soll);
883
884#define kError 0x01
885#define kMoving 0x02
886#define kTracking 0x04
887#define kStopping 0x08
888#define kStopped 0x10
889
890 EnableLabel(fError, stat&kError);
891 EnableLabel(fMoving, stat&kMoving);
892 EnableLabel(fTracking, stat&kTracking);
893 EnableLabel(fStopping, stat&kStopping);
894 EnableLabel(fStopped, stat&kStopped);
895 EnableLabel(fRaSoll, stat&kTracking);
896 EnableLabel(fDecSoll, stat&kTracking);
897 EnableLabel(fZdSoll, stat&kMoving);
898 EnableLabel(fAzSoll, stat&kMoving);
899
900 SetLabelColor(fAvailMac1, stat2&0x01);
901 SetLabelColor(fAvailMac2, stat2&0x02);
902 SetLabelColor(fAvailMac3, stat2&0x04);
903 SetLabelColor(fAvailSe1, stat2&0x08);
904 SetLabelColor(fAvailSe2, stat2&0x10);
905 SetLabelColor(fAvailSe3, stat2&0x20);
906
907 stat&kTracking ? fAccuracy->MapWindow() : fAccuracy->UnmapWindow();
908 stat&kTracking ? fVelocity->MapWindow() : fVelocity->UnmapWindow();
909 // stat&kTracking ? fOffset->MapWindow() : fOffset->UnmapWindow();
910
911 if (fLog->TestBit(kHasChanged))
912 {
913 fLog->MapSubwindows();
914 fLog->Layout();
915 fLog->ResetBit(kHasChanged);
916 }
917}
918// ======================================================================
919
920void MGCosy::CloseWindow()
921{
922 // Got close message for this MainFrame. Calls parent CloseWindow()
923 // (which destroys the window) and terminate the application.
924 // The close message is generated by the window manager when its close
925 // window menu item is selected.
926
927 // gSystem->ExitLoop();
928 // gSystem->DispatchOneEvent(kTRUE);
929
930 // TGMainFrame::CloseWindow();
931 cout << "Closing window - waiting until all nodes are stopped." << endl;
932 fQueue->PostMsg(WM_QUIT, 0, 0);
933 cout << "Closing window - done." << endl;
934 // gApplication->Terminate(0);
935}
936
937void MGCosy::StartTrack()
938{
939 cout << "Start tracking." << endl;
940
941 XY xy = fCRaDec->GetCoordinates();
942 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
943
944 cout << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
945
946 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
947
948 cout << "PostMsg (WM_Track) returned." << endl;
949}
950
951void MGCosy::StartPos()
952{
953 cout << "Start positioning." << endl;
954
955 XY xy = fCZdAz->GetCoordinates();
956 ZdAz dest(xy.X(), xy.Y());
957
958 cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
959
960 fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
961
962 cout << "PostMsg (WM_Position) returned." << endl;
963}
964
965//
966// ************************** For demo purpose **********************
967//
968#include <TRandom.h>
969class MDemo : public MThread
970{
971private:
972 MsgQueue *fQueue;
973 TRandom fRand;
974
975public:
976 MDemo() : MThread(false) {}
977
978 void SetQueue(MsgQueue *q) { fQueue = q; }
979
980 virtual void *Thread()
981 {
982 while (1)
983 {
984 Timer tm;
985 tm.Now();
986
987 Float_t h = 2.+tm.H()+(10.7+tm.M())/60.;
988 RaDec dest(h*15, 129.7);
989
990 cout << dest.Ra()/15 << "h " << dest.Dec() << "°" << endl;
991
992 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
993
994 int i = 0;
995 while (!HasStopFlag() && i++<60) // 2.5min
996 usleep(1000000);
997 if (HasStopFlag())
998 break;
999
1000 //fQueue->PostMsg(WM_STOP, 0, 0);
1001
1002 ZdAz dest1(fRand.Integer(36)+25, fRand.Integer(360));
1003
1004 cout << "Demo: Zd=" << dest1.Zd() << "° Az=" << dest1.Az() << "°" << endl;
1005
1006 fQueue->PostMsg(WM_POSITION, &dest1, sizeof(dest1));
1007
1008 i = 0;
1009 while (!HasStopFlag() && i++<15) // 30s
1010 usleep(1000000);
1011 if (HasStopFlag())
1012 break;
1013
1014 //ZdAz dest2(5, 30);
1015 //fQueue->PostMsg(WM_POSITION, &dest2, sizeof(dest2));
1016 /*
1017 i = 0;
1018 while (!HasStopFlag() && i++<30) // 30s
1019 usleep(1000000);
1020 */
1021 //if (HasStopFlag())
1022 // break;
1023 }
1024 cout << "Demo Thread: done." << endl;
1025 return NULL;
1026 }
1027};
1028
1029MDemo demo;
1030
1031void MGCosy::StartDemo()
1032{
1033 cout << "Start Demo." << endl;
1034
1035 demo.SetQueue(fQueue);
1036 demo.Start();
1037
1038 cout << "PostMsg (WM_Demo) returned." << endl;
1039}
1040
1041void StopDemo()
1042{
1043 cout << "Stopping demo." << endl;
1044 demo.Stop();
1045}
1046
1047void MGCosy::StartCalib()
1048{
1049 cout << "Start Calibration." << endl;
1050
1051 XY xy = fCCalib->GetCoordinates();
1052 RaDec pos(xy.X()*360/24, xy.Y());
1053
1054 fQueue->PostMsg(WM_CALIB, &pos, sizeof(pos));
1055
1056 cout << "PostMsg (WM_Calib) returned." << endl;
1057}
1058
1059void MGCosy::StartTPoint()
1060{
1061 cout << "Start writing tpoint pair." << endl;
1062
1063 XY xy = fCCalib->GetCoordinates();
1064 RaDec pos(xy.X()*360/24, xy.Y());
1065
1066 //fQueue->PostMsg(WM_TPOINT, &pos, sizeof(pos));
1067 fQueue->Proc(WM_TPOINT, &pos);
1068
1069 cout << "PostMsg (WM_TPoint) returned." << endl;
1070}
1071//
1072// ******************************************************************
1073//
1074
1075Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1076{
1077 //
1078 // This processing is serialized!
1079 //
1080 switch (GET_MSG(msg))
1081 {
1082 case kC_COMMAND:
1083 switch (GET_SUBMSG(msg))
1084 {
1085 case kCM_TAB:
1086 //cout << "Tab: " << mp1 << endl;
1087 return kTRUE;
1088
1089 case kCM_BUTTON:
1090
1091 switch (mp1)
1092 {
1093 /*
1094 case kPB_POSITION:
1095 Start(0);
1096 return kTRUE;
1097
1098 case kPB_TRACK:
1099 Start(1);
1100 return kTRUE;
1101 */
1102 case kPB_START:
1103 switch (fTab->GetCurrent())
1104 {
1105 case 0:
1106 StartPos();
1107 return kTRUE;
1108 case 1:
1109 StartTrack();
1110 return kTRUE;
1111 case 2:
1112 fCRaDec->SetCoordinates(fCCalib->GetCoordinates());
1113 return kTRUE;
1114 case 3:
1115 StartDemo();
1116 return kTRUE;
1117 }
1118 return kTRUE;
1119
1120 case kPB_STOP:
1121 cout << "Sending stop movement msg." << endl;
1122 StopDemo();
1123 fQueue->PostMsg(WM_STOP, 0, 0);
1124 cout << "PostMsg (WM_Stop) returned." << endl;
1125 return kTRUE;
1126
1127 case kPB_CALCALTAZ:
1128 {
1129 XY xy = fCRaDec->GetCoordinates();
1130 fQueue->Proc(WM_CALCALTAZ, &xy);
1131 }
1132 return kTRUE;
1133
1134 case kPB_RAp:
1135 case kPB_RAm:
1136 case kPB_DECp:
1137 case kPB_DECm:
1138 {
1139 XY xy = fCRaDec->GetCoordinates();
1140 switch (mp1)
1141 {
1142 case kPB_RAp:
1143 xy.X(xy.X()+1./60);
1144 break;
1145 case kPB_RAm:
1146 xy.X(xy.X()-1./60);
1147 break;
1148 case kPB_DECp:
1149 xy.Y(xy.Y()+1./60);
1150 break;
1151 case kPB_DECm:
1152 xy.Y(xy.Y()-1./60);
1153 break;
1154 }
1155 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
1156 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1157 //fQueue->Proc(WM_NEWTRACK, &dest);
1158 fCRaDec->SetCoordinates(xy);
1159
1160 cout << "New Ra/Dec: " << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
1161 }
1162 return kTRUE;
1163
1164 case kPB_TPOINT:
1165 StartTPoint();
1166 return kTRUE;
1167 case kPB_CALIBSE:
1168 StartCalib();
1169 return kTRUE;
1170 case kPB_LoadBending:
1171 fQueue->Proc(WM_LOADBENDING, NULL);
1172 return kTRUE;
1173 case kPB_ResetBending:
1174 fQueue->Proc(WM_RESETBENDING, NULL);
1175 return kTRUE;
1176 case kPB_HOME:
1177 fQueue->PostMsg(WM_HOME, 0, 0);
1178 return kTRUE;
1179
1180 default:
1181 return kTRUE;
1182 }
1183 return kTRUE;
1184
1185 case kCM_MENU:
1186
1187 switch (mp1)
1188 {
1189 case IDM_EXIT:
1190 cout << "IDM_EXIT: Posting WM_QUIT." << endl;
1191 fQueue->PostMsg(WM_QUIT, 0, 0);
1192 cout << "IDM_EXIT: WM_QUIT done." << endl;
1193 //cout << "Idm_Exit." << endl;
1194 //CloseWindow();
1195 return kTRUE;
1196 case IDM_ASPECT:
1197 Int_t w = GetWidth();
1198 Int_t h = GetHeight();
1199 if (w>940*h/660)
1200 w = 940*h/660;
1201 else
1202 h = 660*w/940;
1203 Resize(w, h);
1204 return kTRUE;
1205 }
1206 return kTRUE;
1207 }
1208 }
1209
1210 //
1211 // Start a thread to process the message.
1212 //
1213 // fQueue->PostMsg(msg, mp1, mp2);
1214 return kTRUE;
1215
1216}
Note: See TracBrowser for help on using the repository browser.