]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSubZonePainter.cxx
Updated comments for Doxygen - corrected warnings
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSubZonePainter.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpSubZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 //
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
25   
26 #include "AliMpSubZonePainter.h"
27 #include "AliMpGraphContext.h"
28 #include "AliMpSubZone.h"
29 #include "AliMpVRowSegment.h"
30 #include "AliMpVMotif.h"
31
32 #include <TVirtualX.h>
33 #include <TPad.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliMpSubZonePainter)
37 /// \endcond
38
39 //_______________________________________________________________________
40 AliMpSubZonePainter::AliMpSubZonePainter()
41   : AliMpVPainter(),
42     fSubZone(0)
43 {
44   /// Default constructor
45 }
46
47 //_______________________________________________________________________
48 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
49   : AliMpVPainter(),
50     fSubZone(subZone)
51 {
52   /// Standard constructor 
53
54 }
55
56 //_____________________________________________________________________________
57 AliMpSubZonePainter::AliMpSubZonePainter(const AliMpSubZonePainter& right) 
58   : AliMpVPainter(right) 
59 {  
60   /// Protected copy constructor (not provided)
61
62   Fatal("AliMpSubZonePainter", "Copy constructor not provided.");
63 }
64
65 //_______________________________________________________________________
66 AliMpSubZonePainter::~AliMpSubZonePainter()
67 {
68   /// Destructor
69 }
70
71 //_____________________________________________________________________________
72 AliMpSubZonePainter& 
73 AliMpSubZonePainter::operator=(const AliMpSubZonePainter& right)
74 {
75   /// Assignment operator (not provided)
76
77   // check assignment to self
78   if (this == &right) return *this;
79
80   Fatal("operator =", "Assignment operator not provided.");
81     
82   return *this;  
83 }    
84
85 //_______________________________________________________________________
86 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
87 {
88   /// Dist to the nearest segment center if (x,y) is inside the sub-zone
89   /// 9999 otherwise
90   
91   if (fSubZone->GetNofRowSegments()<1) return 9999;
92   AliMpGraphContext *gr = AliMpGraphContext::Instance();
93
94   gr->Push();
95   InitGraphContext();
96
97
98   TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
99
100   Double_t res=9999.;
101   for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
102     //for each row segments
103     AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
104
105     TVector2 pos,dim;
106     gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
107
108     if ( IsInside(point,pos,dim) ){
109       Double_t value = (point-pos).Mod();
110       if (value<res) res=value;
111     }
112   }
113   gr->Pop();
114   return (Int_t)res;
115 }
116
117 //_______________________________________________________________________
118 void AliMpSubZonePainter::DumpObject()
119 {
120   //// Draw the owned object
121   
122   fSubZone->Dump();
123 }
124
125 //_______________________________________________________________________
126 TVector2 AliMpSubZonePainter::GetPosition() const
127 {
128   //// Get the owned object's position
129
130   if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
131   AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
132
133   // bl = bottom left position;
134   TVector2 bl = seg->Position()-seg->Dimensions();
135   // ur = upper right position
136   TVector2 ur = seg->Position()+seg->Dimensions();
137
138   for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
139     seg = fSubZone->GetRowSegment(iseg);
140     // update the bottom-left corner
141     if (bl.X()>seg->Position().X()-seg->Dimensions().X())
142       bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
143     if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
144       bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
145     // update the upper-right corner
146     if (ur.X()<seg->Position().X()+seg->Dimensions().X())
147       ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
148     if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
149       ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
150   }
151   return (ur+bl)/2.;
152 }
153
154 //_______________________________________________________________________
155 TVector2 AliMpSubZonePainter::GetDimensions() const
156 {
157   //// Get the owned object's dimensions
158
159   if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
160   AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
161
162   // bl = bottom left position;
163   TVector2 bl = seg->Position()-seg->Dimensions();
164   // ur = upper right position
165   TVector2 ur = seg->Position()+seg->Dimensions();
166
167   for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
168     seg = fSubZone->GetRowSegment(iseg);
169     // update the bottom-left corner
170     if (bl.X()>seg->Position().X()-seg->Dimensions().X())
171       bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
172     if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
173       bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
174     // update the upper-right corner
175     if (ur.X()<seg->Position().X()+seg->Dimensions().X())
176       ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
177     if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
178       ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
179   }
180   return (ur-bl)/2.;
181 }
182
183 //_______________________________________________________________________
184 void AliMpSubZonePainter::Draw(Option_t *option)
185 {
186 /// Draw the sector on the current pad
187 /// The first letter of \a option is treated as follows:
188 /// - case "S" : each row segments are drawn separately
189 /// - case ""  : the whole subzone is drawn at once
190 /// in both cases, the rest of the option is passed
191 /// as argument to the Draw function of respectively
192 /// zone or row objects.
193
194   if (!fSubZone) return;
195   AliMpGraphContext *gr = AliMpGraphContext::Instance();
196
197   gr->Push();
198   InitGraphContext();
199   switch (option[0]){
200   case 'S':
201     {
202
203         for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
204           gr->Push();
205           AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
206
207           gr->SetPadPosForReal(rowSegment->Position(),
208                                rowSegment->Dimensions());
209           gr->SetColor(GetColor());
210           DrawObject(rowSegment,option+1);
211       
212           gr->Pop();
213         }
214     }
215     break;
216   default: AppendPad(option);
217   }
218   gr->Pop();
219 }
220
221
222 //_______________________________________________________________________
223 void AliMpSubZonePainter::Paint(Option_t *option)
224 {
225 //// Paint the object
226
227   AliMpGraphContext *gr = AliMpGraphContext::Instance();
228   if (!fSubZone) return;
229   if (fSubZone->GetNofRowSegments()<1) return;
230   gr->Push();
231   gPad->Range(0.,0.,1.,1.);
232   Int_t col=gVirtualX->GetFillColor();
233   InitGraphContext();
234   
235   gVirtualX->SetFillColor(GetColor());
236   for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
237     AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
238     TVector2 pos,dim;
239     gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
240                   pos,dim);
241     gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
242                    pos.X()+dim.X(),pos.Y()+dim.Y());
243     if (option[0]=='T'){
244       Float_t textSize =   gVirtualX->GetTextSize();
245       gVirtualX->SetTextSize(15);
246       gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
247                       fSubZone->GetMotif()->GetID());
248       gVirtualX->SetTextSize(textSize);
249     }
250   }
251
252   gVirtualX->SetFillColor(col);
253   gr->Pop();
254 }