1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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 <LDOM_Text.hxx>
27 #include <LDOMString.hxx>
28 #include <LDOM_Element.hxx>
30 #include <UnitsAPI.hxx>
31 #include <Units_Dimensions.hxx>
33 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, Standard_Transient)
37 \brief This class provides an information about datum (phisical characteristic parameter).
43 Creates the instance of empty dictionary item.
45 DDS_DicItem::DDS_DicItem()
57 \brief Copy constructor (put in private section to prevent object copying).
59 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
60 : Standard_Transient()
65 \brief Assignment operator (put in private section to prevent object copying).
67 void DDS_DicItem::operator=( const DDS_DicItem& )
72 \brief Get the identifier of parameter.
75 TCollection_AsciiString DDS_DicItem::GetId() const
81 \brief Get the type of parameter.
82 \return parameter type
84 DDS_DicItem::Type DDS_DicItem::GetType() const
86 return (DDS_DicItem::Type)myType;
90 \brief Get the label of the parameter.
91 \return parameter label
93 TCollection_ExtendedString DDS_DicItem::GetLabel() const
99 \brief Get the filter (regular expression) for the parameter values.
100 \return parameter filter
102 TCollection_ExtendedString DDS_DicItem::GetFilter() const
108 \brief Get the Required attribute of the parameter.
109 \return Required attribute
111 TCollection_ExtendedString DDS_DicItem::GetRequired() const
117 \brief Get the wrong value warning level of the parameter.
118 \return warning level
120 DDS_MsgType DDS_DicItem::GetWarningLevel() const
122 return (DDS_MsgType)myWarnLevel;
126 \brief Get the long description of the parameter.
127 \return long description
129 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
135 \brief Get the short description of the parameter.
136 \return short description
138 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
144 \brief Get the name of the component (parameter owner).
145 \return component name
147 TCollection_AsciiString DDS_DicItem::GetComponent() const
149 TCollection_AsciiString aCompName;
150 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
151 if ( !aComponent.IsNull() )
152 aCompName = aComponent->GetName();
157 \brief Get the parameter measure units for active units system.
158 \return parameter units
160 TCollection_AsciiString DDS_DicItem::GetUnits() const
162 return GetUnits( GetActiveUnitSystem() );
166 \brief Get the parameter measure units for specified units system \a theSystem.
168 If specified units system doesn't exist, empty string is returned.
170 \param theSystem units system
171 \return parameter units
173 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
175 TCollection_AsciiString anUnits;
176 UnitData* unitData = GetUnitData( theSystem );
178 anUnits = unitData->myUnits;
183 \brief Get the minimum value of the parameter for active units system.
185 Returned value is converted to SI.
187 \return minimum value
189 Standard_Real DDS_DicItem::GetMinValue() const
191 return GetMinValue( GetActiveUnitSystem() );
195 \brief Get the minimum value of the parameter for the specified
196 units system \a theSystem.
198 Returned value is converted to SI.
200 \param theUnitsSystem units system
201 \return minimum value
203 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
205 return FromSI( myMin, theUnitsSystem );
209 \brief Get the maximum value of the parameter for active units system.
211 Returned value converted to SI.
213 \return maximum value
215 Standard_Real DDS_DicItem::GetMaxValue() const
217 return GetMaxValue( GetActiveUnitSystem() );
221 \brief Get the maximum value of the parameter for specified
222 units system \a theSystem.
224 Returned value converted to SI.
226 \param theUnitsSystem units system
227 \return maximum value
229 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
231 return FromSI( myMax, theUnitsSystem );
235 \brief Get the precision (number of digits after decimal point)
236 of the parameter for active units system.
237 \return parameter precision
239 Standard_Integer DDS_DicItem::GetPrecision() const
241 return GetPrecision( GetActiveUnitSystem() );
245 \brief Get the precision (number of digits after decimal point) of the parameter
246 for specified units system \a theSystem.
248 If specified units system doesn't exist, zero is returned.
250 \param theSystem units system
251 \return parameter precision
253 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
255 Standard_Integer aRes = 0;
256 UnitData* unitData = GetUnitData( theSystem );
258 aRes = unitData->myPrecision;
263 \brief Get the default value of the parameter for active units system.
265 Default value is returned as string.
266 If type of the value is numerical (Float or Integer) and default value
267 is defined, then the returning value is converted to SI.
269 \return default value
271 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
273 return GetDefaultValue( GetActiveUnitSystem() );
277 \brief Get the default value of the parameter for specified
278 units system \a theSystem.
280 Default value is returned as string.
281 If type of the value is numerical (Float or Integer) and default value
282 is defined, then the returning value is converted to SI.
284 \param theSystem units system
285 \return default value
287 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
289 if ( !myDefString.Length() )
292 TCollection_ExtendedString aStr;
298 aStr = FromSI( myDefValue, theSystem );
311 \brief Get the format string of the parameter for active units system.
313 If argument \a theCanonical is \c true, format string is reduced according
314 to the sprintf() specification (without extra non standard qualifiers).
316 \param theCanonical 'canonical form' flag
317 \return format string
319 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
321 return GetFormat( GetActiveUnitSystem(), theCanonical );
325 \brief Get the format string of the parameter for specified
326 units system \a theSystem.
328 If argument \a theCanonical is \c true, format string is reduced according
329 to the sprintf() specification (without extra non standard qualifiers).
331 \param theSystem units system
332 \param theCanonical 'canonical form' flag
333 \return format string
335 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
336 const Standard_Boolean theCanonical ) const
338 TCollection_AsciiString aFormat;
339 UnitData* unitData = GetUnitData( theSystem );
341 aFormat = unitData->myFormat;
343 if ( theCanonical && aFormat.Length() > 1 )
345 static TCollection_AsciiString f;
347 Standard_Boolean isRemoved = false;
350 char ch = f.Value( f.Length() - 1 );
351 if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
352 f.Remove( f.Length() - 1 );
363 \brief Get the name of a list referenced by the parameter.
365 This string is empty if the list reference is not defined.
366 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
369 \return referenced list name
370 \sa GetListOfValues()
372 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
378 \brief Get item names and item identifiers of a list referenced
381 These sequences are empty if the list reference is not defined.
382 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
385 \param theStrings returning items names
386 \param theIntegers returning items identifiers
387 \return \c true if returning lists are not empty
388 \sa GetNameOfValues()
390 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
391 Handle(TColStd_HArray1OfInteger)& theIntegers ) const
393 theStrings = myListRef;
394 theIntegers = myListRefID;
395 return !theIntegers.IsNull() && !theStrings.IsNull();
399 \brief Get item names, item identifiers and item icons of a list
400 referenced by the parameter.
404 These sequences are empty if the list reference is not defined.
405 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
408 \param theStrings returning items names
409 \param theIntegers returning items identifiers
410 \param theIcons returning items icons
411 \return \c true if returning lists are not empty
412 \sa GetNameOfValues()
414 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
415 Handle(TColStd_HArray1OfInteger)& theIntegers,
416 Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
418 theStrings = myListRef;
419 theIntegers = myListRefID;
420 theIcons = myListRefIcons;
421 return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
426 \brief Get special values of the parameter.
427 \param theMap returning map of the special values
428 \return \c true if returning map is not empty
430 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
433 if ( !myListRef.IsNull() )
435 for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
437 if ( myListRef->Value( i ).IsAscii() )
439 TCollection_AsciiString aStr( myListRef->Value( i ) );
440 if ( aStr.IsRealValue() )
441 theMap.Add( aStr.RealValue() );
446 return theMap.Extent() > 0;
450 \brief Get minimum value of lateral zooming.
451 \return lateral zooming minimum value
453 Standard_Real DDS_DicItem::GetMinZoom() const
459 \brief Get maximum value of lateral zooming.
460 \return lateral zooming maximum value
462 Standard_Real DDS_DicItem::GetMaxZoom() const
468 \brief Get order of lateral zooming.
469 \return lateral zooming order
471 Standard_Real DDS_DicItem::GetZoomOrder() const
477 \brief Convert value \a theVal to the default SI units
478 according to the active units system.
479 \param theVal value being converted
480 \return value converted to SI
482 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
484 return ToSI( theVal, GetActiveUnitSystem() );
488 \brief Convert value \a theVal from the default SI units
489 according to the active units system.
490 \param theVal value being converted
491 \return value converted from SI
493 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
495 return FromSI( theVal, GetActiveUnitSystem() );
499 \brief Convert value to the default SI units according to the
500 units system \a theUnitsSystem.
501 \param theVal value being converted
502 \param theUnitsSystem units system
503 \return value converted to the specified units system
505 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
507 Standard_Real aRes = theVal;
508 UnitData* anUnitData = GetUnitData( theUnitsSystem );
510 aRes = anUnitData->myZero + aRes * anUnitData->myScale;
515 \brief Convert value from the default SI units according to the
516 units system \a theUnitsSystem.
517 \param theVal value being converted
518 \param theUnitsSystem units system
519 \return value converted from the specified units system
521 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
523 Standard_Real aRes = theVal;
524 UnitData* anUnitData = GetUnitData( theUnitsSystem );
526 aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
531 \brief Check data existence.
532 \param flag data flag
533 \return \c true if data specified by \a flag exists
535 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
537 return ( myData & flag ) == flag;
541 \brief Get option for specified name \a name.
543 If option is not found, empty string is returned.
545 \param name option name
548 TCollection_ExtendedString DDS_DicItem::GetOption( const TCollection_AsciiString& name ) const
550 TCollection_ExtendedString res;
551 if ( myOptions.IsBound( name ) )
552 res = myOptions.Find( name );
557 \brief Get names of all existing options.
558 \param names returning list of options
559 \return \c true if list is not empty
561 Standard_Boolean DDS_DicItem::GetOptionNames( TColStd_SequenceOfAsciiString& names ) const
565 for ( OptionsMap::Iterator it( myOptions ); it.More(); it.Next() )
566 names.Append( it.Key() );
568 return !names.IsEmpty();
573 \brief Parse record from XML file and retrieve information relevant for
575 \param theID item identifier
576 \param theDatum datum XML node
577 \param theCompElement component XML node
578 \param theDocElement document XML node
579 \param theSystems units system names
581 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
582 const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
583 const TColStd_SequenceOfAsciiString& theSystems )
585 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
586 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
587 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
588 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
590 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
592 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
594 UnitSystem anUnitSystem = theSystems.Value( j );
595 if ( !anUnitSystem.Length() )
598 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
600 if ( !myUnitData.IsBound( anUnitSystem ) )
601 myUnitData.Bind( anUnitSystem, UnitData() );
603 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
604 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
607 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
608 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
610 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
611 if ( units.Length() )
612 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
615 TCollection_AsciiString units;
616 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
617 units = iter.Value().myUnits;
619 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
621 UnitData& dataUnits = itr.ChangeValue();
622 if ( dataUnits.myUnits.IsEmpty() )
623 dataUnits.myUnits = units;
626 // 2. Elements ( domain, description )
627 Standard_Real aRealMinV = 0;
628 Standard_Real aRealMaxV = 0;
629 Standard_Real aRealDefV = 0;
631 TCollection_AsciiString aType;
633 DDS_MsgType aWrongValue = DDS_MT_NONE;
634 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
636 TCollection_AsciiString aMinV;
637 TCollection_AsciiString aMaxV;
638 TCollection_AsciiString aDefV;
639 TCollection_AsciiString aListName;
641 TCollection_AsciiString aLongD;
642 TCollection_AsciiString aShortD;
644 TColStd_SequenceOfInteger aSeqOfValueID;
645 TColStd_SequenceOfExtendedString aSeqOfValue;
646 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
649 Standard_Real aMinZoom = 0;
650 Standard_Real aMaxZoom = 0;
651 Standard_Real aZoomOrder = 0;
653 // Datum::Reports tags (if any)
654 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
655 if ( !aWLev.isNull() )
657 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
658 if ( aWrongValWL.IsEqual( "Info" ) )
659 aWrongValue = DDS_MT_INFO;
660 else if ( aWrongValWL.IsEqual( "Warning" ) )
661 aWrongValue = DDS_MT_WARNING;
662 else if ( aWrongValWL.IsEqual( "Alarm" ) )
663 aWrongValue = DDS_MT_ALARM;
664 else if ( aWrongValWL.IsEqual( "Error" ) )
665 aWrongValue = DDS_MT_ERROR;
668 // Datum::Presentation
669 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
670 if ( !aPrs.isNull() )
672 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
673 if ( !aLateralZoom.isNull() )
675 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
676 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
677 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
679 aMinZoomStr.RemoveAll( ' ' );
680 if ( aMinZoomStr.IsRealValue() )
681 aMinZoom = aMinZoomStr.RealValue();
683 aMaxZoomStr.RemoveAll( ' ' );
684 if ( aMaxZoomStr.IsRealValue() )
685 aMaxZoom = aMaxZoomStr.RealValue();
687 aZoomOrderStr.RemoveAll( ' ' );
688 if ( aZoomOrderStr.IsRealValue() )
689 aZoomOrder = aZoomOrderStr.RealValue();
693 // Quantity::Domain record as the only child of that tag name
694 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
695 if ( !aDomain.isNull() )
697 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
698 if ( !aValueDescr.isNull() )
700 // read: valueDescr? (type?,min?,max?,default?)
701 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
702 if ( aType.IsEqual( "String" ) )
704 else if ( aType.IsEqual( "Float" ) )
706 else if ( aType.IsEqual( "Integer" ) )
709 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
711 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
712 aMinV.RemoveAll( ' ' );
713 if ( aMinV.IsRealValue() )
714 aRealMinV = aMinV.RealValue();
715 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
717 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
718 aMaxV.RemoveAll( ' ' );
719 if ( aMaxV.IsRealValue() )
720 aRealMaxV = aMaxV.RealValue();
721 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
722 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
723 myData |= DefaultValue;
725 aDefV.RemoveAll( ' ' );
726 if ( aDefV.IsRealValue() )
727 aRealDefV = aDefV.RealValue();
729 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
730 Split( aSpecVal, myListRef );
734 // read: listRef? (list?)
735 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
736 if ( !aListRef.isNull() )
740 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
741 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
742 aDefV.RemoveAll( ' ' );
743 LDOM_Element foundListItem;
744 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
745 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
747 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
748 foundListItem = aListItem;
751 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
752 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
754 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
755 foundListItem = aLstItem;
758 if ( foundListItem != NULL )
760 // The appropriate list of values is found: store the list name
761 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
762 // Iteration through the list of values
763 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
764 while ( aListItemValue != NULL )
767 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
768 if ( aListValueID.IsIntegerValue() )
770 // Read the text in the element "value"
771 //LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
772 LDOM_Node aNode = aListItemValue.getFirstChild();
773 const LDOM_Text& aText = (const LDOM_Text&) aNode;
774 LDOM_Text aListItemTxt(aText);
775 if ( !aListItemTxt.isNull() )
777 // adding ID and text value to sequence
778 aSeqOfValueID.Append( aListValueID.IntegerValue() );
779 aSeqOfValue.Append( aListItemTxt.getData() );
780 // adding icon file name (optional) to sequence
781 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
782 aSeqOfValueIconName.Append( aListValueIcon );
784 aListItemValue = aListItemValue.GetSiblingByTagName();
792 // Quantity::Description record as the only child of that tag name
793 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
794 if ( !aDescr.isNull() )
796 // short description (#PCDATA)*
797 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
798 if ( !aShDescr.isNull() )
800 // text is always a sub-node of element, containing it
801 //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
802 LDOM_Node aNode = aShDescr.getFirstChild();
803 const LDOM_Text& aText = (const LDOM_Text&) aNode;
804 LDOM_Text aShDescrTxt(aText);
805 if ( !aShDescrTxt.isNull() )
806 aShortD = aShDescrTxt.getData();
809 // long description (#PCDATA)*
810 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
811 if ( !aLDescr.isNull() )
813 // text is always a sub-node of element, containing it
814 //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
815 LDOM_Node aNode = aLDescr.getFirstChild();
816 const LDOM_Text& aText = (const LDOM_Text&) aNode;
817 LDOM_Text aLDescrTxt(aText);
818 if ( !aLDescrTxt.isNull() )
819 aLongD = aLDescrTxt.getData();
824 LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) );
825 if ( !anOpt.isNull() )
827 LDOM_NodeList anOptions = anOpt.GetAttributesList();//anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) );
828 for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ )
830 LDOM_Node node = anOptions.item( oi );
831 LDOM_Node::NodeType t = node.getNodeType();
833 TCollection_AsciiString name;
834 TCollection_ExtendedString value;
836 if( t==LDOM_Node::ELEMENT_NODE )
838 const LDOM_Element& elem = ( const LDOM_Element& )node;
839 name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) );
841 const LDOM_Node aNode = elem.getFirstChild();
842 LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) );
843 if ( !anOptTxt.isNull() )
844 value = anOptTxt.getData();
846 else if( t==LDOM_Node::ATTRIBUTE_NODE )
848 const LDOM_Attr& attr = ( const LDOM_Attr& )node;
849 name = ( Standard_CString )attr.getName().GetString();
850 LDOMString v = attr.getValue();
851 if( v.Type()==LDOMBasicString::LDOM_Integer )
853 Standard_Integer ival;
854 v.GetInteger( ival );
855 value = TCollection_ExtendedString( ival );
858 value = ( Standard_CString )v.GetString();
863 if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) )
864 myOptions.Bind( name, value );
868 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
870 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
872 UnitData& anUnitData = it.ChangeValue();
875 anUnitData.myZero = 0.;
876 anUnitData.myScale = 1.;
878 Standard_CString aUnitDataStr;
879 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
880 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
882 Handle(Units_Dimensions) aDim;
883 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
884 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
885 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
886 if ( !aDimMap.IsBound( it.Key() ) )
887 aDimMap.Bind( it.Key(), aDim );
889 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
890 anUnitData.myScale = 0.01;
892 catch( Standard_Failure& ) {
893 anUnitData.myUnits.Clear();
896 Handle(Units_Dimensions) aPrev;
897 Standard_Boolean aStatus = Standard_True;
898 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
899 itr.More() && aStatus; itr.Next() )
901 if ( itr.Value().IsNull() )
904 if ( aPrev.IsNull() )
907 aStatus = aPrev->IsEqual( itr.Value() );
911 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
916 myWarnLevel = aWrongValue;
917 myLabel = aLabel.ToCString();
918 myFilter = aFilter.ToCString();
919 myLongDescr = aLongD.ToCString();
920 myShortDescr = aShortD.ToCString();
923 myDefValue = aRealDefV;
924 myDefString = aDefV.ToCString();
925 myRequired = aRequired.ToCString();
926 myListName = aListName.ToCString();
927 myMinZoom = aMinZoom;
928 myMaxZoom = aMaxZoom;
929 myZoomOrder = aZoomOrder;
932 PrepareFormats( aFormat );
934 const Standard_Integer aLength = aSeqOfValue.Length();
937 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
938 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
939 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
940 for ( Standard_Integer i = aLength; i > 0; i-- )
942 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
943 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
944 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
948 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
949 myDefString = myListRef->Value( myListRef->Lower() );
953 \brief Restore default formats for all the units systems.
955 void DDS_DicItem::GetDefaultFormat()
957 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
959 UnitData& anUnitData = it.ChangeValue();
964 anUnitData.myFormat = "%d";
967 anUnitData.myFormat = "%g";
971 anUnitData.myFormat.Clear();
978 \brief Get format for the string.
979 \param theFlags format flags
980 \param theWidth field width
981 \param thePrecision precision
982 \param theTypePrefix type prefix
983 \param theFormat returning format string
985 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
986 const TCollection_AsciiString& theWidth,
987 const TCollection_AsciiString& thePrecision,
988 const TCollection_AsciiString& theTypePrefix,
989 TCollection_AsciiString& theFormat )
992 theFormat += theFlags;
993 theFormat += theWidth;
995 if ( !thePrecision.IsEmpty() )
998 theFormat += thePrecision;
1001 theFormat += theTypePrefix;
1006 \brief Get format for the integer.
1007 \param theFlags format flags
1008 \param theWidth field width
1009 \param thePrecision precision
1010 \param theTypePrefix type prefix
1011 \param theType integer value type
1012 \param theFormat returning format string
1014 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
1015 const TCollection_AsciiString& theWidth,
1016 const TCollection_AsciiString& thePrecision,
1017 const TCollection_AsciiString& theTypePrefix,
1018 const Standard_Character theType,
1019 TCollection_AsciiString& theFormat )
1021 Standard_Integer aPrecision = 0;
1022 if ( !thePrecision.IsEmpty() )
1023 aPrecision = thePrecision.IntegerValue();
1024 Standard_Integer aWidth = 0;
1026 if ( !theWidth.IsEmpty() )
1027 aWidth = theWidth.IntegerValue();
1029 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
1031 // possible value 0.1 will be 10.0
1032 aWidth -= aPrecision;
1036 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1037 aWidth = aPrecision + 2;
1041 theFormat += theFlags;
1042 if ( !theWidth.IsEmpty() )
1043 theFormat += aWidth;
1045 theFormat += theTypePrefix;
1046 theFormat += theType;
1050 \brief Returns format for the float.
1051 \param theFlags format flags
1052 \param theWidth field width
1053 \param thePrecision precision
1054 \param theTypePrefix type prefix
1055 \param theType floating point value type
1056 \param theFormat returning format string
1058 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
1059 const TCollection_AsciiString& theWidth,
1060 const TCollection_AsciiString& thePrecision,
1061 const TCollection_AsciiString& theTypePrefix,
1062 const Standard_Character theType,
1063 TCollection_AsciiString& theFormat )
1065 Standard_Integer aPrecision = 0;
1066 if ( !thePrecision.IsEmpty() )
1067 aPrecision = thePrecision.IntegerValue();
1068 Standard_Integer aWidth = 0;
1070 if (!theWidth.IsEmpty() )
1071 aWidth = theWidth.IntegerValue();
1073 if (!thePrecision.IsEmpty() && aPrecision < 0 )
1075 // possible value 0.1 will be 10.0
1076 aWidth -= aPrecision;
1080 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1082 aWidth = aPrecision + 2;
1086 theFormat += theFlags;
1088 if ( !theWidth.IsEmpty() )
1089 theFormat += aWidth;
1091 if ( !thePrecision.IsEmpty() )
1094 theFormat += aPrecision;
1097 theFormat += theTypePrefix;
1098 theFormat += theType;
1102 \brief Prepare formats for all units systems.
1103 \param theFormat format string
1105 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
1107 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
1109 UnitData& anUnitData = it.ChangeValue();
1111 anUnitData.myFormat = theFormat;
1112 anUnitData.myPrecision = 0;
1115 TCollection_AsciiString aPrecisionStr;
1116 if ( theFormat.IsEmpty() && myType == List )
1119 // checking % presenting
1120 if ( *theFormat.ToCString() != '%' )
1126 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
1127 Standard_Character aType = aStr.Value( aStr.Length() );
1129 if ( ( aType != 's' && myType == String ) ||
1130 ( aType != 'd' && myType == Integer ) ||
1131 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
1137 // removing type character
1138 aStr.Trunc( aStr.Length() - 1 );
1140 TCollection_AsciiString aFlags;
1141 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
1143 aFlags = aFlags + aStr.Value( 1 );
1147 Standard_Integer aPos = 1;
1148 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
1149 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
1152 TCollection_AsciiString aTypePrefix;
1153 if ( aPos <= aStr.Length() )
1155 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
1156 aStr.Trunc( aPos - 1 );
1159 Standard_Integer aBasePrecision = 0;
1161 // taking width and precision
1162 TCollection_AsciiString aPrecision;
1164 aPos = aStr.Search( "." );
1167 // aPrecision is defined
1168 aPrecision = aStr.Split( aPos );
1169 aStr.Remove( aStr.Length() );
1170 if ( !aPrecision.IsEmpty() )
1172 if ( !aPrecision.IsIntegerValue() )
1179 aPrecisionStr = aPrecision;
1180 aBasePrecision = aPrecision.IntegerValue();
1185 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
1191 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
1196 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1198 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
1199 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
1204 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1206 UnitData& anUnitData = itr.ChangeValue();
1207 Standard_Integer aAmendment =
1208 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
1209 anUnitData.myPrecision = aBasePrecision + aAmendment;
1210 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
1213 if ( myType == Integer )
1214 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1216 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1226 \brief Split the string \a theStr separated by spaces.
1227 \param theStr source string
1228 \param aRes returning substrings array
1230 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
1234 if ( theStr.Length() > 0 )
1236 TCollection_AsciiString aStr = theStr;
1237 TColStd_SequenceOfAsciiString aSeq;
1238 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1239 while( anIndex > 1 )
1241 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
1242 tmpStr.RemoveAll( ( Standard_Character )' ' );
1243 if ( tmpStr.Length() > 0 )
1244 aSeq.Append( tmpStr );
1245 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1248 aStr.RemoveAll( ( Standard_Character )' ' );
1249 if ( aStr.Length() > 0 )
1250 aSeq.Append( aStr );
1252 if ( aSeq.Length() > 0 )
1254 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
1255 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
1256 aRes->ChangeValue( i ) = aSeq( i );
1262 \brief Get units structure for specified units system \a sys.
1263 \param sys units system
1264 \return units system information structure
1266 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
1270 if ( myUnitData.IsBound( sys ) )
1271 unit = (UnitData*)&myUnitData.Find( sys );
1277 \brief Get the active units system.
1278 \return active units system
1280 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
1283 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
1284 if ( !aComponent.IsNull() )
1285 aSystem = aComponent->GetActiveUnitSystem();
1290 \brief Set item's identify string.
1291 \param theId identify string.
1293 void DDS_DicItem::SetId( const TCollection_AsciiString& theId )
1299 \brief Set item's component pointer.
1300 \param theComponent component pointer.
1302 void DDS_DicItem::SetComponent( const Handle(Standard_Transient)& theComponent )
1304 myComponent = theComponent;
1308 \brief Set item's label string.
1309 \param theLabel label string.
1311 void DDS_DicItem::SetLabel( const TCollection_AsciiString& theLabel )
1317 \brief Set item's filter string.
1318 \param theFilter filter string.
1320 void DDS_DicItem::SetFilter( const TCollection_AsciiString& theFilter )
1322 myFilter = theFilter;
1326 \brief Set item's required value.
1327 \param theRequired required value string.
1329 void DDS_DicItem::SetRequired( const TCollection_AsciiString& theRequired )
1331 myRequired = theRequired;
1335 \brief Set item's warning level value.
1336 \param theWarningLevel warning level value.
1338 void DDS_DicItem::SetWarningLevel( const Standard_Integer& theWarningLevel )
1340 myWarnLevel = theWarningLevel;
1344 \brief Set item's minimum zoom value.
1345 \param theMinZoom minimum zoom value.
1347 void DDS_DicItem::SetMinZoom( const Standard_Real& theMinZoom )
1349 myMinZoom = theMinZoom;
1353 \brief Set item's maximum zoom value.
1354 \param theMaxZoom maximum zoom value.
1356 void DDS_DicItem::SetMaxZoom( const Standard_Real& theMaxZoom )
1358 myMaxZoom = theMaxZoom;
1362 \brief Set item's zoom order value.
1363 \param theZoomOrder zoom order value.
1365 void DDS_DicItem::SetZoomOrder( const Standard_Real& theZoomOrder )
1367 myZoomOrder = theZoomOrder;
1371 \brief Set item's short description.
1372 \param theShortDescr short description string.
1374 void DDS_DicItem::SetShortDescription( const TCollection_ExtendedString& theShortDescr )
1376 myShortDescr = theShortDescr;
1380 \brief Set item's long description.
1381 \param theLongDescr long description string.
1383 void DDS_DicItem::SetLongDescription( const TCollection_ExtendedString& theLongDescr )
1385 myLongDescr = theLongDescr;
1389 \brief Add item's option.
1390 \param theOptionName option name string.
1391 \param theOptionValue option value string.
1393 bool DDS_DicItem::SetOption( const TCollection_AsciiString& theOptionName,
1394 const TCollection_AsciiString& theOptionValue )
1396 return myOptions.Bind( theOptionName, theOptionValue );
1400 \brief Set item's type value.
1401 \param theType item value type.
1403 void DDS_DicItem::SetType( const DDS_DicItem::Type& theType )
1409 \brief Set item's minimum value.
1410 \param theMinVal minimum possible value.
1412 void DDS_DicItem::SetMin( const Standard_Real& theMinVal )
1419 \brief Set item's maximum value.
1420 \param theMaxVal maximum possible value.
1422 void DDS_DicItem::SetMax( const Standard_Real& theMaxVal )
1429 \brief Set item's default value as a real number.
1430 \param theDefVal default value.
1432 void DDS_DicItem::SetDefaultValue( const Standard_Real& theDefVal )
1434 myData |= DefaultValue;
1435 myDefValue = theDefVal;
1439 \brief Set item's default value as a string.
1440 \param theDefStr default value.
1442 void DDS_DicItem::SetDefaultValue( const TCollection_AsciiString& theDefStr )
1444 myDefString = theDefStr;
1448 \brief Set item's value list.
1449 \param theStrings list of value strings.
1450 \param theIntegers list of integer values associated with string item.
1452 void DDS_DicItem::SetListOfValues( const Handle(TColStd_HArray1OfExtendedString)& theStrings,
1453 const Handle(TColStd_HArray1OfInteger)& theIntegers )
1455 myListRef = theStrings;
1456 myListRefID = theIntegers;
1460 \brief Set item's value list and icons.
1461 \param theStrings list of value strings.
1462 \param theIntegers list of integer values associated with string item.
1463 \param theIcons list of icons associated with string item.
1465 void DDS_DicItem::SetListOfValues( const Handle(TColStd_HArray1OfExtendedString)& theStrings,
1466 const Handle(TColStd_HArray1OfInteger)& theIntegers,
1467 const Handle(TColStd_HArray1OfExtendedString)& theIcons )
1469 myListRef = theStrings;
1470 myListRefID = theIntegers;
1471 myListRefIcons = theIcons;