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

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