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