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