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