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