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