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

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