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

Last change on this file since 1194 was 1111, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 14.6 KB
Line 
1#include "MGCosy.h"
2
3#include <iostream.h>
4
5#include "msgqueue.h"
6#include "coord.h"
7
8#include <TROOT.h>
9
10#include <TGTab.h> // TGTab
11#include <TGMenu.h> // TGPopupMenu
12#include <TGButton.h> // TGButton
13#include <TSystem.h> // gSystem
14#include <TGLabel.h> // TGLabel
15#include <TGListBox.h> // TGListBox
16#include <TG3DLine.h> // TGHorizontal3DLine (TGSplitter)
17#include <TGFrame.h> // TGGroupFrame
18#include <TApplication.h> // gApplication
19
20//#include "timer.h" // Timer
21
22#include "MCosy.h"
23#include "MGList.h"
24#include "MGAccuracy.h"
25#include "MGCoordinates.h"
26#include "MGSkyPosition.h"
27#include "MGVelocity.h"
28
29#include "SlaStars.h"
30
31ClassImp(MGCosy);
32
33#define IDM_EXIT 1
34#define IDM_TEXT 2
35
36#define kPB_POSITION 0x1001
37#define kPB_TRACK 0x1002
38#define kPB_STOP 0x1003
39#define kPB_CALCALTAZ 0x1004
40#define kPB_POLARIS 0x1005
41#define kPB_START 0x1006
42
43#define kEF_A 0x1010
44#define kEF_B 0x1011
45
46void MGCosy::CreateMenu()
47{
48 fLayMenuBar = new TGLayoutHints (kLHintsNormal | kLHintsExpandX);
49 fLayMenuItem = new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0);
50
51 //
52 // crate the menu bar
53 //
54 TGPopupMenu *fFileMenu = new TGPopupMenu(gClient->GetRoot());
55 fFileMenu->AddEntry("Exit", IDM_EXIT);
56 fFileMenu->Associate(this);
57 fList->Add(fFileMenu);
58
59 //
60 // the button messages are handled by main frame (this)
61 //
62 TGMenuBar *fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
63 fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem);
64 AddFrame(fMenuBar, fLayMenuBar);
65 fList->Add(fMenuBar);
66
67 //
68 // Seperator beyond menubar
69 //
70
71 TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
72 AddFrame(fLineSep, fLayMenuBar);
73 fList->Add(fLineSep);
74}
75
76void MGCosy::CreateLabel(TGCompositeFrame *f)
77{
78 const int x = 180;
79 const int y = 25;
80
81 TGLabel *l;
82
83 l = new TGLabel(f, "SE-Az:");
84 l->Move(x-60, y);
85 fList->Add(l);
86
87 l = new TGLabel(f, "SE-Zd1:");
88 l->Move(x-60, y+20);
89 fList->Add(l);
90
91 l = new TGLabel(f, "SE-Zd2:");
92 l->Move(x-60, y+40);
93 fList->Add(l);
94
95
96 fLabel1 = new TGLabel*[3];
97 fLabel1[0] = new TGLabel(f, "00000"); // Max: 16384
98 fLabel1[1] = new TGLabel(f, "000"); // Max: 256
99 fLabel1[2] = new TGLabel(f, "000"); // Max: 256
100 fLabel1[0]->SetTextJustify(kTextRight);
101 fLabel1[1]->SetTextJustify(kTextRight);
102 fLabel1[2]->SetTextJustify(kTextRight);
103 fLabel1[0]->Move(x, y);
104 fLabel1[1]->Move(x+43, y);
105 fLabel1[2]->Move(x+70, y);
106 fList->Add(fLabel1[0]);
107 fList->Add(fLabel1[1]);
108 fList->Add(fLabel1[2]);
109 //f->AddFrame(fLabel1[0]);
110 //f->AddFrame(fLabel1[1]);
111 //f->AddFrame(fLabel1[2]);
112
113 fLabel2 = new TGLabel*[3];
114 fLabel2[0] = new TGLabel(f, "00000");
115 fLabel2[1] = new TGLabel(f, "000");
116 fLabel2[2] = new TGLabel(f, "000");
117 fLabel2[0]->SetTextJustify(kTextRight);
118 fLabel2[1]->SetTextJustify(kTextRight);
119 fLabel2[2]->SetTextJustify(kTextRight);
120 fLabel2[0]->Move(x, y+20);
121 fLabel2[1]->Move(x+43, y+20);
122 fLabel2[2]->Move(x+70, y+20);
123 fList->Add(fLabel2[0]);
124 fList->Add(fLabel2[1]);
125 fList->Add(fLabel2[2]);
126 //f->AddFrame(fLabel2[0]);
127 //f->AddFrame(fLabel2[1]);
128 //f->AddFrame(fLabel2[2]);
129
130 fLabel3 = new TGLabel*[3];
131 fLabel3[0] = new TGLabel(f, "00000");
132 fLabel3[1] = new TGLabel(f, "000");
133 fLabel3[2] = new TGLabel(f, "000");
134 fLabel3[0]->SetTextJustify(kTextRight);
135 fLabel3[1]->SetTextJustify(kTextRight);
136 fLabel3[2]->SetTextJustify(kTextRight);
137 fLabel3[0]->Move(x, y+40);
138 fLabel3[1]->Move(x+43, y+40);
139 fLabel3[2]->Move(x+70, y+40);
140 fList->Add(fLabel3[0]);
141 fList->Add(fLabel3[1]);
142 fList->Add(fLabel3[2]);
143 //f->AddFrame(fLabel3[0]);
144 //f->AddFrame(fLabel3[1]);
145 //f->AddFrame(fLabel3[2]);
146
147 l = new TGLabel(f, "Offset-Zd:");
148 l->Move(x-60, y+80);
149 fList->Add(l);
150
151 l = new TGLabel(f, "Offset-Az:");
152 l->Move(x-60, y+100);
153 fList->Add(l);
154
155 fOffsetZd = new TGLabel(f, "0000000");
156 fOffsetAz = new TGLabel(f, "0000000");
157 fOffsetZd->SetTextJustify(kTextRight);
158 fOffsetAz->SetTextJustify(kTextRight);
159 fOffsetZd->Move(x, y+80);
160 fOffsetAz->Move(x, y+100);
161 fList->Add(fOffsetZd);
162 fList->Add(fOffsetAz);
163
164
165 fError = new TGLabel(f, "Error");
166 fMoving = new TGLabel(f, "Moving");
167 fTracking = new TGLabel(f, "Tracking");
168 fStopping = new TGLabel(f, "Stopping");
169 fStopped = new TGLabel(f, "Stopped");
170
171 fError ->SetBackgroundColor(224); // red
172 fMoving ->SetBackgroundColor(10); // blue
173 fTracking->SetBackgroundColor(47); // blue
174 fStopping->SetBackgroundColor(164); // orange
175 fStopped ->SetBackgroundColor(20); // green
176
177 fError ->Move(10, 25);
178 fMoving ->Move(10, 25+20);
179 fTracking->Move(10, 25+40);
180 fStopping->Move(10, 25+60);
181 fStopped ->Move(10, 25+80);
182
183 fError ->Resize(60, 20);
184 fMoving ->Resize(60, 20);
185 fTracking->Resize(60, 20);
186 fStopping->Resize(60, 20);
187 fStopped ->Resize(60, 20);
188
189 fList->Add(fError);
190 fList->Add(fMoving);
191 fList->Add(fTracking);
192 fList->Add(fStopping);
193 fList->Add(fStopped);
194}
195
196void MGCosy::CreateTabs(TGTab *fTab)
197{
198 TGCompositeFrame *tf1 = fTab->AddTab("Position Zd/Az");
199 TGCompositeFrame *tf2 = fTab->AddTab("Track Ra/Dec");
200
201 fCZdAz = new MGCoordinates(tf1, kETypeZdAz);
202 fCZdAz->Move(27, 105);
203 fList->Add(fCZdAz);
204
205 fCRaDec = new MGCoordinates(tf2, kETypeRaDec);
206 fCRaDec->Move(27, 105);
207 fList->Add(fCRaDec);
208
209
210 const int x=15;
211 const int y=12;
212 const int h=16;
213
214 TGLabel *l1 = new TGLabel(tf1, "Move the telescope to a position given in");
215 TGLabel *l2 = new TGLabel(tf1, "local coordinates. The given coordinates");
216 TGLabel *l3 = new TGLabel(tf1, "are pointing coordinates, which means that the");
217 TGLabel *l4 = new TGLabel(tf1, "coordinates are corrected for the bending of");
218 TGLabel *l5 = new TGLabel(tf1, "the telescope.");
219 l1->Move(x, y);
220 l2->Move(x, y+h);
221 l3->Move(x, y+2*h);
222 l4->Move(x, y+3*h);
223 l5->Move(x, y+4*h);
224 fList->Add(l1);
225 fList->Add(l2);
226 fList->Add(l3);
227 fList->Add(l4);
228 fList->Add(l5);
229
230 l1 = new TGLabel(tf2, "Track a position given in sky coordinates.");
231 l2 = new TGLabel(tf2, "Right Ascension and declination must be given");
232 l3 = new TGLabel(tf2, "in the FK5, J2000 coordinate system");
233 l1->Move(x, y);
234 l2->Move(x, y+h);
235 l3->Move(x, y+2*h);
236 fList->Add(l1);
237 fList->Add(l2);
238 fList->Add(l3);
239
240 //
241 // light green: 3 light red: 2 blue?: 2
242 // dark green: 8 dark red: 50 dark blue?: 1
243
244 //
245 // blue: 0-7, 9, 10,11, 14, 15, 18, 19, 22, 23, 27, 31, 33-39, 41-43
246 // 46, 47
247 // green: 8, 12,13, 16, 17, 20, 21, 24, 25, 26, 28, 29, 30, 40, 44
248 // 45, 48
249 // gray: 31, 113-
250 // red: 164, 192, 224, 232
251 //
252 TGTextButton *but;
253
254 but= new TGTextButton(this, "Calc Zd/Az", kPB_CALCALTAZ);
255 but->Resize(80, 25);
256 but->Move(37, 257);
257 but->SetToolTipText("Calculate Zd/Az corresponding to Ra/Dec.");
258 fList->Add(but);
259
260 but = new TGTextButton(this, "Set Polaris", kPB_POLARIS);
261 but->Resize(80, 25);
262 but->Move(37, 288);
263 but->SetToolTipText("Set the actual position as the position of Polaris.");
264 fList->Add(but);
265
266 but = new TGTextButton(this, "Start", kPB_START);
267 but->SetBackgroundColor(20);
268 but->Move(147, 275);
269 but->Resize(62, 25);
270 but->SetToolTipText("Start a telescope movement.");
271 fList->Add(but);
272
273 but = new TGTextButton(this, "Stop", kPB_STOP);
274 but->SetBackgroundColor(224);
275 but->Move(212, 275);
276 but->Resize(62, 25);
277 but->SetToolTipText("Stop any movement of telescope.");
278 fList->Add(but);
279
280}
281
282MGCosy::MGCosy(MsgQueue *q, const TGWindow *p, UInt_t w, UInt_t h)
283 : TGMainFrame(p, w, h), fQueue(q)
284{
285 fList = new MGList;
286
287 CreateMenu();
288
289 TGCompositeFrame *f = new TGCompositeFrame(this, 0, 0);
290 f->SetLayoutManager(new TGMatrixLayout(f, 3, 2, 10));
291 fList->Add(f);
292
293 fTab = new TGTab(f, 300, 300);
294 fList->Add(fTab);
295
296 fSkyPosition = new MGSkyPosition(f, 300);
297 fAccuracy = new MGAccuracy (f, 300);
298 fVelocity = new MGVelocity (f, "Velocity [\"/min]", 300);
299// fOffset = new MGVelocity (f, "Offset se-re [']", 300);
300
301 fList->Add(fSkyPosition);
302 fList->Add(fAccuracy);
303 fList->Add(fVelocity);
304// fList->Add(fOffset);
305
306 TGGroupFrame *frame = new TGGroupFrame(f, "Status");
307 frame->Resize(300, 300);
308 fList->Add(frame);
309
310 fLog = new TGListBox(f, -1, kSunkenFrame); //kSunkenFrame|kDoubleBorder,
311 fLog->Resize(300, 300);
312 fLog->ChangeBackground(TGFrame::GetBlackPixel());
313 fList->Add(fLog);
314
315 //
316 // Layout the window, tile by tile...
317 //
318 f->AddFrame(fTab);
319 f->AddFrame(fSkyPosition);
320 f->AddFrame(fAccuracy);
321 f->AddFrame(frame);
322 f->AddFrame(fVelocity);
323 f->AddFrame(fLog);
324
325 AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 1, 0));
326
327 //
328 // FIXME!
329 //
330 CreateTabs(fTab);
331 CreateLabel(frame);
332
333 //
334 // Map the window, set up the layout, etc.
335 //
336 const Int_t w = 940;
337 const Int_t h = 660;
338 SetWMSizeHints(w, h, w, h, 10, 10); // set the smallest and biggest size of the Main frame
339
340 SetWindowName("Cosy Main Window");
341 SetIconName("Cosy");
342
343 MapSubwindows();
344 Resize(GetDefaultSize());
345 MapWindow();
346}
347
348// ======================================================================
349
350MGCosy::~MGCosy()
351{
352 cout << "MGCosy::~MGCosy called." << endl;
353
354 delete fLayMenuBar;
355 delete fLayMenuItem;
356
357 cout << "Deleting MGCosy::fList" << endl;
358
359 delete fList;
360
361 cout << "MGCosy::~MGCosy done." << endl;
362}
363// ======================================================================
364void MGCosy::EnableLabel(TGLabel *label, Bool_t stat)
365{
366 stat ? label->MapWindow() : label->UnmapWindow();
367
368 /*
369 TGGC *fRedTextGC(TGButton::GetDefaultGC())
370 // Set foreground color in graphics context for drawing of
371 // TGlabel and TGButtons with text in red.
372 ULong_t red;
373 gClient->GetColorByName("red", red);
374 fRedTextGC.SetForeground(red);
375 */
376}
377
378void MGCosy::UpdateOffset(ZdAz &off)
379{
380 static Int_t zd=~0;
381 static Int_t az=~0;
382
383 char text[21];
384
385 if (zd!=(Int_t)off.Zd())
386 {
387 zd = (Int_t)off.Zd();
388 sprintf(text, "%d", zd);
389 fOffsetZd->SetText(new TGString(text));
390 }
391 if (az!=(Int_t)off.Az())
392 {
393 az = (Int_t)off.Az();
394 sprintf(text, "%d", az);
395 fOffsetAz->SetText(new TGString(text));
396 }
397}
398
399void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off, UInt_t stat)
400{
401 fSkyPosition->Update(pos);
402 fAccuracy->Update(pos, acc);
403 fVelocity->Update(vel);
404 UpdateOffset(off);
405
406#define kError 0x01
407#define kMoving 0x02
408#define kTracking 0x04
409#define kStopping 0x08
410#define kStopped 0x10
411
412 EnableLabel(fError, stat&kError);
413 EnableLabel(fMoving, stat&kMoving);
414 EnableLabel(fTracking, stat&kTracking);
415 EnableLabel(fStopping, stat&kStopping);
416 EnableLabel(fStopped, stat&kStopped);
417
418 stat&kTracking ? fAccuracy->MapWindow() : fAccuracy->UnmapWindow();
419 stat&kTracking ? fVelocity->MapWindow() : fVelocity->UnmapWindow();
420 // stat&kTracking ? fOffset->MapWindow() : fOffset->UnmapWindow();
421
422 if (!fLog->TestBit(kHasChanged))
423 return;
424
425 fLog->MapSubwindows();
426 fLog->Layout();
427 fLog->ResetBit(kHasChanged);
428}
429// ======================================================================
430
431void MGCosy::CloseWindow()
432{
433 // Got close message for this MainFrame. Calls parent CloseWindow()
434 // (which destroys the window) and terminate the application.
435 // The close message is generated by the window manager when its close
436 // window menu item is selected.
437
438 // gSystem->ExitLoop();
439 // gSystem->DispatchOneEvent(kTRUE);
440
441 // TGMainFrame::CloseWindow();
442 cout << "Closing window - waiting until all nodes are stopped." << endl;
443 fQueue->PostMsg(WM_QUIT, 0, 0);
444 // gApplication->Terminate(0);
445}
446
447void MGCosy::StartTrack()
448{
449 cout << "Start tracking." << endl;
450
451 XY xy = fCRaDec->GetCoordinates();
452 RaDec dest(xy.X()*15., xy.Y()); // xy.X() [h]->[ø]
453
454 cout << dest.Ra() << "h " << dest.Dec() << "\xb0" << endl;
455
456 fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
457
458 cout << "PostMsg (WM_Track) returned." << endl;
459}
460
461void MGCosy::StartPos()
462{
463 cout << "Start positioning." << endl;
464
465 XY xy = fCZdAz->GetCoordinates();
466 ZdAz dest(xy.X(), xy.Y());
467
468 cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
469
470 fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
471
472 cout << "PostMsg (WM_Position) returned." << endl;
473}
474
475Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
476{
477 //
478 // This processing is serialized!
479 //
480 switch (GET_MSG(msg))
481 {
482 case kC_COMMAND:
483 switch (GET_SUBMSG(msg))
484 {
485 case kCM_TAB:
486 //cout << "Tab: " << mp1 << endl;
487 return kTRUE;
488
489 case kCM_BUTTON:
490
491 switch (mp1)
492 {
493 /*
494 case kPB_POSITION:
495 Start(0);
496 return kTRUE;
497
498 case kPB_TRACK:
499 Start(1);
500 return kTRUE;
501 */
502 case kPB_START:
503 fTab->GetCurrent() ? StartTrack() : StartPos();
504 return kTRUE;
505
506 case kPB_STOP:
507 cout << "Sending stop movement msg." << endl;
508 fQueue->PostMsg(WM_STOP, 0, 0);
509 cout << "PostMsg (WM_Stop) returned." << endl;
510 return kTRUE;
511
512 case kPB_CALCALTAZ:
513 {
514 SlaStars sla;
515 sla.SetMjd2Now();
516
517 XY xy = fCRaDec->GetCoordinates();
518 RaDec rd(xy.X()*15., xy.Y());
519
520 cout << "Ra/Dec: " << rd.Ra() << kDEG << " " << rd.Dec() << kDEG << endl;
521 ZdAz aa=sla.CalcZdAz(rd*kDeg2Rad)*kRad2Deg;
522 cout << "Zd/Az: " << aa.Zd() << kDEG << " " << aa.Az() << kDEG << endl;
523 }
524 return kTRUE;
525
526 case kPB_POLARIS:
527 fQueue->PostMsg(WM_POLARIS, 0, 0);
528 return kTRUE;
529
530 default:
531 return kTRUE;
532 }
533 return kTRUE;
534
535 case kCM_MENU:
536
537 switch (mp1)
538 {
539 case IDM_EXIT:
540 fQueue->PostMsg(WM_QUIT, 0, 0);
541 //cout << "Idm_Exit." << endl;
542 //CloseWindow();
543 return kTRUE;
544 }
545 return kTRUE;
546 }
547 }
548
549 //
550 // Start a thread to process the message.
551 //
552 // fQueue->PostMsg(msg, mp1, mp2);
553 return kTRUE;
554
555}
Note: See TracBrowser for help on using the repository browser.