]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifPainter.cxx
Fixing Doxygen warnings
[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 //-----------------------------------------------------------------------------
21 // Class AliMpMotifPainter
22 // -----------------------
23 // Class for drawing a motif into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
27
28 #include "AliMpMotifPainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpMotifPosition.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpMotif.h"
33 #include "AliMpConnection.h"
34 #include "AliLog.h"
35
36 #include <TVirtualX.h>
37 #include <TPad.h>
38  
39 #include <cstdlib>
40
41 /// \cond CLASSIMP
42 ClassImp(AliMpMotifPainter)
43 /// \endcond
44
45 //_______________________________________________________________________
46 AliMpMotifPainter::AliMpMotifPainter()
47   : AliMpVPainter(),
48     fMotifPos(0)
49 {
50   /// Default constructor
51 }
52
53 //_______________________________________________________________________
54 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
55   : AliMpVPainter(),
56     fMotifPos(motifPos)
57 {
58   /// Standard constructor 
59       AliDebug(1,"Default ctor");
60 }
61
62 //_______________________________________________________________________
63 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
64 : AliMpVPainter(),
65 fMotifPos(0x0)
66 {
67   /// Constructor from a motif Type. We hereby create a MotifPosition
68   /// object from it, using arbitrary pad sizes, as this is just a way
69   /// to visualize the *shape* of the motif.
70   
71   AliDebug(1,"Ctor from motifType");
72   
73   const Double_t kdx = 5;
74   const Double_t kdy = 5; // cm but arbitrary anyway
75   
76   AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
77                                       motifType,
78                                       kdx,kdy);
79
80   fMotifPos = new AliMpMotifPosition(-1,motif,
81                                      motif->DimensionX(), motif->DimensionY());
82 }
83
84 //_______________________________________________________________________
85 AliMpMotifPainter::~AliMpMotifPainter()
86 {
87   /// Default constructor
88 }
89
90 //_______________________________________________________________________
91 void AliMpMotifPainter::DumpObject()
92 {
93 /// Dump the owned object
94
95   fMotifPos->Dump();
96 }
97
98 //_______________________________________________________________________
99 TVector2 AliMpMotifPainter::GetPosition() const
100 {
101 /// Get the owned object's position
102
103   return TVector2(fMotifPos->GetPositionX(), fMotifPos->GetPositionY());
104 }
105
106 //_______________________________________________________________________
107 TVector2 AliMpMotifPainter::GetDimensions() const
108 {
109 /// Get the owned object's dimensions
110
111   return TVector2(fMotifPos->GetDimensionX(), fMotifPos->GetDimensionY());
112 }
113
114 //_______________________________________________________________________
115 void AliMpMotifPainter::Paint(Option_t *option)
116 {
117 /// Paint the object
118
119   AliMpGraphContext *gr = AliMpGraphContext::Instance();
120   if (!fMotifPos) return;
121   Int_t col=gVirtualX->GetFillColor();
122   gr->Push();
123   gPad->Range(0.,0.,1.,1.);
124   InitGraphContext();
125
126   gVirtualX->SetLineWidth(1);
127   
128   switch (option[0]){
129     case 'T':
130     case 'I':
131     case 'X':
132     {
133       PaintWholeBox();
134       Float_t textSize =   gVirtualX->GetTextSize();
135       gVirtualX->SetTextSize(10);
136       TString str;
137       switch (option[0]) {
138         case 'T' : 
139           str = Form("%d",fMotifPos->GetID());
140           break;
141         case 'I':{
142           switch (option[1]){
143             case '+' :
144               str = Form("(%d,%d)",fMotifPos->GetHighLimitIx(),
145                          fMotifPos->GetHighLimitIy());
146               break;
147             default:
148               str = Form("(%d,%d)",fMotifPos->GetLowLimitIx(),
149                          fMotifPos->GetLowLimitIy());
150           }
151         }
152           break;
153         case 'X' :
154           str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
155                      (GetPosition()-GetDimensions()).Y());
156           break;
157       }
158       gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
159       
160       gVirtualX->SetTextSize(textSize);
161     }
162       break;
163     case 'P':
164     case 'Z':
165     {
166       //PaintWholeBox(kFALSE);
167       AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
168       for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
169         for (Int_t i=0;i<motifType->GetNofPadsX();i++){
170           AliMpConnection* connect = 
171             motifType->FindConnectionByLocalIndices(i,j);
172           if (connect){
173             Double_t localPosX, localPosY;
174             fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY);
175             TVector2 realPadPos = 
176             GetPosition()+TVector2(localPosX, localPosY);
177
178             Double_t dx, dy;
179             fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j, dx, dy);
180             
181             TVector2 padPadPos,padPadDim;
182             gr->RealToPad(realPadPos,
183                           TVector2(dx, dy),
184                           padPadPos,padPadDim);
185             TVector2 bl = padPadPos - padPadDim;
186             TVector2 ur = padPadPos + padPadDim;
187
188             Style_t sty = gVirtualX->GetFillStyle();
189             gVirtualX->SetFillStyle(1);
190             gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
191             gVirtualX->SetFillStyle(0);
192             gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
193             gVirtualX->SetFillStyle(sty);
194
195             if (option[1]=='T'){
196               Float_t textSize =   gVirtualX->GetTextSize();
197               gVirtualX->SetTextSize(10);
198               gVirtualX->SetTextAlign(22);
199               gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
200                               Form("%d",connect->GetManuChannel()));
201               
202               gVirtualX->SetTextSize(textSize);
203                  }
204             }
205           }
206       }
207       if ( option[0]=='Z' )
208       {
209         PaintContour(option,kFALSE);
210       }
211     }
212       break;
213       
214     case 'C':
215       PaintContour(option,kTRUE);
216       break;
217       
218     default:
219       PaintWholeBox(kFALSE);
220   }
221   gr->Pop();
222   gVirtualX->SetFillColor(col);
223 }
224
225 //_______________________________________________________________________
226 void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
227 {
228 /// Drawing real motif (not envelop) the real contour
229
230   AliMpGraphContext *gr = AliMpGraphContext::Instance();
231   
232   Float_t xl = 0;
233   Float_t yl = 0;
234   Int_t manuId = 0;
235   Int_t searchMotif = -1;
236   TVector2 bl0 = TVector2(999, 999);
237   TVector2 ur0 = TVector2(0,0); 
238   TVector2 padPadPos,padPadDim;
239   
240   AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
241   manuId = fMotifPos->GetID();
242   
243   if ( fill )
244   {
245     if (manuId % 5 == 0) 
246       gVirtualX->SetFillColor(0);
247     if (manuId % 5 == 1) 
248       gVirtualX->SetFillColor(38);
249     if (manuId % 5 == 2) 
250       gVirtualX->SetFillColor(33);
251     if (manuId % 5 == 3) 
252       gVirtualX->SetFillColor(16);
253     if (manuId % 5 == 4) 
254       gVirtualX->SetFillColor(44);
255   }
256   
257   Width_t lineW = gPad->GetLineWidth();
258   Width_t lw = lineW*3;
259   Double_t xlw = gPad->PixeltoX(lw/2);
260   
261
262   if (option[1] == 'I' && option[2] == ':')
263       searchMotif = atoi(&option[3]);
264
265   gVirtualX->SetLineWidth(lw);
266     
267     for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
268       
269       for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
270         
271         AliMpConnection* connect =  motifType->FindConnectionByLocalIndices(i,j);
272
273         if (connect){
274           Double_t localPosX, localPosY;
275           fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY);
276
277           TVector2 realPadPos = 
278           GetPosition()+TVector2(localPosX, localPosY);
279           
280           Double_t dx, dy;
281           fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j, dx, dy);
282           
283           gr->RealToPad(realPadPos, 
284                         TVector2(dx, dy),
285                         padPadPos, padPadDim);
286           
287           TVector2 bl = padPadPos - padPadDim;
288           TVector2 ur = padPadPos + padPadDim;
289
290           if (bl0.X() > bl.X())
291             bl0 = bl;
292           
293           if (ur0.Y() < ur.Y())
294             ur0 = ur;
295           
296           if ( fill )
297           {
298             Style_t csty = gVirtualX->GetFillColor();
299             Style_t sty = gVirtualX->GetFillStyle();
300             gVirtualX->SetFillStyle(1);
301             if (manuId == searchMotif) 
302                 gVirtualX->SetFillColor(5); // yellow
303             gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
304             gVirtualX->SetFillStyle(sty);
305             gVirtualX->SetFillColor(csty);
306           } 
307
308           if (!motifType->FindConnectionByLocalIndices(i,j-1))
309           {
310             gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
311           }
312           
313           if (!motifType->FindConnectionByLocalIndices(i,j+1))
314           {
315             gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() +  padPadDim.Y()*2);
316           }
317           if (!motifType->FindConnectionByLocalIndices(i-1,j))
318           {
319             gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);                  
320           }          
321
322           if (!motifType->FindConnectionByLocalIndices(i+1,j))
323           {
324             gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);  
325           } 
326         }
327
328       }
329     }
330     
331     switch (option[1]) {
332       // add manudId indexes
333       case 'I' :
334         xl = bl0.X()+ padPadDim.X()/2.;
335         
336         yl = bl0.Y() + 1.5*padPadDim.Y();
337         
338         Float_t textSize =   gVirtualX->GetTextSize();
339         gVirtualX->SetTextSize(12);
340         gVirtualX->SetTextAlign(13);
341         gVirtualX->SetTextAngle(90.);
342         
343         gPad->PaintText(xl, yl, Form("%d", manuId));
344         
345         gVirtualX->SetTextAngle(0.);
346         gVirtualX->SetTextSize(textSize);
347         break;
348     }
349
350     gVirtualX->SetLineWidth(lineW);
351
352 }