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: AliMpZonePainter.cxx,v 1.6 2005/08/26 15:43:36 ivana Exp $
20 // Class AliMpZonePainter
21 // ----------------------
22 // Class for drawing a zone into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
26 #include <TVirtualX.h>
30 #include "AliMpZonePainter.h"
31 #include "AliMpGraphContext.h"
32 #include "AliMpZone.h"
33 #include "AliMpSubZone.h"
34 #include "AliMpVRowSegment.h"
36 ClassImp(AliMpZonePainter)
38 //_______________________________________________________________________
39 AliMpZonePainter::AliMpZonePainter()
43 /// Default constructor
46 //_______________________________________________________________________
47 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
51 /// Standard constructor
55 //_____________________________________________________________________________
56 AliMpZonePainter::AliMpZonePainter(const AliMpZonePainter& right)
57 : AliMpVPainter(right)
59 /// Protected copy constructor (not provided)
61 Fatal("AliMpZonePainter", "Copy constructor not provided.");
64 //_______________________________________________________________________
65 AliMpZonePainter::~AliMpZonePainter()
70 //_____________________________________________________________________________
72 AliMpZonePainter::operator=(const AliMpZonePainter& 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 AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
87 /// Distance to the nearest segment center if (x,y) is inside the zone
90 if (fZone->GetNofSubZones()<1) return 9999;
91 AliMpGraphContext *gr = AliMpGraphContext::Instance();
96 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
99 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
100 // for each sub-zones
101 AliMpSubZone* sub = fZone->GetSubZone(isub);
102 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
103 //for each row segments
104 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
107 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
109 if ( IsInside(point,pos,dim) ){
110 Double_t value = (point-pos).Mod();
111 if (value<res) res=value;
119 //_______________________________________________________________________
120 void AliMpZonePainter::DumpObject()
122 /// Dump the owned object
127 //_______________________________________________________________________
128 TVector2 AliMpZonePainter::GetPosition() const
130 //// Get the owned object's position
132 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
134 TVector2 bl(9999,9999),ur(-9999,-9999);
136 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
137 // for each sub-zones
138 AliMpSubZone* sub = fZone->GetSubZone(isub);
139 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
140 //for each row segments
141 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
143 // update the bottom-left corner
144 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
145 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
146 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
147 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
148 // update the upper-right corner
149 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
150 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
151 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
152 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
158 //_______________________________________________________________________
159 TVector2 AliMpZonePainter::GetDimensions() const
161 //// Get the owned object's dimensions
163 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
165 TVector2 bl(9999,9999),ur(-9999,-9999);
167 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
168 // for each sub-zones
169 AliMpSubZone* sub = fZone->GetSubZone(isub);
170 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
171 //for each row segments
172 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
174 // update the bottom-left corner
175 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
176 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
177 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
178 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
179 // update the upper-right corner
180 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
181 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
182 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
183 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
189 //_______________________________________________________________________
190 void AliMpZonePainter::Draw(Option_t *option)
192 /// Draw the sector on the current pad
193 /// The first letter of <option> is treated as follows:
194 /// - case "S" : each sub zones are drawn separately
195 /// - case "" : the whole zone is drawn at once
196 /// in both cases, the rest of the option is passed
197 /// as argument to the Draw function of respectively
198 /// zone or row objects.
200 AliMpGraphContext *gr = AliMpGraphContext::Instance();
208 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
209 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
212 Double_t blx= 9999, bly= 9999;
213 Double_t urx= -9999, ury= -9999;
215 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
216 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
218 TVector2 bl = rowSegment->Position();
219 bl-=rowSegment->Dimensions();
220 TVector2 ur = rowSegment->Position();
221 ur+=rowSegment->Dimensions();
223 if (bl.X()<blx) blx=bl.X();
224 if (bl.Y()<bly) bly=bl.Y();
225 if (ur.X()>urx) urx=ur.X();
226 if (ur.Y()>ury) ury=ur.Y();
228 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
229 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
231 gr->SetPadPosForReal(position,dimensions);
232 gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
233 DrawObject(subZone,option+1);
239 default: AppendPad(option);
244 //_______________________________________________________________________
245 void AliMpZonePainter::Paint(Option_t *option)
247 //// Paint the object
249 AliMpGraphContext *gr = AliMpGraphContext::Instance();
251 if (fZone->GetNofSubZones()<1) return;
253 gPad->Range(0.,0.,1.,1.);
255 Int_t col=gVirtualX->GetFillColor();
258 gVirtualX->SetFillColor(GetColor());
259 Float_t textSize = gVirtualX->GetTextSize();
260 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
261 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
262 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
263 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
265 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
267 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
268 pos.X()+dim.X(),pos.Y()+dim.Y());
270 gVirtualX->SetTextSize(15);
271 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
272 Form("%d",fZone->GetID()));
276 gVirtualX->SetTextSize(textSize);
277 gVirtualX->SetFillColor(col);