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

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