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

Last change on this file since 9223 was 9132, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 44.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 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)
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.txt");
334 if (!fin)
335 {
336 gLog << err << "ERROR: Predifined positions in 'prepos.txt' 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()
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);
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, 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->DrawText("0.5se", "1.0se", "2.0se", "Ctrl Deviation [min]");
758 fAccuracy->DrawCircles();
759
760 fImage = new MGImage(f2, 768/2-1, 576/2-1, kRaisedFrame);
761 //fVelocity = new MGVelocity(f2, "Velocity [U_{mot}/min]", 300);
762 // fOffset = new MGVelocity (f, "Offset se-re [']", 300);
763// fAccuracyTime = new MGAccuracyTime(f2, 300);
764
765 //fList->Add(fSkyPosition);
766 //fList->Add(fAccuracy);
767 // fList->Add(fAccuracyTime);
768 // fList->Add(fVelocity);
769 // fList->Add(fOffset);
770 //fList->Add(fImage);
771
772 TGGroupFrame *frame = new TGGroupFrame(f2, "Status");
773 // frame->SetCleanup();
774 //fList->Add(frame);
775
776 fLog = new TGTextView(f2, 300, 300);
777 if (fFont)
778 fLog->SetFont(fFont);
779 //fList->Add(fLog);
780
781 TGLayoutHints *hints1 = new TGLayoutHints(kLHintsNormal | kLHintsExpandX|kLHintsExpandY, 6, 6, 6, 3);
782 TGLayoutHints *hints2 = new TGLayoutHints(kLHintsNormal | kLHintsExpandX|kLHintsExpandY, 6, 6, 3, 6);
783
784 TGLayoutHints *hints1a = new TGLayoutHints(kLHintsLeft | kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
785 TGLayoutHints *hints2a = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY|kLHintsExpandX|kLHintsExpandY, 6, 6);
786 TGLayoutHints *hints3a = new TGLayoutHints(kLHintsRight | kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
787 TGLayoutHints *hints1b = new TGLayoutHints(kLHintsLeft | kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
788 TGLayoutHints *hints2b = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 6, 6);
789 TGLayoutHints *hints3b = new TGLayoutHints(kLHintsRight | kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
790
791 /*
792 fList->Add(hints1);
793 fList->Add(hints2);
794 fList->Add(hints1a);
795 fList->Add(hints2a);
796 fList->Add(hints3a);
797 fList->Add(hints1b);
798 fList->Add(hints2b);
799 fList->Add(hints3b);
800 */
801 // Layout upper frame
802 f1->AddFrame(fTab, hints1a);
803 f1->AddFrame(fSkyPosition, hints2a);
804 f1->AddFrame(fAccuracy, hints3a);
805
806 // Layout upper frame
807 f2->AddFrame(frame, hints1b);
808 f2->AddFrame(fImage, hints2b);
809 //f2->AddFrame(fVelocity, hints2b);
810 //f2->AddFrame(fAccuracyTime, hints2b);
811 f2->AddFrame(fLog, hints3b);
812
813 // Layout window
814 AddFrame(f1, hints1);
815 AddFrame(f2, hints2);
816
817 CreateTabs();
818 CreateLabel(frame);
819
820
821 //
822 // Map the window, set up the layout, etc.
823 //
824 const Int_t ww = 1010;
825 const Int_t hh = 680;
826 SetWMSizeHints(ww, hh, ww, hh, 1, 1); // set the smallest and biggest size of the Main frame
827
828 SetWindowName("Cosy Main Window");
829 SetIconName("Cosy");
830
831#ifdef DEBUG
832 cout << "MGCosy: Map Window" << endl;
833#endif
834 MapSubwindows();
835 Resize(ww, hh); //GetDefaultSize());
836 MapWindow();
837}
838
839// ======================================================================
840
841MGCosy::~MGCosy()
842{
843 /*
844 TIter Next(fList);
845 TObject *o=0;
846 while((o=Next()))
847 {
848 cout << o << " " << flush;
849 cout << o->ClassName() << " " << flush;
850 cout << o->GetName() << " " << endl;
851 delete o;
852 }
853 */
854#ifdef DEBUG
855 cout << "MGCosy::~MGCosy called." << endl;
856#endif
857 delete fList;
858#ifdef DEBUG
859 cout << "Deleting MGCosy::fFont" << endl;
860#endif
861 if (fFont)
862 gVirtualX->DeleteFont(fFont);
863#ifdef DEBUG
864 cout << "MGCosy::~MGCosy done." << endl;
865#endif
866}
867
868void MGCosy::SetLabelColor(TGLabel *label, Bool_t col)
869{
870 ULong_t red, green;
871
872 gClient->GetColorByName("Red", red);
873 gClient->GetColorByName("Green", green);
874
875 if (col && label->TestBit(BIT(14)))
876 return;
877
878 if (!col && !label->TestBit(BIT(14)))
879 return;
880
881 col ? label->SetBit(BIT(14)) : label->ResetBit(BIT(14));
882
883 label->UnmapWindow();
884 label->SetBackgroundColor(col ? green : red);
885 label->MapWindow();
886}
887
888// ======================================================================
889void MGCosy::EnableLabel(TGLabel *label, Bool_t stat)
890{
891 stat ? label->MapWindow() : label->UnmapWindow();
892
893 /*
894 TGGC *fRedTextGC(TGButton::GetDefaultGC())
895 // Set foreground color in graphics context for drawing of
896 // TGlabel and TGButtons with text in red.
897 ULong_t red;
898 gClient->GetColorByName("red", red);
899 fRedTextGC.SetForeground(red);
900 */
901}
902
903void MGCosy::UpdateRaDec(ZdAz &pos, double mjd, RaDec &radec)
904{
905 static Int_t rai=~0;
906 static Int_t deci=~0;
907 static Int_t ras=~0;
908 static Int_t decs=~0;
909
910 static SlaStars sla(fObservatory);
911 sla.SetMjd(mjd);
912
913 RaDec rd = sla.CalcRaDec(pos*2*TMath::Pi()/360);
914
915 char text[64];
916
917 UShort_t h, d;
918 Double_t hm, dm;
919 Char_t sh, sd;
920
921 // Calculate Display values
922 MAstro::Rad2Hm(rd.Ra(), sh, h, hm);
923 MAstro::Rad2Dm(rd.Dec(), sd, d, dm);
924
925 rd.Ra(rd.Ra() * 12/TMath::Pi());
926 rd.Dec(rd.Dec()*180/TMath::Pi());
927
928 RaDec test = rd*600;
929 if (rai!=(int)test.Ra())
930 {
931 rai = (int)test.Ra();
932 //sprintf(text, "%c%dh %.1fm", rd.Ra()<0?'-':'+', abs((int)rd.Ra()), 0.1*(abs((int)test.Ra())%600));
933 sprintf(text, "%c%dh %.1fm", sh, h, hm);
934 fRaEst->SetText(new TGString(text));
935 }
936 if (deci!=(int)test.Dec())
937 {
938 deci = (int)test.Dec();
939 //sprintf(text, "%c%dd %.1fm", rd.Dec()<0?'-':'+' , abs((int)rd.Dec()), 0.1*(abs((int)test.Dec())%600));
940 sprintf(text, "%c%dd %.1fm", sd, d, dm);
941 fDecEst->SetText(new TGString(text));
942 }
943
944 // Align RaDec
945 radec.Ra(radec.Ra() * 12/TMath::Pi());
946 radec.Dec(radec.Dec()*180/TMath::Pi());
947 if (radec.Dec()>90|| radec.Dec()<-90)
948 {
949 radec.Ra(radec.Ra()+12);
950 radec.Dec(180-radec.Dec());
951 }
952 radec.Ra(fmod((radec.Ra()+48), 24));
953
954 // Calculate display values
955 MAstro::Hor2Hm(radec.Ra(), sh, h, hm);
956 MAstro::Deg2Dm(radec.Dec(), sd, d, dm);
957
958 test = radec*600;
959 if (ras!=(int)test.Ra())
960 {
961 ras = (int)test.Ra();
962 //sprintf(text, "%c%dh %.1fm", radec.Ra()<0?'-':'+', abs((int)radec.Ra()), 0.1*(abs((int)test.Ra())%600));
963 sprintf(text, "%c%dh %.1fm", sh, h, hm);
964 fRaSoll->SetText(new TGString(text));
965 }
966 if (decs!=(int)test.Dec())
967 {
968 decs = (int)test.Dec();
969 //sprintf(text, "%c%dd %.1fm", radec.Dec()<0?'-':'+' , abs((int)radec.Dec()), 0.1*(abs((int)test.Dec())%600));
970 sprintf(text, "%c%dd %.1fm", sd, d, dm);
971 fDecSoll->SetText(new TGString(text));
972 }
973}
974/*
975void MGCosy::UpdateOffset(ZdAz &off)
976{
977 static Int_t zd=~0;
978 static Int_t az=~0;
979
980 char text[21];
981
982 if (zd!=(Int_t)off.Zd())
983 {
984 zd = (Int_t)off.Zd();
985 sprintf(text, "%dre", zd);
986 fOffsetZd->SetText(new TGString(text));
987 }
988 if (az!=(Int_t)off.Az())
989 {
990 az = (Int_t)off.Az();
991 sprintf(text, "%dre", az);
992 fOffsetAz->SetText(new TGString(text));
993 }
994}
995*/
996void MGCosy::UpdateZdAz(ZdAz &soll)
997{
998 static Int_t zd=~0;
999 static Int_t az=~0;
1000
1001 char text[21];
1002
1003 UShort_t z, a;
1004 Double_t zm, am;
1005 Char_t sz, sa;
1006
1007 MAstro::Rad2Dm(soll.Zd(), sz, z, zm);
1008 MAstro::Rad2Dm(soll.Az(), sa, a, am);
1009
1010 const ZdAz test = soll*kRad2Deg*600;
1011 if (zd!=(int)test.Zd())
1012 {
1013 zd = (int)test.Zd();
1014 sprintf(text, "%c%dd %.1fm", sz, z, zm);
1015 fZdSoll->SetText(new TGString(text));
1016 }
1017 if (az!=(int)test.Az())
1018 {
1019 az = (int)test.Az();
1020 sprintf(text, "%c%dd %.1fm", sa, a, am);
1021 fAzSoll->SetText(new TGString(text));
1022 }
1023}
1024
1025double MGCosy::UpdateTime()
1026{
1027 MTime time;
1028 time.Now();
1029
1030 static TString oldtxt;
1031
1032 TString text(time.GetString());
1033 text.Remove(text.Last('.')+2);
1034
1035 if (text!=oldtxt)
1036 {
1037 fUtc->SetText(new TGString(text));
1038 oldtxt = text;
1039 }
1040
1041 static ULong_t oldmjd=0;
1042 const double mjd = time.GetMjd();
1043
1044 if (oldmjd != (ULong_t)(1000000*mjd))
1045 {
1046 fMjd->SetText(new TGString(MString::Format("%12.6f", mjd)));
1047 oldmjd = (ULong_t)(1000000*mjd);
1048 }
1049
1050 return mjd;
1051}
1052
1053void MGCosy::Update(ZdAz pos, ZdAz acc, /*ZdAz vel, ZdAz off,*/ RaDec radec,
1054 ZdAz soll, UInt_t stat, UInt_t pdo3, UInt_t stat2, Bool_t armed, const TString &statzd, const TString &stataz)
1055{
1056 // acc [rad]
1057 acc *= kRad2Deg; // [deg]
1058
1059 const double mjd = UpdateTime();
1060 fSkyPosition->Update(pos, mjd);
1061 //UpdateOffset(off);
1062 UpdateRaDec(pos, mjd, radec);
1063 UpdateZdAz(soll);
1064
1065 EnableLabel(fError, stat&MDriveCom::kError);
1066 EnableLabel(fMoving, stat&MDriveCom::kMoving);
1067 EnableLabel(fTracking, stat&MDriveCom::kTracking);
1068 EnableLabel(fStopping, stat&MDriveCom::kStopping);
1069 EnableLabel(fStopped, stat&MDriveCom::kStopped);
1070 EnableLabel(fRaSoll, stat&MDriveCom::kTracking);
1071 EnableLabel(fDecSoll, stat&MDriveCom::kTracking);
1072 EnableLabel(fZdSoll, stat&MDriveCom::kMoving);
1073 EnableLabel(fAzSoll, stat&MDriveCom::kMoving);
1074
1075 SetLabelColor(fAvailTcp, stat2);
1076
1077 if (!stat2)
1078 pdo3 = 0;
1079
1080 SetLabelColor(fDkcReady1, pdo3&0x0001);
1081 SetLabelColor(fDkcReady2, pdo3&0x0100);
1082 SetLabelColor(fDkcEmergency, (pdo3&0x0404)==0x0404);
1083 SetLabelColor(fDkcPcMode, (pdo3&0x1010)!=0x1010 && pdo3);
1084 SetLabelColor(fDkcRF1, pdo3&0x0020);
1085 SetLabelColor(fDkcRF2, pdo3&0x2000);
1086 SetLabelColor(fDkcBrake, (pdo3&0x4040)==0x4040);
1087 SetLabelColor(fDkcPower, (pdo3&0x8080)==0x8080);
1088
1089 EnableLabel(fArmed, armed);
1090
1091 fMsgZd->SetText(new TGString(TString(" Zd: ")+statzd));
1092 fMsgAz->SetText(new TGString(TString(" Az: ")+stataz));
1093
1094
1095 if (stat&MDriveCom::kTracking)
1096 {
1097 fAccuracy->Update(pos, acc);
1098 // fAccuracyTime->Update(pos, acc);
1099 // fVelocity->Update(vel);
1100 fAccuracy->MapWindow();
1101 // fAccuracyTime->MapWindow();
1102 // fVelocity->MapWindow();
1103 }
1104 else
1105 {
1106 fAccuracy->UnmapWindow();
1107 // fAccuracyTime->UnmapWindow();
1108 // fVelocity->UnmapWindow();
1109 }
1110 // stat&kTracking ? fOffset->MapWindow() : fOffset->UnmapWindow();
1111
1112 //unsigned char empty[(768/2-1)*(576/2-1)];
1113 //fImage->DrawImg(empty);
1114 //fImage->DoRedraw();
1115
1116 // if (IsMapped())
1117 // fImage->DoRedraw();
1118}
1119
1120void MGCosy::UpdateWeather(const MCeCoCom &com)
1121{
1122 ULong_t color;
1123 switch (com.GetWeatherStatus())
1124 {
1125 case 0:
1126 color=TGFrame::GetDefaultFrameBackground();
1127 break;
1128 case 1:
1129 gClient->GetColorByName("Yellow", color);
1130 break;
1131 case 2:
1132 gClient->GetColorByName("Orange", color);
1133 break;
1134 default:
1135 gClient->GetColorByName("Red", color);
1136 break;
1137 }
1138
1139 if (com.HasAlarm())
1140 {
1141 static int i=0;
1142 if ((i++/4)%2==0)
1143 color = TGFrame::GetDefaultFrameBackground();
1144 }
1145
1146 const TString old(fWeather->GetText()->GetString());
1147 const TString txt(com.GetWeather());
1148
1149 // Color is only updated if the text has changed
1150 if (old!=txt || color!=fWeather->GetBackground())
1151 fWeather->SetText(txt);
1152
1153 if (color!=fWeather->GetBackground())
1154 fWeather->SetBackgroundColor(color);
1155}
1156
1157void MGCosy::CloseWindow()
1158{
1159 // Got close message for this MainFrame. Calls parent CloseWindow()
1160 // (which destroys the window) and terminate the application.
1161 // The close message is generated by the window manager when its close
1162 // window menu item is selected.
1163
1164 // gSystem->ExitLoop();
1165 // gSystem->DispatchOneEvent(kTRUE);
1166
1167 // TGMainFrame::CloseWindow();
1168 cout << "Closing window - waiting until all nodes are stopped." << endl;
1169 fQueue->PostMsg(WM_QUIT);
1170 cout << "Closing window - done." << endl;
1171 // gApplication->Terminate(0);
1172}
1173
1174void MGCosy::StartTrack(bool track)
1175{
1176 cout << "Start tracking." << endl;
1177
1178 XY xy0 = fCRaDec->GetCoordinates();
1179 XY xy1 = track ? xy0 : fCCalib->GetCoordinates();
1180
1181 RaDec dest0(xy0.X()*15., xy0.Y()); // xy.X() [h]->[ø]
1182 RaDec dest1(xy1.X()*15., xy1.Y()); // xy.X() [h]->[ø]
1183
1184 cout << "TrackPos: " << dest0.Ra() << "\xb0 " << dest0.Dec() << "\xb0" << endl;
1185 cout << "CalibPos: " << dest1.Ra() << "\xb0 " << dest1.Dec() << "\xb0" << endl;
1186
1187 RaDec dest[2] = { dest0, dest1 };
1188
1189 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1190
1191 cout << "PostMsg (WM_Track) returned." << endl;
1192}
1193
1194void MGCosy::StartTrackPos(Long_t mp1)
1195{
1196 cout << "Start tracking Zd/Az pos." << endl;
1197
1198 const XY &xy = fCZdAz->GetCoordinates();
1199
1200 ZdAz za(xy.X(), xy.Y());
1201
1202 switch (mp1)
1203 {
1204 case kPB_ZDm:
1205 za.Zd(za.Zd()-360/16384.);
1206 break;
1207 case kPB_ZDp:
1208 za.Zd(za.Zd()+360/16384.);
1209 break;
1210 case kPB_AZm:
1211 za.Az(za.Az()-360/16384.);
1212 break;
1213 case kPB_AZp:
1214 za.Az(za.Az()+360/16384.);
1215 break;
1216 }
1217
1218 cout << za.Zd() << "\xb0 " << za.Az() << "\xb0" << endl;
1219
1220 fQueue->PostMsg(WM_TRACKPOS, &za, sizeof(za));
1221
1222 cout << "PostMsg (WM_TrackPos) returned." << endl;
1223}
1224
1225void MGCosy::StartPos()
1226{
1227 cout << "Start positioning." << endl;
1228
1229 XY xy = fCZdAz->GetCoordinates();
1230 ZdAz dest(xy.X(), xy.Y());
1231
1232 cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
1233
1234 fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
1235
1236 cout << "PostMsg (WM_Position) returned." << endl;
1237}
1238
1239//
1240// ************************** For demo purpose **********************
1241//
1242#ifdef HAS_DEMO
1243
1244#include <TRandom.h>
1245class MDemo : public MThread
1246{
1247private:
1248 MsgQueue *fQueue;
1249 TRandom fRand;
1250
1251public:
1252 MDemo() : MThread(false) {}
1253
1254 void SetQueue(MsgQueue *q) { fQueue = q; }
1255
1256 bool Wait(int s, int m)
1257 {
1258 int i = 0;
1259 while (!HasStopFlag() && i++<m)
1260 usleep(s);
1261 if (HasStopFlag())
1262 return false;
1263 return true;
1264 }
1265
1266 bool Move(float zd, float az, int s, int m)
1267 {
1268 ZdAz dest1(zd, az);
1269 fQueue->PostMsg(WM_POSITION1, &dest1, sizeof(dest1));
1270 return Wait(s, m); // 30s?
1271 }
1272
1273 virtual void *Thread()
1274 {
1275 if (!Move(90, -65, 1000000, 27))
1276 return NULL;
1277
1278 Int_t i=1;
1279 while (i-->0)
1280 {
1281 //Timer tm;
1282 //tm.Now();
1283
1284 if (!Move(75, -80, 1000000, 13))
1285 break;
1286 if (!Move(60, -65, 1000000, 13))
1287 break;
1288 if (!Move(75, -50, 1000000, 13))
1289 break;
1290 if (!Move(90, -65, 1000000, 13))
1291 break;
1292 }
1293 if (!Move(60, -65, 1000000, 17))
1294 return NULL;
1295 if (!Move(90, -65, 1000000, 19))
1296 return NULL;
1297 if (!Move(90, -10, 1000000, 28))
1298 return NULL;
1299
1300 cout << "Demo Thread: done." << endl;
1301 return NULL;
1302 }
1303};
1304
1305MDemo demo;
1306
1307void MGCosy::StartDemo()
1308{
1309 cout << "Start Demo." << endl;
1310
1311 demo.SetQueue(fQueue);
1312 demo.Start();
1313
1314 cout << "PostMsg (WM_Demo) returned." << endl;
1315}
1316
1317void StopDemo()
1318{
1319 cout << "Stopping demo." << endl;
1320 demo.Stop();
1321}
1322#endif //HAS_DEMO
1323
1324/*
1325void MGCosy::StartCalib()
1326{
1327 cout << "Start Calibration." << endl;
1328
1329 XY xy = fCCalib->GetCoordinates();
1330 RaDec pos(xy.X()*360/24, xy.Y());
1331
1332 fQueue->PostMsg(WM_CALIB, &pos, sizeof(pos));
1333
1334 cout << "PostMsg (WM_Calib) returned." << endl;
1335}
1336*/
1337void MGCosy::StartTPoint()
1338{
1339 cout << "Start writing tpoint pair." << endl;
1340
1341 XY xy = fCCalib->GetCoordinates();
1342 RaDec pos(xy.X()*360/24, xy.Y());
1343
1344 //fQueue->PostMsg(WM_TPOINT, &pos, sizeof(pos));
1345 fQueue->Proc(WM_TPOINT, &pos);
1346
1347 cout << "PostMsg (WM_TPoint) returned." << endl;
1348}
1349//
1350// ******************************************************************
1351//
1352
1353Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1354{
1355 //
1356 // This processing is serialized!
1357 //
1358 switch (GET_MSG(msg))
1359 {
1360 case kC_COMMAND:
1361 switch (GET_SUBMSG(msg))
1362 {
1363 case kCM_COMBOBOX:
1364 switch (mp1)
1365 {
1366 case kCB_PredefPos:
1367 {
1368 MStar *pos = fPreDefList[mp2];
1369 if (pos)
1370 fCZdAz->SetCoordinates(ZdAz(pos->GetX(), pos->GetY()));
1371 return kTRUE;
1372 }
1373 case kCB_StarList:
1374 {
1375 MStar *pos = fStarList[mp2];
1376 if (pos)
1377 fCCalib->SetCoordinates(RaDec(pos->GetX(), pos->GetY()));
1378 return kTRUE;
1379 }
1380 }
1381 return kTRUE;
1382
1383 case kCM_TAB:
1384 //cout << "Tab: " << mp1 << endl;
1385 return kTRUE;
1386
1387 case kCM_BUTTON:
1388
1389 switch (mp1)
1390 {
1391 /*
1392 case kPB_POSITION:
1393 Start(0);
1394 return kTRUE;
1395
1396 case kPB_TRACK:
1397 Start(1);
1398 return kTRUE;
1399 */
1400 case kPB_START:
1401 switch (fTab->GetCurrent())
1402 {
1403 case 0:
1404 StartPos();
1405 return kTRUE;
1406 case 1:
1407 StartTrack(true);
1408 return kTRUE;
1409 case 2:
1410 fCRaDec->SetCoordinates(fCCalib->GetCoordinates());
1411 StartTrack(false);
1412 return kTRUE;
1413 case 3:
1414 fQueue->Proc(WM_TESTSE, (void*)1);
1415 return kTRUE;
1416 case 4:
1417 fQueue->Proc(WM_GEAR, (void*)1);
1418 return kTRUE;
1419#ifdef HAS_DEMO
1420 case 5:
1421 StartDemo();
1422 return kTRUE;
1423#endif
1424 }
1425 return kTRUE;
1426
1427 case kPB_STOP:
1428 cout << "Sending stop movement msg." << endl;
1429#ifdef HAS_DEMO
1430 StopDemo();
1431#endif
1432 fQueue->PostMsg(WM_STOP);
1433 if (fTab->GetCurrent()==3)
1434 fQueue->Proc(WM_TESTSE);
1435 if (fTab->GetCurrent()==4)
1436 fQueue->Proc(WM_GEAR);
1437 cout << "PostMsg (WM_Stop) returned." << endl;
1438 return kTRUE;
1439
1440 case kPB_CALCALTAZ:
1441 {
1442 XY xy = fCRaDec->GetCoordinates();
1443 fQueue->Proc(WM_CALCALTAZ, &xy);
1444 }
1445 return kTRUE;
1446
1447 case kPB_SavePreDef:
1448 {
1449 ofstream fout("prepos.txt", ios::app);
1450 XY za = fCZdAz->GetCoordinates();
1451 fout << setprecision(7) << za.X() << " \t" << za.Y();
1452 fout << " New Position" << endl;
1453 }
1454 return kTRUE;
1455 case kPB_SaveStar:
1456 {
1457 ofstream fout("stars.txt", ios::app);
1458 XY za = fCCalib->GetCoordinates();
1459
1460 UShort_t d, m, s;
1461 Char_t sgn;
1462 MAstro::Deg2Dms(za.X(), sgn, d, m, s);
1463 if (sgn=='-') fout << sgn;
1464 fout << d << " " << m << " " << s << " \t";
1465 MAstro::Deg2Dms(za.Y(), sgn, d, m, s);
1466 if (sgn=='-') fout << sgn;
1467 fout << d << " " << m << " " << s << " \t";
1468 fout << " New Star/Source" << endl;
1469 }
1470 return kTRUE;
1471
1472 case kPB_RAp:
1473 case kPB_RAm:
1474 case kPB_DECp:
1475 case kPB_DECm:
1476 {
1477 XY xy = fCRaDec->GetCoordinates();
1478 switch (mp1)
1479 {
1480 case kPB_RAp:
1481 xy.Set(xy.X()+1./60, xy.Y());
1482 break;
1483 case kPB_RAm:
1484 xy.Set(xy.X()-1./60, xy.Y());
1485 break;
1486 case kPB_DECp:
1487 xy.Set(xy.X(), xy.Y()+1./60);
1488 break;
1489 case kPB_DECm:
1490 xy.Set(xy.X(), xy.Y()-1./60);
1491 break;
1492 }
1493 fCRaDec->SetCoordinates(xy);
1494 StartTrack(false);
1495 /*
1496 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
1497 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
1498 //fQueue->Proc(WM_NEWTRACK, &dest);
1499 */
1500 //cout << "New Ra/Dec: " << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
1501 }
1502 return kTRUE;
1503
1504 case kPB_ZDp:
1505 case kPB_ZDm:
1506 case kPB_AZp:
1507 case kPB_AZm:
1508 StartTrackPos(mp1);
1509 return kTRUE;
1510
1511 case kPB_TPOINT:
1512 StartTPoint();
1513 return kTRUE;
1514
1515 case kPB_ENDSWITCH:
1516 fQueue->Proc(WM_ENDSWITCH);
1517 return kTRUE;
1518 /*
1519 case kPB_CALIBSE:
1520 StartCalib();
1521 return kTRUE;
1522 */
1523 case kPB_LoadBending:
1524 fQueue->Proc(WM_LOADBENDING);
1525 return kTRUE;
1526 case kPB_ResetBending:
1527 fQueue->Proc(WM_RESETBENDING);
1528 return kTRUE;
1529 /*
1530 case kPB_HOME:
1531 fQueue->PostMsg(WM_HOME, 0, 0);
1532 return kTRUE;
1533 */
1534 case kPB_TRACKPOS:
1535 StartTrackPos();
1536 return kTRUE;
1537 case kPB_ARM:
1538 fQueue->PostMsg(WM_ARM);
1539 return kTRUE;
1540 case kPB_DISPLAY1:
1541 case kPB_DISPLAY2:
1542 fQueue->PostMsg(WM_DISPLAY);
1543 return kTRUE;
1544
1545 default:
1546 return kTRUE;
1547 }
1548 return kTRUE;
1549
1550 case kCM_MENU:
1551
1552 switch (mp1)
1553 {
1554 case IDM_EXIT:
1555 cout << "IDM_EXIT: Posting WM_QUIT." << endl;
1556 fQueue->PostMsg(WM_QUIT);
1557 cout << "IDM_EXIT: WM_QUIT done." << endl;
1558 //cout << "Idm_Exit." << endl;
1559 //CloseWindow();
1560 return kTRUE;
1561 case IDM_ASPECT:
1562 {
1563 Int_t w = GetWidth();
1564 Int_t h = GetHeight();
1565 if (w>940*h/660)
1566 w = 940*h/660;
1567 else
1568 h = 660*w/940;
1569 Resize(w, h);
1570 }
1571 return kTRUE;
1572 case kLogClear:
1573 fLog->Clear();
1574 return kTRUE;
1575 case kLogCopy:
1576 fLog->Copy();
1577 return kTRUE;
1578 case kLogSelect:
1579 fLog->SelectAll();
1580 return kTRUE;
1581 case kLogSearch:
1582 //virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
1583 return kTRUE;
1584 case kLogSave:
1585 cout << "Saving log... " << flush;
1586 if (fLog->GetText()->Save("cosylog.txt"))
1587 cout << "done." << endl;
1588 else
1589 cout << "failed!" << endl;
1590 return kTRUE;
1591
1592 case kLogAppend:
1593 cout << "Appending log... " << flush;
1594 if (fLog->GetText()->Append("cosylog.txt"))
1595 cout << "done." << endl;
1596 else
1597 cout << "failed!" << endl;
1598 return kTRUE;
1599 }
1600 return kTRUE;
1601 }
1602 }
1603
1604 //
1605 // Start a thread to process the message.
1606 //
1607 // fQueue->PostMsg(msg, mp1, mp2);
1608 return kTRUE;
1609
1610}
Note: See TracBrowser for help on using the repository browser.