From e3dcb9db4ffac4d1babeb95ab02a6deec827ba21 Mon Sep 17 00:00:00 2001
From: Matevz Tadel <matevz.tadel@cern.ch>
Date: Wed, 7 May 2008 18:20:21 +0000
Subject: [PATCH] TEveManager::GetGeometry() - if TGeoManager is locked, unlock
 it on load time and re-lock it back afterwards.

TEveGeoShape - added method SetShape() so that full object can be
constructed also in program (required loading from file before).


git-svn-id: http://root.cern.ch/svn/root/trunk@23731 27541ba8-7e3a-0410-8455-c3a389f83636
---
 graf3d/eve/inc/TEveGeoNode.h   |  7 ++++---
 graf3d/eve/src/TEveGeoNode.cxx | 16 +++++++++++++---
 graf3d/eve/src/TEveManager.cxx | 18 ++++++++++++++----
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/graf3d/eve/inc/TEveGeoNode.h b/graf3d/eve/inc/TEveGeoNode.h
index be7aee74d95..c068853d513 100644
--- a/graf3d/eve/inc/TEveGeoNode.h
+++ b/graf3d/eve/inc/TEveGeoNode.h
@@ -137,14 +137,15 @@ public:
    TEveGeoShape(const Text_t* name="TEveGeoShape", const Text_t* title=0);
    virtual ~TEveGeoShape();
 
-   virtual Bool_t CanEditMainColor() const { return kTRUE; }
+   virtual Bool_t  CanEditMainColor() const { return kTRUE; }
 
    virtual Bool_t  CanEditMainTransparency() const { return kTRUE; }
    virtual UChar_t GetMainTransparency()     const { return fTransparency; }
    virtual void    SetMainTransparency(UChar_t t)  { fTransparency = t; }
 
-   Color_t     GetColor() const  { return fColor; }
-   TGeoShape*  GetShape()        { return fShape; }
+   Color_t     GetColor() const { return fColor; }
+   TGeoShape*  GetShape()       { return fShape; }
+   void        SetShape(TGeoShape* s);
 
    virtual void Paint(Option_t* option="");
 
diff --git a/graf3d/eve/src/TEveGeoNode.cxx b/graf3d/eve/src/TEveGeoNode.cxx
index 5a50afecd1e..1433339d443 100644
--- a/graf3d/eve/src/TEveGeoNode.cxx
+++ b/graf3d/eve/src/TEveGeoNode.cxx
@@ -476,11 +476,23 @@ TEveGeoShape::~TEveGeoShape()
 {
    // Destructor.
 
+   SetShape(0);
+}
+
+//______________________________________________________________________________
+void TEveGeoShape::SetShape(TGeoShape* s)
+{
+   // Set TGeoShape shown by this object.
+
    if (fShape) {
       fShape->SetUniqueID(fShape->GetUniqueID() - 1);
       if (fShape->GetUniqueID() == 0)
          delete fShape;
    }
+   fShape = s;
+   if (fShape) {
+      fShape->SetUniqueID(fShape->GetUniqueID() + 1);
+   }
 }
 
 /******************************************************************************/
@@ -598,9 +610,7 @@ TEveGeoShape* TEveGeoShape::SubImportShapeExtract(TEveGeoShapeExtract* gse,
    gsre->fTransparency = (UChar_t) (100.0f*(1.0f - rgba[3]));
    gsre->SetRnrSelf(gse->GetRnrSelf());
    gsre->SetRnrChildren(gse->GetRnrElements());
-   gsre->fShape = gse->GetShape();
-   if (gsre->fShape)
-      gsre->fShape->SetUniqueID(gsre->fShape->GetUniqueID() + 1);
+   gsre->SetShape(gse->GetShape());
 
    if (parent)
       parent->AddElement(gsre);
diff --git a/graf3d/eve/src/TEveManager.cxx b/graf3d/eve/src/TEveManager.cxx
index d53862ac343..58df24c2fdb 100644
--- a/graf3d/eve/src/TEveManager.cxx
+++ b/graf3d/eve/src/TEveManager.cxx
@@ -481,6 +481,7 @@ TGeoManager* TEveManager::GetGeometry(const TString& filename)
    // Get geometry with given filename.
    // This is cached internally so the second time this function is
    // called with the same argument the same geo-manager is returned.
+   // gGeoManager is set to the return value.
 
    static const TEveException eh("TEveManager::GetGeometry ");
 
@@ -491,11 +492,20 @@ TGeoManager* TEveManager::GetGeometry(const TString& filename)
 
    std::map<TString, TGeoManager*>::iterator geom = fGeometries.find(filename);
    if (geom != fGeometries.end()) {
-      return geom->second;
+      gGeoManager = geom->second;
    } else {
       gGeoManager = 0;
-      if (TGeoManager::Import(filename) == 0)
-         throw(eh + "GeoManager::Import() failed for '" + exp_filename + "'.");
+      Bool_t locked = TGeoManager::IsLocked();
+      if (locked) {
+         Warning(eh, "TGeoManager is locked ... unlocking it.");
+         TGeoManager::UnlockGeometry();
+      }
+      if (TGeoManager::Import(filename) == 0) {
+         throw(eh + "TGeoManager::Import() failed for '" + exp_filename + "'.");
+      }
+      if (locked) {
+         TGeoManager::LockGeometry();
+      }
 
       gGeoManager->GetTopVolume()->VisibleDaughters(1);
 
@@ -520,8 +530,8 @@ TGeoManager* TEveManager::GetGeometry(const TString& filename)
       }
 
       fGeometries[filename] = gGeoManager;
-      return gGeoManager;
    }
+   return gGeoManager;
 }
 
 //______________________________________________________________________________
-- 
GitLab