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