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