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

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