]> SALOME platform Git repositories - modules/gui.git/blob - src/DDS/DDS_DicGroup.cxx
Salome HOME
look for the list in component
[modules/gui.git] / src / DDS / DDS_DicGroup.cxx
1 #include "DDS_DicGroup.h"
2
3 #include "DDS_Dictionary.h"
4
5 #include <LDOMString.hxx>
6 #include <LDOM_Element.hxx>
7
8 #include <UnitsAPI.hxx>
9
10 #include <TColStd_SequenceOfAsciiString.hxx>
11
12 #include <Standard_Failure.hxx>
13 #include <Standard_ErrorHandler.hxx>
14
15 IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared)
16 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
17
18 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
19 : MMgt_TShared(),
20 myName( name ),
21 myActiveSystem( UNIT_SYSTEM_SI )
22 {
23 }
24
25 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
26 {
27 }
28
29 TCollection_AsciiString DDS_DicGroup::GetName() const
30 {
31   return myName;
32 }
33
34 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
35 {
36   theSystemSeq.Clear();
37   for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
38   {
39     if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
40       theSystemSeq.Prepend( it.Key() );
41     else
42       theSystemSeq.Append( it.Key() );
43   }
44 }
45
46 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
47 {
48   TCollection_ExtendedString aLabel;
49   if ( myUnitSystem.IsBound( name ) )
50     aLabel = myUnitSystem.Find( name );
51   return aLabel;
52 }
53
54 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
55 {
56   return myActiveSystem;
57 }
58
59 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
60 {
61   if ( myUnitSystem.IsBound( theSystem ) )
62     myActiveSystem = theSystem;
63 }
64
65 void DDS_DicGroup::operator=( const DDS_DicGroup& )
66 {
67 }
68
69 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
70 {
71   TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
72
73   LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
74   if ( !systems.isNull() )
75   {
76     LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
77     for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
78     {
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" ) );
82
83       if ( aName.IsEmpty() )
84         continue;
85
86       if ( !myUnitSystem.IsBound( aName ) )
87         myUnitSystem.Bind( aName, aLabel );
88     }
89   }
90
91   if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
92   {
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" ) );
95   }
96
97   TColStd_SequenceOfAsciiString unitSystems;
98   GetUnitSystems( unitSystems );
99
100   LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
101   if ( !aData.getLength() )
102     return;
103
104   for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
105   {
106     LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
107
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();
111
112     aDicItem->myComponent = this;
113     aDicItem->FillDataMap( anID, aQuantity, theComponentData, unitSystems );
114     myDataMap.Add( anID, aDicItem );
115   }
116 }
117
118 /*!
119   Returns DicItem with all attached data
120 */
121
122 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
123 {
124   Handle(DDS_DicItem) aDicItem;
125   // get dictionary item by id
126   if ( myDataMap.Contains( theID ) )
127     aDicItem = myDataMap.FindFromKey( theID );
128
129   return aDicItem;
130 }