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/ or email : webmaster.salome@opencascade.com
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)
39 This class to provide set of DDS_DicItem objects from one component.
43 Constructor. Create the group with name \aname.
45 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
48 myActiveSystem( UNIT_SYSTEM_SI )
55 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
60 Get the name of group (component).
62 TCollection_AsciiString DDS_DicGroup::GetName() const
68 Returns the names list of defined unit systems.
69 Parameter \atheSystems will contains the sequence of string names.
71 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
74 for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
76 if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
77 theSystemSeq.Prepend( it.Key() );
79 theSystemSeq.Append( it.Key() );
84 Returns the label of unit system \aname. If unit system not found then empty string returned.
86 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
88 TCollection_ExtendedString aLabel;
89 if ( myUnitSystem.IsBound( name ) )
90 aLabel = myUnitSystem.Find( name );
95 Gets the name of active unit system.
97 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
99 return myActiveSystem;
103 Sets the name of active unit system.
105 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
107 if ( myUnitSystem.IsBound( theSystem ) )
108 myActiveSystem = theSystem;
114 void DDS_DicGroup::operator=( const DDS_DicGroup& )
119 Fill the internal data structures from XML parsed structures. Internal.
121 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
123 TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
125 LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
126 if ( !systems.isNull() )
128 LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
129 for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
131 //const LDOM_Element& aSystem = (const LDOM_Element &)systemList.item( i );
132 LDOM_Node aNode = systemList.item( i );
133 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
134 LDOM_Element aSystem(anElem);
135 TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
136 TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
138 if ( aName.IsEmpty() )
141 if ( !myUnitSystem.IsBound( aName ) )
142 myUnitSystem.Bind( aName, aLabel );
146 if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
148 printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
149 myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
152 TColStd_SequenceOfAsciiString unitSystems;
153 GetUnitSystems( unitSystems );
155 LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
156 if ( !aData.getLength() )
159 for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
161 //LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
162 LDOM_Node aNode = aData.item( i );
163 const LDOM_Element& anElem = (const LDOM_Element&) aNode;
164 LDOM_Element aQuantity(anElem);
166 // 1. Attributes (id,label,units?,format?,required?)
167 TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
168 Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
170 aDicItem->myComponent = this;
171 aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
172 myDataMap.Add( anID, aDicItem );
177 Gets dictionary item with specified identifier \atheID.
178 If dictionary item not found then null handle returned.
180 Handle(DDS_DicItem) DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
182 Handle(DDS_DicItem) aDicItem;
183 // get dictionary item by id
184 if ( myDataMap.Contains( theID ) )
185 aDicItem = myDataMap.FindFromKey( theID );