| 1 | //
|
|---|
| 2 | // This File contains the definition of the MGCoordinates-class
|
|---|
| 3 | //
|
|---|
| 4 | // Author: Thomas Bretz
|
|---|
| 5 | // Version: V1.0 (1-8-2000)
|
|---|
| 6 |
|
|---|
| 7 | #include "MGSkyPosition.h"
|
|---|
| 8 |
|
|---|
| 9 | #include <iostream.h> // cout
|
|---|
| 10 |
|
|---|
| 11 | #include <TArc.h>
|
|---|
| 12 | #include <TLine.h>
|
|---|
| 13 | #include <TText.h>
|
|---|
| 14 | #include <TList.h>
|
|---|
| 15 | #include <TCanvas.h>
|
|---|
| 16 |
|
|---|
| 17 | #include "coord.h"
|
|---|
| 18 | #include "SlaPlanets.h"
|
|---|
| 19 |
|
|---|
| 20 | ClassImp(MGSkyPosition);
|
|---|
| 21 |
|
|---|
| 22 | void MGSkyPosition::InitPlanets()
|
|---|
| 23 | {
|
|---|
| 24 | //
|
|---|
| 25 | // Magnitudes:
|
|---|
| 26 | // -----------
|
|---|
| 27 | // Moon -12.8
|
|---|
| 28 | // Jupiter -4.6
|
|---|
| 29 | // Venus -4.0
|
|---|
| 30 | // Mars -2.0
|
|---|
| 31 | // Merkur 0.0
|
|---|
| 32 | // Saturn 0.7
|
|---|
| 33 | // Uranus 5.5
|
|---|
| 34 | // Neptun 7.8
|
|---|
| 35 | //
|
|---|
| 36 | fSlalib = new SlaPlanets;
|
|---|
| 37 |
|
|---|
| 38 | //
|
|---|
| 39 | // Colors: black .. white:
|
|---|
| 40 | //
|
|---|
| 41 | // 1, 12, 13, 14, 15, 16, 17, 18, 19, 10
|
|---|
| 42 | //
|
|---|
| 43 | fMars = new TArc(0, 0, 1);
|
|---|
| 44 | fMars->SetFillStyle(1001); // solid (s. TAttFill)
|
|---|
| 45 | fMars->SetFillColor(13); // light grey (s. TAttFill)
|
|---|
| 46 | fMars->SetLineColor(12);
|
|---|
| 47 | fMars->Draw();
|
|---|
| 48 |
|
|---|
| 49 | fVenus = new TArc(0, 0, 2);
|
|---|
| 50 | fVenus->SetFillStyle(1001); // solid (s. TAttFill)
|
|---|
| 51 | fVenus->SetFillColor(15); // light grey (s. TAttFill)
|
|---|
| 52 | fVenus->SetLineColor(14);
|
|---|
| 53 | fVenus->Draw();
|
|---|
| 54 |
|
|---|
| 55 | fJupiter = new TArc(0, 0, 2);
|
|---|
| 56 | fJupiter->SetFillStyle(1001); // solid (s. TAttFill)
|
|---|
| 57 | fJupiter->SetFillColor(17); // light grey (s. TAttFill)
|
|---|
| 58 | fJupiter->SetLineColor(16);
|
|---|
| 59 | fJupiter->Draw();
|
|---|
| 60 |
|
|---|
| 61 | fMoon = new TArc(0, 0, 3, 290, 70);
|
|---|
| 62 | fMoon->SetFillStyle(1001); // solid (s. TAttFill)
|
|---|
| 63 | fMoon->SetFillColor(19); // light grey (s. TAttFill)
|
|---|
| 64 | fMoon->SetLineColor(15);
|
|---|
| 65 | fMoon->Draw();
|
|---|
| 66 |
|
|---|
| 67 | for (int i=0; i<4; i++)
|
|---|
| 68 | {
|
|---|
| 69 | fSunL[i] = new TLine(0,0,0,0);
|
|---|
| 70 | fSunL[i]->SetLineColor(10); // white gray
|
|---|
| 71 | fSunL[i]->SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 72 | fSunL[i]->Draw();
|
|---|
| 73 |
|
|---|
| 74 | fList->Add(fSunL[i]);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | fSun = new TArc(0, 0, 2);
|
|---|
| 78 | fSun->SetFillStyle(1001); // solid (s. TAttFill)
|
|---|
| 79 | fSun->SetFillColor(10); // white (s. TAttFill)
|
|---|
| 80 | fSun->SetLineColor(19);
|
|---|
| 81 | fSun->Draw();
|
|---|
| 82 |
|
|---|
| 83 | fList->Add(fMars);
|
|---|
| 84 | fList->Add(fVenus);
|
|---|
| 85 | fList->Add(fJupiter);
|
|---|
| 86 | fList->Add(fMoon);
|
|---|
| 87 | fList->Add(fSun);
|
|---|
| 88 |
|
|---|
| 89 | //
|
|---|
| 90 | // Reset 'static' positions of planets
|
|---|
| 91 | //
|
|---|
| 92 | for (int i=0; i<9; i++)
|
|---|
| 93 | {
|
|---|
| 94 | fX[i] = ~0;
|
|---|
| 95 | fY[i] = ~0;
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | void MGSkyPosition::InitText()
|
|---|
| 100 | {
|
|---|
| 101 | fText = new TText(105, 105, "");
|
|---|
| 102 | //fText->SetFillStyle(4000); // transparent
|
|---|
| 103 | fText->SetTextAlign(33); // right, top
|
|---|
| 104 | fText->SetTextColor(10); // white
|
|---|
| 105 | fText->Draw();
|
|---|
| 106 |
|
|---|
| 107 | fList->Add(fText);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | void MGSkyPosition::DrawCoordinateSystem()
|
|---|
| 111 | {
|
|---|
| 112 | TArc arc;
|
|---|
| 113 | arc.SetFillStyle(4000); // transparent
|
|---|
| 114 | arc.SetLineColor(13); // dark gray
|
|---|
| 115 | arc.SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 116 | arc.DrawArc(0, 0, 90);
|
|---|
| 117 | arc.DrawArc(0, 0, 67.5);
|
|---|
| 118 | arc.DrawArc(0, 0, 45);
|
|---|
| 119 | arc.DrawArc(0, 0, 22.5);
|
|---|
| 120 |
|
|---|
| 121 | //
|
|---|
| 122 | // FIXME? Use TAxis?
|
|---|
| 123 | //
|
|---|
| 124 | TLine line;
|
|---|
| 125 | line.SetLineColor(1); // black
|
|---|
| 126 | line.SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 127 | line.DrawLine(-95, 0, 95, 0);
|
|---|
| 128 | line.DrawLine( 0, -95, 0, 95);
|
|---|
| 129 |
|
|---|
| 130 | TText text;
|
|---|
| 131 | text.SetTextAlign(22); // centered, centered (s.TAttText)
|
|---|
| 132 | text.SetTextColor(13); // dark gray
|
|---|
| 133 | text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0");
|
|---|
| 134 | text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0");
|
|---|
| 135 | text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0");
|
|---|
| 136 | text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0");
|
|---|
| 137 |
|
|---|
| 138 | text.SetTextAlign(22); // centered, centered (s.TAttText)
|
|---|
| 139 | text.SetTextColor(1); // black
|
|---|
| 140 |
|
|---|
| 141 | text.DrawText(0, 102, "N (0\xb0)");
|
|---|
| 142 | text.DrawText(0, -102, "S (180\xb0)");
|
|---|
| 143 |
|
|---|
| 144 | text.SetTextAngle(270);
|
|---|
| 145 | text.DrawText( 102, 0, "E (90\xb0)");
|
|---|
| 146 |
|
|---|
| 147 | text.SetTextAngle(90);
|
|---|
| 148 | text.DrawText(-102, 0, "W (270\xb0)");
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | void MGSkyPosition::InitPosition()
|
|---|
| 152 | {
|
|---|
| 153 | fLin1a = new TLine(0, 0, 0, 0);
|
|---|
| 154 | fLin1b = new TLine(0, 0, 0, 0);
|
|---|
| 155 | fLin2 = new TLine(0, 0, 0, 0);
|
|---|
| 156 |
|
|---|
| 157 | fLin1a->SetLineColor(5); // yellow (s. TAttFill)
|
|---|
| 158 | fLin1b->SetLineColor(5); // yellow
|
|---|
| 159 | fLin2 ->SetLineColor(10); // white
|
|---|
| 160 | fLin1a->SetLineStyle(1); // solid (s. TAttLine)
|
|---|
| 161 | fLin1b->SetLineStyle(2); // dashed
|
|---|
| 162 |
|
|---|
| 163 | fLin1a->Draw();
|
|---|
| 164 | fLin1b->Draw();
|
|---|
| 165 | fLin2->Draw();
|
|---|
| 166 |
|
|---|
| 167 | fList->Add(fLin1a);
|
|---|
| 168 | fList->Add(fLin1b);
|
|---|
| 169 | fList->Add(fLin2);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | MGSkyPosition::MGSkyPosition(const TGWindow* p, const UInt_t w)
|
|---|
| 173 | : MGEmbeddedCanvas("SkyPosition", p, w, 110)
|
|---|
| 174 | {
|
|---|
| 175 | DrawCoordinateSystem();
|
|---|
| 176 | InitPlanets();
|
|---|
| 177 | InitPosition();
|
|---|
| 178 | InitText();
|
|---|
| 179 | InitCanvas();
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | MGSkyPosition::~MGSkyPosition()
|
|---|
| 183 | {
|
|---|
| 184 | delete fSlalib;
|
|---|
| 185 |
|
|---|
| 186 | cout << "MGSkyPosition destroyed." << endl;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | void MGSkyPosition::SetLin1(Float_t x, Float_t y)
|
|---|
| 190 | {
|
|---|
| 191 | fLin1a->SetX2(x);
|
|---|
| 192 | fLin1a->SetY2(y);
|
|---|
| 193 | fLin1b->SetX2(-x);
|
|---|
| 194 | fLin1b->SetY2(-y);
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
|
|---|
| 198 | {
|
|---|
| 199 | fLin2->SetX1(x1);
|
|---|
| 200 | fLin2->SetX2(x2);
|
|---|
| 201 | fLin2->SetY1(y1);
|
|---|
| 202 | fLin2->SetY2(y2);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | void MGSkyPosition::UpdatePosition(Float_t zd, Float_t az)
|
|---|
| 206 | {
|
|---|
| 207 | static int X =~0;
|
|---|
| 208 | static int Y =~0;
|
|---|
| 209 | static int Rx=~0;
|
|---|
| 210 | static int Ry=~0;
|
|---|
| 211 |
|
|---|
| 212 | const float rad = az*kDeg2Rad;
|
|---|
| 213 |
|
|---|
| 214 | const float s = sin(rad);
|
|---|
| 215 | const float c = cos(rad);
|
|---|
| 216 |
|
|---|
| 217 | const float x = s*zd;
|
|---|
| 218 | const float y = c*zd;
|
|---|
| 219 |
|
|---|
| 220 | const int pixx = (int)(x/fPix);
|
|---|
| 221 | const int pixy = (int)(y/fPix);
|
|---|
| 222 |
|
|---|
| 223 | const int rx = (int)(s*fWidth/2.);
|
|---|
| 224 | const int ry = (int)(c*fWidth/2.);
|
|---|
| 225 |
|
|---|
| 226 | if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
|
|---|
| 227 | return;
|
|---|
| 228 |
|
|---|
| 229 | X = pixx;
|
|---|
| 230 | Y = pixy;
|
|---|
| 231 |
|
|---|
| 232 | Rx = rx;
|
|---|
| 233 | Ry = ry;
|
|---|
| 234 |
|
|---|
| 235 | const float dx = s*4.;
|
|---|
| 236 | const float dy = c*4.;
|
|---|
| 237 |
|
|---|
| 238 | SetLin1(s*95., c*95.);
|
|---|
| 239 | SetLin2(x+dy, y-dx, x-dy, y+dx);
|
|---|
| 240 |
|
|---|
| 241 | SetModified();
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | void MGSkyPosition::UpdateText(Float_t x, Float_t y)
|
|---|
| 245 | {
|
|---|
| 246 | static int X = ~0;
|
|---|
| 247 | static int Y = ~0;
|
|---|
| 248 |
|
|---|
| 249 | int xd = (int)floor(x);
|
|---|
| 250 | int yd = (int)floor(y);
|
|---|
| 251 | x *= 60.;
|
|---|
| 252 | y *= 60.;
|
|---|
| 253 |
|
|---|
| 254 | int fx = (int)floor(x*10.);
|
|---|
| 255 | int fy = (int)floor(y*10.);
|
|---|
| 256 |
|
|---|
| 257 | if (X==fx && Y==fy)
|
|---|
| 258 | return;
|
|---|
| 259 |
|
|---|
| 260 | X = fx;
|
|---|
| 261 | Y = fy;
|
|---|
| 262 |
|
|---|
| 263 | float xm = fmod(fabs(x), 60.);
|
|---|
| 264 | float ym = fmod(fabs(y), 60.);
|
|---|
| 265 |
|
|---|
| 266 | char txt[100];
|
|---|
| 267 | sprintf(txt, "Zd=%d\xb0%02.1f'\nAz=%d\xb0%02.1f'",
|
|---|
| 268 | xd, xm, yd, ym);
|
|---|
| 269 |
|
|---|
| 270 | fText->SetText(fText->GetX(), fText->GetY(), txt);
|
|---|
| 271 |
|
|---|
| 272 | SetModified();
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | void MGSkyPosition::Update(ZdAz &pos)
|
|---|
| 277 | {
|
|---|
| 278 | //
|
|---|
| 279 | // calculate actual time for planet positions
|
|---|
| 280 | //
|
|---|
| 281 | fSlalib->SetMjd2Now();
|
|---|
| 282 |
|
|---|
| 283 | UpdatePlanet(kESun, fSun);
|
|---|
| 284 | UpdatePlanet(kEMoon, fMoon);
|
|---|
| 285 | UpdatePlanet(kEJupiter, fJupiter);
|
|---|
| 286 | UpdatePlanet(kEVenus, fVenus);
|
|---|
| 287 | UpdatePlanet(kEMars, fMars);
|
|---|
| 288 |
|
|---|
| 289 | UpdatePosition(pos.Zd(), pos.Az());
|
|---|
| 290 | UpdateText(pos.Zd(), pos.Az());
|
|---|
| 291 |
|
|---|
| 292 | UpdateCanvas();
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
|
|---|
| 296 | {
|
|---|
| 297 | //
|
|---|
| 298 | // calculate actual position of planet
|
|---|
| 299 | //
|
|---|
| 300 | fSlalib->UpdatePlanetPos((ePlanets_t)planet);
|
|---|
| 301 |
|
|---|
| 302 | ZdAz zdaz = fSlalib->GetPlanetPos((ePlanets_t)planet);
|
|---|
| 303 |
|
|---|
| 304 | //
|
|---|
| 305 | // check whether we have to change the position where it is drawn
|
|---|
| 306 | //
|
|---|
| 307 | const float s = sin(zdaz.Az());
|
|---|
| 308 | const float c = cos(zdaz.Az());
|
|---|
| 309 |
|
|---|
| 310 | const float deg = zdaz.Zd()*kRad2Deg;
|
|---|
| 311 |
|
|---|
| 312 | const float x = s*deg;
|
|---|
| 313 | const float y = c*deg;
|
|---|
| 314 |
|
|---|
| 315 | const int pixx = (int)(x/fPix);
|
|---|
| 316 | const int pixy = (int)(y/fPix);
|
|---|
| 317 |
|
|---|
| 318 | if (fX[planet]==pixx && fY[planet]==pixy)
|
|---|
| 319 | return;
|
|---|
| 320 |
|
|---|
| 321 | fX[planet] = pixx;
|
|---|
| 322 | fY[planet] = pixy;
|
|---|
| 323 |
|
|---|
| 324 | //
|
|---|
| 325 | // Set new position
|
|---|
| 326 | //
|
|---|
| 327 | arc->SetX1(x);
|
|---|
| 328 | arc->SetY1(y);
|
|---|
| 329 |
|
|---|
| 330 | SetModified();
|
|---|
| 331 |
|
|---|
| 332 | if (planet!=kESun)
|
|---|
| 333 | return;
|
|---|
| 334 |
|
|---|
| 335 | // cout << "Sun: x=" << x << " y=" << y;
|
|---|
| 336 | // cout << " Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
|
|---|
| 337 |
|
|---|
| 338 | fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
|
|---|
| 339 | fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
|
|---|
| 340 | fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
|
|---|
| 341 | fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
|
|---|
| 342 |
|
|---|
| 343 | fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
|
|---|
| 344 | fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
|
|---|
| 345 | fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
|
|---|
| 346 | fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
|
|---|
| 347 | }
|
|---|