]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/GeoNode.cxx
Map SetRnrSelf and SetRnrChildren to node visibility and to node daughters visibility.
[u/mrichter/AliRoot.git] / EVE / Reve / GeoNode.cxx
1 // $Header$
2
3 #include "GeoNode.h"
4 #include <Reve/RGTopFrame.h>
5
6 #include "TGeoShapeExtract.h"
7
8 #include <TPad.h>
9 #include <TBuffer3D.h>
10 #include <TVirtualViewer3D.h>
11 #include <TColor.h>
12
13 #include <TGeoShape.h>
14 #include <TGeoVolume.h>
15 #include <TGeoNode.h>
16 #include <TGeoManager.h>
17 #include <TVirtualGeoPainter.h>
18
19 using namespace Reve;
20
21 //______________________________________________________________________
22 // GeoNodeRnrEl
23 //
24
25 ClassImp(GeoNodeRnrEl)
26
27 GeoNodeRnrEl::GeoNodeRnrEl(TGeoNode* node) :
28   RenderElement(),
29   TObject(),
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
36   fRnrSelf      = fNode->TGeoAtt::IsVisible();
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.
48   // Then calls RenderElement::ExpandIntoListTree.
49
50   if(fChildren.empty() && fNode->GetVolume()->GetNdaughters() > 0) {
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   }
58   return RenderElement::ExpandIntoListTree(ltree, parent);
59 }
60
61 /**************************************************************************/
62
63 void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr)
64 {
65   RenderElement::SetRnrSelf(rnr);
66   fNode->SetVisibility(rnr);
67 }
68
69 void GeoNodeRnrEl::SetRnrChildren(Bool_t rnr)
70 {
71   RenderElement::SetRnrChildren(rnr);
72   fNode->VisibleDaughters(rnr);
73 }
74
75 void GeoNodeRnrEl::SetRnrState(Bool_t rnr)
76 {
77   RenderElement::SetRnrState(rnr);
78   fNode->SetVisibility(rnr);
79   fNode->VisibleDaughters(rnr);
80 }
81
82 /**************************************************************************/
83
84 void GeoNodeRnrEl::SetMainColor(Color_t color)
85 {
86   fNode->GetVolume()->SetLineColor(color);
87   UpdateItems();
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)
113     UpdateItems();
114
115   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
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)
135     UpdateItems();
136
137   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
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 //
155 // A wrapper over a TGeoNode, possibly displaced with a global
156 // trasformation fGlobalTrans (the matrix is owned by this class).
157 /**************************************************************************/
158
159 ClassImp(GeoTopNodeRnrEl)
160
161 GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node,
162                                  Int_t visopt, Int_t vislvl) :
163   GeoNodeRnrEl (node),
164   fManager     (manager),
165   fVisOption   (visopt),
166   fVisLevel    (vislvl)
167 {
168   fRnrSelf = true;
169 }
170
171 GeoTopNodeRnrEl::~GeoTopNodeRnrEl()
172 {}
173
174 /**************************************************************************/
175
176 void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m)
177 {
178   fGlobalTrans.SetFrom(*m);
179 }
180
181 void GeoTopNodeRnrEl::UseNodeTrans()
182 {
183   fGlobalTrans.SetFrom(*fNode->GetMatrix());
184 }
185
186 /**************************************************************************/
187
188 void GeoTopNodeRnrEl::SetVisOption(Int_t visopt)
189 {
190   fVisOption = visopt;
191   gReve->Redraw3D();
192 }
193
194 void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl)
195 {
196   fVisLevel = vislvl;
197   gReve->Redraw3D(); 
198 }
199
200 /**************************************************************************/
201
202 void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr)
203 {
204   // Revert from GeoNode to back to standard behaviour.
205   RenderElement::SetRnrSelf(rnr);
206 }
207
208 /**************************************************************************/
209
210 void GeoTopNodeRnrEl::Draw(Option_t* option)
211 {
212   AppendPad(option);
213 }
214
215 void GeoTopNodeRnrEl::Paint(Option_t* option)
216 {
217   if(fRnrSelf) {
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;
226     TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
227     if(vgp != 0) {
228 #if ROOT_VERSION_CODE > ROOT_VERSION(5,11,6)
229       TGeoHMatrix geomat;
230       fGlobalTrans.SetGeoHMatrix(geomat);
231       vgp->PaintNode(fNode, option, &geomat);
232 #else
233       vgp->PaintNode(fNode, option);
234 #endif
235     }
236     fManager->SetTopVolume(top_volume);
237   }
238 }
239
240 /**************************************************************************/
241
242 void 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
249 void 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
256 void 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 }
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
272 ClassImp(GeoShapeRnrEl)
273
274 GeoShapeRnrEl::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
282 GeoShapeRnrEl::~GeoShapeRnrEl()
283 {
284   if (fShape) {
285     fShape->SetUniqueID(fShape->GetUniqueID() - 1);
286     if (fShape->GetUniqueID() == 0)
287       delete fShape;
288   }
289 }
290
291 /**************************************************************************/
292
293 void GeoShapeRnrEl::Paint(Option_t* /*option*/)
294 {
295   if (fShape == 0)
296     return;
297
298   TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
299     (TBuffer3D::kCore, false);
300
301   buff.fID           = this;
302   buff.fColor        = fColor;
303   buff.fTransparency = fTransparency;
304   fHMTrans.SetBuffer3D(buff);
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
321 Int_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
331 Int_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());
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 }