]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpZonePainter.cxx
Coding conventions corrections only
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpZonePainter.cxx
1 // $Id$
2 // Category: graphics
3 //
4 // Class AliMpZonePainter
5 // ----------------------
6 // Class for drawing a zone into canvas
7 //
8 // Authors: David Guez, IPN Orsay
9  
10 #include <TVirtualX.h>
11 #include <TPad.h>
12
13 #include "AliMpZonePainter.h"
14 #include "AliMpGraphContext.h"
15 #include "AliMpZone.h"
16 #include "AliMpSubZone.h"
17 #include "AliMpVRowSegment.h"
18
19 ClassImp(AliMpZonePainter)
20
21 //_______________________________________________________________________
22 AliMpZonePainter::AliMpZonePainter()
23   : AliMpVPainter(),
24     fZone(0)
25 {
26   // default dummy constructor
27 }
28
29 //_______________________________________________________________________
30 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
31   : AliMpVPainter(),
32     fZone(zone)
33 {
34   // normal constructor 
35
36 }
37
38 //_______________________________________________________________________
39 AliMpZonePainter::~AliMpZonePainter()
40 {
41   // destructor 
42
43 }
44
45 //_______________________________________________________________________
46 Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
47 {
48   // dist to the nearest segment center if (x,y) is inside the zone
49   // 9999 otherwise
50   if (fZone->GetNofSubZones()<1) return 9999;
51   AliMpGraphContext *gr = AliMpGraphContext::Instance();
52
53   gr->Push();
54   InitGraphContext();
55   
56   TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
57
58   Double_t res=9999.;
59   for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
60     // for each sub-zones
61     AliMpSubZone* sub = fZone->GetSubZone(isub);
62     for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
63       //for each row segments
64       AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
65
66       TVector2 pos,dim;
67       gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
68
69       if ( IsInside(point,pos,dim) ){
70         Double_t value = (point-pos).Mod();
71         if (value<res) res=value;
72       }
73     }
74   }
75   gr->Pop();
76   return (Int_t)res;
77 }
78
79 //_______________________________________________________________________
80 void AliMpZonePainter::DumpObject()
81 {
82 // Draw the owned object
83   fZone->Dump();
84
85 }
86
87 //_______________________________________________________________________
88 TVector2 AliMpZonePainter::GetPosition() const
89 {
90   // Get the owned object's position
91
92   if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
93
94   TVector2 bl(9999,9999),ur(-9999,-9999);
95
96   for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
97     // for each sub-zones
98     AliMpSubZone* sub = fZone->GetSubZone(isub);
99     for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
100       //for each row segments
101       AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
102
103       // update the bottom-left corner
104       if (bl.X()>seg->Position().X()-seg->Dimensions().X())
105         bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
106       if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
107         bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
108       // update the upper-right corner
109       if (ur.X()<seg->Position().X()+seg->Dimensions().X())
110         ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
111       if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
112         ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
113     } //iseg
114   } //isub
115   return (ur+bl)/2.;
116 }
117
118 //_______________________________________________________________________
119 TVector2 AliMpZonePainter::GetDimensions() const
120 {
121   // Get the owned object's dimensions
122
123   if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
124
125   TVector2 bl(9999,9999),ur(-9999,-9999);
126
127   for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
128     // for each sub-zones
129     AliMpSubZone* sub = fZone->GetSubZone(isub);
130     for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
131       //for each row segments
132       AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
133
134       // update the bottom-left corner
135       if (bl.X()>seg->Position().X()-seg->Dimensions().X())
136         bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
137       if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
138         bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
139       // update the upper-right corner
140       if (ur.X()<seg->Position().X()+seg->Dimensions().X())
141         ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
142       if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
143         ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
144     } //iseg
145   } //isub
146   return (ur-bl)/2.;
147 }
148
149 //_______________________________________________________________________
150 void AliMpZonePainter::Draw(Option_t *option)
151 {
152 // Draw the sector on the current pad
153 // The first letter of <option> is treated as follows:
154 // case "S" : each sub zones are drawn separately
155 // case ""  : the whole zone is drawn at once
156 // in both cases, the rest of the option is passed
157 // as argument to the Draw function of respectively
158 // zone or row objects.
159 // ---
160
161   AliMpGraphContext *gr = AliMpGraphContext::Instance();
162   if (!fZone) return;
163
164   gr->Push();
165   InitGraphContext();
166   switch (option[0]){
167   case 'S':
168     {
169       for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
170         AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
171         gr->Push();
172
173         Double_t blx=  9999,  bly=  9999;
174         Double_t urx= -9999,  ury= -9999;
175
176           for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
177             AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
178
179             TVector2 bl = rowSegment->Position();
180             bl-=rowSegment->Dimensions();
181             TVector2 ur = rowSegment->Position();
182             ur+=rowSegment->Dimensions();
183             
184             if (bl.X()<blx) blx=bl.X();
185             if (bl.Y()<bly) bly=bl.Y();
186             if (ur.X()>urx) urx=ur.X();
187             if (ur.Y()>ury) ury=ur.Y();
188           }
189           TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
190           TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
191       
192           gr->SetPadPosForReal(position,dimensions);
193           gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
194           DrawObject(subZone,option+1);
195       
196           gr->Pop();
197       }
198     }
199     break;
200   default: AppendPad(option);
201   }
202   gr->Pop();
203 }
204
205 //_______________________________________________________________________
206 void AliMpZonePainter::Paint(Option_t *option)
207 {
208 // Paint the object
209   AliMpGraphContext *gr = AliMpGraphContext::Instance();
210   if (!fZone) return;
211   if (fZone->GetNofSubZones()<1) return;
212   gr->Push();
213   gPad->Range(0.,0.,1.,1.);
214
215   Int_t col=gVirtualX->GetFillColor();
216   InitGraphContext();
217   
218   gVirtualX->SetFillColor(GetColor());
219   Float_t textSize =   gVirtualX->GetTextSize();
220   for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
221     AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
222     for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
223       AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
224       TVector2 pos,dim;
225       gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
226                     pos,dim);
227       gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
228                      pos.X()+dim.X(),pos.Y()+dim.Y());
229       if (option[0]=='T'){
230         gVirtualX->SetTextSize(15);
231         gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
232                         Form("%d",fZone->GetID()));
233       }
234     }
235   }
236   gVirtualX->SetTextSize(textSize);
237   gVirtualX->SetFillColor(col);
238   gr->Pop();
239 }