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