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

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