]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpVPainter.cxx
Coding conventions corrections only
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVPainter.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: graphics
3//
4// Class AliMpVPainter
5// --------------
6// Class for drawing objects into canvas
7//
8// Authors: David Guez, IPN Orsay
9
10#include <TROOT.h>
2998a151 11#include <TList.h>
12#include <TVirtualX.h>
13#include <TPad.h>
5f91c9e8 14
15#include "AliMpVPainter.h"
16#include "AliMpGraphContext.h"
17#include "AliMpSector.h"
18#include "AliMpRow.h"
19#include "AliMpZone.h"
20#include "AliMpSubZone.h"
21#include "AliMpVRowSegment.h"
22#include "AliMpMotifPosition.h"
23#include "AliMpSectorPainter.h"
24#include "AliMpRowPainter.h"
25#include "AliMpZonePainter.h"
26#include "AliMpSubZonePainter.h"
27#include "AliMpRowSegmentPainter.h"
28#include "AliMpMotifPainter.h"
29
30ClassImp(AliMpVPainter)
31
32//_______________________________________________________________________
33AliMpVPainter::AliMpVPainter()
34 : TObject(),
35 fColor(2)
36{
37 // Default constructor
38 AliMpGraphContext *gr = AliMpGraphContext::Instance();
39 fPadPosition = gr->GetPadPosition();
40 fPadDimensions = gr->GetPadDimensions();
41 fColor=gr->GetColor();
42 fTrashList = new TList;
43}
44
45//_______________________________________________________________________
46AliMpVPainter::~AliMpVPainter()
47{
48 // Default destructor
49 if (fTrashList){
50 fTrashList->Delete();
51 delete fTrashList;
52 }
53}
54
55//_______________________________________________________________________
56Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim)
57{
58 // does the point <point> inside the area (pos,dim)
59 return ( (TMath::Abs(point.X()-pos.X())<dim.X() ) && (TMath::Abs(point.Y()-pos.Y())<dim.Y() ) );
60}
61
62//_______________________________________________________________________
63Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y)
64{
65 // dist to the center if (x,y) is inside the box defined by (fPadPosition,fPadDimensions)
66 // 9999 otherwise
67 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
68 if ( IsInside(point,fPadPosition,fPadDimensions))
69 return (Int_t)(point-fPadPosition).Mod();
70 else
71 return 9999;
72}
73
74//_______________________________________________________________________
75void AliMpVPainter::DumpObject() const
76{
77 // Dump the painted object
78}
79
80//_______________________________________________________________________
81TObject* AliMpVPainter::Clone(const char* newname) const
82{
83 // create a clone of this object
84 AliMpVPainter *newobj = (AliMpVPainter *)TObject::Clone(newname);
85 if (!newobj) return 0;
86 AliMpGraphContext *gr = AliMpGraphContext::Instance();
87 newobj->fPadPosition = gr->GetPadPosition();
88 newobj->fPadDimensions = gr->GetPadDimensions();
89 return newobj;
90}
91
92//_______________________________________________________________________
93TObject* AliMpVPainter::DrawClone(Option_t* option) const
94{
95 TVirtualPad *pad = gROOT->GetSelectedPad();
96 TVirtualPad *padsav = gPad;
97
98 TObject *newobj = Clone();
99
100 if (!newobj) return 0;
101
102 if (pad) pad->cd();
103 newobj->Draw(option);
104 if (padsav) padsav->cd();
105 return newobj;
106}
107
108//_______________________________________________________________________
109AliMpVPainter *AliMpVPainter::CreatePainter(TObject *object)
110{
111 // create a new painter, which correspond to the
112 // class of object
113 AliMpVPainter *painter=0;
114 if (object->InheritsFrom(AliMpSector::Class()))
115 painter = new AliMpSectorPainter((AliMpSector *)object);
116 else if (object->InheritsFrom(AliMpZone::Class()))
117 painter = new AliMpZonePainter((AliMpZone *)object);
118 else if (object->InheritsFrom(AliMpSubZone::Class()))
119 painter = new AliMpSubZonePainter((AliMpSubZone *)object);
120 else if (object->InheritsFrom(AliMpRow::Class()))
121 painter = new AliMpRowPainter((AliMpRow *)object);
122 else if (object->InheritsFrom(AliMpVRowSegment::Class()))
123 painter = new AliMpRowSegmentPainter((AliMpVRowSegment *)object);
124 else if (object->InheritsFrom(AliMpMotifPosition::Class()))
125 painter = new AliMpMotifPainter((AliMpMotifPosition *)object);
126
127 return painter;
128}
129
130//_______________________________________________________________________
131void AliMpVPainter::AddPainter(AliMpVPainter *painter)
132{
133 // add a painter to the list of painters (private)
134 fTrashList->Add(painter);
135}
136
137
138//_______________________________________________________________________
139AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
140{
141 // Draw the object
142 // return the AliMpVPainter object created for the drawing
143 AliMpVPainter *painter=CreatePainter(object);
144
145 if (painter){
146 painter->Draw(option);
147 AddPainter(painter);
148 }
149 return painter;
150}
151
152//_______________________________________________________________________
153void AliMpVPainter::InitGraphContext()
154{
155 // Set the pad and real area of the graphic context to
156 // the one stored in this painter
157
158 AliMpGraphContext *gr = AliMpGraphContext::Instance();
159 gr->SetPadPosition(fPadPosition);
160 gr->SetPadDimensions(fPadDimensions);
161 gr->SetRealPosition(GetPosition());
162 gr->SetRealDimensions(GetDimensions());
163 gVirtualX->SetFillColor(fColor);
164 gVirtualX->SetTextColor(1);
165 gVirtualX->SetLineColor(1);
166}
167
168//_______________________________________________________________________
169void AliMpVPainter::PaintWholeBox(Bool_t fill)
170{
171 // Paint the box around the total pad area given in this painter
172 // fill it or bnot following the parameter value
173
174 Double_t x1,y1,x2,y2;
175 x1 = fPadPosition.X()-fPadDimensions.X();
176 y1 = fPadPosition.Y()-fPadDimensions.Y();
177 x2 = fPadPosition.X()+fPadDimensions.X();
178 y2 = fPadPosition.Y()+fPadDimensions.Y();
179
180 Style_t sty = gVirtualX->GetFillStyle();
181 gVirtualX->SetFillStyle(fill?1:0);
182 gPad->PaintBox(x1,y1,x2,y2);
183 gVirtualX->SetFillStyle(0);
184 gPad->PaintBox(x1,y1,x2,y2);
185 gVirtualX->SetFillStyle(sty);
186}
187
188//_______________________________________________________________________
189TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
190{
191// transform a real position into its equivalent position in a canvas
192
193 AliMpGraphContext *gr = AliMpGraphContext::Instance();
194 gr->Push();
195 gr->SetPadPosition(fPadPosition);
196 gr->SetPadDimensions(fPadDimensions);
197 gr->SetRealPosition(GetPosition());
198 gr->SetRealDimensions(GetDimensions());
199
200
201 TVector2 ans = gr->RealToPad(realPos);
202 gr->Pop();
203 return ans;
204}