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

Last change on this file since 2588 was 2518, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 42.0 KB
Line 
1#include "MGCosy.h"
2
3#include <iomanip.h>
4#include <iostream.h>
5
6#include "msgqueue.h"
7#include "coord.h"
8#include "slalib.h"
9
10#include <TROOT.h>
11
12#include <TGTab.h> // TGTab
13#include <TGMenu.h> // TGPopupMenu
14#include <TGFrame.h> // TGGroupFrame
15#include <TSystem.h> // gSystem
16#include <TGLabel.h> // TGLabel
17#include <TG3DLine.h> // TGHorizontal3DLine (TGSplitter)
18#include <TGButton.h> // TGButton
19#include <TGTextView.h> // TGTextView
20#include <TGComboBox.h> // TGComboBox
21#include <TGTextEntry.h> // TGTextEntry
22#include <TApplication.h> // gApplication
23
24//#include "timer.h" // Timer
25
26#include "MCosy.h"
27#include "MGList.h"
28#include "MDriveCom.h"
29#include "MGAccuracy.h"
30#include "MGCoordinates.h"
31#include "MGSkyPosition.h"
32#include "MGVelocity.h"
33
34#include "SlaStars.h"
35
36#undef DEBUG
37//#define EXPERT
38//#define HAS_DEMO
39
40ClassImp(MGCosy);
41
42#define IDM_EXIT 1
43#define IDM_TEXT 2
44#define IDM_ASPECT 3
45
46
47enum
48{
49 kPB_POSITION,
50 kPB_TRACK,
51 kPB_STOP,
52 kPB_TRACKPOS,
53 kPB_CALCALTAZ,
54 kPB_TPOINT,
55 kPB_ENDSWITCH,
56 kPB_START,
57 kPB_DISPLAY1,
58 kPB_DISPLAY2,
59 kPB_RAp,
60 kPB_RAm,
61 kPB_DECp,
62 kPB_DECm,
63 kPB_ZDp,
64 kPB_ZDm,
65 kPB_AZp,
66 kPB_AZm,
67 kPB_LoadBending,
68 kPB_ResetBending,
69 kPB_CALIBSE,
70 kCB_PredefPos,
71 kCB_StarList,
72 kPB_SavePreDef,
73 kPB_SaveStar,
74
75 // kLog
76 kLogCopy, kLogClear, kLogSelect, kLogSearch, kLogSave, kLogAppend
77};
78
79void MGCosy::CreateMenu()
80{
81 TGLayoutHints *laymenubar = new TGLayoutHints (kLHintsNormal | kLHintsExpandX);
82 TGLayoutHints *laymenuitem = new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0);
83 fList->Add(laymenubar);
84 fList->Add(laymenuitem);
85
86 //
87 // crate the menu bar
88 //
89 TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
90 filemenu->AddEntry("Set Aspect", IDM_ASPECT);
91 filemenu->AddEntry("Exit", IDM_EXIT);
92 filemenu->Associate(this);
93 fList->Add(filemenu);
94
95 //
96 // Log Menu
97 //
98 TGPopupMenu *logmenu = new TGPopupMenu(gClient->GetRoot());
99 logmenu->AddEntry("&Copy Selected", kLogCopy);
100 logmenu->AddEntry("&Select All", kLogSelect);
101 logmenu->AddSeparator();
102 logmenu->AddEntry("Clear &all", kLogClear);
103 /*
104 logmenu->AddSeparator();
105 logmenu->AddEntry("Search", kLogSearch);
106 */
107 logmenu->AddSeparator();
108 logmenu->AddEntry("Sa&ve", kLogSave);
109 logmenu->AddEntry("Save a&ppend", kLogAppend);
110 logmenu->Associate(this);
111
112 //
113 // the button messages are handled by main frame (this)
114 //
115 TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
116 menubar->AddPopup("File", filemenu, laymenuitem);
117 menubar->AddPopup("Lo&g", logmenu, laymenuitem);
118 AddFrame(menubar, laymenubar);
119 fList->Add(menubar);
120
121 //
122 // Seperator beyond menubar
123 //
124 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
125 AddFrame(linesep, laymenubar);
126 fList->Add(linesep);
127}
128
129void MGCosy::CreateLabel(TGCompositeFrame *f)
130{
131 const int x = 180;
132 const int y = 25;
133
134 TGLabel *l;
135
136 l = new TGLabel(f, "UTC:");
137 l->Move(x-60, y);
138 fList->Add(l);
139
140 l = new TGLabel(f, "Mjd:");
141 l->Move(x-60, y+17);
142 fList->Add(l);
143
144 fUtc = new TGLabel(f, "0000/00/00 00:00:00.0");
145 fMjd = new TGLabel(f, "00000.000000");
146 fUtc->Move(x-25, y);
147 fMjd->Move(x-25, y+17);
148 fList->Add(fUtc);
149 fList->Add(fMjd);
150
151 l = new TGLabel(f, "SE-Az:");
152 l->Move(x-60, y+40);
153 fList->Add(l);
154
155 l = new TGLabel(f, "SE-Zd1:");
156 l->Move(x-60, y+57);
157 fList->Add(l);
158
159 l = new TGLabel(f, "SE-Zd2:");
160 l->Move(x-60, y+74);
161 fList->Add(l);
162
163 fLabel1 = new TGLabel(f, "00000"); // Max: 16384
164 fLabel2 = new TGLabel(f, "00000");
165 fLabel3 = new TGLabel(f, "00000");
166 fLabel1->SetTextJustify(kTextRight);
167 fLabel2->SetTextJustify(kTextRight);
168 fLabel3->SetTextJustify(kTextRight);
169 fLabel1->Move(x, y+40);
170 fLabel2->Move(x, y+57);
171 fLabel3->Move(x, y+74);
172 fList->Add(fLabel1);
173 fList->Add(fLabel2);
174 fList->Add(fLabel3);
175/*
176 l = new TGLabel(f, "Offset-Zd:");
177 l->Move(x-60, y+102);
178 fList->Add(l);
179
180 l = new TGLabel(f, "Offset-Az:");
181 l->Move(x-60, y+119);
182 fList->Add(l);
183
184 fOffsetZd = new TGLabel(f, "000000000");
185 fOffsetAz = new TGLabel(f, "000000000");
186 fOffsetZd->SetTextJustify(kTextRight);
187 fOffsetAz->SetTextJustify(kTextRight);
188 fOffsetZd->Move(x+15, y+102);
189 fOffsetAz->Move(x+15, y+119);
190 fList->Add(fOffsetZd);
191 fList->Add(fOffsetAz);
192*/
193 l = new TGLabel(f, "Ra (estimated):");
194 l->Move(x-60, y+142-20);
195 fList->Add(l);
196
197 l = new TGLabel(f, "Ra (nominal):");
198 l->Move(x-60, y+159-20);
199 fList->Add(l);
200
201 l = new TGLabel(f, "Dec (estimated):");
202 l->Move(x-60, y+182-20);
203 fList->Add(l);
204
205 l = new TGLabel(f, "Dec (nominal):");
206 l->Move(x-60, y+199-20);
207 fList->Add(l);
208
209 l = new TGLabel(f, "Zd (nominal):");
210 l->Move(x-60, y+222);
211 fList->Add(l);
212
213 l = new TGLabel(f, "Az (nominal):");
214 l->Move(x-60, y+239);
215 fList->Add(l);
216
217 fRaEst = new TGLabel(f, "+000h 00.0m");
218 fDecEst = new TGLabel(f, "+000d 00.0m");
219 fRaSoll = new TGLabel(f, "+000h 00.0m");
220 fDecSoll = new TGLabel(f, "+000d 00.0m");
221 fZdSoll = new TGLabel(f, "+000d 00.0m");
222 fAzSoll = new TGLabel(f, "+000d 00.0m");
223 fRaEst->SetTextJustify(kTextRight);
224 fDecEst->SetTextJustify(kTextRight);
225 fRaSoll->SetTextJustify(kTextRight);
226 fDecSoll->SetTextJustify(kTextRight);
227 fZdSoll->SetTextJustify(kTextRight);
228 fAzSoll->SetTextJustify(kTextRight);
229 fRaEst->Move(x+30, y+142-20);
230 fRaSoll->Move(x+30, y+159-20);
231 fDecEst->Move(x+30, y+182-20);
232 fDecSoll->Move(x+30, y+199-20);
233 fZdSoll->Move(x+30, y+222);
234 fAzSoll->Move(x+30, y+239);
235 fList->Add(fRaEst);
236 fList->Add(fDecEst);
237 fList->Add(fRaSoll);
238 fList->Add(fDecSoll);
239 fList->Add(fZdSoll);
240 fList->Add(fAzSoll);
241
242 fError = new TGLabel(f, "Error");
243 fMoving = new TGLabel(f, "Moving");
244 fTracking = new TGLabel(f, "Tracking");
245 fStopping = new TGLabel(f, "Stopping");
246 fStopped = new TGLabel(f, "Stopped");
247 fAvailMac1 = new TGLabel(f, "- MAC1 -");
248 fAvailMac2 = new TGLabel(f, "- MAC2 -");
249 //fAvailMac3 = new TGLabel(f, "- MAC3 -");
250 fAvailSe1 = new TGLabel(f, "-SE/Zd1-");
251 fAvailSe2 = new TGLabel(f, "-SE/Zd2-");
252 fAvailSe3 = new TGLabel(f, "- SE/Az -");
253
254 ULong_t color;
255
256 gClient->GetColorByName("Red", color);
257 fError->SetBackgroundColor(color);
258 fAvailMac1->SetBackgroundColor(color);
259 fAvailMac2->SetBackgroundColor(color);
260 //fAvailMac3->SetBackgroundColor(color);
261 fAvailSe1->SetBackgroundColor(color);
262 fAvailSe2->SetBackgroundColor(color);
263 fAvailSe3->SetBackgroundColor(color);
264 gClient->GetColorByName("LightBlue", color);
265 fMoving->SetBackgroundColor(color);
266 gClient->GetColorByName("Blue", color);
267 fTracking->SetBackgroundColor(color);
268 gClient->GetColorByName("Orange", color);
269 fStopping->SetBackgroundColor(color);
270 gClient->GetColorByName("Green", color);
271 fStopped->SetBackgroundColor(color);
272
273 fError ->MoveResize(10, 25, 60, 20);
274 fMoving ->MoveResize(10, 25+20, 60, 20);
275 fTracking->MoveResize(10, 25+40, 60, 20);
276 fStopping->MoveResize(10, 25+60, 60, 20);
277 fStopped ->MoveResize(10, 25+80, 60, 20);
278 fAvailMac1->MoveResize(10, 25+120, 60, 20);
279 fAvailMac2->MoveResize(10, 25+140, 60, 20);
280 //fAvailMac3->Move(10, 25+160);
281 fAvailSe1->MoveResize(10, 25+200, 60, 20);
282 fAvailSe2->MoveResize(10, 25+220, 60, 20);
283 fAvailSe3->MoveResize(10, 25+180, 60, 20);
284
285 fList->Add(fError);
286 fList->Add(fMoving);
287 fList->Add(fTracking);
288 fList->Add(fStopping);
289 fList->Add(fStopped);
290 fList->Add(fAvailMac1);
291 fList->Add(fAvailMac2);
292 //fList->Add(fAvailMac3);
293 fList->Add(fAvailSe1);
294 fList->Add(fAvailSe2);
295 fList->Add(fAvailSe3);
296}
297
298void MGCosy::CreatePredefinedPos(TGCompositeFrame *tf1)
299{
300 TGComboBox *box = new TGComboBox(tf1, kCB_PredefPos);
301 box->Resize(120, 20);
302 box->Associate(this);
303
304 TGLayoutHints *lay = new TGLayoutHints(kLHintsLeft|kLHintsTop,
305 27, 0, 200, 0);
306 tf1->AddFrame(box, lay);
307
308 fList->Add(box);
309 fList->Add(lay);
310
311 ifstream fin("prepos.txt");
312 if (!fin)
313 {
314 cout << "ERROR: Predifined positions in 'prepos.txt' not found." << endl;
315 return;
316 }
317
318 int i=0;
319 while (1)
320 {
321 Double_t zd, az;
322 fin >> zd >> az;
323
324 TString str;
325 str.ReadLine(fin);
326 if (!fin)
327 break;
328
329 box->AddEntry(str, i++);
330 fPreDefList.Add(zd, az);
331 }
332}
333
334void MGCosy::CreateStarList(TGCompositeFrame *tf1)
335{
336 TGComboBox *box = new TGComboBox(tf1, kCB_StarList);
337 box->Resize(170, 20);
338 box->Associate(this);
339
340 TGLayoutHints *lay = new TGLayoutHints(kLHintsLeft|kLHintsTop,
341 27, 0, 70, 0);
342 tf1->AddFrame(box, lay);
343
344 fList->Add(box);
345 fList->Add(lay);
346
347 ifstream fin("stars.txt");
348 if (!fin)
349 {
350 cout << "ERROR: Star List 'stars.txt' not found." << endl;
351 return;
352 }
353
354 int i=0;
355 while (1)
356 {
357 Int_t h, m, s, d, am, as;
358 fin >> h >> m >> s >> d >> am >> as;
359
360 TString str;
361 str.ReadLine(fin);
362 if (!fin)
363 break;
364
365 box->AddEntry(str, i++);
366
367 fStarList.Add(Slalib::Hms2Hor(h, m, s), Slalib::Dms2Deg(d, am, as));
368 }
369}
370
371void MGCosy::CreateTabs()
372{
373 TGCompositeFrame *tf1 = fTab->AddTab("Position");
374 TGCompositeFrame *tf2 = fTab->AddTab("Track");
375 TGCompositeFrame *tf4 = fTab->AddTab("Calib");
376#ifdef EXPERT
377 TGCompositeFrame *tf5 = fTab->AddTab("Test SE");
378 TGCompositeFrame *tf6 = fTab->AddTab("Gear");
379#endif
380#ifdef HAS_DEMO
381 /*TGCompositeFrame *tf3 =*/ fTab->AddTab("Demo");
382#endif
383
384 fCZdAz = new MGCoordinates(tf1, kETypeZdAz);
385 fCZdAz->Move(27, 105);
386 fList->Add(fCZdAz);
387
388 CreatePredefinedPos(tf1);
389 CreateStarList(tf4);
390
391 fCRaDec = new MGCoordinates(tf2, kETypeRaDec);
392 fCRaDec->Move(27, 105);
393 fList->Add(fCRaDec);
394
395 fCCalib = new MGCoordinates(tf4, kETypeRaDec);
396 fCCalib->Move(27, 105);
397 fList->Add(fCCalib);
398
399 const int x=15;
400 const int y=12;
401 const int h=16;
402
403 TGLabel *l1 = new TGLabel(tf1, "Move the telescope to a position given in");
404 TGLabel *l2 = new TGLabel(tf1, "local coordinates. The given coordinates");
405 TGLabel *l3 = new TGLabel(tf1, "are pointing coordinates. Enter the coordinates");
406 TGLabel *l4 = new TGLabel(tf1, "manually or choose a predefined position");
407 TGLabel *l5 = new TGLabel(tf1, "from the combobox below.");
408 l1->Move(x, y);
409 l2->Move(x, y+h);
410 l3->Move(x, y+2*h);
411 l4->Move(x, y+3*h);
412 l5->Move(x, y+4*h);
413 fList->Add(l1);
414 fList->Add(l2);
415 fList->Add(l3);
416 fList->Add(l4);
417 fList->Add(l5);
418
419 l1 = new TGLabel(tf2, "Track a position given in sky coordinates.");
420 l2 = new TGLabel(tf2, "Right Ascension and declination must be given");
421 l3 = new TGLabel(tf2, "in the FK5, J2000 coordinate system.");
422 l1->Move(x, y);
423 l2->Move(x, y+h);
424 l3->Move(x, y+2*h);
425 fList->Add(l1);
426 fList->Add(l2);
427 fList->Add(l3);
428
429 l1 = new TGLabel(tf4, "Start the calibration using the Start button.");
430 l2 = new TGLabel(tf4, "Write a coordinate pair to a TPoint file using");
431 l3 = new TGLabel(tf4, "the TPoint button.");
432 //l3 = new TGLabel(tf4, "the TPoint button. To set the Shaftencoder offset");
433 //l4 = new TGLabel(tf4, "use the Calib SE button.");
434 l1->Move(x, y);
435 l2->Move(x, y+h);
436 l3->Move(x, y+2*h);
437 l4->Move(x, y+3*h);
438 fList->Add(l1);
439 fList->Add(l2);
440 fList->Add(l3);
441 fList->Add(l4);
442
443#ifdef EXPERT
444 l1 = new TGLabel(tf5, "START starts histograming the differences of");
445 l2 = new TGLabel(tf5, "the two shaftencoders at the elevation axis.");
446 l3 = new TGLabel(tf5, "Use STOP to stop histograming and display the");
447 l4 = new TGLabel(tf5, "results on the screen.");
448 l1->Move(x, y);
449 l2->Move(x, y+h);
450 l3->Move(x, y+2*h);
451 l4->Move(x, y+3*h);
452 fList->Add(l1);
453 fList->Add(l2);
454 fList->Add(l3);
455 fList->Add(l4);
456
457 l1 = new TGLabel(tf6, "FIXME Text missing / Only one axis?");
458 l1->Move(x, y);
459 fList->Add(l1);
460#endif
461
462 //
463 // light green: 3 light red: 2 blue?: 2
464 // dark green: 8 dark red: 50 dark blue?: 1
465
466 //
467 // blue: 0-7, 9, 10,11, 14, 15, 18, 19, 22, 23, 27, 31, 33-39, 41-43
468 // 46, 47
469 // green: 8, 12,13, 16, 17, 20, 21, 24, 25, 26, 28, 29, 30, 40, 44
470 // 45, 48
471 // gray: 31, 113-
472 // red: 164, 192, 224, 232
473 //
474 TGTextButton *but;
475
476 but= new TGTextButton(tf2, "Ra -", kPB_RAm);
477 but->MoveResize(25, 210, 50, 25);
478 but->SetToolTipText("Right ascension -= 1'");
479 but->Associate(this);
480 fList->Add(but);
481 but= new TGTextButton(tf2, "RA +", kPB_RAp);
482 but->MoveResize(90, 210, 50, 25);
483 but->SetToolTipText("Right ascension += 1'");
484 but->Associate(this);
485 fList->Add(but);
486 but= new TGTextButton(tf2, "DEC +", kPB_DECp);
487 but->MoveResize(55, 185, 50, 25);
488 but->SetToolTipText("Declination += 1'");
489 but->Associate(this);
490 fList->Add(but);
491 but= new TGTextButton(tf2, "DEC -", kPB_DECm);
492 but->MoveResize(55, 235, 50, 25);
493 but->SetToolTipText("Declination -= 1'");
494 but->Associate(this);
495 fList->Add(but);
496
497 but = new TGTextButton(tf1, "Move'n'Track", kPB_TRACKPOS);
498 but->MoveResize(25, 242, 100, 25);
499 but->SetToolTipText("Move telescope to a Zd/Az position and start tracking.");
500 but->Associate(this);
501 fList->Add(but);
502
503 but= new TGTextButton(tf2, "Calc Zd/Az", kPB_CALCALTAZ);
504 but->MoveResize(165, 197, 80, 25);
505 but->SetToolTipText("Calculate Zd/Az corresponding to Ra/Dec.");
506 but->Associate(this);
507 fList->Add(but);
508
509 but = new TGTextButton(tf4, "TPoint", kPB_TPOINT);
510 but->MoveResize(139, 213, 62, 25);
511 but->SetToolTipText("Trigger writing a tpoint coordinate pair.");
512 but->Associate(this);
513 fList->Add(but);
514
515 but = new TGTextButton(tf4, "Endswitch", kPB_ENDSWITCH);
516 but->MoveResize(204, 213, 62, 25);
517 but->SetToolTipText("Print coordinates in 'Endswitch-Position' units.");
518 but->Associate(this);
519 fList->Add(but);
520
521#ifdef EXPERT
522 but= new TGTextButton(tf1, "New Position", kPB_SavePreDef);
523 but->MoveResize(165, 197, 80, 25);
524 but->SetToolTipText("Save new predefined position.");
525 but->Associate(this);
526 fList->Add(but);
527
528 but= new TGTextButton(tf4, "New", kPB_SaveStar);
529 but->MoveResize(211, 69, 60, 23);
530 but->SetToolTipText("Save new Source position.");
531 but->Associate(this);
532 fList->Add(but);
533
534 but = new TGTextButton(tf5, "Display", kPB_DISPLAY1);
535 but->MoveResize(160, 197, 80, 25);
536 but->SetToolTipText("Display Histogram.");
537 but->Associate(this);
538 fList->Add(but);
539
540 but = new TGTextButton(tf6, "Display", kPB_DISPLAY2);
541 but->MoveResize(160, 197, 80, 25);
542 but->SetToolTipText("Display Histogram.");
543 but->Associate(this);
544 fList->Add(but);
545
546 but = new TGTextButton(tf4, "Load", kPB_LoadBending);
547 but->ResizeMove(151, 185, 50, 25);
548 but->SetToolTipText("Load bending corrections from file 'bending.txt'");
549 but->Associate(this);
550 fList->Add(but);
551
552 but = new TGTextButton(tf4, "Reset", kPB_ResetBending);
553 but->MoveResize(206, 185, 50, 25);
554 but->SetToolTipText("Reset bending correction (coefficients=0)");
555 but->Associate(this);
556 fList->Add(but);
557
558 but= new TGTextButton(tf4, "Zd -", kPB_ZDm);
559 but->MoveResize(25, 210, 50, 25);
560 but->SetToolTipText("Zenith Distance -= 1SE");
561 but->Associate(this);
562 fList->Add(but);
563 but= new TGTextButton(tf4, "Zd +", kPB_ZDp);
564 but->MoveResize(90, 210, 50, 25);
565 but->SetToolTipText("Zenith Distance += 1SE");
566 but->Associate(this);
567 fList->Add(but);
568 but= new TGTextButton(tf4, "Az +", kPB_AZp);
569 but->MoveResize(55, 185, 50, 25);
570 but->SetToolTipText("Azimuth += 1SE");
571 but->Associate(this);
572 fList->Add(but);
573 but= new TGTextButton(tf4, "Az -", kPB_AZm);
574 but->MoveResize(55, 235, 50, 25);
575 but->SetToolTipText("Azimuth -= 1SE");
576 but->Associate(this);
577 fList->Add(but);
578#endif
579
580 ULong_t color;
581
582 but = new TGTextButton(this, "Start", kPB_START);
583 gClient->GetColorByName("Green", color);
584 but->SetBackgroundColor(color);
585 but->MoveResize(147, 295, 62, 25);
586 but->SetToolTipText("Start a telescope movement.");
587 fList->Add(but);
588
589 but = new TGTextButton(this, "Stop", kPB_STOP);
590
591 gClient->GetColorByName("Red", color);
592 but->SetBackgroundColor(color);
593 but->MoveResize(212, 295, 62, 25);
594 but->SetToolTipText("Stop any movement of telescope.");
595 fList->Add(but);
596
597 /*
598 const Double_t ca = 0; // Left-Right Collimation Error
599 const Double_t an = 0; // Azimuth Axis Misalignment (N-S)
600 const Double_t aw = 0; // Azimuth Axis Misalignment (E-W)
601 const Double_t npae = 0; // Az-El Nonperpendicularity
602 const Double_t nrx = 0; // Nasmyth rotator displacement, horizontan
603 const Double_t nry = 0; // Nasmyth rotator displacement, vertical
604 const Double_t crx = 0; // Alt/Az Coude Displacement (N-S)
605 const Double_t cry = 0; // Alt/Az Coude Displacement (E-W)
606 l1 = new TGLabel(tf5, "CA");
607 l1->SetTextJustify(kTextLeft);
608 l1->Move(x, y+2*h*1.5);
609 l1->MapWindow();
610 fList->Add(l1);
611 l1 = new TGLabel(tf5, "AN");
612 l1->SetTextJustify(kTextLeft);
613 l1->Move(x, y+3*h*1.5);
614 l1->MapWindow();
615 fList->Add(l1);
616 l1 = new TGLabel(tf5, "AW");
617 l1->SetTextJustify(kTextLeft);
618 l1->Move(x, y+4*h*1.5);
619 l1->MapWindow();
620 fList->Add(l1);
621 l1 = new TGLabel(tf5, "NPAE");
622 l1->SetTextJustify(kTextLeft);
623 l1->Move(x, y+5*h*1.5);
624 l1->MapWindow();
625 fList->Add(l1);
626 l1 = new TGLabel(tf5, "NRX");
627 l1->SetTextJustify(kTextLeft);
628 l1->Move(x, y+6*h*1.5);
629 l1->MapWindow();
630 fList->Add(l1);
631 l1 = new TGLabel(tf5, "NRY");
632 l1->SetTextJustify(kTextLeft);
633 l1->Move(x, y+7*h*1.5);
634 l1->MapWindow();
635 fList->Add(l1);
636 l1 = new TGLabel(tf5, "CRX");
637 l1->SetTextJustify(kTextLeft);
638 l1->Move(x, y+8*h*1.5);
639 l1->MapWindow();
640 fList->Add(l1);
641 l1 = new TGLabel(tf5, "CRY");
642 l1->SetTextJustify(kTextLeft);
643 l1->Move(x, y+9*h*1.5);
644 l1->MapWindow();
645 fList->Add(l1);
646 const Double_t ie = 0; // Index Error in Elevation
647 const Double_t ia = 0; // Index Error in Azimuth
648 const Double_t eces = 0; // Elevation Centering Error (sin)
649 const Double_t ecec = 0; // Elevation Centering Error (cos)
650 const Double_t aces = 0; // Azimuth Centering Error (sin)
651 const Double_t acec = 0; // Azimuth Centering Error (cos)
652 l1 = new TGLabel(tf5, "IE");
653 l1->SetTextJustify(kTextLeft);
654 l1->Move(x+150, y+3*h*1.5);
655 l1->MapWindow();
656 fList->Add(l1);
657 l1 = new TGLabel(tf5, "IA");
658 l1->SetTextJustify(kTextLeft);
659 l1->Move(x+150, y+4*h*1.5);
660 l1->MapWindow();
661 fList->Add(l1);
662 l1 = new TGLabel(tf5, "ECES");
663 l1->SetTextJustify(kTextLeft);
664 l1->Move(x+150, y+5*h*1.5);
665 l1->MapWindow();
666 fList->Add(l1);
667 l1 = new TGLabel(tf5, "ECEC");
668 l1->SetTextJustify(kTextLeft);
669 l1->Move(x+150, y+6*h*1.5);
670 l1->MapWindow();
671 fList->Add(l1);
672 l1 = new TGLabel(tf5, "ACES");
673 l1->SetTextJustify(kTextLeft);
674 l1->Move(x+150, y+4*h*1.5);
675 l1->MapWindow();
676 fList->Add(l1);
677 l1 = new TGLabel(tf5, "IA");
678 l1->SetTextJustify(kTextLeft);
679 l1->Move(x+150, y+4*h*1.5);
680 l1->MapWindow();
681 fList->Add(l1);
682
683
684 TGTextEntry *entry = new TGTextEntry(tf5, "****", kEF_BendIE);
685 entry->Associate(this);
686 entry->Move(x+50, y+2*h*1.5);
687 entry->MapWindow();
688 fList->Add(entry);
689
690 entry = new TGTextEntry(tf5, "*****", kEF_BendIA);
691 entry->Associate(this);
692 entry->Move(x+50, y+3*h*1.5);
693 entry->MapWindow();
694 fList->Add(entry);
695 */
696}
697
698MGCosy::MGCosy(MObservatory::LocationName_t key, MsgQueue *q, const TGWindow *p, UInt_t w, UInt_t h)
699 : TGMainFrame(p, w, h), fObservatory(key), fQueue(q)
700{
701 fList = new MGList;
702
703 fFont = gVirtualX->LoadQueryFont("7x13bold");
704
705#ifdef DEBUG
706 cout << "MGCosy: Creating Menu" << endl;
707#endif
708 CreateMenu();
709
710#ifdef DEBUG
711 cout << "MGCosy: Creating TGCompositeFrame" << endl;
712#endif
713 TGHorizontalFrame *f1 = new TGHorizontalFrame(this, 0, 0);
714 TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 0, 0);
715 fList->Add(f1);
716 fList->Add(f2);
717
718#ifdef DEBUG
719 cout << "MGCosy: Creating TGTab" << endl;
720#endif
721 fTab = new TGTab(f1, 300, 300);
722 fList->Add(fTab);
723
724#ifdef DEBUG
725 cout << "MGCosy: Creating MGSkyPosition" << endl;
726#endif
727 fSkyPosition = new MGSkyPosition(fObservatory, f1, 300);
728#ifdef DEBUG
729 cout << "MGCosy: Creating MGAccuracy" << endl;
730#endif
731 fAccuracy = new MGAccuracy(f1, 300);
732#ifdef DEBUG
733 cout << "MGCosy: Creating MGVelocity" << endl;
734#endif
735 fVelocity = new MGVelocity(f2, "Velocity [\"/min]", 300);
736// fOffset = new MGVelocity (f, "Offset se-re [']", 300);
737
738 fList->Add(fSkyPosition);
739 fList->Add(fAccuracy);
740 fList->Add(fVelocity);
741// fList->Add(fOffset);
742
743#ifdef DEBUG
744 cout << "MGCosy: Creating TGGroupFrame" << endl;
745#endif
746 TGGroupFrame *frame = new TGGroupFrame(f2, "Status");
747 fList->Add(frame);
748
749#ifdef DEBUG
750 cout << "MGCosy: Creating TGTextView" << endl;
751#endif
752 fLog = new TGTextView(f2, 300, 300);
753 if (fFont)
754 fLog->SetFont(fFont);
755 fList->Add(fLog);
756
757 TGLayoutHints *hints1 = new TGLayoutHints(kLHintsNormal | kLHintsExpandX|kLHintsExpandY, 6, 6, 6, 3);
758 TGLayoutHints *hints2 = new TGLayoutHints(kLHintsNormal | kLHintsExpandX|kLHintsExpandY, 6, 6, 3, 6);
759 TGLayoutHints *hints1a = new TGLayoutHints(kLHintsLeft | kLHintsTop |kLHintsExpandX|kLHintsExpandY);
760 TGLayoutHints *hints2a = new TGLayoutHints(kLHintsCenterY | kLHintsTop |kLHintsExpandX|kLHintsExpandY, 6, 6);
761 TGLayoutHints *hints3a = new TGLayoutHints(kLHintsRight | kLHintsTop |kLHintsExpandX|kLHintsExpandY);
762 TGLayoutHints *hints1b = new TGLayoutHints(kLHintsLeft | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
763 TGLayoutHints *hints2b = new TGLayoutHints(kLHintsCenterY | kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 6, 6);
764 TGLayoutHints *hints3b = new TGLayoutHints(kLHintsRight | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
765
766 fList->Add(hints1);
767 fList->Add(hints2);
768 fList->Add(hints1a);
769 fList->Add(hints2a);
770 fList->Add(hints3a);
771 fList->Add(hints1b);
772 fList->Add(hints2b);
773 fList->Add(hints3b);
774
775 // Layout upper frame
776 f1->AddFrame(fTab, hints1a);
777 f1->AddFrame(fSkyPosition, hints2a);
778 f1->AddFrame(fAccuracy, hints3a);
779
780 // Layout upper frame
781 f2->AddFrame(frame, hints1b);
782 f2->AddFrame(fVelocity, hints2b);
783 f2->AddFrame(fLog, hints3b);
784
785 // Layout window
786 AddFrame(f1, hints1);
787 AddFrame(f2, hints2);
788
789#ifdef DEBUG
790 cout << "MGCosy: Creating Tabs" << endl;
791#endif
792 CreateTabs();
793#ifdef DEBUG
794 cout << "MGCosy: Creating Label" << endl;
795#endif
796 CreateLabel(frame);
797
798 //
799 // Map the window, set up the layout, etc.
800 //
801#ifdef DEBUG
802 cout << "MGCosy: Setting Size" << endl;
803#endif
804 const Int_t w = 940;
805 const Int_t h = 660;
806 SetWMSizeHints(w, h, 1280, 900, 10, 10); // set the smallest and biggest size of the Main frame
807
808 SetWindowName("Cosy Main Window");
809 SetIconName("Cosy");
810
811#ifdef DEBUG
812 cout << "MGCosy: Map Window" << endl;
813#endif
814 MapSubwindows();
815 Resize(w, h); //GetDefaultSize());
816 MapWindow();
817}
818
819// ======================================================================
820
821MGCosy::~MGCosy()
822{
823#ifdef DEBUG
824 cout << "MGCosy::~MGCosy called." << endl;
825#endif
826 delete fList;
827#ifdef DEBUG
828 cout << "Deleting MGCosy::fFont" << endl;
829#endif
830 if (fFont)
831 gVirtualX->DeleteFont(fFont);
832#ifdef DEBUG
833 cout << "MGCosy::~MGCosy done." << endl;
834#endif
835}
836
837void MGCosy::SetLabelColor(TGLabel *label, Bool_t col)
838{
839 ULong_t red, green;
840
841 gClient->GetColorByName("Red", red);
842 gClient->GetColorByName("Green", green);
843
844 if (col && label->TestBit(BIT(14)))
845 return;
846
847 if (!col && !label->TestBit(BIT(14)))
848 return;
849
850 col ? label->SetBit(BIT(14)) : label->ResetBit(BIT(14));
851
852 label->UnmapWindow();
853 label->SetBackgroundColor(col ? green : red);
854 label->MapWindow();
855}
856
857// ======================================================================
858void MGCosy::EnableLabel(TGLabel *label, Bool_t stat)
859{
860 stat ? label->MapWindow() : label->UnmapWindow();
861
862 /*
863 TGGC *fRedTextGC(TGButton::GetDefaultGC())
864 // Set foreground color in graphics context for drawing of
865 // TGlabel and TGButtons with text in red.
866 ULong_t red;
867 gClient->GetColorByName("red", red);
868 fRedTextGC.SetForeground(red);
869 */
870}
871
872void MGCosy::UpdateRaDec(ZdAz &pos, double mjd, RaDec &radec)
873{
874 static Int_t rai=~0;
875 static Int_t deci=~0;
876 static Int_t ras=~0;
877 static Int_t decs=~0;
878
879 static SlaStars sla(fObservatory);
880 sla.SetMjd(mjd);
881
882 RaDec rd = sla.CalcRaDec(pos*2*TMath::Pi()/360);
883
884 char text[64];
885
886 UShort_t h, d;
887 Double_t hm, dm;
888 Char_t sh, sd;
889
890 // Calculate Display values
891 Slalib::Rad2Hm(rd.Ra(), sh, h, hm);
892 Slalib::Rad2Dm(rd.Dec(), sd, d, dm);
893
894 rd.Ra(rd.Ra() * 12/TMath::Pi());
895 rd.Dec(rd.Dec()*180/TMath::Pi());
896
897 RaDec test = rd*600;
898 if (rai!=(int)test.Ra())
899 {
900 rai = (int)test.Ra();
901 //sprintf(text, "%c%dh %.1fm", rd.Ra()<0?'-':'+', abs((int)rd.Ra()), 0.1*(abs((int)test.Ra())%600));
902 sprintf(text, "%c%dh %.1fm", sh, h, hm);
903 fRaEst->SetText(new TGString(text));
904 }
905 if (deci!=(int)test.Dec())
906 {
907 deci = (int)test.Dec();
908 //sprintf(text, "%c%dd %.1fm", rd.Dec()<0?'-':'+' , abs((int)rd.Dec()), 0.1*(abs((int)test.Dec())%600));
909 sprintf(text, "%c%dd %.1fm", sd, d, dm);
910 fDecEst->SetText(new TGString(text));
911 }
912
913 // Align RaDec
914 radec.Ra(radec.Ra() * 12/TMath::Pi());
915 radec.Dec(radec.Dec()*180/TMath::Pi());
916 if (radec.Dec()>90|| radec.Dec()<-90)
917 {
918 radec.Ra(radec.Ra()+12);
919 radec.Dec(180-radec.Dec());
920 }
921 radec.Ra(fmod((radec.Ra()+48), 24));
922
923 // Calculate display values
924 Slalib::Hor2Hm(radec.Ra(), sh, h, hm);
925 Slalib::Deg2Dm(radec.Dec(), sd, d, dm);
926
927 test = radec*600;
928 if (ras!=(int)test.Ra())
929 {
930 ras = (int)test.Ra();
931 //sprintf(text, "%c%dh %.1fm", radec.Ra()<0?'-':'+', abs((int)radec.Ra()), 0.1*(abs((int)test.Ra())%600));
932 sprintf(text, "%c%dh %.1fm", sh, h, hm);
933 fRaSoll->SetText(new TGString(text));
934 }
935 if (decs!=(int)test.Dec())
936 {
937 decs = (int)test.Dec();
938 //sprintf(text, "%c%dd %.1fm", radec.Dec()<0?'-':'+' , abs((int)radec.Dec()), 0.1*(abs((int)test.Dec())%600));
939 sprintf(text, "%c%dd %.1fm", sd, d, dm);
940 fDecSoll->SetText(new TGString(text));
941 }
942}
943/*
944void MGCosy::UpdateOffset(ZdAz &off)
945{
946 static Int_t zd=~0;
947 static Int_t az=~0;
948
949 char text[21];
950
951 if (zd!=(Int_t)off.Zd())
952 {
953 zd = (Int_t)off.Zd();
954 sprintf(text, "%dre", zd);
955 fOffsetZd->SetText(new TGString(text));
956 }
957 if (az!=(Int_t)off.Az())
958 {
959 az = (Int_t)off.Az();
960 sprintf(text, "%dre", az);
961 fOffsetAz->SetText(new TGString(text));
962 }
963}
964*/
965void MGCosy::UpdateZdAz(ZdAz &soll)
966{
967 static Int_t zd=~0;
968 static Int_t az=~0;
969
970 char text[21];
971
972 UShort_t z, a;
973 Double_t zm, am;
974 Char_t sz, sa;
975
976 Slalib::Rad2Dm(soll.Zd(), sz, z, zm);
977 Slalib::Rad2Dm(soll.Az(), sa, a, am);
978
979 const ZdAz test = soll*kRad2Deg*600;
980 if (zd!=(int)test.Zd())
981 {
982 zd = (int)test.Zd();
983 sprintf(text, "%c%dd %.1fm", sz, z, zm);
984 fZdSoll->SetText(new TGString(text));
985 }
986 if (az!=(int)test.Az())
987 {
988 az = (int)test.Az();
989 sprintf(text, "%c%dd %.1fm", sa, a, am);
990 fAzSoll->SetText(new TGString(text));
991 }
992}
993
994double MGCosy::UpdateTime()
995{
996 Timer time;
997 time.Now();
998
999 static char oldtxt[256];
1000
1001 char text[256];
1002
1003 strcpy(text, time.GetTimeStr());
1004
1005 char *dot = strrchr(text, '.');
1006
1007 if (dot)
1008 dot[2] = 0;
1009
1010 if (strcmp(oldtxt, text))
1011 {
1012 fUtc->SetText(new TGString(text));
1013 strcpy(oldtxt, text);
1014 }
1015
1016 static long oldmjd;
1017 double mjd = time.GetMjd();
1018
1019 if (oldmjd != 1000000*mjd)
1020 {
1021 sprintf(text, "%12.6f", mjd);
1022 fMjd->SetText(new TGString(text));
1023
1024 oldmjd = (long)(1000000*mjd);
1025 }
1026
1027 return mjd;
1028}
1029
1030void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec,
1031 ZdAz soll, UInt_t stat, UInt_t stat2)
1032{
1033 // acc [rad]
1034 acc *= kRad2Deg; // [deg]
1035
1036 double mjd = UpdateTime();
1037 fSkyPosition->Update(pos, mjd);
1038 //UpdateOffset(off);
1039 UpdateRaDec(pos, mjd, radec);
1040 UpdateZdAz(soll);
1041
1042 EnableLabel(fError, stat&MDriveCom::kError);
1043 EnableLabel(fMoving, stat&MDriveCom::kMoving);
1044 EnableLabel(fTracking, stat&MDriveCom::kTracking);
1045 EnableLabel(fStopping, stat&MDriveCom::kStopping);
1046 EnableLabel(fStopped, stat&MDriveCom::kStopped);
1047 EnableLabel(fRaSoll, stat&MDriveCom::kTracking);
1048 EnableLabel(fDecSoll, stat&MDriveCom::kTracking);
1049 EnableLabel(fZdSoll, stat&MDriveCom::kMoving);
1050 EnableLabel(fAzSoll, stat&MDriveCom::kMoving);
1051
1052 SetLabelColor(fAvailMac1, stat2&0x01);
1053 SetLabelColor(fAvailMac2, stat2&0x02);
1054 //SetLabelColor(fAvailMac3, stat2&0x04);
1055 SetLabelColor(fAvailSe1, stat2&0x08);
1056 SetLabelColor(fAvailSe2, stat2&0x10);
1057 SetLabelColor(fAvailSe3, stat2&0x20);
1058
1059 if (stat&MDriveCom::kTracking)
1060 {
1061 fAccuracy->Update(pos, acc);
1062 fVelocity->Update(vel);
1063 fAccuracy->MapWindow();
1064 fVelocity->MapWindow();
1065 }
1066 else
1067 {
1068 fAccuracy->UnmapWindow();
1069 fVelocity->UnmapWindow();
1070 }
1071 // stat&kTracking ? fOffset->MapWindow() : fOffset->UnmapWindow();
1072
1073/*
1074 if (fLog->TestBit(kHasChanged))
1075 {
1076 fLog->MapSubwindows();
1077 fLog->Layout();
1078 fLog->ResetBit(kHasChanged);
1079 }*/
1080}
1081// ======================================================================
1082
1083void MGCosy::CloseWindow()
1084{
1085 // Got close message for this MainFrame. Calls parent CloseWindow()
1086 // (which destroys the window) and terminate the application.
1087 // The close message is generated by the window manager when its close
1088 // window menu item is selected.
1089
1090 // gSystem->ExitLoop();
1091 // gSystem->DispatchOneEvent(kTRUE);
1092
1093 // TGMainFrame::CloseWindow();
1094 cout << "Closing window - waiting until all nodes are stopped." << endl;
1095 fQueue->PostMsg(WM_QUIT);
1096 cout << "Closing window - done." << endl;
1097 // gApplication->Terminate(0);
1098}
1099
1100void MGCosy::StartTrack(bool track)
1101{
1102 cout << "Start tracking." << endl;
1103
1104 XY xy0 = fCRaDec->GetCoordinates();
1105 XY xy1 = track ? xy0 : fCCalib->GetCoordinates();
1106
1107 RaDec dest0(xy0.X()*15., xy0.Y()); // xy.X() [h]->[ø]
1108 RaDec dest1(xy1.X()*15., xy1.Y()); // xy.X() [h]->[ø]
1109
1110 cout << "TrackPos: " << dest0.Ra() << "h " << dest0.Dec() << "\xb0" << endl;
1111 cout << "CalibPos: " << dest1.Ra() << "h " << dest1.Dec() << "\xb0" << endl;
1112
1113 RaDec dest[2] = { dest0, dest1 };
1114
1115 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1116
1117 cout << "PostMsg (WM_Track) returned." << endl;
1118}
1119
1120void MGCosy::StartTrackPos(Long_t mp1)
1121{
1122 cout << "Start tracking Zd/Az pos." << endl;
1123
1124 const XY &xy = fCZdAz->GetCoordinates();
1125
1126 ZdAz za(xy.X(), xy.Y());
1127
1128 switch (mp1)
1129 {
1130 case kPB_ZDm:
1131 za.Zd(za.Zd()-360/16384.);
1132 break;
1133 case kPB_ZDp:
1134 za.Zd(za.Zd()+360/16384.);
1135 break;
1136 case kPB_AZm:
1137 za.Az(za.Az()-360/16384.);
1138 break;
1139 case kPB_AZp:
1140 za.Az(za.Az()+360/16384.);
1141 break;
1142 }
1143
1144 cout << za.Zd() << "\xb0 " << za.Az() << "\xb0" << endl;
1145
1146 fQueue->PostMsg(WM_TRACKPOS, &za, sizeof(za));
1147
1148 cout << "PostMsg (WM_TrackPos) returned." << endl;
1149}
1150
1151void MGCosy::StartPos()
1152{
1153 cout << "Start positioning." << endl;
1154
1155 XY xy = fCZdAz->GetCoordinates();
1156 ZdAz dest(xy.X(), xy.Y());
1157
1158 cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
1159
1160 fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
1161
1162 cout << "PostMsg (WM_Position) returned." << endl;
1163}
1164
1165//
1166// ************************** For demo purpose **********************
1167//
1168#ifdef HAS_DEMO
1169
1170#include <TRandom.h>
1171class MDemo : public MThread
1172{
1173private:
1174 MsgQueue *fQueue;
1175 TRandom fRand;
1176
1177public:
1178 MDemo() : MThread(false) {}
1179
1180 void SetQueue(MsgQueue *q) { fQueue = q; }
1181
1182 bool Wait(int s, int m)
1183 {
1184 int i = 0;
1185 while (!HasStopFlag() && i++<m)
1186 usleep(s);
1187 if (HasStopFlag())
1188 return false;
1189 return true;
1190 }
1191
1192 bool Move(float zd, float az, int s, int m)
1193 {
1194 ZdAz dest1(zd, az);
1195 fQueue->PostMsg(WM_POSITION1, &dest1, sizeof(dest1));
1196 return Wait(s, m); // 30s?
1197 }
1198
1199 virtual void *Thread()
1200 {
1201 if (!Move(90, -65, 1000000, 27))
1202 return NULL;
1203
1204 Int_t i=1;
1205 while (i-->0)
1206 {
1207 Timer tm;
1208 tm.Now();
1209
1210 if (!Move(75, -80, 1000000, 13))
1211 break;
1212 if (!Move(60, -65, 1000000, 13))
1213 break;
1214 if (!Move(75, -50, 1000000, 13))
1215 break;
1216 if (!Move(90, -65, 1000000, 13))
1217 break;
1218 }
1219 if (!Move(60, -65, 1000000, 17))
1220 return NULL;
1221 if (!Move(90, -65, 1000000, 19))
1222 return NULL;
1223 if (!Move(90, -10, 1000000, 28))
1224 return NULL;
1225
1226 cout << "Demo Thread: done." << endl;
1227 return NULL;
1228 }
1229};
1230
1231MDemo demo;
1232
1233void MGCosy::StartDemo()
1234{
1235 cout << "Start Demo." << endl;
1236
1237 demo.SetQueue(fQueue);
1238 demo.Start();
1239
1240 cout << "PostMsg (WM_Demo) returned." << endl;
1241}
1242
1243void StopDemo()
1244{
1245 cout << "Stopping demo." << endl;
1246 demo.Stop();
1247}
1248#endif //HAS_DEMO
1249
1250/*
1251void MGCosy::StartCalib()
1252{
1253 cout << "Start Calibration." << endl;
1254
1255 XY xy = fCCalib->GetCoordinates();
1256 RaDec pos(xy.X()*360/24, xy.Y());
1257
1258 fQueue->PostMsg(WM_CALIB, &pos, sizeof(pos));
1259
1260 cout << "PostMsg (WM_Calib) returned." << endl;
1261}
1262*/
1263void MGCosy::StartTPoint()
1264{
1265 cout << "Start writing tpoint pair." << endl;
1266
1267 XY xy = fCCalib->GetCoordinates();
1268 RaDec pos(xy.X()*360/24, xy.Y());
1269
1270 //fQueue->PostMsg(WM_TPOINT, &pos, sizeof(pos));
1271 fQueue->Proc(WM_TPOINT, &pos);
1272
1273 cout << "PostMsg (WM_TPoint) returned." << endl;
1274}
1275//
1276// ******************************************************************
1277//
1278
1279Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1280{
1281 //
1282 // This processing is serialized!
1283 //
1284 switch (GET_MSG(msg))
1285 {
1286 case kC_COMMAND:
1287 switch (GET_SUBMSG(msg))
1288 {
1289 case kCM_COMBOBOX:
1290 switch (mp1)
1291 {
1292 case kCB_PredefPos:
1293 {
1294 MStar *pos = fPreDefList[mp2];
1295 if (pos)
1296 fCZdAz->SetCoordinates(ZdAz(pos->GetX(), pos->GetY()));
1297 return kTRUE;
1298 }
1299 case kCB_StarList:
1300 {
1301 MStar *pos = fStarList[mp2];
1302 if (pos)
1303 fCCalib->SetCoordinates(RaDec(pos->GetX(), pos->GetY()));
1304 return kTRUE;
1305 }
1306 }
1307 return kTRUE;
1308
1309 case kCM_TAB:
1310 //cout << "Tab: " << mp1 << endl;
1311 return kTRUE;
1312
1313 case kCM_BUTTON:
1314
1315 switch (mp1)
1316 {
1317 /*
1318 case kPB_POSITION:
1319 Start(0);
1320 return kTRUE;
1321
1322 case kPB_TRACK:
1323 Start(1);
1324 return kTRUE;
1325 */
1326 case kPB_START:
1327 switch (fTab->GetCurrent())
1328 {
1329 case 0:
1330 StartPos();
1331 return kTRUE;
1332 case 1:
1333 StartTrack(true);
1334 return kTRUE;
1335 case 2:
1336 fCRaDec->SetCoordinates(fCCalib->GetCoordinates());
1337 StartTrack(false);
1338 return kTRUE;
1339 case 3:
1340 fQueue->Proc(WM_TESTSE, (void*)1);
1341 return kTRUE;
1342 case 4:
1343 fQueue->Proc(WM_GEAR, (void*)1);
1344 return kTRUE;
1345#ifdef HAS_DEMO
1346 case 5:
1347 StartDemo();
1348 return kTRUE;
1349#endif
1350 }
1351 return kTRUE;
1352
1353 case kPB_STOP:
1354 cout << "Sending stop movement msg." << endl;
1355#ifdef HAS_DEMO
1356 StopDemo();
1357#endif
1358 fQueue->PostMsg(WM_STOP);
1359 if (fTab->GetCurrent()==3)
1360 fQueue->Proc(WM_TESTSE);
1361 if (fTab->GetCurrent()==4)
1362 fQueue->Proc(WM_GEAR);
1363 cout << "PostMsg (WM_Stop) returned." << endl;
1364 return kTRUE;
1365
1366 case kPB_CALCALTAZ:
1367 {
1368 XY xy = fCRaDec->GetCoordinates();
1369 fQueue->Proc(WM_CALCALTAZ, &xy);
1370 }
1371 return kTRUE;
1372
1373 case kPB_SavePreDef:
1374 {
1375 ofstream fout("prepos.txt", ios::app);
1376 XY za = fCZdAz->GetCoordinates();
1377 fout << setprecision(7) << za.X() << " \t" << za.Y();
1378 fout << " New Position" << endl;
1379 }
1380 return kTRUE;
1381 case kPB_SaveStar:
1382 {
1383 ofstream fout("stars.txt", ios::app);
1384 XY za = fCCalib->GetCoordinates();
1385
1386 UShort_t d, m, s;
1387 Char_t sgn;
1388 Slalib::Deg2Dms(za.X(), sgn, d, m, s);
1389 if (sgn=='-') fout << sgn;
1390 fout << d << " " << m << " " << s << " \t";
1391 Slalib::Deg2Dms(za.Y(), sgn, d, m, s);
1392 if (sgn=='-') fout << sgn;
1393 fout << d << " " << m << " " << s << " \t";
1394 fout << " New Star/Source" << endl;
1395 }
1396 return kTRUE;
1397
1398 case kPB_RAp:
1399 case kPB_RAm:
1400 case kPB_DECp:
1401 case kPB_DECm:
1402 {
1403 XY xy = fCRaDec->GetCoordinates();
1404 switch (mp1)
1405 {
1406 case kPB_RAp:
1407 xy.X(xy.X()+1./60);
1408 break;
1409 case kPB_RAm:
1410 xy.X(xy.X()-1./60);
1411 break;
1412 case kPB_DECp:
1413 xy.Y(xy.Y()+1./60);
1414 break;
1415 case kPB_DECm:
1416 xy.Y(xy.Y()-1./60);
1417 break;
1418 }
1419 fCRaDec->SetCoordinates(xy);
1420 StartTrack(false);
1421 /*
1422 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
1423 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1424 //fQueue->Proc(WM_NEWTRACK, &dest);
1425 */
1426 //cout << "New Ra/Dec: " << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
1427 }
1428 return kTRUE;
1429
1430 case kPB_ZDp:
1431 case kPB_ZDm:
1432 case kPB_AZp:
1433 case kPB_AZm:
1434 StartTrackPos(mp1);
1435 return kTRUE;
1436
1437 case kPB_TPOINT:
1438 StartTPoint();
1439 return kTRUE;
1440
1441 case kPB_ENDSWITCH:
1442 fQueue->Proc(WM_ENDSWITCH);
1443 return kTRUE;
1444 /*
1445 case kPB_CALIBSE:
1446 StartCalib();
1447 return kTRUE;
1448 */
1449 case kPB_LoadBending:
1450 fQueue->Proc(WM_LOADBENDING);
1451 return kTRUE;
1452 case kPB_ResetBending:
1453 fQueue->Proc(WM_RESETBENDING);
1454 return kTRUE;
1455 /*
1456 case kPB_HOME:
1457 fQueue->PostMsg(WM_HOME, 0, 0);
1458 return kTRUE;
1459 */
1460 case kPB_TRACKPOS:
1461 StartTrackPos();
1462 return kTRUE;
1463 case kPB_DISPLAY1:
1464 case kPB_DISPLAY2:
1465 fQueue->PostMsg(WM_DISPLAY);
1466 return kTRUE;
1467
1468 default:
1469 return kTRUE;
1470 }
1471 return kTRUE;
1472
1473 case kCM_MENU:
1474
1475 switch (mp1)
1476 {
1477 case IDM_EXIT:
1478 cout << "IDM_EXIT: Posting WM_QUIT." << endl;
1479 fQueue->PostMsg(WM_QUIT);
1480 cout << "IDM_EXIT: WM_QUIT done." << endl;
1481 //cout << "Idm_Exit." << endl;
1482 //CloseWindow();
1483 return kTRUE;
1484 case IDM_ASPECT:
1485 {
1486 Int_t w = GetWidth();
1487 Int_t h = GetHeight();
1488 if (w>940*h/660)
1489 w = 940*h/660;
1490 else
1491 h = 660*w/940;
1492 Resize(w, h);
1493 }
1494 return kTRUE;
1495 case kLogClear:
1496 fLog->Clear();
1497 return kTRUE;
1498 case kLogCopy:
1499 fLog->Copy();
1500 return kTRUE;
1501 case kLogSelect:
1502 fLog->SelectAll();
1503 return kTRUE;
1504 case kLogSearch:
1505 //virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
1506 return kTRUE;
1507 case kLogSave:
1508 cout << "Saving log... " << flush;
1509 if (fLog->GetText()->Save("cosylog.txt"))
1510 cout << "done." << endl;
1511 else
1512 cout << "failed!" << endl;
1513 return kTRUE;
1514
1515 case kLogAppend:
1516 cout << "Appending log... " << flush;
1517 if (fLog->GetText()->Append("cosylog.txt"))
1518 cout << "done." << endl;
1519 else
1520 cout << "failed!" << endl;
1521 return kTRUE;
1522 }
1523 return kTRUE;
1524 }
1525 }
1526
1527 //
1528 // Start a thread to process the message.
1529 //
1530 // fQueue->PostMsg(msg, mp1, mp2);
1531 return kTRUE;
1532
1533}
Note: See TracBrowser for help on using the repository browser.