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