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

Last change on this file since 1702 was 1702, 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 SetNoContextMenu();
180}
181
182MGSkyPosition::~MGSkyPosition()
183{
184 delete fSlaPlanet;
185 delete fSlaStar;
186
187 cout << "MGSkyPosition destroyed." << endl;
188}
189
190void MGSkyPosition::SetLin1(Float_t x, Float_t y)
191{
192 fLin1a->SetX2(x);
193 fLin1a->SetY2(y);
194 fLin1b->SetX2(-x);
195 fLin1b->SetY2(-y);
196}
197
198void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
199{
200 fLin2->SetX1(x1);
201 fLin2->SetX2(x2);
202 fLin2->SetY1(y1);
203 fLin2->SetY2(y2);
204}
205
206void MGSkyPosition::SetDot(TArc *arc, RaDec &radec, Int_t off)
207{
208 RaDec rd(radec.Ra()+off*360/24*kDeg2Rad, radec.Dec());
209 ZdAz zdaz = fSlaStar->CalcZdAzFast(rd);
210
211 const float s = sin(zdaz.Az());
212 const float c = cos(zdaz.Az());
213
214 const float x = s*zdaz.Zd()*kRad2Deg; // [deg]
215 const float y = c*zdaz.Zd()*kRad2Deg; // [deg]
216
217 arc->SetX1(x);
218 arc->SetY1(y);
219
220 SetModified();
221}
222
223void MGSkyPosition::UpdatePosition(RaDec &radec, Float_t zd, Float_t az)
224{
225 //
226 // zd [deg]
227 // az [deg]
228 //
229 static int X =~0;
230 static int Y =~0;
231 static int Rx=~0;
232 static int Ry=~0;
233
234 const float rad = az*kDeg2Rad; // [rad]
235
236 const float s = sin(rad);
237 const float c = cos(rad);
238
239 const float x = s*zd; // [deg]
240 const float y = c*zd; // [deg]
241
242 const int pixx = (int)(x/fPix);
243 const int pixy = (int)(y/fPix);
244
245 const int rx = (int)(s*fWidth/2.);
246 const int ry = (int)(c*fWidth/2.);
247
248 if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
249 return;
250
251 X = pixx;
252 Y = pixy;
253
254 Rx = rx;
255 Ry = ry;
256
257 const float dx = s*4.;
258 const float dy = c*4.;
259
260 SetLin1(s*95., c*95.);
261 SetLin2(x+dy, y-dx, x-dy, y+dx);
262
263 if (zd<80)
264 {
265 for(int i=0; i<3; i++)
266 SetDot(fDot[i], radec, i-3);
267 for(int i=3; i<6; i++)
268 SetDot(fDot[i], radec, i-2);
269 }
270
271 SetModified();
272}
273
274void MGSkyPosition::UpdateText(Float_t x, Float_t y)
275{
276 static int X = ~0;
277 static int Y = ~0;
278
279 int xd = (int)/*floor*/(x);
280 int yd = (int)/*floor*/(y);
281 x *= 60.;
282 y *= 60.;
283
284 int fx = (int)/*floor*/(x*10.);
285 int fy = (int)/*floor*/(y*10.);
286
287 if (X==fx && Y==fy)
288 return;
289
290 X = fx;
291 Y = fy;
292
293 float xm = fmod(fabs(x), 60.);
294 float ym = fmod(fabs(y), 60.);
295
296 char txt[100];
297 sprintf(txt, "Zd=%s%d\xb0%02.1f'\nAz=%s%d\xb0%02.1f'",
298 x<0?"-":"", abs(xd), xm, y<0?"-":"", abs(yd), ym);
299
300 fText->SetText(fText->GetX(), fText->GetY(), txt);
301
302 SetModified();
303}
304
305
306void MGSkyPosition::Update(ZdAz &pos, double mjd)
307{
308 //
309 // calculate actual time for planet positions
310 //
311 fSlaPlanet->SetMjd(mjd);
312 fSlaStar->SetMjd(mjd);
313
314 UpdatePlanet(kESun, fSun);
315 UpdatePlanet(kEMoon, fMoon);
316 UpdatePlanet(kEJupiter, fJupiter);
317 UpdatePlanet(kEVenus, fVenus);
318 UpdatePlanet(kEMars, fMars);
319
320 RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
321
322 UpdatePosition(radec, pos.Zd(), pos.Az());
323 UpdateText(pos.Zd(), pos.Az());
324
325 UpdateCanvas();
326}
327
328void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
329{
330 //
331 // calculate actual position of planet
332 //
333 fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
334
335 ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
336
337 //
338 // check whether we have to change the position where it is drawn
339 //
340 const float s = sin(zdaz.Az());
341 const float c = cos(zdaz.Az());
342
343 const float deg = zdaz.Zd()*kRad2Deg;
344
345 const float x = s*deg;
346 const float y = c*deg;
347
348 const int pixx = (int)(x/fPix);
349 const int pixy = (int)(y/fPix);
350
351 if (fX[planet]==pixx && fY[planet]==pixy)
352 return;
353
354 fX[planet] = pixx;
355 fY[planet] = pixy;
356
357 //
358 // Set new position
359 //
360 arc->SetX1(x);
361 arc->SetY1(y);
362
363 SetModified();
364
365 if (planet!=kESun)
366 return;
367
368 // cout << "Sun: x=" << x << " y=" << y;
369 // cout << " Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
370
371 fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
372 fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
373 fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
374 fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
375
376 fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
377 fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
378 fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
379 fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
380}
Note: See TracBrowser for help on using the repository browser.