1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "DDS_DicGroup.h"
21 #include "DDS_Dictionary.h"
23 #include <LDOMString.hxx>
24 #include <LDOM_Element.hxx>
26 #include <UnitsAPI.hxx>
28 #include <TColStd_SequenceOfAsciiString.hxx>
30 #include <Standard_Failure.hxx>
31 #include <Standard_ErrorHandler.hxx>
33 IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared)
34 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
36 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
39 myActiveSystem( UNIT_SYSTEM_SI )
43 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
47 TCollection_AsciiString DDS_DicGroup::GetName() const
52 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
55 for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
57 if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
58 theSystemSeq.Prepend( it.Key() );
60 theSystemSeq.Append( it.Key() );
64 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
66 TCollection_ExtendedString aLabel;
67 if ( myUnitSystem.IsBound( name ) )
68 aLabel = myUnitSystem.Find( name );
72 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
74 return myActiveSystem;
77 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
79 if ( myUnitSystem.IsBound( theSystem ) )
80 myActiveSystem = theSystem;
83 void DDS_DicGroup::operator=( const DDS_DicGroup& )
87 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
89 TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
91 LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
92 if ( !systems.isNull() )
94 LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
95 for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
97 //const LDOM_Element& aSystem = (const LDOM_Element &)systemList.item( i );
98 LDOM_Node aNode = systemList.item( i );
99 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
100 LDOM_Element aSystem(anElem);
101 TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
102 TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
104 if ( aName.IsEmpty() )
107 if ( !myUnitSystem.IsBound( aName ) )
108 myUnitSystem.Bind( aName, aLabel );
112 if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
114 printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
115 myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
118 TColStd_SequenceOfAsciiString unitSystems;
119 GetUnitSystems( unitSystems );
121 LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
122 if ( !aData.getLength() )
125 for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
127 //LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
128 LDOM_Node aNode = aData.item( i );
129 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
130 LDOM_Element aQuantity(anElem);
132 // 1. Attributes (id,label,units?,format?,required?)
133 TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
134 Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
136 aDicItem->myComponent = this;
137 aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
138 myDataMap.Add( anID, aDicItem );
143 Returns DicItem with all attached data
146 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
148 Handle(DDS_DicItem) aDicItem;
149 // get dictionary item by id
150 if ( myDataMap.Contains( theID ) )
151 aDicItem = myDataMap.FindFromKey( theID );