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