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

Last change on this file since 1701 was 1701, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 7.8 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->SetLabelOffset(-0.02);
126 axe->SetBit(kCanDelete);
127 axe->Draw();
128}
129
130void MGVelocity::InitVelocity()
131{
132 /*
133 fLin1 = new TLine(0, 0, 0, 0);
134 fLin2 = new TLine(0, 0, 0, 0);
135
136 fLin1->SetLineColor(10); // white (s. TAttFill)
137 fLin2->SetLineColor(10); // white
138 fLin1->SetLineStyle(1); // solid (s. TAttLine)
139 fLin2->SetLineStyle(1);
140
141 fLin1->Draw();
142 fLin2->Draw();
143
144 fList->Add(fLin1);
145 fList->Add(fLin2);
146 */
147 fArrow = new TArrow(0, 0, 0, 0, 0.01);
148 fArrowX = new TArrow(0, 0, 0, 0, 0.01);
149 fArrowY = new TArrow(0, 0, 0, 0, 0.01);
150 fArrowAvg = new TArrow(0, 0, 0, 0, 0.01);
151
152 fArrow->SetLineColor(10); // white
153 fArrowX->SetLineColor(17); // light gray
154 fArrowY->SetLineColor(17); // light gray
155 fArrowAvg->SetLineColor(137); // light gray
156
157 fArrow->Draw();
158 fArrowX->Draw();
159 fArrowY->Draw();
160 fArrowAvg->Draw();
161
162 fList->Add(fArrow);
163 fList->Add(fArrowX);
164 fList->Add(fArrowY);
165 fList->Add(fArrowAvg);
166
167 fText = new TText(70*2, -70*2, "x1");
168 fText->SetTextColor(10);
169 fText->SetTextAlign(31); // right, bottom
170 fText->Draw();
171 fList->Add(fText);
172
173 fTextVel = new TText(2*70, 2*70, "");
174 fTextVel->SetTextAlign(33); // right, top
175 fTextVel->SetTextColor(10); // white
176 fTextVel->Draw();
177 fList->Add(fTextVel);
178}
179
180MGVelocity::MGVelocity(const TGWindow* p, const char *name, const UInt_t w)
181: MGEmbeddedCanvas(name, p, w, 75*2), fPos(-1), fScale(1)
182{
183 fOld = new XY;
184 fAvg = new XY[10];
185
186 DrawCoordinateSystem();
187 InitVelocity();
188
189 InitCanvas();
190}
191
192MGVelocity::~MGVelocity()
193{
194 delete fOld;
195 delete fAvg;
196
197 // cout << "MGVelocity destroyed." << endl;
198}
199
200void MGVelocity::UpdateText()
201{
202 char txt[10];
203
204 if (fScale>1)
205 sprintf(txt, "/%.0f", fScale);
206 else
207 sprintf(txt, "x%.0f", 1./fScale);
208
209 fText->SetText(fText->GetX(), fText->GetY(), txt);
210}
211
212Bool_t MGVelocity::UpdateAvg(const float x, const float y)
213{
214
215 //
216 // calculate scale factor from avarage over
217 // speed, not pixels
218 //
219 // different scales for Az and Zd
220 //
221 // check for the number of the value
222 //
223 //
224 const int num = 10;
225
226 // static int pos = -1;
227 // static XY avg[num];
228
229 if (fPos<0)
230 for (int i=1; i<num; i++)
231 fAvg[i].Set(x, y);
232
233 fPos++;
234 fPos %= num;
235
236 fAvg[fPos].Set(x, y);
237
238 Float_t avgx = 0;
239 Float_t avgy = 0;
240
241 for (int i=0; i<num; i++)
242 {
243 avgx += fAvg[i].X();
244 avgy += fAvg[i].Y();
245 }
246
247 avgx /= 10.;
248 avgy /= 10.;
249
250 avgx *= fScale;
251 avgy *= fScale;
252
253 fArrowAvg->SetX2(avgx);
254 fArrowAvg->SetY2(avgy);
255
256 // cout << avgx << " " << avgy << endl;
257
258 if ((fabs(avgx)>/*40.*/110. || fabs(avgy)>/*40.*/110.))
259 {
260 fScale /= 2;
261 return kTRUE;
262 }
263
264 if ((fabs(avgx)< 5. && fabs(avgy)<20.) ||
265 (fabs(avgx)<20. && fabs(avgy)< 5.))
266 {
267 fScale *= 2;
268 return kTRUE;
269 }
270
271 return kFALSE;
272}
273
274void MGVelocity::UpdateVelText(Float_t vx, Float_t vy)
275{
276 static int X = ~0;
277 static int Y = ~0;
278
279 vx /= 60.; //['/min]
280 vy /= 60.; //['/min]
281
282 int fx = (int)/*floor*/(vx*10.);
283 int fy = (int)/*floor*/(vy*10.);
284
285 if (X==fx && Y==fy)
286 return;
287
288 X = fx;
289 Y = fy;
290
291 char txt[100];
292 sprintf(txt, "Zd=%.1f'\nAz=%.1f'",
293 vy, vx);
294
295 fTextVel->SetText(fTextVel->GetX(), fTextVel->GetY(), txt);
296}
297
298void MGVelocity::Update(ZdAz &zdaz)
299{
300 //
301 // calculate actual time for planet positions
302 //
303 // static int X = 0xaffe;
304 // static int Y = 0xaffe;
305
306 float vx = zdaz.Az()*3600.; // ["/min]
307 float vy = zdaz.Zd()*3600.; // ["/min]
308
309 UpdateVelText(vx, vy);
310
311 int pixx = (int)(vx*fScale/fPix);
312 int pixy = (int)(vy*fScale/fPix);
313
314 //
315 // FIXME! Check for the right place!
316 //
317 Bool_t rc = kFALSE;
318
319 if (pixx || pixy)
320 rc = UpdateAvg(vx, vy);
321
322 if (rc)
323 UpdateText();
324
325 if (!rc && (int)fOld->X()==pixx && (int)fOld->Y()==pixy)
326 return;
327
328 // cout << fScale << ": " << pixx << " " << pixy;
329 // cout << fScale << ": " << (int)rc << (int)((int)fOld->X()==pixx) << (int)((int)fOld->Y()==pixy) << " ";
330 // cout << zdaz.Az()*3600. << " " << zdaz.Zd()*3600. << endl;
331
332 vx *= fScale;
333 vy *= fScale;
334
335 fArrow->SetX2(vx);
336 fArrow->SetY2(vy);
337
338 fArrowX->SetX2(vx);
339 fArrowY->SetY2(vy);
340
341 fOld->Set(pixx, pixy);
342
343 SetModified();
344 UpdateCanvas();
345}
Note: See TracBrowser for help on using the repository browser.