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 // Class AliMpSubZonePainter
21 // -------------------------
22 // Class for drawing a subzone into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
26 #include "AliMpSubZonePainter.h"
27 #include "AliMpGraphContext.h"
28 #include "AliMpSubZone.h"
29 #include "AliMpVRowSegment.h"
30 #include "AliMpVMotif.h"
32 #include <TVirtualX.h>
36 ClassImp(AliMpSubZonePainter)
39 //_______________________________________________________________________
40 AliMpSubZonePainter::AliMpSubZonePainter()
44 /// Default constructor
47 //_______________________________________________________________________
48 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
52 /// Standard constructor
56 //_____________________________________________________________________________
57 AliMpSubZonePainter::AliMpSubZonePainter(const AliMpSubZonePainter& right)
58 : AliMpVPainter(right)
60 /// Protected copy constructor (not provided)
62 Fatal("AliMpSubZonePainter", "Copy constructor not provided.");
65 //_______________________________________________________________________
66 AliMpSubZonePainter::~AliMpSubZonePainter()
71 //_____________________________________________________________________________
73 AliMpSubZonePainter::operator=(const AliMpSubZonePainter& right)
75 /// Assignment operator (not provided)
77 // check assignment to self
78 if (this == &right) return *this;
80 Fatal("operator =", "Assignment operator not provided.");
85 //_______________________________________________________________________
86 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
88 /// Dist to the nearest segment center if (x,y) is inside the sub-zone
91 if (fSubZone->GetNofRowSegments()<1) return 9999;
92 AliMpGraphContext *gr = AliMpGraphContext::Instance();
98 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
101 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
102 //for each row segments
103 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
106 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
108 if ( IsInside(point,pos,dim) ){
109 Double_t value = (point-pos).Mod();
110 if (value<res) res=value;
117 //_______________________________________________________________________
118 void AliMpSubZonePainter::DumpObject()
120 //// Draw the owned object
125 //_______________________________________________________________________
126 TVector2 AliMpSubZonePainter::GetPosition() const
128 //// Get the owned object's position
130 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
131 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
133 // bl = bottom left position;
134 TVector2 bl = seg->Position()-seg->Dimensions();
135 // ur = upper right position
136 TVector2 ur = seg->Position()+seg->Dimensions();
138 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
139 seg = fSubZone->GetRowSegment(iseg);
140 // update the bottom-left corner
141 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
142 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
143 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
144 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
145 // update the upper-right corner
146 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
147 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
148 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
149 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
154 //_______________________________________________________________________
155 TVector2 AliMpSubZonePainter::GetDimensions() const
157 //// Get the owned object's dimensions
159 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
160 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
162 // bl = bottom left position;
163 TVector2 bl = seg->Position()-seg->Dimensions();
164 // ur = upper right position
165 TVector2 ur = seg->Position()+seg->Dimensions();
167 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
168 seg = fSubZone->GetRowSegment(iseg);
169 // update the bottom-left corner
170 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
171 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
172 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
173 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
174 // update the upper-right corner
175 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
176 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
177 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
178 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
183 //_______________________________________________________________________
184 void AliMpSubZonePainter::Draw(Option_t *option)
186 /// Draw the sector on the current pad
187 /// The first letter of \a option is treated as follows:
188 /// - case "S" : each row segments are drawn separately
189 /// - case "" : the whole subzone is drawn at once
190 /// in both cases, the rest of the option is passed
191 /// as argument to the Draw function of respectively
192 /// zone or row objects.
194 if (!fSubZone) return;
195 AliMpGraphContext *gr = AliMpGraphContext::Instance();
203 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
205 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
207 gr->SetPadPosForReal(rowSegment->Position(),
208 rowSegment->Dimensions());
209 gr->SetColor(GetColor());
210 DrawObject(rowSegment,option+1);
216 default: AppendPad(option);
222 //_______________________________________________________________________
223 void AliMpSubZonePainter::Paint(Option_t *option)
225 //// Paint the object
227 AliMpGraphContext *gr = AliMpGraphContext::Instance();
228 if (!fSubZone) return;
229 if (fSubZone->GetNofRowSegments()<1) return;
231 gPad->Range(0.,0.,1.,1.);
232 Int_t col=gVirtualX->GetFillColor();
235 gVirtualX->SetFillColor(GetColor());
236 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
237 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
239 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
241 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
242 pos.X()+dim.X(),pos.Y()+dim.Y());
244 Float_t textSize = gVirtualX->GetTextSize();
245 gVirtualX->SetTextSize(15);
246 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
247 fSubZone->GetMotif()->GetID());
248 gVirtualX->SetTextSize(textSize);
252 gVirtualX->SetFillColor(col);