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