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