]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // | |
3 | // Authors: David Guez, IPN Orsay | |
4 | ||
2998a151 | 5 | #include <TVirtualX.h> |
6 | #include <TPad.h> | |
fb1bf5c0 | 7 | #include <TError.h> |
2998a151 | 8 | |
5f91c9e8 | 9 | #include "AliMpSectorPainter.h" |
10 | #include "AliMpGraphContext.h" | |
11 | #include "AliMpSector.h" | |
12 | #include "AliMpZone.h" | |
13 | #include "AliMpSubZone.h" | |
14 | #include "AliMpRow.h" | |
15 | #include "AliMpVRowSegment.h" | |
5f91c9e8 | 16 | |
17 | ClassImp(AliMpSectorPainter) | |
18 | ||
19 | //_______________________________________________________________________ | |
2998a151 | 20 | AliMpSectorPainter::AliMpSectorPainter() |
5f91c9e8 | 21 | :AliMpVPainter(), |
22 | fSector(0) | |
23 | { | |
24 | // default dummy constructor | |
25 | } | |
26 | //_______________________________________________________________________ | |
27 | AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector) | |
28 | :AliMpVPainter(), | |
29 | fSector(sector) | |
30 | { | |
31 | // normal constructor | |
32 | ||
33 | } | |
fb1bf5c0 | 34 | |
35 | //_____________________________________________________________________________ | |
36 | AliMpSectorPainter::AliMpSectorPainter(const AliMpSectorPainter& right) | |
37 | : AliMpVPainter(right) | |
38 | { | |
39 | // copy constructor (not implemented) | |
40 | ||
41 | Fatal("AliMpSectorPainter", "Copy constructor not provided."); | |
42 | } | |
43 | ||
5f91c9e8 | 44 | //_______________________________________________________________________ |
2998a151 | 45 | AliMpSectorPainter::~AliMpSectorPainter() |
46 | { | |
47 | // destructor | |
48 | } | |
fb1bf5c0 | 49 | |
50 | //_____________________________________________________________________________ | |
51 | AliMpSectorPainter& | |
52 | AliMpSectorPainter::operator=(const AliMpSectorPainter& right) | |
53 | { | |
54 | // assignement operator (not implemented) | |
55 | ||
56 | // check assignement to self | |
57 | if (this == &right) return *this; | |
58 | ||
59 | Fatal("operator =", "Assignement operator not provided."); | |
60 | ||
61 | return *this; | |
62 | } | |
63 | ||
2998a151 | 64 | //_______________________________________________________________________ |
5f91c9e8 | 65 | void AliMpSectorPainter::DumpObject() |
66 | { | |
67 | // Draw the owned object | |
68 | fSector->Dump(); | |
69 | ||
70 | } | |
71 | //_______________________________________________________________________ | |
72 | TVector2 AliMpSectorPainter::GetPosition() const | |
73 | { | |
74 | // Get the owned object's position | |
75 | ||
76 | if (fSector->GetNofRows()<1) return TVector2(0.,0.); | |
77 | AliMpRow* row = fSector->GetRow(0); | |
78 | ||
79 | // bl = bottom left position; | |
80 | TVector2 bl = row->Position()-row->Dimensions(); | |
81 | // ur = upper right position | |
82 | TVector2 ur = row->Position()+row->Dimensions();; | |
83 | ||
84 | for (Int_t irow=1;irow<fSector->GetNofRows();++irow){ | |
85 | row = fSector->GetRow(irow); | |
86 | // update the bottom-left corner | |
87 | if (bl.X()>row->Position().X()-row->Dimensions().X()) | |
88 | bl.Set(row->Position().X()-row->Position().X(),bl.Y()); | |
89 | if (bl.Y()>row->Position().Y()-row->Dimensions().Y()) | |
90 | bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y()); | |
91 | // update the upper-right corner | |
92 | if (ur.X()<row->Position().X()+row->Dimensions().X()) | |
93 | ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y()); | |
94 | if (ur.Y()<row->Position().Y()+row->Dimensions().Y()) | |
95 | ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y()); | |
96 | } | |
97 | return (ur+bl)/2.; | |
98 | } | |
99 | //_______________________________________________________________________ | |
100 | TVector2 AliMpSectorPainter::GetDimensions() const | |
101 | { | |
102 | // Get the owned object's dimensions | |
103 | if (fSector->GetNofRows()<1) return TVector2(0.,0.); | |
104 | AliMpRow* row = fSector->GetRow(0); | |
105 | ||
106 | ||
107 | // bl = bottom left position | |
108 | TVector2 bl = row->Position()-row->Dimensions(); | |
109 | // ur = upper right position | |
110 | TVector2 ur = row->Position()+row->Dimensions(); | |
111 | ||
112 | for (Int_t irow=1;irow<fSector->GetNofRows();++irow){ | |
113 | row = fSector->GetRow(irow); | |
114 | // update the bottom-left corner | |
115 | if (bl.X()>row->Position().X()-row->Dimensions().X()) | |
116 | bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y()); | |
117 | if (bl.Y()>row->Position().Y()-row->Dimensions().Y()) | |
118 | bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y()); | |
119 | // update the upper-right corner | |
120 | if (ur.X()<row->Position().X()+row->Dimensions().X()) | |
121 | ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y()); | |
122 | if (ur.Y()<row->Position().Y()+row->Dimensions().Y()) | |
123 | ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y()); | |
124 | } | |
125 | return (ur-bl)/2.; | |
126 | ||
127 | } | |
128 | //_______________________________________________________________________ | |
129 | void AliMpSectorPainter::Draw(Option_t *option) | |
130 | { | |
131 | // Draw the sector on the current pad | |
132 | // The first letter of <option> is treated as follows: | |
133 | // case "Z" : each zones are drawn separately | |
134 | // case "R" : each rows are drawn separately | |
135 | // case "" : the whole sector is drawn at once | |
136 | // in both cases, the rest of the option is passed | |
137 | // as argument to the Draw function of respectively | |
138 | // zone or row objects. | |
139 | // --- | |
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 | ||
197 | ||
198 | ||
199 | //_______________________________________________________________________ | |
2998a151 | 200 | void AliMpSectorPainter::Paint(Option_t* /*option*/) |
5f91c9e8 | 201 | { |
202 | // Paint the object | |
203 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
204 | if (!fSector) return; | |
205 | if (fSector->GetNofRows()<1) return; | |
206 | Int_t col=gVirtualX->GetFillColor(); | |
207 | gr->Push(); | |
208 | InitGraphContext(); | |
209 | gPad->Range(0.,0.,1.,1.); | |
210 | ||
211 | ||
212 | Double_t lx1=0.; | |
213 | Double_t lx2=0.; | |
214 | Int_t iRow; | |
215 | for (iRow=0;iRow<fSector->GetNofRows();++iRow){ | |
216 | AliMpRow *row = fSector->GetRow(iRow); | |
217 | TVector2 pos,dim; | |
218 | gr->RealToPad(row->Position(),row->Dimensions(),pos,dim); | |
219 | gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
220 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
221 | gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
222 | pos.X()-dim.X(),pos.Y()+dim.Y()); | |
223 | gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(), | |
224 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
225 | ||
226 | if (iRow>0){ | |
227 | gPad->DrawLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y()); | |
228 | gPad->DrawLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y()); | |
229 | } | |
230 | lx1=pos.X()-dim.X(); | |
231 | lx2=pos.X()+dim.X(); | |
232 | } | |
233 | ||
234 | // now we draw the lower and upper horizontal lines | |
235 | ||
236 | AliMpRow *row = fSector->GetRow(0); | |
237 | TVector2 pos,dim; | |
238 | gr->RealToPad(row->Position(),row->Dimensions(),pos,dim); | |
239 | gPad->DrawLine(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
240 | pos.X()+dim.X(),pos.Y()-dim.Y()); | |
241 | ||
242 | row = fSector->GetRow(fSector->GetNofRows()-1); | |
243 | gr->RealToPad(row->Position(),row->Dimensions(),pos,dim); | |
244 | gPad->DrawLine(pos.X()-dim.X(),pos.Y()+dim.Y(), | |
245 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
246 | ||
247 | gr->Pop(); | |
248 | gVirtualX->SetFillColor(col); | |
249 | } | |
250 |