source: trunk/Cosy/gui/MGSkyPosition.cc@ 10305

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