Salome HOME
Copyright update 2020
[modules/gui.git] / src / DDS / DDS_Dictionary.cxx
index 28c309574dc5435aabef61e3e453f00ea96be51c..7ff1ee53c63046933ea8657b1e02deafc9c140fb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,8 +24,6 @@
 
 #include "DDS_KeyWords.h"
 
-#include <Basics_OCCTVersion.hxx>
-
 #include <LDOMString.hxx>
 #include <LDOMParser.hxx>
 
@@ -40,8 +38,9 @@
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx>
 
-IMPLEMENT_STANDARD_HANDLE(DDS_Dictionary, MMgt_TShared)
-IMPLEMENT_STANDARD_RTTIEXT(DDS_Dictionary, MMgt_TShared)
+IMPLEMENT_STANDARD_RTTIEXT(DDS_Dictionary, Standard_Transient)
+
+Handle(DDS_Dictionary) DDS_Dictionary::myDictionary = Handle(DDS_Dictionary)();
 
 /*!
   \class DDS_Dictionary
@@ -260,7 +259,7 @@ IMPLEMENT_STANDARD_RTTIEXT(DDS_Dictionary, MMgt_TShared)
   Use Get() method instead.
 */
 DDS_Dictionary::DDS_Dictionary()
-: MMgt_TShared()
+: Standard_Transient()
 {
 }
 
@@ -423,14 +422,12 @@ void DDS_Dictionary::SetActiveUnitSystem( const TCollection_AsciiString& theSyst
   \brief Get the only instance of the data dictionary.
   \return the only instance of the data dictionary
 */
-Handle_DDS_Dictionary DDS_Dictionary::Get()
+Handle(DDS_Dictionary) DDS_Dictionary::Get()
 {
-  static Handle(DDS_Dictionary) sDictionary;
-
-  if ( sDictionary.IsNull() )
-    sDictionary = new DDS_Dictionary();
+  if ( myDictionary.IsNull() )
+    myDictionary = new DDS_Dictionary();
 
-  return sDictionary;
+  return myDictionary;
 }
 
 /*!
@@ -456,9 +453,8 @@ Standard_Boolean DDS_Dictionary::Load( const TCollection_AsciiString theFileName
 
   LDOM_Document aDoc = aParser.getDocument();
   LDOM_Element aDocElement = aDoc.getDocumentElement();
-  for ( LDOM_Element aComponentElem = aDocElement.GetChildByTagName( KeyWord( "COMPONENT" ) );
-        !aComponentElem.isNull(); aComponentElem = aComponentElem.GetSiblingByTagName() )
-    aDic->FillDataMap( aComponentElem, aDocElement );
+  if ( !aDocElement.isNull() )
+    aDic->FillDataMap( aDocElement );
 
   _LoadMap.Add( theFileName );
 
@@ -496,7 +492,7 @@ LDOMString DDS_Dictionary::KeyWord( const TCollection_AsciiString& key )
   \param theComponent component name
   \return handle to the data dictionary item
 */
-Handle_DDS_DicItem DDS_Dictionary::GetDicItem( const TCollection_AsciiString& theID,
+Handle(DDS_DicItem) DDS_Dictionary::GetDicItem( const TCollection_AsciiString& theID,
                                                 const TCollection_AsciiString& theComponent ) const
 {
   Handle(DDS_DicItem) aDicItem;
@@ -517,7 +513,7 @@ Handle_DDS_DicItem DDS_Dictionary::GetDicItem( const TCollection_AsciiString& th
   \param theID data dictionary item ID
   \return handle to the data dictionary item
 */
-Handle_DDS_DicItem DDS_Dictionary::GetDicItem( const TCollection_AsciiString& theID ) const
+Handle(DDS_DicItem) DDS_Dictionary::GetDicItem( const TCollection_AsciiString& theID ) const
 {
   Handle(DDS_DicItem) aDicItem;
   for ( Standard_Integer i = 1; i <= myGroupMap.Extent() && aDicItem.IsNull(); i++ )
@@ -527,17 +523,20 @@ Handle_DDS_DicItem DDS_Dictionary::GetDicItem( const TCollection_AsciiString& th
 
 /*!
   \brief Fill the internal data structures from the XML node.
-  \param theComponentData component XML node
   \param theDocElement document XML node
 */
-void DDS_Dictionary::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
+void DDS_Dictionary::FillDataMap( const LDOM_Element& theDocElement )
 {
-  TCollection_AsciiString aCompName = theComponentData.getAttribute( KeyWord( "COMPONENT_NAME" ) );
-  if ( !myGroupMap.Contains( aCompName ) )
-    myGroupMap.Add( aCompName, new DDS_DicGroup( aCompName ) );
-  Handle(DDS_DicGroup) aDicGroup = myGroupMap.FindFromKey( aCompName );
-  aDicGroup->FillDataMap( theComponentData, theDocElement );
-  myGroupMap.Add( aCompName, aDicGroup );
+  for ( LDOM_Element aComponentElem = theDocElement.GetChildByTagName( KeyWord( "COMPONENT" ) );
+        !aComponentElem.isNull(); aComponentElem = aComponentElem.GetSiblingByTagName() )
+  {
+    TCollection_AsciiString aCompName = aComponentElem.getAttribute( KeyWord( "COMPONENT_NAME" ) );
+    if ( !myGroupMap.Contains( aCompName ) )
+      myGroupMap.Add( aCompName, CreateGroup( aCompName ) );
+    Handle(DDS_DicGroup) aDicGroup = myGroupMap.FindFromKey( aCompName );
+    aDicGroup->FillDataMap( aComponentElem, theDocElement );
+    myGroupMap.Add( aCompName, aDicGroup );
+  }
 }
 
 /*!
@@ -553,9 +552,7 @@ Standard_Real DDS_Dictionary::ToSI( const Standard_Real theValue, const Standard
   if ( theUnits && *theUnits && strcmp( theUnits, "%" ) )
   {
     try {
-#if OCC_VERSION_LARGE > 0x06010000
       OCC_CATCH_SIGNALS;
-#endif
       aRetValue = UnitsAPI::AnyToSI( theValue, theUnits );
     }
     catch( Standard_Failure ) {
@@ -580,9 +577,7 @@ Standard_Real DDS_Dictionary::FromSI( const Standard_Real theValue, const Standa
   if ( theUnits && *theUnits && strcmp( theUnits, "%" ) )
   {
     try {
-#if OCC_VERSION_LARGE > 0x06010000
       OCC_CATCH_SIGNALS;
-#endif
       aRetValue = UnitsAPI::AnyFromSI( theValue, theUnits );
     }
     catch( Standard_Failure ) {
@@ -608,3 +603,25 @@ void DDS_Dictionary::GetKeys( const TCollection_AsciiString& theComponent, TColS
   if( !aDicGroup.IsNull() )
     aDicGroup->GetKeys( seq );
 }
+
+/*!
+  \brief  Create instance of a dictionary group. This method can
+          be used for customization data dictionary by specific
+          groups design.
+  \return New dictionary group instance.
+*/
+Handle(DDS_DicGroup) DDS_Dictionary::CreateGroup( const TCollection_AsciiString& theCompName ) const
+{
+  return new DDS_DicGroup( theCompName );
+}
+
+/*!
+  \brief Set instance of dictionary. This method might be used in descendant classes to initialize
+         custom dictionary and replace the default implementation.
+         This method overrides static handle on dictionary that is available
+         through Get() method
+*/
+void DDS_Dictionary::SetDictionary( const Handle(DDS_Dictionary)& theDict )
+{
+  myDictionary = theDict; 
+}