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 // Class AliMpMotifPainter
21 // -----------------------
22 // Class for drawing a motif into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
26 #include "AliMpMotifPainter.h"
27 #include "AliMpGraphContext.h"
28 #include "AliMpMotifPosition.h"
29 #include "AliMpMotifType.h"
30 #include "AliMpMotif.h"
31 #include "AliMpConnection.h"
32 #include "AliMpIntPair.h"
35 #include <TVirtualX.h>
39 ClassImp(AliMpMotifPainter)
42 //_______________________________________________________________________
43 AliMpMotifPainter::AliMpMotifPainter()
47 /// Default constructor
50 //_______________________________________________________________________
51 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
55 /// Standard constructor
56 AliDebug(1,"Default ctor");
59 //_______________________________________________________________________
60 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
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.
68 AliDebug(1,"Ctor from motifType");
70 const Double_t kdx = 5;
71 const Double_t kdy = 5; // cm but arbitrary anyway
73 AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
77 fMotifPos = new AliMpMotifPosition(-1,motif,motif->Dimensions());
80 //_______________________________________________________________________
81 AliMpMotifPainter::~AliMpMotifPainter()
83 /// Default constructor
86 //_______________________________________________________________________
87 void AliMpMotifPainter::DumpObject()
89 /// Dump the owned object
94 //_______________________________________________________________________
95 TVector2 AliMpMotifPainter::GetPosition() const
97 /// Get the owned object's position
99 return fMotifPos->Position();
102 //_______________________________________________________________________
103 TVector2 AliMpMotifPainter::GetDimensions() const
105 /// Get the owned object's dimensions
107 return fMotifPos->Dimensions();
110 //_______________________________________________________________________
111 void AliMpMotifPainter::Paint(Option_t *option)
115 AliMpGraphContext *gr = AliMpGraphContext::Instance();
116 if (!fMotifPos) return;
117 Int_t col=gVirtualX->GetFillColor();
119 gPad->Range(0.,0.,1.,1.);
122 gVirtualX->SetLineWidth(1);
130 Float_t textSize = gVirtualX->GetTextSize();
131 gVirtualX->SetTextSize(10);
135 str = Form("%d",fMotifPos->GetID());
140 str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
141 fMotifPos->GetHighIndicesLimit().GetSecond());
144 str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
145 fMotifPos->GetLowIndicesLimit().GetSecond());
150 str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
151 (GetPosition()-GetDimensions()).Y());
154 gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
156 gVirtualX->SetTextSize(textSize);
162 //PaintWholeBox(kFALSE);
163 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
164 for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
165 for (Int_t i=0;i<motifType->GetNofPadsX();i++){
166 AliMpIntPair indices(i,j);
167 AliMpConnection* connect =
168 motifType->FindConnectionByLocalIndices(indices);
170 TVector2 realPadPos =
171 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
172 TVector2 padPadPos,padPadDim;
173 gr->RealToPad(realPadPos,
174 fMotifPos->GetMotif()->GetPadDimensions(indices),
175 padPadPos,padPadDim);
176 TVector2 bl = padPadPos - padPadDim;
177 TVector2 ur = padPadPos + padPadDim;
179 Style_t sty = gVirtualX->GetFillStyle();
180 gVirtualX->SetFillStyle(1);
181 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
182 gVirtualX->SetFillStyle(0);
183 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
184 gVirtualX->SetFillStyle(sty);
187 Float_t textSize = gVirtualX->GetTextSize();
188 gVirtualX->SetTextSize(10);
189 gVirtualX->SetTextAlign(22);
190 gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
191 Form("%d",connect->GetGassiNum()));
193 gVirtualX->SetTextSize(textSize);
198 if ( option[0]=='Z' )
200 PaintContour(option,kFALSE);
206 PaintContour(option,kTRUE);
210 PaintWholeBox(kFALSE);
213 gVirtualX->SetFillColor(col);
216 //_______________________________________________________________________
217 void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
219 /// Drawing real motif (not envelop) the real contour
221 AliMpGraphContext *gr = AliMpGraphContext::Instance();
226 Int_t searchMotif = -1;
227 TVector2 bl0 = TVector2(999, 999);
228 TVector2 ur0 = TVector2(0,0);
229 TVector2 padPadPos,padPadDim;
231 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
232 manuId = fMotifPos->GetID();
237 gVirtualX->SetFillColor(0);
239 gVirtualX->SetFillColor(38);
241 gVirtualX->SetFillColor(33);
243 gVirtualX->SetFillColor(16);
245 gVirtualX->SetFillColor(44);
248 Width_t lineW = gPad->GetLineWidth();
249 Width_t lw = lineW*3;
250 Double_t xlw = gPad->PixeltoX(lw/2);
253 if (option[1] == 'I' && option[2] == ':')
254 searchMotif = atoi(&option[3]);
256 gVirtualX->SetLineWidth(lw);
258 for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
260 for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
262 AliMpIntPair indices = AliMpIntPair(i,j);
263 AliMpConnection* connect = motifType->FindConnectionByLocalIndices(indices);
266 TVector2 realPadPos =
267 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
268 gr->RealToPad(realPadPos, fMotifPos->GetMotif()->GetPadDimensions(indices),
269 padPadPos, padPadDim);
271 TVector2 bl = padPadPos - padPadDim;
272 TVector2 ur = padPadPos + padPadDim;
274 if (bl0.X() > bl.X())
277 if (ur0.Y() < ur.Y())
282 Style_t csty = gVirtualX->GetFillColor();
283 Style_t sty = gVirtualX->GetFillStyle();
284 gVirtualX->SetFillStyle(1);
285 if (manuId == searchMotif)
286 gVirtualX->SetFillColor(5); // yellow
287 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
288 gVirtualX->SetFillStyle(sty);
289 gVirtualX->SetFillColor(csty);
292 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j-1)))
294 gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
297 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j+1)))
299 gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2);
301 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i-1,j)))
303 gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
306 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i+1,j)))
308 gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);
316 // add manudId indexes
318 xl = bl0.X()+ padPadDim.X()/2.;
320 yl = bl0.Y() + 1.5*padPadDim.Y();
322 Float_t textSize = gVirtualX->GetTextSize();
323 gVirtualX->SetTextSize(12);
324 gVirtualX->SetTextAlign(13);
325 gVirtualX->SetTextAngle(90.);
327 gPad->PaintText(xl, yl, Form("%d", manuId));
329 gVirtualX->SetTextAngle(0.);
330 gVirtualX->SetTextSize(textSize);
334 gVirtualX->SetLineWidth(lineW);