source: trunk/MagicSoft/Cosy/gui/MGVelocity.cc@ 1213

Last change on this file since 1213 was 1111, 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 "MGVelocity.h"
8
9#include <iostream.h> // cout
10
11#include <TArc.h>
12#include <TWbox.h>
13#include <TLine.h>
14#include <TText.h>
15#include <TList.h>
16#include <TGaxis.h>
17#include <TArrow.h>
18#include <TCanvas.h>
19
20#include "coord.h"
21
22ClassImp(MGVelocity);
23
24void MGVelocity::DrawCoordinateSystem()
25{
26 /*
27 TArc arc;
28 arc.SetFillStyle(4000); // transparent
29 arc.SetFillColor(39);
30 arc.SetLineColor(3); // green
31 arc.SetLineStyle(2); // dashed (s. TAttLine)
32 arc.DrawArc(0, 0, 20);
33
34 arc.SetLineColor(5); // yellow
35 arc.DrawArc(0, 0, 40);
36
37 arc.SetLineColor(2); // red
38 arc.DrawArc(0, 0, 60);
39 */
40 //
41 // FIXME? Use TAxis?
42 //
43/*
44 TLine line;
45 line.SetLineColor(13);
46 line.SetLineStyle(3); // dotted (s. TAttLine)
47 line.DrawLine(-30., -65., -30., 65.);
48 line.DrawLine(-65., -30., 65., -30.);
49 line.DrawLine( 30., -65., 30., 65.);
50 line.DrawLine( -6., 30., 65., 30.);
51
52 line.DrawLine(-15., -65., -15., 65.);
53 line.DrawLine(-65., -15., 65., -15.);
54 line.DrawLine( 15., -65., 15., 65.);
55 line.DrawLine(-65., 15., 65., 15.);
56
57 line.DrawLine(-45., -65., -45., 65.);
58 line.DrawLine(-65., -45., 65., -45.);
59 line.DrawLine( 45., -65., 45., 65.);
60 line.DrawLine(-65., 45., 65., 45.);
61
62 line.SetLineColor(12);
63 line.SetLineStyle(2); // dashed (s. TAttLine)
64 line.DrawLine(-60., -65., -60., 65.);
65 line.DrawLine(-65., -60., 65., -60.);
66 line.DrawLine( 60., -65., 60., 65.);
67 line.DrawLine(-65., 60., 65., 60.);
68
69 line.SetLineColor(1); // black
70 line.SetLineStyle(1); // solid (s. TAttLine)
71 line.DrawLine(-65., 0, 65., 0);
72 line.DrawLine( 0, -65., 0, 65.);
73
74 line.DrawLine(-1., 60., 1., 60.);
75 line.DrawLine(-1., -60., 1., -60.);
76 line.DrawLine(-1., 30., 1., 30.);
77 line.DrawLine(-1., -30., 1., -30.);
78
79 line.DrawLine( 60., -1., 60., 1.);
80 line.DrawLine(-60., -1., -60., 1.);
81 line.DrawLine( 30., -1., 30., 1.);
82 line.DrawLine(-30., -1., -30., 1.);
83
84 TText text;
85 text.SetTextAlign(22); // centered, centered (s.TAttText)
86 text.DrawText(60., 5., "vAz['/min]");
87 text.DrawText(0, 70., "vZd['/min]");
88
89 text.SetTextAlign(23); // centered, centered (s.TAttText)
90 text.DrawText(-60., -2., "-1'");
91 text.DrawText( 60., -2., "1'");
92 text.DrawText(-30., -2., "-.5'");
93 text.DrawText( 30., -2., ".5'");
94
95 text.SetTextAlign(32); // centered, centered (s.TAttText)
96 text.DrawText(-2., -60., "-1'");
97 text.DrawText(-2., 60., "1'");
98 text.DrawText(-2., -30., "-.5'");
99 text.DrawText(-2., 30., ".5'");
100 */
101 TWbox box;
102 box.DrawWbox(-145, 145, -35, 120, 18, 2, 1);
103
104 TText text;
105 text.SetTextAlign(22); // centered, centered (s.TAttText)
106 text.DrawText(-90., 132.5, fCanvas->GetName());
107
108
109 TLine line;
110 line.DrawLine(-65*2, 0, 65*2, 0);
111 line.DrawLine( 0, -65*2, 0, 65*2);
112
113 //
114 // Can be replaced by TGaxis axe; in a later root version
115 // than 3.01/06. I talked to Rene
116 //
117 TGaxis *axe;
118 axe = new TGaxis(-60*2, 0, 60*2, 0, -2, 2, 304, "+-N");
119 axe->SetTitle("Az"); // \xb0
120 axe->SetBit(kCanDelete);
121 axe->Draw();
122
123 axe = new TGaxis(0, -60*2, 0, 60*2, -2, 2, 304, "+-N");
124 axe->SetTitle("Zd"); // \xb0
125 axe->SetBit(kCanDelete);
126 axe->Draw();
127}
128
129void MGVelocity::InitVelocity()
130{
131 /*
132 fLin1 = new TLine(0, 0, 0, 0);
133 fLin2 = new TLine(0, 0, 0, 0);
134
135 fLin1->SetLineColor(10); // white (s. TAttFill)
136 fLin2->SetLineColor(10); // white
137 fLin1->SetLineStyle(1); // solid (s. TAttLine)
138 fLin2->SetLineStyle(1);
139
140 fLin1->Draw();
141 fLin2->Draw();
142
143 fList->Add(fLin1);
144 fList->Add(fLin2);
145 */
146 fArrow = new TArrow(0, 0, 0, 0, 0.01);
147 fArrowX = new TArrow(0, 0, 0, 0, 0.01);
148 fArrowY = new TArrow(0, 0, 0, 0, 0.01);
149 fArrowAvg = new TArrow(0, 0, 0, 0, 0.01);
150
151 fArrow->SetLineColor(10); // white
152 fArrowX->SetLineColor(17); // light gray
153 fArrowY->SetLineColor(17); // light gray
154 fArrowAvg->SetLineColor(137); // light gray
155
156 fArrow->Draw();
157 fArrowX->Draw();
158 fArrowY->Draw();
159 fArrowAvg->Draw();
160
161 fList->Add(fArrow);
162 fList->Add(fArrowX);
163 fList->Add(fArrowY);
164 fList->Add(fArrowAvg);
165
166 fText = new TText(70*2, -70*2, "x1");
167 fText->SetTextColor(10);
168 fText->SetTextAlign(31); // right, bottom
169 fText->Draw();
170 fList->Add(fText);
171
172 fTextVel = new TText(2*70, 2*70, "");
173 fTextVel->SetTextAlign(33); // right, top
174 fTextVel->SetTextColor(10); // white
175 fTextVel->Draw();
176 fList->Add(fTextVel);
177}
178
179MGVelocity::MGVelocity(const TGWindow* p, const char *name, const UInt_t w)
180: MGEmbeddedCanvas(name, p, w, 75*2), fPos(-1), fScale(1)
181{
182 fOld = new XY;
183 fAvg = new XY[10];
184
185 DrawCoordinateSystem();
186 InitVelocity();
187
188 InitCanvas();
189}
190
191MGVelocity::~MGVelocity()
192{
193 delete fOld;
194 delete fAvg;
195
196 // cout << "MGVelocity destroyed." << endl;
197}
198
199void MGVelocity::UpdateText()
200{
201 char txt[10];
202
203 if (fScale>1)
204 sprintf(txt, "/%.0f", fScale);
205 else
206 sprintf(txt, "x%.0f", 1./fScale);
207
208 fText->SetText(fText->GetX(), fText->GetY(), txt);
209}
210
211Bool_t MGVelocity::UpdateAvg(const float x, const float y)
212{
213
214 //
215 // calculate scale factor from avarage over
216 // speed, not pixels
217 //
218 // different scales for Az and Zd
219 //
220 // check for the number of the value
221 //
222 //
223 const int num = 10;
224
225 // static int pos = -1;
226 // static XY avg[num];
227
228 if (fPos<0)
229 for (int i=1; i<num; i++)
230 fAvg[i].Set(x, y);
231
232 fPos++;
233 fPos %= num;
234
235 fAvg[fPos].Set(x, y);
236
237 Float_t avgx = 0;
238 Float_t avgy = 0;
239
240 for (int i=0; i<num; i++)
241 {
242 avgx += fAvg[i].X();
243 avgy += fAvg[i].Y();
244 }
245
246 avgx /= 10.;
247 avgy /= 10.;
248
249 avgx *= fScale;
250 avgy *= fScale;
251
252 fArrowAvg->SetX2(avgx);
253 fArrowAvg->SetY2(avgy);
254
255 // cout << avgx << " " << avgy << endl;
256
257 if ((fabs(avgx)>/*40.*/110. || fabs(avgy)>/*40.*/110.))
258 {
259 fScale /= 2;
260 return kTRUE;
261 }
262
263 if ((fabs(avgx)< 5. && fabs(avgy)<20.) ||
264 (fabs(avgx)<20. && fabs(avgy)< 5.))
265 {
266 fScale *= 2;
267 return kTRUE;
268 }
269
270 return kFALSE;
271}
272
273void MGVelocity::UpdateVelText(Float_t vx, Float_t vy)
274{
275 static int X = ~0;
276 static int Y = ~0;
277
278 vx /= 60.; //['/min]
279 vy /= 60.; //['/min]
280
281 int fx = (int)floor(vx*10.);
282 int fy = (int)floor(vy*10.);
283
284 if (X==fx && Y==fy)
285 return;
286
287 X = fx;
288 Y = fy;
289
290 char txt[100];
291 sprintf(txt, "Zd=%.1f'\nAz=%.1f'",
292 vx, vy);
293
294 fTextVel->SetText(fTextVel->GetX(), fTextVel->GetY(), txt);
295}
296
297void MGVelocity::Update(ZdAz &zdaz)
298{
299 //
300 // calculate actual time for planet positions
301 //
302 // static int X = 0xaffe;
303 // static int Y = 0xaffe;
304
305 float vx = zdaz.Az()*3600.; // ["/min]
306 float vy = zdaz.Zd()*3600.; // ["/min]
307
308 UpdateVelText(vx, vy);
309
310 int pixx = (int)(vx*fScale/fPix);
311 int pixy = (int)(vy*fScale/fPix);
312
313 //
314 // FIXME! Check for the right place!
315 //
316 Bool_t rc = kFALSE;
317
318 if (pixx || pixy)
319 rc = UpdateAvg(vx, vy);
320
321 if (rc)
322 UpdateText();
323
324 if (!rc && (int)fOld->X()==pixx && (int)fOld->Y()==pixy)
325 return;
326
327 // cout << fScale << ": " << pixx << " " << pixy;
328 // cout << fScale << ": " << (int)rc << (int)((int)fOld->X()==pixx) << (int)((int)fOld->Y()==pixy) << " ";
329 // cout << zdaz.Az()*3600. << " " << zdaz.Zd()*3600. << endl;
330
331 vx *= fScale;
332 vy *= fScale;
333
334 fArrow->SetX2(vx);
335 fArrow->SetY2(vy);
336
337 fArrowX->SetX2(vx);
338 fArrowY->SetY2(vy);
339
340 fOld->Set(pixx, pixy);
341
342 SetModified();
343 UpdateCanvas();
344}
Note: See TracBrowser for help on using the repository browser.