4 // Class AliMpSubZonePainter
5 // -------------------------
6 // Class for drawing a subzone into canvas
8 // Authors: David Guez, IPN Orsay
10 #include "AliMpSubZonePainter.h"
11 #include "AliMpGraphContext.h"
12 #include "AliMpSubZone.h"
13 #include "AliMpVRowSegment.h"
14 #include "AliMpVMotif.h"
16 ClassImp(AliMpSubZonePainter)
18 //_______________________________________________________________________
19 AliMpSubZonePainter::AliMpSubZonePainter()
23 // default dummy constructor
25 //_______________________________________________________________________
26 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
33 //_______________________________________________________________________
34 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
36 // dist to the nearest segment center if (x,y) is inside the sub-zone
38 if (fSubZone->GetNofRowSegments()<1) return 9999;
39 AliMpGraphContext *gr = AliMpGraphContext::Instance();
45 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
48 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
49 //for each row segments
50 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
53 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
55 if ( IsInside(point,pos,dim) ){
56 Double_t value = (point-pos).Mod();
57 if (value<res) res=value;
64 //_______________________________________________________________________
65 void AliMpSubZonePainter::DumpObject()
67 // Draw the owned object
71 //_______________________________________________________________________
72 TVector2 AliMpSubZonePainter::GetPosition() const
74 // Get the owned object's position
76 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
77 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
79 // bl = bottom left position;
80 TVector2 bl = seg->Position()-seg->Dimensions();
81 // ur = upper right position
82 TVector2 ur = seg->Position()+seg->Dimensions();
84 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
85 seg = fSubZone->GetRowSegment(iseg);
86 // update the bottom-left corner
87 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
88 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
89 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
90 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
91 // update the upper-right corner
92 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
93 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
94 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
95 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
99 //_______________________________________________________________________
100 TVector2 AliMpSubZonePainter::GetDimensions() const
102 // Get the owned object's dimensions
104 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
105 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
107 // bl = bottom left position;
108 TVector2 bl = seg->Position()-seg->Dimensions();
109 // ur = upper right position
110 TVector2 ur = seg->Position()+seg->Dimensions();
112 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
113 seg = fSubZone->GetRowSegment(iseg);
114 // update the bottom-left corner
115 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
116 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
117 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
118 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
119 // update the upper-right corner
120 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
121 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
122 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
123 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
127 //_______________________________________________________________________
128 void AliMpSubZonePainter::Draw(Option_t *option)
130 // Draw the sector on the current pad
131 // The first letter of <option> is treated as follows:
132 // case "S" : each row segments are drawn separately
133 // case "" : the whole subzone is drawn at once
134 // in both cases, the rest of the option is passed
135 // as argument to the Draw function of respectively
136 // zone or row objects.
139 if (!fSubZone) return;
140 AliMpGraphContext *gr = AliMpGraphContext::Instance();
148 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
150 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
152 gr->SetPadPosForReal(rowSegment->Position(),
153 rowSegment->Dimensions());
154 gr->SetColor(GetColor());
155 DrawObject(rowSegment,option+1);
161 default: AppendPad(option);
167 //_______________________________________________________________________
168 void AliMpSubZonePainter::Paint(Option_t *option)
171 AliMpGraphContext *gr = AliMpGraphContext::Instance();
172 if (!fSubZone) return;
173 if (fSubZone->GetNofRowSegments()<1) return;
175 gPad->Range(0.,0.,1.,1.);
176 Int_t col=gVirtualX->GetFillColor();
179 gVirtualX->SetFillColor(GetColor());
180 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
181 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
183 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
185 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
186 pos.X()+dim.X(),pos.Y()+dim.Y());
188 Float_t textSize = gVirtualX->GetTextSize();
189 gVirtualX->SetTextSize(15);
190 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
191 fSubZone->GetMotif()->GetID());
192 gVirtualX->SetTextSize(textSize);
196 gVirtualX->SetFillColor(col);