1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifPainter
22 // -----------------------
23 // Class for drawing a motif into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpMotifPainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpMotifPosition.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpMotif.h"
33 #include "AliMpConnection.h"
34 #include "AliMpIntPair.h"
37 #include <TVirtualX.h>
41 ClassImp(AliMpMotifPainter)
44 //_______________________________________________________________________
45 AliMpMotifPainter::AliMpMotifPainter()
49 /// Default constructor
52 //_______________________________________________________________________
53 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
57 /// Standard constructor
58 AliDebug(1,"Default ctor");
61 //_______________________________________________________________________
62 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
66 /// Constructor from a motif Type. We hereby create a MotifPosition
67 /// object from it, using arbitrary pad sizes, as this is just a way
68 /// to visualize the *shape* of the motif.
70 AliDebug(1,"Ctor from motifType");
72 const Double_t kdx = 5;
73 const Double_t kdy = 5; // cm but arbitrary anyway
75 AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
79 fMotifPos = new AliMpMotifPosition(-1,motif,motif->Dimensions());
82 //_______________________________________________________________________
83 AliMpMotifPainter::~AliMpMotifPainter()
85 /// Default constructor
88 //_______________________________________________________________________
89 void AliMpMotifPainter::DumpObject()
91 /// Dump the owned object
96 //_______________________________________________________________________
97 TVector2 AliMpMotifPainter::GetPosition() const
99 /// Get the owned object's position
101 return fMotifPos->Position();
104 //_______________________________________________________________________
105 TVector2 AliMpMotifPainter::GetDimensions() const
107 /// Get the owned object's dimensions
109 return fMotifPos->Dimensions();
112 //_______________________________________________________________________
113 void AliMpMotifPainter::Paint(Option_t *option)
117 AliMpGraphContext *gr = AliMpGraphContext::Instance();
118 if (!fMotifPos) return;
119 Int_t col=gVirtualX->GetFillColor();
121 gPad->Range(0.,0.,1.,1.);
124 gVirtualX->SetLineWidth(1);
132 Float_t textSize = gVirtualX->GetTextSize();
133 gVirtualX->SetTextSize(10);
137 str = Form("%d",fMotifPos->GetID());
142 str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
143 fMotifPos->GetHighIndicesLimit().GetSecond());
146 str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
147 fMotifPos->GetLowIndicesLimit().GetSecond());
152 str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
153 (GetPosition()-GetDimensions()).Y());
156 gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
158 gVirtualX->SetTextSize(textSize);
164 //PaintWholeBox(kFALSE);
165 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
166 for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
167 for (Int_t i=0;i<motifType->GetNofPadsX();i++){
168 AliMpIntPair indices(i,j);
169 AliMpConnection* connect =
170 motifType->FindConnectionByLocalIndices(indices);
172 TVector2 realPadPos =
173 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
174 TVector2 padPadPos,padPadDim;
175 gr->RealToPad(realPadPos,
176 fMotifPos->GetMotif()->GetPadDimensions(indices),
177 padPadPos,padPadDim);
178 TVector2 bl = padPadPos - padPadDim;
179 TVector2 ur = padPadPos + padPadDim;
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);
189 Float_t textSize = gVirtualX->GetTextSize();
190 gVirtualX->SetTextSize(10);
191 gVirtualX->SetTextAlign(22);
192 gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
193 Form("%d",connect->GetGassiNum()));
195 gVirtualX->SetTextSize(textSize);
200 if ( option[0]=='Z' )
202 PaintContour(option,kFALSE);
208 PaintContour(option,kTRUE);
212 PaintWholeBox(kFALSE);
215 gVirtualX->SetFillColor(col);
218 //_______________________________________________________________________
219 void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
221 /// Drawing real motif (not envelop) the real contour
223 AliMpGraphContext *gr = AliMpGraphContext::Instance();
228 Int_t searchMotif = -1;
229 TVector2 bl0 = TVector2(999, 999);
230 TVector2 ur0 = TVector2(0,0);
231 TVector2 padPadPos,padPadDim;
233 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
234 manuId = fMotifPos->GetID();
239 gVirtualX->SetFillColor(0);
241 gVirtualX->SetFillColor(38);
243 gVirtualX->SetFillColor(33);
245 gVirtualX->SetFillColor(16);
247 gVirtualX->SetFillColor(44);
250 Width_t lineW = gPad->GetLineWidth();
251 Width_t lw = lineW*3;
252 Double_t xlw = gPad->PixeltoX(lw/2);
255 if (option[1] == 'I' && option[2] == ':')
256 searchMotif = atoi(&option[3]);
258 gVirtualX->SetLineWidth(lw);
260 for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
262 for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
264 AliMpIntPair indices = AliMpIntPair(i,j);
265 AliMpConnection* connect = motifType->FindConnectionByLocalIndices(indices);
268 TVector2 realPadPos =
269 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
270 gr->RealToPad(realPadPos, fMotifPos->GetMotif()->GetPadDimensions(indices),
271 padPadPos, padPadDim);
273 TVector2 bl = padPadPos - padPadDim;
274 TVector2 ur = padPadPos + padPadDim;
276 if (bl0.X() > bl.X())
279 if (ur0.Y() < ur.Y())
284 Style_t csty = gVirtualX->GetFillColor();
285 Style_t sty = gVirtualX->GetFillStyle();
286 gVirtualX->SetFillStyle(1);
287 if (manuId == searchMotif)
288 gVirtualX->SetFillColor(5); // yellow
289 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
290 gVirtualX->SetFillStyle(sty);
291 gVirtualX->SetFillColor(csty);
294 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j-1)))
296 gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
299 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j+1)))
301 gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2);
303 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i-1,j)))
305 gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
308 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i+1,j)))
310 gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);
318 // add manudId indexes
320 xl = bl0.X()+ padPadDim.X()/2.;
322 yl = bl0.Y() + 1.5*padPadDim.Y();
324 Float_t textSize = gVirtualX->GetTextSize();
325 gVirtualX->SetTextSize(12);
326 gVirtualX->SetTextAlign(13);
327 gVirtualX->SetTextAngle(90.);
329 gPad->PaintText(xl, yl, Form("%d", manuId));
331 gVirtualX->SetTextAngle(0.);
332 gVirtualX->SetTextSize(textSize);
336 gVirtualX->SetLineWidth(lineW);