Salome HOME
Libraries for several kinds of controls (line edit, spinbox, combobox, ...). These...
[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   TColStd_SequenceOfAsciiString unitSystems;
72
73   TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
74
75   LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
76   if ( !systems.isNull() )
77   {
78     LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
79     for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
80     {
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" ) );
84
85       if ( aName.IsEmpty() )
86         continue;
87
88       if ( !myUnitSystem.IsBound( aName ) )
89         myUnitSystem.Bind( aName, aLabel );
90
91       unitSystems.Append( aName );
92     }
93   }
94
95   if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
96   {
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" ) );
99   }
100
101   LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
102   if ( !aData.getLength() )
103     return;
104
105   for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
106   {
107     LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
108
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();
112
113     aDicItem->myComponent = this;
114     aDicItem->FillDataMap( anID, aQuantity, theDocElement, unitSystems );
115     myDataMap.Add( anID, aDicItem );
116   }
117 }
118
119 /*!
120   Returns DicItem with all attached data
121 */
122
123 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
124 {
125   Handle(DDS_DicItem) aDicItem;
126   // get dictionary item by id
127   if ( myDataMap.Contains( theID ) )
128     aDicItem = myDataMap.FindFromKey( theID );
129
130   return aDicItem;
131 }