From Laurent
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPCBPainter.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: AliMpPCBPainter.cxx,v 1.4 2005/09/19 18:56:46 ivana Exp $
18 // Category: graphics
19 //
20 // Class AliMpSlatPainter
21 // -----------------------
22 // Class for drawing a PCB into canvas
23 // Authors: Laurent Aphecetche
24
25 #include "AliMpPCBPainter.h"
26
27 #include "AliMpGraphContext.h"
28 #include "AliMpMotifPosition.h"
29 #include "AliMpPCB.h"
30
31 #include "TVirtualX.h"
32 #include "TPad.h"
33
34 #include <iostream>
35
36 ClassImp(AliMpPCBPainter)
37
38 //_____________________________________________________________________________
39 AliMpPCBPainter::AliMpPCBPainter(AliMpPCB* pcb)
40   : AliMpVPainter(), fPCB(pcb)
41 {
42     //
43     // Default ctor.
44     //
45 }
46
47 //_____________________________________________________________________________
48 AliMpPCBPainter::~AliMpPCBPainter()
49 {
50   //
51   // Dtor.
52   //
53 }
54
55 //_____________________________________________________________________________
56 TVector2
57 AliMpPCBPainter::GetDimensions() const
58 {
59   //
60   // Returns the half-sizes of the PCB.
61   //
62   return TVector2(fPCB->DX(),fPCB->DY());
63 }
64
65 //_____________________________________________________________________________
66 TVector2
67 AliMpPCBPainter::GetPosition() const
68 {
69   //
70   // Returns the (x,y) position of the PCB.
71   //
72   return TVector2(fPCB->X(),fPCB->Y());
73 }
74
75 //_____________________________________________________________________________
76 void
77 AliMpPCBPainter::Draw(Option_t* option)
78 {
79   //
80   // Draws the PCB.
81   //
82   AliMpGraphContext *gr = AliMpGraphContext::Instance();
83   if (!fPCB) return;
84
85   gr->Push();
86   InitGraphContext();
87
88   std::cout << "PCB Position and Dimensions:" << std::endl;
89   GetPosition().Print();
90   GetDimensions().Print();
91
92   switch (option[0])
93     {
94     case 'M':
95       for ( AliMpPCB::Size_t i = 0; i < fPCB->GetSize(); ++i )
96         {
97           AliMpMotifPosition* pos = fPCB->GetMotifPosition(i);
98           
99           gr->Push();
100           gr->SetPadPosForReal(pos->Position(),
101                                pos->Dimensions());
102           //      
103           std::cout << "Motif Position " << pos->GetID()
104                     << std::endl;
105           pos->GetMotif()->Print("");
106           std::cout << "Motif dimension:" << std::endl;
107           pos->GetMotif()->Dimensions().Print();
108           std::cout << "MotifPosition position:" << std::endl;
109           pos->Position().Print();
110           std::cout << "MotifPosition dimensions:" << std::endl;
111           pos->Dimensions().Print();
112           //      int id = atoi(pos->GetMotif()->GetID().Data());
113           gr->SetColor(2+i%7);
114           
115           DrawObject(pos,option+1);
116           
117           gr->Pop();
118         }
119       break;
120     default:
121       AppendPad(option);
122     }
123
124   gr->Pop();
125 }
126
127 //_____________________________________________________________________________
128 void
129 AliMpPCBPainter::Paint(Option_t* /*option*/)
130 {
131   //
132   // Paint the object.
133   //
134   AliMpGraphContext* gr = AliMpGraphContext::Instance();
135   if (!fPCB) return;
136   Int_t col=gVirtualX->GetFillColor();
137   gr->Push();
138   gPad->Range(0.,0.,1.,1.);
139   InitGraphContext();
140
141   PaintWholeBox(kTRUE);
142   
143   gr->Pop();
144   gVirtualX->SetFillColor(col);
145 }