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

Last change on this file since 1802 was 1793, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 11.0 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 if (x>95 || x<-95 || y>95 || y<-95)
265 {
266 if (arc->GetX1()==10 && arc->GetY1()==100)
267 return;
268
269 x=-100;
270 y= 100;
271 }
272
273 const int pixx = (int)(x/fPix);
274 const int pixy = (int)(y/fPix);
275
276 const int oldx = (int)(arc->GetX1()/fPix);
277 const int oldy = (int)(arc->GetY1()/fPix);
278
279 if (pixx==oldx && pixy==oldy)
280 return;
281
282 arc->SetX1(x);
283 arc->SetY1(y);
284
285 SetModified(); //***MEMORY LEAK!!!***
286}
287
288void MGSkyPosition::UpdatePosition(RaDec &radec, Float_t zd, Float_t az)
289{
290 //
291 // zd [deg]
292 // az [deg]
293 //
294 static int X =~0;
295 static int Y =~0;
296 static int Rx=~0;
297 static int Ry=~0;
298
299 const float rad = az*kDeg2Rad; // [rad]
300
301 const float s = sin(rad);
302 const float c = cos(rad);
303
304 const float x = s*zd; // [deg]
305 const float y = c*zd; // [deg]
306
307 const int pixx = (int)(x/fPix);
308 const int pixy = (int)(y/fPix);
309
310 const int rx = (int)(s*fWidth/2.);
311 const int ry = (int)(c*fWidth/2.);
312
313 if (X==pixx && Y==pixy && Rx==rx && Ry==ry)
314 return;
315
316 X = pixx;
317 Y = pixy;
318
319 Rx = rx;
320 Ry = ry;
321
322 const float dx = s*4.;
323 const float dy = c*4.;
324
325 SetLin1(s*95., c*95.);
326 SetLin2(x+dy, y-dx, x-dy, y+dx);
327
328 //if (zd<80)
329 //{
330 for(int i=0; i<3; i++)
331 SetDot(fDot[i], radec, i-3);
332 for(int i=3; i<6; i++)
333 SetDot(fDot[i], radec, i-2);
334 //}
335
336 SetModified();
337}
338
339void MGSkyPosition::UpdateText(Float_t x, Float_t y)
340{
341 static int X = ~0;
342 static int Y = ~0;
343
344 int xd = (int)/*floor*/(x);
345 int yd = (int)/*floor*/(y);
346 x *= 60.;
347 y *= 60.;
348
349 int fx = (int)/*floor*/(x*10.);
350 int fy = (int)/*floor*/(y*10.);
351
352 if (X==fx && Y==fy)
353 return;
354
355 X = fx;
356 Y = fy;
357
358 float xm = fmod(fabs(x), 60.);
359 float ym = fmod(fabs(y), 60.);
360
361 char txt[100];
362 sprintf(txt, "Zd=%s%d\xb0%02.1f'\nAz=%s%d\xb0%02.1f'",
363 x<0?"-":"", abs(xd), xm, y<0?"-":"", abs(yd), ym);
364
365 fText->SetText(fText->GetX(), fText->GetY(), txt);
366
367 SetModified();
368}
369
370
371void MGSkyPosition::Update(ZdAz &pos, double mjd)
372{
373 //
374 // calculate actual time for planet positions
375 //
376 fSlaPlanet->SetMjd(mjd);
377 fSlaStar->SetMjd(mjd);
378
379 UpdatePlanet(kESun, fSun);
380 UpdatePlanet(kEMoon, fMoon);
381 UpdatePlanet(kEJupiter, fJupiter);
382 UpdatePlanet(kEVenus, fVenus);
383 UpdatePlanet(kEMars, fMars);
384 UpdatePlanet(kESaturn, fSaturn);
385
386 UpdateStars();
387
388 RaDec radec = fSlaStar->CalcRaDecFast(pos*kDeg2Rad);
389 UpdatePosition(radec, pos.Zd(), pos.Az());
390 UpdateText(pos.Zd(), pos.Az());
391
392 UpdateCanvas();
393}
394
395void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
396{
397 //
398 // calculate actual position of planet
399 //
400 fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
401
402 ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
403
404 //
405 // check whether we have to change the position where it is drawn
406 //
407 const float s = sin(zdaz.Az());
408 const float c = cos(zdaz.Az());
409
410 const float deg = zdaz.Zd()*kRad2Deg;
411
412 float x = s*deg;
413 float y = c*deg;
414
415 if (x>95 || x<-95 || y>95 || y<-95)
416 {
417 if (arc->GetX1()==10 && arc->GetY1()==100)
418 return;
419
420 x=-100;
421 y= 100;
422 }
423
424 const int pixx = (int)(x/fPix);
425 const int pixy = (int)(y/fPix);
426
427 const int oldx = (int)(arc->GetX1()/fPix);
428 const int oldy = (int)(arc->GetY1()/fPix);
429
430 if (oldx==pixx && oldy==pixy)
431 return;
432
433 //
434 // Set new position
435 //
436 arc->SetX1(x);
437 arc->SetY1(y);
438
439 SetModified();
440
441 if (planet==kESaturn)
442 {
443 fSaturnRing->SetX1(x);
444 fSaturnRing->SetY1(y);
445 }
446
447 if (planet==kESun)
448 {
449 fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
450 fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
451 fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
452 fSunL[3]->SetX1(x); fSunL[3]->SetX2(x);
453
454 fSunL[0]->SetY1(y); fSunL[0]->SetY2(y);
455 fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
456 fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
457 fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
458 }
459}
Note: See TracBrowser for help on using the repository browser.