1 #include "DDS_DicGroup.h"
3 #include "DDS_Dictionary.h"
5 #include <LDOMString.hxx>
6 #include <LDOM_Element.hxx>
8 #include <UnitsAPI.hxx>
10 #include <TColStd_SequenceOfAsciiString.hxx>
12 #include <Standard_Failure.hxx>
13 #include <Standard_ErrorHandler.hxx>
15 IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared)
16 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
18 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
21 myActiveSystem( UNIT_SYSTEM_SI )
25 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
29 TCollection_AsciiString DDS_DicGroup::GetName() const
34 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
37 for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
39 if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
40 theSystemSeq.Prepend( it.Key() );
42 theSystemSeq.Append( it.Key() );
46 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
48 TCollection_ExtendedString aLabel;
49 if ( myUnitSystem.IsBound( name ) )
50 aLabel = myUnitSystem.Find( name );
54 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
56 return myActiveSystem;
59 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
61 if ( myUnitSystem.IsBound( theSystem ) )
62 myActiveSystem = theSystem;
65 void DDS_DicGroup::operator=( const DDS_DicGroup& )
69 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
71 TColStd_SequenceOfAsciiString unitSystems;
73 TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
75 LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
76 if ( !systems.isNull() )
78 LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
79 for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
81 LDOM_Element aSystem = (const LDOM_Element &)systemList.item( i );
82 TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
83 TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
85 if ( aName.IsEmpty() )
88 if ( !myUnitSystem.IsBound( aName ) )
89 myUnitSystem.Bind( aName, aLabel );
91 unitSystems.Append( aName );
95 if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
97 printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
98 myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
101 LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
102 if ( !aData.getLength() )
105 for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
107 LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
109 // 1. Attributes (id,label,units?,format?,required?)
110 TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
111 Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
113 aDicItem->myComponent = this;
114 aDicItem->FillDataMap( anID, aQuantity, theDocElement, unitSystems );
115 myDataMap.Add( anID, aDicItem );
120 Returns DicItem with all attached data
123 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
125 Handle(DDS_DicItem) aDicItem;
126 // get dictionary item by id
127 if ( myDataMap.Contains( theID ) )
128 aDicItem = myDataMap.FindFromKey( theID );