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

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