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

Last change on this file since 1727 was 1727, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 8.8 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;
46 fSlaStar = new SlaStars;
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<4; i++)
72 {
73 fSunL[i] = new TLine(0,0,0,0);
74 fSunL[i]->SetLineColor(10); // white gray
75 fSunL[i]->SetLineStyle(1); // solid (s. TAttLine)
76 fSunL[i]->Draw();
77
78 fList->Add(fSunL[i]);
79 }
80 InitArc(fSun, 1001, kYellow/*10*/, kYellow/*19*/);
81
82 fList->Add(fMars);
83 fList->Add(fVenus);
84 fList->Add(fJupiter);
85 fList->Add(fMoon);
86 fList->Add(fSun);
87 fList->Add(fSaturn);
88
89 //
90 // Reset 'static' positions of planets
91 //
92 for (int i=0; i<9; i++)
93 {
94 fX[i] = ~0;
95 fY[i] = ~0;
96 }
97}
98
99void MGSkyPosition::InitText()
100{
101 fText = new TText(105, 105, "");
102 //fText->SetFillStyle(4000); // transparent
103 fText->SetTextAlign(33); // right, top
104 fText->SetTextColor(10); // white
105 fText->Draw();
106
107 fList->Add(fText);
108}
109
110void MGSkyPosition::DrawCoordinateSystem()
111{
112 TArc arc;
113 arc.SetFillStyle(4000); // transparent
114 arc.SetLineColor(13); // dark gray
115 arc.SetLineStyle(1); // solid (s. TAttLine)
116 arc.DrawArc(0, 0, 90);
117 arc.DrawArc(0, 0, 67.5);
118 arc.DrawArc(0, 0, 45);
119 arc.DrawArc(0, 0, 22.5);
120
121 //
122 // FIXME? Use TAxis?
123 //
124 TLine line;
125 line.SetLineColor(1); // black
126 line.SetLineStyle(1); // solid (s. TAttLine)
127 line.DrawLine(-95, 0, 95, 0);
128 line.DrawLine( 0, -95, 0, 95);
129
130 TText text;
131 text.SetTextAlign(22); // centered, centered (s.TAttText)
132 text.SetTextColor(13); // dark gray
133 text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0");
134 text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0");
135 text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0");
136 text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0");
137
138 text.SetTextAlign(22); // centered, centered (s.TAttText)
139 text.SetTextColor(1); // black
140
141 text.DrawText(0, 102, "N (0\xb0)");
142 text.DrawText(0, -102, "S (180\xb0)");
143
144 text.SetTextAngle(270);
145 text.DrawText( 102, 0, "E (90\xb0)");
146
147 text.SetTextAngle(90);
148 text.DrawText(-102, 0, "W (270\xb0)");
149}
150
151void MGSkyPosition::InitPosition()
152{
153 fLin1a = new TLine(0, 0, 0, 0);
154 fLin1b = new TLine(0, 0, 0, 0);
155 fLin2 = new TLine(0, 0, 0, 0);
156
157 fLin1a->SetLineColor(5); // yellow (s. TAttFill)
158 fLin1b->SetLineColor(5); // yellow
159 fLin2 ->SetLineColor(10); // white
160 fLin1a->SetLineStyle(1); // solid (s. TAttLine)
161 fLin1b->SetLineStyle(2); // dashed
162
163 fLin1a->Draw();
164 fLin1b->Draw();
165 fLin2->Draw();
166
167 fList->Add(fLin1a);
168 fList->Add(fLin1b);
169 fList->Add(fLin2);
170
171 for (int i=0; i<6; i++)
172 {
173 fDot[i] = new TArc(0, 0, 1);
174 InitArc(fDot[i], 1001, 10, 19);
175 fList->Add(fDot[i]);
176 }
177}
178
179MGSkyPosition::MGSkyPosition(const TGWindow* p, const UInt_t w)
180 : MGEmbeddedCanvas("SkyPosition", p, w, 110)
181{
182 DrawCoordinateSystem();
183 InitPlanets();
184 InitPosition();
185 InitText();
186 InitCanvas();
187 SetNoContextMenu();
188}
189
190MGSkyPosition::~MGSkyPosition()
191{
192 delete fSlaPlanet;
193 delete fSlaStar;
194
195 cout << "MGSkyPosition destroyed." << endl;
196}
197
198void MGSkyPosition::SetLin1(Float_t x, Float_t y)
199{
200 fLin1a->SetX2(x);
201 fLin1a->SetY2(y);
202 fLin1b->SetX2(-x);
203 fLin1b->SetY2(-y);
204}
205
206void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
207{
208 fLin2->SetX1(x1);
209 fLin2->SetX2(x2);
210 fLin2->SetY1(y1);
211 fLin2->SetY2(y2);
212}
213
214void MGSkyPosition::SetDot(TArc *arc, RaDec &radec, Int_t off)
215{
216 RaDec rd(radec.Ra()+off*360/24*kDeg2Rad, radec.Dec());
217 ZdAz zdaz = fSlaStar->CalcZdAzFast(rd);
218
219 const float s = sin(zdaz.Az());
220 const float c = cos(zdaz.Az());
221
222 const float x = s*zdaz.Zd()*kRad2Deg; // [deg]
223 const float y = c*zdaz.Zd()*kRad2Deg; // [deg]
224
225 arc->SetX1(x);
226 arc->SetY1(y);
227
228 SetModified();
229}
230
231void MGSkyPosition::UpdatePosition(RaDec &radec, Float_t zd, Float_t az)
232{
233 //
234 // zd [deg]
235 // az [deg]
236 //
237 static int X =~0;
238 static int Y =~0;
239 static int Rx=~0;
240 static int Ry=~0;
241
242 const float rad = az*kDeg2Rad; // [rad]
243
244 const float s = sin(rad);
245 const float c = cos(rad);
246
247 const float x = s*zd; // [deg]
248 const float y = c*zd; // [deg]
249
250 const int pixx = (int)(x/fPix);
251 const int pixy = (int)(y/fPix);
252
253 const int rx = (int)(s*fWidth/2.);
254 const int ry = (int)(c*fWidth/2.);
255
256 if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
257 return;
258
259 X = pixx;
260 Y = pixy;
261
262 Rx = rx;
263 Ry = ry;
264
265 const float dx = s*4.;
266 const float dy = c*4.;
267
268 SetLin1(s*95., c*95.);
269 SetLin2(x+dy, y-dx, x-dy, y+dx);
270
271 if (zd<80)
272 {
273 for(int i=0; i<3; i++)
274 SetDot(fDot[i], radec, i-3);
275 for(int i=3; i<6; i++)
276 SetDot(fDot[i], radec, i-2);
277 }
278
279 SetModified();
280}
281
282void MGSkyPosition::UpdateText(Float_t x, Float_t y)
283{
284 static int X = ~0;
285 static int Y = ~0;
286
287 int xd = (int)/*floor*/(x);
288 int yd = (int)/*floor*/(y);
289 x *= 60.;
290 y *= 60.;
291
292 int fx = (int)/*floor*/(x*10.);
293 int fy = (int)/*floor*/(y*10.);
294
295 if (X==fx && Y==fy)
296 return;
297
298 X = fx;
299 Y = fy;
300
301 float xm = fmod(fabs(x), 60.);
302 float ym = fmod(fabs(y), 60.);
303
304 char txt[100];
305 sprintf(txt, "Zd=%s%d\xb0%02.1f'\nAz=%s%d\xb0%02.1f'",
306 x<0?"-":"", abs(xd), xm, y<0?"-":"", abs(yd), ym);
307
308 fText->SetText(fText->GetX(), fText->GetY(), txt);
309
310 SetModified();
311}
312
313
314void MGSkyPosition::Update(ZdAz &pos, double mjd)
315{
316 //
317 // calculate actual time for planet positions
318 //
319 fSlaPlanet->SetMjd(mjd);
320 fSlaStar->SetMjd(mjd);
321
322 UpdatePlanet(kESun, fSun);
323 UpdatePlanet(kEMoon, fMoon);
324 UpdatePlanet(kEJupiter, fJupiter);
325 UpdatePlanet(kEVenus, fVenus);
326 UpdatePlanet(kEMars, fMars);
327 UpdatePlanet(kESaturn, fSaturn);
328
329 RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
330
331 UpdatePosition(radec, pos.Zd(), pos.Az());
332 UpdateText(pos.Zd(), pos.Az());
333
334 UpdateCanvas();
335}
336
337void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
338{
339 //
340 // calculate actual position of planet
341 //
342 fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
343
344 ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
345
346 //
347 // check whether we have to change the position where it is drawn
348 //
349 const float s = sin(zdaz.Az());
350 const float c = cos(zdaz.Az());
351
352 const float deg = zdaz.Zd()*kRad2Deg;
353
354 const float x = s*deg;
355 const float y = c*deg;
356
357 const int pixx = (int)(x/fPix);
358 const int pixy = (int)(y/fPix);
359
360 if (fX[planet]==pixx && fY[planet]==pixy)
361 return;
362
363 fX[planet] = pixx;
364 fY[planet] = pixy;
365
366 //
367 // Set new position
368 //
369 arc->SetX1(x);
370 arc->SetY1(y);
371
372 SetModified();
373
374 if (planet==kESaturn)
375 {
376 fSaturnRing->SetX1(x);
377 fSaturnRing->SetY1(y);
378 }
379
380 if (planet==kESun)
381 {
382 fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
383 fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
384 fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
385 fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
386
387 fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
388 fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
389 fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
390 fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
391 }
392}
Note: See TracBrowser for help on using the repository browser.