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