]>
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 | |
5f91c9e8 | 28 | #include "AliMpMotifPainter.h" |
29 | #include "AliMpGraphContext.h" | |
30 | #include "AliMpMotifPosition.h" | |
31 | #include "AliMpMotifType.h" | |
bde6e10f | 32 | #include "AliMpMotif.h" |
5f91c9e8 | 33 | #include "AliMpConnection.h" |
bde6e10f | 34 | #include "AliLog.h" |
5f91c9e8 | 35 | |
2c605e66 | 36 | #include <TVirtualX.h> |
37 | #include <TPad.h> | |
38 | ||
168e9c4d | 39 | #include <cstdlib> |
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, | |
6e97fbb8 | 78 | kdx,kdy); |
bde6e10f | 79 | |
6e97fbb8 | 80 | fMotifPos = new AliMpMotifPosition(-1,motif, |
81 | motif->DimensionX(), motif->DimensionY()); | |
5f91c9e8 | 82 | } |
fb1bf5c0 | 83 | |
5f91c9e8 | 84 | //_______________________________________________________________________ |
2998a151 | 85 | AliMpMotifPainter::~AliMpMotifPainter() |
86 | { | |
dee1d5f1 | 87 | /// Default constructor |
2998a151 | 88 | } |
fb1bf5c0 | 89 | |
2998a151 | 90 | //_______________________________________________________________________ |
5f91c9e8 | 91 | void AliMpMotifPainter::DumpObject() |
92 | { | |
dee1d5f1 | 93 | /// Dump the owned object |
5f91c9e8 | 94 | |
dee1d5f1 | 95 | fMotifPos->Dump(); |
5f91c9e8 | 96 | } |
97 | ||
98 | //_______________________________________________________________________ | |
99 | TVector2 AliMpMotifPainter::GetPosition() const | |
100 | { | |
dee1d5f1 | 101 | /// Get the owned object's position |
5f91c9e8 | 102 | |
6e97fbb8 | 103 | return TVector2(fMotifPos->GetPositionX(), fMotifPos->GetPositionY()); |
5f91c9e8 | 104 | } |
dee1d5f1 | 105 | |
5f91c9e8 | 106 | //_______________________________________________________________________ |
107 | TVector2 AliMpMotifPainter::GetDimensions() const | |
108 | { | |
dee1d5f1 | 109 | /// Get the owned object's dimensions |
5f91c9e8 | 110 | |
6e97fbb8 | 111 | return TVector2(fMotifPos->GetDimensionX(), fMotifPos->GetDimensionY()); |
5f91c9e8 | 112 | } |
113 | ||
114 | //_______________________________________________________________________ | |
115 | void AliMpMotifPainter::Paint(Option_t *option) | |
116 | { | |
dee1d5f1 | 117 | /// Paint the object |
118 | ||
5f91c9e8 | 119 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
120 | if (!fMotifPos) return; | |
121 | Int_t col=gVirtualX->GetFillColor(); | |
122 | gr->Push(); | |
123 | gPad->Range(0.,0.,1.,1.); | |
124 | InitGraphContext(); | |
125 | ||
aae373bb | 126 | gVirtualX->SetLineWidth(1); |
127 | ||
5f91c9e8 | 128 | switch (option[0]){ |
aae373bb | 129 | case 'T': |
130 | case 'I': | |
131 | case 'X': | |
5f91c9e8 | 132 | { |
133 | PaintWholeBox(); | |
134 | Float_t textSize = gVirtualX->GetTextSize(); | |
135 | gVirtualX->SetTextSize(10); | |
136 | TString str; | |
137 | switch (option[0]) { | |
138 | case 'T' : | |
139 | str = Form("%d",fMotifPos->GetID()); | |
140 | break; | |
141 | case 'I':{ | |
aae373bb | 142 | switch (option[1]){ |
143 | case '+' : | |
168e9c4d | 144 | str = Form("(%d,%d)",fMotifPos->GetHighLimitIx(), |
145 | fMotifPos->GetHighLimitIy()); | |
aae373bb | 146 | break; |
147 | default: | |
168e9c4d | 148 | str = Form("(%d,%d)",fMotifPos->GetLowLimitIx(), |
149 | fMotifPos->GetLowLimitIy()); | |
5f91c9e8 | 150 | } |
aae373bb | 151 | } |
152 | break; | |
5f91c9e8 | 153 | case 'X' : |
154 | str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(), | |
aae373bb | 155 | (GetPosition()-GetDimensions()).Y()); |
5f91c9e8 | 156 | break; |
157 | } | |
158 | gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str); | |
159 | ||
160 | gVirtualX->SetTextSize(textSize); | |
161 | } | |
aae373bb | 162 | break; |
163 | case 'P': | |
164 | case 'Z': | |
165 | { | |
166 | //PaintWholeBox(kFALSE); | |
167 | AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType(); | |
aae373bb | 168 | for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){ |
169 | for (Int_t i=0;i<motifType->GetNofPadsX();i++){ | |
aae373bb | 170 | AliMpConnection* connect = |
168e9c4d | 171 | motifType->FindConnectionByLocalIndices(i,j); |
aae373bb | 172 | if (connect){ |
6e97fbb8 | 173 | Double_t localPosX, localPosY; |
174 | fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY); | |
aae373bb | 175 | TVector2 realPadPos = |
6e97fbb8 | 176 | GetPosition()+TVector2(localPosX, localPosY); |
177 | ||
178 | Double_t dx, dy; | |
179 | fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j, dx, dy); | |
180 | ||
aae373bb | 181 | TVector2 padPadPos,padPadDim; |
182 | gr->RealToPad(realPadPos, | |
6e97fbb8 | 183 | TVector2(dx, dy), |
aae373bb | 184 | padPadPos,padPadDim); |
185 | TVector2 bl = padPadPos - padPadDim; | |
186 | TVector2 ur = padPadPos + padPadDim; | |
38f79959 | 187 | |
aae373bb | 188 | Style_t sty = gVirtualX->GetFillStyle(); |
189 | gVirtualX->SetFillStyle(1); | |
190 | gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y()); | |
191 | gVirtualX->SetFillStyle(0); | |
192 | gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y()); | |
193 | gVirtualX->SetFillStyle(sty); | |
38f79959 | 194 | |
aae373bb | 195 | if (option[1]=='T'){ |
196 | Float_t textSize = gVirtualX->GetTextSize(); | |
197 | gVirtualX->SetTextSize(10); | |
198 | gVirtualX->SetTextAlign(22); | |
aae373bb | 199 | gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0, |
34ee05d7 | 200 | Form("%d",connect->GetManuChannel())); |
aae373bb | 201 | |
202 | gVirtualX->SetTextSize(textSize); | |
203 | } | |
204 | } | |
205 | } | |
206 | } | |
207 | if ( option[0]=='Z' ) | |
208 | { | |
209 | PaintContour(option,kFALSE); | |
210 | } | |
211 | } | |
212 | break; | |
213 | ||
214 | case 'C': | |
215 | PaintContour(option,kTRUE); | |
216 | break; | |
217 | ||
218 | default: | |
219 | PaintWholeBox(kFALSE); | |
220 | } | |
221 | gr->Pop(); | |
222 | gVirtualX->SetFillColor(col); | |
223 | } | |
224 | ||
225 | //_______________________________________________________________________ | |
226 | void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill) | |
227 | { | |
144129ae | 228 | /// Drawing real motif (not envelop) the real contour |
229 | ||
aae373bb | 230 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
231 | ||
aae373bb | 232 | Float_t xl = 0; |
233 | Float_t yl = 0; | |
234 | Int_t manuId = 0; | |
38f79959 | 235 | Int_t searchMotif = -1; |
aae373bb | 236 | TVector2 bl0 = TVector2(999, 999); |
237 | TVector2 ur0 = TVector2(0,0); | |
238 | TVector2 padPadPos,padPadDim; | |
239 | ||
240 | AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType(); | |
241 | manuId = fMotifPos->GetID(); | |
242 | ||
243 | if ( fill ) | |
bde6e10f | 244 | { |
aae373bb | 245 | if (manuId % 5 == 0) |
246 | gVirtualX->SetFillColor(0); | |
247 | if (manuId % 5 == 1) | |
248 | gVirtualX->SetFillColor(38); | |
249 | if (manuId % 5 == 2) | |
250 | gVirtualX->SetFillColor(33); | |
251 | if (manuId % 5 == 3) | |
252 | gVirtualX->SetFillColor(16); | |
253 | if (manuId % 5 == 4) | |
254 | gVirtualX->SetFillColor(44); | |
255 | } | |
256 | ||
257 | Width_t lineW = gPad->GetLineWidth(); | |
38f79959 | 258 | Width_t lw = lineW*3; |
259 | Double_t xlw = gPad->PixeltoX(lw/2); | |
aae373bb | 260 | |
38f79959 | 261 | |
262 | if (option[1] == 'I' && option[2] == ':') | |
263 | searchMotif = atoi(&option[3]); | |
264 | ||
aae373bb | 265 | gVirtualX->SetLineWidth(lw); |
266 | ||
267 | for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){ | |
268 | ||
269 | for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){ | |
270 | ||
168e9c4d | 271 | AliMpConnection* connect = motifType->FindConnectionByLocalIndices(i,j); |
38f79959 | 272 | |
bde6e10f | 273 | if (connect){ |
6e97fbb8 | 274 | Double_t localPosX, localPosY; |
275 | fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY); | |
276 | ||
bde6e10f | 277 | TVector2 realPadPos = |
6e97fbb8 | 278 | GetPosition()+TVector2(localPosX, localPosY); |
279 | ||
280 | Double_t dx, dy; | |
281 | fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j, dx, dy); | |
282 | ||
168e9c4d | 283 | gr->RealToPad(realPadPos, |
6e97fbb8 | 284 | TVector2(dx, dy), |
aae373bb | 285 | padPadPos, padPadDim); |
286 | ||
bde6e10f | 287 | TVector2 bl = padPadPos - padPadDim; |
288 | TVector2 ur = padPadPos + padPadDim; | |
38f79959 | 289 | |
aae373bb | 290 | if (bl0.X() > bl.X()) |
291 | bl0 = bl; | |
bde6e10f | 292 | |
aae373bb | 293 | if (ur0.Y() < ur.Y()) |
294 | ur0 = ur; | |
bde6e10f | 295 | |
aae373bb | 296 | if ( fill ) |
297 | { | |
38f79959 | 298 | Style_t csty = gVirtualX->GetFillColor(); |
299 | Style_t sty = gVirtualX->GetFillStyle(); | |
300 | gVirtualX->SetFillStyle(1); | |
301 | if (manuId == searchMotif) | |
302 | gVirtualX->SetFillColor(5); // yellow | |
303 | gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y()); | |
aae373bb | 304 | gVirtualX->SetFillStyle(sty); |
38f79959 | 305 | gVirtualX->SetFillColor(csty); |
306 | } | |
307 | ||
168e9c4d | 308 | if (!motifType->FindConnectionByLocalIndices(i,j-1)) |
aae373bb | 309 | { |
310 | gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y()); | |
5f91c9e8 | 311 | } |
aae373bb | 312 | |
168e9c4d | 313 | if (!motifType->FindConnectionByLocalIndices(i,j+1)) |
aae373bb | 314 | { |
315 | gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2); | |
316 | } | |
168e9c4d | 317 | if (!motifType->FindConnectionByLocalIndices(i-1,j)) |
aae373bb | 318 | { |
319 | gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2); | |
320 | } | |
321 | ||
168e9c4d | 322 | if (!motifType->FindConnectionByLocalIndices(i+1,j)) |
aae373bb | 323 | { |
38f79959 | 324 | gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2); |
325 | } | |
aae373bb | 326 | } |
38f79959 | 327 | |
5f91c9e8 | 328 | } |
aae373bb | 329 | } |
bde6e10f | 330 | |
aae373bb | 331 | switch (option[1]) { |
332 | // add manudId indexes | |
333 | case 'I' : | |
334 | xl = bl0.X()+ padPadDim.X()/2.; | |
335 | ||
336 | yl = bl0.Y() + 1.5*padPadDim.Y(); | |
337 | ||
338 | Float_t textSize = gVirtualX->GetTextSize(); | |
339 | gVirtualX->SetTextSize(12); | |
340 | gVirtualX->SetTextAlign(13); | |
341 | gVirtualX->SetTextAngle(90.); | |
342 | ||
343 | gPad->PaintText(xl, yl, Form("%d", manuId)); | |
344 | ||
345 | gVirtualX->SetTextAngle(0.); | |
346 | gVirtualX->SetTextSize(textSize); | |
347 | break; | |
5f91c9e8 | 348 | } |
0f6198f2 | 349 | |
aae373bb | 350 | gVirtualX->SetLineWidth(lineW); |
0f6198f2 | 351 | |
5f91c9e8 | 352 | } |