Back to index

salome-gui  6.5.0
DDS_DicGroup.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "DDS_DicGroup.h"
00024 
00025 #include "DDS_Dictionary.h"
00026 
00027 #include <LDOMString.hxx>
00028 #include <LDOM_Element.hxx>
00029 
00030 #include <UnitsAPI.hxx>
00031 
00032 #include <Standard_Failure.hxx>
00033 #include <Standard_ErrorHandler.hxx>
00034 
00035 IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared)
00036 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared)
00037 
00050 DDS_DicGroup::DDS_DicGroup( const TCollection_AsciiString& name )
00051 : MMgt_TShared(),
00052   myName( name ),
00053   myActiveSystem( UNIT_SYSTEM_SI )
00054 {
00055 }
00056 
00060 DDS_DicGroup::DDS_DicGroup( const DDS_DicGroup& )
00061 {
00062 }
00063 
00068 TCollection_AsciiString DDS_DicGroup::GetName() const
00069 {
00070   return myName;
00071 }
00072 
00077 void DDS_DicGroup::GetUnitSystems( TColStd_SequenceOfAsciiString& theSystemSeq ) const
00078 {
00079   theSystemSeq.Clear();
00080   for ( UnitSystemMap::Iterator it( myUnitSystem ); it.More(); it.Next() )
00081   {
00082     if ( it.Key() == TCollection_AsciiString( UNIT_SYSTEM_SI ) )
00083       theSystemSeq.Prepend( it.Key() );
00084     else
00085       theSystemSeq.Append( it.Key() );
00086   }
00087 }
00088 
00097 TCollection_ExtendedString DDS_DicGroup::GetUnitSystemLabel( const TCollection_AsciiString& name ) const
00098 {
00099   TCollection_ExtendedString aLabel;
00100   if ( myUnitSystem.IsBound( name ) )
00101     aLabel = myUnitSystem.Find( name );
00102   return aLabel;
00103 }
00104 
00109 TCollection_AsciiString DDS_DicGroup::GetActiveUnitSystem() const
00110 {
00111   return myActiveSystem;
00112 }
00113 
00118 void DDS_DicGroup::SetActiveUnitSystem( const TCollection_AsciiString& theSystem )
00119 {
00120   if ( myUnitSystem.IsBound( theSystem ) )
00121     myActiveSystem = theSystem;
00122 }
00123 
00127 void DDS_DicGroup::operator=( const DDS_DicGroup& )
00128 {
00129 }
00130 
00136 void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM_Element& theDocElement )
00137 {
00138   TCollection_AsciiString aCompName = theComponentData.getAttribute( DDS_Dictionary::KeyWord( "COMPONENT_NAME" ) );
00139 
00140   LDOM_Element systems = theComponentData.GetChildByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEMS" ) );
00141   if ( !systems.isNull() )
00142   {
00143     LDOM_NodeList systemList = systems.getElementsByTagName( DDS_Dictionary::KeyWord( "UNIT_SYSTEM" ) );
00144     for ( Standard_Integer i = 0; i < systemList.getLength(); i++ )
00145     {
00146       //const LDOM_Element& aSystem = (const LDOM_Element &)systemList.item( i );
00147       LDOM_Node aNode = systemList.item( i );
00148       const LDOM_Element& anElem = (const LDOM_Element&) aNode;
00149       LDOM_Element aSystem(anElem);
00150       TCollection_AsciiString aName = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_NAME" ) );
00151       TCollection_ExtendedString aLabel = aSystem.getAttribute( DDS_Dictionary::KeyWord( "UNIT_SYSTEM_LABEL" ) );
00152 
00153       if ( aName.IsEmpty() )
00154         continue;
00155 
00156       if ( !myUnitSystem.IsBound( aName ) )
00157         myUnitSystem.Bind( aName, aLabel );
00158 
00159 
00160     }
00161   }
00162 
00163   if ( !myUnitSystem.IsBound( UNIT_SYSTEM_SI ) )
00164   {
00165     printf( "Warning: Mandatory unit system SI not defined in component: \"%s\". Added automaticaly", aCompName.ToCString() );
00166     myUnitSystem.Bind( UNIT_SYSTEM_SI, TCollection_ExtendedString( "System international" ) );
00167   }
00168 
00169   TColStd_SequenceOfAsciiString unitSystems;
00170   GetUnitSystems( unitSystems );
00171 
00172   LDOM_NodeList aData = theComponentData.getElementsByTagName( DDS_Dictionary::KeyWord( "DATUM" ) );
00173   if ( !aData.getLength() )
00174     return;
00175 
00176   for ( Standard_Integer i = 0; i < aData.getLength(); i++ )
00177   {
00178     //LDOM_Element aQuantity = (const LDOM_Element&)aData.item( i );
00179     LDOM_Node aNode = aData.item( i );
00180     const LDOM_Element& anElem = (const LDOM_Element&) aNode;
00181     LDOM_Element aQuantity(anElem);
00182 
00183     // 1. Attributes (id,label,units?,format?,required?)
00184     TCollection_AsciiString anID = aQuantity.getAttribute( DDS_Dictionary::KeyWord( "DATUM_ID" ) );
00185     Handle(DDS_DicItem) aDicItem = new DDS_DicItem();
00186 
00187     aDicItem->myComponent = this;
00188     aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems );
00189     myDataMap.Add( anID, aDicItem );
00190 
00191     bool exist = false;
00192     for( int i=1, n=myKeys.Length(); i<=n && !exist; i++ )
00193       if( myKeys.Value( i )==anID )
00194       {
00195         cout << "Doubled key:" << anID << endl;
00196         exist = true;
00197       }
00198     if( !exist )
00199       myKeys.Append( anID );
00200   }
00201 }
00202 
00211 Handle_DDS_DicItem DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theID ) const
00212 {
00213   Handle(DDS_DicItem) aDicItem;
00214   // get dictionary item by id
00215   if ( myDataMap.Contains( theID ) )
00216     aDicItem = myDataMap.FindFromKey( theID );
00217 
00218   return aDicItem;
00219 }
00220 
00225 void DDS_DicGroup::GetKeys( TColStd_SequenceOfAsciiString& seq ) const
00226 {
00227   seq = myKeys;
00228 }