]>
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: AliMpSectorPainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $ |
3d1463c8 | 18 | |
19 | //----------------------------------------------------------------------------- | |
dbe945cc | 20 | // Class AliMpSectorPainter |
21 | // ------------------------ | |
22 | // Class for drawing a sector into canvas | |
23 | // Included in AliRoot: 2003/05/02 | |
5f91c9e8 | 24 | // Authors: David Guez, IPN Orsay |
3d1463c8 | 25 | //----------------------------------------------------------------------------- |
5f91c9e8 | 26 | |
27 | #include "AliMpSectorPainter.h" | |
28 | #include "AliMpGraphContext.h" | |
29 | #include "AliMpSector.h" | |
30 | #include "AliMpZone.h" | |
31 | #include "AliMpSubZone.h" | |
32 | #include "AliMpRow.h" | |
33 | #include "AliMpVRowSegment.h" | |
5f91c9e8 | 34 | |
2c605e66 | 35 | #include <TVirtualX.h> |
36 | #include <TPad.h> | |
37 | ||
13985652 | 38 | /// \cond CLASSIMP |
5f91c9e8 | 39 | ClassImp(AliMpSectorPainter) |
13985652 | 40 | /// \endcond |
5f91c9e8 | 41 | |
42 | //_______________________________________________________________________ | |
2998a151 | 43 | AliMpSectorPainter::AliMpSectorPainter() |
5f91c9e8 | 44 | :AliMpVPainter(), |
45 | fSector(0) | |
46 | { | |
dee1d5f1 | 47 | /// Default constructor |
5f91c9e8 | 48 | } |
49 | //_______________________________________________________________________ | |
50 | AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector) | |
51 | :AliMpVPainter(), | |
52 | fSector(sector) | |
53 | { | |
dee1d5f1 | 54 | /// Standard constructor |
5f91c9e8 | 55 | |
56 | } | |
fb1bf5c0 | 57 | |
5f91c9e8 | 58 | //_______________________________________________________________________ |
2998a151 | 59 | AliMpSectorPainter::~AliMpSectorPainter() |
60 | { | |
dee1d5f1 | 61 | /// Destructor |
2998a151 | 62 | } |
fb1bf5c0 | 63 | |
2998a151 | 64 | //_______________________________________________________________________ |
5f91c9e8 | 65 | void AliMpSectorPainter::DumpObject() |
66 | { | |
f5671fc3 | 67 | /// Draw the owned object |
5f91c9e8 | 68 | |
dee1d5f1 | 69 | fSector->Dump(); |
5f91c9e8 | 70 | } |
dee1d5f1 | 71 | |
5f91c9e8 | 72 | //_______________________________________________________________________ |
73 | TVector2 AliMpSectorPainter::GetPosition() const | |
74 | { | |
f5671fc3 | 75 | /// Get the owned object's position |
5f91c9e8 | 76 | |
77 | if (fSector->GetNofRows()<1) return TVector2(0.,0.); | |
78 | AliMpRow* row = fSector->GetRow(0); | |
79 | ||
80 | // bl = bottom left position; | |
6e97fbb8 | 81 | TVector2 bl = TVector2(row->GetPositionX(), row->GetPositionY())- |
82 | TVector2(row->GetDimensionX(), row->GetDimensionY()); | |
5f91c9e8 | 83 | // ur = upper right position |
6e97fbb8 | 84 | TVector2 ur = TVector2(row->GetPositionX(), row->GetPositionY())+ |
85 | TVector2(row->GetDimensionX(), row->GetDimensionY());; | |
5f91c9e8 | 86 | |
87 | for (Int_t irow=1;irow<fSector->GetNofRows();++irow){ | |
88 | row = fSector->GetRow(irow); | |
89 | // update the bottom-left corner | |
6e97fbb8 | 90 | if (bl.X()>row->GetPositionX()-row->GetDimensionX()) |
91 | bl.Set(row->GetPositionX()-row->GetPositionX(),bl.Y()); | |
92 | if (bl.Y()>row->GetPositionY()-row->GetDimensionY()) | |
93 | bl.Set(bl.X(),row->GetPositionY()-row->GetDimensionY()); | |
5f91c9e8 | 94 | // update the upper-right corner |
6e97fbb8 | 95 | if (ur.X()<row->GetPositionX()+row->GetDimensionX()) |
96 | ur.Set(row->GetPositionX()+row->GetDimensionX(),ur.Y()); | |
97 | if (ur.Y()<row->GetPositionY()+row->GetDimensionY()) | |
98 | ur.Set(ur.X(),row->GetPositionY()+row->GetDimensionY()); | |
5f91c9e8 | 99 | } |
100 | return (ur+bl)/2.; | |
101 | } | |
dee1d5f1 | 102 | |
5f91c9e8 | 103 | //_______________________________________________________________________ |
104 | TVector2 AliMpSectorPainter::GetDimensions() const | |
105 | { | |
f5671fc3 | 106 | /// Get the owned object's dimensions |
dee1d5f1 | 107 | |
5f91c9e8 | 108 | if (fSector->GetNofRows()<1) return TVector2(0.,0.); |
109 | AliMpRow* row = fSector->GetRow(0); | |
110 | ||
111 | ||
112 | // bl = bottom left position | |
6e97fbb8 | 113 | TVector2 bl = TVector2(row->GetPositionX(), row->GetPositionY())- |
114 | TVector2(row->GetDimensionX(), row->GetDimensionY()); | |
5f91c9e8 | 115 | // ur = upper right position |
6e97fbb8 | 116 | TVector2 ur = TVector2(row->GetPositionX(), row->GetPositionY())+ |
117 | TVector2(row->GetDimensionX(), row->GetDimensionY()); | |
5f91c9e8 | 118 | |
119 | for (Int_t irow=1;irow<fSector->GetNofRows();++irow){ | |
120 | row = fSector->GetRow(irow); | |
121 | // update the bottom-left corner | |
6e97fbb8 | 122 | if (bl.X()>row->GetPositionX()-row->GetDimensionX()) |
123 | bl.Set(row->GetPositionX()-row->GetDimensionX(),bl.Y()); | |
124 | if (bl.Y()>row->GetPositionY()-row->GetDimensionY()) | |
125 | bl.Set(bl.X(),row->GetPositionY()-row->GetDimensionY()); | |
5f91c9e8 | 126 | // update the upper-right corner |
6e97fbb8 | 127 | if (ur.X()<row->GetPositionX()+row->GetDimensionX()) |
128 | ur.Set(row->GetPositionX()+row->GetDimensionX(),ur.Y()); | |
129 | if (ur.Y()<row->GetPositionY()+row->GetDimensionY()) | |
130 | ur.Set(ur.X(),row->GetPositionY()+row->GetDimensionY()); | |
5f91c9e8 | 131 | } |
132 | return (ur-bl)/2.; | |
133 | ||
134 | } | |
135 | //_______________________________________________________________________ | |
136 | void AliMpSectorPainter::Draw(Option_t *option) | |
137 | { | |
dee1d5f1 | 138 | /// Draw the sector on the current pad |
13985652 | 139 | /// The first letter of \a option is treated as follows: |
dee1d5f1 | 140 | /// - case "Z" : each zones are drawn separately |
141 | /// - case "R" : each rows are drawn separately | |
142 | /// - case "" : the whole sector is drawn at once | |
143 | /// in both cases, the rest of the option is passed | |
144 | /// as argument to the Draw function of respectively | |
145 | /// zone or row objects. | |
5f91c9e8 | 146 | |
147 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
148 | if (!fSector) return; | |
149 | gr->Push(); | |
150 | InitGraphContext(); | |
151 | ||
152 | switch (option[0]){ | |
153 | case 'Z': | |
154 | { | |
155 | for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){ | |
156 | AliMpZone *zone = fSector->GetZone(iZone); | |
157 | gr->Push(); | |
158 | ||
159 | Double_t blx= 9999, bly= 9999; | |
160 | Double_t urx= -9999, ury= -9999; | |
161 | ||
162 | for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){ | |
163 | AliMpSubZone *subZone = zone->GetSubZone(iSubZone); | |
164 | for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){ | |
165 | AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg); | |
166 | ||
6e97fbb8 | 167 | TVector2 bl = TVector2(rowSegment->GetPositionX(), |
168 | rowSegment->GetPositionY()) - | |
169 | TVector2(rowSegment->GetDimensionX(), | |
170 | rowSegment->GetDimensionY()); | |
171 | TVector2 ur = TVector2(rowSegment->GetPositionX(), | |
172 | rowSegment->GetPositionY())+ | |
173 | TVector2(rowSegment->GetDimensionX(), | |
174 | rowSegment->GetDimensionY()); | |
5f91c9e8 | 175 | |
176 | if (bl.X()<blx) blx=bl.X(); | |
177 | if (bl.Y()<bly) bly=bl.Y(); | |
178 | if (ur.X()>urx) urx=ur.X(); | |
179 | if (ur.Y()>ury) ury=ur.Y(); | |
180 | } | |
181 | } | |
182 | TVector2 position ( (urx+blx)/2.,(ury+bly)/2. ); | |
183 | TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. ); | |
184 | ||
185 | gr->SetPadPosForReal(position,dimensions); | |
186 | gr->SetColor(iZone+3); | |
187 | DrawObject(zone,option+1); | |
188 | ||
189 | gr->Pop(); | |
190 | } | |
191 | } | |
192 | break; | |
193 | case 'R': | |
194 | { | |
195 | for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){ | |
196 | AliMpRow *row = fSector->GetRow(iRow); | |
197 | gr->Push(); | |
6e97fbb8 | 198 | gr->SetPadPosForReal(TVector2(row->GetPositionX(), row->GetPositionY()), |
199 | TVector2(row->GetDimensionX(), row->GetDimensionY())); | |
5f91c9e8 | 200 | DrawObject(row,option+1); |
201 | gr->Pop(); | |
202 | } | |
203 | } | |
204 | break; | |
205 | default: AppendPad(option); | |
206 | } | |
207 | gr->Pop(); | |
208 | } | |
209 | ||
5f91c9e8 | 210 | //_______________________________________________________________________ |
2998a151 | 211 | void AliMpSectorPainter::Paint(Option_t* /*option*/) |
5f91c9e8 | 212 | { |
f5671fc3 | 213 | /// Paint the object |
dee1d5f1 | 214 | |
5f91c9e8 | 215 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
216 | if (!fSector) return; | |
217 | if (fSector->GetNofRows()<1) return; | |
218 | Int_t col=gVirtualX->GetFillColor(); | |
219 | gr->Push(); | |
220 | InitGraphContext(); | |
221 | gPad->Range(0.,0.,1.,1.); | |
222 | ||
223 | ||
224 | Double_t lx1=0.; | |
225 | Double_t lx2=0.; | |
226 | Int_t iRow; | |
227 | for (iRow=0;iRow<fSector->GetNofRows();++iRow){ | |
228 | AliMpRow *row = fSector->GetRow(iRow); | |
229 | TVector2 pos,dim; | |
6e97fbb8 | 230 | gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()), |
231 | TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim); | |
5f91c9e8 | 232 | gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(), |
233 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
234 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
235 | pos.X()-dim.X(),pos.Y()+dim.Y()); | |
236 | gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(), | |
237 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
238 | ||
239 | if (iRow>0){ | |
e191bb57 | 240 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y()); |
241 | gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y()); | |
5f91c9e8 | 242 | } |
243 | lx1=pos.X()-dim.X(); | |
244 | lx2=pos.X()+dim.X(); | |
245 | } | |
246 | ||
247 | // now we draw the lower and upper horizontal lines | |
248 | ||
249 | AliMpRow *row = fSector->GetRow(0); | |
250 | TVector2 pos,dim; | |
6e97fbb8 | 251 | gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()), |
252 | TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim); | |
e191bb57 | 253 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(), |
5f91c9e8 | 254 | pos.X()+dim.X(),pos.Y()-dim.Y()); |
255 | ||
256 | row = fSector->GetRow(fSector->GetNofRows()-1); | |
6e97fbb8 | 257 | gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()), |
258 | TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim); | |
e191bb57 | 259 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(), |
5f91c9e8 | 260 | pos.X()+dim.X(),pos.Y()+dim.Y()); |
261 | ||
262 | gr->Pop(); | |
263 | gVirtualX->SetFillColor(col); | |
264 | } | |
265 |