]>
Commit | Line | Data |
---|---|---|
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: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $ |
5f91c9e8 | 18 | // Category: graphics |
19 | // | |
20 | // Class AliMpGraphContext | |
21 | // ----------------------- | |
22 | // Class describing a the correspondance between a given area | |
23 | // in pad, and a zone of real (cm) position | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Author: David GUEZ, IPN Orsay |
26 | ||
27 | #include "AliMpGraphContext.h" | |
28 | ||
13985652 | 29 | /// \cond CLASSIMP |
30 | ClassImp(AliMpGraphContext) | |
31 | /// \endcond | |
32 | ||
5f91c9e8 | 33 | AliMpGraphContext *AliMpGraphContext::fgInstance = 0; |
5006ec94 | 34 | AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack; |
2c605e66 | 35 | |
f79c58a5 | 36 | #ifdef WITH_ROOT |
37 | Int_t AliMpGraphContext::fgStackSize = 0; | |
38 | #endif | |
5f91c9e8 | 39 | |
fb1bf5c0 | 40 | //_____________________________________________________________________________ |
5f91c9e8 | 41 | AliMpGraphContext::AliMpGraphContext(): |
42 | TObject(), | |
0471c97b | 43 | fColor(20), |
5f91c9e8 | 44 | fPadPosition(TVector2(0.5,0.5)), |
45 | fPadDimensions(TVector2(0.49,0.49)), | |
46 | fRealPosition(TVector2(0.,0.)), | |
47 | fRealDimensions(TVector2(1,1)) | |
48 | { | |
0471c97b | 49 | /// Default constructor (private) |
5f91c9e8 | 50 | } |
fb1bf5c0 | 51 | |
52 | //_____________________________________________________________________________ | |
53 | AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right) | |
bcf37928 | 54 | : TObject(right), |
55 | fColor(right.fColor), | |
56 | fPadPosition(right.fPadPosition), | |
57 | fPadDimensions(right.fPadDimensions), | |
58 | fRealPosition(right.fRealPosition), | |
59 | fRealDimensions(right.fRealDimensions) | |
fb1bf5c0 | 60 | { |
dee1d5f1 | 61 | /// Copy constructor |
fb1bf5c0 | 62 | } |
63 | ||
64 | //_____________________________________________________________________________ | |
65 | AliMpGraphContext& | |
66 | AliMpGraphContext::operator=(const AliMpGraphContext& right) | |
67 | { | |
dee1d5f1 | 68 | /// Protected assignment operator |
fb1bf5c0 | 69 | |
dee1d5f1 | 70 | // check assignment to self |
fb1bf5c0 | 71 | if (this == &right) return *this; |
72 | ||
bcf37928 | 73 | fColor = right.fColor; |
74 | fPadPosition = right.fPadPosition; | |
75 | fPadDimensions = right.fPadDimensions; | |
76 | fRealPosition = right.fRealPosition; | |
77 | fRealDimensions = right.fRealDimensions; | |
fb1bf5c0 | 78 | |
79 | return *this; | |
80 | } | |
81 | ||
82 | //_____________________________________________________________________________ | |
5f91c9e8 | 83 | AliMpGraphContext *AliMpGraphContext::Instance() |
84 | { | |
dee1d5f1 | 85 | /// Return or create a unique instance of this class |
86 | ||
5f91c9e8 | 87 | if (fgInstance) return fgInstance; |
88 | fgInstance = new AliMpGraphContext; | |
89 | return fgInstance; | |
90 | } | |
91 | ||
fb1bf5c0 | 92 | //_____________________________________________________________________________ |
5f91c9e8 | 93 | TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const |
94 | { | |
dee1d5f1 | 95 | /// Transform a real position into its equivalent position in the pad |
96 | ||
5f91c9e8 | 97 | Double_t x=position.X(); |
98 | Double_t y=position.Y(); | |
99 | x-= (fRealPosition.X()-fRealDimensions.X()); | |
100 | x/=fRealDimensions.X(); | |
101 | x*=fPadDimensions.X(); | |
102 | x+= (fPadPosition.X()-fPadDimensions.X() ); | |
103 | ||
104 | y-= (fRealPosition.Y()-fRealDimensions.Y()); | |
105 | y/=fRealDimensions.Y(); | |
106 | y*=fPadDimensions.Y(); | |
107 | y+= (fPadPosition.Y()-fPadDimensions.Y() ); | |
108 | ||
109 | return TVector2(x,y); | |
110 | } | |
111 | ||
fb1bf5c0 | 112 | //_____________________________________________________________________________ |
5f91c9e8 | 113 | void AliMpGraphContext::RealToPad(const TVector2 &position, |
114 | const TVector2 &dimensions, | |
115 | TVector2 &padPosition, | |
116 | TVector2 &padDimensions) const | |
117 | { | |
dee1d5f1 | 118 | // Transform the real area (position,dimensions) to |
5f91c9e8 | 119 | // its equivalent pad area |
dee1d5f1 | 120 | |
5f91c9e8 | 121 | padPosition = RealToPad(position); |
122 | padDimensions = | |
123 | TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(), | |
124 | dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y()); | |
125 | ||
126 | } | |
fb1bf5c0 | 127 | |
128 | //_____________________________________________________________________________ | |
5f91c9e8 | 129 | void AliMpGraphContext::SetPadPosForReal(const TVector2 &position, |
130 | const TVector2 &dimensions) | |
131 | { | |
dee1d5f1 | 132 | /// Set the pad area from the actual one |
133 | /// corresponding to the given real area. | |
134 | ||
5f91c9e8 | 135 | RealToPad(position,dimensions,fPadPosition,fPadDimensions); |
136 | } | |
fb1bf5c0 | 137 | |
138 | //_____________________________________________________________________________ | |
5f91c9e8 | 139 | void AliMpGraphContext::Push() const |
140 | { | |
dee1d5f1 | 141 | /// Store the current configuration |
142 | ||
5f91c9e8 | 143 | AliMpGraphContext *save = new AliMpGraphContext(*this); |
f79c58a5 | 144 | |
145 | #ifdef WITH_STL | |
5f91c9e8 | 146 | fgStack.push_back(save); |
f79c58a5 | 147 | #endif |
148 | ||
149 | #ifdef WITH_ROOT | |
150 | fgStack.AddAt(save, fgStackSize++); | |
151 | #endif | |
5f91c9e8 | 152 | } |
fb1bf5c0 | 153 | |
154 | //_____________________________________________________________________________ | |
5f91c9e8 | 155 | void AliMpGraphContext::Pop() |
156 | { | |
dee1d5f1 | 157 | /// Pop an object from the stack. |
158 | ||
f79c58a5 | 159 | #ifdef WITH_STL |
5f91c9e8 | 160 | // restore the last saved configuration |
161 | if (!fgStack.empty()){ | |
162 | AliMpGraphContext *obj = fgStack.back(); | |
163 | *this = *obj; | |
164 | fgStack.pop_back(); | |
165 | delete obj; | |
166 | } | |
f79c58a5 | 167 | #endif |
168 | ||
169 | #ifdef WITH_ROOT | |
170 | // restore the last saved configuration | |
171 | if ( fgStackSize ){ | |
172 | AliMpGraphContext *obj | |
173 | = (AliMpGraphContext*)fgStack.At(--fgStackSize); | |
174 | *this = *obj; | |
175 | fgStack.RemoveAt(fgStackSize); | |
176 | delete obj; | |
177 | } | |
178 | #endif | |
5f91c9e8 | 179 | } |