]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpVPainter.cxx
No need to be a singleton
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVPainter.cxx
CommitLineData
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"
49#include "AliMpSlatSegmentation.h"
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 58ClassImp(AliMpVPainter)
13985652 59/// \endcond
5f91c9e8 60
61//_______________________________________________________________________
62AliMpVPainter::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//_______________________________________________________________________
79AliMpVPainter::~AliMpVPainter()
80{
dee1d5f1 81 /// Destructor
82
5f91c9e8 83 if (fTrashList){
84 fTrashList->Delete();
85 delete fTrashList;
86 }
87}
88
89//_______________________________________________________________________
90Bool_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//_______________________________________________________________________
98Int_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//_______________________________________________________________________
112void AliMpVPainter::DumpObject() const
113{
dee1d5f1 114 /// Dump the painted object
5f91c9e8 115}
116
117//_______________________________________________________________________
118TObject* 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//_______________________________________________________________________
131TObject* 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//_______________________________________________________________________
149AliMpVPainter *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
183 const AliMpSlatSegmentation* slatSegmentation = dynamic_cast<const AliMpSlatSegmentation*>(object);
184 if (slatSegmentation)
185 {
186 return new AliMpSlatPainter(slatSegmentation->Slat());
187 }
188 }
5f91c9e8 189 return painter;
190}
191
192//_______________________________________________________________________
193void AliMpVPainter::AddPainter(AliMpVPainter *painter)
194{
dee1d5f1 195 /// Add a painter to the list of painters (private)
196
5f91c9e8 197 fTrashList->Add(painter);
198}
199
200
201//_______________________________________________________________________
202AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
203{
dee1d5f1 204 /// Draw the object \n
205 /// Return the AliMpVPainter object created for the drawing
206
5f91c9e8 207 AliMpVPainter *painter=CreatePainter(object);
208
209 if (painter){
210 painter->Draw(option);
211 AddPainter(painter);
212 }
213 return painter;
214}
215
216//_______________________________________________________________________
217void AliMpVPainter::InitGraphContext()
218{
dee1d5f1 219 /// Set the pad and real area of the graphic context to
220 /// the one stored in this painter
5f91c9e8 221
222 AliMpGraphContext *gr = AliMpGraphContext::Instance();
223 gr->SetPadPosition(fPadPosition);
224 gr->SetPadDimensions(fPadDimensions);
225 gr->SetRealPosition(GetPosition());
226 gr->SetRealDimensions(GetDimensions());
227 gVirtualX->SetFillColor(fColor);
228 gVirtualX->SetTextColor(1);
229 gVirtualX->SetLineColor(1);
230}
231
232//_______________________________________________________________________
233void AliMpVPainter::PaintWholeBox(Bool_t fill)
234{
dee1d5f1 235 /// Paint the box around the total pad area given in this painter
236 /// fill it or bnot following the parameter value
5f91c9e8 237
238 Double_t x1,y1,x2,y2;
239 x1 = fPadPosition.X()-fPadDimensions.X();
240 y1 = fPadPosition.Y()-fPadDimensions.Y();
241 x2 = fPadPosition.X()+fPadDimensions.X();
242 y2 = fPadPosition.Y()+fPadDimensions.Y();
243
244 Style_t sty = gVirtualX->GetFillStyle();
245 gVirtualX->SetFillStyle(fill?1:0);
246 gPad->PaintBox(x1,y1,x2,y2);
247 gVirtualX->SetFillStyle(0);
248 gPad->PaintBox(x1,y1,x2,y2);
249 gVirtualX->SetFillStyle(sty);
250}
251
252//_______________________________________________________________________
253TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
254{
dee1d5f1 255 /// Transform a real position into its equivalent position in a canvas
5f91c9e8 256
257 AliMpGraphContext *gr = AliMpGraphContext::Instance();
258 gr->Push();
259 gr->SetPadPosition(fPadPosition);
260 gr->SetPadDimensions(fPadDimensions);
261 gr->SetRealPosition(GetPosition());
262 gr->SetRealDimensions(GetDimensions());
263
264
265 TVector2 ans = gr->RealToPad(realPos);
266 gr->Pop();
267 return ans;
268}