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