AliRoot Core  edcc906 (edcc906)
AliMpVPainter.cxx
Go to the documentation of this file.
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 
16 // $Id$
17 // $MpId: AliMpVPainter.cxx,v 1.10 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpVPainter
22 // --------------
23 // Class for drawing objects into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
27 
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"
42 #include "AliMpMotifType.h"
43 #include "AliMpPCB.h"
44 #include "AliMpPCBPainter.h"
45 #include "AliMpSlat.h"
46 #include "AliMpSlatPainter.h"
47 #include "AliMpIteratorPainter.h"
48 #include "AliMpVPadIterator.h"
49 #include "AliMpSegmentation.h"
50 //#include "AliMpSectorSegmentation.h"
51 
52 #include <TList.h>
53 #include <TVirtualX.h>
54 #include <TPad.h>
55 #include <TROOT.h>
56 
57 #include "AliLog.h"
59 ClassImp(AliMpVPainter)
61 
62 //_______________________________________________________________________
64  : TObject(),
65  fColor(2),
66  fPadPosition(),
67  fPadDimensions(),
68  fTrashList(0)
69 {
71 
73  fPadPosition = gr->GetPadPosition();
74  fPadDimensions = gr->GetPadDimensions();
75  fColor=gr->GetColor();
76  fTrashList = new TList;
77 }
78 
79 //_______________________________________________________________________
81 {
83 
84  if (fTrashList){
85  fTrashList->Delete();
86  delete fTrashList;
87  }
88 }
89 
90 //_______________________________________________________________________
91 Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim)
92 {
94 
95  return ( (TMath::Abs(point.X()-pos.X())<dim.X() ) && (TMath::Abs(point.Y()-pos.Y())<dim.Y() ) );
96 }
97 
98 //_______________________________________________________________________
99 Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y)
100 {
103 
104  TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
105  if ( IsInside(point,fPadPosition,fPadDimensions) )
106  {
107  return (Int_t)(point-fPadPosition).Mod();
108  }
109  return 9999;
110 }
111 
112 //_______________________________________________________________________
114 {
116 }
117 
118 //_______________________________________________________________________
119 TObject* AliMpVPainter::Clone(const char* newname) const
120 {
122 
123  AliMpVPainter *newobj = (AliMpVPainter *)TObject::Clone(newname);
124  if (!newobj) return 0;
126  newobj->fPadPosition = gr->GetPadPosition();
127  newobj->fPadDimensions = gr->GetPadDimensions();
128  return newobj;
129 }
130 
131 //_______________________________________________________________________
132 TObject* AliMpVPainter::DrawClone(Option_t* option) const
133 {
135 
136  TVirtualPad *pad = gROOT->GetSelectedPad();
137  TVirtualPad *padsav = gPad;
138 
139  TObject *newobj = Clone();
140 
141  if (!newobj) return 0;
142 
143  if (pad) pad->cd();
144  newobj->Draw(option);
145  if (padsav) padsav->cd();
146  return newobj;
147 }
148 
149 //_______________________________________________________________________
151 {
154 
155  AliMpVPainter *painter=0;
156  if (object->InheritsFrom(AliMpSector::Class()))
157  painter = new AliMpSectorPainter((AliMpSector *)object);
158  else if (object->InheritsFrom(AliMpZone::Class()))
159  painter = new AliMpZonePainter((AliMpZone *)object);
160  else if (object->InheritsFrom(AliMpSubZone::Class()))
161  painter = new AliMpSubZonePainter((AliMpSubZone *)object);
162  else if (object->InheritsFrom(AliMpRow::Class()))
163  painter = new AliMpRowPainter((AliMpRow *)object);
164  else if (object->InheritsFrom(AliMpVRowSegment::Class()))
165  painter = new AliMpRowSegmentPainter((AliMpVRowSegment *)object);
166  else if (object->InheritsFrom(AliMpMotifPosition::Class()))
167  painter = new AliMpMotifPainter((AliMpMotifPosition *)object);
168  else if (object->InheritsFrom(AliMpMotifType::Class()))
169  painter = new AliMpMotifPainter((AliMpMotifType *)object);
170  else if (object->InheritsFrom(AliMpPCB::Class()))
171  painter = new AliMpPCBPainter((AliMpPCB *)object);
172  else if (object->InheritsFrom(AliMpSlat::Class()))
173  painter = new AliMpSlatPainter((AliMpSlat*)object);
174  else if (object->InheritsFrom(AliMpVPadIterator::Class()))
175  painter = new AliMpIteratorPainter((AliMpVPadIterator*)object);
176  else if (object->InheritsFrom(AliMpVSegmentation::Class()))
177  {
178  // const AliMpSectorSegmentation* sectorSegmentation = dynamic_cast<const AliMpSectorSegmentation*>(object);
179 // if (sectorSegmentation)
180 // {
181 // return new AliMpSectorPainter(sectorSegmentation->GetSector());
182 // }
183 
184  /*
185  const AliMpSlatSegmentation* slatSegmentation = dynamic_cast<const AliMpSlatSegmentation*>(object);
186  if (slatSegmentation)
187  {
188  return new AliMpSlatPainter(slatSegmentation->Slat());
189  }
190  */
191  const AliMpSlat* kSlat
193  if ( kSlat )
194  {
195  return new AliMpSlatPainter(kSlat);
196  }
197 
198  }
199  return painter;
200 }
201 
202 //_______________________________________________________________________
204 {
206 
207  fTrashList->Add(painter);
208 }
209 
210 
211 //_______________________________________________________________________
212 AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
213 {
216 
217  AliMpVPainter *painter=CreatePainter(object);
218 
219  if (painter){
220  painter->Draw(option);
221  AddPainter(painter);
222  }
223  return painter;
224 }
225 
226 //_______________________________________________________________________
228 {
231 
237  gVirtualX->SetFillColor(fColor);
238  gVirtualX->SetTextColor(1);
239  gVirtualX->SetLineColor(1);
240 
241 
242  AliDebug(1,Form("%s gpad pos %f %f gpad dim %f %f real pos %f %f real dim %f %f",
243  ClassName(),
244  fPadPosition.X(),fPadPosition.Y(),
246  GetPosition().X(),GetPosition().Y(),
247  GetDimensions().X(),GetDimensions().Y()));
248 }
249 
250 //_______________________________________________________________________
251 void AliMpVPainter::PaintWholeBox(Bool_t fill, Bool_t center)
252 {
255 
256  Double_t x1,y1,x2,y2;
257  x1 = fPadPosition.X()-fPadDimensions.X();
258  y1 = fPadPosition.Y()-fPadDimensions.Y();
259  x2 = fPadPosition.X()+fPadDimensions.X();
260  y2 = fPadPosition.Y()+fPadDimensions.Y();
261 
262  Style_t sty = gVirtualX->GetFillStyle();
263  gVirtualX->SetFillStyle(fill?1:0);
264  gPad->PaintBox(x1,y1,x2,y2);
265  gVirtualX->SetFillStyle(0);
266  gPad->PaintBox(x1,y1,x2,y2);
267 
268  if (center) {
269  gVirtualX->SetLineColor(2);
270  gPad->PaintLine(x1,y1,x2,y2);
271  gPad->PaintLine(x1,y2,x2,y1);
272  }
273  gVirtualX->SetFillStyle(sty);
274 }
275 
276 //_______________________________________________________________________
277 TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
278 {
280 
282  gr->Push();
287 
288 
289  TVector2 ans = gr->RealToPad(realPos);
290  gr->Pop();
291  return ans;
292 }
static AliMpVPainter * CreatePainter(TObject *object)
Painter for a group of pads defined by an iterator.
void SetRealPosition(const TVector2 &position)
Set position of the real area where to draw.
Class for drawing a PCB into canvas.
static AliMpSegmentation * Instance(Bool_t warn=true)
Class for drawing a row into canvas.
const AliMpSlat * GetSlat(const AliMpVSegmentation *kSegmentation, Bool_t warn=true) const
A PCB for station 3,4 or 5.
Definition: AliMpPCB.h:46
TROOT * gROOT
TVector2 GetPadDimensions() const
Return dimensions of the pad area where to draw.
Class for drawing a slat into canvas.
static AliMpGraphContext * Instance()
A slat (building block of stations 3, 4 and 5)
Definition: AliMpSlat.h:51
Int_t GetColor() const
Return color to use.
void SetPadPosition(const TVector2 &position)
Set position of the pad area where to draw.
A region of pads of the same dimensions composed of subzones.
Definition: AliMpZone.h:25
virtual TVector2 GetPosition() const =0
Return the owned object&#39;s position.
Bool_t IsInside(const TVector2 &point, const TVector2 &pos, const TVector2 &dim)
TVector2 fPadPosition
position inside the graphics pad
Definition: AliMpVPainter.h:81
An interface for a row segment.
Class for drawing a zone into canvas.
void SetRealDimensions(const TVector2 &dimensions)
Set dimensions of the real area where to draw.
Int_t fColor
color
Definition: AliMpVPainter.h:80
A placed motif.
virtual TVector2 GetDimensions() const =0
Return the owned object&#39;s dimensions.
TGraph * gr
Definition: CalibTime.C:25
An interface for an iterator over pads.
virtual ~AliMpVPainter()
void SetPadDimensions(const TVector2 &dimensions)
Set dimensions of the pad area where to draw.
Abstract base class for drawing objects into canvas.
Definition: AliMpVPainter.h:21
Class for drawing a motif into canvas.
virtual TObject * Clone(const char *newname="") const
TVector2 GetPadPosition() const
Return position of the pad area where to draw.
Class for drawing a sector into canvas.
A row composed of the row segments.
Definition: AliMpRow.h:26
Class for drawing a motif into canvas.
A sector (quadrant) of the MUON chamber of stations 1 and 2.
Definition: AliMpSector.h:34
TVector2 RealToPad(const TVector2 &realPos)
TVector2 fPadDimensions
dimensions inside the graphics pad
Definition: AliMpVPainter.h:82
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
The abstract base class for the segmentation.
AliMpVPainter * DrawObject(TObject *object, Option_t *option="")
Not implemented.
TVector2 RealToPad(const TVector2 &position) const
void PaintWholeBox(Bool_t fill=kTRUE, Bool_t center=kFALSE)
void AddPainter(AliMpVPainter *painter)
Not implemented.
Class describing the correspondance between a given area in pad, and a zone of real (cm) position...
virtual Int_t DistancetoPrimitive(Int_t x, Int_t y)
virtual TObject * DrawClone(Option_t *option) const
TList * fTrashList
list of painter object created
Definition: AliMpVPainter.h:83
Class for drawing a subzone into canvas.
void InitGraphContext()
Class that defines the motif properties.
A region in zone composed of the row segments with the same motif type.
Definition: AliMpSubZone.h:23
void DumpObject() const