4 // Class AliMpSubZonePainter
5 // -------------------------
6 // Class for drawing a subzone into canvas
8 // Authors: David Guez, IPN Orsay
10 #include <TVirtualX.h>
14 #include "AliMpSubZonePainter.h"
15 #include "AliMpGraphContext.h"
16 #include "AliMpSubZone.h"
17 #include "AliMpVRowSegment.h"
18 #include "AliMpVMotif.h"
20 ClassImp(AliMpSubZonePainter)
22 //_______________________________________________________________________
23 AliMpSubZonePainter::AliMpSubZonePainter()
27 // default dummy constructor
30 //_______________________________________________________________________
31 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
39 //_____________________________________________________________________________
40 AliMpSubZonePainter::AliMpSubZonePainter(const AliMpSubZonePainter& right)
41 : AliMpVPainter(right)
43 // copy constructor (not implemented)
45 Fatal("AliMpSubZonePainter", "Copy constructor not provided.");
48 //_______________________________________________________________________
49 AliMpSubZonePainter::~AliMpSubZonePainter()
54 //_____________________________________________________________________________
56 AliMpSubZonePainter::operator=(const AliMpSubZonePainter& right)
58 // assignement operator (not implemented)
60 // check assignement to self
61 if (this == &right) return *this;
63 Fatal("operator =", "Assignement operator not provided.");
68 //_______________________________________________________________________
69 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
71 // dist to the nearest segment center if (x,y) is inside the sub-zone
73 if (fSubZone->GetNofRowSegments()<1) return 9999;
74 AliMpGraphContext *gr = AliMpGraphContext::Instance();
80 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
83 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
84 //for each row segments
85 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
88 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
90 if ( IsInside(point,pos,dim) ){
91 Double_t value = (point-pos).Mod();
92 if (value<res) res=value;
99 //_______________________________________________________________________
100 void AliMpSubZonePainter::DumpObject()
102 // Draw the owned object
106 //_______________________________________________________________________
107 TVector2 AliMpSubZonePainter::GetPosition() const
109 // Get the owned object's position
111 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
112 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
114 // bl = bottom left position;
115 TVector2 bl = seg->Position()-seg->Dimensions();
116 // ur = upper right position
117 TVector2 ur = seg->Position()+seg->Dimensions();
119 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
120 seg = fSubZone->GetRowSegment(iseg);
121 // update the bottom-left corner
122 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
123 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
124 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
125 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
126 // update the upper-right corner
127 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
128 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
129 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
130 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
134 //_______________________________________________________________________
135 TVector2 AliMpSubZonePainter::GetDimensions() const
137 // Get the owned object's dimensions
139 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
140 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
142 // bl = bottom left position;
143 TVector2 bl = seg->Position()-seg->Dimensions();
144 // ur = upper right position
145 TVector2 ur = seg->Position()+seg->Dimensions();
147 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
148 seg = fSubZone->GetRowSegment(iseg);
149 // update the bottom-left corner
150 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
151 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
152 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
153 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
154 // update the upper-right corner
155 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
156 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
157 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
158 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 <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.
174 if (!fSubZone) return;
175 AliMpGraphContext *gr = AliMpGraphContext::Instance();
183 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
185 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
187 gr->SetPadPosForReal(rowSegment->Position(),
188 rowSegment->Dimensions());
189 gr->SetColor(GetColor());
190 DrawObject(rowSegment,option+1);
196 default: AppendPad(option);
202 //_______________________________________________________________________
203 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);