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.8 2005/08/26 15:43:36 ivana Exp $
20 // Class AliMpVPainter
22 // Class for drawing objects into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
28 #include <TVirtualX.h>
32 #include "AliMpVPainter.h"
33 #include "AliMpGraphContext.h"
34 #include "AliMpSector.h"
36 #include "AliMpZone.h"
37 #include "AliMpSubZone.h"
38 #include "AliMpVRowSegment.h"
39 #include "AliMpMotifPosition.h"
40 #include "AliMpSectorPainter.h"
41 #include "AliMpRowPainter.h"
42 #include "AliMpZonePainter.h"
43 #include "AliMpSubZonePainter.h"
44 #include "AliMpRowSegmentPainter.h"
45 #include "AliMpMotifPainter.h"
47 #include "AliMpPCBPainter.h"
48 #include "AliMpSlat.h"
49 #include "AliMpSlatPainter.h"
51 ClassImp(AliMpVPainter)
53 //_______________________________________________________________________
54 AliMpVPainter::AliMpVPainter()
58 /// Default constructor
60 AliMpGraphContext *gr = AliMpGraphContext::Instance();
61 fPadPosition = gr->GetPadPosition();
62 fPadDimensions = gr->GetPadDimensions();
63 fColor=gr->GetColor();
64 fTrashList = new TList;
67 //_____________________________________________________________________________
68 AliMpVPainter::AliMpVPainter(const AliMpVPainter& right)
71 /// Protected copy constructor (not provided)
73 Fatal("AliMpVPainter", "Copy constructor not provided.");
76 //_______________________________________________________________________
77 AliMpVPainter::~AliMpVPainter()
87 //_____________________________________________________________________________
88 AliMpVPainter& AliMpVPainter::operator=(const AliMpVPainter& right)
90 /// Assignment operator (not provided)
92 // check assignment to self
93 if (this == &right) return *this;
95 Fatal("operator =", "Assignment operator not provided.");
100 //_______________________________________________________________________
101 Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim)
103 /// Is the point <point> inside the area (pos,dim)?
105 return ( (TMath::Abs(point.X()-pos.X())<dim.X() ) && (TMath::Abs(point.Y()-pos.Y())<dim.Y() ) );
108 //_______________________________________________________________________
109 Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y)
111 /// Distance to the center if (x,y) is inside the box defined by (fPadPosition,fPadDimensions)
114 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
115 if ( IsInside(point,fPadPosition,fPadDimensions) )
117 return (Int_t)(point-fPadPosition).Mod();
122 //_______________________________________________________________________
123 void AliMpVPainter::DumpObject() const
125 /// Dump the painted object
128 //_______________________________________________________________________
129 TObject* AliMpVPainter::Clone(const char* newname) const
131 /// Create a clone of this object
133 AliMpVPainter *newobj = (AliMpVPainter *)TObject::Clone(newname);
134 if (!newobj) return 0;
135 AliMpGraphContext *gr = AliMpGraphContext::Instance();
136 newobj->fPadPosition = gr->GetPadPosition();
137 newobj->fPadDimensions = gr->GetPadDimensions();
141 //_______________________________________________________________________
142 TObject* AliMpVPainter::DrawClone(Option_t* option) const
144 /// Draw the clone object
146 TVirtualPad *pad = gROOT->GetSelectedPad();
147 TVirtualPad *padsav = gPad;
149 TObject *newobj = Clone();
151 if (!newobj) return 0;
154 newobj->Draw(option);
155 if (padsav) padsav->cd();
159 //_______________________________________________________________________
160 AliMpVPainter *AliMpVPainter::CreatePainter(TObject *object)
162 /// Create a new painter, which correspond to the
165 AliMpVPainter *painter=0;
166 if (object->InheritsFrom(AliMpSector::Class()))
167 painter = new AliMpSectorPainter((AliMpSector *)object);
168 else if (object->InheritsFrom(AliMpZone::Class()))
169 painter = new AliMpZonePainter((AliMpZone *)object);
170 else if (object->InheritsFrom(AliMpSubZone::Class()))
171 painter = new AliMpSubZonePainter((AliMpSubZone *)object);
172 else if (object->InheritsFrom(AliMpRow::Class()))
173 painter = new AliMpRowPainter((AliMpRow *)object);
174 else if (object->InheritsFrom(AliMpVRowSegment::Class()))
175 painter = new AliMpRowSegmentPainter((AliMpVRowSegment *)object);
176 else if (object->InheritsFrom(AliMpMotifPosition::Class()))
177 painter = new AliMpMotifPainter((AliMpMotifPosition *)object);
178 else if (object->InheritsFrom(AliMpPCB::Class()))
179 painter = new AliMpPCBPainter((AliMpPCB *)object);
180 else if (object->InheritsFrom(AliMpSlat::Class()))
181 painter = new AliMpSlatPainter((AliMpSlat*)object);
185 //_______________________________________________________________________
186 void AliMpVPainter::AddPainter(AliMpVPainter *painter)
188 /// Add a painter to the list of painters (private)
190 fTrashList->Add(painter);
194 //_______________________________________________________________________
195 AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
197 /// Draw the object \n
198 /// Return the AliMpVPainter object created for the drawing
200 AliMpVPainter *painter=CreatePainter(object);
203 painter->Draw(option);
209 //_______________________________________________________________________
210 void AliMpVPainter::InitGraphContext()
212 /// Set the pad and real area of the graphic context to
213 /// the one stored in this painter
215 AliMpGraphContext *gr = AliMpGraphContext::Instance();
216 gr->SetPadPosition(fPadPosition);
217 gr->SetPadDimensions(fPadDimensions);
218 gr->SetRealPosition(GetPosition());
219 gr->SetRealDimensions(GetDimensions());
220 gVirtualX->SetFillColor(fColor);
221 gVirtualX->SetTextColor(1);
222 gVirtualX->SetLineColor(1);
225 //_______________________________________________________________________
226 void AliMpVPainter::PaintWholeBox(Bool_t fill)
228 /// Paint the box around the total pad area given in this painter
229 /// fill it or bnot following the parameter value
231 Double_t x1,y1,x2,y2;
232 x1 = fPadPosition.X()-fPadDimensions.X();
233 y1 = fPadPosition.Y()-fPadDimensions.Y();
234 x2 = fPadPosition.X()+fPadDimensions.X();
235 y2 = fPadPosition.Y()+fPadDimensions.Y();
237 Style_t sty = gVirtualX->GetFillStyle();
238 gVirtualX->SetFillStyle(fill?1:0);
239 gPad->PaintBox(x1,y1,x2,y2);
240 gVirtualX->SetFillStyle(0);
241 gPad->PaintBox(x1,y1,x2,y2);
242 gVirtualX->SetFillStyle(sty);
245 //_______________________________________________________________________
246 TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
248 /// Transform a real position into its equivalent position in a canvas
250 AliMpGraphContext *gr = AliMpGraphContext::Instance();
252 gr->SetPadPosition(fPadPosition);
253 gr->SetPadDimensions(fPadDimensions);
254 gr->SetRealPosition(GetPosition());
255 gr->SetRealDimensions(GetDimensions());
258 TVector2 ans = gr->RealToPad(realPos);