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

Last change on this file since 1997 was 1702, 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 SetNoContextMenu();
192}
193
194MGVelocity::~MGVelocity()
195{
196 delete fOld;
197 delete fAvg;
198
199 // cout << "MGVelocity destroyed." << endl;
200}
201
202void MGVelocity::UpdateText()
203{
204 char txt[10];
205
206 if (fScale>1)
207 sprintf(txt, "/%.0f", fScale);
208 else
209 sprintf(txt, "x%.0f", 1./fScale);
210
211 fText->SetText(fText->GetX(), fText->GetY(), txt);
212}
213
214Bool_t MGVelocity::UpdateAvg(const float x, const float y)
215{
216
217 //
218 // calculate scale factor from avarage over
219 // speed, not pixels
220 //
221 // different scales for Az and Zd
222 //
223 // check for the number of the value
224 //
225 //
226 const int num = 10;
227
228 // static int pos = -1;
229 // static XY avg[num];
230
231 if (fPos<0)
232 for (int i=1; i<num; i++)
233 fAvg[i].Set(x, y);
234
235 fPos++;
236 fPos %= num;
237
238 fAvg[fPos].Set(x, y);
239
240 Float_t avgx = 0;
241 Float_t avgy = 0;
242
243 for (int i=0; i<num; i++)
244 {
245 avgx += fAvg[i].X();
246 avgy += fAvg[i].Y();
247 }
248
249 avgx /= 10.;
250 avgy /= 10.;
251
252 avgx *= fScale;
253 avgy *= fScale;
254
255 fArrowAvg->SetX2(avgx);
256 fArrowAvg->SetY2(avgy);
257
258 // cout << avgx << " " << avgy << endl;
259
260 if ((fabs(avgx)>/*40.*/110. || fabs(avgy)>/*40.*/110.))
261 {
262 fScale /= 2;
263 return kTRUE;
264 }
265
266 if ((fabs(avgx)< 5. && fabs(avgy)<20.) ||
267 (fabs(avgx)<20. && fabs(avgy)< 5.))
268 {
269 fScale *= 2;
270 return kTRUE;
271 }
272
273 return kFALSE;
274}
275
276void MGVelocity::UpdateVelText(Float_t vx, Float_t vy)
277{
278 static int X = ~0;
279 static int Y = ~0;
280
281 vx /= 60.; //['/min]
282 vy /= 60.; //['/min]
283
284 int fx = (int)/*floor*/(vx*10.);
285 int fy = (int)/*floor*/(vy*10.);
286
287 if (X==fx && Y==fy)
288 return;
289
290 X = fx;
291 Y = fy;
292
293 char txt[100];
294 sprintf(txt, "Zd=%.1f'\nAz=%.1f'",
295 vy, vx);
296
297 fTextVel->SetText(fTextVel->GetX(), fTextVel->GetY(), txt);
298}
299
300void MGVelocity::Update(ZdAz &zdaz)
301{
302 //
303 // calculate actual time for planet positions
304 //
305 // static int X = 0xaffe;
306 // static int Y = 0xaffe;
307
308 float vx = zdaz.Az()*3600.; // ["/min]
309 float vy = zdaz.Zd()*3600.; // ["/min]
310
311 UpdateVelText(vx, vy);
312
313 int pixx = (int)(vx*fScale/fPix);
314 int pixy = (int)(vy*fScale/fPix);
315
316 //
317 // FIXME! Check for the right place!
318 //
319 Bool_t rc = kFALSE;
320
321 if (pixx || pixy)
322 rc = UpdateAvg(vx, vy);
323
324 if (rc)
325 UpdateText();
326
327 if (!rc && (int)fOld->X()==pixx && (int)fOld->Y()==pixy)
328 return;
329
330 // cout << fScale << ": " << pixx << " " << pixy;
331 // cout << fScale << ": " << (int)rc << (int)((int)fOld->X()==pixx) << (int)((int)fOld->Y()==pixy) << " ";
332 // cout << zdaz.Az()*3600. << " " << zdaz.Zd()*3600. << endl;
333
334 vx *= fScale;
335 vy *= fScale;
336
337 fArrow->SetX2(vx);
338 fArrow->SetY2(vy);
339
340 fArrowX->SetX2(vx);
341 fArrowY->SetY2(vy);
342
343 fOld->Set(pixx, pixy);
344
345 SetModified();
346 UpdateCanvas();
347}
Note: See TracBrowser for help on using the repository browser.