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

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