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

Last change on this file since 3204 was 2615, 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 "MCosy.h"
25#include "MTime.h"
26#include "MAstro.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(MAstro::Hms2Hor(h, m, s), MAstro::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 MAstro::Rad2Hm(rd.Ra(), sh, h, hm);
892 MAstro::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 MAstro::Hor2Hm(radec.Ra(), sh, h, hm);
925 MAstro::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 MAstro::Rad2Dm(soll.Zd(), sz, z, zm);
977 MAstro::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 MTime time;
997 time.Now();
998
999 static TString oldtxt;
1000
1001 TString text(time.GetString());
1002 text.Remove(text.Last('.')+2);
1003
1004 if (text!=oldtxt)
1005 {
1006 fUtc->SetText(new TGString(text));
1007 oldtxt = text;
1008 }
1009
1010 static ULong_t oldmjd=0;
1011 const double mjd = time.GetMjd();
1012
1013 if (oldmjd != (ULong_t)(1000000*mjd))
1014 {
1015 fMjd->SetText(new TGString(Form("%12.6f", mjd)));
1016 oldmjd = (ULong_t)(1000000*mjd);
1017 }
1018
1019 return mjd;
1020}
1021
1022void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, /*ZdAz off,*/ RaDec radec,
1023 ZdAz soll, UInt_t stat, UInt_t stat2)
1024{
1025 // acc [rad]
1026 acc *= kRad2Deg; // [deg]
1027
1028 const double mjd = UpdateTime();
1029 fSkyPosition->Update(pos, mjd);
1030 //UpdateOffset(off);
1031 UpdateRaDec(pos, mjd, radec);
1032 UpdateZdAz(soll);
1033
1034 EnableLabel(fError, stat&MDriveCom::kError);
1035 EnableLabel(fMoving, stat&MDriveCom::kMoving);
1036 EnableLabel(fTracking, stat&MDriveCom::kTracking);
1037 EnableLabel(fStopping, stat&MDriveCom::kStopping);
1038 EnableLabel(fStopped, stat&MDriveCom::kStopped);
1039 EnableLabel(fRaSoll, stat&MDriveCom::kTracking);
1040 EnableLabel(fDecSoll, stat&MDriveCom::kTracking);
1041 EnableLabel(fZdSoll, stat&MDriveCom::kMoving);
1042 EnableLabel(fAzSoll, stat&MDriveCom::kMoving);
1043
1044 SetLabelColor(fAvailMac1, stat2&0x01);
1045 SetLabelColor(fAvailMac2, stat2&0x02);
1046 //SetLabelColor(fAvailMac3, stat2&0x04);
1047 SetLabelColor(fAvailSe1, stat2&0x08);
1048 SetLabelColor(fAvailSe2, stat2&0x10);
1049 SetLabelColor(fAvailSe3, stat2&0x20);
1050
1051 if (stat&MDriveCom::kTracking)
1052 {
1053 fAccuracy->Update(pos, acc);
1054 fVelocity->Update(vel);
1055 fAccuracy->MapWindow();
1056 fVelocity->MapWindow();
1057 }
1058 else
1059 {
1060 fAccuracy->UnmapWindow();
1061 fVelocity->UnmapWindow();
1062 }
1063 // stat&kTracking ? fOffset->MapWindow() : fOffset->UnmapWindow();
1064
1065/*
1066 if (fLog->TestBit(kHasChanged))
1067 {
1068 fLog->MapSubwindows();
1069 fLog->Layout();
1070 fLog->ResetBit(kHasChanged);
1071 }*/
1072}
1073// ======================================================================
1074
1075void MGCosy::CloseWindow()
1076{
1077 // Got close message for this MainFrame. Calls parent CloseWindow()
1078 // (which destroys the window) and terminate the application.
1079 // The close message is generated by the window manager when its close
1080 // window menu item is selected.
1081
1082 // gSystem->ExitLoop();
1083 // gSystem->DispatchOneEvent(kTRUE);
1084
1085 // TGMainFrame::CloseWindow();
1086 cout << "Closing window - waiting until all nodes are stopped." << endl;
1087 fQueue->PostMsg(WM_QUIT);
1088 cout << "Closing window - done." << endl;
1089 // gApplication->Terminate(0);
1090}
1091
1092void MGCosy::StartTrack(bool track)
1093{
1094 cout << "Start tracking." << endl;
1095
1096 XY xy0 = fCRaDec->GetCoordinates();
1097 XY xy1 = track ? xy0 : fCCalib->GetCoordinates();
1098
1099 RaDec dest0(xy0.X()*15., xy0.Y()); // xy.X() [h]->[ø]
1100 RaDec dest1(xy1.X()*15., xy1.Y()); // xy.X() [h]->[ø]
1101
1102 cout << "TrackPos: " << dest0.Ra() << "h " << dest0.Dec() << "\xb0" << endl;
1103 cout << "CalibPos: " << dest1.Ra() << "h " << dest1.Dec() << "\xb0" << endl;
1104
1105 RaDec dest[2] = { dest0, dest1 };
1106
1107 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1108
1109 cout << "PostMsg (WM_Track) returned." << endl;
1110}
1111
1112void MGCosy::StartTrackPos(Long_t mp1)
1113{
1114 cout << "Start tracking Zd/Az pos." << endl;
1115
1116 const XY &xy = fCZdAz->GetCoordinates();
1117
1118 ZdAz za(xy.X(), xy.Y());
1119
1120 switch (mp1)
1121 {
1122 case kPB_ZDm:
1123 za.Zd(za.Zd()-360/16384.);
1124 break;
1125 case kPB_ZDp:
1126 za.Zd(za.Zd()+360/16384.);
1127 break;
1128 case kPB_AZm:
1129 za.Az(za.Az()-360/16384.);
1130 break;
1131 case kPB_AZp:
1132 za.Az(za.Az()+360/16384.);
1133 break;
1134 }
1135
1136 cout << za.Zd() << "\xb0 " << za.Az() << "\xb0" << endl;
1137
1138 fQueue->PostMsg(WM_TRACKPOS, &za, sizeof(za));
1139
1140 cout << "PostMsg (WM_TrackPos) returned." << endl;
1141}
1142
1143void MGCosy::StartPos()
1144{
1145 cout << "Start positioning." << endl;
1146
1147 XY xy = fCZdAz->GetCoordinates();
1148 ZdAz dest(xy.X(), xy.Y());
1149
1150 cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
1151
1152 fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
1153
1154 cout << "PostMsg (WM_Position) returned." << endl;
1155}
1156
1157//
1158// ************************** For demo purpose **********************
1159//
1160#ifdef HAS_DEMO
1161
1162#include <TRandom.h>
1163class MDemo : public MThread
1164{
1165private:
1166 MsgQueue *fQueue;
1167 TRandom fRand;
1168
1169public:
1170 MDemo() : MThread(false) {}
1171
1172 void SetQueue(MsgQueue *q) { fQueue = q; }
1173
1174 bool Wait(int s, int m)
1175 {
1176 int i = 0;
1177 while (!HasStopFlag() && i++<m)
1178 usleep(s);
1179 if (HasStopFlag())
1180 return false;
1181 return true;
1182 }
1183
1184 bool Move(float zd, float az, int s, int m)
1185 {
1186 ZdAz dest1(zd, az);
1187 fQueue->PostMsg(WM_POSITION1, &dest1, sizeof(dest1));
1188 return Wait(s, m); // 30s?
1189 }
1190
1191 virtual void *Thread()
1192 {
1193 if (!Move(90, -65, 1000000, 27))
1194 return NULL;
1195
1196 Int_t i=1;
1197 while (i-->0)
1198 {
1199 //Timer tm;
1200 //tm.Now();
1201
1202 if (!Move(75, -80, 1000000, 13))
1203 break;
1204 if (!Move(60, -65, 1000000, 13))
1205 break;
1206 if (!Move(75, -50, 1000000, 13))
1207 break;
1208 if (!Move(90, -65, 1000000, 13))
1209 break;
1210 }
1211 if (!Move(60, -65, 1000000, 17))
1212 return NULL;
1213 if (!Move(90, -65, 1000000, 19))
1214 return NULL;
1215 if (!Move(90, -10, 1000000, 28))
1216 return NULL;
1217
1218 cout << "Demo Thread: done." << endl;
1219 return NULL;
1220 }
1221};
1222
1223MDemo demo;
1224
1225void MGCosy::StartDemo()
1226{
1227 cout << "Start Demo." << endl;
1228
1229 demo.SetQueue(fQueue);
1230 demo.Start();
1231
1232 cout << "PostMsg (WM_Demo) returned." << endl;
1233}
1234
1235void StopDemo()
1236{
1237 cout << "Stopping demo." << endl;
1238 demo.Stop();
1239}
1240#endif //HAS_DEMO
1241
1242/*
1243void MGCosy::StartCalib()
1244{
1245 cout << "Start Calibration." << endl;
1246
1247 XY xy = fCCalib->GetCoordinates();
1248 RaDec pos(xy.X()*360/24, xy.Y());
1249
1250 fQueue->PostMsg(WM_CALIB, &pos, sizeof(pos));
1251
1252 cout << "PostMsg (WM_Calib) returned." << endl;
1253}
1254*/
1255void MGCosy::StartTPoint()
1256{
1257 cout << "Start writing tpoint pair." << endl;
1258
1259 XY xy = fCCalib->GetCoordinates();
1260 RaDec pos(xy.X()*360/24, xy.Y());
1261
1262 //fQueue->PostMsg(WM_TPOINT, &pos, sizeof(pos));
1263 fQueue->Proc(WM_TPOINT, &pos);
1264
1265 cout << "PostMsg (WM_TPoint) returned." << endl;
1266}
1267//
1268// ******************************************************************
1269//
1270
1271Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1272{
1273 //
1274 // This processing is serialized!
1275 //
1276 switch (GET_MSG(msg))
1277 {
1278 case kC_COMMAND:
1279 switch (GET_SUBMSG(msg))
1280 {
1281 case kCM_COMBOBOX:
1282 switch (mp1)
1283 {
1284 case kCB_PredefPos:
1285 {
1286 MStar *pos = fPreDefList[mp2];
1287 if (pos)
1288 fCZdAz->SetCoordinates(ZdAz(pos->GetX(), pos->GetY()));
1289 return kTRUE;
1290 }
1291 case kCB_StarList:
1292 {
1293 MStar *pos = fStarList[mp2];
1294 if (pos)
1295 fCCalib->SetCoordinates(RaDec(pos->GetX(), pos->GetY()));
1296 return kTRUE;
1297 }
1298 }
1299 return kTRUE;
1300
1301 case kCM_TAB:
1302 //cout << "Tab: " << mp1 << endl;
1303 return kTRUE;
1304
1305 case kCM_BUTTON:
1306
1307 switch (mp1)
1308 {
1309 /*
1310 case kPB_POSITION:
1311 Start(0);
1312 return kTRUE;
1313
1314 case kPB_TRACK:
1315 Start(1);
1316 return kTRUE;
1317 */
1318 case kPB_START:
1319 switch (fTab->GetCurrent())
1320 {
1321 case 0:
1322 StartPos();
1323 return kTRUE;
1324 case 1:
1325 StartTrack(true);
1326 return kTRUE;
1327 case 2:
1328 fCRaDec->SetCoordinates(fCCalib->GetCoordinates());
1329 StartTrack(false);
1330 return kTRUE;
1331 case 3:
1332 fQueue->Proc(WM_TESTSE, (void*)1);
1333 return kTRUE;
1334 case 4:
1335 fQueue->Proc(WM_GEAR, (void*)1);
1336 return kTRUE;
1337#ifdef HAS_DEMO
1338 case 5:
1339 StartDemo();
1340 return kTRUE;
1341#endif
1342 }
1343 return kTRUE;
1344
1345 case kPB_STOP:
1346 cout << "Sending stop movement msg." << endl;
1347#ifdef HAS_DEMO
1348 StopDemo();
1349#endif
1350 fQueue->PostMsg(WM_STOP);
1351 if (fTab->GetCurrent()==3)
1352 fQueue->Proc(WM_TESTSE);
1353 if (fTab->GetCurrent()==4)
1354 fQueue->Proc(WM_GEAR);
1355 cout << "PostMsg (WM_Stop) returned." << endl;
1356 return kTRUE;
1357
1358 case kPB_CALCALTAZ:
1359 {
1360 XY xy = fCRaDec->GetCoordinates();
1361 fQueue->Proc(WM_CALCALTAZ, &xy);
1362 }
1363 return kTRUE;
1364
1365 case kPB_SavePreDef:
1366 {
1367 ofstream fout("prepos.txt", ios::app);
1368 XY za = fCZdAz->GetCoordinates();
1369 fout << setprecision(7) << za.X() << " \t" << za.Y();
1370 fout << " New Position" << endl;
1371 }
1372 return kTRUE;
1373 case kPB_SaveStar:
1374 {
1375 ofstream fout("stars.txt", ios::app);
1376 XY za = fCCalib->GetCoordinates();
1377
1378 UShort_t d, m, s;
1379 Char_t sgn;
1380 MAstro::Deg2Dms(za.X(), sgn, d, m, s);
1381 if (sgn=='-') fout << sgn;
1382 fout << d << " " << m << " " << s << " \t";
1383 MAstro::Deg2Dms(za.Y(), sgn, d, m, s);
1384 if (sgn=='-') fout << sgn;
1385 fout << d << " " << m << " " << s << " \t";
1386 fout << " New Star/Source" << endl;
1387 }
1388 return kTRUE;
1389
1390 case kPB_RAp:
1391 case kPB_RAm:
1392 case kPB_DECp:
1393 case kPB_DECm:
1394 {
1395 XY xy = fCRaDec->GetCoordinates();
1396 switch (mp1)
1397 {
1398 case kPB_RAp:
1399 xy.X(xy.X()+1./60);
1400 break;
1401 case kPB_RAm:
1402 xy.X(xy.X()-1./60);
1403 break;
1404 case kPB_DECp:
1405 xy.Y(xy.Y()+1./60);
1406 break;
1407 case kPB_DECm:
1408 xy.Y(xy.Y()-1./60);
1409 break;
1410 }
1411 fCRaDec->SetCoordinates(xy);
1412 StartTrack(false);
1413 /*
1414 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
1415 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1416 //fQueue->Proc(WM_NEWTRACK, &dest);
1417 */
1418 //cout << "New Ra/Dec: " << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
1419 }
1420 return kTRUE;
1421
1422 case kPB_ZDp:
1423 case kPB_ZDm:
1424 case kPB_AZp:
1425 case kPB_AZm:
1426 StartTrackPos(mp1);
1427 return kTRUE;
1428
1429 case kPB_TPOINT:
1430 StartTPoint();
1431 return kTRUE;
1432
1433 case kPB_ENDSWITCH:
1434 fQueue->Proc(WM_ENDSWITCH);
1435 return kTRUE;
1436 /*
1437 case kPB_CALIBSE:
1438 StartCalib();
1439 return kTRUE;
1440 */
1441 case kPB_LoadBending:
1442 fQueue->Proc(WM_LOADBENDING);
1443 return kTRUE;
1444 case kPB_ResetBending:
1445 fQueue->Proc(WM_RESETBENDING);
1446 return kTRUE;
1447 /*
1448 case kPB_HOME:
1449 fQueue->PostMsg(WM_HOME, 0, 0);
1450 return kTRUE;
1451 */
1452 case kPB_TRACKPOS:
1453 StartTrackPos();
1454 return kTRUE;
1455 case kPB_DISPLAY1:
1456 case kPB_DISPLAY2:
1457 fQueue->PostMsg(WM_DISPLAY);
1458 return kTRUE;
1459
1460 default:
1461 return kTRUE;
1462 }
1463 return kTRUE;
1464
1465 case kCM_MENU:
1466
1467 switch (mp1)
1468 {
1469 case IDM_EXIT:
1470 cout << "IDM_EXIT: Posting WM_QUIT." << endl;
1471 fQueue->PostMsg(WM_QUIT);
1472 cout << "IDM_EXIT: WM_QUIT done." << endl;
1473 //cout << "Idm_Exit." << endl;
1474 //CloseWindow();
1475 return kTRUE;
1476 case IDM_ASPECT:
1477 {
1478 Int_t w = GetWidth();
1479 Int_t h = GetHeight();
1480 if (w>940*h/660)
1481 w = 940*h/660;
1482 else
1483 h = 660*w/940;
1484 Resize(w, h);
1485 }
1486 return kTRUE;
1487 case kLogClear:
1488 fLog->Clear();
1489 return kTRUE;
1490 case kLogCopy:
1491 fLog->Copy();
1492 return kTRUE;
1493 case kLogSelect:
1494 fLog->SelectAll();
1495 return kTRUE;
1496 case kLogSearch:
1497 //virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
1498 return kTRUE;
1499 case kLogSave:
1500 cout << "Saving log... " << flush;
1501 if (fLog->GetText()->Save("cosylog.txt"))
1502 cout << "done." << endl;
1503 else
1504 cout << "failed!" << endl;
1505 return kTRUE;
1506
1507 case kLogAppend:
1508 cout << "Appending log... " << flush;
1509 if (fLog->GetText()->Append("cosylog.txt"))
1510 cout << "done." << endl;
1511 else
1512 cout << "failed!" << endl;
1513 return kTRUE;
1514 }
1515 return kTRUE;
1516 }
1517 }
1518
1519 //
1520 // Start a thread to process the message.
1521 //
1522 // fQueue->PostMsg(msg, mp1, mp2);
1523 return kTRUE;
1524
1525}
Note: See TracBrowser for help on using the repository browser.