| 1 | #include "MGCosy.h"
|
|---|
| 2 |
|
|---|
| 3 | #include "msgqueue.h"
|
|---|
| 4 |
|
|---|
| 5 | #include <TROOT.h>
|
|---|
| 6 |
|
|---|
| 7 | #include <TGMenu.h> // TGPopupMenu
|
|---|
| 8 | #include <TGButton.h> // TGButton
|
|---|
| 9 | #include <TSystem.h> // gSystem
|
|---|
| 10 | #include <TGLabel.h> // TGLabel
|
|---|
| 11 | #include <TGSplitter.h> // TGHorizontal3DLine
|
|---|
| 12 |
|
|---|
| 13 | #include "timer.h" // Timer
|
|---|
| 14 |
|
|---|
| 15 | #include "MCosy.h"
|
|---|
| 16 | #include "MGList.h"
|
|---|
| 17 | #include "MGCoordinates.h"
|
|---|
| 18 |
|
|---|
| 19 | #include "Slalib.h"
|
|---|
| 20 |
|
|---|
| 21 | #define IDM_EXIT 1
|
|---|
| 22 | #define IDM_TEXT 2
|
|---|
| 23 |
|
|---|
| 24 | #define kPB_POSITION 0x1001
|
|---|
| 25 | #define kPB_TRACK 0x1002
|
|---|
| 26 | #define kPB_STOP 0x1003
|
|---|
| 27 | #define kPB_CALCALTAZ 0x1004
|
|---|
| 28 | #define kPB_POLARIS 0x1005
|
|---|
| 29 |
|
|---|
| 30 | #define kEF_A 0x1010
|
|---|
| 31 | #define kEF_B 0x1011
|
|---|
| 32 |
|
|---|
| 33 | void MGCosy::CreateMenu()
|
|---|
| 34 | {
|
|---|
| 35 | fLayMenuBar = new TGLayoutHints (kLHintsNormal | kLHintsExpandX);
|
|---|
| 36 | fLayMenuItem = new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0);
|
|---|
| 37 |
|
|---|
| 38 | //
|
|---|
| 39 | // crate the menu bar
|
|---|
| 40 | //
|
|---|
| 41 | TGPopupMenu *fFileMenu = new TGPopupMenu(fClient->GetRoot());
|
|---|
| 42 | fFileMenu->AddEntry ("Exit", IDM_EXIT) ;
|
|---|
| 43 | fFileMenu->Associate(this);
|
|---|
| 44 | fList->Add(fFileMenu);
|
|---|
| 45 |
|
|---|
| 46 | //
|
|---|
| 47 | // the button messages are handled by main frame (this)
|
|---|
| 48 | //
|
|---|
| 49 | TGMenuBar *fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
|
|---|
| 50 | fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem);
|
|---|
| 51 | AddFrame(fMenuBar);
|
|---|
| 52 | fList->Add(fMenuBar);
|
|---|
| 53 |
|
|---|
| 54 | //
|
|---|
| 55 | // Seperator beyonf menubar
|
|---|
| 56 | //
|
|---|
| 57 | TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
|
|---|
| 58 | AddFrame(fLineSep, fLayMenuBar);
|
|---|
| 59 | fList->Add(fLineSep);
|
|---|
| 60 |
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void MGCosy::CreateLabel()
|
|---|
| 64 | {
|
|---|
| 65 | fLabel1 = new TGLabel*[3];
|
|---|
| 66 | fLabel1[0] = new TGLabel(this, "00000"); // Max: 16384
|
|---|
| 67 | fLabel1[0]->SetTextJustify(kTextRight);
|
|---|
| 68 | fLabel1[0]->Move(5, 40);
|
|---|
| 69 | fList->Add(fLabel1[0]);
|
|---|
| 70 | // AddFrame(fLabel1[0], new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
|
|---|
| 71 | fLabel1[1] = new TGLabel(this, "000"); // Max: 256
|
|---|
| 72 | fLabel1[1]->SetTextJustify(kTextRight);
|
|---|
| 73 | fLabel1[1]->Move(48, 40);
|
|---|
| 74 | fList->Add(fLabel1[1]);
|
|---|
| 75 | // AddFrame(fLabel1[1], new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
|
|---|
| 76 | fLabel1[2] = new TGLabel(this, "000"); // Max: 256
|
|---|
| 77 | fLabel1[2]->SetTextJustify(kTextRight);
|
|---|
| 78 | fLabel1[2]->Move(75, 40);
|
|---|
| 79 | fList->Add(fLabel1[2]);
|
|---|
| 80 | // AddFrame(fLabel1[2], new TGLayoutHints(kLHintsNormal, 9, 9, 9, 9));
|
|---|
| 81 |
|
|---|
| 82 | fLabel2 = new TGLabel*[3];
|
|---|
| 83 | fLabel2[0] = new TGLabel(this, "00000");
|
|---|
| 84 | fLabel2[0]->SetTextJustify(kTextRight);
|
|---|
| 85 | fLabel2[0]->Move(5, 60);
|
|---|
| 86 | fList->Add(fLabel2[0]);
|
|---|
| 87 | // AddFrame(fLabel2[0], new TGLayoutHints); //(kLHintsNormal, 0, 0, 0, 0));
|
|---|
| 88 | fLabel2[1] = new TGLabel(this, "000");
|
|---|
| 89 | fLabel2[1]->SetTextJustify(kTextRight);
|
|---|
| 90 | fLabel2[1]->Move(48, 60);
|
|---|
| 91 | fList->Add(fLabel2[1]);
|
|---|
| 92 | // AddFrame(fLabel2[1], new TGLayoutHints); //(kLHintsNormal, 1, 0, 0, 0));
|
|---|
| 93 | fLabel2[2] = new TGLabel(this, "000");
|
|---|
| 94 | fLabel2[2]->SetTextJustify(kTextRight);
|
|---|
| 95 | fLabel2[2]->Move(75, 60);
|
|---|
| 96 | fList->Add(fLabel2[2]);
|
|---|
| 97 | // AddFrame(fLabel2[2], new TGLayoutHints); //(kLHintsNormal, 2, 0, 0, 0));
|
|---|
| 98 |
|
|---|
| 99 | fLabel3 = new TGLabel*[3];
|
|---|
| 100 | fLabel3[0] = new TGLabel(this, "00000");
|
|---|
| 101 | fLabel3[0]->SetTextJustify(kTextRight);
|
|---|
| 102 | fLabel3[0]->Move(5, 80);
|
|---|
| 103 | fList->Add(fLabel3[0]);
|
|---|
| 104 | // AddFrame(fLabel3[0]); //, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
|
|---|
| 105 | fLabel3[1] = new TGLabel(this, "000");
|
|---|
| 106 | fLabel3[1]->SetTextJustify(kTextRight);
|
|---|
| 107 | fLabel3[1]->Move(48, 80);
|
|---|
| 108 | fList->Add(fLabel3[1]);
|
|---|
| 109 | // AddFrame(fLabel3[1]); //, new TGLayoutHints(kLHintsNormal, 1, 0, 0, 0));
|
|---|
| 110 | fLabel3[2] = new TGLabel(this, "000");
|
|---|
| 111 | fLabel3[2]->SetTextJustify(kTextRight);
|
|---|
| 112 | fLabel3[2]->Move(75, 80);
|
|---|
| 113 | fList->Add(fLabel3[2]);
|
|---|
| 114 | // AddFrame(fLabel3[2]); //, new TGLayoutHints(kLHintsNormal, 2, 0, 0, 0));
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | void MGCosy::CreateButton()
|
|---|
| 118 | {
|
|---|
| 119 | TGTextButton *fButton1 = new TGTextButton(this, "Position Zd/Az", kPB_POSITION);
|
|---|
| 120 | TGTextButton *fButton2 = new TGTextButton(this, "Track Ra/Dec", kPB_TRACK);
|
|---|
| 121 | TGTextButton *fButton3 = new TGTextButton(this, "Stop", kPB_STOP);
|
|---|
| 122 | TGTextButton *fButton4 = new TGTextButton(this, "Calc Zd/Az", kPB_CALCALTAZ);
|
|---|
| 123 | TGTextButton *fButton5 = new TGTextButton(this, "Set Polaris", kPB_POLARIS);
|
|---|
| 124 | fButton1->Move(110, 40);
|
|---|
| 125 | fButton2->Move(110, 65);
|
|---|
| 126 | fButton3->Move(260, 90);
|
|---|
| 127 | fButton4->Move(110, 90);
|
|---|
| 128 | fButton5->Move(110, 115);
|
|---|
| 129 | fButton1->SetToolTipText("Move Telescope to Zd/Az position.");
|
|---|
| 130 | fButton2->SetToolTipText("Track the coordinates given in Ra/Dec.");
|
|---|
| 131 | fButton3->SetToolTipText("Stop movement of telescope.");
|
|---|
| 132 | fButton4->SetToolTipText("Calculate Zd/Az corresponding to Ra/Dec.");
|
|---|
| 133 | fButton5->SetToolTipText("Set the actual position as the position of Polaris.");
|
|---|
| 134 | fList->Add(fButton1);
|
|---|
| 135 | fList->Add(fButton2);
|
|---|
| 136 | fList->Add(fButton3);
|
|---|
| 137 | fList->Add(fButton4);
|
|---|
| 138 | fList->Add(fButton5);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | MGCosy::MGCosy(MsgQueue *q, const TGWindow *p, UInt_t w, UInt_t h)
|
|---|
| 142 | : TGMainFrame(p, w, h), fQueue(q)
|
|---|
| 143 | {
|
|---|
| 144 | fList = new MGList;
|
|---|
| 145 |
|
|---|
| 146 | CreateMenu();
|
|---|
| 147 | CreateLabel();
|
|---|
| 148 | CreateButton();
|
|---|
| 149 |
|
|---|
| 150 | fCoord = new MGCoordinates(this, kTRUE,
|
|---|
| 151 | "Coordinate 1 [\xb0]:", "Coordinate 2 [\xb0]:");
|
|---|
| 152 | fCoord->Move(10, 160);
|
|---|
| 153 | fList->Add(fCoord);
|
|---|
| 154 |
|
|---|
| 155 | //
|
|---|
| 156 | // Map the window, set up the layout, etc.
|
|---|
| 157 | //
|
|---|
| 158 | SetWMSizeHints(350, 250, 350, 250, 10, 10 ) ; // set the smallest and biggest size of the Main frame
|
|---|
| 159 |
|
|---|
| 160 | MapSubwindows();
|
|---|
| 161 | Layout();
|
|---|
| 162 |
|
|---|
| 163 | SetWindowName("Cosy Main Window");
|
|---|
| 164 | SetIconName("Cosy");
|
|---|
| 165 |
|
|---|
| 166 | MapWindow();
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 | // ======================================================================
|
|---|
| 172 |
|
|---|
| 173 | MGCosy::~MGCosy()
|
|---|
| 174 | {
|
|---|
| 175 | delete fLayMenuBar;
|
|---|
| 176 | delete fLayMenuItem;
|
|---|
| 177 |
|
|---|
| 178 | fList->Delete();
|
|---|
| 179 | delete fList;
|
|---|
| 180 | }
|
|---|
| 181 | // ======================================================================
|
|---|
| 182 |
|
|---|
| 183 | void MGCosy::CloseWindow()
|
|---|
| 184 | {
|
|---|
| 185 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
|---|
| 186 | // (which destroys the window) and terminate the application.
|
|---|
| 187 | // The close message is generated by the window manager when its close
|
|---|
| 188 | // window menu item is selected.
|
|---|
| 189 |
|
|---|
| 190 | gSystem->ExitLoop();
|
|---|
| 191 | // gSystem->DispatchOneEvent(kTRUE);
|
|---|
| 192 |
|
|---|
| 193 | // TGMainFrame::CloseWindow();
|
|---|
| 194 | // gROOT->GetApplication()->Terminate(0);
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | #include <iostream.h>
|
|---|
| 198 |
|
|---|
| 199 | Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
|
|---|
| 200 | {
|
|---|
| 201 | //
|
|---|
| 202 | // This processing is serialized!
|
|---|
| 203 | //
|
|---|
| 204 | switch (GET_MSG(msg))
|
|---|
| 205 | {
|
|---|
| 206 | case kC_COMMAND:
|
|---|
| 207 | switch (GET_SUBMSG(msg))
|
|---|
| 208 | {
|
|---|
| 209 | case kCM_BUTTON:
|
|---|
| 210 |
|
|---|
| 211 | switch (mp1)
|
|---|
| 212 | {
|
|---|
| 213 | case kPB_POSITION:
|
|---|
| 214 | cout << "Start positioning." << endl;
|
|---|
| 215 | {
|
|---|
| 216 | XY xy = fCoord->GetCoordinates();
|
|---|
| 217 | ZdAz dest(xy.X(), xy.Y());
|
|---|
| 218 | cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
|
|---|
| 219 | fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
|
|---|
| 220 | }
|
|---|
| 221 | cout << "PostMsg(WM_POSITION) returned." << endl;
|
|---|
| 222 | return kTRUE;
|
|---|
| 223 |
|
|---|
| 224 | case kPB_TRACK:
|
|---|
| 225 | cout << "Start tracking." << endl;
|
|---|
| 226 | {
|
|---|
| 227 | XY xy = fCoord->GetCoordinates();
|
|---|
| 228 | RaDec dest(xy.X(), xy.Y());
|
|---|
| 229 | cout << dest.Ra() << kDEG << " " << dest.Dec() << kDEG << endl;
|
|---|
| 230 | fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
|
|---|
| 231 | }
|
|---|
| 232 | cout << "PostMsg(WM_TRACK) returned." << endl;
|
|---|
| 233 | return kTRUE;
|
|---|
| 234 |
|
|---|
| 235 | case kPB_STOP:
|
|---|
| 236 | cout << "Sending stop movement msg." << endl;
|
|---|
| 237 | fQueue->PostMsg(WM_STOP, 0, 0);
|
|---|
| 238 | cout << "PostMsg(WM_STOP) returned." << endl;
|
|---|
| 239 | return kTRUE;
|
|---|
| 240 |
|
|---|
| 241 | case kPB_CALCALTAZ:
|
|---|
| 242 | {
|
|---|
| 243 | Timer t;
|
|---|
| 244 | t.GetTime();
|
|---|
| 245 |
|
|---|
| 246 | Slalib sla;
|
|---|
| 247 | sla.Set(t.GetMjd());
|
|---|
| 248 |
|
|---|
| 249 | XY xy = fCoord->GetCoordinates();
|
|---|
| 250 | RaDec rd(xy.X(), xy.Y());
|
|---|
| 251 |
|
|---|
| 252 | cout << "Ra/Dec: " << rd.Ra() << kDEG << " " << rd.Dec() << kDEG << endl;
|
|---|
| 253 | ZdAz aa=sla.CalcZdAz(rd*D2PI/360.0)*360.0/D2PI;
|
|---|
| 254 | cout << "Zd/Az: " << aa.Zd() << kDEG << " " << aa.Az() << kDEG << endl;
|
|---|
| 255 | }
|
|---|
| 256 | return kTRUE;
|
|---|
| 257 |
|
|---|
| 258 | case kPB_POLARIS:
|
|---|
| 259 | fQueue->PostMsg(WM_POLARIS, 0, 0);
|
|---|
| 260 | return kTRUE;
|
|---|
| 261 |
|
|---|
| 262 | default:
|
|---|
| 263 | return kTRUE;
|
|---|
| 264 | }
|
|---|
| 265 | break;
|
|---|
| 266 |
|
|---|
| 267 | case kCM_MENU:
|
|---|
| 268 |
|
|---|
| 269 | switch (mp1)
|
|---|
| 270 | {
|
|---|
| 271 | case IDM_EXIT:
|
|---|
| 272 | CloseWindow();
|
|---|
| 273 | return kTRUE;
|
|---|
| 274 |
|
|---|
| 275 | default:
|
|---|
| 276 | return kTRUE;
|
|---|
| 277 | }
|
|---|
| 278 | return kTRUE;
|
|---|
| 279 |
|
|---|
| 280 | default:
|
|---|
| 281 | return kTRUE;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | default:
|
|---|
| 285 | return kTRUE;
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | //
|
|---|
| 289 | // Start a thread to process the message.
|
|---|
| 290 | //
|
|---|
| 291 | // fQueue->PostMsg(msg, mp1, mp2);
|
|---|
| 292 | return kTRUE;
|
|---|
| 293 |
|
|---|
| 294 | }
|
|---|