]> SALOME platform Git repositories - modules/gui.git/blob - src/DDS/DDS_DicGroup.cxx
Salome HOME
6655e4fb7fcd81005f8d058e3322fbcdb2530bb5
[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       //const LDOM_Element& aSystem = (const LDOM_Element &)systemList.item( i );
80       LDOM_Node aNode = systemList.item( i );
81       const LDOM_Element& anElem = (const LDOM_Element&) aNode;
82       LDOM_Element aSystem(anElem);
83       TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
84       TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
85
86       if ( aName.IsEmpty() )
87         continue;
88
89       if ( !myUnitSystem.IsBound( aName ) )
90         myUnitSystem.Bind( aName, aLabel );
91     }
92   }
93
94   if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
95   {
96     printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
97     myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
98   }
99
100   TColStd_SequenceOfAsciiString unitSystems;
101   GetUnitSystems( unitSystems );
102
103   LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
104   if ( !aData.getLength() )
105     return;
106
107   for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
108   {
109     //LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
110     LDOM_Node aNode = aData.item( i );
111     const LDOM_Element& anElem = (const LDOM_Element&) aNode;
112     LDOM_Element aQuantity(anElem);
113
114     // 1. Attributes (id,label,units?,format?,required?)
115     TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
116     Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
117
118     aDicItem->myComponent = this;
119     aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
120     myDataMap.Add( anID, aDicItem );
121   }
122 }
123
124 /*!
125   Returns DicItem with all attached data
126 */
127
128 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
129 {
130   Handle(DDS_DicItem) aDicItem;
131   // get dictionary item by id
132   if ( myDataMap.Contains( theID ) )
133     aDicItem = myDataMap.FindFromKey( theID );
134
135   return aDicItem;
136 }