AliRoot Core  da88d91 (da88d91)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpMotifPainter.cxx
Go to the documentation of this file.
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 
16 // $Id$
17 // $MpId: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 
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 //-----------------------------------------------------------------------------
27 
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 "AliLog.h"
35 
36 #include <TVirtualX.h>
37 #include <TPad.h>
38 
39 #include <cstdlib>
40 
44 
45 //_______________________________________________________________________
47  : AliMpVPainter(),
48  fMotifPos(0)
49 {
51 }
52 
53 //_______________________________________________________________________
55  : AliMpVPainter(),
56  fMotifPos(motifPos)
57 {
59  AliDebug(1,"Default ctor");
60 }
61 
62 //_______________________________________________________________________
64 : AliMpVPainter(),
65 fMotifPos(0x0)
66 {
70 
71  AliDebug(1,"Ctor from motifType");
72 
73  const Double_t kdx = 5;
74  const Double_t kdy = 5; // cm but arbitrary anyway
75 
76  AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
77  motifType,
78  kdx,kdy);
79 
80  fMotifPos = new AliMpMotifPosition(-1,motif,
81  motif->DimensionX(), motif->DimensionY());
82 }
83 
84 //_______________________________________________________________________
86 {
88 }
89 
90 //_______________________________________________________________________
92 {
94 
95  fMotifPos->Dump();
96 }
97 
98 //_______________________________________________________________________
100 {
102 
103  return TVector2(fMotifPos->GetPositionX(), fMotifPos->GetPositionY());
104 }
105 
106 //_______________________________________________________________________
108 {
110 
111  return TVector2(fMotifPos->GetDimensionX(), fMotifPos->GetDimensionY());
112 }
113 
114 //_______________________________________________________________________
115 void AliMpMotifPainter::Paint(Option_t *option)
116 {
118 
120  if (!fMotifPos) return;
121  Int_t col=gVirtualX->GetFillColor();
122  gr->Push();
123  gPad->Range(0.,0.,1.,1.);
125 
126  gVirtualX->SetLineWidth(1);
127 
128  switch (option[0]){
129  case 'T':
130  case 'I':
131  case 'X':
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':{
142  switch (option[1]){
143  case '+' :
144  str = Form("(%d,%d)",fMotifPos->GetHighLimitIx(),
146  break;
147  default:
148  str = Form("(%d,%d)",fMotifPos->GetLowLimitIx(),
150  }
151  }
152  break;
153  case 'X' :
154  str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
155  (GetPosition()-GetDimensions()).Y());
156  break;
157  }
158  gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
159 
160  gVirtualX->SetTextSize(textSize);
161  }
162  break;
163  case 'P':
164  case 'Z':
165  {
166  //PaintWholeBox(kFALSE);
167  AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
168  for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
169  for (Int_t i=0;i<motifType->GetNofPadsX();i++){
170  AliMpConnection* connect =
171  motifType->FindConnectionByLocalIndices(i,j);
172  if (connect){
173  Double_t localPosX, localPosY;
174  fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY);
175  TVector2 realPadPos =
176  GetPosition()+TVector2(localPosX, localPosY);
177 
178  Double_t dx, dy;
180 
181  TVector2 padPadPos,padPadDim;
182  gr->RealToPad(realPadPos,
183  TVector2(dx, dy),
184  padPadPos,padPadDim);
185  TVector2 bl = padPadPos - padPadDim;
186  TVector2 ur = padPadPos + padPadDim;
187 
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);
194 
195  if (option[1]=='T'){
196  Float_t textSize = gVirtualX->GetTextSize();
197  gVirtualX->SetTextSize(10);
198  gVirtualX->SetTextAlign(22);
199  gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
200  Form("%d",connect->GetManuChannel()));
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 {
229 
231 
232  Float_t xl = 0;
233  Float_t yl = 0;
234  Int_t manuId = 0;
235  Int_t searchMotif = -1;
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 )
244  {
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();
258  Width_t lw = lineW*3;
259  Double_t xlw = gPad->PixeltoX(lw/2);
260 
261 
262  if (option[1] == 'I' && option[2] == ':')
263  searchMotif = atoi(&option[3]);
264 
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 
271  AliMpConnection* connect = motifType->FindConnectionByLocalIndices(i,j);
272 
273  if (connect){
274  Double_t localPosX, localPosY;
275  fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY);
276 
277  TVector2 realPadPos =
278  GetPosition()+TVector2(localPosX, localPosY);
279 
280  Double_t dx, dy;
282 
283  gr->RealToPad(realPadPos,
284  TVector2(dx, dy),
285  padPadPos, padPadDim);
286 
287  TVector2 bl = padPadPos - padPadDim;
288  TVector2 ur = padPadPos + padPadDim;
289 
290  if (bl0.X() > bl.X())
291  bl0 = bl;
292 
293  if (ur0.Y() < ur.Y())
294  ur0 = ur;
295 
296  if ( fill )
297  {
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());
304  gVirtualX->SetFillStyle(sty);
305  gVirtualX->SetFillColor(csty);
306  }
307 
308  if (!motifType->FindConnectionByLocalIndices(i,j-1))
309  {
310  gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
311  }
312 
313  if (!motifType->FindConnectionByLocalIndices(i,j+1))
314  {
315  gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2);
316  }
317  if (!motifType->FindConnectionByLocalIndices(i-1,j))
318  {
319  gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
320  }
321 
322  if (!motifType->FindConnectionByLocalIndices(i+1,j))
323  {
324  gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);
325  }
326  }
327 
328  }
329  }
330 
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;
348  }
349 
350  gVirtualX->SetLineWidth(lineW);
351 
352 }
Double_t GetPositionY() const
Return y position.
void PaintContour(Option_t *option, Bool_t fill)
AliMpMotifPosition * fMotifPos
the motif to draw
Int_t GetLowLimitIx() const
Double_t GetDimensionY() const
Return y dimension.
A connection properties.
virtual Double_t DimensionY() const =0
Return y dimensions.
Double_t GetDimensionX() const
Return x dimension.
Int_t GetLowLimitIy() const
Int_t GetHighLimitIy() const
virtual TVector2 GetPosition() const
Return the owned object's position.
AliMpConnection * FindConnectionByLocalIndices(MpPair_t localIndices) const
static AliMpGraphContext * Instance()
virtual TVector2 GetDimensions() const
Return the owned object's dimensions.
AliMpMotifType * GetMotifType() const
Return the motif type.
Definition: AliMpVMotif.h:87
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t GetID() const
Return motif position ID = manu id.
A placed motif.
Int_t GetNofPadsX() const
Return number of pads in x direction.
TGraph * gr
Definition: CalibTime.C:25
Int_t GetNofPadsY() const
Return number of pads in y direction.
Abstract base class for drawing objects into canvas.
Definition: AliMpVPainter.h:21
AliMpVMotif * GetMotif() const
Return motif.
Class for drawing a motif into canvas.
virtual Double_t DimensionX() const =0
Return x dimensions.
void PaintWholeBox(Bool_t fill=kTRUE)
virtual void PadPositionLocal(MpPair_t localIndices, Double_t &posx, Double_t &posy) const =0
Fill local position of the pad specified by local indices.
virtual void Paint(Option_t *option)
Paint the associated object.
Abstract base class for a motif with its unique ID and the motif type.
Definition: AliMpVMotif.h:24
TString GetID() const
Return unique motif ID.
Int_t GetManuChannel() const
Return manu channel number.
TVector2 RealToPad(const TVector2 &position) const
Int_t str
Definition: AliFMDv1.cxx:83
virtual void DumpObject()
Double_t GetPositionX() const
Return x position.
TVector2 GetPadPosition() const
Return the position inside the graphics pad.
Definition: AliMpVPainter.h:37
A motif with its unique ID and the motif type.
Definition: AliMpMotif.h:23
Int_t GetHighLimitIx() const
Class describing the correspondance between a given area in pad, and a zone of real (cm) position...
void InitGraphContext()
Class that defines the motif properties.
return kTRUE
Definition: AliFMDv1.cxx:97
virtual void GetPadDimensionsByIndices(MpPair_t localIndices, Double_t &dx, Double_t &dy) const =0
Return the dimensions of the pad specified by localIndices.