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