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