1 // Copyright (C) 2007-2016 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, 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 OCCT_IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
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& )
64 \brief Assignment operator (put in private section to prevent object copying).
66 void DDS_DicItem::operator=( const DDS_DicItem& )
71 \brief Get the identifier of parameter.
74 TCollection_AsciiString DDS_DicItem::GetId() const
80 \brief Get the type of parameter.
81 \return parameter type
83 DDS_DicItem::Type DDS_DicItem::GetType() const
85 return (DDS_DicItem::Type)myType;
89 \brief Get the label of the parameter.
90 \return parameter label
92 TCollection_ExtendedString DDS_DicItem::GetLabel() const
98 \brief Get the filter (regular expression) for the parameter values.
99 \return parameter filter
101 TCollection_ExtendedString DDS_DicItem::GetFilter() const
107 \brief Get the Required attribute of the parameter.
108 \return Required attribute
110 TCollection_ExtendedString DDS_DicItem::GetRequired() const
116 \brief Get the wrong value warning level of the parameter.
117 \return warning level
119 DDS_MsgType DDS_DicItem::GetWarningLevel() const
121 return (DDS_MsgType)myWarnLevel;
125 \brief Get the long description of the parameter.
126 \return long description
128 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
134 \brief Get the short description of the parameter.
135 \return short description
137 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
143 \brief Get the name of the component (parameter owner).
144 \return component name
146 TCollection_AsciiString DDS_DicItem::GetComponent() const
148 TCollection_AsciiString aCompName;
149 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
150 if ( !aComponent.IsNull() )
151 aCompName = aComponent->GetName();
156 \brief Get the parameter measure units for active units system.
157 \return parameter units
159 TCollection_AsciiString DDS_DicItem::GetUnits() const
161 return GetUnits( GetActiveUnitSystem() );
165 \brief Get the parameter measure units for specified units system \a theSystem.
167 If specified units system doesn't exist, empty string is returned.
169 \param theSystem units system
170 \return parameter units
172 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
174 TCollection_AsciiString anUnits;
175 UnitData* unitData = GetUnitData( theSystem );
177 anUnits = unitData->myUnits;
182 \brief Get the minimum value of the parameter for active units system.
184 Returned value is converted to SI.
186 \return minimum value
188 Standard_Real DDS_DicItem::GetMinValue() const
190 return GetMinValue( GetActiveUnitSystem() );
194 \brief Get the minimum value of the parameter for the specified
195 units system \a theSystem.
197 Returned value is converted to SI.
199 \param theUnitsSystem units system
200 \return minimum value
202 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
204 return FromSI( myMin, theUnitsSystem );
208 \brief Get the maximum value of the parameter for active units system.
210 Returned value converted to SI.
212 \return maximum value
214 Standard_Real DDS_DicItem::GetMaxValue() const
216 return GetMaxValue( GetActiveUnitSystem() );
220 \brief Get the maximum value of the parameter for specified
221 units system \a theSystem.
223 Returned value converted to SI.
225 \param theUnitsSystem units system
226 \return maximum value
228 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
230 return FromSI( myMax, theUnitsSystem );
234 \brief Get the precision (number of digits after decimal point)
235 of the parameter for active units system.
236 \return parameter precision
238 Standard_Integer DDS_DicItem::GetPrecision() const
240 return GetPrecision( GetActiveUnitSystem() );
244 \brief Get the precision (number of digits after decimal point) of the parameter
245 for specified units system \a theSystem.
247 If specified units system doesn't exist, zero is returned.
249 \param theSystem units system
250 \return parameter precision
252 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
254 Standard_Integer aRes = 0;
255 UnitData* unitData = GetUnitData( theSystem );
257 aRes = unitData->myPrecision;
262 \brief Get the default value of the parameter for active units system.
264 Default value is returned as string.
265 If type of the value is numerical (Float or Integer) and default value
266 is defined, then the returning value is converted to SI.
268 \return default value
270 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
272 return GetDefaultValue( GetActiveUnitSystem() );
276 \brief Get the default value of the parameter for specified
277 units system \a theSystem.
279 Default value is returned as string.
280 If type of the value is numerical (Float or Integer) and default value
281 is defined, then the returning value is converted to SI.
283 \param theSystem units system
284 \return default value
286 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
288 if ( !myDefString.Length() )
291 TCollection_ExtendedString aStr;
297 aStr = FromSI( myDefValue, theSystem );
310 \brief Get the format string of the parameter for active units system.
312 If argument \a theCanonical is \c true, format string is reduced according
313 to the sprintf() specification (without extra non standard qualifiers).
315 \param theCanonical 'canonical form' flag
316 \return format string
318 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
320 return GetFormat( GetActiveUnitSystem(), theCanonical );
324 \brief Get the format string of the parameter for specified
325 units system \a theSystem.
327 If argument \a theCanonical is \c true, format string is reduced according
328 to the sprintf() specification (without extra non standard qualifiers).
330 \param theSystem units system
331 \param theCanonical 'canonical form' flag
332 \return format string
334 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
335 const Standard_Boolean theCanonical ) const
337 TCollection_AsciiString aFormat;
338 UnitData* unitData = GetUnitData( theSystem );
340 aFormat = unitData->myFormat;
342 if ( theCanonical && aFormat.Length() > 1 )
344 static TCollection_AsciiString f;
346 Standard_Boolean isRemoved = false;
349 char ch = f.Value( f.Length() - 1 );
350 if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
351 f.Remove( f.Length() - 1 );
362 \brief Get the name of a list referenced by the parameter.
364 This string is empty if the list reference is not defined.
365 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
368 \return referenced list name
369 \sa GetListOfValues()
371 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
377 \brief Get item names and item identifiers of a list referenced
380 These sequences are empty if the list reference is not defined.
381 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
384 \param theStrings returning items names
385 \param theIntegers returning items identifiers
386 \return \c true if returning lists are not empty
387 \sa GetNameOfValues()
389 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
390 Handle(TColStd_HArray1OfInteger)& theIntegers ) const
392 theStrings = myListRef;
393 theIntegers = myListRefID;
394 return !theIntegers.IsNull() && !theStrings.IsNull();
398 \brief Get item names, item identifiers and item icons of a list
399 referenced by the parameter.
403 These sequences are empty if the list reference is not defined.
404 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
407 \param theStrings returning items names
408 \param theIntegers returning items identifiers
409 \param theIcons returning items icons
410 \return \c true if returning lists are not empty
411 \sa GetNameOfValues()
413 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
414 Handle(TColStd_HArray1OfInteger)& theIntegers,
415 Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
417 theStrings = myListRef;
418 theIntegers = myListRefID;
419 theIcons = myListRefIcons;
420 return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
425 \brief Get special values of the parameter.
426 \param theMap returning map of the special values
427 \return \c true if returning map is not empty
429 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
432 if ( !myListRef.IsNull() )
434 for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
436 if ( myListRef->Value( i ).IsAscii() )
438 TCollection_AsciiString aStr( myListRef->Value( i ) );
439 if ( aStr.IsRealValue() )
440 theMap.Add( aStr.RealValue() );
445 return theMap.Extent() > 0;
449 \brief Get minimum value of lateral zooming.
450 \return lateral zooming minimum value
452 Standard_Real DDS_DicItem::GetMinZoom() const
458 \brief Get maximum value of lateral zooming.
459 \return lateral zooming maximum value
461 Standard_Real DDS_DicItem::GetMaxZoom() const
467 \brief Get order of lateral zooming.
468 \return lateral zooming order
470 Standard_Real DDS_DicItem::GetZoomOrder() const
476 \brief Convert value \a theVal to the default SI units
477 according to the active units system.
478 \param theVal value being converted
479 \return value converted to SI
481 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
483 return ToSI( theVal, GetActiveUnitSystem() );
487 \brief Convert value \a theVal from the default SI units
488 according to the active units system.
489 \param theVal value being converted
490 \return value converted from SI
492 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
494 return FromSI( theVal, GetActiveUnitSystem() );
498 \brief Convert value to the default SI units according to the
499 units system \a theUnitsSystem.
500 \param theVal value being converted
501 \param theUnitsSystem units system
502 \return value converted to the specified units system
504 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
506 Standard_Real aRes = theVal;
507 UnitData* anUnitData = GetUnitData( theUnitsSystem );
509 aRes = anUnitData->myZero + aRes * anUnitData->myScale;
514 \brief Convert value from the default SI units according to the
515 units system \a theUnitsSystem.
516 \param theVal value being converted
517 \param theUnitsSystem units system
518 \return value converted from the specified units system
520 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
522 Standard_Real aRes = theVal;
523 UnitData* anUnitData = GetUnitData( theUnitsSystem );
525 aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
530 \brief Check data existence.
531 \param flag data flag
532 \return \c true if data specified by \a flag exists
534 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
536 return ( myData & flag ) == flag;
540 \brief Get option for specified name \a name.
542 If option is not found, empty string is returned.
544 \param name option name
547 TCollection_ExtendedString DDS_DicItem::GetOption( const TCollection_AsciiString& name ) const
549 TCollection_ExtendedString res;
550 if ( myOptions.IsBound( name ) )
551 res = myOptions.Find( name );
556 \brief Get names of all existing options.
557 \param names returning list of options
558 \return \c true if list is not empty
560 Standard_Boolean DDS_DicItem::GetOptionNames( TColStd_SequenceOfAsciiString& names ) const
564 for ( OptionsMap::Iterator it( myOptions ); it.More(); it.Next() )
565 names.Append( it.Key() );
567 return !names.IsEmpty();
572 \brief Parse record from XML file and retrieve information relevant for
574 \param theID item identifier
575 \param theDatum datum XML node
576 \param theCompElement component XML node
577 \param theDocElement document XML node
578 \param theSystems units system names
580 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
581 const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
582 const TColStd_SequenceOfAsciiString& theSystems )
584 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
585 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
586 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
587 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
589 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
591 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
593 UnitSystem anUnitSystem = theSystems.Value( j );
594 if ( !anUnitSystem.Length() )
597 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
599 if ( !myUnitData.IsBound( anUnitSystem ) )
600 myUnitData.Bind( anUnitSystem, UnitData() );
602 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
603 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
606 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
607 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
609 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
610 if ( units.Length() )
611 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
614 TCollection_AsciiString units;
615 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
616 units = iter.Value().myUnits;
618 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
620 UnitData& dataUnits = itr.ChangeValue();
621 if ( dataUnits.myUnits.IsEmpty() )
622 dataUnits.myUnits = units;
625 // 2. Elements ( domain, description )
626 Standard_Real aRealMinV = 0;
627 Standard_Real aRealMaxV = 0;
628 Standard_Real aRealDefV = 0;
630 TCollection_AsciiString aType;
632 DDS_MsgType aWrongValue = DDS_MT_NONE;
633 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
635 TCollection_AsciiString aMinV;
636 TCollection_AsciiString aMaxV;
637 TCollection_AsciiString aDefV;
638 TCollection_AsciiString aListName;
640 TCollection_AsciiString aLongD;
641 TCollection_AsciiString aShortD;
643 TColStd_SequenceOfInteger aSeqOfValueID;
644 TColStd_SequenceOfExtendedString aSeqOfValue;
645 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
648 Standard_Real aMinZoom = 0;
649 Standard_Real aMaxZoom = 0;
650 Standard_Real aZoomOrder = 0;
652 // Datum::Reports tags (if any)
653 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
654 if ( !aWLev.isNull() )
656 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
657 if ( aWrongValWL.IsEqual( "Info" ) )
658 aWrongValue = DDS_MT_INFO;
659 else if ( aWrongValWL.IsEqual( "Warning" ) )
660 aWrongValue = DDS_MT_WARNING;
661 else if ( aWrongValWL.IsEqual( "Alarm" ) )
662 aWrongValue = DDS_MT_ALARM;
663 else if ( aWrongValWL.IsEqual( "Error" ) )
664 aWrongValue = DDS_MT_ERROR;
667 // Datum::Presentation
668 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
669 if ( !aPrs.isNull() )
671 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
672 if ( !aLateralZoom.isNull() )
674 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
675 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
676 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
678 aMinZoomStr.RemoveAll( ' ' );
679 if ( aMinZoomStr.IsRealValue() )
680 aMinZoom = aMinZoomStr.RealValue();
682 aMaxZoomStr.RemoveAll( ' ' );
683 if ( aMaxZoomStr.IsRealValue() )
684 aMaxZoom = aMaxZoomStr.RealValue();
686 aZoomOrderStr.RemoveAll( ' ' );
687 if ( aZoomOrderStr.IsRealValue() )
688 aZoomOrder = aZoomOrderStr.RealValue();
692 // Quantity::Domain record as the only child of that tag name
693 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
694 if ( !aDomain.isNull() )
696 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
697 if ( !aValueDescr.isNull() )
699 // read: valueDescr? (type?,min?,max?,default?)
700 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
701 if ( aType.IsEqual( "String" ) )
703 else if ( aType.IsEqual( "Float" ) )
705 else if ( aType.IsEqual( "Integer" ) )
708 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
710 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
711 aMinV.RemoveAll( ' ' );
712 if ( aMinV.IsRealValue() )
713 aRealMinV = aMinV.RealValue();
714 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
716 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
717 aMaxV.RemoveAll( ' ' );
718 if ( aMaxV.IsRealValue() )
719 aRealMaxV = aMaxV.RealValue();
720 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
721 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
722 myData |= DefaultValue;
724 aDefV.RemoveAll( ' ' );
725 if ( aDefV.IsRealValue() )
726 aRealDefV = aDefV.RealValue();
728 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
729 Split( aSpecVal, myListRef );
733 // read: listRef? (list?)
734 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
735 if ( !aListRef.isNull() )
739 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
740 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
741 aDefV.RemoveAll( ' ' );
742 LDOM_Element foundListItem;
743 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
744 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
746 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
747 foundListItem = aListItem;
750 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
751 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
753 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
754 foundListItem = aLstItem;
757 if ( foundListItem != NULL )
759 // The appropriate list of values is found: store the list name
760 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
761 // Iteration through the list of values
762 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
763 while ( aListItemValue != NULL )
766 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
767 if ( aListValueID.IsIntegerValue() )
769 // Read the text in the element "value"
770 //LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
771 LDOM_Node aNode = aListItemValue.getFirstChild();
772 const LDOM_Text& aText = (const LDOM_Text&) aNode;
773 LDOM_Text aListItemTxt(aText);
774 if ( !aListItemTxt.isNull() )
776 // adding ID and text value to sequence
777 aSeqOfValueID.Append( aListValueID.IntegerValue() );
778 aSeqOfValue.Append( aListItemTxt.getData() );
779 // adding icon file name (optional) to sequence
780 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
781 aSeqOfValueIconName.Append( aListValueIcon );
783 aListItemValue = aListItemValue.GetSiblingByTagName();
791 // Quantity::Description record as the only child of that tag name
792 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
793 if ( !aDescr.isNull() )
795 // short description (#PCDATA)*
796 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
797 if ( !aShDescr.isNull() )
799 // text is always a sub-node of element, containing it
800 //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
801 LDOM_Node aNode = aShDescr.getFirstChild();
802 const LDOM_Text& aText = (const LDOM_Text&) aNode;
803 LDOM_Text aShDescrTxt(aText);
804 if ( !aShDescrTxt.isNull() )
805 aShortD = aShDescrTxt.getData();
808 // long description (#PCDATA)*
809 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
810 if ( !aLDescr.isNull() )
812 // text is always a sub-node of element, containing it
813 //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
814 LDOM_Node aNode = aLDescr.getFirstChild();
815 const LDOM_Text& aText = (const LDOM_Text&) aNode;
816 LDOM_Text aLDescrTxt(aText);
817 if ( !aLDescrTxt.isNull() )
818 aLongD = aLDescrTxt.getData();
823 LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) );
824 if ( !anOpt.isNull() )
826 LDOM_NodeList anOptions = anOpt.GetAttributesList();//anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) );
827 for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ )
829 LDOM_Node node = anOptions.item( oi );
830 LDOM_Node::NodeType t = node.getNodeType();
832 TCollection_AsciiString name;
833 TCollection_ExtendedString value;
835 if( t==LDOM_Node::ELEMENT_NODE )
837 const LDOM_Element& elem = ( const LDOM_Element& )node;
838 name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) );
840 const LDOM_Node aNode = elem.getFirstChild();
841 LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) );
842 if ( !anOptTxt.isNull() )
843 value = anOptTxt.getData();
845 else if( t==LDOM_Node::ATTRIBUTE_NODE )
847 const LDOM_Attr& attr = ( const LDOM_Attr& )node;
848 name = ( Standard_CString )attr.getName().GetString();
849 LDOMString v = attr.getValue();
850 if( v.Type()==LDOMBasicString::LDOM_Integer )
852 Standard_Integer ival;
853 v.GetInteger( ival );
854 value = TCollection_ExtendedString( ival );
857 value = ( Standard_CString )v.GetString();
862 if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) )
863 myOptions.Bind( name, value );
867 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
869 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
871 UnitData& anUnitData = it.ChangeValue();
874 anUnitData.myZero = 0.;
875 anUnitData.myScale = 1.;
877 Standard_CString aUnitDataStr;
878 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
879 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
881 Handle(Units_Dimensions) aDim;
882 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
883 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
884 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
885 if ( !aDimMap.IsBound( it.Key() ) )
886 aDimMap.Bind( it.Key(), aDim );
888 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
889 anUnitData.myScale = 0.01;
891 catch( Standard_Failure ) {
892 anUnitData.myUnits.Clear();
895 Handle(Units_Dimensions) aPrev;
896 Standard_Boolean aStatus = Standard_True;
897 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
898 itr.More() && aStatus; itr.Next() )
900 if ( itr.Value().IsNull() )
903 if ( aPrev.IsNull() )
906 aStatus = aPrev->IsEqual( itr.Value() );
910 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
915 myWarnLevel = aWrongValue;
916 myLabel = aLabel.ToCString();
917 myFilter = aFilter.ToCString();
918 myLongDescr = aLongD.ToCString();
919 myShortDescr = aShortD.ToCString();
922 myDefValue = aRealDefV;
923 myDefString = aDefV.ToCString();
924 myRequired = aRequired.ToCString();
925 myListName = aListName.ToCString();
926 myMinZoom = aMinZoom;
927 myMaxZoom = aMaxZoom;
928 myZoomOrder = aZoomOrder;
931 PrepareFormats( aFormat );
933 const Standard_Integer aLength = aSeqOfValue.Length();
936 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
937 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
938 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
939 for ( Standard_Integer i = aLength; i > 0; i-- )
941 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
942 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
943 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
947 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
948 myDefString = myListRef->Value( myListRef->Lower() );
952 \brief Restore default formats for all the units systems.
954 void DDS_DicItem::GetDefaultFormat()
956 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
958 UnitData& anUnitData = it.ChangeValue();
963 anUnitData.myFormat = "%d";
966 anUnitData.myFormat = "%g";
970 anUnitData.myFormat.Clear();
977 \brief Get format for the string.
978 \param theFlags format flags
979 \param theWidth field width
980 \param thePrecision precision
981 \param theTypePrefix type prefix
982 \param theFormat returning format string
984 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
985 const TCollection_AsciiString& theWidth,
986 const TCollection_AsciiString& thePrecision,
987 const TCollection_AsciiString& theTypePrefix,
988 TCollection_AsciiString& theFormat )
991 theFormat += theFlags;
992 theFormat += theWidth;
994 if ( !thePrecision.IsEmpty() )
997 theFormat += thePrecision;
1000 theFormat += theTypePrefix;
1005 \brief Get format for the integer.
1006 \param theFlags format flags
1007 \param theWidth field width
1008 \param thePrecision precision
1009 \param theTypePrefix type prefix
1010 \param theType integer value type
1011 \param theFormat returning format string
1013 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
1014 const TCollection_AsciiString& theWidth,
1015 const TCollection_AsciiString& thePrecision,
1016 const TCollection_AsciiString& theTypePrefix,
1017 const Standard_Character theType,
1018 TCollection_AsciiString& theFormat )
1020 Standard_Integer aPrecision = 0;
1021 if ( !thePrecision.IsEmpty() )
1022 aPrecision = thePrecision.IntegerValue();
1023 Standard_Integer aWidth = 0;
1025 if ( !theWidth.IsEmpty() )
1026 aWidth = theWidth.IntegerValue();
1028 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
1030 // possible value 0.1 will be 10.0
1031 aWidth -= aPrecision;
1035 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1036 aWidth = aPrecision + 2;
1040 theFormat += theFlags;
1041 if ( !theWidth.IsEmpty() )
1042 theFormat += aWidth;
1044 theFormat += theTypePrefix;
1045 theFormat += theType;
1049 \brief Returns format for the float.
1050 \param theFlags format flags
1051 \param theWidth field width
1052 \param thePrecision precision
1053 \param theTypePrefix type prefix
1054 \param theType floating point value type
1055 \param theFormat returning format string
1057 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
1058 const TCollection_AsciiString& theWidth,
1059 const TCollection_AsciiString& thePrecision,
1060 const TCollection_AsciiString& theTypePrefix,
1061 const Standard_Character theType,
1062 TCollection_AsciiString& theFormat )
1064 Standard_Integer aPrecision = 0;
1065 if ( !thePrecision.IsEmpty() )
1066 aPrecision = thePrecision.IntegerValue();
1067 Standard_Integer aWidth = 0;
1069 if (!theWidth.IsEmpty() )
1070 aWidth = theWidth.IntegerValue();
1072 if (!thePrecision.IsEmpty() && aPrecision < 0 )
1074 // possible value 0.1 will be 10.0
1075 aWidth -= aPrecision;
1079 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1081 aWidth = aPrecision + 2;
1085 theFormat += theFlags;
1087 if ( !theWidth.IsEmpty() )
1088 theFormat += aWidth;
1090 if ( !thePrecision.IsEmpty() )
1093 theFormat += aPrecision;
1096 theFormat += theTypePrefix;
1097 theFormat += theType;
1101 \brief Prepare formats for all units systems.
1102 \param theFormat format string
1104 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
1106 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
1108 UnitData& anUnitData = it.ChangeValue();
1110 anUnitData.myFormat = theFormat;
1111 anUnitData.myPrecision = 0;
1114 TCollection_AsciiString aPrecisionStr;
1115 if ( theFormat.IsEmpty() && myType == List )
1118 // checking % presenting
1119 if ( *theFormat.ToCString() != '%' )
1125 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
1126 Standard_Character aType = aStr.Value( aStr.Length() );
1128 if ( ( aType != 's' && myType == String ) ||
1129 ( aType != 'd' && myType == Integer ) ||
1130 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
1136 // removing type character
1137 aStr.Trunc( aStr.Length() - 1 );
1139 TCollection_AsciiString aFlags;
1140 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
1142 aFlags = aFlags + aStr.Value( 1 );
1146 Standard_Integer aPos = 1;
1147 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
1148 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
1151 TCollection_AsciiString aTypePrefix;
1152 if ( aPos <= aStr.Length() )
1154 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
1155 aStr.Trunc( aPos - 1 );
1158 Standard_Integer aBasePrecision = 0;
1160 // taking width and precision
1161 TCollection_AsciiString aPrecision;
1163 aPos = aStr.Search( "." );
1166 // aPrecision is defined
1167 aPrecision = aStr.Split( aPos );
1168 aStr.Remove( aStr.Length() );
1169 if ( !aPrecision.IsEmpty() )
1171 if ( !aPrecision.IsIntegerValue() )
1178 aPrecisionStr = aPrecision;
1179 aBasePrecision = aPrecision.IntegerValue();
1184 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
1190 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
1195 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1197 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
1198 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
1203 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1205 UnitData& anUnitData = itr.ChangeValue();
1206 Standard_Integer aAmendment =
1207 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
1208 anUnitData.myPrecision = aBasePrecision + aAmendment;
1209 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
1212 if ( myType == Integer )
1213 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1215 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1225 \brief Split the string \a theStr separated by spaces.
1226 \param theStr source string
1227 \param aRes returning substrings array
1229 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
1233 if ( theStr.Length() > 0 )
1235 TCollection_AsciiString aStr = theStr;
1236 TColStd_SequenceOfAsciiString aSeq;
1237 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1238 while( anIndex > 1 )
1240 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
1241 tmpStr.RemoveAll( ( Standard_Character )' ' );
1242 if ( tmpStr.Length() > 0 )
1243 aSeq.Append( tmpStr );
1244 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1247 aStr.RemoveAll( ( Standard_Character )' ' );
1248 if ( aStr.Length() > 0 )
1249 aSeq.Append( aStr );
1251 if ( aSeq.Length() > 0 )
1253 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
1254 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
1255 aRes->ChangeValue( i ) = aSeq( i );
1261 \brief Get units structure for specified units system \a sys.
1262 \param sys units system
1263 \return units system information structure
1265 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
1269 if ( myUnitData.IsBound( sys ) )
1270 unit = (UnitData*)&myUnitData.Find( sys );
1276 \brief Get the active units system.
1277 \return active units system
1279 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
1282 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
1283 if ( !aComponent.IsNull() )
1284 aSystem = aComponent->GetActiveUnitSystem();
1289 \brief Set item's identify string.
1290 \param theId identify string.
1292 void DDS_DicItem::SetId( const TCollection_AsciiString& theId )
1298 \brief Set item's component pointer.
1299 \param theComponent component pointer.
1301 void DDS_DicItem::SetComponent( const Handle(Standard_Transient)& theComponent )
1303 myComponent = theComponent;
1307 \brief Set item's label string.
1308 \param theLabel label string.
1310 void DDS_DicItem::SetLabel( const TCollection_AsciiString& theLabel )
1316 \brief Set item's filter string.
1317 \param theFilter filter string.
1319 void DDS_DicItem::SetFilter( const TCollection_AsciiString& theFilter )
1321 myFilter = theFilter;
1325 \brief Set item's required value.
1326 \param theRequired required value string.
1328 void DDS_DicItem::SetRequired( const TCollection_AsciiString& theRequired )
1330 myRequired = theRequired;
1334 \brief Set item's warning level value.
1335 \param theWarningLevel warning level value.
1337 void DDS_DicItem::SetWarningLevel( const Standard_Integer& theWarningLevel )
1339 myWarnLevel = theWarningLevel;
1343 \brief Set item's minimum zoom value.
1344 \param theMinZoom minimum zoom value.
1346 void DDS_DicItem::SetMinZoom( const Standard_Real& theMinZoom )
1348 myMinZoom = theMinZoom;
1352 \brief Set item's maximum zoom value.
1353 \param theMaxZoom maximum zoom value.
1355 void DDS_DicItem::SetMaxZoom( const Standard_Real& theMaxZoom )
1357 myMaxZoom = theMaxZoom;
1361 \brief Set item's zoom order value.
1362 \param theZoomOrder zoom order value.
1364 void DDS_DicItem::SetZoomOrder( const Standard_Real& theZoomOrder )
1366 myZoomOrder = theZoomOrder;
1370 \brief Set item's short description.
1371 \param theShortDescr short description string.
1373 void DDS_DicItem::SetShortDescription( const TCollection_ExtendedString& theShortDescr )
1375 myShortDescr = theShortDescr;
1379 \brief Set item's long description.
1380 \param theLongDescr long description string.
1382 void DDS_DicItem::SetLongDescription( const TCollection_ExtendedString& theLongDescr )
1384 myLongDescr = theLongDescr;
1388 \brief Add item's option.
1389 \param theOptionName option name string.
1390 \param theOptionValue option value string.
1392 bool DDS_DicItem::SetOption( const TCollection_AsciiString& theOptionName,
1393 const TCollection_AsciiString& theOptionValue )
1395 return myOptions.Bind( theOptionName, theOptionValue );
1399 \brief Set item's type value.
1400 \param theType item value type.
1402 void DDS_DicItem::SetType( const DDS_DicItem::Type& theType )
1408 \brief Set item's minimum value.
1409 \param theMinVal minimum possible value.
1411 void DDS_DicItem::SetMin( const Standard_Real& theMinVal )
1418 \brief Set item's maximum value.
1419 \param theMaxVal maximum possible value.
1421 void DDS_DicItem::SetMax( const Standard_Real& theMaxVal )
1428 \brief Set item's default value as a real number.
1429 \param theDefVal default value.
1431 void DDS_DicItem::SetDefaultValue( const Standard_Real& theDefVal )
1433 myData |= DefaultValue;
1434 myDefValue = theDefVal;
1438 \brief Set item's default value as a string.
1439 \param theDefStr default value.
1441 void DDS_DicItem::SetDefaultValue( const TCollection_AsciiString& theDefStr )
1443 myDefString = theDefStr;
1447 \brief Set item's value list.
1448 \param theStrings list of value strings.
1449 \param theIntegers list of integer values associated with string item.
1451 void DDS_DicItem::SetListOfValues( const Handle(TColStd_HArray1OfExtendedString)& theStrings,
1452 const Handle(TColStd_HArray1OfInteger)& theIntegers )
1454 myListRef = theStrings;
1455 myListRefID = theIntegers;
1459 \brief Set item's value list and icons.
1460 \param theStrings list of value strings.
1461 \param theIntegers list of integer values associated with string item.
1462 \param theIcons list of icons associated with string item.
1464 void DDS_DicItem::SetListOfValues( const Handle(TColStd_HArray1OfExtendedString)& theStrings,
1465 const Handle(TColStd_HArray1OfInteger)& theIntegers,
1466 const Handle(TColStd_HArray1OfExtendedString)& theIcons )
1468 myListRef = theStrings;
1469 myListRefID = theIntegers;
1470 myListRefIcons = theIcons;