source: trunk/Cosy/gui/MGNumStars.cc@ 20046

Last change on this file since 20046 was 8376, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 3.4 KB
Line 
1#include "MGNumStars.h"
2
3#include <iostream> // cout
4
5#include <TLine.h>
6#include <TText.h>
7#include <TWbox.h>
8#include <TGaxis.h>
9#include <TGraph.h>
10#include <TCanvas.h>
11
12#include "MTime.h"
13
14ClassImp(MGNumStars);
15
16using namespace std;
17
18void MGNumStars::DrawText(const char*txt)
19{
20 fCanvas->SetEditable(kTRUE);
21 fCanvas->cd();
22
23 TText text;
24 text.SetTextAlign(22); // centered, centered (s.TAttText)
25 text.SetTextSize(0.12);
26 text.DrawText(275, 44, txt);
27
28 fCanvas->SetEditable(kFALSE);
29}
30
31void MGNumStars::DrawCoordinateSystem()
32{
33 fCanvas->Range(-50, -4, 600, 50);
34
35 TWbox box;
36 box.DrawWbox(325-150-50, 38, 325+150-50, 48, 18, 2, 1);
37
38 TLine line;
39 line.DrawLine(0, 0, 600-25, 0);
40 line.SetLineStyle(kDashed);
41 line.SetLineColor(kRed);
42 line.DrawLine(0, 6.5, 600-25, 6.5);
43 line.SetLineColor(kYellow);
44 line.DrawLine(0, 10.5, 600-25, 10.5);
45
46 TGaxis *axe;
47 axe = new TGaxis(0, 0, 0, 47.5, 0, 47.5, 304, "-");
48 axe->SetLabelSize(0.1);
49 axe->SetLabelOffset(0.02);
50 axe->SetBit(kCanDelete);
51 axe->Draw();
52}
53
54void MGNumStars::InitText()
55{
56 fTxt = new TText(600*0.97, 50*0.92, "0/0");
57 fTxt->SetTextAlign(33); // right, top
58 fTxt->SetTextColor(10);
59 fTxt->SetTextSize(0.12);
60 fTxt->Draw();
61
62 fList->Add(fTxt);
63}
64
65void MGNumStars::InitBar(TLine* &bar)
66{
67 bar = new TLine(0, 0, 0, 0);
68 bar->SetLineColor(kBlack);
69 bar->SetLineStyle(1);
70 bar->SetLineWidth(5);
71 bar->Draw();
72
73 fList->Add(bar);
74}
75
76void MGNumStars::InitGraph(TGraph* &graph, Int_t col)
77{
78 graph = new TGraph;
79 graph->SetPoint(0, 0, 0);
80 graph->SetLineColor(col);
81 graph->SetMarkerColor(col);
82 graph->SetMarkerStyle(kFullDotMedium);
83 graph->Draw("LP");
84 fList->Add(graph);
85}
86
87MGNumStars::MGNumStars(const TGWindow* p, const UInt_t w)
88: MGEmbeddedCanvas("NumStars", p, w, 300)
89{
90 DrawCoordinateSystem();
91
92 InitGraph(fGraph1, kBlue);
93 InitGraph(fGraph2, kCyan);
94
95 InitText();
96 InitBar(fBar1);
97 InitBar(fBar2);
98
99 InitCanvas();
100
101 Resize(245, 100);
102
103 SetNoContextMenu();
104
105 MTime t(-1);
106 fTime = t.GetAxisTime();
107}
108
109MGNumStars::~MGNumStars()
110{
111}
112
113// dist [deg]
114void MGNumStars::UpdateBar(TLine &bar, UInt_t num)
115{
116 bar.SetY2(num);
117 if (num<11)
118 bar.SetLineColor(kYellow);
119 else
120 if (num<7)
121 bar.SetLineColor(kRed);
122 else
123 bar.SetLineColor(kGreen);
124
125 SetModified();
126}
127
128// dist [deg]
129void MGNumStars::UpdateGraph(TGraph &graph, Double_t dtime, UInt_t num)
130{
131 graph.SetPoint(graph.GetN(), dtime, num);
132
133 const Double_t ntime = dtime;
134 for (int i=0; i<graph.GetN(); i++)
135 {
136 Double_t x, y;
137 graph.GetPoint(i, x, y);
138 graph.SetPoint(i, x+ntime, y);
139 }
140 while (graph.GetN()>0)
141 {
142 Double_t x, y;
143 graph.GetPoint(0, x, y);
144
145 if (x==+ntime && y==0)
146 {
147 graph.RemovePoint(0);
148 continue;
149 }
150
151 if (x<2*4.75*60)
152 break;
153
154 graph.RemovePoint(0);
155 }
156
157 SetModified();
158}
159
160void MGNumStars::Update(UInt_t det, UInt_t cor)
161{
162 char txt[100];
163 sprintf(txt, "%d/%d", cor, det);
164 fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
165
166 UpdateBar(*fBar1, det);
167 UpdateBar(*fBar2, cor);
168
169 MTime t(-1);
170 const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h]
171
172 UpdateGraph(*fGraph1, dtime, det);
173 UpdateGraph(*fGraph2, dtime, cor);
174
175 fTime = t.GetAxisTime();
176
177 UpdateCanvas();
178}
Note: See TracBrowser for help on using the repository browser.