source: trunk/Cosy/gui/MGCosy.cc@ 12589

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