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

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