source: trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc@ 2628

Last change on this file since 2628 was 2615, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 11.1 KB
Line 
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 "MAstro.h"
19#include "SlaStars.h"
20#include "SlaPlanets.h"
21
22ClassImp(MGSkyPosition);
23
24void MGSkyPosition::InitArc(TArc *arc, Int_t fillstyle, Int_t fillcolor, Int_t linecolor)
25{
26 arc->SetFillStyle(fillstyle); // (s. TAttFill)
27 arc->SetFillColor(fillcolor); // (s. TAttFill)
28 arc->SetLineColor(linecolor);
29 arc->Draw();
30}
31
32void MGSkyPosition::InitPlanets()
33{
34 //
35 // Magnitudes:
36 // -----------
37 // Moon -12.8
38 // Jupiter -4.6
39 // Venus -4.0
40 // Mars -2.0
41 // Merkur 0.0
42 // Saturn 0.7
43 // Uranus 5.5
44 // Neptun 7.8
45 //
46 fSlaPlanet = new SlaPlanets(fObservatory);
47 fSlaStar = new SlaStars(fObservatory);
48
49 //
50 // Colors: black .. white:
51 //
52 // 1, 12, 13, 14, 15, 16, 17, 18, 19, 10
53 //
54 fMars = new TArc(0, 0, 1);
55 fVenus = new TArc(0, 0, 2);
56 fJupiter = new TArc(0, 0, 2);
57 fMoon = new TArc(0, 0, 3, 290, 70);
58 fSun = new TArc(0, 0, 2);
59 fSaturn = new TArc(0, 0, 1);
60
61 fSaturnRing = new TArc(0, 0, 2);
62 fSaturnRing->SetFillStyle(4000); // (s. TAttFill)
63 fSaturnRing->SetLineColor(kRed);
64 fSaturnRing->Draw();
65
66 InitArc(fMars, 1001, kRed/*13*/, kRed/*12*/);
67 InitArc(fVenus, 1001, 15, 14);
68 InitArc(fJupiter, 1001, 17, 16);
69 InitArc(fMoon, 1001, 19, 15);
70 InitArc(fSaturn, 1001, kYellow/*17*/, 16);
71
72 for (int i=0; i<14; i++)
73 {
74 fStars[i] = new TArc(0, 0, 1);
75 InitArc(fStars[i], 1001, 17, 15);
76 fList->Add(fStars[i]);
77 }
78
79 for (int i=0; i<4; i++)
80 {
81 fSunL[i] = new TLine(0,0,0,0);
82 fSunL[i]->SetLineColor(10); // white gray
83 fSunL[i]->SetLineStyle(1); // solid (s. TAttLine)
84 fSunL[i]->Draw();
85
86 fList->Add(fSunL[i]);
87 }
88 InitArc(fSun, 1001, kYellow/*10*/, kYellow/*19*/);
89
90 fList->Add(fMars);
91 fList->Add(fVenus);
92 fList->Add(fJupiter);
93 fList->Add(fMoon);
94 fList->Add(fSun);
95 fList->Add(fSaturn);
96
97 //
98 // Reset 'static' positions of planets
99 //
100 /*
101 for (int i=0; i<9; i++)
102 {
103 fPlanetX[i] = ~0;
104 fPlanetY[i] = ~0;
105 }
106 for (int i=0; i<13; i++)
107 {
108 fStarX[i] = ~0;
109 fStarY[i] = ~0;
110 }*/
111}
112
113static const RaDec stars[14] =
114{
115 // 32349 Sirius -1.44 1.45 2.64 0.009 A0m
116 (RaDec(MAstro::Hms2Rad( 6, 45, 0), MAstro::Dms2Rad(-16, 42, 0))),
117 // 30438 Canopus -0.62 -5.53 95.88 0.164 F0Ib
118 (RaDec(MAstro::Hms2Rad( 6, 23, 0), MAstro::Dms2Rad(-52, 41, 0))),
119 // 69673 Arcturus -0.05 -0.31 11.25 1.239 K2IIIp
120 (RaDec(MAstro::Hms2Rad( 14, 15, 0), MAstro::Dms2Rad( 19, 10, 0))),
121 // Vega 0.03
122 (RaDec(MAstro::Hms2Rad( 18, 37, 0), MAstro::Dms2Rad( 38, 47, 0))),
123 // Altair 0.77
124 (RaDec(MAstro::Hms2Rad( 19, 50, 0), MAstro::Dms2Rad( 8, 52, 6))),
125 // Antares 0.96
126 (RaDec(MAstro::Hms2Rad( 16, 29, 25), MAstro::Dms2Rad(-26, 25, 55))),
127 // Spica 0.98
128 (RaDec(MAstro::Hms2Rad( 13, 25, 13), MAstro::Dms2Rad(-11, 9, 41))),
129 // Deneb 1.25
130 (RaDec(MAstro::Hms2Rad( 20, 41, 26), MAstro::Dms2Rad( 45, 16, 49))),
131 (RaDec(MAstro::Hms2Rad( 1, 37, 6), MAstro::Dms2Rad(-57, 14, 0))),
132 (RaDec(MAstro::Hms2Rad( 12, 26, 6), MAstro::Dms2Rad(-63, 06, 0))),
133 (RaDec(MAstro::Hms2Rad( 5, 14, 0), MAstro::Dms2Rad(- 8, 12, 5))),
134 (RaDec(MAstro::Hms2Rad( 5, 16, 0), MAstro::Dms2Rad( 46, 00, 0))),
135 (RaDec(MAstro::Hms2Rad( 7, 39, 0), MAstro::Dms2Rad( 5, 14, 0))),
136 (RaDec(MAstro::Hms2Rad( 5, 55, 0), MAstro::Dms2Rad( 7, 24, 0)))
137};
138
139void MGSkyPosition::UpdateStars()
140{
141 for (int i=0; i<14; i++)
142 SetDot(fStars[i], stars[i], 0);
143}
144
145void MGSkyPosition::InitText()
146{
147 fText1 = new TText(-105, 105, "");
148 fText2 = new TText(105, 105, "");
149
150 fText1->SetTextAlign(13); // left, top
151 fText2->SetTextAlign(33); // right, top
152
153 fText1->SetTextColor(10); // white
154 fText2->SetTextColor(10); // white
155
156 fText1->Draw();
157 fText2->Draw();
158
159 fList->Add(fText1);
160 fList->Add(fText2);
161}
162
163void MGSkyPosition::DrawCoordinateSystem()
164{
165 TArc arc;
166 arc.SetFillStyle(4000); // transparent
167 arc.SetLineColor(13); // dark gray
168 arc.SetLineStyle(1); // solid (s. TAttLine)
169 arc.DrawArc(0, 0, 90);
170 arc.DrawArc(0, 0, 67.5);
171 arc.DrawArc(0, 0, 45);
172 arc.DrawArc(0, 0, 22.5);
173
174 //
175 // FIXME? Use TAxis?
176 //
177 TLine line;
178 line.SetLineColor(1); // black
179 line.SetLineStyle(1); // solid (s. TAttLine)
180 line.DrawLine(-95, 0, 95, 0);
181 line.DrawLine( 0, -95, 0, 95);
182
183 TText text;
184 text.SetTextAlign(22); // centered, centered (s.TAttText)
185 text.SetTextColor(13); // dark gray
186 text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0");
187 text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0");
188 text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0");
189 text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0");
190
191 text.SetTextAlign(22); // centered, centered (s.TAttText)
192 text.SetTextColor(1); // black
193
194 text.DrawText(0, 102, "N (0\xb0)");
195 text.DrawText(0, -102, "S (180\xb0)");
196
197 text.SetTextAngle(270);
198 text.DrawText( 102, 0, "E (90\xb0)");
199
200 text.SetTextAngle(90);
201 text.DrawText(-102, 0, "W (270\xb0)");
202}
203
204void MGSkyPosition::InitPosition()
205{
206 fLin1a = new TLine(0, 0, 0, 0);
207 fLin1b = new TLine(0, 0, 0, 0);
208 fLin2 = new TLine(0, 0, 0, 0);
209
210 fLin1a->SetLineColor(5); // yellow (s. TAttFill)
211 fLin1b->SetLineColor(5); // yellow
212 fLin2 ->SetLineColor(10); // white
213 fLin1a->SetLineStyle(1); // solid (s. TAttLine)
214 fLin1b->SetLineStyle(2); // dashed
215
216 fLin1a->Draw();
217 fLin1b->Draw();
218 fLin2->Draw();
219
220 fList->Add(fLin1a);
221 fList->Add(fLin1b);
222 fList->Add(fLin2);
223
224 for (int i=0; i<6; i++)
225 {
226 fDot[i] = new TArc(0, 0, 1);
227 InitArc(fDot[i], 1001, 10, 19);
228 fList->Add(fDot[i]);
229 }
230}
231
232MGSkyPosition::MGSkyPosition(MObservatory::LocationName_t key, const TGWindow* p, const UInt_t w)
233 : MGEmbeddedCanvas("SkyPosition", p, w, 110), fObservatory(key)
234{
235 DrawCoordinateSystem();
236 InitPlanets();
237 InitPosition();
238 InitText();
239 InitCanvas();
240 SetNoContextMenu();
241}
242
243MGSkyPosition::~MGSkyPosition()
244{
245 delete fSlaPlanet;
246 delete fSlaStar;
247
248 cout << "MGSkyPosition destroyed." << endl;
249}
250
251void MGSkyPosition::SetLin1(Float_t x, Float_t y)
252{
253 fLin1a->SetX2(x);
254 fLin1a->SetY2(y);
255 fLin1b->SetX2(-x);
256 fLin1b->SetY2(-y);
257}
258
259void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
260{
261 fLin2->SetX1(x1);
262 fLin2->SetX2(x2);
263 fLin2->SetY1(y1);
264 fLin2->SetY2(y2);
265}
266
267void MGSkyPosition::SetDot(TArc *arc, const RaDec &radec, Int_t off)
268{
269 RaDec rd(radec.Ra()+off*360/24*kDeg2Rad, radec.Dec());
270 ZdAz zdaz = fSlaStar->CalcZdAzFast(rd);
271
272 const float s = sin(zdaz.Az());
273 const float c = cos(zdaz.Az());
274
275 float x = s*zdaz.Zd()*kRad2Deg; // [deg]
276 float y = c*zdaz.Zd()*kRad2Deg; // [deg]
277
278 SetDotRange(arc, x, y);
279}
280
281void MGSkyPosition::UpdatePosition(RaDec &radec, Float_t zd, Float_t az)
282{
283 //
284 // zd [deg]
285 // az [deg]
286 //
287 static int X =~0;
288 static int Y =~0;
289 static int Rx=~0;
290 static int Ry=~0;
291
292 const float rad = az*kDeg2Rad; // [rad]
293
294 const float s = sin(rad);
295 const float c = cos(rad);
296
297 const float x = s*zd; // [deg]
298 const float y = c*zd; // [deg]
299
300 const int pixx = (int)(x/fPix);
301 const int pixy = (int)(y/fPix);
302
303 const int rx = (int)(s*fWidth/2.);
304 const int ry = (int)(c*fWidth/2.);
305
306 if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
307 return;
308
309 X = pixx;
310 Y = pixy;
311
312 Rx = rx;
313 Ry = ry;
314
315 const float dx = s*4.;
316 const float dy = c*4.;
317
318 SetLin1(s*95., c*95.);
319 SetLin2(x+dy, y-dx, x-dy, y+dx);
320
321 for(int i=0; i<3; i++)
322 SetDot(fDot[i], radec, i-3);
323 for(int i=3; i<6; i++)
324 SetDot(fDot[i], radec, i-2);
325
326 SetModified();
327}
328
329void MGSkyPosition::UpdateText(Float_t x, Float_t y)
330{
331 static int X = ~0;
332 static int Y = ~0;
333
334 UShort_t xd, yd;
335 Char_t sx, sy;
336 Double_t xm, ym;
337 MAstro::Deg2Dm(x, sx, xd, xm);
338 MAstro::Deg2Dm(y, sy, yd, ym);
339
340 const int fx = (int)(x*600);
341 const int fy = (int)(y*600);
342
343 if (X==fx && Y==fy)
344 return;
345
346 X = fx;
347 Y = fy;
348
349 char txt[100];
350 sprintf(txt, "Zd=%s%d\xb0%02.1f'", sx=='-'?"-":"", xd, xm);
351 fText1->SetText(fText1->GetX(), fText1->GetY(), txt);
352
353 sprintf(txt, "Az=%s%d\xb0%02.1f'", sy=='-'?"-":"", yd, ym);
354 fText2->SetText(fText2->GetX(), fText2->GetY(), txt);
355
356 SetModified();
357}
358
359
360void MGSkyPosition::Update(ZdAz &pos, double mjd)
361{
362 //
363 // calculate actual time for planet positions
364 //
365 fSlaPlanet->SetMjd(mjd);
366 fSlaStar->SetMjd(mjd);
367
368 UpdatePlanet(kESun, fSun);
369 UpdatePlanet(kEMoon, fMoon);
370 UpdatePlanet(kEJupiter, fJupiter);
371 UpdatePlanet(kEVenus, fVenus);
372 UpdatePlanet(kEMars, fMars);
373 UpdatePlanet(kESaturn, fSaturn);
374
375 UpdateStars();
376
377 RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
378 UpdatePosition(radec, pos.Zd(), pos.Az());
379 UpdateText(pos.Zd(), pos.Az());
380
381 UpdateCanvas();
382}
383
384bool MGSkyPosition::SetDotRange(TArc *arc, float &x, float &y)
385{
386 if (!(x>-95 && x<95 && y>-95 && y<95))
387 {
388 if (arc->GetX1()==-100 && arc->GetY1()==100)
389 return false;
390
391 x= 100;
392 y=-100;
393 }
394
395 const int pixx = (int)(x/fPix);
396 const int pixy = (int)(y/fPix);
397
398 const int oldx = (int)(arc->GetX1()/fPix);
399 const int oldy = (int)(arc->GetY1()/fPix);
400
401 if (pixx==oldx && pixy==oldy)
402 return false;
403
404 arc->SetX1(x);
405 arc->SetY1(y);
406
407 SetModified();
408
409 return true;
410}
411
412void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
413{
414 //
415 // calculate actual position of planet
416 //
417 fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
418
419 const ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
420
421 //
422 // check whether we have to change the position where it is drawn
423 //
424 const float s = sin(zdaz.Az());
425 const float c = cos(zdaz.Az());
426
427 const float deg = zdaz.Zd()*kRad2Deg;
428
429 float x = s*deg;
430 float y = c*deg;
431
432 if (!SetDotRange(arc, x, y))
433 return;
434
435 if (planet==kESaturn)
436 {
437 fSaturnRing->SetX1(x);
438 fSaturnRing->SetY1(y);
439 }
440
441 if (planet==kESun)
442 {
443 fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
444 fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
445 fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
446 fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
447
448 fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
449 fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
450 fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
451 fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
452 }
453}
Note: See TracBrowser for help on using the repository browser.