1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpVPainter.cxx,v 1.10 2006/05/24 13:58:32 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpVPainter
23 // Class for drawing objects into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpVPainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpSector.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"
42 #include "AliMpMotifType.h"
44 #include "AliMpPCBPainter.h"
45 #include "AliMpSlat.h"
46 #include "AliMpSlatPainter.h"
47 #include "AliMpIteratorPainter.h"
48 #include "AliMpVPadIterator.h"
49 #include "AliMpSlatSegmentation.h"
50 //#include "AliMpSectorSegmentation.h"
53 #include <TVirtualX.h>
58 ClassImp(AliMpVPainter)
61 //_______________________________________________________________________
62 AliMpVPainter::AliMpVPainter()
69 /// Default constructor
71 AliMpGraphContext *gr = AliMpGraphContext::Instance();
72 fPadPosition = gr->GetPadPosition();
73 fPadDimensions = gr->GetPadDimensions();
74 fColor=gr->GetColor();
75 fTrashList = new TList;
78 //_______________________________________________________________________
79 AliMpVPainter::~AliMpVPainter()
89 //_______________________________________________________________________
90 Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim)
92 /// Is the point \a point inside the \a area (pos,dim)?
94 return ( (TMath::Abs(point.X()-pos.X())<dim.X() ) && (TMath::Abs(point.Y()-pos.Y())<dim.Y() ) );
97 //_______________________________________________________________________
98 Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y)
100 /// Distance to the center if (x,y) is inside the box defined by (fPadPosition,fPadDimensions)
103 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
104 if ( IsInside(point,fPadPosition,fPadDimensions) )
106 return (Int_t)(point-fPadPosition).Mod();
111 //_______________________________________________________________________
112 void AliMpVPainter::DumpObject() const
114 /// Dump the painted object
117 //_______________________________________________________________________
118 TObject* AliMpVPainter::Clone(const char* newname) const
120 /// Create a clone of this object
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();
130 //_______________________________________________________________________
131 TObject* AliMpVPainter::DrawClone(Option_t* option) const
133 /// Draw the clone object
135 TVirtualPad *pad = gROOT->GetSelectedPad();
136 TVirtualPad *padsav = gPad;
138 TObject *newobj = Clone();
140 if (!newobj) return 0;
143 newobj->Draw(option);
144 if (padsav) padsav->cd();
148 //_______________________________________________________________________
149 AliMpVPainter *AliMpVPainter::CreatePainter(TObject *object)
151 /// Create a new painter, which correspond to the
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);
167 else if (object->InheritsFrom(AliMpMotifType::Class()))
168 painter = new AliMpMotifPainter((AliMpMotifType *)object);
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);
173 else if (object->InheritsFrom(AliMpVPadIterator::Class()))
174 painter = new AliMpIteratorPainter((AliMpVPadIterator*)object);
175 else if (object->InheritsFrom(AliMpVSegmentation::Class()))
177 // const AliMpSectorSegmentation* sectorSegmentation = dynamic_cast<const AliMpSectorSegmentation*>(object);
178 // if (sectorSegmentation)
180 // return new AliMpSectorPainter(sectorSegmentation->GetSector());
183 const AliMpSlatSegmentation* slatSegmentation = dynamic_cast<const AliMpSlatSegmentation*>(object);
184 if (slatSegmentation)
186 return new AliMpSlatPainter(slatSegmentation->Slat());
192 //_______________________________________________________________________
193 void AliMpVPainter::AddPainter(AliMpVPainter *painter)
195 /// Add a painter to the list of painters (private)
197 fTrashList->Add(painter);
201 //_______________________________________________________________________
202 AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
204 /// Draw the object \n
205 /// Return the AliMpVPainter object created for the drawing
207 AliMpVPainter *painter=CreatePainter(object);
210 painter->Draw(option);
216 //_______________________________________________________________________
217 void AliMpVPainter::InitGraphContext()
219 /// Set the pad and real area of the graphic context to
220 /// the one stored in this painter
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);
232 //_______________________________________________________________________
233 void AliMpVPainter::PaintWholeBox(Bool_t fill)
235 /// Paint the box around the total pad area given in this painter
236 /// fill it or bnot following the parameter value
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();
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);
252 //_______________________________________________________________________
253 TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
255 /// Transform a real position into its equivalent position in a canvas
257 AliMpGraphContext *gr = AliMpGraphContext::Instance();
259 gr->SetPadPosition(fPadPosition);
260 gr->SetPadDimensions(fPadDimensions);
261 gr->SetRealPosition(GetPosition());
262 gr->SetRealDimensions(GetDimensions());
265 TVector2 ans = gr->RealToPad(realPos);