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