1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "DDS_DicGroup.h"
25 #include "DDS_Dictionary.h"
27 #include <LDOMString.hxx>
28 #include <LDOM_Element.hxx>
30 #include <UnitsAPI.hxx>
32 #include <Standard_Failure.hxx>
33 #include <Standard_ErrorHandler.hxx>
35 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, Standard_Transient)
39 \brief This class provides a set of DDS_DicItem objects from one component.
45 Create the group with name \a name.
47 \param name group name
49 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
50 : Standard_Transient(),
52 myActiveSystem( UNIT_SYSTEM_SI )
57 \brief Copy constructor (put in private section to prevent object copying).
59 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
60 : Standard_Transient()
65 \brief Get the name of group (component).
68 TCollection_AsciiString DDS_DicGroup::GetName() const
74 \brief Get the names of all defined units systems.
75 \param theSystemsSeq returning sequence of names
77 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
80 for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
82 if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
83 theSystemSeq.Prepend( it.Key() );
85 theSystemSeq.Append( it.Key() );
90 \brief Get the label of units system \a name.
92 If units system is not found, empty string is returned.
94 \param make units system name
95 \return units system label
97 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
99 TCollection_ExtendedString aLabel;
100 if ( myUnitSystem.IsBound( name ) )
101 aLabel = myUnitSystem.Find( name );
106 \brief Get the name of active units system.
107 \return active units system name
109 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
111 return myActiveSystem;
115 \brief Set the active unit system.
116 \param theSystem name of the units system to be made active
118 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
120 if ( myUnitSystem.IsBound( theSystem ) )
121 myActiveSystem = theSystem;
125 \brief Assignment operator (put in private section to prevent object copying).
127 void DDS_DicGroup::operator=( const DDS_DicGroup& )
132 \brief Fill the internal data structures from XML parsed structures.
133 \param theComponentData component data DOM node
134 \param theDocElement document element DOM node
136 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
138 TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
140 LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
141 if ( !systems.isNull() )
143 LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
144 for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
146 //const LDOM_Element& aSystem = (const LDOM_Element &)systemList.item( i );
147 LDOM_Node aNode = systemList.item( i );
148 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
149 LDOM_Element aSystem(anElem);
150 TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
151 TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
153 if ( aName.IsEmpty() )
156 if ( !myUnitSystem.IsBound( aName ) )
157 myUnitSystem.Bind( aName, aLabel );
163 if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
165 printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
166 myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
169 TColStd_SequenceOfAsciiString unitSystems;
170 GetUnitSystems( unitSystems );
172 LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
173 if ( !aData.getLength() )
176 for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
178 //LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
179 LDOM_Node aNode = aData.item( i );
180 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
181 LDOM_Element aQuantity(anElem);
183 // 1. Attributes (id,label,units?,format?,required?)
184 TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
185 Handle(DDS_DicItem) aDicItem = CreateItem();
187 aDicItem->myComponent = this;
188 aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
189 myDataMap.Add( anID, aDicItem );
192 for( int i=1, n=myKeys.Length(); i<=n && !exist; i++ )
193 if( myKeys.Value( i )==anID )
195 std::cout << "Doubled key:" << anID << std::endl;
199 myKeys.Append( anID );
204 \brief Get the dictionary item with specified identifier \a theID.
206 If dictionary item is not found, null handle is returned.
208 \param theID item identifier
209 \return dictionary item
211 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
213 Handle(DDS_DicItem) aDicItem;
214 // get dictionary item by id
215 if ( myDataMap.Contains( theID ) )
216 aDicItem = myDataMap.FindFromKey( theID );
222 \brief Return all keys of the group
223 \param seq - string container to be filled with keys
225 void DDS_DicGroup::GetKeys( TColStd_SequenceOfAsciiString& seq ) const
231 \brief Instantiate new dictionary item, used for customization of
232 data dictionary items.
233 \return New dictionary item instance.
235 Handle(DDS_DicItem) DDS_DicGroup::CreateItem() const
237 return new DDS_DicItem();
241 \brief Bind dictionary item to ID
242 \return Standard_True if the item has been succesfully bound.
243 Standard_False if there is an item with same id.
245 Standard_Boolean DDS_DicGroup::AddDicItem( const TCollection_AsciiString& theID,
246 const Handle(DDS_DicItem)& theDicItem )
248 if ( myDataMap.Contains( theID ) )
249 return Standard_False;
251 myDataMap.Add( theID, theDicItem );
252 myKeys.Append( theID );
254 return Standard_True;
258 \brief Check if there is item bounded by id.
259 \return Standard_True if there is an item bound in map with given id.
261 Standard_Boolean DDS_DicGroup::HasDicItem( const TCollection_AsciiString& theID ) const
263 return myDataMap.Contains( theID );
267 \brief Clear dictionary items map
269 void DDS_DicGroup::RemoveAllDicItems()
276 \brief Returns a reference to a map. Can be used to iterate through
279 const DDS_IndexedDataMapOfDicItems& DDS_DicGroup::GetItemMap() const
285 \brief Add new unit system and bind its label name.
286 \return Standard_False if there is other system bound by this key.
288 Standard_Boolean DDS_DicGroup::AddUnitSystem( const TCollection_AsciiString& theSystemKey,
289 const TCollection_ExtendedString& theSystemLabel )
291 return myUnitSystem.Bind( theSystemKey, theSystemLabel );