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