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