]>
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 | ||
7d42b6c2 | 63 | void GeoNodeRnrEl::UpdateItems() |
5a5a1232 | 64 | { |
5b457dfa | 65 | fRnrSelf = fNode->TGeoAtt::IsVisible(); |
66 | RenderElement::UpdateItems(); | |
5a5a1232 | 67 | } |
68 | ||
69 | /**************************************************************************/ | |
70 | ||
5b457dfa | 71 | void GeoNodeRnrEl::SetRnrSelf(Bool_t rnr) |
5a5a1232 | 72 | { |
73 | fNode->SetVisibility(rnr); | |
7d42b6c2 | 74 | UpdateItems(); |
5a5a1232 | 75 | } |
76 | ||
77 | /**************************************************************************/ | |
78 | ||
79 | void GeoNodeRnrEl::SetMainColor(Color_t color) | |
80 | { | |
81 | fNode->GetVolume()->SetLineColor(color); | |
7d42b6c2 | 82 | UpdateItems(); |
5a5a1232 | 83 | } |
84 | ||
85 | void GeoNodeRnrEl::SetMainColor(Pixel_t pixel) | |
86 | { | |
87 | // This one needed for proper calling via CINT (signals). | |
88 | ||
89 | SetMainColor(Color_t(TColor::GetColor(pixel))); | |
90 | } | |
91 | ||
92 | /**************************************************************************/ | |
93 | ||
94 | void GeoNodeRnrEl::UpdateNode(TGeoNode* node) | |
95 | { | |
96 | // Updates all reve-browsers having the node in their contents. | |
97 | // All 3D-pads updated if any change found. | |
98 | // | |
99 | // Should (could?) be optimized with some assumptions about | |
100 | // volume/node structure (search for parent, know the same node can not | |
101 | // reoccur on lower level once found). | |
102 | ||
103 | static const Exc_t eH("GeoNodeRnrEl::UpdateNode "); | |
104 | ||
105 | // printf("%s node %s %p\n", eH.Data(), node->GetName(), node); | |
106 | ||
107 | if(fNode == node) | |
7d42b6c2 | 108 | UpdateItems(); |
5a5a1232 | 109 | |
e6ac3950 | 110 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 111 | ((GeoNodeRnrEl*)(*i))->UpdateNode(node); |
112 | } | |
113 | ||
114 | } | |
115 | ||
116 | void GeoNodeRnrEl::UpdateVolume(TGeoVolume* volume) | |
117 | { | |
118 | // Updates all reve-browsers having the volume in their contents. | |
119 | // All 3D-pads updated if any change found. | |
120 | // | |
121 | // Should (could?) be optimized with some assumptions about | |
122 | // volume/node structure (search for parent, know the same node can not | |
123 | // reoccur on lower level once found). | |
124 | ||
125 | static const Exc_t eH("GeoNodeRnrEl::UpdateVolume "); | |
126 | ||
127 | // printf("%s volume %s %p\n", eH.Data(), volume->GetName(), volume); | |
128 | ||
129 | if(fNode->GetVolume() == volume) | |
7d42b6c2 | 130 | UpdateItems(); |
5a5a1232 | 131 | |
e6ac3950 | 132 | for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) { |
5a5a1232 | 133 | ((GeoNodeRnrEl*)(*i))->UpdateVolume(volume); |
134 | } | |
135 | } | |
136 | ||
137 | /**************************************************************************/ | |
138 | ||
139 | void GeoNodeRnrEl::Draw(Option_t* option) | |
140 | { | |
141 | TString opt("SAME"); | |
142 | opt += option; | |
143 | fNode->GetVolume()->Draw(opt); | |
144 | } | |
145 | ||
146 | /**************************************************************************/ | |
147 | //______________________________________________________________________ | |
148 | // GeoTopNodeRnrEl | |
149 | // | |
24e2ff4a | 150 | // A wrapper over a TGeoNode, possibly displaced with a global |
151 | // trasformation fGlobalTrans (the matrix is owned by this class). | |
5a5a1232 | 152 | /**************************************************************************/ |
153 | ||
154 | ClassImp(GeoTopNodeRnrEl) | |
155 | ||
156 | GeoTopNodeRnrEl::GeoTopNodeRnrEl(TGeoManager* manager, TGeoNode* node, | |
157 | Int_t visopt, Int_t vislvl) : | |
158 | GeoNodeRnrEl(node), | |
159 | fManager(manager), | |
24e2ff4a | 160 | fGlobalTrans(0), |
161 | fUseNodeTrans(kFALSE), | |
5a5a1232 | 162 | fVisOption(visopt), fVisLevel(vislvl) |
163 | { | |
5b457dfa | 164 | fRnrSelf = true; |
5a5a1232 | 165 | } |
166 | ||
24e2ff4a | 167 | GeoTopNodeRnrEl::~GeoTopNodeRnrEl() |
168 | { | |
169 | delete fGlobalTrans; | |
170 | } | |
171 | ||
172 | /**************************************************************************/ | |
173 | ||
174 | void GeoTopNodeRnrEl::SetGlobalTrans(TGeoHMatrix* m) | |
175 | { | |
176 | delete fGlobalTrans; | |
177 | fGlobalTrans = m; | |
178 | } | |
179 | ||
180 | void GeoTopNodeRnrEl::SetUseNodeTrans(Bool_t u) | |
181 | { | |
182 | fUseNodeTrans = u; | |
183 | } | |
184 | ||
5a5a1232 | 185 | /**************************************************************************/ |
186 | ||
187 | void GeoTopNodeRnrEl::SetVisOption(Int_t visopt) | |
188 | { | |
189 | fVisOption = visopt; | |
190 | gReve->Redraw3D(); | |
191 | } | |
192 | ||
193 | void GeoTopNodeRnrEl::SetVisLevel(Int_t vislvl) | |
194 | { | |
195 | fVisLevel = vislvl; | |
196 | gReve->Redraw3D(); | |
197 | } | |
198 | ||
199 | /**************************************************************************/ | |
200 | ||
7d42b6c2 | 201 | void GeoTopNodeRnrEl::UpdateItems() |
5a5a1232 | 202 | { |
5b457dfa | 203 | RenderElement::UpdateItems(); |
5a5a1232 | 204 | } |
205 | ||
206 | /**************************************************************************/ | |
5b457dfa | 207 | void GeoTopNodeRnrEl::SetRnrSelf(Bool_t rnr) |
5a5a1232 | 208 | { |
209 | // Revert from GeoNode to back to standard behaviour. | |
5b457dfa | 210 | RenderElement::SetRnrSelf(rnr); |
5a5a1232 | 211 | } |
5a5a1232 | 212 | /**************************************************************************/ |
213 | ||
214 | void GeoTopNodeRnrEl::Draw(Option_t* option) | |
215 | { | |
216 | AppendPad(option); | |
217 | } | |
218 | ||
219 | void GeoTopNodeRnrEl::Paint(Option_t* option) | |
220 | { | |
5b457dfa | 221 | if(fRnrSelf) { |
5a5a1232 | 222 | gGeoManager = fManager; |
223 | TVirtualPad* pad = gPad; | |
224 | gPad = 0; | |
225 | TGeoVolume* top_volume = fManager->GetTopVolume(); | |
226 | fManager->SetVisOption(fVisOption); | |
227 | fManager->SetVisLevel(fVisLevel); | |
228 | fManager->SetTopVolume(fNode->GetVolume()); | |
229 | gPad = pad; | |
24e2ff4a | 230 | TVirtualGeoPainter* vgp = fManager->GetGeomPainter(); |
231 | if(vgp != 0) { | |
7d42b6c2 | 232 | #if ROOT_VERSION_CODE > ROOT_VERSION(5,11,6) |
24e2ff4a | 233 | vgp->PaintNode(fNode, option, fUseNodeTrans ? fNode->GetMatrix() : fGlobalTrans); |
234 | #else | |
235 | vgp->PaintNode(fNode, option); | |
236 | #endif | |
237 | } | |
5a5a1232 | 238 | fManager->SetTopVolume(top_volume); |
239 | } | |
240 | } | |
241 | ||
242 | /**************************************************************************/ | |
243 | ||
244 | void GeoTopNodeRnrEl::VolumeVisChanged(TGeoVolume* volume) | |
245 | { | |
246 | static const Exc_t eH("GeoTopNodeRnrEl::VolumeVisChanged "); | |
247 | printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume); | |
248 | UpdateVolume(volume); | |
249 | } | |
250 | ||
251 | void GeoTopNodeRnrEl::VolumeColChanged(TGeoVolume* volume) | |
252 | { | |
253 | static const Exc_t eH("GeoTopNodeRnrEl::VolumeColChanged "); | |
254 | printf("%s volume %s %p\n", eH.Data(), volume->GetName(), (void*)volume); | |
255 | UpdateVolume(volume); | |
256 | } | |
257 | ||
258 | void GeoTopNodeRnrEl::NodeVisChanged(TGeoNode* node) | |
259 | { | |
260 | static const Exc_t eH("GeoTopNodeRnrEl::NodeVisChanged "); | |
261 | printf("%s node %s %p\n", eH.Data(), node->GetName(), (void*)node); | |
262 | UpdateNode(node); | |
263 | } | |
5b3adb7e | 264 | |
265 | ||
266 | /**************************************************************************/ | |
267 | //______________________________________________________________________ | |
268 | // GeoShapeRnrEl | |
269 | // | |
270 | // Minimal shape-wrapper allowing import of stuff from gled and retaining | |
271 | // user-set visibility, colors and transparency. | |
272 | /**************************************************************************/ | |
273 | ||
274 | ClassImp(GeoShapeRnrEl) | |
275 | ||
276 | GeoShapeRnrEl::GeoShapeRnrEl(const Text_t* name, const Text_t* title) : | |
277 | RenderElement (fColor), | |
278 | TNamed (name, title), | |
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.fLocalFrame = true; | |
304 | buff.fID = this; | |
305 | buff.fColor = fColor; | |
306 | buff.fTransparency = fTransparency; | |
307 | memcpy(buff.fLocalMaster, fHMTrans.Array(), 16*sizeof(Double_t)); | |
308 | ||
309 | fShape->GetBuffer3D(TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific, true); | |
310 | ||
311 | Int_t reqSec = gPad->GetViewer3D()->AddObject(buff); | |
312 | ||
313 | if (reqSec != TBuffer3D::kNone) { | |
314 | fShape->GetBuffer3D(reqSec, true); | |
315 | reqSec = gPad->GetViewer3D()->AddObject(buff); | |
316 | } | |
317 | ||
318 | if (reqSec != TBuffer3D::kNone) | |
319 | printf("spooky reqSec=%d for %s\n", reqSec, GetName()); | |
320 | } | |
321 | ||
322 | /**************************************************************************/ | |
323 | ||
324 | Int_t GeoShapeRnrEl::ImportShapeExtract(TGeoShapeExtract * gse, | |
325 | RenderElement * parent) | |
326 | { | |
327 | gReve->DisableRedraw(); | |
328 | Int_t n = SubImportShapeExtract(gse, parent); | |
329 | printf ("GeoShapeRnrEl::ImportShapeExtract imported %d elements\n", n); | |
330 | gReve->EnableRedraw(); | |
331 | return n; | |
332 | } | |
333 | ||
334 | Int_t GeoShapeRnrEl::SubImportShapeExtract(TGeoShapeExtract * gse, | |
335 | RenderElement * parent) | |
336 | { | |
337 | Int_t ncreated = 1; | |
338 | ||
339 | GeoShapeRnrEl* gsre = new GeoShapeRnrEl(gse->GetName(), gse->GetTitle()); | |
340 | gsre->fHMTrans.SetFromArray(gse->GetTrans()); | |
341 | gsre->fHMTrans.TransposeRotationPart(); // Transpose from gled-to-tgeo. | |
342 | const Float_t* rgba = gse->GetRGBA(); | |
343 | gsre->fColor = TColor::GetColor(rgba[0], rgba[1], rgba[2]); | |
344 | gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3])); | |
345 | gsre->SetRnrSelf(gse->GetRnrSelf()); | |
346 | gsre->SetRnrChildren(gse->GetRnrElements()); | |
347 | gsre->fShape = gse->GetShape(); | |
348 | if (gsre->fShape) | |
349 | gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1); | |
350 | ||
351 | if (parent) | |
352 | gReve->AddGlobalRenderElement(parent, gsre); | |
353 | else | |
354 | gReve->AddGlobalRenderElement(gsre); | |
355 | ||
356 | if (gse->HasElements()) | |
357 | { | |
358 | TIter next(gse->GetElements()); | |
359 | TGeoShapeExtract* chld; | |
360 | while ((chld = (TGeoShapeExtract*) next()) != 0) | |
361 | ncreated += SubImportShapeExtract(chld, gsre); | |
362 | } | |
363 | ||
364 | return ncreated; | |
365 | } |