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

Last change on this file since 13845 was 12590, checked in by tbretz, 13 years ago
Removed special fact status -- unified already in MCosy.cc
File size: 46.7 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 SetLabelColor(fDkcReady1, pdo3&0x00000001);
1136 SetLabelColor(fDkcReady2, pdo3&0x00010000);
1137 SetLabelColor(fDkcEmergency, (pdo3&0x00040004)==0x00040004);
1138 SetLabelColor(fDkcPcMode, (pdo3&0x00100010)!=0x00100010);
1139 SetLabelColor(fDkcRF1, pdo3&0x00000020);
1140 SetLabelColor(fDkcRF2, pdo3&0x00200000);
1141 SetLabelColor(fDkcBrake, (pdo3&0x00400040)==0x00400040);
1142 SetLabelColor(fDkcPower, (pdo3&0x00800080)==0x00800080);
1143
1144 EnableLabel(fArmed, armed);
1145
1146 fMsgZd->SetText(new TGString(TString(" Zd: ")+statzd));
1147 fMsgAz->SetText(new TGString(TString(" Az: ")+stataz));
1148
1149
1150 if (stat&MDriveCom::kTracking)
1151 {
1152 fAccuracy->Update(pos, acc);
1153 // fAccuracyTime->Update(pos, acc);
1154 // fVelocity->Update(vel);
1155 fAccuracy->MapWindow();
1156 // fAccuracyTime->MapWindow();
1157 // fVelocity->MapWindow();
1158 }
1159 else
1160 {
1161 fAccuracy->UnmapWindow();
1162 // fAccuracyTime->UnmapWindow();
1163 // fVelocity->UnmapWindow();
1164 }
1165 // stat&kTracking ? fOffset->MapWindow() : fOffset->UnmapWindow();
1166
1167 //unsigned char empty[(768/2-1)*(576/2-1)];
1168 //fImage->DrawImg(empty);
1169 //fImage->DoRedraw();
1170
1171 // if (IsMapped())
1172 // fImage->DoRedraw();
1173}
1174
1175void MGCosy::UpdateWeather(const MCeCoCom &com)
1176{
1177 ULong_t color;
1178 switch (com.GetWeatherStatus())
1179 {
1180 case 0:
1181 color=TGFrame::GetDefaultFrameBackground();
1182 break;
1183 case 1:
1184 gClient->GetColorByName("Yellow", color);
1185 break;
1186 case 2:
1187 gClient->GetColorByName("Orange", color);
1188 break;
1189 default:
1190 gClient->GetColorByName("Red", color);
1191 break;
1192 }
1193
1194 if (com.HasAlarm())
1195 {
1196 static int i=0;
1197 if ((i++/4)%2==0)
1198 color = TGFrame::GetDefaultFrameBackground();
1199 }
1200
1201 const TString old(fWeather->GetText()->GetString());
1202 const TString txt(com.GetWeather());
1203
1204 // Color is only updated if the text has changed
1205 if (old!=txt || color!=fWeather->GetBackground())
1206 fWeather->SetText(txt);
1207
1208 if (color!=fWeather->GetBackground())
1209 fWeather->SetBackgroundColor(color);
1210}
1211
1212void MGCosy::CloseWindow()
1213{
1214 // Got close message for this MainFrame. Calls parent CloseWindow()
1215 // (which destroys the window) and terminate the application.
1216 // The close message is generated by the window manager when its close
1217 // window menu item is selected.
1218
1219 // gSystem->ExitLoop();
1220 // gSystem->DispatchOneEvent(kTRUE);
1221
1222 // TGMainFrame::CloseWindow();
1223 cout << "Closing window - waiting until all nodes are stopped." << endl;
1224 fQueue->PostMsg(WM_QUIT);
1225 cout << "Closing window - done." << endl;
1226 // gApplication->Terminate(0);
1227}
1228
1229void MGCosy::StartTrack(bool track)
1230{
1231 cout << "Start tracking." << endl;
1232
1233 XY xy0 = fCRaDec->GetCoordinates();
1234 XY xy1 = track ? xy0 : fCCalib->GetCoordinates();
1235
1236 RaDec dest0(xy0.X()*15., xy0.Y()); // xy.X() [h]->[ø]
1237 RaDec dest1(xy1.X()*15., xy1.Y()); // xy.X() [h]->[ø]
1238
1239 cout << "TrackPos: " << dest0.Ra() << "\xb0 " << dest0.Dec() << "\xb0" << endl;
1240 cout << "CalibPos: " << dest1.Ra() << "\xb0 " << dest1.Dec() << "\xb0" << endl;
1241
1242 RaDec dest[2] = { dest0, dest1 };
1243
1244 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1245
1246 cout << "PostMsg (WM_Track) returned." << endl;
1247}
1248
1249void MGCosy::StartCelest()
1250{
1251 cout << "Start celest." << endl;
1252
1253 Double_t tx[3] = { fCelestObj, 0, 0 };
1254
1255 fQueue->PostMsg(WM_CELEST, tx, sizeof(Double_t)*3);
1256
1257 cout << "PostMsg (WM_CELEST) returned." << endl;
1258}
1259
1260void MGCosy::StartTrackPos(Long_t mp1)
1261{
1262 cout << "Start tracking Zd/Az pos." << endl;
1263
1264 const XY &xy = fCZdAz->GetCoordinates();
1265
1266 ZdAz za(xy.X(), xy.Y());
1267
1268 switch (mp1)
1269 {
1270 case kPB_ZDm:
1271 za.Zd(za.Zd()-360/16384.);
1272 break;
1273 case kPB_ZDp:
1274 za.Zd(za.Zd()+360/16384.);
1275 break;
1276 case kPB_AZm:
1277 za.Az(za.Az()-360/16384.);
1278 break;
1279 case kPB_AZp:
1280 za.Az(za.Az()+360/16384.);
1281 break;
1282 }
1283
1284 cout << za.Zd() << "\xb0 " << za.Az() << "\xb0" << endl;
1285
1286 fQueue->PostMsg(WM_TRACKPOS, &za, sizeof(za));
1287
1288 cout << "PostMsg (WM_TrackPos) returned." << endl;
1289}
1290
1291void MGCosy::StartPos()
1292{
1293 cout << "Start positioning." << endl;
1294
1295 XY xy = fCZdAz->GetCoordinates();
1296 ZdAz dest(xy.X(), xy.Y());
1297
1298 cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
1299
1300 fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
1301
1302 cout << "PostMsg (WM_Position) returned." << endl;
1303}
1304
1305//
1306// ************************** For demo purpose **********************
1307//
1308#ifdef HAS_DEMO
1309
1310#include <TRandom.h>
1311class MDemo : public MThread
1312{
1313private:
1314 MsgQueue *fQueue;
1315 TRandom fRand;
1316
1317public:
1318 MDemo() : MThread(false) {}
1319
1320 void SetQueue(MsgQueue *q) { fQueue = q; }
1321
1322 bool Wait(int s, int m)
1323 {
1324 int i = 0;
1325 while (!HasStopFlag() && i++<m)
1326 usleep(s);
1327 if (HasStopFlag())
1328 return false;
1329 return true;
1330 }
1331
1332 bool Move(float zd, float az, int s, int m)
1333 {
1334 ZdAz dest1(zd, az);
1335 fQueue->PostMsg(WM_POSITION1, &dest1, sizeof(dest1));
1336 return Wait(s, m); // 30s?
1337 }
1338
1339 virtual void *Thread()
1340 {
1341 if (!Move(90, -65, 1000000, 27))
1342 return NULL;
1343
1344 Int_t i=1;
1345 while (i-->0)
1346 {
1347 //Timer tm;
1348 //tm.Now();
1349
1350 if (!Move(75, -80, 1000000, 13))
1351 break;
1352 if (!Move(60, -65, 1000000, 13))
1353 break;
1354 if (!Move(75, -50, 1000000, 13))
1355 break;
1356 if (!Move(90, -65, 1000000, 13))
1357 break;
1358 }
1359 if (!Move(60, -65, 1000000, 17))
1360 return NULL;
1361 if (!Move(90, -65, 1000000, 19))
1362 return NULL;
1363 if (!Move(90, -10, 1000000, 28))
1364 return NULL;
1365
1366 cout << "Demo Thread: done." << endl;
1367 return NULL;
1368 }
1369};
1370
1371MDemo demo;
1372
1373void MGCosy::StartDemo()
1374{
1375 cout << "Start Demo." << endl;
1376
1377 demo.SetQueue(fQueue);
1378 demo.Start();
1379
1380 cout << "PostMsg (WM_Demo) returned." << endl;
1381}
1382
1383void StopDemo()
1384{
1385 cout << "Stopping demo." << endl;
1386 demo.Stop();
1387}
1388#endif //HAS_DEMO
1389
1390/*
1391void MGCosy::StartCalib()
1392{
1393 cout << "Start Calibration." << endl;
1394
1395 XY xy = fCCalib->GetCoordinates();
1396 RaDec pos(xy.X()*360/24, xy.Y());
1397
1398 fQueue->PostMsg(WM_CALIB, &pos, sizeof(pos));
1399
1400 cout << "PostMsg (WM_Calib) returned." << endl;
1401}
1402*/
1403void MGCosy::StartTPoint()
1404{
1405 cout << "Start writing tpoint pair." << endl;
1406
1407 XY xy = fCCalib->GetCoordinates();
1408 RaDec pos(xy.X()*360/24, xy.Y());
1409
1410 //fQueue->PostMsg(WM_TPOINT, &pos, sizeof(pos));
1411 fQueue->Proc(WM_TPOINT, &pos);
1412
1413 cout << "PostMsg (WM_TPoint) returned." << endl;
1414}
1415//
1416// ******************************************************************
1417//
1418
1419Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1420{
1421 //
1422 // This processing is serialized!
1423 //
1424 switch (GET_MSG(msg))
1425 {
1426 case kC_COMMAND:
1427 switch (GET_SUBMSG(msg))
1428 {
1429 case kCM_COMBOBOX:
1430 switch (mp1)
1431 {
1432 case kCB_PredefPos:
1433 {
1434 MStar *pos = fPreDefList[mp2];
1435 if (pos)
1436 fCZdAz->SetCoordinates(ZdAz(pos->GetX(), pos->GetY()));
1437 return kTRUE;
1438 }
1439 case kCB_StarList:
1440 {
1441 MStar *pos = fStarList[mp2];
1442 if (pos)
1443 fCCalib->SetCoordinates(RaDec(pos->GetX(), pos->GetY()));
1444 return kTRUE;
1445 }
1446 case kCB_CelestList:
1447 {
1448 fCelestObj = mp2;
1449 return kTRUE;
1450 }
1451 }
1452 return kTRUE;
1453
1454 case kCM_TAB:
1455 //cout << "Tab: " << mp1 << endl;
1456 return kTRUE;
1457
1458 case kCM_BUTTON:
1459
1460 switch (mp1)
1461 {
1462 /*
1463 case kPB_POSITION:
1464 Start(0);
1465 return kTRUE;
1466
1467 case kPB_TRACK:
1468 Start(1);
1469 return kTRUE;
1470 */
1471 case kPB_START:
1472 switch (fTab->GetCurrent())
1473 {
1474 case 0:
1475 StartPos();
1476 return kTRUE;
1477 case 1:
1478 StartTrack(true);
1479 return kTRUE;
1480 case 2:
1481 StartCelest();
1482 return kTRUE;
1483 case 3:
1484 fCRaDec->SetCoordinates(fCCalib->GetCoordinates());
1485 StartTrack(false);
1486 return kTRUE;
1487 case 4:
1488 fQueue->Proc(WM_TESTSE, (void*)1);
1489 return kTRUE;
1490 case 5:
1491 fQueue->Proc(WM_GEAR, (void*)1);
1492 return kTRUE;
1493#ifdef HAS_DEMO
1494 case 6:
1495 StartDemo();
1496 return kTRUE;
1497#endif
1498 }
1499 return kTRUE;
1500
1501 case kPB_STOP:
1502 cout << "Sending stop movement msg." << endl;
1503#ifdef HAS_DEMO
1504 StopDemo();
1505#endif
1506 fQueue->PostMsg(WM_STOP);
1507 if (fTab->GetCurrent()==4)
1508 fQueue->Proc(WM_TESTSE);
1509 if (fTab->GetCurrent()==5)
1510 fQueue->Proc(WM_GEAR);
1511 cout << "PostMsg (WM_Stop) returned." << endl;
1512 return kTRUE;
1513
1514 case kPB_CALCALTAZ:
1515 {
1516 XY xy = fCRaDec->GetCoordinates();
1517 fQueue->Proc(WM_CALCALTAZ, &xy);
1518 }
1519 return kTRUE;
1520
1521 case kPB_SavePreDef:
1522 {
1523 ofstream fout("prepos.txt", ios::app);
1524 XY za = fCZdAz->GetCoordinates();
1525 fout << setprecision(7) << za.X() << " \t" << za.Y();
1526 fout << " New Position" << endl;
1527 }
1528 return kTRUE;
1529 case kPB_SaveStar:
1530 {
1531 ofstream fout("stars.txt", ios::app);
1532 XY za = fCCalib->GetCoordinates();
1533
1534 UShort_t d, m, s;
1535 Char_t sgn;
1536 MAstro::Deg2Dms(za.X(), sgn, d, m, s);
1537 if (sgn=='-') fout << sgn;
1538 fout << d << " " << m << " " << s << " \t";
1539 MAstro::Deg2Dms(za.Y(), sgn, d, m, s);
1540 if (sgn=='-') fout << sgn;
1541 fout << d << " " << m << " " << s << " \t";
1542 fout << " New Star/Source" << endl;
1543 }
1544 return kTRUE;
1545
1546 case kPB_RAp:
1547 case kPB_RAm:
1548 case kPB_DECp:
1549 case kPB_DECm:
1550 {
1551 XY xy = fCRaDec->GetCoordinates();
1552 switch (mp1)
1553 {
1554 case kPB_RAp:
1555 xy.Set(xy.X()+1./60, xy.Y());
1556 break;
1557 case kPB_RAm:
1558 xy.Set(xy.X()-1./60, xy.Y());
1559 break;
1560 case kPB_DECp:
1561 xy.Set(xy.X(), xy.Y()+1./60);
1562 break;
1563 case kPB_DECm:
1564 xy.Set(xy.X(), xy.Y()-1./60);
1565 break;
1566 }
1567 fCRaDec->SetCoordinates(xy);
1568 StartTrack(false);
1569 /*
1570 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
1571 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1572 //fQueue->Proc(WM_NEWTRACK, &dest);
1573 */
1574 //cout << "New Ra/Dec: " << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
1575 }
1576 return kTRUE;
1577
1578 case kPB_ZDp:
1579 case kPB_ZDm:
1580 case kPB_AZp:
1581 case kPB_AZm:
1582 StartTrackPos(mp1);
1583 return kTRUE;
1584
1585 case kPB_TPOINT:
1586 StartTPoint();
1587 return kTRUE;
1588
1589 case kPB_ENDSWITCH:
1590 fQueue->Proc(WM_ENDSWITCH);
1591 return kTRUE;
1592 /*
1593 case kPB_CALIBSE:
1594 StartCalib();
1595 return kTRUE;
1596 */
1597 case kPB_LoadBending:
1598 fQueue->Proc(WM_LOADBENDING);
1599 return kTRUE;
1600 case kPB_ResetBending:
1601 fQueue->Proc(WM_RESETBENDING);
1602 return kTRUE;
1603 /*
1604 case kPB_HOME:
1605 fQueue->PostMsg(WM_HOME, 0, 0);
1606 return kTRUE;
1607 */
1608 case kPB_TRACKPOS:
1609 StartTrackPos();
1610 return kTRUE;
1611 case kPB_ARM:
1612 fQueue->PostMsg(WM_ARM);
1613 return kTRUE;
1614 case kPB_DISPLAY1:
1615 case kPB_DISPLAY2:
1616 fQueue->PostMsg(WM_DISPLAY);
1617 return kTRUE;
1618
1619 default:
1620 return kTRUE;
1621 }
1622 return kTRUE;
1623
1624 case kCM_MENU:
1625
1626 switch (mp1)
1627 {
1628 case IDM_EXIT:
1629 cout << "IDM_EXIT: Posting WM_QUIT." << endl;
1630 fQueue->PostMsg(WM_QUIT);
1631 cout << "IDM_EXIT: WM_QUIT done." << endl;
1632 //cout << "Idm_Exit." << endl;
1633 //CloseWindow();
1634 return kTRUE;
1635 case IDM_ASPECT:
1636 {
1637 Int_t w = GetWidth();
1638 Int_t h = GetHeight();
1639 if (w>940*h/660)
1640 w = 940*h/660;
1641 else
1642 h = 660*w/940;
1643 Resize(w, h);
1644 }
1645 return kTRUE;
1646 case kLogClear:
1647 fLog->Clear();
1648 return kTRUE;
1649 case kLogCopy:
1650 fLog->Copy();
1651 return kTRUE;
1652 case kLogSelect:
1653 fLog->SelectAll();
1654 return kTRUE;
1655 case kLogSearch:
1656 //virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
1657 return kTRUE;
1658 case kLogSave:
1659 cout << "Saving log... " << flush;
1660 if (fLog->GetText()->Save("cosylog.txt"))
1661 cout << "done." << endl;
1662 else
1663 cout << "failed!" << endl;
1664 return kTRUE;
1665
1666 case kLogAppend:
1667 cout << "Appending log... " << flush;
1668 if (fLog->GetText()->Append("cosylog.txt"))
1669 cout << "done." << endl;
1670 else
1671 cout << "failed!" << endl;
1672 return kTRUE;
1673 }
1674 return kTRUE;
1675 }
1676 }
1677
1678 //
1679 // Start a thread to process the message.
1680 //
1681 // fQueue->PostMsg(msg, mp1, mp2);
1682 return kTRUE;
1683
1684}
Note: See TracBrowser for help on using the repository browser.