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