]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorPainter.cxx
In assignment operator: added check for assignment to self
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPainter.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: AliMpSectorPainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
18
19 //-----------------------------------------------------------------------------
20 // Class AliMpSectorPainter
21 // ------------------------
22 // Class for drawing a sector into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
25 //-----------------------------------------------------------------------------
26   
27 #include "AliMpSectorPainter.h"
28 #include "AliMpGraphContext.h"
29 #include "AliMpSector.h"
30 #include "AliMpZone.h"
31 #include "AliMpSubZone.h"
32 #include "AliMpRow.h"
33 #include "AliMpVRowSegment.h"
34
35 #include <TVirtualX.h>
36 #include <TPad.h>
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpSectorPainter)
40 /// \endcond
41
42 //_______________________________________________________________________
43 AliMpSectorPainter::AliMpSectorPainter()
44   :AliMpVPainter(),
45    fSector(0)
46 {
47   /// Default constructor
48 }
49 //_______________________________________________________________________
50 AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector)
51   :AliMpVPainter(),
52    fSector(sector)
53 {
54   /// Standard constructor 
55
56 }
57
58 //_______________________________________________________________________
59 AliMpSectorPainter::~AliMpSectorPainter()
60 {
61   /// Destructor
62 }
63
64 //_______________________________________________________________________
65 void AliMpSectorPainter::DumpObject()
66 {
67 /// Draw the owned object
68
69   fSector->Dump();
70 }
71
72 //_______________________________________________________________________
73 TVector2 AliMpSectorPainter::GetPosition() const
74 {
75 /// Get the owned object's position
76
77   if (fSector->GetNofRows()<1) return TVector2(0.,0.);
78   AliMpRow* row = fSector->GetRow(0);
79
80   // bl = bottom left position;
81   TVector2 bl = row->Position()-row->Dimensions();
82   // ur = upper right position
83   TVector2 ur = row->Position()+row->Dimensions();;
84
85   for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
86     row = fSector->GetRow(irow);
87     // update the bottom-left corner
88     if (bl.X()>row->Position().X()-row->Dimensions().X())
89       bl.Set(row->Position().X()-row->Position().X(),bl.Y());
90     if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
91       bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
92     // update the upper-right corner
93     if (ur.X()<row->Position().X()+row->Dimensions().X())
94       ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
95     if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
96       ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
97   }
98   return (ur+bl)/2.;
99 }
100
101 //_______________________________________________________________________
102 TVector2 AliMpSectorPainter::GetDimensions() const
103 {
104 /// Get the owned object's dimensions
105
106   if (fSector->GetNofRows()<1) return TVector2(0.,0.);
107   AliMpRow* row = fSector->GetRow(0);
108
109
110   // bl = bottom left position
111   TVector2 bl = row->Position()-row->Dimensions();
112   // ur = upper right position
113   TVector2 ur = row->Position()+row->Dimensions();
114
115   for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
116     row = fSector->GetRow(irow);
117     // update the bottom-left corner
118     if (bl.X()>row->Position().X()-row->Dimensions().X())
119       bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y());
120     if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
121       bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
122     // update the upper-right corner
123     if (ur.X()<row->Position().X()+row->Dimensions().X())
124       ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
125     if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
126       ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
127   }
128   return (ur-bl)/2.;
129
130 }
131 //_______________________________________________________________________
132 void AliMpSectorPainter::Draw(Option_t *option)
133 {
134 /// Draw the sector on the current pad
135 /// The first letter of \a option is treated as follows:
136 /// - case "Z" : each zones are drawn separately
137 /// - case "R" : each rows are drawn separately
138 /// - case ""  : the whole sector is drawn at once
139 /// in both cases, the rest of the option is passed
140 /// as argument to the Draw function of respectively
141 /// zone or row objects.
142
143   AliMpGraphContext *gr = AliMpGraphContext::Instance();
144   if (!fSector) return;
145   gr->Push();
146   InitGraphContext();
147
148   switch (option[0]){
149   case 'Z':
150     {
151       for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
152         AliMpZone *zone = fSector->GetZone(iZone);
153         gr->Push();
154
155         Double_t blx=  9999,  bly=  9999;
156         Double_t urx= -9999,  ury= -9999;
157         
158         for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
159           AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
160           for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
161             AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
162             
163             TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
164             TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
165             
166             if (bl.X()<blx) blx=bl.X();
167             if (bl.Y()<bly) bly=bl.Y();
168             if (ur.X()>urx) urx=ur.X();
169             if (ur.Y()>ury) ury=ur.Y();
170           }
171         }
172         TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
173         TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
174
175         gr->SetPadPosForReal(position,dimensions);
176         gr->SetColor(iZone+3);
177         DrawObject(zone,option+1);
178
179         gr->Pop();
180       }
181     }
182     break;
183   case 'R':
184     {
185       for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
186         AliMpRow *row = fSector->GetRow(iRow);
187         gr->Push();
188         gr->SetPadPosForReal(row->Position(),row->Dimensions());
189         DrawObject(row,option+1);
190         gr->Pop();
191       }
192     }
193     break;
194   default: AppendPad(option);
195   }
196   gr->Pop();
197 }
198
199 //_______________________________________________________________________
200 void AliMpSectorPainter::Paint(Option_t* /*option*/)
201 {
202 /// Paint the object
203
204   AliMpGraphContext *gr = AliMpGraphContext::Instance();
205   if (!fSector) return;
206   if (fSector->GetNofRows()<1) return;
207   Int_t col=gVirtualX->GetFillColor();
208   gr->Push();
209   InitGraphContext();
210   gPad->Range(0.,0.,1.,1.);
211
212
213   Double_t lx1=0.;
214   Double_t lx2=0.;
215   Int_t iRow;
216   for (iRow=0;iRow<fSector->GetNofRows();++iRow){
217     AliMpRow *row = fSector->GetRow(iRow);
218     TVector2 pos,dim;
219     gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
220     gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
221                    pos.X()+dim.X(),pos.Y()+dim.Y());
222     gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
223                    pos.X()-dim.X(),pos.Y()+dim.Y());
224     gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
225                    pos.X()+dim.X(),pos.Y()+dim.Y());
226           
227     if (iRow>0){
228       gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
229       gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
230     }
231     lx1=pos.X()-dim.X();
232     lx2=pos.X()+dim.X();
233   }
234
235   // now we draw the lower and upper horizontal lines
236
237   AliMpRow *row = fSector->GetRow(0);
238   TVector2 pos,dim;
239   gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
240   gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
241                  pos.X()+dim.X(),pos.Y()-dim.Y());
242   
243   row = fSector->GetRow(fSector->GetNofRows()-1);
244   gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
245   gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
246                  pos.X()+dim.X(),pos.Y()+dim.Y());
247
248   gr->Pop();
249   gVirtualX->SetFillColor(col);
250 }
251