1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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& )
64 \brief Get the name of group (component).
67 TCollection_AsciiString DDS_DicGroup::GetName() const
73 \brief Get the names of all defined units systems.
74 \param theSystemsSeq returning sequence of names
76 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
79 for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
81 if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
82 theSystemSeq.Prepend( it.Key() );
84 theSystemSeq.Append( it.Key() );
89 \brief Get the label of units system \a name.
91 If units system is not found, empty string is returned.
93 \param make units system name
94 \return units system label
96 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
98 TCollection_ExtendedString aLabel;
99 if ( myUnitSystem.IsBound( name ) )
100 aLabel = myUnitSystem.Find( name );
105 \brief Get the name of active units system.
106 \return active units system name
108 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
110 return myActiveSystem;
114 \brief Set the active unit system.
115 \param theSystem name of the units system to be made active
117 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
119 if ( myUnitSystem.IsBound( theSystem ) )
120 myActiveSystem = theSystem;
124 \brief Assignment operator (put in private section to prevent object copying).
126 void DDS_DicGroup::operator=( const DDS_DicGroup& )
131 \brief Fill the internal data structures from XML parsed structures.
132 \param theComponentData component data DOM node
133 \param theDocElement document element DOM node
135 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
137 TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
139 LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
140 if ( !systems.isNull() )
142 LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
143 for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
145 //const LDOM_Element& aSystem = (const LDOM_Element &)systemList.item( i );
146 LDOM_Node aNode = systemList.item( i );
147 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
148 LDOM_Element aSystem(anElem);
149 TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
150 TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
152 if ( aName.IsEmpty() )
155 if ( !myUnitSystem.IsBound( aName ) )
156 myUnitSystem.Bind( aName, aLabel );
162 if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
164 printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
165 myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
168 TColStd_SequenceOfAsciiString unitSystems;
169 GetUnitSystems( unitSystems );
171 LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
172 if ( !aData.getLength() )
175 for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
177 //LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
178 LDOM_Node aNode = aData.item( i );
179 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
180 LDOM_Element aQuantity(anElem);
182 // 1. Attributes (id,label,units?,format?,required?)
183 TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
184 Handle(DDS_DicItem) aDicItem = CreateItem();
186 aDicItem->myComponent = this;
187 aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
188 myDataMap.Add( anID, aDicItem );
191 for( int i=1, n=myKeys.Length(); i<=n && !exist; i++ )
192 if( myKeys.Value( i )==anID )
194 cout << "Doubled key:" << anID << endl;
198 myKeys.Append( anID );
203 \brief Get the dictionary item with specified identifier \a theID.
205 If dictionary item is not found, null handle is returned.
207 \param theID item identifier
208 \return dictionary item
210 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
212 Handle(DDS_DicItem) aDicItem;
213 // get dictionary item by id
214 if ( myDataMap.Contains( theID ) )
215 aDicItem = myDataMap.FindFromKey( theID );
221 \brief Return all keys of the group
222 \param seq - string container to be filled with keys
224 void DDS_DicGroup::GetKeys( TColStd_SequenceOfAsciiString& seq ) const
230 \brief Instantiate new dictionary item, used for customization of
231 data dictionary items.
232 \return New dictionary item instance.
234 Handle(DDS_DicItem) DDS_DicGroup::CreateItem() const
236 return new DDS_DicItem();
240 \brief Bind dictionary item to ID
241 \return Standard_True if the item has been succesfully bound.
242 Standard_False if there is an item with same id.
244 Standard_Boolean DDS_DicGroup::AddDicItem( const TCollection_AsciiString& theID,
245 const Handle(DDS_DicItem)& theDicItem )
247 if ( myDataMap.Contains( theID ) )
248 return Standard_False;
250 myDataMap.Add( theID, theDicItem );
251 myKeys.Append( theID );
253 return Standard_True;
257 \brief Check if there is item bounded by id.
258 \return Standard_True if there is an item bound in map with given id.
260 Standard_Boolean DDS_DicGroup::HasDicItem( const TCollection_AsciiString& theID ) const
262 return myDataMap.Contains( theID );
266 \brief Clear dictionary items map
268 void DDS_DicGroup::RemoveAllDicItems()
275 \brief Returns a reference to a map. Can be used to iterate through
278 const DDS_IndexedDataMapOfDicItems& DDS_DicGroup::GetItemMap() const
284 \brief Add new unit system and bind its label name.
285 \return Standard_False if there is other system bound by this key.
287 Standard_Boolean DDS_DicGroup::AddUnitSystem( const TCollection_AsciiString& theSystemKey,
288 const TCollection_ExtendedString& theSystemLabel )
290 return myUnitSystem.Bind( theSystemKey, theSystemLabel );