]>
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: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $ |
5f91c9e8 | 18 | // Category: graphics |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpMotifPainter |
22 | // ----------------------- | |
23 | // Class for drawing a motif into canvas | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
b09247a2 | 28 | #include <cstdlib> |
5f91c9e8 | 29 | #include "AliMpMotifPainter.h" |
30 | #include "AliMpGraphContext.h" | |
31 | #include "AliMpMotifPosition.h" | |
32 | #include "AliMpMotifType.h" | |
bde6e10f | 33 | #include "AliMpMotif.h" |
5f91c9e8 | 34 | #include "AliMpConnection.h" |
35 | #include "AliMpIntPair.h" | |
bde6e10f | 36 | #include "AliLog.h" |
5f91c9e8 | 37 | |
2c605e66 | 38 | #include <TVirtualX.h> |
39 | #include <TPad.h> | |
40 | ||
13985652 | 41 | /// \cond CLASSIMP |
5f91c9e8 | 42 | ClassImp(AliMpMotifPainter) |
13985652 | 43 | /// \endcond |
5f91c9e8 | 44 | |
45 | //_______________________________________________________________________ | |
46 | AliMpMotifPainter::AliMpMotifPainter() | |
47 | : AliMpVPainter(), | |
48 | fMotifPos(0) | |
49 | { | |
dee1d5f1 | 50 | /// Default constructor |
5f91c9e8 | 51 | } |
fb1bf5c0 | 52 | |
5f91c9e8 | 53 | //_______________________________________________________________________ |
54 | AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos) | |
55 | : AliMpVPainter(), | |
56 | fMotifPos(motifPos) | |
57 | { | |
dee1d5f1 | 58 | /// Standard constructor |
bde6e10f | 59 | AliDebug(1,"Default ctor"); |
60 | } | |
5f91c9e8 | 61 | |
bde6e10f | 62 | //_______________________________________________________________________ |
63 | AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType) | |
64 | : AliMpVPainter(), | |
65 | fMotifPos(0x0) | |
66 | { | |
67 | /// Constructor from a motif Type. We hereby create a MotifPosition | |
68 | /// object from it, using arbitrary pad sizes, as this is just a way | |
69 | /// to visualize the *shape* of the motif. | |
70 | ||
71 | AliDebug(1,"Ctor from motifType"); | |
72 | ||
6231d6db | 73 | const Double_t kdx = 5; |
74 | const Double_t kdy = 5; // cm but arbitrary anyway | |
bde6e10f | 75 | |
76 | AliMpVMotif* motif = new AliMpMotif(motifType->GetID(), | |
77 | motifType, | |
6231d6db | 78 | TVector2(kdx,kdy)); |
bde6e10f | 79 | |
80 | fMotifPos = new AliMpMotifPosition(-1,motif,motif->Dimensions()); | |
5f91c9e8 | 81 | } |
fb1bf5c0 | 82 | |
5f91c9e8 | 83 | //_______________________________________________________________________ |
2998a151 | 84 | AliMpMotifPainter::~AliMpMotifPainter() |
85 | { | |
dee1d5f1 | 86 | /// Default constructor |
2998a151 | 87 | } |
fb1bf5c0 | 88 | |
2998a151 | 89 | //_______________________________________________________________________ |
5f91c9e8 | 90 | void AliMpMotifPainter::DumpObject() |
91 | { | |
dee1d5f1 | 92 | /// Dump the owned object |
5f91c9e8 | 93 | |
dee1d5f1 | 94 | fMotifPos->Dump(); |
5f91c9e8 | 95 | } |
96 | ||
97 | //_______________________________________________________________________ | |
98 | TVector2 AliMpMotifPainter::GetPosition() const | |
99 | { | |
dee1d5f1 | 100 | /// Get the owned object's position |
5f91c9e8 | 101 | |
dee1d5f1 | 102 | return fMotifPos->Position(); |
5f91c9e8 | 103 | } |
dee1d5f1 | 104 | |
5f91c9e8 | 105 | //_______________________________________________________________________ |
106 | TVector2 AliMpMotifPainter::GetDimensions() const | |
107 | { | |
dee1d5f1 | 108 | /// Get the owned object's dimensions |
5f91c9e8 | 109 | |
dee1d5f1 | 110 | return fMotifPos->Dimensions(); |
5f91c9e8 | 111 | } |
112 | ||
113 | //_______________________________________________________________________ | |
114 | void AliMpMotifPainter::Paint(Option_t *option) | |
115 | { | |
dee1d5f1 | 116 | /// Paint the object |
117 | ||
5f91c9e8 | 118 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
119 | if (!fMotifPos) return; | |
120 | Int_t col=gVirtualX->GetFillColor(); | |
121 | gr->Push(); | |
122 | gPad->Range(0.,0.,1.,1.); | |
123 | InitGraphContext(); | |
124 | ||
aae373bb | 125 | gVirtualX->SetLineWidth(1); |
126 | ||
5f91c9e8 | 127 | switch (option[0]){ |
aae373bb | 128 | case 'T': |
129 | case 'I': | |
130 | case 'X': | |
5f91c9e8 | 131 | { |
132 | PaintWholeBox(); | |
133 | Float_t textSize = gVirtualX->GetTextSize(); | |
134 | gVirtualX->SetTextSize(10); | |
135 | TString str; | |
136 | switch (option[0]) { | |
137 | case 'T' : | |
138 | str = Form("%d",fMotifPos->GetID()); | |
139 | break; | |
140 | case 'I':{ | |
aae373bb | 141 | switch (option[1]){ |
142 | case '+' : | |
143 | str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(), | |
144 | fMotifPos->GetHighIndicesLimit().GetSecond()); | |
145 | break; | |
146 | default: | |
147 | str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(), | |
148 | fMotifPos->GetLowIndicesLimit().GetSecond()); | |
5f91c9e8 | 149 | } |
aae373bb | 150 | } |
151 | break; | |
5f91c9e8 | 152 | case 'X' : |
153 | str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(), | |
aae373bb | 154 | (GetPosition()-GetDimensions()).Y()); |
5f91c9e8 | 155 | break; |
156 | } | |
157 | gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str); | |
158 | ||
159 | gVirtualX->SetTextSize(textSize); | |
160 | } | |
aae373bb | 161 | break; |
162 | case 'P': | |
163 | case 'Z': | |
164 | { | |
165 | //PaintWholeBox(kFALSE); | |
166 | AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType(); | |
aae373bb | 167 | for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){ |
168 | for (Int_t i=0;i<motifType->GetNofPadsX();i++){ | |
169 | AliMpIntPair indices(i,j); | |
170 | AliMpConnection* connect = | |
171 | motifType->FindConnectionByLocalIndices(indices); | |
172 | if (connect){ | |
173 | TVector2 realPadPos = | |
174 | GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices); | |
175 | TVector2 padPadPos,padPadDim; | |
176 | gr->RealToPad(realPadPos, | |
177 | fMotifPos->GetMotif()->GetPadDimensions(indices), | |
178 | padPadPos,padPadDim); | |
179 | TVector2 bl = padPadPos - padPadDim; | |
180 | TVector2 ur = padPadPos + padPadDim; | |
38f79959 | 181 | |
aae373bb | 182 | Style_t sty = gVirtualX->GetFillStyle(); |
183 | gVirtualX->SetFillStyle(1); | |
184 | gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y()); | |
185 | gVirtualX->SetFillStyle(0); | |
186 | gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y()); | |
187 | gVirtualX->SetFillStyle(sty); | |
38f79959 | 188 | |
aae373bb | 189 | if (option[1]=='T'){ |
190 | Float_t textSize = gVirtualX->GetTextSize(); | |
191 | gVirtualX->SetTextSize(10); | |
192 | gVirtualX->SetTextAlign(22); | |
aae373bb | 193 | gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0, |
194 | Form("%d",connect->GetGassiNum())); | |
195 | ||
196 | gVirtualX->SetTextSize(textSize); | |
197 | } | |
198 | } | |
199 | } | |
200 | } | |
201 | if ( option[0]=='Z' ) | |
202 | { | |
203 | PaintContour(option,kFALSE); | |
204 | } | |
205 | } | |
206 | break; | |
207 | ||
208 | case 'C': | |
209 | PaintContour(option,kTRUE); | |
210 | break; | |
211 | ||
212 | default: | |
213 | PaintWholeBox(kFALSE); | |
214 | } | |
215 | gr->Pop(); | |
216 | gVirtualX->SetFillColor(col); | |
217 | } | |
218 | ||
219 | //_______________________________________________________________________ | |
220 | void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill) | |
221 | { | |
144129ae | 222 | /// Drawing real motif (not envelop) the real contour |
223 | ||
aae373bb | 224 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
225 | ||
aae373bb | 226 | Float_t xl = 0; |
227 | Float_t yl = 0; | |
228 | Int_t manuId = 0; | |
38f79959 | 229 | Int_t searchMotif = -1; |
aae373bb | 230 | TVector2 bl0 = TVector2(999, 999); |
231 | TVector2 ur0 = TVector2(0,0); | |
232 | TVector2 padPadPos,padPadDim; | |
233 | ||
234 | AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType(); | |
235 | manuId = fMotifPos->GetID(); | |
236 | ||
237 | if ( fill ) | |
bde6e10f | 238 | { |
aae373bb | 239 | if (manuId % 5 == 0) |
240 | gVirtualX->SetFillColor(0); | |
241 | if (manuId % 5 == 1) | |
242 | gVirtualX->SetFillColor(38); | |
243 | if (manuId % 5 == 2) | |
244 | gVirtualX->SetFillColor(33); | |
245 | if (manuId % 5 == 3) | |
246 | gVirtualX->SetFillColor(16); | |
247 | if (manuId % 5 == 4) | |
248 | gVirtualX->SetFillColor(44); | |
249 | } | |
250 | ||
251 | Width_t lineW = gPad->GetLineWidth(); | |
38f79959 | 252 | Width_t lw = lineW*3; |
253 | Double_t xlw = gPad->PixeltoX(lw/2); | |
aae373bb | 254 | |
38f79959 | 255 | |
256 | if (option[1] == 'I' && option[2] == ':') | |
257 | searchMotif = atoi(&option[3]); | |
258 | ||
aae373bb | 259 | gVirtualX->SetLineWidth(lw); |
260 | ||
261 | for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){ | |
262 | ||
263 | for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){ | |
264 | ||
265 | AliMpIntPair indices = AliMpIntPair(i,j); | |
266 | AliMpConnection* connect = motifType->FindConnectionByLocalIndices(indices); | |
38f79959 | 267 | |
bde6e10f | 268 | if (connect){ |
269 | TVector2 realPadPos = | |
aae373bb | 270 | GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices); |
271 | gr->RealToPad(realPadPos, fMotifPos->GetMotif()->GetPadDimensions(indices), | |
272 | padPadPos, padPadDim); | |
273 | ||
bde6e10f | 274 | TVector2 bl = padPadPos - padPadDim; |
275 | TVector2 ur = padPadPos + padPadDim; | |
38f79959 | 276 | |
aae373bb | 277 | if (bl0.X() > bl.X()) |
278 | bl0 = bl; | |
bde6e10f | 279 | |
aae373bb | 280 | if (ur0.Y() < ur.Y()) |
281 | ur0 = ur; | |
bde6e10f | 282 | |
aae373bb | 283 | if ( fill ) |
284 | { | |
38f79959 | 285 | Style_t csty = gVirtualX->GetFillColor(); |
286 | Style_t sty = gVirtualX->GetFillStyle(); | |
287 | gVirtualX->SetFillStyle(1); | |
288 | if (manuId == searchMotif) | |
289 | gVirtualX->SetFillColor(5); // yellow | |
290 | gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y()); | |
aae373bb | 291 | gVirtualX->SetFillStyle(sty); |
38f79959 | 292 | gVirtualX->SetFillColor(csty); |
293 | } | |
294 | ||
295 | if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j-1))) | |
aae373bb | 296 | { |
297 | gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y()); | |
5f91c9e8 | 298 | } |
aae373bb | 299 | |
300 | if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j+1))) | |
301 | { | |
302 | gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2); | |
303 | } | |
aae373bb | 304 | if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i-1,j))) |
305 | { | |
306 | gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2); | |
307 | } | |
308 | ||
309 | if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i+1,j))) | |
310 | { | |
38f79959 | 311 | gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2); |
312 | } | |
aae373bb | 313 | } |
38f79959 | 314 | |
5f91c9e8 | 315 | } |
aae373bb | 316 | } |
bde6e10f | 317 | |
aae373bb | 318 | switch (option[1]) { |
319 | // add manudId indexes | |
320 | case 'I' : | |
321 | xl = bl0.X()+ padPadDim.X()/2.; | |
322 | ||
323 | yl = bl0.Y() + 1.5*padPadDim.Y(); | |
324 | ||
325 | Float_t textSize = gVirtualX->GetTextSize(); | |
326 | gVirtualX->SetTextSize(12); | |
327 | gVirtualX->SetTextAlign(13); | |
328 | gVirtualX->SetTextAngle(90.); | |
329 | ||
330 | gPad->PaintText(xl, yl, Form("%d", manuId)); | |
331 | ||
332 | gVirtualX->SetTextAngle(0.); | |
333 | gVirtualX->SetTextSize(textSize); | |
334 | break; | |
5f91c9e8 | 335 | } |
0f6198f2 | 336 | |
aae373bb | 337 | gVirtualX->SetLineWidth(lineW); |
0f6198f2 | 338 | |
5f91c9e8 | 339 | } |