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.6 2005/08/26 15:43:36 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 <TVirtualX.h>
30 #include "AliMpSubZonePainter.h"
31 #include "AliMpGraphContext.h"
32 #include "AliMpSubZone.h"
33 #include "AliMpVRowSegment.h"
34 #include "AliMpVMotif.h"
36 ClassImp(AliMpSubZonePainter)
38 //_______________________________________________________________________
39 AliMpSubZonePainter::AliMpSubZonePainter()
43 /// Default constructor
46 //_______________________________________________________________________
47 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
51 /// Standard constructor
55 //_____________________________________________________________________________
56 AliMpSubZonePainter::AliMpSubZonePainter(const AliMpSubZonePainter& right)
57 : AliMpVPainter(right)
59 /// Protected copy constructor (not provided)
61 Fatal("AliMpSubZonePainter", "Copy constructor not provided.");
64 //_______________________________________________________________________
65 AliMpSubZonePainter::~AliMpSubZonePainter()
70 //_____________________________________________________________________________
72 AliMpSubZonePainter::operator=(const AliMpSubZonePainter& right)
74 /// Assignment operator (not provided)
76 // check assignment to self
77 if (this == &right) return *this;
79 Fatal("operator =", "Assignment operator not provided.");
84 //_______________________________________________________________________
85 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
87 /// Dist to the nearest segment center if (x,y) is inside the sub-zone
90 if (fSubZone->GetNofRowSegments()<1) return 9999;
91 AliMpGraphContext *gr = AliMpGraphContext::Instance();
97 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
100 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
101 //for each row segments
102 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
105 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
107 if ( IsInside(point,pos,dim) ){
108 Double_t value = (point-pos).Mod();
109 if (value<res) res=value;
116 //_______________________________________________________________________
117 void AliMpSubZonePainter::DumpObject()
119 //// Draw the owned object
124 //_______________________________________________________________________
125 TVector2 AliMpSubZonePainter::GetPosition() const
127 //// Get the owned object's position
129 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
130 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
132 // bl = bottom left position;
133 TVector2 bl = seg->Position()-seg->Dimensions();
134 // ur = upper right position
135 TVector2 ur = seg->Position()+seg->Dimensions();
137 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
138 seg = fSubZone->GetRowSegment(iseg);
139 // update the bottom-left corner
140 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
141 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
142 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
143 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
144 // update the upper-right corner
145 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
146 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
147 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
148 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
153 //_______________________________________________________________________
154 TVector2 AliMpSubZonePainter::GetDimensions() const
156 //// Get the owned object's dimensions
158 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
159 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
161 // bl = bottom left position;
162 TVector2 bl = seg->Position()-seg->Dimensions();
163 // ur = upper right position
164 TVector2 ur = seg->Position()+seg->Dimensions();
166 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
167 seg = fSubZone->GetRowSegment(iseg);
168 // update the bottom-left corner
169 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
170 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
171 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
172 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
173 // update the upper-right corner
174 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
175 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
176 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
177 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
182 //_______________________________________________________________________
183 void AliMpSubZonePainter::Draw(Option_t *option)
185 /// Draw the sector on the current pad
186 /// The first letter of <option> is treated as follows:
187 /// - case "S" : each row segments are drawn separately
188 /// - case "" : the whole subzone is drawn at once
189 /// in both cases, the rest of the option is passed
190 /// as argument to the Draw function of respectively
191 /// zone or row objects.
193 if (!fSubZone) return;
194 AliMpGraphContext *gr = AliMpGraphContext::Instance();
202 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
204 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
206 gr->SetPadPosForReal(rowSegment->Position(),
207 rowSegment->Dimensions());
208 gr->SetColor(GetColor());
209 DrawObject(rowSegment,option+1);
215 default: AppendPad(option);
221 //_______________________________________________________________________
222 void AliMpSubZonePainter::Paint(Option_t *option)
224 //// Paint the object
226 AliMpGraphContext *gr = AliMpGraphContext::Instance();
227 if (!fSubZone) return;
228 if (fSubZone->GetNofRowSegments()<1) return;
230 gPad->Range(0.,0.,1.,1.);
231 Int_t col=gVirtualX->GetFillColor();
234 gVirtualX->SetFillColor(GetColor());
235 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
236 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
238 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
240 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
241 pos.X()+dim.X(),pos.Y()+dim.Y());
243 Float_t textSize = gVirtualX->GetTextSize();
244 gVirtualX->SetTextSize(15);
245 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
246 fSubZone->GetMotif()->GetID());
247 gVirtualX->SetTextSize(textSize);
251 gVirtualX->SetFillColor(col);