]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "GeoNode.h" | |
4 | #include <Reve/RGTopFrame.h> | |
5 | ||
5b3adb7e | 6 | #include "TGeoShapeExtract.h" |
7 | ||
5a5a1232 | 8 | #include <TPad.h> |
5b3adb7e | 9 | #include <TBuffer3D.h> |
10 | #include <TVirtualViewer3D.h> | |
5a5a1232 | 11 | #include <TColor.h> |
12 | ||
5b3adb7e | 13 | #include <TGeoShape.h> |
5a5a1232 | 14 | #include <TGeoVolume.h> |
15 | #include <TGeoNode.h> | |
16 | #include <TGeoManager.h> | |
24e2ff4a | 17 | #include <TVirtualGeoPainter.h> |
5a5a1232 | 18 | |
19 | using namespace Reve; | |
20 | ||
21 | //______________________________________________________________________ | |
22 | // GeoNodeRnrEl | |
23 | // | |
24 | ||
25 | ClassImp(GeoNodeRnrEl) | |
26 | ||
27 | GeoNodeRnrEl::GeoNodeRnrEl(TGeoNode* node) : | |
5b457dfa | 28 | RenderElement(), |
7d42b6c2 | 29 | TObject(), |
5a5a1232 | 30 | fNode(node) |
31 | { | |
32 | // Hack!! Should use cint to retrieve TAttLine::fLineColor offset. | |
33 | char* l = (char*) dynamic_cast<TAttLine*>(node->GetVolume()); | |
34 | SetMainColorPtr((Color_t*)(l + sizeof(void*))); | |
35 | ||
5b457dfa | 36 | fRnrSelf = fNode->TGeoAtt::IsVisible(); |
5a5a1232 | 37 | } |
38 | ||
39 | const Text_t* GeoNodeRnrEl::GetName() const { return fNode->GetName(); } | |
40 | const Text_t* GeoNodeRnrEl::GetTitle() const { return fNode->GetTitle(); } | |
41 | ||
42 | /**************************************************************************/ | |
43 | ||
44 | Int_t GeoNodeRnrEl::ExpandIntoListTree(TGListTree* ltree, | |
45 | TGListTreeItem* parent) | |
46 | { | |
47 | // Checks if child-nodes have been imported ... imports them if not. | |
5b457dfa | 48 | // Then calls RenderElement::ExpandIntoListTree. |
5a5a1232 | 49 | |
7d42b6c2 | 50 | if(fChildren.empty() && fNode->GetVolume()->GetNdaughters() > 0) { |
5a5a1232 | 51 | TIter next(fNode->GetVolume()->GetNodes()); |
52 | TGeoNode* dnode; | |
53 | while((dnode = (TGeoNode*) next()) != 0) { | |
54 | GeoNodeRnrEl* node_re = new GeoNodeRnrEl(dnode); | |
55 | AddElement(node_re); | |
56 | } | |
57 | } | |
5b457dfa | 58 | return RenderElement::ExpandIntoListTree(ltree, parent); |
5a5a1232 | 59 | } |
60 | ||
61 | /**************************************************************************/ | |
62 | ||
44f64ac9 | 63 | void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr) |
5a5a1232 | 64 | { |
44f64ac9 | 65 | RenderElement::SetRnrSelf(rnr); |
66 | fNode->SetVisibility(rnr); | |
5a5a1232 | 67 | } |
68 | ||
44f64ac9 | 69 | void GeoNodeRnrEl::SetRnrChildren(Bool_t rnr) |
70 | { | |
71 | RenderElement::SetRnrChildren(rnr); | |
72 | fNode->VisibleDaughters(rnr); | |
73 | } | |
5a5a1232 | 74 | |
44f64ac9 | 75 | void GeoNodeRnrEl::SetRnrState(Bool_t rnr) |
5a5a1232 | 76 | { |
44f64ac9 | 77 | RenderElement::SetRnrState(rnr); |
5a5a1232 | 78 | fNode->SetVisibility(rnr); |
44f64ac9 | 79 | fNode->VisibleDaughters(rnr); |
5a5a1232 | 80 | } |
81 | ||
82 | /**************************************************************************/ | |
83 | ||
84 | void GeoNodeRnrEl::SetMainColor(Color_t color) | |
85 | { | |
86 | fNode->GetVolume()->SetLineColor(color); | |
7d42b6c2 | 87 | UpdateItems(); |
5a5a1232 | 88 | } |
89 | ||
90 | void GeoNodeRnrEl::SetMainColor(Pixel_t pixel) | |
91 | { | |
92 | // This one needed for proper calling via CINT (signals). | |
93 | ||
94 | SetMainColor(Color_t(TColor::GetColor(pixel))); | |
95 | } | |
96 | ||
97 | /**************************************************************************/ | |
98 | ||
99 | void GeoNodeRnrEl::UpdateNode(TGeoNode* node) | |
100 | { | |
101 | // Updates all reve-browsers having the node in their contents. | |
102 | // All 3D-pads updated if any change found. | |
103 | // | |
104 | // Should (could?) be optimized with some assumptions about | |
105 | // volume/node structure (search for parent, know the same node can not | |
106 | // reoccur on lower level once found). | |
107 | ||
108 | static const Exc_t eH("GeoNodeRnrEl::UpdateNode "); | |
109 | ||
110 | // printf("%s node %s %p\n", eH.Data(), node->GetName(), node); | |
111 | ||
112 | if(fNode == node) | |
7d42b6c2 | 113 | UpdateItems(); |
5a5a1232 | 114 | |
e6ac3950 | 115 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 116 | ((GeoNodeRnrEl*)(*i))->UpdateNode(node); |
117 | } | |
118 | ||
119 | } | |
120 | ||
121 | void GeoNodeRnrEl::UpdateVolume(TGeoVolume* volume) | |
122 | { | |
123 | // Updates all reve-browsers having the volume in their contents. | |
124 | // All 3D-pads updated if any change found. | |
125 | // | |
126 | // Should (could?) be optimized with some assumptions about | |
127 | // volume/node structure (search for parent, know the same node can not | |
128 | // reoccur on lower level once found). | |
129 | ||
130 | static const Exc_t eH("GeoNodeRnrEl::UpdateVolume "); | |
131 | ||
132 | // printf("%s volume %s %p\n", eH.Data(), volume->GetName(), volume); | |
133 | ||
134 | if(fNode->GetVolume() == volume) | |
7d42b6c2 | 135 | UpdateItems(); |
5a5a1232 | 136 | |
e6ac3950 | 137 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 138 | ((GeoNodeRnrEl*)(*i))->UpdateVolume(volume); |
139 | } | |
140 | } | |
141 | ||
142 | /**************************************************************************/ | |
143 | ||
144 | void GeoNodeRnrEl::Draw(Option_t* option) | |
145 | { | |
146 | TString opt("SAME"); | |
147 | opt += option; | |
148 | fNode->GetVolume()->Draw(opt); | |
149 | } | |
150 | ||
151 | /**************************************************************************/ | |
152 | //______________________________________________________________________ | |
153 | // GeoTopNodeRnrEl | |
154 | // | |
24e2ff4a | 155 | // A wrapper over a TGeoNode, possibly displaced with a global |
156 | // trasformation fGlobalTrans (the matrix is owned by this class). | |
5a5a1232 | 157 | /**************************************************************************/ |
158 | ||
159 | ClassImp(GeoTopNodeRnrEl) | |
160 | ||
161 | GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node, | |
162 | Int_t visopt, Int_t vislvl) : | |
57ad1faf | 163 | GeoNodeRnrEl (node), |
f36b73bd | 164 | fGlobalTrans (), |
57ad1faf | 165 | fManager (manager), |
166 | fVisOption (visopt), | |
167 | fVisLevel (vislvl) | |
5a5a1232 | 168 | { |
5b457dfa | 169 | fRnrSelf = true; |
5a5a1232 | 170 | } |
171 | ||
24e2ff4a | 172 | GeoTopNodeRnrEl::~GeoTopNodeRnrEl() |
57ad1faf | 173 | {} |
24e2ff4a | 174 | |
175 | /**************************************************************************/ | |
176 | ||
57ad1faf | 177 | void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m) |
24e2ff4a | 178 | { |
57ad1faf | 179 | fGlobalTrans.SetFrom(*m); |
24e2ff4a | 180 | } |
181 | ||
57ad1faf | 182 | void GeoTopNodeRnrEl::UseNodeTrans() |
24e2ff4a | 183 | { |
57ad1faf | 184 | fGlobalTrans.SetFrom(*fNode->GetMatrix()); |
24e2ff4a | 185 | } |
186 | ||
5a5a1232 | 187 | /**************************************************************************/ |
188 | ||
189 | void GeoTopNodeRnrEl::SetVisOption(Int_t visopt) | |
190 | { | |
191 | fVisOption = visopt; | |
192 | gReve->Redraw3D(); | |
193 | } | |
194 | ||
195 | void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl) | |
196 | { | |
197 | fVisLevel = vislvl; | |
198 | gReve->Redraw3D(); | |
199 | } | |
200 | ||
201 | /**************************************************************************/ | |
202 | ||
5b457dfa | 203 | void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr) |
5a5a1232 | 204 | { |
205 | // Revert from GeoNode to back to standard behaviour. | |
5b457dfa | 206 | RenderElement::SetRnrSelf(rnr); |
5a5a1232 | 207 | } |
57ad1faf | 208 | |
5a5a1232 | 209 | /**************************************************************************/ |
210 | ||
211 | void GeoTopNodeRnrEl::Draw(Option_t* option) | |
212 | { | |
213 | AppendPad(option); | |
214 | } | |
215 | ||
216 | void GeoTopNodeRnrEl::Paint(Option_t* option) | |
217 | { | |
5b457dfa | 218 | if(fRnrSelf) { |
5a5a1232 | 219 | gGeoManager = fManager; |
220 | TVirtualPad* pad = gPad; | |
221 | gPad = 0; | |
222 | TGeoVolume* top_volume = fManager->GetTopVolume(); | |
223 | fManager->SetVisOption(fVisOption); | |
224 | fManager->SetVisLevel(fVisLevel); | |
225 | fManager->SetTopVolume(fNode->GetVolume()); | |
226 | gPad = pad; | |
24e2ff4a | 227 | TVirtualGeoPainter* vgp = fManager->GetGeomPainter(); |
228 | if(vgp != 0) { | |
7d42b6c2 | 229 | #if ROOT_VERSION_CODE > ROOT_VERSION(5,11,6) |
57ad1faf | 230 | TGeoHMatrix geomat; |
231 | fGlobalTrans.SetGeoHMatrix(geomat); | |
232 | vgp->PaintNode(fNode, option, &geomat); | |
24e2ff4a | 233 | #else |
234 | vgp->PaintNode(fNode, option); | |
235 | #endif | |
236 | } | |
5a5a1232 | 237 | fManager->SetTopVolume(top_volume); |
238 | } | |
239 | } | |
240 | ||
241 | /**************************************************************************/ | |
242 | ||
243 | void GeoTopNodeRnrEl::VolumeVisChanged(TGeoVolume* volume) | |
244 | { | |
245 | static const Exc_t eH("GeoTopNodeRnrEl::VolumeVisChanged "); | |
246 | printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume); | |
247 | UpdateVolume(volume); | |
248 | } | |
249 | ||
250 | void GeoTopNodeRnrEl::VolumeColChanged(TGeoVolume* volume) | |
251 | { | |
252 | static const Exc_t eH("GeoTopNodeRnrEl::VolumeColChanged "); | |
253 | printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume); | |
254 | UpdateVolume(volume); | |
255 | } | |
256 | ||
257 | void GeoTopNodeRnrEl::NodeVisChanged(TGeoNode* node) | |
258 | { | |
259 | static const Exc_t eH("GeoTopNodeRnrEl::NodeVisChanged "); | |
260 | printf("%s node %s %p\n", eH.Data(), node->GetName(), (void*)node); | |
261 | UpdateNode(node); | |
262 | } | |
5b3adb7e | 263 | |
264 | ||
265 | /**************************************************************************/ | |
266 | //______________________________________________________________________ | |
267 | // GeoShapeRnrEl | |
268 | // | |
269 | // Minimal shape-wrapper allowing import of stuff from gled and retaining | |
270 | // user-set visibility, colors and transparency. | |
271 | /**************************************************************************/ | |
272 | ||
273 | ClassImp(GeoShapeRnrEl) | |
274 | ||
275 | GeoShapeRnrEl::GeoShapeRnrEl(const Text_t* name, const Text_t* title) : | |
276 | RenderElement (fColor), | |
277 | TNamed (name, title), | |
f36b73bd | 278 | fHMTrans (), |
5b3adb7e | 279 | fColor (0), |
280 | fTransparency (0), | |
281 | fShape (0) | |
282 | {} | |
283 | ||
284 | GeoShapeRnrEl::~GeoShapeRnrEl() | |
285 | { | |
286 | if (fShape) { | |
287 | fShape->SetUniqueID(fShape->GetUniqueID() - 1); | |
288 | if (fShape->GetUniqueID() == 0) | |
289 | delete fShape; | |
290 | } | |
291 | } | |
292 | ||
293 | /**************************************************************************/ | |
294 | ||
295 | void GeoShapeRnrEl::Paint(Option_t* /*option*/) | |
296 | { | |
297 | if (fShape == 0) | |
298 | return; | |
299 | ||
300 | TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D | |
301 | (TBuffer3D::kCore, false); | |
302 | ||
5b3adb7e | 303 | buff.fID = this; |
304 | buff.fColor = fColor; | |
305 | buff.fTransparency = fTransparency; | |
57ad1faf | 306 | fHMTrans.SetBuffer3D(buff); |
5b3adb7e | 307 | |
308 | fShape->GetBuffer3D(TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific, true); | |
309 | ||
310 | Int_t reqSec = gPad->GetViewer3D()->AddObject(buff); | |
311 | ||
312 | if (reqSec != TBuffer3D::kNone) { | |
313 | fShape->GetBuffer3D(reqSec, true); | |
314 | reqSec = gPad->GetViewer3D()->AddObject(buff); | |
315 | } | |
316 | ||
317 | if (reqSec != TBuffer3D::kNone) | |
318 | printf("spooky reqSec=%d for %s\n", reqSec, GetName()); | |
319 | } | |
320 | ||
321 | /**************************************************************************/ | |
322 | ||
323 | Int_t GeoShapeRnrEl::ImportShapeExtract(TGeoShapeExtract * gse, | |
324 | RenderElement * parent) | |
325 | { | |
326 | gReve->DisableRedraw(); | |
327 | Int_t n = SubImportShapeExtract(gse, parent); | |
328 | printf ("GeoShapeRnrEl::ImportShapeExtract imported %d elements\n", n); | |
329 | gReve->EnableRedraw(); | |
330 | return n; | |
331 | } | |
332 | ||
333 | Int_t GeoShapeRnrEl::SubImportShapeExtract(TGeoShapeExtract * gse, | |
334 | RenderElement * parent) | |
335 | { | |
336 | Int_t ncreated = 1; | |
337 | ||
338 | GeoShapeRnrEl* gsre = new GeoShapeRnrEl(gse->GetName(), gse->GetTitle()); | |
339 | gsre->fHMTrans.SetFromArray(gse->GetTrans()); | |
5b3adb7e | 340 | const Float_t* rgba = gse->GetRGBA(); |
341 | gsre->fColor = TColor::GetColor(rgba[0], rgba[1], rgba[2]); | |
342 | gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3])); | |
343 | gsre->SetRnrSelf(gse->GetRnrSelf()); | |
344 | gsre->SetRnrChildren(gse->GetRnrElements()); | |
345 | gsre->fShape = gse->GetShape(); | |
346 | if (gsre->fShape) | |
347 | gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1); | |
348 | ||
349 | if (parent) | |
350 | gReve->AddGlobalRenderElement(parent, gsre); | |
351 | else | |
352 | gReve->AddGlobalRenderElement(gsre); | |
353 | ||
354 | if (gse->HasElements()) | |
355 | { | |
356 | TIter next(gse->GetElements()); | |
357 | TGeoShapeExtract* chld; | |
358 | while ((chld = (TGeoShapeExtract*) next()) != 0) | |
359 | ncreated += SubImportShapeExtract(chld, gsre); | |
360 | } | |
361 | ||
362 | return ncreated; | |
363 | } |