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

Last change on this file since 912 was 912, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 6.3 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 <TList.h>
14#include <TCanvas.h>
15
16#include "coord.h"
17#include "SlaPlanets.h"
18
19void MGSkyPosition::InitPlanets()
20{
21 //
22 // Magnitudes:
23 // -----------
24 // Moon -12.8
25 // Jupiter -4.6
26 // Venus -4.0
27 // Mars -2.0
28 // Merkur 0.0
29 // Saturn 0.7
30 // Uranus 5.5
31 // Neptun 7.8
32 //
33 fSlalib = new SlaPlanets;
34
35 //
36 // Colors: black .. white:
37 //
38 // 1, 12, 13, 14, 15, 16, 17, 18, 19, 10
39 //
40 fMars = new TArc(0, 0, 1);
41 fMars->SetFillStyle(1001); // solid (s. TAttFill)
42 fMars->SetFillColor(13); // light grey (s. TAttFill)
43 fMars->SetLineColor(12);
44 fMars->Draw();
45
46 fVenus = new TArc(0, 0, 2);
47 fVenus->SetFillStyle(1001); // solid (s. TAttFill)
48 fVenus->SetFillColor(15); // light grey (s. TAttFill)
49 fVenus->SetLineColor(14);
50 fVenus->Draw();
51
52 fJupiter = new TArc(0, 0, 2);
53 fJupiter->SetFillStyle(1001); // solid (s. TAttFill)
54 fJupiter->SetFillColor(17); // light grey (s. TAttFill)
55 fJupiter->SetLineColor(16);
56 fJupiter->Draw();
57
58 fMoon = new TArc(0, 0, 3, 290, 70);
59 fMoon->SetFillStyle(1001); // solid (s. TAttFill)
60 fMoon->SetFillColor(19); // light grey (s. TAttFill)
61 fMoon->SetLineColor(15);
62 fMoon->Draw();
63
64 for (int i=0; i<4; i++)
65 {
66 fSunL[i] = new TLine(0,0,0,0);
67 fSunL[i]->SetLineColor(10); // white gray
68 fSunL[i]->SetLineStyle(1); // solid (s. TAttLine)
69 fSunL[i]->Draw();
70
71 fList->Add(fSunL[i]);
72 }
73
74 fSun = new TArc(0, 0, 2);
75 fSun->SetFillStyle(1001); // solid (s. TAttFill)
76 fSun->SetFillColor(10); // white (s. TAttFill)
77 fSun->SetLineColor(19);
78 fSun->Draw();
79
80 fList->Add(fMars);
81 fList->Add(fVenus);
82 fList->Add(fJupiter);
83 fList->Add(fMoon);
84 fList->Add(fSun);
85
86 //
87 // Reset 'static' positions of planets
88 //
89 for (int i=0; i<9; i++)
90 {
91 fX[i] = ~0;
92 fY[i] = ~0;
93 }
94}
95
96void MGSkyPosition::DrawCoordinateSystem()
97{
98 TArc arc;
99 arc.SetFillStyle(4000); // transparent
100 arc.SetLineColor(13); // dark gray
101 arc.SetLineStyle(1); // solid (s. TAttLine)
102 arc.DrawArc(0, 0, 90);
103 arc.DrawArc(0, 0, 67.5);
104 arc.DrawArc(0, 0, 45);
105 arc.DrawArc(0, 0, 22.5);
106
107 TLine line;
108 line.SetLineColor(1); // black
109 line.SetLineStyle(1); // solid (s. TAttLine)
110 line.DrawLine(-95, 0, 95, 0);
111 line.DrawLine( 0, -95, 0, 95);
112}
113
114void MGSkyPosition::InitPosition()
115{
116 fLin1a = new TLine(0, 0, 0, 0);
117 fLin1b = new TLine(0, 0, 0, 0);
118 fLin2 = new TLine(0, 0, 0, 0);
119
120 fLin1a->SetLineColor(5); // yellow (s. TAttFill)
121 fLin1b->SetLineColor(5); // yellow
122 fLin2 ->SetLineColor(10); // white
123 fLin1a->SetLineStyle(1); // solid (s. TAttLine)
124 fLin1b->SetLineStyle(2); // dashed
125
126 fLin1a->Draw();
127 fLin1b->Draw();
128 fLin2->Draw();
129
130 fList->Add(fLin1a);
131 fList->Add(fLin1b);
132 fList->Add(fLin2);
133}
134
135MGSkyPosition::MGSkyPosition(const TGWindow* p, const Int_t w, const Int_t h)
136 : TRootEmbeddedCanvas("SkyPosition", p, w-1, h-1, kRaisedFrame),//, 0) //234, 76, kFixedSize)
137 fModified(kFALSE)
138{
139 fCanvas = GetCanvas();
140
141 fCanvas->SetFillColor(39); // s. TAttFill
142 fCanvas->Range(-100, -100, 100, 100);
143
144 fList = new TList;
145 fList->SetOwner();
146
147 DrawCoordinateSystem();
148 InitPosition();
149 InitPlanets();
150
151 Resize(w, h); //GetDefaultSize()); // ???
152 MapSubwindows();
153}
154
155MGSkyPosition::~MGSkyPosition()
156{
157 delete fList;
158 delete fSlalib;
159
160 cout << "MGSkyPosition destroyed." << endl;
161}
162
163void MGSkyPosition::SetLin1(int x, int y)
164{
165 fLin1a->SetX2(x);
166 fLin1a->SetY2(y);
167 fLin1b->SetX2(-x);
168 fLin1b->SetY2(-y);
169}
170
171void MGSkyPosition::SetLin2(int x1, int y1, int x2, int y2)
172{
173 fLin2->SetX1(x1);
174 fLin2->SetX2(x2);
175 fLin2->SetY1(y1);
176 fLin2->SetY2(y2);
177}
178
179void MGSkyPosition::DrawPosition(Float_t zd, Float_t az)
180{
181 static int X=~0;
182 static int Y=~0;
183
184 const float rad = D2PI*az/360.0;
185
186 const float s = sin(rad);
187 const float c = cos(rad);
188
189 const int x = (int)(s*zd);
190 const int y = (int)(c*zd);
191
192 if (X==x && Y==y)
193 return;
194
195 X = x;
196 Y = y;
197
198 const int dx = (int)(s*4);
199 const int dy = (int)(c*4);
200
201 SetLin1(s*95, c*95);
202 SetLin2(x+dy, y-dx, x-dy, y+dx);
203
204 fModified = kTRUE;
205}
206
207void MGSkyPosition::Update(ZdAz &pos)
208{
209 //
210 // calculate actual time for planet positions
211 //
212 fSlalib->SetMjd2Now();
213
214 DrawPlanet(kESun, fSun);
215 DrawPlanet(kEMoon, fMoon);
216 DrawPlanet(kEJupiter, fJupiter);
217 DrawPlanet(kEVenus, fVenus);
218 DrawPlanet(kEMars, fMars);
219
220 DrawPosition(pos.Zd(), pos.Az());
221
222 if (!fModified)
223 return;
224
225 // FIXME: Sometimes (if the canvas couldn't be created correctly:
226 // X11 Pixmap error) Update hangs the Gui system.
227
228 fCanvas->Modified();
229 fCanvas->Update();
230
231 fModified = kFALSE;
232}
233
234void MGSkyPosition::DrawPlanet(Int_t planet, TArc *arc)
235{
236 //
237 // calculate actual position of planet
238 //
239 fSlalib->UpdatePlanetPos((ePlanets_t)planet);
240
241 ZdAz zdaz = fSlalib->GetPlanetPos((ePlanets_t)planet);
242
243 //
244 // check whether we have to change the position where it is drawn
245 //
246 const float s = sin(zdaz.Az());
247 const float c = cos(zdaz.Az());
248
249 const float deg = 360.0/D2PI*zdaz.Zd();
250
251 const int x = (int)(s*deg);
252 const int y = (int)(c*deg);
253
254 if (fX[planet]==x && fY[planet]==y)
255 return;
256
257 fX[planet] = x;
258 fY[planet] = y;
259
260 //
261 // Set new position
262 //
263 arc->SetX1(x);
264 arc->SetY1(y);
265
266 fModified = kTRUE;
267
268 if (planet!=kESun)
269 return;
270
271 cout << "Sun: x=" << x << " y=" << y;
272 cout << " Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
273
274 fSunL[0]->SetX1(x-4); fSunL[0]->SetX2(x+4);
275 fSunL[1]->SetX1(x-3); fSunL[1]->SetX2(x+3);
276 fSunL[2]->SetX1(x-3); fSunL[2]->SetX2(x+3);
277 fSunL[3]->SetX1(x ); fSunL[3]->SetX2(x );
278
279 fSunL[0]->SetY1(y ); fSunL[0]->SetY2(y );
280 fSunL[1]->SetY1(y-3); fSunL[1]->SetY2(y+3);
281 fSunL[2]->SetY1(y+3); fSunL[2]->SetY2(y-3);
282 fSunL[3]->SetY1(y-4); fSunL[3]->SetY2(y+4);
283}
Note: See TracBrowser for help on using the repository browser.