]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // Category: graphics | |
3 | // | |
4 | // Class AliMpGraphContext | |
5 | // ----------------------- | |
6 | // Class describing a the correspondance between a given area | |
7 | // in pad, and a zone of real (cm) position | |
8 | // | |
9 | // Author: David GUEZ, IPN Orsay | |
10 | ||
fb1bf5c0 | 11 | #include <TError.h> |
12 | ||
5f91c9e8 | 13 | #include "AliMpGraphContext.h" |
14 | ||
15 | ClassImp(AliMpGraphContext) | |
16 | ||
17 | AliMpGraphContext *AliMpGraphContext::fgInstance = 0; | |
18 | GraphContextVector AliMpGraphContext::fgStack; | |
f79c58a5 | 19 | #ifdef WITH_ROOT |
20 | Int_t AliMpGraphContext::fgStackSize = 0; | |
21 | #endif | |
5f91c9e8 | 22 | |
fb1bf5c0 | 23 | //_____________________________________________________________________________ |
5f91c9e8 | 24 | AliMpGraphContext::AliMpGraphContext(): |
25 | TObject(), | |
26 | fPadPosition(TVector2(0.5,0.5)), | |
27 | fPadDimensions(TVector2(0.49,0.49)), | |
28 | fRealPosition(TVector2(0.,0.)), | |
29 | fRealDimensions(TVector2(1,1)) | |
30 | { | |
fb1bf5c0 | 31 | // private constructor |
32 | ||
5f91c9e8 | 33 | fColor = 20; |
34 | // default constructor (private) | |
35 | } | |
fb1bf5c0 | 36 | |
37 | //_____________________________________________________________________________ | |
38 | AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right) | |
39 | : TObject(right) | |
40 | { | |
41 | // protected copy constructor | |
42 | ||
43 | Fatal("AliMpGraphContext", "Copy constructor not provided."); | |
44 | } | |
45 | ||
46 | //_____________________________________________________________________________ | |
47 | AliMpGraphContext& | |
48 | AliMpGraphContext::operator=(const AliMpGraphContext& right) | |
49 | { | |
50 | // protected assignement operator | |
51 | ||
52 | // check assignement to self | |
53 | if (this == &right) return *this; | |
54 | ||
55 | Fatal("operator =", "Assignement operator not provided."); | |
56 | ||
57 | return *this; | |
58 | } | |
59 | ||
60 | //_____________________________________________________________________________ | |
5f91c9e8 | 61 | AliMpGraphContext *AliMpGraphContext::Instance() |
62 | { | |
63 | // return or create a unique instance of this class | |
64 | if (fgInstance) return fgInstance; | |
65 | fgInstance = new AliMpGraphContext; | |
66 | return fgInstance; | |
67 | } | |
68 | ||
fb1bf5c0 | 69 | //_____________________________________________________________________________ |
5f91c9e8 | 70 | TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const |
71 | { | |
72 | // transform a real position into its equivalent position in the pad | |
73 | Double_t x=position.X(); | |
74 | Double_t y=position.Y(); | |
75 | x-= (fRealPosition.X()-fRealDimensions.X()); | |
76 | x/=fRealDimensions.X(); | |
77 | x*=fPadDimensions.X(); | |
78 | x+= (fPadPosition.X()-fPadDimensions.X() ); | |
79 | ||
80 | y-= (fRealPosition.Y()-fRealDimensions.Y()); | |
81 | y/=fRealDimensions.Y(); | |
82 | y*=fPadDimensions.Y(); | |
83 | y+= (fPadPosition.Y()-fPadDimensions.Y() ); | |
84 | ||
85 | return TVector2(x,y); | |
86 | } | |
87 | ||
fb1bf5c0 | 88 | //_____________________________________________________________________________ |
5f91c9e8 | 89 | void AliMpGraphContext::RealToPad(const TVector2 &position, |
90 | const TVector2 &dimensions, | |
91 | TVector2 &padPosition, | |
92 | TVector2 &padDimensions) const | |
93 | { | |
94 | // transform the real area (position,dimensions) to | |
95 | // its equivalent pad area | |
96 | padPosition = RealToPad(position); | |
97 | padDimensions = | |
98 | TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(), | |
99 | dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y()); | |
100 | ||
101 | } | |
fb1bf5c0 | 102 | |
103 | //_____________________________________________________________________________ | |
5f91c9e8 | 104 | void AliMpGraphContext::SetPadPosForReal(const TVector2 &position, |
105 | const TVector2 &dimensions) | |
106 | { | |
107 | // Set the pad area from the actual one | |
108 | // corresponding to the given real area. | |
109 | RealToPad(position,dimensions,fPadPosition,fPadDimensions); | |
110 | } | |
fb1bf5c0 | 111 | |
112 | //_____________________________________________________________________________ | |
5f91c9e8 | 113 | void AliMpGraphContext::Push() const |
114 | { | |
115 | // Store the current configuration | |
116 | AliMpGraphContext *save = new AliMpGraphContext(*this); | |
f79c58a5 | 117 | |
118 | #ifdef WITH_STL | |
5f91c9e8 | 119 | fgStack.push_back(save); |
f79c58a5 | 120 | #endif |
121 | ||
122 | #ifdef WITH_ROOT | |
123 | fgStack.AddAt(save, fgStackSize++); | |
124 | #endif | |
5f91c9e8 | 125 | } |
fb1bf5c0 | 126 | |
127 | //_____________________________________________________________________________ | |
5f91c9e8 | 128 | void AliMpGraphContext::Pop() |
129 | { | |
fb1bf5c0 | 130 | // Pops object from the stack. |
f79c58a5 | 131 | #ifdef WITH_STL |
5f91c9e8 | 132 | // restore the last saved configuration |
133 | if (!fgStack.empty()){ | |
134 | AliMpGraphContext *obj = fgStack.back(); | |
135 | *this = *obj; | |
136 | fgStack.pop_back(); | |
137 | delete obj; | |
138 | } | |
f79c58a5 | 139 | #endif |
140 | ||
141 | #ifdef WITH_ROOT | |
142 | // restore the last saved configuration | |
143 | if ( fgStackSize ){ | |
144 | AliMpGraphContext *obj | |
145 | = (AliMpGraphContext*)fgStack.At(--fgStackSize); | |
146 | *this = *obj; | |
147 | fgStack.RemoveAt(fgStackSize); | |
148 | delete obj; | |
149 | } | |
150 | #endif | |
5f91c9e8 | 151 | } |