]> OCCT Git - occt.git/commitdiff
0033232: Data Exchange, DE_Wrapper - Implement ability to change global session
authordpasukhi <dpasukhi@opencascade.com>
Tue, 29 Nov 2022 15:43:56 +0000 (15:43 +0000)
committersmoskvin <smoskvin@opencascade.com>
Sun, 4 Dec 2022 10:46:38 +0000 (13:46 +0300)
Add ability to set/get global session

src/DE/DE_Wrapper.cxx
src/DE/DE_Wrapper.hxx

index 33bbfc8f9dc2c9bb135cc515df08886a97fabf99..b22c5b7d8074e53db233b72b51aea4c2aa2f2b13 100644 (file)
@@ -34,6 +34,9 @@ namespace
     static const TCollection_AsciiString aScope ("global");
     return aScope;
   }
+
+  //! Global configuration of current DE Session
+  static Handle(DE_Wrapper) THE_GLOBAL_CONFIGURATION;
 }
 
 //=======================================================================
@@ -72,8 +75,23 @@ DE_Wrapper::DE_Wrapper(const Handle(DE_Wrapper)& theWrapper)
 //=======================================================================
 Handle(DE_Wrapper) DE_Wrapper::GlobalWrapper()
 {
-  static const Handle(DE_Wrapper)& aConfiguration = new DE_Wrapper();
-  return aConfiguration;
+  if (THE_GLOBAL_CONFIGURATION.IsNull())
+  {
+    THE_GLOBAL_CONFIGURATION = new DE_Wrapper();
+  }
+  return THE_GLOBAL_CONFIGURATION;
+}
+
+//=======================================================================
+// function : SetGlobalWrapper
+// purpose  :
+//=======================================================================
+void DE_Wrapper::SetGlobalWrapper(const Handle(DE_Wrapper)& theWrapper)
+{
+  if (!theWrapper.IsNull())
+  {
+    THE_GLOBAL_CONFIGURATION = theWrapper;
+  }
 }
 
 //=======================================================================
index de57c830515cc502488cfcac111ff2c609fc6d78..98587aa7d588644af1f5280f949625cc32d05d8d 100644 (file)
@@ -61,10 +61,15 @@ public:
   //! @param[in] theWrapper object to copy
   Standard_EXPORT DE_Wrapper(const Handle(DE_Wrapper)& theWrapper);
 
-  //! Gets global configuration singleton
+  //! Gets global configuration singleton.
+  //! If wrapper is not set, create it by default as base class object.
   //! @return point to global configuration
   Standard_EXPORT static Handle(DE_Wrapper) GlobalWrapper();
 
+  //! Sets global configuration singleton
+  //! @param[in] theWrapper object to set as global configuration
+  Standard_EXPORT static void SetGlobalWrapper(const Handle(DE_Wrapper)& theWrapper);
+
 public:
 
   //! Reads a CAD file, according internal configuration
@@ -227,7 +232,7 @@ public:
 
   //! Copies values of all fields
   //! @return new object with the same field values
-  Standard_EXPORT Handle(DE_Wrapper) Copy() const;
+  Standard_EXPORT virtual Handle(DE_Wrapper) Copy() const;
 
 protected: