]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifPainter.cxx
New classes for shuttle (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifPainter.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: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 //
20 // Class AliMpMotifPainter
21 // -----------------------
22 // Class for drawing a motif into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
25
26 #include "AliMpMotifPainter.h"
27 #include "AliMpGraphContext.h"
28 #include "AliMpMotifPosition.h"
29 #include "AliMpMotifType.h"
30 #include "AliMpConnection.h"
31 #include "AliMpIntPair.h"
32
33 #include <TVirtualX.h>
34 #include <TPad.h>
35  
36 /// \cond CLASSIMP
37 ClassImp(AliMpMotifPainter)
38 /// \endcond
39
40 //_______________________________________________________________________
41 AliMpMotifPainter::AliMpMotifPainter()
42   : AliMpVPainter(),
43     fMotifPos(0)
44 {
45   /// Default constructor
46 }
47
48 //_______________________________________________________________________
49 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
50   : AliMpVPainter(),
51     fMotifPos(motifPos)
52 {
53   /// Standard constructor 
54
55 }
56
57 //_______________________________________________________________________
58 AliMpMotifPainter::~AliMpMotifPainter()
59 {
60   /// Default constructor
61 }
62
63 //_______________________________________________________________________
64 void AliMpMotifPainter::DumpObject()
65 {
66 /// Dump the owned object
67
68   fMotifPos->Dump();
69 }
70
71 //_______________________________________________________________________
72 TVector2 AliMpMotifPainter::GetPosition() const
73 {
74 /// Get the owned object's position
75
76   return fMotifPos->Position();
77 }
78
79 //_______________________________________________________________________
80 TVector2 AliMpMotifPainter::GetDimensions() const
81 {
82 /// Get the owned object's dimensions
83
84   return fMotifPos->Dimensions();
85 }
86
87 //_______________________________________________________________________
88 void AliMpMotifPainter::Paint(Option_t *option)
89 {
90 /// Paint the object
91
92   AliMpGraphContext *gr = AliMpGraphContext::Instance();
93   if (!fMotifPos) return;
94   Int_t col=gVirtualX->GetFillColor();
95   gr->Push();
96   gPad->Range(0.,0.,1.,1.);
97   InitGraphContext();
98
99   switch (option[0]){
100   case 'T':
101   case 'I':
102   case 'X':
103     {
104       PaintWholeBox();
105       Float_t textSize =   gVirtualX->GetTextSize();
106       gVirtualX->SetTextSize(10);
107       TString str;
108       switch (option[0]) {
109         case 'T' : 
110           str = Form("%d",fMotifPos->GetID());
111           break;
112         case 'I':{
113           switch (option[1]){
114             case '+' :
115             str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
116                                fMotifPos->GetHighIndicesLimit().GetSecond());
117             break;
118             default:
119             str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
120                                fMotifPos->GetLowIndicesLimit().GetSecond());
121           }
122         }
123         break;
124         case 'X' :
125           str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
126                                (GetPosition()-GetDimensions()).Y());
127           break;
128       }
129       gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
130       
131       gVirtualX->SetTextSize(textSize);
132     }
133     break;
134   case 'P':
135     {
136       //PaintWholeBox(kFALSE);
137       AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
138       for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
139            for (Int_t i=0;i<motifType->GetNofPadsX();i++){
140              AliMpIntPair indices = AliMpIntPair(i,j);
141                AliMpConnection* connect = 
142                  motifType->FindConnectionByLocalIndices(indices);
143              if (connect){
144                TVector2 realPadPos = 
145                 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
146                TVector2 padPadPos,padPadDim;
147                gr->RealToPad(realPadPos,
148                                fMotifPos->GetMotif()->GetPadDimensions(indices),
149                          padPadPos,padPadDim);
150                TVector2 bl = padPadPos - padPadDim;
151                TVector2 ur = padPadPos + padPadDim;
152
153
154                Style_t sty = gVirtualX->GetFillStyle();
155                gVirtualX->SetFillStyle(1);
156                gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
157                gVirtualX->SetFillStyle(0);
158                gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
159                gVirtualX->SetFillStyle(sty);
160                if (option[1]=='T'){
161                  Float_t textSize =   gVirtualX->GetTextSize();
162                  gVirtualX->SetTextSize(10);
163                  gVirtualX->SetTextAlign(22);
164                  //              gPad->PaintText(padPadPos.X()-0.01,padPadPos.Y()-0.01,
165                  gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
166                               Form("%d",connect->GetGassiNum()));
167               
168                  gVirtualX->SetTextSize(textSize);
169                  }
170             }
171           }
172       }
173
174     }
175     break;
176
177  case 'C':
178    {
179      // drawing real motif (not envelop) the real contour
180      Float_t xl = 0;
181      Float_t yl = 0;
182      Int_t manuId = 0;
183      TVector2 bl0 = TVector2(999, 999);
184      TVector2 ur0 = TVector2(0,0); 
185      TVector2 padPadPos,padPadDim;
186
187      AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
188      manuId = fMotifPos->GetID();
189
190      if (manuId % 5 == 0) 
191         gVirtualX->SetFillColor(0);
192      if (manuId % 5 == 1) 
193         gVirtualX->SetFillColor(38);
194      if (manuId % 5 == 2) 
195         gVirtualX->SetFillColor(33);
196      if (manuId % 5 == 3) 
197         gVirtualX->SetFillColor(16);
198      if (manuId % 5 == 4) 
199         gVirtualX->SetFillColor(44);
200
201      for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
202
203        for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
204
205          AliMpIntPair indices = AliMpIntPair(i,j);
206          AliMpConnection* connect =  motifType->FindConnectionByLocalIndices(indices);
207          if (connect){
208            TVector2 realPadPos = 
209              GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
210            gr->RealToPad(realPadPos, fMotifPos->GetMotif()->GetPadDimensions(indices),
211                          padPadPos, padPadDim);
212
213            TVector2 bl = padPadPos - padPadDim;
214            TVector2 ur = padPadPos + padPadDim;
215            if (bl0.X() > bl.X())
216              bl0 = bl;
217
218            if (ur0.Y() < ur.Y())
219              ur0 = ur;
220           
221            Style_t sty = gVirtualX->GetFillStyle();
222            gVirtualX->SetFillStyle(1);
223            gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
224            gVirtualX->SetFillStyle(0);
225
226            if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j-1)))
227                gPad->PaintLine(bl.X(), bl.Y(), bl.X()+ padPadDim.X()*2, bl.Y());
228
229            if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j+1)))
230                gPad->PaintLine(bl.X(), bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2, bl.Y() +  padPadDim.Y()*2);
231              
232            if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i-1,j)))
233              gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
234
235            gVirtualX->SetFillStyle(sty);
236
237          }
238        }
239      }
240
241      switch (option[1]) {
242        // add manudId indexes
243      case 'I' :
244        xl = bl0.X()+ padPadDim.X()/2.;
245   
246        yl = bl0.Y() + 1.5*padPadDim.Y();
247      
248        Float_t textSize =   gVirtualX->GetTextSize();
249        gVirtualX->SetTextSize(12);
250        gVirtualX->SetTextAlign(13);
251        gVirtualX->SetTextAngle(90.);
252        
253        gPad->PaintText(xl, yl, Form("%d", manuId));
254        
255        gVirtualX->SetTextAngle(0.);
256        gVirtualX->SetTextSize(textSize);
257        break;
258      }
259    }
260    break;
261
262   default:
263     PaintWholeBox(kFALSE);
264   }
265   gr->Pop();
266   gVirtualX->SetFillColor(col);
267 }