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

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