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