]>
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: AliMpSubZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $ |
5f91c9e8 | 18 | // Category: graphics |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpSubZonePainter |
22 | // ------------------------- | |
23 | // Class for drawing a subzone into canvas | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
28 | #include "AliMpSubZonePainter.h" | |
29 | #include "AliMpGraphContext.h" | |
30 | #include "AliMpSubZone.h" | |
31 | #include "AliMpVRowSegment.h" | |
32 | #include "AliMpVMotif.h" | |
33 | ||
2c605e66 | 34 | #include <TVirtualX.h> |
35 | #include <TPad.h> | |
36 | ||
13985652 | 37 | /// \cond CLASSIMP |
5f91c9e8 | 38 | ClassImp(AliMpSubZonePainter) |
13985652 | 39 | /// \endcond |
5f91c9e8 | 40 | |
41 | //_______________________________________________________________________ | |
42 | AliMpSubZonePainter::AliMpSubZonePainter() | |
43 | : AliMpVPainter(), | |
44 | fSubZone(0) | |
45 | { | |
dee1d5f1 | 46 | /// Default constructor |
5f91c9e8 | 47 | } |
fb1bf5c0 | 48 | |
5f91c9e8 | 49 | //_______________________________________________________________________ |
50 | AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone) | |
51 | : AliMpVPainter(), | |
52 | fSubZone(subZone) | |
53 | { | |
dee1d5f1 | 54 | /// Standard constructor |
5f91c9e8 | 55 | |
56 | } | |
fb1bf5c0 | 57 | |
5f91c9e8 | 58 | //_______________________________________________________________________ |
2998a151 | 59 | AliMpSubZonePainter::~AliMpSubZonePainter() |
60 | { | |
dee1d5f1 | 61 | /// Destructor |
2998a151 | 62 | } |
fb1bf5c0 | 63 | |
2998a151 | 64 | //_______________________________________________________________________ |
5f91c9e8 | 65 | Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y) |
66 | { | |
dee1d5f1 | 67 | /// Dist to the nearest segment center if (x,y) is inside the sub-zone |
68 | /// 9999 otherwise | |
69 | ||
5f91c9e8 | 70 | if (fSubZone->GetNofRowSegments()<1) return 9999; |
71 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
72 | ||
73 | gr->Push(); | |
74 | InitGraphContext(); | |
75 | ||
76 | ||
77 | TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y)); | |
78 | ||
79 | Double_t res=9999.; | |
80 | for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){ | |
81 | //for each row segments | |
82 | AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg); | |
83 | ||
84 | TVector2 pos,dim; | |
85 | gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim); | |
86 | ||
87 | if ( IsInside(point,pos,dim) ){ | |
88 | Double_t value = (point-pos).Mod(); | |
89 | if (value<res) res=value; | |
90 | } | |
91 | } | |
92 | gr->Pop(); | |
93 | return (Int_t)res; | |
94 | } | |
95 | ||
96 | //_______________________________________________________________________ | |
97 | void AliMpSubZonePainter::DumpObject() | |
98 | { | |
f5671fc3 | 99 | /// Draw the owned object |
dee1d5f1 | 100 | |
5f91c9e8 | 101 | fSubZone->Dump(); |
5f91c9e8 | 102 | } |
dee1d5f1 | 103 | |
5f91c9e8 | 104 | //_______________________________________________________________________ |
105 | TVector2 AliMpSubZonePainter::GetPosition() const | |
106 | { | |
f5671fc3 | 107 | /// Get the owned object's position |
5f91c9e8 | 108 | |
109 | if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.); | |
110 | AliMpVRowSegment* seg = fSubZone->GetRowSegment(0); | |
111 | ||
112 | // bl = bottom left position; | |
113 | TVector2 bl = seg->Position()-seg->Dimensions(); | |
114 | // ur = upper right position | |
115 | TVector2 ur = seg->Position()+seg->Dimensions(); | |
116 | ||
117 | for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){ | |
118 | seg = fSubZone->GetRowSegment(iseg); | |
119 | // update the bottom-left corner | |
120 | if (bl.X()>seg->Position().X()-seg->Dimensions().X()) | |
121 | bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y()); | |
122 | if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y()) | |
123 | bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y()); | |
124 | // update the upper-right corner | |
125 | if (ur.X()<seg->Position().X()+seg->Dimensions().X()) | |
126 | ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y()); | |
127 | if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y()) | |
128 | ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y()); | |
129 | } | |
130 | return (ur+bl)/2.; | |
131 | } | |
dee1d5f1 | 132 | |
5f91c9e8 | 133 | //_______________________________________________________________________ |
134 | TVector2 AliMpSubZonePainter::GetDimensions() const | |
135 | { | |
f5671fc3 | 136 | /// Get the owned object's dimensions |
5f91c9e8 | 137 | |
138 | if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.); | |
139 | AliMpVRowSegment* seg = fSubZone->GetRowSegment(0); | |
140 | ||
141 | // bl = bottom left position; | |
142 | TVector2 bl = seg->Position()-seg->Dimensions(); | |
143 | // ur = upper right position | |
144 | TVector2 ur = seg->Position()+seg->Dimensions(); | |
145 | ||
146 | for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){ | |
147 | seg = fSubZone->GetRowSegment(iseg); | |
148 | // update the bottom-left corner | |
149 | if (bl.X()>seg->Position().X()-seg->Dimensions().X()) | |
150 | bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y()); | |
151 | if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y()) | |
152 | bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y()); | |
153 | // update the upper-right corner | |
154 | if (ur.X()<seg->Position().X()+seg->Dimensions().X()) | |
155 | ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y()); | |
156 | if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y()) | |
157 | ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y()); | |
158 | } | |
159 | return (ur-bl)/2.; | |
160 | } | |
dee1d5f1 | 161 | |
5f91c9e8 | 162 | //_______________________________________________________________________ |
163 | void AliMpSubZonePainter::Draw(Option_t *option) | |
164 | { | |
dee1d5f1 | 165 | /// Draw the sector on the current pad |
13985652 | 166 | /// The first letter of \a option is treated as follows: |
dee1d5f1 | 167 | /// - case "S" : each row segments are drawn separately |
168 | /// - case "" : the whole subzone is drawn at once | |
169 | /// in both cases, the rest of the option is passed | |
170 | /// as argument to the Draw function of respectively | |
171 | /// zone or row objects. | |
5f91c9e8 | 172 | |
173 | if (!fSubZone) return; | |
174 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
175 | ||
176 | gr->Push(); | |
177 | InitGraphContext(); | |
178 | switch (option[0]){ | |
179 | case 'S': | |
180 | { | |
181 | ||
182 | for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){ | |
183 | gr->Push(); | |
184 | AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg); | |
185 | ||
186 | gr->SetPadPosForReal(rowSegment->Position(), | |
187 | rowSegment->Dimensions()); | |
188 | gr->SetColor(GetColor()); | |
189 | DrawObject(rowSegment,option+1); | |
190 | ||
191 | gr->Pop(); | |
192 | } | |
193 | } | |
194 | break; | |
195 | default: AppendPad(option); | |
196 | } | |
197 | gr->Pop(); | |
198 | } | |
199 | ||
200 | ||
201 | //_______________________________________________________________________ | |
202 | void AliMpSubZonePainter::Paint(Option_t *option) | |
203 | { | |
f5671fc3 | 204 | /// Paint the object |
dee1d5f1 | 205 | |
5f91c9e8 | 206 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
207 | if (!fSubZone) return; | |
208 | if (fSubZone->GetNofRowSegments()<1) return; | |
209 | gr->Push(); | |
210 | gPad->Range(0.,0.,1.,1.); | |
211 | Int_t col=gVirtualX->GetFillColor(); | |
212 | InitGraphContext(); | |
213 | ||
214 | gVirtualX->SetFillColor(GetColor()); | |
215 | for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){ | |
216 | AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg); | |
217 | TVector2 pos,dim; | |
218 | gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(), | |
219 | pos,dim); | |
220 | gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
221 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
222 | if (option[0]=='T'){ | |
223 | Float_t textSize = gVirtualX->GetTextSize(); | |
224 | gVirtualX->SetTextSize(15); | |
225 | gPad->PaintText(pos.X()-0.01,pos.Y()-0.01, | |
226 | fSubZone->GetMotif()->GetID()); | |
227 | gVirtualX->SetTextSize(textSize); | |
228 | } | |
229 | } | |
230 | ||
231 | gVirtualX->SetFillColor(col); | |
232 | gr->Pop(); | |
233 | } |