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

Last change on this file since 9029 was 8852, checked in by tbretz, 17 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 <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<14; 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[14] =
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};
142
143void MGSkyPosition::UpdateStars()
144{
145 for (int i=0; i<14; i++)
146 SetDot(fStars[i], stars[i], 0);
147}
148
149void MGSkyPosition::InitText()
150{
151 fText1 = new TText(-105, 105, "");
152 fText2 = new TText(105, 105, "");
153
154 fText1->SetTextAlign(13); // left, top
155 fText2->SetTextAlign(33); // right, top
156
157 fText1->SetTextColor(10); // white
158 fText2->SetTextColor(10); // white
159
160 fText1->Draw();
161 fText2->Draw();
162
163 fList->Add(fText1);
164 fList->Add(fText2);
165}
166
167void MGSkyPosition::DrawCoordinateSystem()
168{
169 TArc arc;
170 arc.SetFillStyle(4000); // transparent
171 arc.SetLineColor(13); // dark gray
172 arc.SetLineStyle(1); // solid (s. TAttLine)
173 arc.DrawArc(0, 0, 90);
174 arc.DrawArc(0, 0, 67.5);
175 arc.DrawArc(0, 0, 45);
176 arc.DrawArc(0, 0, 22.5);
177
178 //
179 // FIXME? Use TAxis?
180 //
181 TLine line;
182 line.SetLineColor(1); // black
183 line.SetLineStyle(1); // solid (s. TAttLine)
184 line.DrawLine(-95, 0, 95, 0);
185 line.DrawLine( 0, -95, 0, 95);
186
187 TText text;
188 text.SetTextAlign(22); // centered, centered (s.TAttText)
189 text.SetTextColor(13); // dark gray
190 text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0");
191 text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0");
192 text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0");
193 text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0");
194
195 text.SetTextAlign(22); // centered, centered (s.TAttText)
196 text.SetTextColor(1); // black
197
198 text.DrawText(0, 102, "N (0\xb0)");
199 text.DrawText(0, -102, "S (180\xb0)");
200
201 text.SetTextAngle(270);
202 text.DrawText( 102, 0, "E (90\xb0)");
203
204 text.SetTextAngle(90);
205 text.DrawText(-102, 0, "W (270\xb0)");
206}
207
208void MGSkyPosition::InitPosition()
209{
210 fLin1a = new TLine(0, 0, 0, 0);
211 fLin1b = new TLine(0, 0, 0, 0);
212 fLin2 = new TLine(0, 0, 0, 0);
213
214 fLin1a->SetLineColor(5); // yellow (s. TAttFill)
215 fLin1b->SetLineColor(5); // yellow
216 fLin2 ->SetLineColor(10); // white
217 fLin1a->SetLineStyle(1); // solid (s. TAttLine)
218 fLin1b->SetLineStyle(2); // dashed
219
220 fLin1a->Draw();
221 fLin1b->Draw();
222 fLin2->Draw();
223
224 fList->Add(fLin1a);
225 fList->Add(fLin1b);
226 fList->Add(fLin2);
227
228 for (int i=0; i<6; i++)
229 {
230 fDot[i] = new TArc(0, 0, 1);
231 InitArc(fDot[i], 1001, 10, 19);
232 fList->Add(fDot[i]);
233 }
234}
235
236MGSkyPosition::MGSkyPosition(MObservatory::LocationName_t key, const TGWindow* p, const UInt_t w)
237 : MGEmbeddedCanvas("SkyPosition", p, w, 110), fObservatory(key)
238{
239 DrawCoordinateSystem();
240 InitPlanets();
241 InitPosition();
242 InitText();
243 InitCanvas();
244 SetNoContextMenu();
245}
246
247MGSkyPosition::~MGSkyPosition()
248{
249 delete fSlaPlanet;
250 delete fSlaStar;
251
252 gLog << inf2 << "MGSkyPosition destroyed." << endl;
253}
254
255void MGSkyPosition::SetLin1(Float_t x, Float_t y)
256{
257 fLin1a->SetX2(x);
258 fLin1a->SetY2(y);
259 fLin1b->SetX2(-x);
260 fLin1b->SetY2(-y);
261}
262
263void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
264{
265 fLin2->SetX1(x1);
266 fLin2->SetX2(x2);
267 fLin2->SetY1(y1);
268 fLin2->SetY2(y2);
269}
270
271void MGSkyPosition::SetDot(TArc *arc, const RaDec &radec, Int_t off)
272{
273 RaDec rd(radec.Ra()+off*360/24*TMath::DegToRad(), radec.Dec());
274 ZdAz zdaz = fSlaStar->CalcZdAzFast(rd);
275
276 const float s = sin(zdaz.Az());
277 const float c = cos(zdaz.Az());
278
279 float x = s*zdaz.Zd()*kRad2Deg; // [deg]
280 float y = c*zdaz.Zd()*kRad2Deg; // [deg]
281
282 SetDotRange(arc, x, y);
283}
284
285void MGSkyPosition::UpdatePosition(RaDec &radec, Float_t zd, Float_t az)
286{
287 //
288 // zd [deg]
289 // az [deg]
290 //
291 static int X =~0;
292 static int Y =~0;
293 static int Rx=~0;
294 static int Ry=~0;
295
296 const float rad = az*TMath::DegToRad(); // [rad]
297
298 const float s = sin(rad);
299 const float c = cos(rad);
300
301 const float x = s*zd; // [deg]
302 const float y = c*zd; // [deg]
303
304 const int pixx = (int)(x/fPix);
305 const int pixy = (int)(y/fPix);
306
307 const int rx = (int)(s*fWidth/2.);
308 const int ry = (int)(c*fWidth/2.);
309
310 if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
311 return;
312
313 X = pixx;
314 Y = pixy;
315
316 Rx = rx;
317 Ry = ry;
318
319 const float dx = s*4.;
320 const float dy = c*4.;
321
322 SetLin1(s*95., c*95.);
323 SetLin2(x+dy, y-dx, x-dy, y+dx);
324
325 for(int i=0; i<3; i++)
326 SetDot(fDot[i], radec, i-3);
327 for(int i=3; i<6; i++)
328 SetDot(fDot[i], radec, i-2);
329
330 SetModified();
331}
332
333void MGSkyPosition::UpdateText(Float_t x, Float_t y)
334{
335 static int X = ~0;
336 static int Y = ~0;
337
338 UShort_t xd, yd;
339 Char_t sx, sy;
340 Double_t xm, ym;
341 MAstro::Deg2Dm(x, sx, xd, xm);
342 MAstro::Deg2Dm(y, sy, yd, ym);
343
344 const int fx = (int)(x*600);
345 const int fy = (int)(y*600);
346
347 if (X==fx && Y==fy)
348 return;
349
350 X = fx;
351 Y = fy;
352
353 char txt[100];
354 sprintf(txt, "Zd=%s%d\xb0%02.1f'", sx=='-'?"-":"", xd, xm);
355 fText1->SetText(fText1->GetX(), fText1->GetY(), txt);
356
357 sprintf(txt, "Az=%s%d\xb0%02.1f'", sy=='-'?"-":"", yd, ym);
358 fText2->SetText(fText2->GetX(), fText2->GetY(), txt);
359
360 SetModified();
361}
362
363
364void MGSkyPosition::Update(ZdAz &pos, double mjd)
365{
366 //
367 // calculate actual time for planet positions
368 //
369 fSlaPlanet->SetMjd(mjd);
370 fSlaStar->SetMjd(mjd);
371
372 UpdatePlanet(kESun, fSun);
373 UpdatePlanet(kEMoon, fMoon);
374 UpdatePlanet(kEJupiter, fJupiter);
375 UpdatePlanet(kEVenus, fVenus);
376 UpdatePlanet(kEMars, fMars);
377 UpdatePlanet(kESaturn, fSaturn);
378
379 UpdateStars();
380
381 RaDec radec = fSlaStar->CalcRaDecFast(pos*TMath::DegToRad());
382 UpdatePosition(radec, pos.Zd(), pos.Az());
383 UpdateText(pos.Zd(), pos.Az());
384
385 UpdateCanvas();
386}
387
388bool MGSkyPosition::SetDotRange(TArc *arc, float &x, float &y)
389{
390 if (!(x>-95 && x<95 && y>-95 && y<95))
391 {
392 if (arc->GetX1()==-100 && arc->GetY1()==100)
393 return false;
394
395 x= 100;
396 y=-100;
397 }
398
399 const int pixx = (int)(x/fPix);
400 const int pixy = (int)(y/fPix);
401
402 const int oldx = (int)(arc->GetX1()/fPix);
403 const int oldy = (int)(arc->GetY1()/fPix);
404
405 if (pixx==oldx && pixy==oldy)
406 return false;
407
408 arc->SetX1(x);
409 arc->SetY1(y);
410
411 SetModified();
412
413 return true;
414}
415
416void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
417{
418 //
419 // calculate actual position of planet
420 //
421 fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
422
423 const ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
424
425 //
426 // check whether we have to change the position where it is drawn
427 //
428 const float s = sin(zdaz.Az());
429 const float c = cos(zdaz.Az());
430
431 const float deg = zdaz.Zd()*kRad2Deg;
432
433 float x = s*deg;
434 float y = c*deg;
435
436 if (!SetDotRange(arc, x, y))
437 return;
438
439 if (planet==kESaturn)
440 {
441 fSaturnRing->SetX1(x);
442 fSaturnRing->SetY1(y);
443 }
444
445 if (planet==kESun)
446 {
447 fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
448 fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
449 fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
450 fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
451
452 fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
453 fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
454 fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
455 fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
456 }
457}
Note: See TracBrowser for help on using the repository browser.