]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/GeoNode.cxx
Getting rid of effC++ warnings about missing copy constructor and assignment operator.
[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   fGlobalTrans (),
165   fManager     (manager),
166   fVisOption   (visopt),
167   fVisLevel    (vislvl)
168 {
169   fRnrSelf = true;
170 }
171
172 GeoTopNodeRnrEl::~GeoTopNodeRnrEl()
173 {}
174
175 /**************************************************************************/
176
177 void GeoTopNodeRnrEl::SetGlobalTrans(const TGeoHMatrix* m)
178 {
179   fGlobalTrans.SetFrom(*m);
180 }
181
182 void GeoTopNodeRnrEl::UseNodeTrans()
183 {
184   fGlobalTrans.SetFrom(*fNode->GetMatrix());
185 }
186
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
203 void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr)
204 {
205   // Revert from GeoNode to back to standard behaviour.
206   RenderElement::SetRnrSelf(rnr);
207 }
208
209 /**************************************************************************/
210
211 void GeoTopNodeRnrEl::Draw(Option_t* option)
212 {
213   AppendPad(option);
214 }
215
216 void GeoTopNodeRnrEl::Paint(Option_t* option)
217 {
218   if(fRnrSelf) {
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;
227     TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
228     if(vgp != 0) {
229 #if ROOT_VERSION_CODE > ROOT_VERSION(5,11,6)
230       TGeoHMatrix geomat;
231       fGlobalTrans.SetGeoHMatrix(geomat);
232       vgp->PaintNode(fNode, option, &geomat);
233 #else
234       vgp->PaintNode(fNode, option);
235 #endif
236     }
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 }
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),
278   fHMTrans      (),
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
303   buff.fID           = this;
304   buff.fColor        = fColor;
305   buff.fTransparency = fTransparency;
306   fHMTrans.SetBuffer3D(buff);
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());
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 }