From: stv Date: Thu, 31 Aug 2006 05:17:19 +0000 (+0000) Subject: Option support for data dictionary item. X-Git-Tag: LAST_STABLE_VERSION_21_09_2006_ON_3_2_0~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6fcc7fe7fd2468cf01e8296b5789943eb7981b8d;p=modules%2Fgui.git Option support for data dictionary item. --- diff --git a/src/DDS/DDS_DicItem.cxx b/src/DDS/DDS_DicItem.cxx index 12b2a0fd9..02cdefb93 100644 --- a/src/DDS/DDS_DicItem.cxx +++ b/src/DDS/DDS_DicItem.cxx @@ -433,6 +433,32 @@ Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const return ( myData & flag ) == flag; } +/*! + Returns options for specified name \aname. If option not found then empty string returned. +*/ +TCollection_ExtendedString DDS_DicItem::GetOption( const TCollection_AsciiString& name ) const +{ + TCollection_ExtendedString res; + if ( myOptions.IsBound( name ) ) + res = myOptions.Find( name ); + return res; +} + +/*! + Returns names list of existing options in the specified sequence \anames. + If list not empty retunrs 'true' otherwise 'false'. +*/ +Standard_Boolean DDS_DicItem::GetOptionNames( TColStd_SequenceOfAsciiString& names ) const +{ + names.Clear(); + + for ( OptionsMap::Iterator it( myOptions ); it.More(); it.Next() ) + names.Append( it.Key() ); + + return !names.IsEmpty(); +} + + /*! Parse record in XML file and retrieve information relevant for this dictionary item */ @@ -678,6 +704,31 @@ void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element } } + // Quantity::Options + LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) ); + if ( !anOpt.isNull() ) + { + LDOM_NodeList anOptions = anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) ); + for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ ) + { + LDOM_Node node = anOptions.item( oi ); + if ( node.getNodeType() != LDOM_Node::ELEMENT_NODE ) + continue; + + LDOM_Element& elem = (LDOM_Element&)node; + TCollection_AsciiString name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) ); + + TCollection_ExtendedString value; + const LDOM_Text& aText = (const LDOM_Text&)elem.getFirstChild(); + LDOM_Text anOptTxt( aText ); + if ( !anOptTxt.isNull() ) + value = anOptTxt.getData(); + + if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) ) + myOptions.Bind( name, value ); + } + } + NCollection_DataMap aDimMap; for ( NCollection_DataMap::Iterator it( myUnitData ); it.More(); it.Next() ) diff --git a/src/DDS/DDS_DicItem.h b/src/DDS/DDS_DicItem.h index 0b9746a6c..b32639900 100644 --- a/src/DDS/DDS_DicItem.h +++ b/src/DDS/DDS_DicItem.h @@ -120,14 +120,17 @@ public: Standard_EXPORT Standard_Real GetMaxZoom() const; Standard_EXPORT Standard_Real GetZoomOrder() const; - Standard_EXPORT Standard_Real ToSI( const Standard_Real ) const; - Standard_EXPORT Standard_Real FromSI( const Standard_Real ) const; + Standard_EXPORT Standard_Real ToSI( const Standard_Real ) const; + Standard_EXPORT Standard_Real FromSI( const Standard_Real ) const; - Standard_EXPORT Standard_Real ToSI( const Standard_Real, const UnitSystem& ) const; - Standard_EXPORT Standard_Real FromSI( const Standard_Real, const UnitSystem& ) const; + Standard_EXPORT Standard_Real ToSI( const Standard_Real, const UnitSystem& ) const; + Standard_EXPORT Standard_Real FromSI( const Standard_Real, const UnitSystem& ) const; Standard_EXPORT Standard_Boolean HasData( const Standard_Integer ) const; + Standard_EXPORT TCollection_ExtendedString GetOption( const TCollection_AsciiString& ) const; + Standard_EXPORT Standard_Boolean GetOptionNames( TColStd_SequenceOfAsciiString& ) const; + private: DDS_DicItem( const DDS_DicItem& ); void operator=( const DDS_DicItem& ); @@ -160,6 +163,9 @@ private: UnitData* GetUnitData( const UnitSystem& ) const; +private: + typedef NCollection_DataMap OptionsMap; + private: TCollection_AsciiString myId; TCollection_ExtendedString myLabel; @@ -193,6 +199,7 @@ private: Handle(Standard_Transient) myComponent; + OptionsMap myOptions; // unitData NCollection_DataMap myUnitData; diff --git a/src/DDS/DDS_Dictionary.cxx b/src/DDS/DDS_Dictionary.cxx index 7e2800357..38eef62cd 100644 --- a/src/DDS/DDS_Dictionary.cxx +++ b/src/DDS/DDS_Dictionary.cxx @@ -67,6 +67,12 @@ IMPLEMENT_STANDARD_RTTIEXT(DDS_Dictionary, MMgt_TShared) [brief_desription_text] [full_description_text] + + + + ... + + ... @@ -120,7 +126,11 @@ IMPLEMENT_STANDARD_RTTIEXT(DDS_Dictionary, MMgt_TShared) Tag "description" (key DESCR) can be defined under the tag "datum". This tag contains two sub tags: \lo "short description" (key SHORT_D) specify a brief datum description text \lo "long description" (key LONG_D) specify a detailed description text - + + Tag "options" (key OPTIONS) can be defined under the tag "datum". This tag contains one or more sub + tags "option" (key OPTION). Each of these XML elements should contain text option value and attribute + "name" (key OPTION_NAME) which specified option name. + Each tag "datum" define most common parameters of phisical characteristic. This parameters placed in two groups: \lo Domain parameters under tag "domain" (key DY_DOMAIN). This tag can contains value description tag diff --git a/src/DDS/DDS_KeyWords.cxx b/src/DDS/DDS_KeyWords.cxx index 83be4f3bf..626bd0fd0 100644 --- a/src/DDS/DDS_KeyWords.cxx +++ b/src/DDS/DDS_KeyWords.cxx @@ -68,6 +68,9 @@ IMPLEMENT_STANDARD_RTTIEXT(DDS_KeyWords, MMgt_TShared) \li LZ_MINV - min \li LZ_MAXV - max \li LZ_ORDER - order + \li OPTIONS - options + \li OPTION - option + \li OPTION_NAME - name */ /*! @@ -124,6 +127,10 @@ DDS_KeyWords::DDS_KeyWords() SetKeyWord( "LZ_MINV", "min" ); SetKeyWord( "LZ_MAXV", "max" ); SetKeyWord( "LZ_ORDER", "order" ); + + SetKeyWord( "OPTIONS", "options" ); + SetKeyWord( "OPTION", "option" ); + SetKeyWord( "OPTION_NAME", "name" ); } /*! diff --git a/src/QDS/QDS_Datum.cxx b/src/QDS/QDS_Datum.cxx index 349cbc173..a542a19b4 100644 --- a/src/QDS/QDS_Datum.cxx +++ b/src/QDS/QDS_Datum.cxx @@ -31,6 +31,8 @@ #include #include +#include + /*! class: QDS_Datum::Wrapper descr: Wrapper widget for sub widgets. [internal] @@ -368,6 +370,72 @@ QString QDS_Datum::shortDescription() const return sdStr; } +/*! + Returns the list of option names. +*/ +QStringList QDS_Datum::options() const +{ + QStringList res; + if ( !dicItem().IsNull() ) + { + TColStd_SequenceOfAsciiString lst; + dicItem()->GetOptionNames( lst ); + for ( int i = 1; i <= lst.Length(); i++ ) + res.append( toQString( lst.Value( i ) ) ); + } + return res; +} + +/*! + Returns the option specified by \aname as QVariant. + If option not exist then not valid QVariant returned. +*/ +QVariant QDS_Datum::option( const QString& name ) const +{ + QVariant res; + if ( !dicItem().IsNull() ) + res = QVariant( toQString( dicItem()->GetOption( toAsciiString( name ) ) ) ); + return res; +} + +/*! + Returns the option specified by \aname as QString. + If option not exist then empty string returned. +*/ +QString QDS_Datum::optionString( const QString& name ) const +{ + QString res; + if ( !dicItem().IsNull() ) + res = toQString( dicItem()->GetOption( toAsciiString( name ) ) ); + return res; +} + +/*! + Returns the option specified by \aname as double. + If option not exist then 0 returned. +*/ +double QDS_Datum::optionDouble( const QString& name ) const +{ + double res = 0; + QVariant opt = option( name ); + if ( opt.isValid() && opt.canCast( QVariant::Double ) ) + res = opt.toDouble(); + return res; +} + +/*! + Returns the option specified by \aname as integer. + If option not exist then 0 returned. +*/ +int QDS_Datum::optionInteger( const QString& name ) const +{ + int res = 0; + QVariant opt = option( name ); + if ( opt.isValid() && opt.canCast( QVariant::Int ) ) + res = opt.toInt(); + return res; +} + /*! Returns the datum value as variant (QVariant object). */ diff --git a/src/QDS/QDS_Datum.h b/src/QDS/QDS_Datum.h index 45ef3458c..9ff431f66 100644 --- a/src/QDS/QDS_Datum.h +++ b/src/QDS/QDS_Datum.h @@ -60,6 +60,12 @@ public: QString minimumValue() const; QString maximumValue() const; + QStringList options() const; + QVariant option( const QString& ) const; + QString optionString( const QString& ) const; + double optionDouble( const QString& ) const; + int optionInteger( const QString& ) const; + virtual QVariant value() const; virtual QString stringValue() const;