]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // Category: graphics | |
3 | // | |
4 | // Class AliMpZonePainter | |
5 | // ---------------------- | |
6 | // Class for drawing a zone into canvas | |
7 | // | |
8 | // Authors: David Guez, IPN Orsay | |
9 | ||
2998a151 | 10 | #include <TVirtualX.h> |
11 | #include <TPad.h> | |
fb1bf5c0 | 12 | #include <TError.h> |
2998a151 | 13 | |
5f91c9e8 | 14 | #include "AliMpZonePainter.h" |
15 | #include "AliMpGraphContext.h" | |
16 | #include "AliMpZone.h" | |
17 | #include "AliMpSubZone.h" | |
18 | #include "AliMpVRowSegment.h" | |
5f91c9e8 | 19 | |
20 | ClassImp(AliMpZonePainter) | |
21 | ||
22 | //_______________________________________________________________________ | |
23 | AliMpZonePainter::AliMpZonePainter() | |
24 | : AliMpVPainter(), | |
25 | fZone(0) | |
26 | { | |
27 | // default dummy constructor | |
28 | } | |
29 | ||
30 | //_______________________________________________________________________ | |
31 | AliMpZonePainter::AliMpZonePainter(AliMpZone *zone) | |
32 | : AliMpVPainter(), | |
33 | fZone(zone) | |
34 | { | |
35 | // normal constructor | |
36 | ||
37 | } | |
38 | ||
fb1bf5c0 | 39 | //_____________________________________________________________________________ |
40 | AliMpZonePainter::AliMpZonePainter(const AliMpZonePainter& right) | |
41 | : AliMpVPainter(right) | |
42 | { | |
43 | // copy constructor (not implemented) | |
44 | ||
45 | Fatal("AliMpZonePainter", "Copy constructor not provided."); | |
46 | } | |
47 | ||
5f91c9e8 | 48 | //_______________________________________________________________________ |
2998a151 | 49 | AliMpZonePainter::~AliMpZonePainter() |
50 | { | |
51 | // destructor | |
52 | ||
53 | } | |
54 | ||
fb1bf5c0 | 55 | //_____________________________________________________________________________ |
56 | AliMpZonePainter& | |
57 | AliMpZonePainter::operator=(const AliMpZonePainter& right) | |
58 | { | |
59 | // assignement operator (not implemented) | |
60 | ||
61 | // check assignement to self | |
62 | if (this == &right) return *this; | |
63 | ||
64 | Fatal("operator =", "Assignement operator not provided."); | |
65 | ||
66 | return *this; | |
67 | } | |
68 | ||
2998a151 | 69 | //_______________________________________________________________________ |
5f91c9e8 | 70 | Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y) |
71 | { | |
72 | // dist to the nearest segment center if (x,y) is inside the zone | |
73 | // 9999 otherwise | |
74 | if (fZone->GetNofSubZones()<1) return 9999; | |
75 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
76 | ||
77 | gr->Push(); | |
78 | InitGraphContext(); | |
79 | ||
80 | TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y)); | |
81 | ||
82 | Double_t res=9999.; | |
83 | for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){ | |
84 | // for each sub-zones | |
85 | AliMpSubZone* sub = fZone->GetSubZone(isub); | |
86 | for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){ | |
87 | //for each row segments | |
88 | AliMpVRowSegment* seg = sub->GetRowSegment(iseg); | |
89 | ||
90 | TVector2 pos,dim; | |
91 | gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim); | |
92 | ||
93 | if ( IsInside(point,pos,dim) ){ | |
94 | Double_t value = (point-pos).Mod(); | |
95 | if (value<res) res=value; | |
96 | } | |
97 | } | |
98 | } | |
99 | gr->Pop(); | |
100 | return (Int_t)res; | |
101 | } | |
102 | ||
103 | //_______________________________________________________________________ | |
104 | void AliMpZonePainter::DumpObject() | |
105 | { | |
106 | // Draw the owned object | |
107 | fZone->Dump(); | |
108 | ||
109 | } | |
110 | ||
111 | //_______________________________________________________________________ | |
112 | TVector2 AliMpZonePainter::GetPosition() const | |
113 | { | |
114 | // Get the owned object's position | |
115 | ||
116 | if (fZone->GetNofSubZones()<1) return TVector2(0.,0.); | |
117 | ||
118 | TVector2 bl(9999,9999),ur(-9999,-9999); | |
119 | ||
120 | for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){ | |
121 | // for each sub-zones | |
122 | AliMpSubZone* sub = fZone->GetSubZone(isub); | |
123 | for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){ | |
124 | //for each row segments | |
125 | AliMpVRowSegment* seg = sub->GetRowSegment(iseg); | |
126 | ||
127 | // update the bottom-left corner | |
128 | if (bl.X()>seg->Position().X()-seg->Dimensions().X()) | |
129 | bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y()); | |
130 | if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y()) | |
131 | bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y()); | |
132 | // update the upper-right corner | |
133 | if (ur.X()<seg->Position().X()+seg->Dimensions().X()) | |
134 | ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y()); | |
135 | if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y()) | |
136 | ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y()); | |
137 | } //iseg | |
138 | } //isub | |
139 | return (ur+bl)/2.; | |
140 | } | |
141 | ||
142 | //_______________________________________________________________________ | |
143 | TVector2 AliMpZonePainter::GetDimensions() const | |
144 | { | |
145 | // Get the owned object's dimensions | |
146 | ||
147 | if (fZone->GetNofSubZones()<1) return TVector2(0.,0.); | |
148 | ||
149 | TVector2 bl(9999,9999),ur(-9999,-9999); | |
150 | ||
151 | for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){ | |
152 | // for each sub-zones | |
153 | AliMpSubZone* sub = fZone->GetSubZone(isub); | |
154 | for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){ | |
155 | //for each row segments | |
156 | AliMpVRowSegment* seg = sub->GetRowSegment(iseg); | |
157 | ||
158 | // update the bottom-left corner | |
159 | if (bl.X()>seg->Position().X()-seg->Dimensions().X()) | |
160 | bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y()); | |
161 | if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y()) | |
162 | bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y()); | |
163 | // update the upper-right corner | |
164 | if (ur.X()<seg->Position().X()+seg->Dimensions().X()) | |
165 | ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y()); | |
166 | if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y()) | |
167 | ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y()); | |
168 | } //iseg | |
169 | } //isub | |
170 | return (ur-bl)/2.; | |
171 | } | |
172 | ||
173 | //_______________________________________________________________________ | |
174 | void AliMpZonePainter::Draw(Option_t *option) | |
175 | { | |
176 | // Draw the sector on the current pad | |
177 | // The first letter of <option> is treated as follows: | |
178 | // case "S" : each sub zones are drawn separately | |
179 | // case "" : the whole zone is drawn at once | |
180 | // in both cases, the rest of the option is passed | |
181 | // as argument to the Draw function of respectively | |
182 | // zone or row objects. | |
183 | // --- | |
184 | ||
185 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
186 | if (!fZone) return; | |
187 | ||
188 | gr->Push(); | |
189 | InitGraphContext(); | |
190 | switch (option[0]){ | |
191 | case 'S': | |
192 | { | |
193 | for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){ | |
194 | AliMpSubZone *subZone = fZone->GetSubZone(iSubZone); | |
195 | gr->Push(); | |
196 | ||
197 | Double_t blx= 9999, bly= 9999; | |
198 | Double_t urx= -9999, ury= -9999; | |
199 | ||
200 | for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){ | |
201 | AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg); | |
202 | ||
203 | TVector2 bl = rowSegment->Position(); | |
204 | bl-=rowSegment->Dimensions(); | |
205 | TVector2 ur = rowSegment->Position(); | |
206 | ur+=rowSegment->Dimensions(); | |
207 | ||
208 | if (bl.X()<blx) blx=bl.X(); | |
209 | if (bl.Y()<bly) bly=bl.Y(); | |
210 | if (ur.X()>urx) urx=ur.X(); | |
211 | if (ur.Y()>ury) ury=ur.Y(); | |
212 | } | |
213 | TVector2 position ( (urx+blx)/2.,(ury+bly)/2. ); | |
214 | TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. ); | |
215 | ||
216 | gr->SetPadPosForReal(position,dimensions); | |
217 | gr->SetColor((fZone->GetID()-1)*5+iSubZone+2); | |
218 | DrawObject(subZone,option+1); | |
219 | ||
220 | gr->Pop(); | |
221 | } | |
222 | } | |
223 | break; | |
224 | default: AppendPad(option); | |
225 | } | |
226 | gr->Pop(); | |
227 | } | |
228 | ||
229 | //_______________________________________________________________________ | |
230 | void AliMpZonePainter::Paint(Option_t *option) | |
231 | { | |
232 | // Paint the object | |
233 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
234 | if (!fZone) return; | |
235 | if (fZone->GetNofSubZones()<1) return; | |
236 | gr->Push(); | |
237 | gPad->Range(0.,0.,1.,1.); | |
238 | ||
239 | Int_t col=gVirtualX->GetFillColor(); | |
240 | InitGraphContext(); | |
241 | ||
242 | gVirtualX->SetFillColor(GetColor()); | |
243 | Float_t textSize = gVirtualX->GetTextSize(); | |
244 | for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){ | |
245 | AliMpSubZone *subZone = fZone->GetSubZone(iSubZone); | |
246 | for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){ | |
247 | AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg); | |
248 | TVector2 pos,dim; | |
249 | gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(), | |
250 | pos,dim); | |
251 | gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
252 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
253 | if (option[0]=='T'){ | |
254 | gVirtualX->SetTextSize(15); | |
255 | gPad->PaintText(pos.X()-0.01,pos.Y()-0.01, | |
256 | Form("%d",fZone->GetID())); | |
257 | } | |
258 | } | |
259 | } | |
260 | gVirtualX->SetTextSize(textSize); | |
261 | gVirtualX->SetFillColor(col); | |
262 | gr->Pop(); | |
263 | } |