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