]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpVPainter.cxx
Code for MUON Station1 (I.Hrivnacova)
[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 //
8 // Authors: David Guez, IPN Orsay
9   
10 #include <TROOT.h>
11
12 #include "AliMpVPainter.h"
13 #include "AliMpGraphContext.h"
14 #include "AliMpSector.h"
15 #include "AliMpRow.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"
26
27 ClassImp(AliMpVPainter)
28
29 //_______________________________________________________________________
30 AliMpVPainter::AliMpVPainter()
31   : TObject(),
32     fColor(2)
33 {
34   // Default constructor
35   AliMpGraphContext *gr = AliMpGraphContext::Instance();
36   fPadPosition  =  gr->GetPadPosition();
37   fPadDimensions =  gr->GetPadDimensions();
38   fColor=gr->GetColor();
39   fTrashList = new TList;
40 }
41
42 //_______________________________________________________________________
43 AliMpVPainter::~AliMpVPainter()
44 {
45   // Default destructor
46   if (fTrashList){
47     fTrashList->Delete();
48     delete fTrashList;
49   }
50 }
51
52 //_______________________________________________________________________
53 Bool_t AliMpVPainter::IsInside(const TVector2 &point,const TVector2& pos,const TVector2& dim)
54 {
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() ) );
57 }
58
59 //_______________________________________________________________________
60 Int_t AliMpVPainter::DistancetoPrimitive(Int_t x, Int_t y)
61 {
62   // dist to the center if (x,y) is inside the box defined by (fPadPosition,fPadDimensions)
63   // 9999 otherwise
64    TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
65    if ( IsInside(point,fPadPosition,fPadDimensions))
66      return (Int_t)(point-fPadPosition).Mod();
67    else
68      return 9999;
69 }
70
71 //_______________________________________________________________________
72 void AliMpVPainter::DumpObject() const
73 {
74   // Dump the painted object
75 }
76
77 //_______________________________________________________________________
78 TObject* AliMpVPainter::Clone(const char* newname) const
79 {
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();
86   return newobj;
87 }
88
89 //_______________________________________________________________________
90 TObject* AliMpVPainter::DrawClone(Option_t* option) const
91 {
92   TVirtualPad *pad = gROOT->GetSelectedPad();
93   TVirtualPad *padsav = gPad;
94
95   TObject *newobj = Clone();
96
97   if (!newobj) return 0;
98
99   if (pad) pad->cd();
100   newobj->Draw(option);
101   if (padsav) padsav->cd();
102   return newobj;
103 }
104
105 //_______________________________________________________________________
106 AliMpVPainter *AliMpVPainter::CreatePainter(TObject *object)
107 {
108   // create a new painter, which correspond to the
109   // class of object
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);
123
124   return painter;
125 }
126
127 //_______________________________________________________________________
128 void AliMpVPainter::AddPainter(AliMpVPainter *painter)
129 {
130   // add a painter to the list of painters (private)
131   fTrashList->Add(painter);
132 }
133
134
135 //_______________________________________________________________________
136 AliMpVPainter *AliMpVPainter::DrawObject(TObject *object,Option_t *option)
137 {
138   // Draw the object
139   // return the AliMpVPainter object created for the drawing
140   AliMpVPainter *painter=CreatePainter(object);
141
142   if (painter){
143     painter->Draw(option);
144     AddPainter(painter);
145   }
146   return painter;
147 }
148
149 //_______________________________________________________________________
150 void AliMpVPainter::InitGraphContext()
151 {
152   // Set the pad and real area of the graphic context to
153   // the one stored in this painter
154
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);
163 }
164
165 //_______________________________________________________________________
166 void AliMpVPainter::PaintWholeBox(Bool_t fill)
167 {
168   // Paint the box around the total pad area given in this painter
169   // fill it or bnot following the parameter value
170
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();
176
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);
183 }
184
185 //_______________________________________________________________________
186 TVector2 AliMpVPainter::RealToPad(const TVector2& realPos)
187 {
188 // transform a real position into its equivalent position in a canvas
189
190   AliMpGraphContext *gr = AliMpGraphContext::Instance();
191   gr->Push();
192   gr->SetPadPosition(fPadPosition);
193   gr->SetPadDimensions(fPadDimensions);
194   gr->SetRealPosition(GetPosition());
195   gr->SetRealDimensions(GetDimensions());
196
197
198   TVector2 ans = gr->RealToPad(realPos);
199   gr->Pop();
200   return ans;
201 }