]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONmpgraphics/AliMpSectorPainter.cxx
MUON + CheckCompiler
[u/mrichter/AliRoot.git] / MUON / MUONmpgraphics / 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 = TVector2(row->GetPositionX(), row->GetPositionY())-
82                 TVector2(row->GetDimensionX(), row->GetDimensionY());
83   // ur = upper right position
84   TVector2 ur = TVector2(row->GetPositionX(), row->GetPositionY())+
85                 TVector2(row->GetDimensionX(), row->GetDimensionY());;
86
87   for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
88     row = fSector->GetRow(irow);
89     // update the bottom-left corner
90     if (bl.X()>row->GetPositionX()-row->GetDimensionX())
91       bl.Set(row->GetPositionX()-row->GetPositionX(),bl.Y());
92     if (bl.Y()>row->GetPositionY()-row->GetDimensionY())
93       bl.Set(bl.X(),row->GetPositionY()-row->GetDimensionY());
94     // update the upper-right corner
95     if (ur.X()<row->GetPositionX()+row->GetDimensionX())
96       ur.Set(row->GetPositionX()+row->GetDimensionX(),ur.Y());
97     if (ur.Y()<row->GetPositionY()+row->GetDimensionY())
98       ur.Set(ur.X(),row->GetPositionY()+row->GetDimensionY());
99   }
100   return (ur+bl)/2.;
101 }
102
103 //_______________________________________________________________________
104 TVector2 AliMpSectorPainter::GetDimensions() const
105 {
106 /// Get the owned object's dimensions
107
108   if (fSector->GetNofRows()<1) return TVector2(0.,0.);
109   AliMpRow* row = fSector->GetRow(0);
110
111
112   // bl = bottom left position
113   TVector2 bl = TVector2(row->GetPositionX(), row->GetPositionY())-
114                 TVector2(row->GetDimensionX(), row->GetDimensionY());
115   // ur = upper right position
116   TVector2 ur = TVector2(row->GetPositionX(), row->GetPositionY())+
117                 TVector2(row->GetDimensionX(), row->GetDimensionY());
118
119   for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
120     row = fSector->GetRow(irow);
121     // update the bottom-left corner
122     if (bl.X()>row->GetPositionX()-row->GetDimensionX())
123       bl.Set(row->GetPositionX()-row->GetDimensionX(),bl.Y());
124     if (bl.Y()>row->GetPositionY()-row->GetDimensionY())
125       bl.Set(bl.X(),row->GetPositionY()-row->GetDimensionY());
126     // update the upper-right corner
127     if (ur.X()<row->GetPositionX()+row->GetDimensionX())
128       ur.Set(row->GetPositionX()+row->GetDimensionX(),ur.Y());
129     if (ur.Y()<row->GetPositionY()+row->GetDimensionY())
130       ur.Set(ur.X(),row->GetPositionY()+row->GetDimensionY());
131   }
132   return (ur-bl)/2.;
133
134 }
135 //_______________________________________________________________________
136 void AliMpSectorPainter::Draw(Option_t *option)
137 {
138 /// Draw the sector on the current pad
139 /// The first letter of \a option is treated as follows:
140 /// - case "Z" : each zones are drawn separately
141 /// - case "R" : each rows are drawn separately
142 /// - case ""  : the whole sector is drawn at once
143 /// in both cases, the rest of the option is passed
144 /// as argument to the Draw function of respectively
145 /// zone or row objects.
146
147   AliMpGraphContext *gr = AliMpGraphContext::Instance();
148   if (!fSector) return;
149   gr->Push();
150   InitGraphContext();
151
152   switch (option[0]){
153   case 'Z':
154     {
155       for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
156         AliMpZone *zone = fSector->GetZone(iZone);
157         gr->Push();
158
159         Double_t blx=  9999,  bly=  9999;
160         Double_t urx= -9999,  ury= -9999;
161         
162         for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
163           AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
164           for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
165             AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
166             
167             TVector2 bl = TVector2(rowSegment->GetPositionX(),
168                                    rowSegment->GetPositionY()) -
169                           TVector2(rowSegment->GetDimensionX(),
170                                    rowSegment->GetDimensionY());
171             TVector2 ur = TVector2(rowSegment->GetPositionX(),
172                                    rowSegment->GetPositionY())+
173                           TVector2(rowSegment->GetDimensionX(),
174                                    rowSegment->GetDimensionY());
175             
176             if (bl.X()<blx) blx=bl.X();
177             if (bl.Y()<bly) bly=bl.Y();
178             if (ur.X()>urx) urx=ur.X();
179             if (ur.Y()>ury) ury=ur.Y();
180           }
181         }
182         TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
183         TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
184
185         gr->SetPadPosForReal(position,dimensions);
186         gr->SetColor(iZone+3);
187         DrawObject(zone,option+1);
188
189         gr->Pop();
190       }
191     }
192     break;
193   case 'R':
194     {
195       for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
196         AliMpRow *row = fSector->GetRow(iRow);
197         gr->Push();
198         gr->SetPadPosForReal(TVector2(row->GetPositionX(), row->GetPositionY()),
199                              TVector2(row->GetDimensionX(), row->GetDimensionY()));
200         DrawObject(row,option+1);
201         gr->Pop();
202       }
203     }
204     break;
205   default: AppendPad(option);
206   }
207   gr->Pop();
208 }
209
210 //_______________________________________________________________________
211 void AliMpSectorPainter::Paint(Option_t* /*option*/)
212 {
213 /// Paint the object
214
215   AliMpGraphContext *gr = AliMpGraphContext::Instance();
216   if (!fSector) return;
217   if (fSector->GetNofRows()<1) return;
218   Int_t col=gVirtualX->GetFillColor();
219   gr->Push();
220   InitGraphContext();
221   gPad->Range(0.,0.,1.,1.);
222
223
224   Double_t lx1=0.;
225   Double_t lx2=0.;
226   Int_t iRow;
227   for (iRow=0;iRow<fSector->GetNofRows();++iRow){
228     AliMpRow *row = fSector->GetRow(iRow);
229     TVector2 pos,dim;
230     gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()),
231                   TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim);
232     gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
233                    pos.X()+dim.X(),pos.Y()+dim.Y());
234     gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
235                    pos.X()-dim.X(),pos.Y()+dim.Y());
236     gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
237                    pos.X()+dim.X(),pos.Y()+dim.Y());
238           
239     if (iRow>0){
240       gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
241       gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
242     }
243     lx1=pos.X()-dim.X();
244     lx2=pos.X()+dim.X();
245   }
246
247   // now we draw the lower and upper horizontal lines
248
249   AliMpRow *row = fSector->GetRow(0);
250   TVector2 pos,dim;
251   gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()),
252                 TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim);
253   gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
254                  pos.X()+dim.X(),pos.Y()-dim.Y());
255   
256   row = fSector->GetRow(fSector->GetNofRows()-1);
257   gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()),
258                 TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim);
259   gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
260                  pos.X()+dim.X(),pos.Y()+dim.Y());
261
262   gr->Pop();
263   gVirtualX->SetFillColor(col);
264 }
265