1 // Copyright (C) 2007-2008 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.
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
22 #include "DDS_DicGroup.h"
24 #include "DDS_Dictionary.h"
26 #include <LDOMString.hxx>
27 #include <LDOM_Element.hxx>
29 #include <UnitsAPI.hxx>
31 #include <Standard_Failure.hxx>
32 #include <Standard_ErrorHandler.hxx>
34 IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared)
35 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
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 )
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 = new DDS_DicItem();
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