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

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