source: trunk/Cosy/gui/MGAccuracy.cc@ 19847

Last change on this file since 19847 was 8847, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 6.0 KB
Line 
1#include "MGAccuracy.h"
2
3#include <iostream> // cout
4
5#include <TArc.h>
6#include <TLine.h>
7#include <TText.h>
8#include <TWbox.h>
9#include <TGaxis.h>
10#include <TGraph.h>
11#include <TCanvas.h>
12
13#include "MTime.h"
14#include "MAstro.h"
15#include "MPointing.h"
16
17ClassImp(MGAccuracy);
18
19using namespace std;
20
21void MGAccuracy::DrawText(const char *c1, const char *c2, const char *c3, const char*txt)
22{
23 fCanvas->SetEditable(kTRUE);
24 fCanvas->cd();
25
26 TText text;
27 text.SetTextAlign(22); // centered, centered (s.TAttText)
28 text.DrawText(-150, 265, txt);
29
30 text.SetTextAlign(11); // left, bottom (s.TAttText)
31 text.SetTextColor(3);
32 text.DrawText(220, -220, c1);
33
34 text.SetTextColor(5);
35 text.DrawText(220, -250, c2);
36
37 text.SetTextColor(2);
38 text.DrawText(220, -280, c3);
39
40 fCanvas->SetEditable(kFALSE);
41}
42
43void MGAccuracy::DrawCircles(Double_t rad)
44{
45 fCanvas->SetEditable(kTRUE);
46 fCanvas->cd();
47
48 TArc arc;
49 arc.SetFillStyle(4000); // transparent
50 arc.SetFillColor(39);
51 arc.SetLineColor(3); // green
52 arc.SetLineStyle(2); // dashed (s. TAttLine)
53 arc.DrawArc(0, 0, rad/2.); // 0.5se
54
55 arc.SetLineColor(5); // yellow
56 arc.DrawArc(0, 0, rad); // 1.0se
57
58 arc.SetLineColor(2); // red
59 arc.DrawArc(0, 0, rad*2.); // 2.0se
60
61 fCanvas->SetEditable(kFALSE);
62}
63
64void MGAccuracy::DrawCoordinateSystem()
65{
66 TWbox box;
67 box.DrawWbox(-290, 290, -10, 240, 18, 2, 1);
68
69// TLine line;
70// line.DrawLine(-65*4, 0, 65*4, 0);
71// line.DrawLine( 0, -65*4, 0, 65*4);
72
73 //
74 // Can be replaced by TGaxis axe; in a later root version
75 // than 3.01/06. I talked to Rene
76 //
77 TGaxis *axe;
78 axe = new TGaxis(-60*4, 0, 60*4, 0, -4, 4, 30204, "+-N");
79 axe->SetTitle("Az"); // \xb0
80 axe->SetBit(kCanDelete);
81 axe->Draw();
82
83 axe = new TGaxis( 0, -60*4, 0, 60*4, -4, 4, 304, "+-N");
84 axe->SetTitle("Zd"); // \xb0
85 axe->SetLabelOffset(-0.02);
86 axe->SetBit(kCanDelete);
87 axe->Draw();
88}
89
90void MGAccuracy::InitText()
91{
92 fTxt = new TText(280, 280, "0' / 0'");
93 fTxt->SetTextAlign(33); // right, top
94 fTxt->SetTextColor(10);
95 fTxt->Draw();
96
97 fList->Add(fTxt);
98}
99
100void MGAccuracy::InitBar()
101{
102 fBar = new TLine(0, 0, 0, 0);
103 fBar->SetLineColor(kBlack);
104 fBar->SetLineStyle(1);
105 fBar->SetLineWidth(5);
106 fBar->Draw();
107
108 fList->Add(fBar);
109}
110
111void MGAccuracy::InitCross()
112{
113 fLin1 = new TLine(0, 0, 0, 0);
114 fLin2 = new TLine(0, 0, 0, 0);
115
116 fLin1->SetLineColor(10); // white (s. TAttFill)
117 fLin2->SetLineColor(10); // white
118 fLin1->SetLineStyle(1); // solid (s. TAttLine)
119 fLin2->SetLineStyle(1);
120
121 fLin1->SetLineWidth(2);
122 fLin2->SetLineWidth(2);
123
124 fLin1->Draw();
125 fLin2->Draw();
126
127 fList->Add(fLin1);
128 fList->Add(fLin2);
129}
130
131MGAccuracy::MGAccuracy(const TGWindow* p, const UInt_t w)
132: MGEmbeddedCanvas("Accuracy", p, w, 300), fColorScale(360*60/16384)
133{
134 // FIXME: Overload MapWindow in newer Root versions to remove
135 // the contents of the graph!
136 fGraph = new TGraph;
137 fGraph->SetPoint(0, 0, 0);
138 fGraph->SetLineColor(kBlue);
139 fGraph->SetMarkerColor(kBlue);
140 fGraph->SetMarkerStyle(kFullDotMedium);
141 fGraph->Draw("LP");
142 fList->Add(fGraph);
143
144 DrawCoordinateSystem();
145
146 InitText();
147 InitCross();
148 InitBar();
149
150 InitCanvas();
151
152 SetNoContextMenu();
153
154 MTime t(-1);
155 fTime = t.GetAxisTime();
156}
157
158MGAccuracy::~MGAccuracy()
159{
160}
161
162// dist [deg]
163void MGAccuracy::UpdateText(Float_t dist)
164{
165 dist *= 3600.; // [sec]
166
167 int rs = TMath::FloorNint(fmod(dist, (float)60.));
168
169 dist /= 60.; // [min]
170 int rm = (int)dist;
171
172 char txt[100];
173 rm ? sprintf(txt, "%d'%02d\"", rm, rs) : sprintf(txt, "%d\"", rs);
174
175 fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
176
177 fBar->SetY2(dist*60); // [sec]
178 if (dist<fColorScale) //1*360*60/16384
179 fBar->SetLineColor(kGreen);
180 else
181 if (dist<2*fColorScale) //2*360*60/16384
182 fBar->SetLineColor(kYellow);
183 else
184 fBar->SetLineColor(kRed);
185
186 SetModified();
187}
188
189// dist [deg]
190void MGAccuracy::UpdateGraph(Float_t dist)
191{
192 MTime t(-1);
193 const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h]
194
195 dist *= 60; // min
196
197 static int odist = -1;
198 if (odist==(int)(dist*10*60) && dtime<10)
199 return;
200
201 odist = (int)(dist*10*60);
202
203 fGraph->SetPoint(fGraph->GetN(), dtime, dist*60);
204
205 const Double_t ntime = dtime;
206 for (int i=0; i<fGraph->GetN(); i++)
207 {
208 Double_t x, y;
209 fGraph->GetPoint(i, x, y);
210 fGraph->SetPoint(i, x-ntime, y);
211 //cout << i << ": " << x-ntime << " / " << y << endl;
212 }
213 while (fGraph->GetN()>0)
214 {
215 Double_t x, y;
216 fGraph->GetPoint(0, x, y);
217
218 if (x==-ntime && y==0)
219 {
220 fGraph->RemovePoint(0);
221 continue;
222 }
223
224 if (x>-4.75*60)
225 break;
226
227 fGraph->RemovePoint(0);
228 }
229
230 fTime = t.GetAxisTime();
231
232 SetModified();
233}
234
235void MGAccuracy::Update(Float_t pzd, Float_t azd, Float_t aaz)
236{
237 const double dist = MAstro::GetDevAbs(pzd, azd, aaz);
238
239 UpdateText(dist);
240 UpdateGraph(dist);
241}
242
243void MGAccuracy::UpdateCross(Float_t x, Float_t y)
244{
245 //
246 // x["], y["]
247 //
248 static int X = ~0;
249 static int Y = ~0;
250
251 int pixx = (int)(x/fPix); // [pix]
252 int pixy = (int)(y/fPix); // [pix]
253
254 if (X==pixx && Y==pixy)
255 return;
256
257 X = pixx;
258 Y = pixy;
259
260 fLin1->SetX1(x-5.);
261 fLin1->SetX2(x+5.);
262
263 fLin2->SetX1(x-5.);
264 fLin2->SetX2(x+5.);
265
266 fLin1->SetY1(y-5.);
267 fLin1->SetY2(y+5.);
268
269 fLin2->SetY1(y+5.);
270 fLin2->SetY2(y-5.);
271
272 SetModified();
273}
274
275void MGAccuracy::Update(ZdAz &pos, ZdAz &dev)
276{
277 // Estimate the distance in az direction on the camera plane
278 const double daz = MAstro::GetDevAbs(pos.Zd(), 0, dev.Az())*3600.;
279
280 //cout << "--> T: " << dev.Az()*60 << " " << dev.Zd()*60. << endl;
281
282 UpdateCross(TMath::Sign(daz, dev.Az()), dev.Zd()*3600.);
283 Update(pos.Zd(), dev.Zd(), dev.Az());
284
285 UpdateCanvas();
286}
Note: See TracBrowser for help on using the repository browser.