]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // Category: graphics | |
3 | // | |
4 | // Class AliMpSubZonePainter | |
5 | // ------------------------- | |
6 | // Class for drawing a subzone into canvas | |
7 | // | |
8 | // Authors: David Guez, IPN Orsay | |
9 | ||
2998a151 | 10 | #include <TVirtualX.h> |
11 | #include <TPad.h> | |
12 | ||
5f91c9e8 | 13 | #include "AliMpSubZonePainter.h" |
14 | #include "AliMpGraphContext.h" | |
15 | #include "AliMpSubZone.h" | |
16 | #include "AliMpVRowSegment.h" | |
17 | #include "AliMpVMotif.h" | |
18 | ||
19 | ClassImp(AliMpSubZonePainter) | |
20 | ||
21 | //_______________________________________________________________________ | |
22 | AliMpSubZonePainter::AliMpSubZonePainter() | |
23 | : AliMpVPainter(), | |
24 | fSubZone(0) | |
25 | { | |
26 | // default dummy constructor | |
27 | } | |
28 | //_______________________________________________________________________ | |
29 | AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone) | |
30 | : AliMpVPainter(), | |
31 | fSubZone(subZone) | |
32 | { | |
33 | // normal constructor | |
34 | ||
35 | } | |
36 | //_______________________________________________________________________ | |
2998a151 | 37 | AliMpSubZonePainter::~AliMpSubZonePainter() |
38 | { | |
39 | // destructor | |
40 | } | |
41 | //_______________________________________________________________________ | |
5f91c9e8 | 42 | Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y) |
43 | { | |
44 | // dist to the nearest segment center if (x,y) is inside the sub-zone | |
45 | // 9999 otherwise | |
46 | if (fSubZone->GetNofRowSegments()<1) return 9999; | |
47 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
48 | ||
49 | gr->Push(); | |
50 | InitGraphContext(); | |
51 | ||
52 | ||
53 | TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y)); | |
54 | ||
55 | Double_t res=9999.; | |
56 | for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){ | |
57 | //for each row segments | |
58 | AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg); | |
59 | ||
60 | TVector2 pos,dim; | |
61 | gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim); | |
62 | ||
63 | if ( IsInside(point,pos,dim) ){ | |
64 | Double_t value = (point-pos).Mod(); | |
65 | if (value<res) res=value; | |
66 | } | |
67 | } | |
68 | gr->Pop(); | |
69 | return (Int_t)res; | |
70 | } | |
71 | ||
72 | //_______________________________________________________________________ | |
73 | void AliMpSubZonePainter::DumpObject() | |
74 | { | |
75 | // Draw the owned object | |
76 | fSubZone->Dump(); | |
77 | ||
78 | } | |
79 | //_______________________________________________________________________ | |
80 | TVector2 AliMpSubZonePainter::GetPosition() const | |
81 | { | |
82 | // Get the owned object's position | |
83 | ||
84 | if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.); | |
85 | AliMpVRowSegment* seg = fSubZone->GetRowSegment(0); | |
86 | ||
87 | // bl = bottom left position; | |
88 | TVector2 bl = seg->Position()-seg->Dimensions(); | |
89 | // ur = upper right position | |
90 | TVector2 ur = seg->Position()+seg->Dimensions(); | |
91 | ||
92 | for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){ | |
93 | seg = fSubZone->GetRowSegment(iseg); | |
94 | // update the bottom-left corner | |
95 | if (bl.X()>seg->Position().X()-seg->Dimensions().X()) | |
96 | bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y()); | |
97 | if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y()) | |
98 | bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y()); | |
99 | // update the upper-right corner | |
100 | if (ur.X()<seg->Position().X()+seg->Dimensions().X()) | |
101 | ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y()); | |
102 | if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y()) | |
103 | ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y()); | |
104 | } | |
105 | return (ur+bl)/2.; | |
106 | } | |
107 | //_______________________________________________________________________ | |
108 | TVector2 AliMpSubZonePainter::GetDimensions() const | |
109 | { | |
110 | // Get the owned object's dimensions | |
111 | ||
112 | if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.); | |
113 | AliMpVRowSegment* seg = fSubZone->GetRowSegment(0); | |
114 | ||
115 | // bl = bottom left position; | |
116 | TVector2 bl = seg->Position()-seg->Dimensions(); | |
117 | // ur = upper right position | |
118 | TVector2 ur = seg->Position()+seg->Dimensions(); | |
119 | ||
120 | for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){ | |
121 | seg = fSubZone->GetRowSegment(iseg); | |
122 | // update the bottom-left corner | |
123 | if (bl.X()>seg->Position().X()-seg->Dimensions().X()) | |
124 | bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y()); | |
125 | if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y()) | |
126 | bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y()); | |
127 | // update the upper-right corner | |
128 | if (ur.X()<seg->Position().X()+seg->Dimensions().X()) | |
129 | ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y()); | |
130 | if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y()) | |
131 | ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y()); | |
132 | } | |
133 | return (ur-bl)/2.; | |
134 | } | |
135 | //_______________________________________________________________________ | |
136 | void AliMpSubZonePainter::Draw(Option_t *option) | |
137 | { | |
138 | // Draw the sector on the current pad | |
139 | // The first letter of <option> is treated as follows: | |
140 | // case "S" : each row segments are drawn separately | |
141 | // case "" : the whole subzone is drawn at once | |
142 | // in both cases, the rest of the option is passed | |
143 | // as argument to the Draw function of respectively | |
144 | // zone or row objects. | |
145 | // --- | |
146 | ||
147 | if (!fSubZone) return; | |
148 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
149 | ||
150 | gr->Push(); | |
151 | InitGraphContext(); | |
152 | switch (option[0]){ | |
153 | case 'S': | |
154 | { | |
155 | ||
156 | for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){ | |
157 | gr->Push(); | |
158 | AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg); | |
159 | ||
160 | gr->SetPadPosForReal(rowSegment->Position(), | |
161 | rowSegment->Dimensions()); | |
162 | gr->SetColor(GetColor()); | |
163 | DrawObject(rowSegment,option+1); | |
164 | ||
165 | gr->Pop(); | |
166 | } | |
167 | } | |
168 | break; | |
169 | default: AppendPad(option); | |
170 | } | |
171 | gr->Pop(); | |
172 | } | |
173 | ||
174 | ||
175 | //_______________________________________________________________________ | |
176 | void AliMpSubZonePainter::Paint(Option_t *option) | |
177 | { | |
178 | // Paint the object | |
179 | AliMpGraphContext *gr = AliMpGraphContext::Instance(); | |
180 | if (!fSubZone) return; | |
181 | if (fSubZone->GetNofRowSegments()<1) return; | |
182 | gr->Push(); | |
183 | gPad->Range(0.,0.,1.,1.); | |
184 | Int_t col=gVirtualX->GetFillColor(); | |
185 | InitGraphContext(); | |
186 | ||
187 | gVirtualX->SetFillColor(GetColor()); | |
188 | for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){ | |
189 | AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg); | |
190 | TVector2 pos,dim; | |
191 | gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(), | |
192 | pos,dim); | |
193 | gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(), | |
194 | pos.X()+dim.X(),pos.Y()+dim.Y()); | |
195 | if (option[0]=='T'){ | |
196 | Float_t textSize = gVirtualX->GetTextSize(); | |
197 | gVirtualX->SetTextSize(15); | |
198 | gPad->PaintText(pos.X()-0.01,pos.Y()-0.01, | |
199 | fSubZone->GetMotif()->GetID()); | |
200 | gVirtualX->SetTextSize(textSize); | |
201 | } | |
202 | } | |
203 | ||
204 | gVirtualX->SetFillColor(col); | |
205 | gr->Pop(); | |
206 | } |