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

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