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(seg->Position(),seg->Dimensions(),pos,dim);
87 if ( IsInside(point,pos,dim) ){
88 Double_t value = (point-pos).Mod();
89 if (value<res) res=value;
96 //_______________________________________________________________________
97 void AliMpSubZonePainter::DumpObject()
99 /// Draw the owned object
104 //_______________________________________________________________________
105 TVector2 AliMpSubZonePainter::GetPosition() const
107 /// Get the owned object's position
109 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
110 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
112 // bl = bottom left position;
113 TVector2 bl = seg->Position()-seg->Dimensions();
114 // ur = upper right position
115 TVector2 ur = seg->Position()+seg->Dimensions();
117 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
118 seg = fSubZone->GetRowSegment(iseg);
119 // update the bottom-left corner
120 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
121 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
122 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
123 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
124 // update the upper-right corner
125 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
126 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
127 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
128 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
133 //_______________________________________________________________________
134 TVector2 AliMpSubZonePainter::GetDimensions() const
136 /// Get the owned object's dimensions
138 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
139 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
141 // bl = bottom left position;
142 TVector2 bl = seg->Position()-seg->Dimensions();
143 // ur = upper right position
144 TVector2 ur = seg->Position()+seg->Dimensions();
146 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
147 seg = fSubZone->GetRowSegment(iseg);
148 // update the bottom-left corner
149 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
150 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
151 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
152 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
153 // update the upper-right corner
154 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
155 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
156 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
157 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
162 //_______________________________________________________________________
163 void AliMpSubZonePainter::Draw(Option_t *option)
165 /// Draw the sector on the current pad
166 /// The first letter of \a option is treated as follows:
167 /// - case "S" : each row segments are drawn separately
168 /// - case "" : the whole subzone is drawn at once
169 /// in both cases, the rest of the option is passed
170 /// as argument to the Draw function of respectively
171 /// zone or row objects.
173 if (!fSubZone) return;
174 AliMpGraphContext *gr = AliMpGraphContext::Instance();
182 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
184 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
186 gr->SetPadPosForReal(rowSegment->Position(),
187 rowSegment->Dimensions());
188 gr->SetColor(GetColor());
189 DrawObject(rowSegment,option+1);
195 default: AppendPad(option);
201 //_______________________________________________________________________
202 void AliMpSubZonePainter::Paint(Option_t *option)
206 AliMpGraphContext *gr = AliMpGraphContext::Instance();
207 if (!fSubZone) return;
208 if (fSubZone->GetNofRowSegments()<1) return;
210 gPad->Range(0.,0.,1.,1.);
211 Int_t col=gVirtualX->GetFillColor();
214 gVirtualX->SetFillColor(GetColor());
215 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
216 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
218 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
220 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
221 pos.X()+dim.X(),pos.Y()+dim.Y());
223 Float_t textSize = gVirtualX->GetTextSize();
224 gVirtualX->SetTextSize(15);
225 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
226 fSubZone->GetMotif()->GetID());
227 gVirtualX->SetTextSize(textSize);
231 gVirtualX->SetFillColor(col);