1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "DDS_DicItem.h"
24 #include "DDS_Dictionary.h"
26 #include <TColStd_SequenceOfInteger.hxx>
27 #include <TColStd_SequenceOfExtendedString.hxx>
29 #include <LDOM_Text.hxx>
30 #include <LDOMString.hxx>
31 #include <LDOM_Element.hxx>
33 #include <UnitsAPI.hxx>
34 #include <Units_Dimensions.hxx>
36 #include <TColStd_MapOfReal.hxx>
37 #include <TColStd_SequenceOfAsciiString.hxx>
39 IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared)
40 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
44 \brief This class provides an information about datum (phisical characteristic parameter).
50 Creates the instance of empty dictionary item.
52 DDS_DicItem::DDS_DicItem()
64 \brief Copy constructor (put in private section to prevent object copying).
66 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
71 \brief Assignment operator (put in private section to prevent object copying).
73 void DDS_DicItem::operator=( const DDS_DicItem& )
78 \brief Get the identifier of parameter.
81 TCollection_AsciiString DDS_DicItem::GetId() const
87 \brief Get the type of parameter.
88 \return parameter type
90 DDS_DicItem::Type DDS_DicItem::GetType() const
92 return (DDS_DicItem::Type)myType;
96 \brief Get the label of the parameter.
97 \return parameter label
99 TCollection_ExtendedString DDS_DicItem::GetLabel() const
105 \brief Get the filter (regular expression) for the parameter values.
106 \return parameter filter
108 TCollection_ExtendedString DDS_DicItem::GetFilter() const
114 \brief Get the Required attribute of the parameter.
115 \return Required attribute
117 TCollection_ExtendedString DDS_DicItem::GetRequired() const
123 \brief Get the wrong value warning level of the parameter.
124 \return warning level
126 DDS_MsgType DDS_DicItem::GetWarningLevel() const
128 return (DDS_MsgType)myWarnLevel;
132 \brief Get the long description of the parameter.
133 \return long description
135 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
141 \brief Get the short description of the parameter.
142 \return short description
144 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
150 \brief Get the name of the component (parameter owner).
151 \return component name
153 TCollection_AsciiString DDS_DicItem::GetComponent() const
155 TCollection_AsciiString aCompName;
156 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
157 if ( !aComponent.IsNull() )
158 aCompName = aComponent->GetName();
163 \brief Get the parameter measure units for active units system.
164 \return parameter units
166 TCollection_AsciiString DDS_DicItem::GetUnits() const
168 return GetUnits( GetActiveUnitSystem() );
172 \brief Get the parameter measure units for specified units system \a theSystem.
174 If specified units system doesn't exist, empty string is returned.
176 \param theSystem units system
177 \return parameter units
179 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
181 TCollection_AsciiString anUnits;
182 UnitData* unitData = GetUnitData( theSystem );
184 anUnits = unitData->myUnits;
189 \brief Get the minimum value of the parameter for active units system.
191 Returned value is converted to SI.
193 \return minimum value
195 Standard_Real DDS_DicItem::GetMinValue() const
197 return GetMinValue( GetActiveUnitSystem() );
201 \brief Get the minimum value of the parameter for the specified
202 units system \a theSystem.
204 Returned value is converted to SI.
206 \param theUnitsSystem units system
207 \return minimum value
209 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
211 return FromSI( myMin, theUnitsSystem );
215 \brief Get the maximum value of the parameter for active units system.
217 Returned value converted to SI.
219 \return maximum value
221 Standard_Real DDS_DicItem::GetMaxValue() const
223 return GetMaxValue( GetActiveUnitSystem() );
227 \brief Get the maximum value of the parameter for specified
228 units system \a theSystem.
230 Returned value converted to SI.
232 \param theUnitsSystem units system
233 \return maximum value
235 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
237 return FromSI( myMax, theUnitsSystem );
241 \brief Get the precision (number of digits after decimal point)
242 of the parameter for active units system.
243 \return parameter precision
245 Standard_Integer DDS_DicItem::GetPrecision() const
247 return GetPrecision( GetActiveUnitSystem() );
251 \brief Get the precision (number of digits after decimal point) of the parameter
252 for specified units system \a theSystem.
254 If specified units system doesn't exist, zero is returned.
256 \param theSystem units system
257 \return parameter precision
259 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
261 Standard_Integer aRes = 0;
262 UnitData* unitData = GetUnitData( theSystem );
264 aRes = unitData->myPrecision;
269 \brief Get the default value of the parameter for active units system.
271 Default value is returned as string.
272 If type of the value is numerical (Float or Integer) and default value
273 is defined, then the returning value is converted to SI.
275 \return default value
277 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
279 return GetDefaultValue( GetActiveUnitSystem() );
283 \brief Get the default value of the parameter for specified
284 units system \a theSystem.
286 Default value is returned as string.
287 If type of the value is numerical (Float or Integer) and default value
288 is defined, then the returning value is converted to SI.
290 \param theSystem units system
291 \return default value
293 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
295 if ( !myDefString.Length() )
298 TCollection_ExtendedString aStr;
304 aStr = FromSI( myDefValue, theSystem );
317 \brief Get the format string of the parameter for active units system.
319 If argument \a theCanonical is \c true, format string is reduced according
320 to the sprintf() specification (without extra non standard qualifiers).
322 \param theCanonical 'canonical form' flag
323 \return format string
325 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
327 return GetFormat( GetActiveUnitSystem(), theCanonical );
331 \brief Get the format string of the parameter for specified
332 units system \a theSystem.
334 If argument \a theCanonical is \c true, format string is reduced according
335 to the sprintf() specification (without extra non standard qualifiers).
337 \param theSystem units system
338 \param theCanonical 'canonical form' flag
339 \return format string
341 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
342 const Standard_Boolean theCanonical ) const
344 TCollection_AsciiString aFormat;
345 UnitData* unitData = GetUnitData( theSystem );
347 aFormat = unitData->myFormat;
349 if ( theCanonical && aFormat.Length() > 1 )
351 static TCollection_AsciiString f;
353 Standard_Boolean isRemoved = false;
356 char ch = f.Value( f.Length() - 1 );
357 if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
358 f.Remove( f.Length() - 1 );
369 \brief Get the name of a list referenced by the parameter.
371 This string is empty if the list reference is not defined.
372 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
375 \return referenced list name
376 \sa GetListOfValues()
378 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
384 \brief Get item names and item identifiers of a list referenced
387 These sequences are empty if the list reference is not defined.
388 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
391 \param theStrings returning items names
392 \param theIntegers returning items identifiers
393 \return \c true if returning lists are not empty
394 \sa GetNameOfValues()
396 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
397 Handle(TColStd_HArray1OfInteger)& theIntegers ) const
399 theStrings = myListRef;
400 theIntegers = myListRefID;
401 return !theIntegers.IsNull() && !theStrings.IsNull();
405 \brief Get item names, item identifiers and item icons of a list
406 referenced by the parameter.
410 These sequences are empty if the list reference is not defined.
411 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
414 \param theStrings returning items names
415 \param theIntegers returning items identifiers
416 \param theIcons returning items icons
417 \return \c true if returning lists are not empty
418 \sa GetNameOfValues()
420 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
421 Handle(TColStd_HArray1OfInteger)& theIntegers,
422 Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
424 theStrings = myListRef;
425 theIntegers = myListRefID;
426 theIcons = myListRefIcons;
427 return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
432 \brief Get special values of the parameter.
433 \param theMap returning map of the special values
434 \return \c true if returning map is not empty
436 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
439 if ( !myListRef.IsNull() )
441 for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
443 if ( myListRef->Value( i ).IsAscii() )
445 TCollection_AsciiString aStr( myListRef->Value( i ) );
446 if ( aStr.IsRealValue() )
447 theMap.Add( aStr.RealValue() );
452 return theMap.Extent() > 0;
456 \brief Get minimum value of lateral zooming.
457 \return lateral zooming minimum value
459 Standard_Real DDS_DicItem::GetMinZoom() const
465 \brief Get maximum value of lateral zooming.
466 \return lateral zooming maximum value
468 Standard_Real DDS_DicItem::GetMaxZoom() const
474 \brief Get order of lateral zooming.
475 \return lateral zooming order
477 Standard_Real DDS_DicItem::GetZoomOrder() const
483 \brief Convert value \a theVal to the default SI units
484 according to the active units system.
485 \param theVal value being converted
486 \return value converted to SI
488 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
490 return ToSI( theVal, GetActiveUnitSystem() );
494 \brief Convert value \a theVal from the default SI units
495 according to the active units system.
496 \param theVal value being converted
497 \return value converted from SI
499 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
501 return FromSI( theVal, GetActiveUnitSystem() );
505 \brief Convert value to the default SI units according to the
506 units system \a theUnitsSystem.
507 \param theVal value being converted
508 \param theUnitsSystem units system
509 \return value converted to the specified units system
511 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
513 Standard_Real aRes = theVal;
514 UnitData* anUnitData = GetUnitData( theUnitsSystem );
516 aRes = anUnitData->myZero + aRes * anUnitData->myScale;
521 \brief Convert value from the default SI units according to the
522 units system \a theUnitsSystem.
523 \param theVal value being converted
524 \param theUnitsSystem units system
525 \return value converted from the specified units system
527 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
529 Standard_Real aRes = theVal;
530 UnitData* anUnitData = GetUnitData( theUnitsSystem );
532 aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
537 \brief Check data existence.
538 \param flag data flag
539 \return \c true if data specified by \a flag exists
541 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
543 return ( myData & flag ) == flag;
547 \brief Get option for specified name \a name.
549 If option is not found, empty string is returned.
551 \param name option name
554 TCollection_ExtendedString DDS_DicItem::GetOption( const TCollection_AsciiString& name ) const
556 TCollection_ExtendedString res;
557 if ( myOptions.IsBound( name ) )
558 res = myOptions.Find( name );
563 \brief Get names of all existing options.
564 \param names returning list of options
565 \return \c true if list is not empty
567 Standard_Boolean DDS_DicItem::GetOptionNames( TColStd_SequenceOfAsciiString& names ) const
571 for ( OptionsMap::Iterator it( myOptions ); it.More(); it.Next() )
572 names.Append( it.Key() );
574 return !names.IsEmpty();
579 \brief Parse record from XML file and retrieve information relevant for
581 \param theID item identifier
582 \param theDatum datum XML node
583 \param theCompElement component XML node
584 \param theDocElement document XML node
585 \param theSystems units system names
587 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
588 const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
589 const TColStd_SequenceOfAsciiString& theSystems )
591 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
592 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
593 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
594 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
596 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
598 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
600 UnitSystem anUnitSystem = theSystems.Value( j );
601 if ( !anUnitSystem.Length() )
604 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
606 if ( !myUnitData.IsBound( anUnitSystem ) )
607 myUnitData.Bind( anUnitSystem, UnitData() );
609 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
610 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
613 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
614 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
616 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
617 if ( units.Length() )
618 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
621 TCollection_AsciiString units;
622 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
623 units = iter.Value().myUnits;
625 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
627 UnitData& dataUnits = itr.ChangeValue();
628 if ( dataUnits.myUnits.IsEmpty() )
629 dataUnits.myUnits = units;
632 // 2. Elements ( domain, description )
633 Standard_Real aRealMinV = 0;
634 Standard_Real aRealMaxV = 0;
635 Standard_Real aRealDefV = 0;
637 TCollection_AsciiString aType;
639 DDS_MsgType aWrongValue = DDS_MT_NONE;
640 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
642 TCollection_AsciiString aMinV;
643 TCollection_AsciiString aMaxV;
644 TCollection_AsciiString aDefV;
645 TCollection_AsciiString aListName;
647 TCollection_AsciiString aLongD;
648 TCollection_AsciiString aShortD;
650 TColStd_SequenceOfInteger aSeqOfValueID;
651 TColStd_SequenceOfExtendedString aSeqOfValue;
652 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
655 Standard_Real aMinZoom = 0;
656 Standard_Real aMaxZoom = 0;
657 Standard_Real aZoomOrder = 0;
659 // Datum::Reports tags (if any)
660 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
661 if ( !aWLev.isNull() )
663 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
664 if ( aWrongValWL.IsEqual( "Info" ) )
665 aWrongValue = DDS_MT_INFO;
666 else if ( aWrongValWL.IsEqual( "Warning" ) )
667 aWrongValue = DDS_MT_WARNING;
668 else if ( aWrongValWL.IsEqual( "Alarm" ) )
669 aWrongValue = DDS_MT_ALARM;
670 else if ( aWrongValWL.IsEqual( "Error" ) )
671 aWrongValue = DDS_MT_ERROR;
674 // Datum::Presentation
675 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
676 if ( !aPrs.isNull() )
678 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
679 if ( !aLateralZoom.isNull() )
681 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
682 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
683 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
685 aMinZoomStr.RemoveAll( ' ' );
686 if ( aMinZoomStr.IsRealValue() )
687 aMinZoom = aMinZoomStr.RealValue();
689 aMaxZoomStr.RemoveAll( ' ' );
690 if ( aMaxZoomStr.IsRealValue() )
691 aMaxZoom = aMaxZoomStr.RealValue();
693 aZoomOrderStr.RemoveAll( ' ' );
694 if ( aZoomOrderStr.IsRealValue() )
695 aZoomOrder = aZoomOrderStr.RealValue();
699 // Quantity::Domain record as the only child of that tag name
700 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
701 if ( !aDomain.isNull() )
703 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
704 if ( !aValueDescr.isNull() )
706 // read: valueDescr? (type?,min?,max?,default?)
707 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
708 if ( aType.IsEqual( "String" ) )
710 else if ( aType.IsEqual( "Float" ) )
712 else if ( aType.IsEqual( "Integer" ) )
715 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
717 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
718 aMinV.RemoveAll( ' ' );
719 if ( aMinV.IsRealValue() )
720 aRealMinV = aMinV.RealValue();
721 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
723 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
724 aMaxV.RemoveAll( ' ' );
725 if ( aMaxV.IsRealValue() )
726 aRealMaxV = aMaxV.RealValue();
727 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
728 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
729 myData |= DefaultValue;
731 aDefV.RemoveAll( ' ' );
732 if ( aDefV.IsRealValue() )
733 aRealDefV = aDefV.RealValue();
735 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
736 Split( aSpecVal, myListRef );
740 // read: listRef? (list?)
741 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
742 if ( !aListRef.isNull() )
746 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
747 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
748 aDefV.RemoveAll( ' ' );
749 LDOM_Element foundListItem;
750 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
751 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
753 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
754 foundListItem = aListItem;
757 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
758 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
760 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
761 foundListItem = aLstItem;
764 if ( foundListItem != NULL )
766 // The appropriate list of values is found: store the list name
767 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
768 // Iteration through the list of values
769 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
770 while ( aListItemValue != NULL )
773 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
774 if ( aListValueID.IsIntegerValue() )
776 // Read the text in the element "value"
777 //LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
778 LDOM_Node aNode = aListItemValue.getFirstChild();
779 const LDOM_Text& aText = (const LDOM_Text&) aNode;
780 LDOM_Text aListItemTxt(aText);
781 if ( !aListItemTxt.isNull() )
783 // adding ID and text value to sequence
784 aSeqOfValueID.Append( aListValueID.IntegerValue() );
785 aSeqOfValue.Append( aListItemTxt.getData() );
786 // adding icon file name (optional) to sequence
787 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
788 aSeqOfValueIconName.Append( aListValueIcon );
790 aListItemValue = aListItemValue.GetSiblingByTagName();
798 // Quantity::Description record as the only child of that tag name
799 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
800 if ( !aDescr.isNull() )
802 // short description (#PCDATA)*
803 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
804 if ( !aShDescr.isNull() )
806 // text is always a sub-node of element, containing it
807 //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
808 LDOM_Node aNode = aShDescr.getFirstChild();
809 const LDOM_Text& aText = (const LDOM_Text&) aNode;
810 LDOM_Text aShDescrTxt(aText);
811 if ( !aShDescrTxt.isNull() )
812 aShortD = aShDescrTxt.getData();
815 // long description (#PCDATA)*
816 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
817 if ( !aLDescr.isNull() )
819 // text is always a sub-node of element, containing it
820 //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
821 LDOM_Node aNode = aLDescr.getFirstChild();
822 const LDOM_Text& aText = (const LDOM_Text&) aNode;
823 LDOM_Text aLDescrTxt(aText);
824 if ( !aLDescrTxt.isNull() )
825 aLongD = aLDescrTxt.getData();
830 LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) );
831 if ( !anOpt.isNull() )
833 LDOM_NodeList anOptions = anOpt.GetAttributesList();//anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) );
834 for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ )
836 LDOM_Node node = anOptions.item( oi );
837 LDOM_Node::NodeType t = node.getNodeType();
839 TCollection_AsciiString name;
840 TCollection_ExtendedString value;
842 if( t==LDOM_Node::ELEMENT_NODE )
844 const LDOM_Element& elem = ( const LDOM_Element& )node;
845 name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) );
847 const LDOM_Node aNode = elem.getFirstChild();
848 LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) );
849 if ( !anOptTxt.isNull() )
850 value = anOptTxt.getData();
852 else if( t==LDOM_Node::ATTRIBUTE_NODE )
854 const LDOM_Attr& attr = ( const LDOM_Attr& )node;
855 name = ( Standard_CString )attr.getName().GetString();
856 LDOMString v = attr.getValue();
857 if( v.Type()==LDOMBasicString::LDOM_Integer )
859 Standard_Integer ival;
860 v.GetInteger( ival );
861 value = TCollection_ExtendedString( ival );
864 value = ( Standard_CString )v.GetString();
869 if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) )
870 myOptions.Bind( name, value );
874 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
876 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
878 UnitData& anUnitData = it.ChangeValue();
881 anUnitData.myZero = 0.;
882 anUnitData.myScale = 1.;
884 Standard_CString aUnitDataStr;
885 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
886 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
888 Handle(Units_Dimensions) aDim;
889 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
890 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
891 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
892 if ( !aDimMap.IsBound( it.Key() ) )
893 aDimMap.Bind( it.Key(), aDim );
895 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
896 anUnitData.myScale = 0.01;
898 catch( Standard_Failure ) {
899 anUnitData.myUnits.Clear();
902 Handle(Units_Dimensions) aPrev;
903 Standard_Boolean aStatus = Standard_True;
904 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
905 itr.More() && aStatus; itr.Next() )
907 if ( itr.Value().IsNull() )
910 if ( aPrev.IsNull() )
913 aStatus = aPrev->IsEqual( itr.Value() );
917 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
922 myWarnLevel = aWrongValue;
923 myLabel = aLabel.ToCString();
924 myFilter = aFilter.ToCString();
925 myLongDescr = aLongD.ToCString();
926 myShortDescr = aShortD.ToCString();
929 myDefValue = aRealDefV;
930 myDefString = aDefV.ToCString();
931 myRequired = aRequired.ToCString();
932 myListName = aListName.ToCString();
933 myMinZoom = aMinZoom;
934 myMaxZoom = aMaxZoom;
935 myZoomOrder = aZoomOrder;
938 PrepareFormats( aFormat );
940 const Standard_Integer aLength = aSeqOfValue.Length();
943 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
944 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
945 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
946 for ( Standard_Integer i = aLength; i > 0; i-- )
948 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
949 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
950 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
954 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
955 myDefString = myListRef->Value( myListRef->Lower() );
959 \brief Restore default formats for all the units systems.
961 void DDS_DicItem::GetDefaultFormat()
963 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
965 UnitData& anUnitData = it.ChangeValue();
970 anUnitData.myFormat = "%d";
973 anUnitData.myFormat = "%g";
977 anUnitData.myFormat.Clear();
984 \brief Get format for the string.
985 \param theFlags format flags
986 \param theWidth field width
987 \param thePrecision precision
988 \param theTypePrefix type prefix
989 \param theFormat returning format string
991 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
992 const TCollection_AsciiString& theWidth,
993 const TCollection_AsciiString& thePrecision,
994 const TCollection_AsciiString& theTypePrefix,
995 TCollection_AsciiString& theFormat )
998 theFormat += theFlags;
999 theFormat += theWidth;
1001 if ( !thePrecision.IsEmpty() )
1004 theFormat += thePrecision;
1007 theFormat += theTypePrefix;
1012 \brief Get format for the integer.
1013 \param theFlags format flags
1014 \param theWidth field width
1015 \param thePrecision precision
1016 \param theTypePrefix type prefix
1017 \param theType integer value type
1018 \param theFormat returning format string
1020 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
1021 const TCollection_AsciiString& theWidth,
1022 const TCollection_AsciiString& thePrecision,
1023 const TCollection_AsciiString& theTypePrefix,
1024 const Standard_Character theType,
1025 TCollection_AsciiString& theFormat )
1027 Standard_Integer aPrecision = 0;
1028 if ( !thePrecision.IsEmpty() )
1029 aPrecision = thePrecision.IntegerValue();
1030 Standard_Integer aWidth = 0;
1032 if ( !theWidth.IsEmpty() )
1033 aWidth = theWidth.IntegerValue();
1035 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
1037 // possible value 0.1 will be 10.0
1038 aWidth -= aPrecision;
1042 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1043 aWidth = aPrecision + 2;
1047 theFormat += theFlags;
1048 if ( !theWidth.IsEmpty() )
1049 theFormat += aWidth;
1051 theFormat += theTypePrefix;
1052 theFormat += theType;
1056 \brief Returns format for the float.
1057 \param theFlags format flags
1058 \param theWidth field width
1059 \param thePrecision precision
1060 \param theTypePrefix type prefix
1061 \param theType floating point value type
1062 \param theFormat returning format string
1064 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
1065 const TCollection_AsciiString& theWidth,
1066 const TCollection_AsciiString& thePrecision,
1067 const TCollection_AsciiString& theTypePrefix,
1068 const Standard_Character theType,
1069 TCollection_AsciiString& theFormat )
1071 Standard_Integer aPrecision = 0;
1072 if ( !thePrecision.IsEmpty() )
1073 aPrecision = thePrecision.IntegerValue();
1074 Standard_Integer aWidth = 0;
1076 if (!theWidth.IsEmpty() )
1077 aWidth = theWidth.IntegerValue();
1079 if (!thePrecision.IsEmpty() && aPrecision < 0 )
1081 // possible value 0.1 will be 10.0
1082 aWidth -= aPrecision;
1086 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1088 aWidth = aPrecision + 2;
1092 theFormat += theFlags;
1094 if ( !theWidth.IsEmpty() )
1095 theFormat += aWidth;
1097 if ( !thePrecision.IsEmpty() )
1100 theFormat += aPrecision;
1103 theFormat += theTypePrefix;
1104 theFormat += theType;
1108 \brief Prepare formats for all units systems.
1109 \param theFormat format string
1111 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
1113 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
1115 UnitData& anUnitData = it.ChangeValue();
1117 anUnitData.myFormat = theFormat;
1118 anUnitData.myPrecision = 0;
1121 TCollection_AsciiString aPrecisionStr;
1122 if ( theFormat.IsEmpty() && myType == List )
1125 // checking % presenting
1126 if ( *theFormat.ToCString() != '%' )
1132 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
1133 Standard_Character aType = aStr.Value( aStr.Length() );
1135 if ( ( aType != 's' && myType == String ) ||
1136 ( aType != 'd' && myType == Integer ) ||
1137 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
1143 // removing type character
1144 aStr.Trunc( aStr.Length() - 1 );
1146 TCollection_AsciiString aFlags;
1147 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
1149 aFlags = aFlags + aStr.Value( 1 );
1153 Standard_Integer aPos = 1;
1154 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
1155 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
1158 TCollection_AsciiString aTypePrefix;
1159 if ( aPos <= aStr.Length() )
1161 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
1162 aStr.Trunc( aPos - 1 );
1165 Standard_Integer aBasePrecision = 0;
1167 // taking width and precision
1168 TCollection_AsciiString aPrecision;
1170 aPos = aStr.Search( "." );
1173 // aPrecision is defined
1174 aPrecision = aStr.Split( aPos );
1175 aStr.Remove( aStr.Length() );
1176 if ( !aPrecision.IsEmpty() )
1178 if ( !aPrecision.IsIntegerValue() )
1185 aPrecisionStr = aPrecision;
1186 aBasePrecision = aPrecision.IntegerValue();
1191 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
1197 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
1202 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1204 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
1205 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
1210 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1212 UnitData& anUnitData = itr.ChangeValue();
1213 Standard_Integer aAmendment =
1214 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
1215 anUnitData.myPrecision = aBasePrecision + aAmendment;
1216 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
1219 if ( myType == Integer )
1220 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1222 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1232 \brief Split the string \a theStr separated by spaces.
1233 \param theStr source string
1234 \param aRes returning substrings array
1236 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
1240 if ( theStr.Length() > 0 )
1242 TCollection_AsciiString aStr = theStr;
1243 TColStd_SequenceOfAsciiString aSeq;
1244 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1245 while( anIndex > 1 )
1247 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
1248 tmpStr.RemoveAll( ( Standard_Character )' ' );
1249 if ( tmpStr.Length() > 0 )
1250 aSeq.Append( tmpStr );
1251 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1254 aStr.RemoveAll( ( Standard_Character )' ' );
1255 if ( aStr.Length() > 0 )
1256 aSeq.Append( aStr );
1258 if ( aSeq.Length() > 0 )
1260 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
1261 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
1262 aRes->ChangeValue( i ) = aSeq( i );
1268 \brief Get units structure for specified units system \a sys.
1269 \param sys units system
1270 \return units system information structure
1272 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
1276 if ( myUnitData.IsBound( sys ) )
1277 unit = (UnitData*)&myUnitData.Find( sys );
1283 \brief Get the active units system.
1284 \return active units system
1286 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
1289 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
1290 if ( !aComponent.IsNull() )
1291 aSystem = aComponent->GetActiveUnitSystem();