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 TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
73 LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
74 if ( !systems.isNull() )
76 LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
77 for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
79 LDOM_Element aSystem = (const LDOM_Element &)systemList.item( i );
80 TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
81 TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
83 if ( aName.IsEmpty() )
86 if ( !myUnitSystem.IsBound( aName ) )
87 myUnitSystem.Bind( aName, aLabel );
91 if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
93 printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
94 myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
97 TColStd_SequenceOfAsciiString unitSystems;
98 GetUnitSystems( unitSystems );
100 LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
101 if ( !aData.getLength() )
104 for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
106 LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
108 // 1. Attributes (id,label,units?,format?,required?)
109 TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
110 Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
112 aDicItem->myComponent = this;
113 aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
114 myDataMap.Add( anID, aDicItem );
119 Returns DicItem with all attached data
122 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
124 Handle(DDS_DicItem) aDicItem;
125 // get dictionary item by id
126 if ( myDataMap.Contains( theID ) )
127 aDicItem = myDataMap.FindFromKey( theID );