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