]>
Commit | Line | Data |
---|---|---|
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$ |
13985652 | 17 | // $MpId: AliMpVPainter.cxx,v 1.10 2006/05/24 13:58:32 ivana Exp $ |
5f91c9e8 | 18 | // Category: graphics |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpVPainter |
22 | // -------------- | |
23 | // Class for drawing objects into canvas | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
5f91c9e8 | 28 | #include "AliMpVPainter.h" |
29 | #include "AliMpGraphContext.h" | |
30 | #include "AliMpSector.h" | |
31 | #include "AliMpRow.h" | |
32 | #include "AliMpZone.h" | |
33 | #include "AliMpSubZone.h" | |
34 | #include "AliMpVRowSegment.h" | |
35 | #include "AliMpMotifPosition.h" | |
36 | #include "AliMpSectorPainter.h" | |
37 | #include "AliMpRowPainter.h" | |
38 | #include "AliMpZonePainter.h" | |
39 | #include "AliMpSubZonePainter.h" | |
40 | #include "AliMpRowSegmentPainter.h" | |
41 | #include "AliMpMotifPainter.h" | |
bde6e10f | 42 | #include "AliMpMotifType.h" |
dee1d5f1 | 43 | #include "AliMpPCB.h" |
44 | #include "AliMpPCBPainter.h" | |
45 | #include "AliMpSlat.h" | |
46 | #include "AliMpSlatPainter.h" | |
0a2fbb23 | 47 | #include "AliMpIteratorPainter.h" |
48 | #include "AliMpVPadIterator.h" | |
f3ed9a44 | 49 | #include "AliMpSegmentation.h" |
0a2fbb23 | 50 | //#include "AliMpSectorSegmentation.h" |
5f91c9e8 | 51 | |
2c605e66 | 52 | #include <TList.h> |
53 | #include <TVirtualX.h> | |
54 | #include <TPad.h> | |
a1e17193 | 55 | #include <TROOT.h> |
2c605e66 | 56 | |
13985652 | 57 | /// \cond CLASSIMP |
5f91c9e8 | 58 | ClassImp(AliMpVPainter) |
13985652 | 59 | /// \endcond |
5f91c9e8 | 60 | |
61 | //_______________________________________________________________________ | |
62 | AliMpVPainter::AliMpVPainter() | |
63 | : TObject(), | |
13e7956b | 64 | fColor(2), |
65 | fPadPosition(), | |
66 | fPadDimensions(), | |
67 | fTrashList(0) | |
5f91c9e8 | 68 | { |
dee1d5f1 | 69 | /// Default constructor |
70 | ||
5f91c9e8 | 71 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); |
72 | fPadPosition = gr->GetPadPosition(); | |
73 | fPadDimensions = gr->GetPadDimensions(); | |
74 | fColor=gr->GetColor(); | |
75 | fTrashList = new TList; | |
76 | } | |
77 | ||
78 | //_______________________________________________________________________ | |
79 | AliMpVPainter::~AliMpVPainter() | |
80 | { | |
dee1d5f1 | 81 | /// Destructor |
82 | ||
5f91c9e8 | 83 | if (fTrashList){ |
84 | fTrashList->Delete(); | |
85 | delete fTrashList; | |
86 | } | |
87 | } | |
88 | ||
89 | //_______________________________________________________________________ | |
90 | Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim) | |
91 | { | |
13985652 | 92 | /// Is the point \a point inside the \a area (pos,dim)? |
dee1d5f1 | 93 | |
5f91c9e8 | 94 | return ( (TMath::Abs(point.X()-pos.X())<dim.X() ) && (TMath::Abs(point.Y()-pos.Y())<dim.Y() ) ); |
95 | } | |
96 | ||
97 | //_______________________________________________________________________ | |
98 | Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y) | |
99 | { | |
dee1d5f1 | 100 | /// Distance to the center if (x,y) is inside the box defined by (fPadPosition,fPadDimensions) |
101 | /// 9999 otherwise | |
102 | ||
103 | TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y)); | |
104 | if ( IsInside(point,fPadPosition,fPadDimensions) ) | |
105 | { | |
106 | return (Int_t)(point-fPadPosition).Mod(); | |
107 | } | |
108 | return 9999; | |
5f91c9e8 | 109 | } |
110 | ||
111 | //_______________________________________________________________________ | |
112 | void AliMpVPainter::DumpObject() const | |
113 | { | |
dee1d5f1 | 114 | /// Dump the painted object |
5f91c9e8 | 115 | } |
116 | ||
117 | //_______________________________________________________________________ | |
118 | TObject* AliMpVPainter::Clone(const char* newname) const | |
119 | { | |
dee1d5f1 | 120 | /// Create a clone of this object |
121 | ||
5f91c9e8 | 122 | AliMpVPainter *newobj = (AliMpVPainter *)TObject::Clone(newname); |
123 | if (!newobj) return 0; | |
124 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
125 | newobj->fPadPosition = gr->GetPadPosition(); | |
126 | newobj->fPadDimensions = gr->GetPadDimensions(); | |
127 | return newobj; | |
128 | } | |
129 | ||
130 | //_______________________________________________________________________ | |
131 | TObject* AliMpVPainter::DrawClone(Option_t* option) const | |
132 | { | |
dee1d5f1 | 133 | /// Draw the clone object |
134 | ||
5f91c9e8 | 135 | TVirtualPad *pad = gROOT->GetSelectedPad(); |
136 | TVirtualPad *padsav = gPad; | |
137 | ||
138 | TObject *newobj = Clone(); | |
139 | ||
140 | if (!newobj) return 0; | |
141 | ||
142 | if (pad) pad->cd(); | |
143 | newobj->Draw(option); | |
144 | if (padsav) padsav->cd(); | |
145 | return newobj; | |
146 | } | |
147 | ||
148 | //_______________________________________________________________________ | |
149 | AliMpVPainter *AliMpVPainter::CreatePainter(TObject *object) | |
150 | { | |
dee1d5f1 | 151 | /// Create a new painter, which correspond to the |
152 | /// class of object | |
153 | ||
5f91c9e8 | 154 | AliMpVPainter *painter=0; |
155 | if (object->InheritsFrom(AliMpSector::Class())) | |
156 | painter = new AliMpSectorPainter((AliMpSector *)object); | |
157 | else if (object->InheritsFrom(AliMpZone::Class())) | |
158 | painter = new AliMpZonePainter((AliMpZone *)object); | |
159 | else if (object->InheritsFrom(AliMpSubZone::Class())) | |
160 | painter = new AliMpSubZonePainter((AliMpSubZone *)object); | |
161 | else if (object->InheritsFrom(AliMpRow::Class())) | |
162 | painter = new AliMpRowPainter((AliMpRow *)object); | |
163 | else if (object->InheritsFrom(AliMpVRowSegment::Class())) | |
164 | painter = new AliMpRowSegmentPainter((AliMpVRowSegment *)object); | |
165 | else if (object->InheritsFrom(AliMpMotifPosition::Class())) | |
166 | painter = new AliMpMotifPainter((AliMpMotifPosition *)object); | |
bde6e10f | 167 | else if (object->InheritsFrom(AliMpMotifType::Class())) |
168 | painter = new AliMpMotifPainter((AliMpMotifType *)object); | |
dee1d5f1 | 169 | else if (object->InheritsFrom(AliMpPCB::Class())) |
170 | painter = new AliMpPCBPainter((AliMpPCB *)object); | |
171 | else if (object->InheritsFrom(AliMpSlat::Class())) | |
172 | painter = new AliMpSlatPainter((AliMpSlat*)object); | |
0a2fbb23 | 173 | else if (object->InheritsFrom(AliMpVPadIterator::Class())) |
174 | painter = new AliMpIteratorPainter((AliMpVPadIterator*)object); | |
175 | else if (object->InheritsFrom(AliMpVSegmentation::Class())) | |
176 | { | |
177 | // const AliMpSectorSegmentation* sectorSegmentation = dynamic_cast<const AliMpSectorSegmentation*>(object); | |
178 | // if (sectorSegmentation) | |
179 | // { | |
180 | // return new AliMpSectorPainter(sectorSegmentation->GetSector()); | |
181 | // } | |
182 | ||
f3ed9a44 | 183 | /* |
0a2fbb23 | 184 | const AliMpSlatSegmentation* slatSegmentation = dynamic_cast<const AliMpSlatSegmentation*>(object); |
185 | if (slatSegmentation) | |
186 | { | |
187 | return new AliMpSlatPainter(slatSegmentation->Slat()); | |
188 | } | |
f3ed9a44 | 189 | */ |
190 | const AliMpSlat* kSlat | |
191 | = AliMpSegmentation::Instance()->GetSlat((AliMpVSegmentation*)object); | |
192 | if ( kSlat ) | |
193 | { | |
194 | return new AliMpSlatPainter(kSlat); | |
195 | } | |
196 | ||
0a2fbb23 | 197 | } |
5f91c9e8 | 198 | return painter; |
199 | } | |
200 | ||
201 | //_______________________________________________________________________ | |
202 | void AliMpVPainter::AddPainter(AliMpVPainter *painter) | |
203 | { | |
dee1d5f1 | 204 | /// Add a painter to the list of painters (private) |
205 | ||
5f91c9e8 | 206 | fTrashList->Add(painter); |
207 | } | |
208 | ||
209 | ||
210 | //_______________________________________________________________________ | |
211 | AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option) | |
212 | { | |
dee1d5f1 | 213 | /// Draw the object \n |
214 | /// Return the AliMpVPainter object created for the drawing | |
215 | ||
5f91c9e8 | 216 | AliMpVPainter *painter=CreatePainter(object); |
217 | ||
218 | if (painter){ | |
219 | painter->Draw(option); | |
220 | AddPainter(painter); | |
221 | } | |
222 | return painter; | |
223 | } | |
224 | ||
225 | //_______________________________________________________________________ | |
226 | void AliMpVPainter::InitGraphContext() | |
227 | { | |
dee1d5f1 | 228 | /// Set the pad and real area of the graphic context to |
229 | /// the one stored in this painter | |
5f91c9e8 | 230 | |
231 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
232 | gr->SetPadPosition(fPadPosition); | |
233 | gr->SetPadDimensions(fPadDimensions); | |
234 | gr->SetRealPosition(GetPosition()); | |
235 | gr->SetRealDimensions(GetDimensions()); | |
236 | gVirtualX->SetFillColor(fColor); | |
237 | gVirtualX->SetTextColor(1); | |
238 | gVirtualX->SetLineColor(1); | |
239 | } | |
240 | ||
241 | //_______________________________________________________________________ | |
242 | void AliMpVPainter::PaintWholeBox(Bool_t fill) | |
243 | { | |
dee1d5f1 | 244 | /// Paint the box around the total pad area given in this painter |
245 | /// fill it or bnot following the parameter value | |
5f91c9e8 | 246 | |
247 | Double_t x1,y1,x2,y2; | |
248 | x1 = fPadPosition.X()-fPadDimensions.X(); | |
249 | y1 = fPadPosition.Y()-fPadDimensions.Y(); | |
250 | x2 = fPadPosition.X()+fPadDimensions.X(); | |
251 | y2 = fPadPosition.Y()+fPadDimensions.Y(); | |
252 | ||
253 | Style_t sty = gVirtualX->GetFillStyle(); | |
254 | gVirtualX->SetFillStyle(fill?1:0); | |
255 | gPad->PaintBox(x1,y1,x2,y2); | |
256 | gVirtualX->SetFillStyle(0); | |
257 | gPad->PaintBox(x1,y1,x2,y2); | |
258 | gVirtualX->SetFillStyle(sty); | |
259 | } | |
260 | ||
261 | //_______________________________________________________________________ | |
262 | TVector2 AliMpVPainter::RealToPad(const TVector2& realPos) | |
263 | { | |
dee1d5f1 | 264 | /// Transform a real position into its equivalent position in a canvas |
5f91c9e8 | 265 | |
266 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
267 | gr->Push(); | |
268 | gr->SetPadPosition(fPadPosition); | |
269 | gr->SetPadDimensions(fPadDimensions); | |
270 | gr->SetRealPosition(GetPosition()); | |
271 | gr->SetRealDimensions(GetDimensions()); | |
272 | ||
273 | ||
274 | TVector2 ans = gr->RealToPad(realPos); | |
275 | gr->Pop(); | |
276 | return ans; | |
277 | } |