]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/GeoNode.cxx
Migrate to the new signature of TMacro::Exec.
[u/mrichter/AliRoot.git] / EVE / Reve / GeoNode.cxx
CommitLineData
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
19using namespace Reve;
20
21//______________________________________________________________________
22// GeoNodeRnrEl
23//
24
25ClassImp(GeoNodeRnrEl)
26
27GeoNodeRnrEl::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
39const Text_t* GeoNodeRnrEl::GetName() const { return fNode->GetName(); }
40const Text_t* GeoNodeRnrEl::GetTitle() const { return fNode->GetTitle(); }
41
42/**************************************************************************/
43
44Int_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 63void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr)
5a5a1232 64{
44f64ac9 65 RenderElement::SetRnrSelf(rnr);
66 fNode->SetVisibility(rnr);
5a5a1232 67}
68
44f64ac9 69void GeoNodeRnrEl::SetRnrChildren(Bool_t rnr)
70{
71 RenderElement::SetRnrChildren(rnr);
72 fNode->VisibleDaughters(rnr);
73}
5a5a1232 74
44f64ac9 75void 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
84void GeoNodeRnrEl::SetMainColor(Color_t color)
85{
86 fNode->GetVolume()->SetLineColor(color);
7d42b6c2 87 UpdateItems();
5a5a1232 88}
89
90void 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
99void 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
121void 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
144void 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
159ClassImp(GeoTopNodeRnrEl)
160
161GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node,
162 Int_t visopt, Int_t vislvl) :
57ad1faf 163 GeoNodeRnrEl (node),
164 fManager (manager),
165 fVisOption (visopt),
166 fVisLevel (vislvl)
5a5a1232 167{
5b457dfa 168 fRnrSelf = true;
5a5a1232 169}
170
24e2ff4a 171GeoTopNodeRnrEl::~GeoTopNodeRnrEl()
57ad1faf 172{}
24e2ff4a 173
174/**************************************************************************/
175
57ad1faf 176void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m)
24e2ff4a 177{
57ad1faf 178 fGlobalTrans.SetFrom(*m);
24e2ff4a 179}
180
57ad1faf 181void GeoTopNodeRnrEl::UseNodeTrans()
24e2ff4a 182{
57ad1faf 183 fGlobalTrans.SetFrom(*fNode->GetMatrix());
24e2ff4a 184}
185
5a5a1232 186/**************************************************************************/
187
188void GeoTopNodeRnrEl::SetVisOption(Int_t visopt)
189{
190 fVisOption = visopt;
191 gReve->Redraw3D();
192}
193
194void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl)
195{
196 fVisLevel = vislvl;
197 gReve->Redraw3D();
198}
199
200/**************************************************************************/
201
5b457dfa 202void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr)
5a5a1232 203{
204 // Revert from GeoNode to back to standard behaviour.
5b457dfa 205 RenderElement::SetRnrSelf(rnr);
5a5a1232 206}
57ad1faf 207
5a5a1232 208/**************************************************************************/
209
210void GeoTopNodeRnrEl::Draw(Option_t* option)
211{
212 AppendPad(option);
213}
214
215void GeoTopNodeRnrEl::Paint(Option_t* option)
216{
5b457dfa 217 if(fRnrSelf) {
5a5a1232 218 gGeoManager = fManager;
219 TVirtualPad* pad = gPad;
220 gPad = 0;
221 TGeoVolume* top_volume = fManager->GetTopVolume();
222 fManager->SetVisOption(fVisOption);
223 fManager->SetVisLevel(fVisLevel);
224 fManager->SetTopVolume(fNode->GetVolume());
225 gPad = pad;
24e2ff4a 226 TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
227 if(vgp != 0) {
7d42b6c2 228#if ROOT_VERSION_CODE > ROOT_VERSION(5,11,6)
57ad1faf 229 TGeoHMatrix geomat;
230 fGlobalTrans.SetGeoHMatrix(geomat);
231 vgp->PaintNode(fNode, option, &geomat);
24e2ff4a 232#else
233 vgp->PaintNode(fNode, option);
234#endif
235 }
5a5a1232 236 fManager->SetTopVolume(top_volume);
237 }
238}
239
240/**************************************************************************/
241
242void GeoTopNodeRnrEl::VolumeVisChanged(TGeoVolume* volume)
243{
244 static const Exc_t eH("GeoTopNodeRnrEl::VolumeVisChanged ");
245 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
246 UpdateVolume(volume);
247}
248
249void GeoTopNodeRnrEl::VolumeColChanged(TGeoVolume* volume)
250{
251 static const Exc_t eH("GeoTopNodeRnrEl::VolumeColChanged ");
252 printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume);
253 UpdateVolume(volume);
254}
255
256void GeoTopNodeRnrEl::NodeVisChanged(TGeoNode* node)
257{
258 static const Exc_t eH("GeoTopNodeRnrEl::NodeVisChanged ");
259 printf("%s node %s %p\n", eH.Data(), node->GetName(), (void*)node);
260 UpdateNode(node);
261}
5b3adb7e 262
263
264/**************************************************************************/
265//______________________________________________________________________
266// GeoShapeRnrEl
267//
268// Minimal shape-wrapper allowing import of stuff from gled and retaining
269// user-set visibility, colors and transparency.
270/**************************************************************************/
271
272ClassImp(GeoShapeRnrEl)
273
274GeoShapeRnrEl::GeoShapeRnrEl(const Text_t* name, const Text_t* title) :
275 RenderElement (fColor),
276 TNamed (name, title),
277 fColor (0),
278 fTransparency (0),
279 fShape (0)
280{}
281
282GeoShapeRnrEl::~GeoShapeRnrEl()
283{
284 if (fShape) {
285 fShape->SetUniqueID(fShape->GetUniqueID() - 1);
286 if (fShape->GetUniqueID() == 0)
287 delete fShape;
288 }
289}
290
291/**************************************************************************/
292
293void GeoShapeRnrEl::Paint(Option_t* /*option*/)
294{
295 if (fShape == 0)
296 return;
297
298 TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
299 (TBuffer3D::kCore, false);
300
5b3adb7e 301 buff.fID = this;
302 buff.fColor = fColor;
303 buff.fTransparency = fTransparency;
57ad1faf 304 fHMTrans.SetBuffer3D(buff);
5b3adb7e 305
306 fShape->GetBuffer3D(TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific, true);
307
308 Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
309
310 if (reqSec != TBuffer3D::kNone) {
311 fShape->GetBuffer3D(reqSec, true);
312 reqSec = gPad->GetViewer3D()->AddObject(buff);
313 }
314
315 if (reqSec != TBuffer3D::kNone)
316 printf("spooky reqSec=%d for %s\n", reqSec, GetName());
317}
318
319/**************************************************************************/
320
321Int_t GeoShapeRnrEl::ImportShapeExtract(TGeoShapeExtract * gse,
322 RenderElement * parent)
323{
324 gReve->DisableRedraw();
325 Int_t n = SubImportShapeExtract(gse, parent);
326 printf ("GeoShapeRnrEl::ImportShapeExtract imported %d elements\n", n);
327 gReve->EnableRedraw();
328 return n;
329}
330
331Int_t GeoShapeRnrEl::SubImportShapeExtract(TGeoShapeExtract * gse,
332 RenderElement * parent)
333{
334 Int_t ncreated = 1;
335
336 GeoShapeRnrEl* gsre = new GeoShapeRnrEl(gse->GetName(), gse->GetTitle());
337 gsre->fHMTrans.SetFromArray(gse->GetTrans());
5b3adb7e 338 const Float_t* rgba = gse->GetRGBA();
339 gsre->fColor = TColor::GetColor(rgba[0], rgba[1], rgba[2]);
340 gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3]));
341 gsre->SetRnrSelf(gse->GetRnrSelf());
342 gsre->SetRnrChildren(gse->GetRnrElements());
343 gsre->fShape = gse->GetShape();
344 if (gsre->fShape)
345 gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1);
346
347 if (parent)
348 gReve->AddGlobalRenderElement(parent, gsre);
349 else
350 gReve->AddGlobalRenderElement(gsre);
351
352 if (gse->HasElements())
353 {
354 TIter next(gse->GetElements());
355 TGeoShapeExtract* chld;
356 while ((chld = (TGeoShapeExtract*) next()) != 0)
357 ncreated += SubImportShapeExtract(chld, gsre);
358 }
359
360 return ncreated;
361}