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; |
81 | TVector2 bl = row->Position()-row->Dimensions(); |
82 | // ur = upper right position |
83 | TVector2 ur = row->Position()+row->Dimensions();; |
84 | |
85 | for (Int_t irow=1;irow<fSector->GetNofRows();++irow){ |
86 | row = fSector->GetRow(irow); |
87 | // update the bottom-left corner |
88 | if (bl.X()>row->Position().X()-row->Dimensions().X()) |
89 | bl.Set(row->Position().X()-row->Position().X(),bl.Y()); |
90 | if (bl.Y()>row->Position().Y()-row->Dimensions().Y()) |
91 | bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y()); |
92 | // update the upper-right corner |
93 | if (ur.X()<row->Position().X()+row->Dimensions().X()) |
94 | ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y()); |
95 | if (ur.Y()<row->Position().Y()+row->Dimensions().Y()) |
96 | ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y()); |
97 | } |
98 | return (ur+bl)/2.; |
99 | } |
dee1d5f1 |
100 | |
5f91c9e8 |
101 | //_______________________________________________________________________ |
102 | TVector2 AliMpSectorPainter::GetDimensions() const |
103 | { |
f5671fc3 |
104 | /// Get the owned object's dimensions |
dee1d5f1 |
105 | |
5f91c9e8 |
106 | if (fSector->GetNofRows()<1) return TVector2(0.,0.); |
107 | AliMpRow* row = fSector->GetRow(0); |
108 | |
109 | |
110 | // bl = bottom left position |
111 | TVector2 bl = row->Position()-row->Dimensions(); |
112 | // ur = upper right position |
113 | TVector2 ur = row->Position()+row->Dimensions(); |
114 | |
115 | for (Int_t irow=1;irow<fSector->GetNofRows();++irow){ |
116 | row = fSector->GetRow(irow); |
117 | // update the bottom-left corner |
118 | if (bl.X()>row->Position().X()-row->Dimensions().X()) |
119 | bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y()); |
120 | if (bl.Y()>row->Position().Y()-row->Dimensions().Y()) |
121 | bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y()); |
122 | // update the upper-right corner |
123 | if (ur.X()<row->Position().X()+row->Dimensions().X()) |
124 | ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y()); |
125 | if (ur.Y()<row->Position().Y()+row->Dimensions().Y()) |
126 | ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y()); |
127 | } |
128 | return (ur-bl)/2.; |
129 | |
130 | } |
131 | //_______________________________________________________________________ |
132 | void AliMpSectorPainter::Draw(Option_t *option) |
133 | { |
dee1d5f1 |
134 | /// Draw the sector on the current pad |
13985652 |
135 | /// The first letter of \a option is treated as follows: |
dee1d5f1 |
136 | /// - case "Z" : each zones are drawn separately |
137 | /// - case "R" : each rows are drawn separately |
138 | /// - case "" : the whole sector is drawn at once |
139 | /// in both cases, the rest of the option is passed |
140 | /// as argument to the Draw function of respectively |
141 | /// zone or row objects. |
5f91c9e8 |
142 | |
143 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
144 | if (!fSector) return; |
145 | gr->Push(); |
146 | InitGraphContext(); |
147 | |
148 | switch (option[0]){ |
149 | case 'Z': |
150 | { |
151 | for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){ |
152 | AliMpZone *zone = fSector->GetZone(iZone); |
153 | gr->Push(); |
154 | |
155 | Double_t blx= 9999, bly= 9999; |
156 | Double_t urx= -9999, ury= -9999; |
157 | |
158 | for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){ |
159 | AliMpSubZone *subZone = zone->GetSubZone(iSubZone); |
160 | for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){ |
161 | AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg); |
162 | |
163 | TVector2 bl = rowSegment->Position()-rowSegment->Dimensions(); |
164 | TVector2 ur = rowSegment->Position()+rowSegment->Dimensions(); |
165 | |
166 | if (bl.X()<blx) blx=bl.X(); |
167 | if (bl.Y()<bly) bly=bl.Y(); |
168 | if (ur.X()>urx) urx=ur.X(); |
169 | if (ur.Y()>ury) ury=ur.Y(); |
170 | } |
171 | } |
172 | TVector2 position ( (urx+blx)/2.,(ury+bly)/2. ); |
173 | TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. ); |
174 | |
175 | gr->SetPadPosForReal(position,dimensions); |
176 | gr->SetColor(iZone+3); |
177 | DrawObject(zone,option+1); |
178 | |
179 | gr->Pop(); |
180 | } |
181 | } |
182 | break; |
183 | case 'R': |
184 | { |
185 | for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){ |
186 | AliMpRow *row = fSector->GetRow(iRow); |
187 | gr->Push(); |
188 | gr->SetPadPosForReal(row->Position(),row->Dimensions()); |
189 | DrawObject(row,option+1); |
190 | gr->Pop(); |
191 | } |
192 | } |
193 | break; |
194 | default: AppendPad(option); |
195 | } |
196 | gr->Pop(); |
197 | } |
198 | |
5f91c9e8 |
199 | //_______________________________________________________________________ |
2998a151 |
200 | void AliMpSectorPainter::Paint(Option_t* /*option*/) |
5f91c9e8 |
201 | { |
f5671fc3 |
202 | /// Paint the object |
dee1d5f1 |
203 | |
5f91c9e8 |
204 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
205 | if (!fSector) return; |
206 | if (fSector->GetNofRows()<1) return; |
207 | Int_t col=gVirtualX->GetFillColor(); |
208 | gr->Push(); |
209 | InitGraphContext(); |
210 | gPad->Range(0.,0.,1.,1.); |
211 | |
212 | |
213 | Double_t lx1=0.; |
214 | Double_t lx2=0.; |
215 | Int_t iRow; |
216 | for (iRow=0;iRow<fSector->GetNofRows();++iRow){ |
217 | AliMpRow *row = fSector->GetRow(iRow); |
218 | TVector2 pos,dim; |
219 | gr->RealToPad(row->Position(),row->Dimensions(),pos,dim); |
220 | gPad->PaintBox(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 | gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(), |
225 | pos.X()+dim.X(),pos.Y()+dim.Y()); |
226 | |
227 | if (iRow>0){ |
e191bb57 |
228 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y()); |
229 | gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y()); |
5f91c9e8 |
230 | } |
231 | lx1=pos.X()-dim.X(); |
232 | lx2=pos.X()+dim.X(); |
233 | } |
234 | |
235 | // now we draw the lower and upper horizontal lines |
236 | |
237 | AliMpRow *row = fSector->GetRow(0); |
238 | TVector2 pos,dim; |
239 | gr->RealToPad(row->Position(),row->Dimensions(),pos,dim); |
e191bb57 |
240 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(), |
5f91c9e8 |
241 | pos.X()+dim.X(),pos.Y()-dim.Y()); |
242 | |
243 | row = fSector->GetRow(fSector->GetNofRows()-1); |
244 | gr->RealToPad(row->Position(),row->Dimensions(),pos,dim); |
e191bb57 |
245 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(), |
5f91c9e8 |
246 | pos.X()+dim.X(),pos.Y()+dim.Y()); |
247 | |
248 | gr->Pop(); |
249 | gVirtualX->SetFillColor(col); |
250 | } |
251 | |