Salome HOME
Copyright update 2022
[modules/gui.git] / src / DDS / DDS_DicGroup.cxx
index 1d7d736f1cea860a4eccb07f1dbc16c606e8a85f..25369418f9335d59c3c0afe78bf9d70c7a78d77b 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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, 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
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "DDS_DicGroup.h"
 
 #include "DDS_Dictionary.h"
@@ -31,8 +32,7 @@
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx>
 
-IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared)
-IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
+IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, Standard_Transient)
 
 /*!
   \class DDS_DicGroup
@@ -47,7 +47,7 @@ IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
   \param name group name
 */
 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
-: MMgt_TShared(),
+: Standard_Transient(),
   myName( name ),
   myActiveSystem( UNIT_SYSTEM_SI )
 {
@@ -57,6 +57,7 @@ DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
   \brief Copy constructor (put in private section to prevent object copying).
 */
 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
+: Standard_Transient()
 {
 }
 
@@ -181,17 +182,17 @@ void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM
 
     // 1. Attributes (id,label,units?,format?,required?)
     TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
-    Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
+    Handle(DDS_DicItem) aDicItem = CreateItem();
 
     aDicItem->myComponent = this;
     aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
     myDataMap.Add( anID, aDicItem );
-
+    
     bool exist = false;
     for( int i=1, n=myKeys.Length(); i<=n && !exist; i++ )
       if( myKeys.Value( i )==anID )
       {
-        cout << "Doubled key:" << anID << endl;
+        std::cout << "Doubled key:" << anID << std::endl;
         exist = true;
       }
     if( !exist )
@@ -207,7 +208,7 @@ void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM
   \param theID item identifier
   \return dictionary item
 */
-Handle_DDS_DicItem DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
+Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
 {
   Handle(DDS_DicItem) aDicItem;
   // get dictionary item by id
@@ -225,3 +226,67 @@ void DDS_DicGroup::GetKeys( TColStd_SequenceOfAsciiString& seq ) const
 {
   seq = myKeys;
 }
+
+/*!
+  \brief Instantiate new dictionary item, used for customization of
+         data dictionary items.
+  \return New dictionary item instance.
+*/
+Handle(DDS_DicItem) DDS_DicGroup::CreateItem() const
+{
+  return new DDS_DicItem();
+}
+
+/*!
+  \brief Bind dictionary item to ID
+  \return Standard_True if the item has been succesfully bound.
+          Standard_False if there is an item with same id.
+*/
+Standard_Boolean DDS_DicGroup::AddDicItem( const TCollection_AsciiString& theID,
+                                           const Handle(DDS_DicItem)& theDicItem )
+{
+  if ( myDataMap.Contains( theID ) )
+    return Standard_False;
+
+  myDataMap.Add( theID, theDicItem );
+  myKeys.Append( theID );
+
+  return Standard_True;
+}
+
+/*!
+  \brief Check if there is item bounded by id.
+  \return Standard_True if there is an item bound in map with given id.
+*/
+Standard_Boolean DDS_DicGroup::HasDicItem( const TCollection_AsciiString& theID ) const 
+{
+  return myDataMap.Contains( theID );
+}
+
+/*!
+  \brief Clear dictionary items map
+*/
+void DDS_DicGroup::RemoveAllDicItems() 
+{
+  myDataMap.Clear();
+  myKeys.Clear();
+}
+
+/*!
+  \brief Returns a reference to a map. Can be used to iterate through
+         dictionary items.
+*/
+const DDS_IndexedDataMapOfDicItems& DDS_DicGroup::GetItemMap() const
+{
+  return myDataMap;
+}
+
+/*!
+  \brief Add new unit system and bind its label name.
+  \return Standard_False if there is other system bound by this key.
+*/
+Standard_Boolean DDS_DicGroup::AddUnitSystem( const TCollection_AsciiString& theSystemKey,
+                                              const TCollection_ExtendedString& theSystemLabel )
+{
+  return myUnitSystem.Bind( theSystemKey, theSystemLabel );
+}