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()
62 //_______________________________________________________________________
63 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
65 /// Dist to the nearest segment center if (x,y) is inside the sub-zone
68 if (fSubZone->GetNofRowSegments()<1) return 9999;
69 AliMpGraphContext *gr = AliMpGraphContext::Instance();
75 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
78 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
79 //for each row segments
80 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
83 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
85 if ( IsInside(point,pos,dim) ){
86 Double_t value = (point-pos).Mod();
87 if (value<res) res=value;
94 //_______________________________________________________________________
95 void AliMpSubZonePainter::DumpObject()
97 //// Draw the owned object
102 //_______________________________________________________________________
103 TVector2 AliMpSubZonePainter::GetPosition() const
105 //// Get the owned object's position
107 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
108 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
110 // bl = bottom left position;
111 TVector2 bl = seg->Position()-seg->Dimensions();
112 // ur = upper right position
113 TVector2 ur = seg->Position()+seg->Dimensions();
115 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
116 seg = fSubZone->GetRowSegment(iseg);
117 // update the bottom-left corner
118 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
119 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
120 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
121 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
122 // update the upper-right corner
123 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
124 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
125 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
126 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
131 //_______________________________________________________________________
132 TVector2 AliMpSubZonePainter::GetDimensions() const
134 //// Get the owned object's dimensions
136 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
137 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
139 // bl = bottom left position;
140 TVector2 bl = seg->Position()-seg->Dimensions();
141 // ur = upper right position
142 TVector2 ur = seg->Position()+seg->Dimensions();
144 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
145 seg = fSubZone->GetRowSegment(iseg);
146 // update the bottom-left corner
147 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
148 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
149 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
150 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
151 // update the upper-right corner
152 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
153 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
154 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
155 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
160 //_______________________________________________________________________
161 void AliMpSubZonePainter::Draw(Option_t *option)
163 /// Draw the sector on the current pad
164 /// The first letter of \a option is treated as follows:
165 /// - case "S" : each row segments are drawn separately
166 /// - case "" : the whole subzone is drawn at once
167 /// in both cases, the rest of the option is passed
168 /// as argument to the Draw function of respectively
169 /// zone or row objects.
171 if (!fSubZone) return;
172 AliMpGraphContext *gr = AliMpGraphContext::Instance();
180 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
182 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
184 gr->SetPadPosForReal(rowSegment->Position(),
185 rowSegment->Dimensions());
186 gr->SetColor(GetColor());
187 DrawObject(rowSegment,option+1);
193 default: AppendPad(option);
199 //_______________________________________________________________________
200 void AliMpSubZonePainter::Paint(Option_t *option)
202 //// Paint the object
204 AliMpGraphContext *gr = AliMpGraphContext::Instance();
205 if (!fSubZone) return;
206 if (fSubZone->GetNofRowSegments()<1) return;
208 gPad->Range(0.,0.,1.,1.);
209 Int_t col=gVirtualX->GetFillColor();
212 gVirtualX->SetFillColor(GetColor());
213 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
214 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
216 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
218 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
219 pos.X()+dim.X(),pos.Y()+dim.Y());
221 Float_t textSize = gVirtualX->GetTextSize();
222 gVirtualX->SetTextSize(15);
223 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
224 fSubZone->GetMotif()->GetID());
225 gVirtualX->SetTextSize(textSize);
229 gVirtualX->SetFillColor(col);