source: trunk/MagicSoft/Cosy/gui/MGAccuracy.cc@ 8238

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