6 // Class for drawing objects into canvas
8 // Authors: David Guez, IPN Orsay
12 #include "AliMpVPainter.h"
13 #include "AliMpGraphContext.h"
14 #include "AliMpSector.h"
16 #include "AliMpZone.h"
17 #include "AliMpSubZone.h"
18 #include "AliMpVRowSegment.h"
19 #include "AliMpMotifPosition.h"
20 #include "AliMpSectorPainter.h"
21 #include "AliMpRowPainter.h"
22 #include "AliMpZonePainter.h"
23 #include "AliMpSubZonePainter.h"
24 #include "AliMpRowSegmentPainter.h"
25 #include "AliMpMotifPainter.h"
27 ClassImp(AliMpVPainter)
29 //_______________________________________________________________________
30 AliMpVPainter::AliMpVPainter()
34 // Default constructor
35 AliMpGraphContext *gr = AliMpGraphContext::Instance();
36 fPadPosition = gr->GetPadPosition();
37 fPadDimensions = gr->GetPadDimensions();
38 fColor=gr->GetColor();
39 fTrashList = new TList;
42 //_______________________________________________________________________
43 AliMpVPainter::~AliMpVPainter()
52 //_______________________________________________________________________
53 Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim)
55 // does the point <point> inside the area (pos,dim)
56 return ( (TMath::Abs(point.X()-pos.X())<dim.X() ) && (TMath::Abs(point.Y()-pos.Y())<dim.Y() ) );
59 //_______________________________________________________________________
60 Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y)
62 // dist to the center if (x,y) is inside the box defined by (fPadPosition,fPadDimensions)
64 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
65 if ( IsInside(point,fPadPosition,fPadDimensions))
66 return (Int_t)(point-fPadPosition).Mod();
71 //_______________________________________________________________________
72 void AliMpVPainter::DumpObject() const
74 // Dump the painted object
77 //_______________________________________________________________________
78 TObject* AliMpVPainter::Clone(const char* newname) const
80 // create a clone of this object
81 AliMpVPainter *newobj = (AliMpVPainter *)TObject::Clone(newname);
82 if (!newobj) return 0;
83 AliMpGraphContext *gr = AliMpGraphContext::Instance();
84 newobj->fPadPosition = gr->GetPadPosition();
85 newobj->fPadDimensions = gr->GetPadDimensions();
89 //_______________________________________________________________________
90 TObject* AliMpVPainter::DrawClone(Option_t* option) const
92 TVirtualPad *pad = gROOT->GetSelectedPad();
93 TVirtualPad *padsav = gPad;
95 TObject *newobj = Clone();
97 if (!newobj) return 0;
100 newobj->Draw(option);
101 if (padsav) padsav->cd();
105 //_______________________________________________________________________
106 AliMpVPainter *AliMpVPainter::CreatePainter(TObject *object)
108 // create a new painter, which correspond to the
110 AliMpVPainter *painter=0;
111 if (object->InheritsFrom(AliMpSector::Class()))
112 painter = new AliMpSectorPainter((AliMpSector *)object);
113 else if (object->InheritsFrom(AliMpZone::Class()))
114 painter = new AliMpZonePainter((AliMpZone *)object);
115 else if (object->InheritsFrom(AliMpSubZone::Class()))
116 painter = new AliMpSubZonePainter((AliMpSubZone *)object);
117 else if (object->InheritsFrom(AliMpRow::Class()))
118 painter = new AliMpRowPainter((AliMpRow *)object);
119 else if (object->InheritsFrom(AliMpVRowSegment::Class()))
120 painter = new AliMpRowSegmentPainter((AliMpVRowSegment *)object);
121 else if (object->InheritsFrom(AliMpMotifPosition::Class()))
122 painter = new AliMpMotifPainter((AliMpMotifPosition *)object);
127 //_______________________________________________________________________
128 void AliMpVPainter::AddPainter(AliMpVPainter *painter)
130 // add a painter to the list of painters (private)
131 fTrashList->Add(painter);
135 //_______________________________________________________________________
136 AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
139 // return the AliMpVPainter object created for the drawing
140 AliMpVPainter *painter=CreatePainter(object);
143 painter->Draw(option);
149 //_______________________________________________________________________
150 void AliMpVPainter::InitGraphContext()
152 // Set the pad and real area of the graphic context to
153 // the one stored in this painter
155 AliMpGraphContext *gr = AliMpGraphContext::Instance();
156 gr->SetPadPosition(fPadPosition);
157 gr->SetPadDimensions(fPadDimensions);
158 gr->SetRealPosition(GetPosition());
159 gr->SetRealDimensions(GetDimensions());
160 gVirtualX->SetFillColor(fColor);
161 gVirtualX->SetTextColor(1);
162 gVirtualX->SetLineColor(1);
165 //_______________________________________________________________________
166 void AliMpVPainter::PaintWholeBox(Bool_t fill)
168 // Paint the box around the total pad area given in this painter
169 // fill it or bnot following the parameter value
171 Double_t x1,y1,x2,y2;
172 x1 = fPadPosition.X()-fPadDimensions.X();
173 y1 = fPadPosition.Y()-fPadDimensions.Y();
174 x2 = fPadPosition.X()+fPadDimensions.X();
175 y2 = fPadPosition.Y()+fPadDimensions.Y();
177 Style_t sty = gVirtualX->GetFillStyle();
178 gVirtualX->SetFillStyle(fill?1:0);
179 gPad->PaintBox(x1,y1,x2,y2);
180 gVirtualX->SetFillStyle(0);
181 gPad->PaintBox(x1,y1,x2,y2);
182 gVirtualX->SetFillStyle(sty);
185 //_______________________________________________________________________
186 TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
188 // transform a real position into its equivalent position in a canvas
190 AliMpGraphContext *gr = AliMpGraphContext::Instance();
192 gr->SetPadPosition(fPadPosition);
193 gr->SetPadDimensions(fPadDimensions);
194 gr->SetRealPosition(GetPosition());
195 gr->SetRealDimensions(GetDimensions());
198 TVector2 ans = gr->RealToPad(realPos);