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: AliMpSubZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpSubZonePainter
22 // -------------------------
23 // Class for drawing a subzone into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpSubZonePainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpSubZone.h"
31 #include "AliMpVRowSegment.h"
32 #include "AliMpVMotif.h"
34 #include <TVirtualX.h>
38 ClassImp(AliMpSubZonePainter)
41 //_______________________________________________________________________
42 AliMpSubZonePainter::AliMpSubZonePainter()
46 /// Default constructor
49 //_______________________________________________________________________
50 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
54 /// Standard constructor
58 //_______________________________________________________________________
59 AliMpSubZonePainter::~AliMpSubZonePainter()
64 //_______________________________________________________________________
65 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
67 /// Dist to the nearest segment center if (x,y) is inside the sub-zone
70 if (fSubZone->GetNofRowSegments()<1) return 9999;
71 AliMpGraphContext *gr = AliMpGraphContext::Instance();
77 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
80 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
81 //for each row segments
82 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
85 gr->RealToPad(TVector2(seg->GetPositionX(), seg->GetPositionY()),
86 TVector2(seg->GetDimensionX(),seg->GetDimensionY()),pos,dim);
88 if ( IsInside(point,pos,dim) ){
89 Double_t value = (point-pos).Mod();
90 if (value<res) res=value;
97 //_______________________________________________________________________
98 void AliMpSubZonePainter::DumpObject()
100 /// Draw the owned object
105 //_______________________________________________________________________
106 TVector2 AliMpSubZonePainter::GetPosition() const
108 /// Get the owned object's position
110 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
111 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
113 // bl = bottom left position;
114 TVector2 bl = TVector2(seg->GetPositionX(), seg->GetPositionY()) -
115 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
116 // ur = upper right position
117 TVector2 ur = TVector2(seg->GetPositionX(), seg->GetPositionY()) +
118 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
120 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
121 seg = fSubZone->GetRowSegment(iseg);
122 // update the bottom-left corner
123 if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
124 bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
125 if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
126 bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
127 // update the upper-right corner
128 if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
129 ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
130 if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
131 ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
136 //_______________________________________________________________________
137 TVector2 AliMpSubZonePainter::GetDimensions() const
139 /// Get the owned object's dimensions
141 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
142 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
144 // bl = bottom left position;
145 TVector2 bl = TVector2(seg->GetPositionX(), seg->GetPositionY()) -
146 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
147 // ur = upper right position
148 TVector2 ur = TVector2(seg->GetPositionX(), seg->GetPositionY()) +
149 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
151 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
152 seg = fSubZone->GetRowSegment(iseg);
153 // update the bottom-left corner
154 if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
155 bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
156 if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
157 bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
158 // update the upper-right corner
159 if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
160 ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
161 if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
162 ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
167 //_______________________________________________________________________
168 void AliMpSubZonePainter::Draw(Option_t *option)
170 /// Draw the sector on the current pad
171 /// The first letter of \a option is treated as follows:
172 /// - case "S" : each row segments are drawn separately
173 /// - case "" : the whole subzone is drawn at once
174 /// in both cases, the rest of the option is passed
175 /// as argument to the Draw function of respectively
176 /// zone or row objects.
178 if (!fSubZone) return;
179 AliMpGraphContext *gr = AliMpGraphContext::Instance();
187 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
189 AliMpVRowSegment* rowSegment = fSubZone->GetRowSegment(iRowSeg);
191 gr->SetPadPosForReal(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
192 TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()));
193 gr->SetColor(GetColor());
194 DrawObject(rowSegment,option+1);
200 default: AppendPad(option);
206 //_______________________________________________________________________
207 void AliMpSubZonePainter::Paint(Option_t *option)
211 AliMpGraphContext *gr = AliMpGraphContext::Instance();
212 if (!fSubZone) return;
213 if (fSubZone->GetNofRowSegments()<1) return;
215 gPad->Range(0.,0.,1.,1.);
216 Int_t col=gVirtualX->GetFillColor();
219 gVirtualX->SetFillColor(GetColor());
220 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
221 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
223 gr->RealToPad(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
224 TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()),
226 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
227 pos.X()+dim.X(),pos.Y()+dim.Y());
229 Float_t textSize = gVirtualX->GetTextSize();
230 gVirtualX->SetTextSize(15);
231 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
232 fSubZone->GetMotif()->GetID());
233 gVirtualX->SetTextSize(textSize);
237 gVirtualX->SetFillColor(col);