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

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