Back to index

salome-gui  6.5.0
DDS_DicItem.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_DicItem.h"
00024 #include "DDS_Dictionary.h"
00025 
00026 #include <TColStd_SequenceOfInteger.hxx>
00027 #include <TColStd_SequenceOfExtendedString.hxx>
00028 
00029 #include <LDOM_Text.hxx>
00030 #include <LDOMString.hxx>
00031 #include <LDOM_Element.hxx>
00032 
00033 #include <UnitsAPI.hxx>
00034 #include <Units_Dimensions.hxx>
00035 
00036 #include <TColStd_MapOfReal.hxx>
00037 #include <TColStd_SequenceOfAsciiString.hxx>
00038 
00039 IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared)
00040 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
00041 
00052 DDS_DicItem::DDS_DicItem()
00053 : myType( 0 ),
00054   myMax( 0 ),
00055   myMin( 0 ),
00056   myDefValue( 0 ),
00057   myMinZoom( 0.1 ),
00058   myMaxZoom( 10 ),
00059   myZoomOrder( 2 )
00060 {
00061 }
00062 
00066 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
00067 {
00068 }
00069 
00073 void DDS_DicItem::operator=( const DDS_DicItem& )
00074 {
00075 }
00076 
00081 TCollection_AsciiString DDS_DicItem::GetId() const
00082 {
00083   return myId;
00084 }
00085 
00090 DDS_DicItem::Type DDS_DicItem::GetType() const
00091 {
00092   return (DDS_DicItem::Type)myType;
00093 }
00094 
00099 TCollection_ExtendedString DDS_DicItem::GetLabel() const
00100 {
00101   return myLabel;
00102 }
00103 
00108 TCollection_ExtendedString DDS_DicItem::GetFilter() const
00109 {
00110   return myFilter;
00111 }
00112 
00117 TCollection_ExtendedString DDS_DicItem::GetRequired() const
00118 {
00119   return myRequired;
00120 }
00121 
00126 DDS_MsgType DDS_DicItem::GetWarningLevel() const
00127 {
00128   return (DDS_MsgType)myWarnLevel;
00129 }
00130 
00135 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
00136 {
00137   return myLongDescr;
00138 }
00139 
00144 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
00145 {
00146   return myShortDescr;
00147 }
00148 
00153 TCollection_AsciiString DDS_DicItem::GetComponent() const
00154 {
00155   TCollection_AsciiString aCompName;
00156   Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
00157   if ( !aComponent.IsNull() )
00158     aCompName = aComponent->GetName();
00159   return aCompName;
00160 }
00161 
00166 TCollection_AsciiString DDS_DicItem::GetUnits() const
00167 {
00168   return GetUnits( GetActiveUnitSystem() );
00169 }
00170 
00179 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
00180 {
00181   TCollection_AsciiString anUnits;
00182   UnitData* unitData = GetUnitData( theSystem );
00183   if ( unitData )
00184     anUnits = unitData->myUnits;
00185   return anUnits;
00186 }
00187 
00195 Standard_Real DDS_DicItem::GetMinValue() const
00196 {
00197   return GetMinValue( GetActiveUnitSystem() );
00198 }
00199 
00209 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
00210 {
00211   return FromSI( myMin, theUnitsSystem );
00212 }
00213 
00221 Standard_Real DDS_DicItem::GetMaxValue() const
00222 {
00223   return GetMaxValue( GetActiveUnitSystem() );
00224 }
00225 
00235 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
00236 {
00237   return FromSI( myMax, theUnitsSystem );
00238 }
00239 
00245 Standard_Integer DDS_DicItem::GetPrecision() const
00246 {
00247   return GetPrecision( GetActiveUnitSystem() );
00248 }
00249 
00259 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
00260 {
00261   Standard_Integer aRes = 0;
00262   UnitData* unitData = GetUnitData( theSystem );
00263   if ( unitData )
00264     aRes = unitData->myPrecision;
00265   return aRes;
00266 }
00267 
00277 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
00278 {
00279   return GetDefaultValue( GetActiveUnitSystem() );
00280 }
00281 
00293 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
00294 {
00295   if ( !myDefString.Length() )
00296     return myDefString;
00297 
00298   TCollection_ExtendedString aStr;
00299 
00300   switch ( myType )
00301   {
00302   case Float:
00303   case Integer:
00304     aStr = FromSI( myDefValue, theSystem );
00305     break;
00306   case List:
00307   case String:
00308     aStr = myDefString;
00309     break;
00310   default:
00311     break;
00312   }
00313   return aStr;
00314 }
00315 
00325 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
00326 {
00327   return GetFormat( GetActiveUnitSystem(), theCanonical );
00328 }
00329 
00341 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
00342                                                 const Standard_Boolean theCanonical ) const
00343 {
00344   TCollection_AsciiString aFormat;
00345   UnitData* unitData = GetUnitData( theSystem );
00346   if ( unitData )
00347     aFormat = unitData->myFormat;
00348 
00349   if ( theCanonical && aFormat.Length() > 1 )
00350   {
00351     static TCollection_AsciiString f;
00352     f = aFormat;
00353     Standard_Boolean isRemoved = false;
00354     while ( !isRemoved )
00355     {
00356       char ch = f.Value( f.Length() - 1 );
00357       if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
00358         f.Remove( f.Length() - 1 );
00359       else
00360         isRemoved = true;
00361     }
00362     aFormat = f;
00363   }
00364 
00365   return aFormat;
00366 }
00367 
00378 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
00379 {
00380   return myListName;
00381 }
00382 
00396 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
00397                                                Handle(TColStd_HArray1OfInteger)& theIntegers ) const
00398 {
00399   theStrings  = myListRef;
00400   theIntegers = myListRefID;
00401   return !theIntegers.IsNull() && !theStrings.IsNull();
00402 }
00403 
00420 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
00421                                                Handle(TColStd_HArray1OfInteger)& theIntegers,
00422                                                Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
00423 {
00424   theStrings  = myListRef;
00425   theIntegers = myListRefID;
00426   theIcons    = myListRefIcons;
00427   return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
00428 }
00429 
00430 
00436 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
00437 {
00438   theMap.Clear();
00439   if ( !myListRef.IsNull() )
00440   {
00441     for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
00442     {
00443       if ( myListRef->Value( i ).IsAscii() )
00444       {
00445         TCollection_AsciiString aStr( myListRef->Value( i ) );
00446         if ( aStr.IsRealValue() )
00447           theMap.Add( aStr.RealValue() );
00448       }
00449     }
00450   }
00451 
00452   return theMap.Extent() > 0;
00453 }
00454 
00459 Standard_Real DDS_DicItem::GetMinZoom() const
00460 {
00461   return myMinZoom;
00462 }
00463 
00468 Standard_Real DDS_DicItem::GetMaxZoom() const
00469 {
00470   return myMaxZoom;
00471 }
00472 
00477 Standard_Real DDS_DicItem::GetZoomOrder() const
00478 {
00479   return myZoomOrder;
00480 }
00481 
00488 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
00489 {
00490   return ToSI( theVal, GetActiveUnitSystem() );
00491 }
00492 
00499 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
00500 {
00501   return FromSI( theVal, GetActiveUnitSystem() );
00502 }
00503 
00511 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
00512 {
00513   Standard_Real aRes = theVal;
00514   UnitData* anUnitData = GetUnitData( theUnitsSystem );
00515   if ( anUnitData )
00516     aRes = anUnitData->myZero + aRes * anUnitData->myScale;
00517   return aRes;
00518 }
00519 
00527 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
00528 {
00529   Standard_Real aRes = theVal;
00530   UnitData* anUnitData = GetUnitData( theUnitsSystem );
00531   if ( anUnitData )
00532     aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
00533   return aRes;
00534 }
00535 
00541 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
00542 {
00543   return ( myData & flag ) == flag;
00544 }
00545 
00554 TCollection_ExtendedString DDS_DicItem::GetOption( const TCollection_AsciiString& name ) const
00555 {
00556   TCollection_ExtendedString res;
00557   if ( myOptions.IsBound( name ) )
00558     res = myOptions.Find( name );
00559   return res;
00560 }
00561 
00567 Standard_Boolean DDS_DicItem::GetOptionNames( TColStd_SequenceOfAsciiString& names ) const
00568 {
00569   names.Clear();
00570 
00571   for ( OptionsMap::Iterator it( myOptions ); it.More(); it.Next() )
00572     names.Append( it.Key() );
00573 
00574   return !names.IsEmpty();
00575 }
00576 
00577 
00587 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
00588                                const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
00589                                const TColStd_SequenceOfAsciiString& theSystems )
00590 {
00591   TCollection_AsciiString aLabel    = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
00592   TCollection_AsciiString aFormat   = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
00593   TCollection_AsciiString aFilter   = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
00594   TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
00595 
00596   TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
00597 
00598   for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
00599   {
00600     UnitSystem anUnitSystem = theSystems.Value( j );
00601     if ( !anUnitSystem.Length() )
00602       continue;
00603 
00604     TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
00605 
00606     if ( !myUnitData.IsBound( anUnitSystem ) )
00607       myUnitData.Bind( anUnitSystem, UnitData() );
00608 
00609     UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
00610     anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
00611   }
00612 
00613   if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
00614        !myUnitData.Find( theSystems.First() ).myUnits.Length() )
00615   {
00616     TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
00617     if ( units.Length() )
00618       myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
00619   }
00620 
00621   TCollection_AsciiString units;
00622   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
00623     units = iter.Value().myUnits;
00624 
00625   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
00626   {
00627     UnitData& dataUnits = itr.ChangeValue();
00628     if ( dataUnits.myUnits.IsEmpty() )
00629       dataUnits.myUnits = units;
00630   }
00631   
00632   // 2. Elements ( domain, description )
00633   Standard_Real aRealMinV = 0;
00634   Standard_Real aRealMaxV = 0;
00635   Standard_Real aRealDefV = 0;
00636 
00637   TCollection_AsciiString aType;
00638 
00639   DDS_MsgType aWrongValue = DDS_MT_NONE;
00640   DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
00641 
00642   TCollection_AsciiString aMinV;
00643   TCollection_AsciiString aMaxV;
00644   TCollection_AsciiString aDefV;
00645   TCollection_AsciiString aListName;
00646 
00647   TCollection_AsciiString aLongD;
00648   TCollection_AsciiString aShortD;
00649 
00650   TColStd_SequenceOfInteger aSeqOfValueID;
00651   TColStd_SequenceOfExtendedString aSeqOfValue;
00652   TColStd_SequenceOfExtendedString aSeqOfValueIconName;
00653 
00654   // Presentation
00655   Standard_Real aMinZoom   = 0;
00656   Standard_Real aMaxZoom   = 0;
00657   Standard_Real aZoomOrder = 0;
00658 
00659   // Datum::Reports tags (if any)
00660   LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
00661   if ( !aWLev.isNull() )
00662   {
00663     TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
00664     if ( aWrongValWL.IsEqual( "Info" ) )
00665       aWrongValue = DDS_MT_INFO;
00666     else if ( aWrongValWL.IsEqual( "Warning" ) )
00667       aWrongValue = DDS_MT_WARNING;
00668     else if ( aWrongValWL.IsEqual( "Alarm" ) )
00669       aWrongValue = DDS_MT_ALARM;
00670     else if ( aWrongValWL.IsEqual( "Error" ) )
00671       aWrongValue = DDS_MT_ERROR;
00672   }
00673 
00674   // Datum::Presentation
00675   LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
00676   if ( !aPrs.isNull() )
00677   {
00678     LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
00679     if ( !aLateralZoom.isNull() )
00680     {
00681       TCollection_AsciiString aMinZoomStr   = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
00682       TCollection_AsciiString aMaxZoomStr   = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
00683       TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
00684       
00685       aMinZoomStr.RemoveAll( ' ' );
00686       if ( aMinZoomStr.IsRealValue() )
00687         aMinZoom = aMinZoomStr.RealValue();
00688 
00689       aMaxZoomStr.RemoveAll( ' ' );
00690       if ( aMaxZoomStr.IsRealValue() )
00691         aMaxZoom = aMaxZoomStr.RealValue();
00692 
00693       aZoomOrderStr.RemoveAll( ' ' );
00694       if ( aZoomOrderStr.IsRealValue() )
00695         aZoomOrder = aZoomOrderStr.RealValue();
00696     }
00697   }
00698 
00699   // Quantity::Domain record as the only child of that tag name
00700   LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
00701   if ( !aDomain.isNull() )
00702   {
00703     LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
00704     if ( !aValueDescr.isNull() )
00705     {
00706       // read: valueDescr? (type?,min?,max?,default?)
00707       aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
00708       if ( aType.IsEqual( "String" ) )
00709         aEnumType = String;
00710       else if ( aType.IsEqual( "Float" ) )
00711         aEnumType = Float;
00712       else if ( aType.IsEqual( "Integer" ) )
00713         aEnumType = Integer;
00714 
00715       if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
00716         myData |= MinValue;
00717       aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
00718       aMinV.RemoveAll( ' ' );
00719       if ( aMinV.IsRealValue() )
00720         aRealMinV = aMinV.RealValue();
00721       if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
00722         myData |= MaxValue;
00723       aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
00724       aMaxV.RemoveAll( ' ' );
00725       if ( aMaxV.IsRealValue() )
00726         aRealMaxV = aMaxV.RealValue();
00727       aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
00728       if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
00729         myData |= DefaultValue;
00730 
00731       aDefV.RemoveAll( ' ' );
00732       if ( aDefV.IsRealValue() )
00733         aRealDefV = aDefV.RealValue();
00734 
00735       TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
00736       Split( aSpecVal, myListRef );
00737     }
00738     else
00739     {
00740       //  read: listRef? (list?)
00741       LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
00742       if ( !aListRef.isNull() )
00743       {
00744         aType = "List";
00745         aEnumType = List;                       
00746         LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
00747         aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
00748         aDefV.RemoveAll( ' ' );
00749         LDOM_Element foundListItem;
00750         for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
00751               aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
00752         {
00753           if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
00754             foundListItem = aListItem;
00755 
00756         }
00757         for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
00758               aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
00759         {
00760           if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
00761             foundListItem = aLstItem;
00762         }
00763 
00764         if ( foundListItem != NULL )
00765         {
00766           //  The appropriate list of values is found: store the list name
00767           aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
00768           //  Iteration through the list of values
00769           LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
00770           while ( aListItemValue != NULL )
00771           {
00772             // read value ID
00773             TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
00774             if ( aListValueID.IsIntegerValue() )
00775             {
00776               //  Read the text in the element "value"
00777               //LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
00778               LDOM_Node aNode = aListItemValue.getFirstChild();
00779               const LDOM_Text& aText = (const LDOM_Text&) aNode;
00780               LDOM_Text aListItemTxt(aText);
00781               if ( !aListItemTxt.isNull() )
00782               {
00783                 // adding ID and text value to sequence
00784                 aSeqOfValueID.Append( aListValueID.IntegerValue() );
00785                 aSeqOfValue.Append( aListItemTxt.getData() );
00786                 // adding icon file name (optional) to sequence
00787                 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
00788                 aSeqOfValueIconName.Append( aListValueIcon );
00789               }
00790               aListItemValue = aListItemValue.GetSiblingByTagName();
00791             }
00792           }
00793         }
00794       }
00795     }
00796   }
00797 
00798   // Quantity::Description record as the only child of that tag name
00799   LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
00800   if ( !aDescr.isNull() )
00801   {
00802     // short description (#PCDATA)*
00803     LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
00804     if ( !aShDescr.isNull() )
00805     {
00806       // text is always a sub-node of element, containing it
00807       //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
00808       LDOM_Node aNode = aShDescr.getFirstChild();
00809       const LDOM_Text& aText = (const LDOM_Text&) aNode;
00810       LDOM_Text aShDescrTxt(aText);
00811       if ( !aShDescrTxt.isNull() )
00812         aShortD = aShDescrTxt.getData();
00813     }
00814 
00815     // long description (#PCDATA)*
00816     LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
00817     if ( !aLDescr.isNull() )
00818     {
00819       // text is always a sub-node of element, containing it
00820       //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
00821       LDOM_Node aNode = aLDescr.getFirstChild();
00822       const LDOM_Text& aText = (const LDOM_Text&) aNode;
00823       LDOM_Text aLDescrTxt(aText);
00824       if ( !aLDescrTxt.isNull() )
00825         aLongD = aLDescrTxt.getData();
00826     }
00827   }
00828 
00829   // Quantity::Options
00830   LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) );
00831   if ( !anOpt.isNull() )
00832   {
00833     LDOM_NodeList anOptions = anOpt.GetAttributesList();//anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) );
00834     for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ )
00835     {
00836       LDOM_Node node = anOptions.item( oi );
00837       LDOM_Node::NodeType t = node.getNodeType();
00838 
00839       TCollection_AsciiString name;
00840       TCollection_ExtendedString value;
00841 
00842       if( t==LDOM_Node::ELEMENT_NODE )
00843       {
00844         const LDOM_Element& elem = ( const LDOM_Element& )node;
00845         name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) );
00846         
00847         const LDOM_Node aNode = elem.getFirstChild();
00848         LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) );
00849         if ( !anOptTxt.isNull() )
00850           value = anOptTxt.getData();
00851       }
00852       else if( t==LDOM_Node::ATTRIBUTE_NODE )
00853       {
00854         const LDOM_Attr& attr = ( const LDOM_Attr& )node;
00855         name = ( Standard_CString )attr.getName().GetString();
00856         LDOMString v = attr.getValue();
00857         if( v.Type()==LDOMBasicString::LDOM_Integer )
00858         {
00859                 Standard_Integer ival;
00860                 v.GetInteger( ival );
00861                 value = TCollection_ExtendedString( ival );
00862         }
00863         else
00864                 value = ( Standard_CString )v.GetString();
00865       }
00866       else
00867         continue;
00868 
00869       if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) )
00870         myOptions.Bind( name, value );
00871     }
00872   }
00873 
00874   NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
00875 
00876   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
00877   {
00878     UnitData& anUnitData = it.ChangeValue();
00879 
00880     // check units
00881     anUnitData.myZero  = 0.;
00882     anUnitData.myScale = 1.;
00883     try {
00884       Standard_CString aUnitDataStr;
00885       aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
00886       if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
00887       {
00888         Handle(Units_Dimensions) aDim;
00889         anUnitData.myZero  = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
00890         anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
00891         UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
00892         if ( !aDimMap.IsBound( it.Key() ) )
00893           aDimMap.Bind( it.Key(), aDim );
00894       }
00895       else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
00896         anUnitData.myScale = 0.01;
00897     }
00898           catch( Standard_Failure ) {
00899       anUnitData.myUnits.Clear();
00900     }
00901 
00902     Handle(Units_Dimensions) aPrev;
00903     Standard_Boolean aStatus = Standard_True;
00904     for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
00905           itr.More() && aStatus; itr.Next() )
00906     {
00907       if ( itr.Value().IsNull() )
00908         continue;
00909 
00910       if ( aPrev.IsNull() )
00911         aPrev = itr.Value();
00912 
00913       aStatus = aPrev->IsEqual( itr.Value() );
00914     }
00915 
00916     if ( !aStatus )
00917       printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
00918   }
00919 
00920   myId                = theID;
00921   myType              = aEnumType;
00922   myWarnLevel         = aWrongValue;
00923   myLabel             = aLabel.ToCString();
00924   myFilter            = aFilter.ToCString();
00925   myLongDescr         = aLongD.ToCString();
00926   myShortDescr        = aShortD.ToCString();
00927   myMin               = aRealMinV;
00928   myMax               = aRealMaxV;
00929   myDefValue          = aRealDefV;
00930   myDefString         = aDefV.ToCString();
00931   myRequired          = aRequired.ToCString();
00932   myListName          = aListName.ToCString();
00933   myMinZoom           = aMinZoom;
00934   myMaxZoom           = aMaxZoom;
00935   myZoomOrder         = aZoomOrder;
00936 
00937   // prepare formats
00938   PrepareFormats( aFormat );
00939 
00940   const Standard_Integer aLength = aSeqOfValue.Length();
00941   if ( aLength > 0 )
00942   {
00943     myListRef      = new TColStd_HArray1OfExtendedString( 1, aLength );
00944     myListRefID    = new TColStd_HArray1OfInteger( 1, aLength );
00945     myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
00946     for ( Standard_Integer i = aLength; i > 0; i-- )
00947     {
00948       myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
00949       myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
00950       myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
00951     }
00952   }
00953 
00954   if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
00955     myDefString = myListRef->Value( myListRef->Lower() );
00956 }
00957 
00961 void DDS_DicItem::GetDefaultFormat()
00962 {
00963   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
00964   {
00965     UnitData& anUnitData = it.ChangeValue();
00966 
00967     switch ( myType )
00968     {
00969     case Integer:
00970       anUnitData.myFormat = "%d";
00971       break;
00972     case Float:
00973       anUnitData.myFormat = "%g";
00974       break;
00975     case String:
00976     default:
00977       anUnitData.myFormat.Clear();
00978       break;;
00979     }
00980   }
00981 }
00982 
00991 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
00992                                    const TCollection_AsciiString& theWidth,
00993                                    const TCollection_AsciiString& thePrecision,
00994                                    const TCollection_AsciiString& theTypePrefix,
00995                                    TCollection_AsciiString& theFormat )
00996 {
00997   theFormat = "%";
00998   theFormat += theFlags;
00999   theFormat += theWidth;
01000 
01001   if ( !thePrecision.IsEmpty() ) 
01002   {
01003     theFormat += ".";
01004     theFormat += thePrecision;
01005   }
01006 
01007   theFormat += theTypePrefix;
01008   theFormat += "s";
01009 }
01010 
01020 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
01021                                     const TCollection_AsciiString& theWidth,
01022                                     const TCollection_AsciiString& thePrecision,
01023                                     const TCollection_AsciiString& theTypePrefix,
01024                                     const Standard_Character theType,
01025                                     TCollection_AsciiString& theFormat )
01026 {
01027   Standard_Integer aPrecision = 0;
01028   if ( !thePrecision.IsEmpty() )
01029     aPrecision = thePrecision.IntegerValue();
01030   Standard_Integer aWidth = 0;
01031 
01032   if ( !theWidth.IsEmpty() )
01033     aWidth = theWidth.IntegerValue();
01034 
01035   if ( !thePrecision.IsEmpty() && aPrecision < 0 )
01036   {
01037     // possible value 0.1 will be 10.0
01038     aWidth -= aPrecision;
01039     aPrecision = 0;
01040   }
01041 
01042   if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
01043     aWidth = aPrecision + 2;
01044 
01045   theFormat = "%";
01046 
01047   theFormat += theFlags;
01048   if ( !theWidth.IsEmpty() )
01049     theFormat += aWidth;
01050 
01051   theFormat += theTypePrefix;
01052   theFormat += theType;
01053 }
01054 
01064 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
01065                                   const TCollection_AsciiString& theWidth,
01066                                   const TCollection_AsciiString& thePrecision,
01067                                   const TCollection_AsciiString& theTypePrefix,
01068                                   const Standard_Character theType,
01069                                   TCollection_AsciiString& theFormat )
01070 {
01071   Standard_Integer aPrecision = 0;
01072   if ( !thePrecision.IsEmpty() )
01073     aPrecision = thePrecision.IntegerValue();
01074   Standard_Integer aWidth = 0;
01075 
01076   if (!theWidth.IsEmpty() )
01077     aWidth = theWidth.IntegerValue();
01078 
01079   if (!thePrecision.IsEmpty() && aPrecision < 0 )
01080   {
01081     // possible value 0.1 will be 10.0
01082     aWidth -= aPrecision;
01083     aPrecision = 0;
01084   }
01085 
01086   if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
01087   {
01088     aWidth = aPrecision + 2;
01089   }
01090 
01091   theFormat = "%";
01092   theFormat += theFlags;
01093 
01094   if ( !theWidth.IsEmpty() ) 
01095     theFormat += aWidth;
01096 
01097   if ( !thePrecision.IsEmpty() ) 
01098   {
01099     theFormat += ".";
01100     theFormat += aPrecision;
01101   }
01102 
01103   theFormat += theTypePrefix;
01104   theFormat += theType;
01105 }
01106 
01111 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
01112 {
01113   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
01114   {
01115     UnitData& anUnitData = it.ChangeValue();
01116 
01117     anUnitData.myFormat = theFormat;
01118     anUnitData.myPrecision = 0;
01119   }
01120 
01121   TCollection_AsciiString aPrecisionStr;
01122   if ( theFormat.IsEmpty() && myType == List )
01123     return;
01124 
01125   // checking % presenting
01126   if ( *theFormat.ToCString() != '%' )
01127   {
01128     GetDefaultFormat();
01129     return;
01130   }
01131 
01132   TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
01133   Standard_Character aType = aStr.Value( aStr.Length() );
01134 
01135   if ( ( aType != 's' && myType == String ) ||
01136        ( aType != 'd' && myType == Integer ) ||
01137        ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
01138   {
01139     GetDefaultFormat();
01140     return;
01141   }
01142 
01143   // removing type character
01144   aStr.Trunc( aStr.Length() - 1 );
01145 
01146   TCollection_AsciiString aFlags;
01147   while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
01148   {
01149     aFlags = aFlags + aStr.Value( 1 );
01150     aStr.Remove( 1 );
01151   }
01152 
01153   Standard_Integer aPos = 1;
01154   while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
01155           ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
01156     aPos++;
01157 
01158   TCollection_AsciiString aTypePrefix;
01159   if ( aPos <= aStr.Length() )
01160   {
01161     aTypePrefix = aStr.SubString( aPos, aStr.Length() );
01162     aStr.Trunc( aPos - 1 );
01163   }
01164 
01165   Standard_Integer aBasePrecision = 0;
01166 
01167   // taking width and precision
01168   TCollection_AsciiString aPrecision;
01169 
01170   aPos = aStr.Search( "." );
01171   if ( aPos >= 0 ) 
01172   {
01173     // aPrecision is defined
01174     aPrecision = aStr.Split( aPos );
01175     aStr.Remove( aStr.Length() );
01176     if ( !aPrecision.IsEmpty() )
01177     {
01178       if ( !aPrecision.IsIntegerValue() ) 
01179       { 
01180         GetDefaultFormat();
01181         return;
01182       }
01183       else
01184       {
01185         aPrecisionStr  = aPrecision;
01186         aBasePrecision = aPrecision.IntegerValue();
01187       }
01188     }
01189   }
01190 
01191   if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
01192   {
01193     GetDefaultFormat();
01194     return;
01195   }
01196 
01197   NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
01198 
01199   switch ( myType )
01200   {
01201   case String:
01202     for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
01203     {
01204       if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
01205         GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
01206     }
01207     break;
01208   case Float:
01209   case Integer:
01210     for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
01211     {
01212       UnitData& anUnitData = itr.ChangeValue();
01213       Standard_Integer aAmendment =
01214         (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
01215       anUnitData.myPrecision = aBasePrecision + aAmendment;
01216       aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
01217 
01218       // create a formats
01219       if ( myType == Integer )
01220         GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
01221       else
01222         GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
01223     }
01224     break;
01225   default:;
01226     GetDefaultFormat();
01227     break;
01228   }
01229 }
01230 
01236 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
01237 {
01238   aRes.Nullify();
01239 
01240   if ( theStr.Length() > 0 )
01241   {
01242     TCollection_AsciiString aStr = theStr;
01243     TColStd_SequenceOfAsciiString aSeq;
01244     Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
01245     while( anIndex > 1 )
01246     {
01247       TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
01248       tmpStr.RemoveAll( ( Standard_Character )' ' );
01249       if ( tmpStr.Length() > 0 )
01250         aSeq.Append( tmpStr );
01251       anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
01252     }
01253 
01254     aStr.RemoveAll( ( Standard_Character )' ' );
01255     if ( aStr.Length() > 0 )
01256       aSeq.Append( aStr );
01257 
01258     if ( aSeq.Length() > 0 )
01259     {
01260       aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
01261       for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
01262         aRes->ChangeValue( i ) = aSeq( i );
01263     }
01264   }
01265 }
01266 
01272 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
01273 {
01274   UnitData* unit = 0;
01275 
01276   if ( myUnitData.IsBound( sys ) )
01277     unit = (UnitData*)&myUnitData.Find( sys );
01278 
01279   return unit;
01280 }
01281 
01286 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
01287 {
01288   UnitSystem aSystem;
01289   Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
01290   if ( !aComponent.IsNull() )
01291     aSystem = aComponent->GetActiveUnitSystem();
01292   return aSystem;
01293 }