source: trunk/Cosy/gui/MGVelocity.cc@ 18450

Last change on this file since 18450 was 8847, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 4.2 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
20ClassImp(MGVelocity);
21
22void MGVelocity::DrawCoordinateSystem()
23{
24 TWbox box;
25 box.DrawWbox(-145, 145, -35, 120, 18, 2, 1);
26
27 TText text;
28 text.SetTextAlign(22); // centered, centered (s.TAttText)
29 text.DrawText(-90., 132.5, fCanvas->GetName());
30
31
32 TLine line;
33 line.DrawLine(-65*2, 0, 65*2, 0);
34 line.DrawLine( 0, -65*2, 0, 65*2);
35
36 //
37 // Can be replaced by TGaxis axe; in a later root version
38 // than 3.01/06. I talked to Rene
39 //
40 TGaxis *axe;
41 axe = new TGaxis(-60*2, 0, 60*2, 0, -2, 2, 304, "+-N");
42 axe->SetTitle("Az"); // \xb0
43 axe->SetBit(kCanDelete);
44 axe->Draw();
45
46 axe = new TGaxis(0, -60*2, 0, 60*2, -2, 2, 304, "+-N");
47 axe->SetTitle("Zd"); // \xb0
48 axe->SetLabelOffset(-0.02);
49 axe->SetBit(kCanDelete);
50 axe->Draw();
51}
52
53void MGVelocity::InitVelocity()
54{
55 fArrow = new TArrow(0, 0, 0, 0, 0.01);
56 fArrowX = new TArrow(0, 0, 0, 0, 0.01);
57 fArrowY = new TArrow(0, 0, 0, 0, 0.01);
58 fArrowAvg = new TArrow(0, 0, 0, 0, 0.01);
59
60 fArrow->SetLineColor(10); // white
61 fArrowX->SetLineColor(17); // light gray
62 fArrowY->SetLineColor(17); // light gray
63 fArrowAvg->SetLineColor(137); // light gray
64
65 fArrow->Draw();
66 fArrowX->Draw();
67 fArrowY->Draw();
68 fArrowAvg->Draw();
69
70 fList->Add(fArrow);
71 fList->Add(fArrowX);
72 fList->Add(fArrowY);
73 fList->Add(fArrowAvg);
74
75 fText = new TText(70*2, -70*2, "x1");
76 fText->SetTextColor(10);
77 fText->SetTextAlign(31); // right, bottom
78 fText->Draw();
79 fList->Add(fText);
80}
81
82MGVelocity::MGVelocity(const TGWindow* p, const char *name, const UInt_t w)
83: MGEmbeddedCanvas(name, p, w, 75*2), fPos(-1), fScale(1)
84{
85 fOld = new XY;
86 fAvg = new XY[10];
87
88 DrawCoordinateSystem();
89 InitVelocity();
90
91 InitCanvas();
92
93 SetNoContextMenu();
94}
95
96MGVelocity::~MGVelocity()
97{
98 delete fOld;
99 delete fAvg;
100
101 // cout << "MGVelocity destroyed." << endl;
102}
103
104void MGVelocity::UpdateText()
105{
106 char txt[10];
107
108 if (fScale>1)
109 sprintf(txt, "/%.0f", fScale);
110 else
111 sprintf(txt, "x%.0f", 1./fScale);
112
113 fText->SetText(fText->GetX(), fText->GetY(), txt);
114}
115
116Bool_t MGVelocity::UpdateAvg(const float x, const float y)
117{
118
119 //
120 // calculate scale factor from avarage over
121 // speed, not pixels
122 //
123 // different scales for Az and Zd
124 //
125 // check for the number of the value
126 //
127 //
128 const int num = 10;
129
130 // static int pos = -1;
131 // static XY avg[num];
132
133 if (fPos<0)
134 for (int i=1; i<num; i++)
135 fAvg[i].Set(x, y);
136
137 fPos++;
138 fPos %= num;
139
140 fAvg[fPos].Set(x, y);
141
142 Float_t avgx = 0;
143 Float_t avgy = 0;
144
145 for (int i=0; i<num; i++)
146 {
147 avgx += fAvg[i].X();
148 avgy += fAvg[i].Y();
149 }
150
151 avgx /= 10.;
152 avgy /= 10.;
153
154 avgx *= fScale;
155 avgy *= fScale;
156
157 fArrowAvg->SetX2(avgx);
158 fArrowAvg->SetY2(avgy);
159
160 if ((fabs(avgx)>/*40.*/110. || fabs(avgy)>/*40.*/110.))
161 {
162 fScale /= 2;
163 return kTRUE;
164 }
165
166 if ((fabs(avgx)< 5. && fabs(avgy)<20.) ||
167 (fabs(avgx)<20. && fabs(avgy)< 5.))
168 {
169 fScale *= 2;
170 return kTRUE;
171 }
172
173 return kFALSE;
174}
175
176void MGVelocity::Update(ZdAz &zdaz)
177{
178 //
179 // calculate actual time for planet positions
180 //
181 float vx = zdaz.Az(); // [U_mot/min]
182 float vy = zdaz.Zd(); // [U_mot/min]
183
184 int pixx = (int)(vx*fScale/fPix);
185 int pixy = (int)(vy*fScale/fPix);
186
187 //
188 // FIXME! Check for the right place!
189 //
190 Bool_t rc = kFALSE;
191
192 if (pixx || pixy)
193 rc = UpdateAvg(vx, vy);
194
195 if (rc)
196 UpdateText();
197
198 if (!rc && (int)fOld->X()==pixx && (int)fOld->Y()==pixy)
199 return;
200
201 vx *= fScale;
202 vy *= fScale;
203
204 fArrow->SetX2(vx);
205 fArrow->SetY2(vy);
206
207 fArrowX->SetX2(vx);
208 fArrowY->SetY2(vy);
209
210 fOld->Set(pixx, pixy);
211
212 SetModified();
213 UpdateCanvas();
214}
Note: See TracBrowser for help on using the repository browser.