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