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