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

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