]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifPainter.cxx
Removing useless ifs
[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.7 2005/08/26 15:43:36 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 <TVirtualX.h>
27 #include <TPad.h>
28 #include <TError.h>
29  
30 #include "AliMpMotifPainter.h"
31 #include "AliMpGraphContext.h"
32 #include "AliMpMotifPosition.h"
33 #include "AliMpMotifType.h"
34 #include "AliMpConnection.h"
35 #include "AliMpIntPair.h"
36
37 ClassImp(AliMpMotifPainter)
38
39 //_______________________________________________________________________
40 AliMpMotifPainter::AliMpMotifPainter()
41   : AliMpVPainter(),
42     fMotifPos(0)
43 {
44   /// Default constructor
45 }
46
47 //_______________________________________________________________________
48 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
49   : AliMpVPainter(),
50     fMotifPos(motifPos)
51 {
52   /// Standard constructor 
53
54 }
55
56 //_____________________________________________________________________________
57 AliMpMotifPainter::AliMpMotifPainter(const AliMpMotifPainter& right) 
58   : AliMpVPainter(right) 
59 {
60   /// Protected copy constructor (not provided) 
61
62   Fatal("AliMpMotifPainter", "Copy constructor not provided.");
63 }
64
65 //_______________________________________________________________________
66 AliMpMotifPainter::~AliMpMotifPainter()
67 {
68   /// Default constructor
69 }
70
71 //_____________________________________________________________________________
72 AliMpMotifPainter& 
73 AliMpMotifPainter::operator=(const AliMpMotifPainter& 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 AliMpMotifPainter::DumpObject()
87 {
88 /// Dump the owned object
89
90   fMotifPos->Dump();
91 }
92
93 //_______________________________________________________________________
94 TVector2 AliMpMotifPainter::GetPosition() const
95 {
96 /// Get the owned object's position
97
98   return fMotifPos->Position();
99 }
100
101 //_______________________________________________________________________
102 TVector2 AliMpMotifPainter::GetDimensions() const
103 {
104 /// Get the owned object's dimensions
105
106   return fMotifPos->Dimensions();
107 }
108
109 //_______________________________________________________________________
110 void AliMpMotifPainter::Paint(Option_t *option)
111 {
112 /// Paint the object
113
114   AliMpGraphContext *gr = AliMpGraphContext::Instance();
115   if (!fMotifPos) return;
116   Int_t col=gVirtualX->GetFillColor();
117   gr->Push();
118   gPad->Range(0.,0.,1.,1.);
119   InitGraphContext();
120
121   switch (option[0]){
122   case 'T':
123   case 'I':
124   case 'X':
125     {
126       PaintWholeBox();
127       Float_t textSize =   gVirtualX->GetTextSize();
128       gVirtualX->SetTextSize(10);
129       TString str;
130       switch (option[0]) {
131         case 'T' : 
132           str = Form("%d",fMotifPos->GetID());
133           break;
134         case 'I':{
135           switch (option[1]){
136             case '+' :
137             str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
138                                fMotifPos->GetHighIndicesLimit().GetSecond());
139             break;
140             default:
141             str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
142                                fMotifPos->GetLowIndicesLimit().GetSecond());
143           }
144         }
145         break;
146         case 'X' :
147           str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
148                                (GetPosition()-GetDimensions()).Y());
149           break;
150       }
151       gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
152       
153       gVirtualX->SetTextSize(textSize);
154     }
155     break;
156   case 'P':
157     {
158       //PaintWholeBox(kFALSE);
159       AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
160       for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
161            for (Int_t i=0;i<motifType->GetNofPadsX();i++){
162              AliMpIntPair indices = AliMpIntPair(i,j);
163                AliMpConnection* connect = 
164                  motifType->FindConnectionByLocalIndices(indices);
165              if (connect){
166                TVector2 realPadPos = 
167                 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
168                TVector2 padPadPos,padPadDim;
169                gr->RealToPad(realPadPos,
170                                fMotifPos->GetMotif()->GetPadDimensions(indices),
171                          padPadPos,padPadDim);
172                TVector2 bl = padPadPos - padPadDim;
173                TVector2 ur = padPadPos + padPadDim;
174
175
176                Style_t sty = gVirtualX->GetFillStyle();
177                gVirtualX->SetFillStyle(1);
178                gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
179                gVirtualX->SetFillStyle(0);
180                gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
181                gVirtualX->SetFillStyle(sty);
182                if (option[1]=='T'){
183                  Float_t textSize =   gVirtualX->GetTextSize();
184                  gVirtualX->SetTextSize(10);
185                  gVirtualX->SetTextAlign(22);
186                  //              gPad->PaintText(padPadPos.X()-0.01,padPadPos.Y()-0.01,
187                  gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
188                               Form("%d",connect->GetGassiNum()));
189               
190                  gVirtualX->SetTextSize(textSize);
191                  }
192             }
193           }
194       }
195     }
196     break;
197   default:
198     PaintWholeBox(kFALSE);
199   }
200   gr->Pop();
201   gVirtualX->SetFillColor(col);
202 }