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

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