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