1 // Copyright (C) 2007-2008 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
22 #include "DDS_DicItem.h"
23 #include "DDS_Dictionary.h"
25 #include <TColStd_SequenceOfInteger.hxx>
26 #include <TColStd_SequenceOfExtendedString.hxx>
28 #include <LDOM_Text.hxx>
29 #include <LDOMString.hxx>
30 #include <LDOM_Element.hxx>
32 #include <UnitsAPI.hxx>
33 #include <Units_Dimensions.hxx>
35 #include <TColStd_MapOfReal.hxx>
36 #include <TColStd_SequenceOfAsciiString.hxx>
38 IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared)
39 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
43 \brief This class provides an information about datum (phisical characteristic parameter).
49 Creates the instance of empty dictionary item.
51 DDS_DicItem::DDS_DicItem()
63 \brief Copy constructor (put in private section to prevent object copying).
65 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
70 \brief Assignment operator (put in private section to prevent object copying).
72 void DDS_DicItem::operator=( const DDS_DicItem& )
77 \brief Get the identifier of parameter.
80 TCollection_AsciiString DDS_DicItem::GetId() const
86 \brief Get the type of parameter.
87 \return parameter type
89 DDS_DicItem::Type DDS_DicItem::GetType() const
91 return (DDS_DicItem::Type)myType;
95 \brief Get the label of the parameter.
96 \return parameter label
98 TCollection_ExtendedString DDS_DicItem::GetLabel() const
104 \brief Get the filter (regular expression) for the parameter values.
105 \return parameter filter
107 TCollection_ExtendedString DDS_DicItem::GetFilter() const
113 \brief Get the Required attribute of the parameter.
114 \return Required attribute
116 TCollection_ExtendedString DDS_DicItem::GetRequired() const
122 \brief Get the wrong value warning level of the parameter.
123 \return warning level
125 DDS_MsgType DDS_DicItem::GetWarningLevel() const
127 return (DDS_MsgType)myWarnLevel;
131 \brief Get the long description of the parameter.
132 \return long description
134 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
140 \brief Get the short description of the parameter.
141 \return short description
143 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
149 \brief Get the name of the component (parameter owner).
150 \return component name
152 TCollection_AsciiString DDS_DicItem::GetComponent() const
154 TCollection_AsciiString aCompName;
155 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
156 if ( !aComponent.IsNull() )
157 aCompName = aComponent->GetName();
162 \brief Get the parameter measure units for active units system.
163 \return parameter units
165 TCollection_AsciiString DDS_DicItem::GetUnits() const
167 return GetUnits( GetActiveUnitSystem() );
171 \brief Get the parameter measure units for specified units system \a theSystem.
173 If specified units system doesn't exist, empty string is returned.
175 \param theSystem units system
176 \return parameter units
178 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
180 TCollection_AsciiString anUnits;
181 UnitData* unitData = GetUnitData( theSystem );
183 anUnits = unitData->myUnits;
188 \brief Get the minimum value of the parameter for active units system.
190 Returned value is converted to SI.
192 \return minimum value
194 Standard_Real DDS_DicItem::GetMinValue() const
196 return GetMinValue( GetActiveUnitSystem() );
200 \brief Get the minimum value of the parameter for the specified
201 units system \a theSystem.
203 Returned value is converted to SI.
205 \param theUnitsSystem units system
206 \return minimum value
208 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
210 return FromSI( myMin, theUnitsSystem );
214 \brief Get the maximum value of the parameter for active units system.
216 Returned value converted to SI.
218 \return maximum value
220 Standard_Real DDS_DicItem::GetMaxValue() const
222 return GetMaxValue( GetActiveUnitSystem() );
226 \brief Get the maximum value of the parameter for specified
227 units system \a theSystem.
229 Returned value converted to SI.
231 \param theUnitsSystem units system
232 \return maximum value
234 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
236 return FromSI( myMax, theUnitsSystem );
240 \brief Get the precision (number of digits after decimal point)
241 of the parameter for active units system.
242 \return parameter precision
244 Standard_Integer DDS_DicItem::GetPrecision() const
246 return GetPrecision( GetActiveUnitSystem() );
250 \brief Get the precision (number of digits after decimal point) of the parameter
251 for specified units system \a theSystem.
253 If specified units system doesn't exist, zero is returned.
255 \param theSystem units system
256 \return parameter precision
258 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
260 Standard_Integer aRes = 0;
261 UnitData* unitData = GetUnitData( theSystem );
263 aRes = unitData->myPrecision;
268 \brief Get the default value of the parameter for active units system.
270 Default value is returned as string.
271 If type of the value is numerical (Float or Integer) and default value
272 is defined, then the returning value is converted to SI.
274 \return default value
276 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
278 return GetDefaultValue( GetActiveUnitSystem() );
282 \brief Get the default value of the parameter for specified
283 units system \a theSystem.
285 Default value is returned as string.
286 If type of the value is numerical (Float or Integer) and default value
287 is defined, then the returning value is converted to SI.
289 \param theSystem units system
290 \return default value
292 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
294 if ( !myDefString.Length() )
297 TCollection_ExtendedString aStr;
303 aStr = FromSI( myDefValue, theSystem );
316 \brief Get the format string of the parameter for active units system.
318 If argument \a theCanonical is \c true, format string is reduced according
319 to the sprintf() specification (without extra non standard qualifiers).
321 \param theCanonical 'canonical form' flag
322 \return format string
324 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
326 return GetFormat( GetActiveUnitSystem(), theCanonical );
330 \brief Get the format string of the parameter for specified
331 units system \a theSystem.
333 If argument \a theCanonical is \c true, format string is reduced according
334 to the sprintf() specification (without extra non standard qualifiers).
336 \param theSystem units system
337 \param theCanonical 'canonical form' flag
338 \return format string
340 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
341 const Standard_Boolean theCanonical ) const
343 TCollection_AsciiString aFormat;
344 UnitData* unitData = GetUnitData( theSystem );
346 aFormat = unitData->myFormat;
348 if ( theCanonical && aFormat.Length() > 1 )
350 static TCollection_AsciiString f;
352 Standard_Boolean isRemoved = false;
355 char ch = f.Value( f.Length() - 1 );
356 if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
357 f.Remove( f.Length() - 1 );
368 \brief Get the name of a list referenced by the parameter.
370 This string is empty if the list reference is not defined.
371 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
374 \return referenced list name
375 \sa GetListOfValues()
377 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
383 \brief Get item names and item identifiers of a list referenced
386 These sequences are empty if the list reference is not defined.
387 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
390 \param theStrings returning items names
391 \param theIntegers returning items identifiers
392 \return \c true if returning lists are not empty
393 \sa GetNameOfValues()
395 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
396 Handle(TColStd_HArray1OfInteger)& theIntegers ) const
398 theStrings = myListRef;
399 theIntegers = myListRefID;
400 return !theIntegers.IsNull() && !theStrings.IsNull();
404 \brief Get item names, item identifiers and item icons of a list
405 referenced by the parameter.
409 These sequences are empty if the list reference is not defined.
410 In this case, other properties (Type, DefaultValue, MaxValue, MinValue)
413 \param theStrings returning items names
414 \param theIntegers returning items identifiers
415 \param theIcons returning items icons
416 \return \c true if returning lists are not empty
417 \sa GetNameOfValues()
419 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
420 Handle(TColStd_HArray1OfInteger)& theIntegers,
421 Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
423 theStrings = myListRef;
424 theIntegers = myListRefID;
425 theIcons = myListRefIcons;
426 return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
431 \brief Get special values of the parameter.
432 \param theMap returning map of the special values
433 \return \c true if returning map is not empty
435 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
438 if ( !myListRef.IsNull() )
440 for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
442 if ( myListRef->Value( i ).IsAscii() )
444 TCollection_AsciiString aStr( myListRef->Value( i ) );
445 if ( aStr.IsRealValue() )
446 theMap.Add( aStr.RealValue() );
451 return theMap.Extent() > 0;
455 \brief Get minimum value of lateral zooming.
456 \return lateral zooming minimum value
458 Standard_Real DDS_DicItem::GetMinZoom() const
464 \brief Get maximum value of lateral zooming.
465 \return lateral zooming maximum value
467 Standard_Real DDS_DicItem::GetMaxZoom() const
473 \brief Get order of lateral zooming.
474 \return lateral zooming order
476 Standard_Real DDS_DicItem::GetZoomOrder() const
482 \brief Convert value \a theVal to the default SI units
483 according to the active units system.
484 \param theVal value being converted
485 \return value converted to SI
487 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
489 return ToSI( theVal, GetActiveUnitSystem() );
493 \brief Convert value \a theVal from the default SI units
494 according to the active units system.
495 \param theVal value being converted
496 \return value converted from SI
498 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
500 return FromSI( theVal, GetActiveUnitSystem() );
504 \brief Convert value to the default SI units according to the
505 units system \a theUnitsSystem.
506 \param theVal value being converted
507 \param theUnitsSystem units system
508 \return value converted to the specified units system
510 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
512 Standard_Real aRes = theVal;
513 UnitData* anUnitData = GetUnitData( theUnitsSystem );
515 aRes = anUnitData->myZero + aRes * anUnitData->myScale;
520 \brief Convert value from the default SI units according to the
521 units system \a theUnitsSystem.
522 \param theVal value being converted
523 \param theUnitsSystem units system
524 \return value converted from the specified units system
526 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
528 Standard_Real aRes = theVal;
529 UnitData* anUnitData = GetUnitData( theUnitsSystem );
531 aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
536 \brief Check data existence.
537 \param flag data flag
538 \return \c true if data specified by \a flag exists
540 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
542 return ( myData & flag ) == flag;
546 \brief Get option for specified name \a name.
548 If option is not found, empty string is returned.
550 \param name option name
553 TCollection_ExtendedString DDS_DicItem::GetOption( const TCollection_AsciiString& name ) const
555 TCollection_ExtendedString res;
556 if ( myOptions.IsBound( name ) )
557 res = myOptions.Find( name );
562 \brief Get names of all existing options.
563 \param names returning list of options
564 \return \c true if list is not empty
566 Standard_Boolean DDS_DicItem::GetOptionNames( TColStd_SequenceOfAsciiString& names ) const
570 for ( OptionsMap::Iterator it( myOptions ); it.More(); it.Next() )
571 names.Append( it.Key() );
573 return !names.IsEmpty();
578 \brief Parse record from XML file and retrieve information relevant for
580 \param theID item identifier
581 \param theDatum datum XML node
582 \param theCompElement component XML node
583 \param theDocElement document XML node
584 \param theSystems units system names
586 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
587 const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
588 const TColStd_SequenceOfAsciiString& theSystems )
590 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
591 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
592 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
593 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
595 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
597 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
599 UnitSystem anUnitSystem = theSystems.Value( j );
600 if ( !anUnitSystem.Length() )
603 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
605 if ( !myUnitData.IsBound( anUnitSystem ) )
606 myUnitData.Bind( anUnitSystem, UnitData() );
608 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
609 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
612 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
613 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
615 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
616 if ( units.Length() )
617 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
620 TCollection_AsciiString units;
621 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
622 units = iter.Value().myUnits;
624 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
626 UnitData& dataUnits = itr.ChangeValue();
627 if ( dataUnits.myUnits.IsEmpty() )
628 dataUnits.myUnits = units;
631 // 2. Elements ( domain, description )
632 Standard_Real aRealMinV = 0;
633 Standard_Real aRealMaxV = 0;
634 Standard_Real aRealDefV = 0;
636 TCollection_AsciiString aType;
638 DDS_MsgType aWrongValue = DDS_MT_NONE;
639 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
641 TCollection_AsciiString aMinV;
642 TCollection_AsciiString aMaxV;
643 TCollection_AsciiString aDefV;
644 TCollection_AsciiString aListName;
646 TCollection_AsciiString aLongD;
647 TCollection_AsciiString aShortD;
649 TColStd_SequenceOfInteger aSeqOfValueID;
650 TColStd_SequenceOfExtendedString aSeqOfValue;
651 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
654 Standard_Real aMinZoom = 0;
655 Standard_Real aMaxZoom = 0;
656 Standard_Real aZoomOrder = 0;
658 // Datum::Reports tags (if any)
659 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
660 if ( !aWLev.isNull() )
662 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
663 if ( aWrongValWL.IsEqual( "Info" ) )
664 aWrongValue = DDS_MT_INFO;
665 else if ( aWrongValWL.IsEqual( "Warning" ) )
666 aWrongValue = DDS_MT_WARNING;
667 else if ( aWrongValWL.IsEqual( "Alarm" ) )
668 aWrongValue = DDS_MT_ALARM;
669 else if ( aWrongValWL.IsEqual( "Error" ) )
670 aWrongValue = DDS_MT_ERROR;
673 // Datum::Presentation
674 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
675 if ( !aPrs.isNull() )
677 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
678 if ( !aLateralZoom.isNull() )
680 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
681 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
682 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
684 aMinZoomStr.RemoveAll( ' ' );
685 if ( aMinZoomStr.IsRealValue() )
686 aMinZoom = aMinZoomStr.RealValue();
688 aMaxZoomStr.RemoveAll( ' ' );
689 if ( aMaxZoomStr.IsRealValue() )
690 aMaxZoom = aMaxZoomStr.RealValue();
692 aZoomOrderStr.RemoveAll( ' ' );
693 if ( aZoomOrderStr.IsRealValue() )
694 aZoomOrder = aZoomOrderStr.RealValue();
698 // Quantity::Domain record as the only child of that tag name
699 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
700 if ( !aDomain.isNull() )
702 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
703 if ( !aValueDescr.isNull() )
705 // read: valueDescr? (type?,min?,max?,default?)
706 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
707 if ( aType.IsEqual( "String" ) )
709 else if ( aType.IsEqual( "Float" ) )
711 else if ( aType.IsEqual( "Integer" ) )
714 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
716 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
717 aMinV.RemoveAll( ' ' );
718 if ( aMinV.IsRealValue() )
719 aRealMinV = aMinV.RealValue();
720 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
722 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
723 aMaxV.RemoveAll( ' ' );
724 if ( aMaxV.IsRealValue() )
725 aRealMaxV = aMaxV.RealValue();
726 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
727 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
728 myData |= DefaultValue;
730 aDefV.RemoveAll( ' ' );
731 if ( aDefV.IsRealValue() )
732 aRealDefV = aDefV.RealValue();
734 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
735 Split( aSpecVal, myListRef );
739 // read: listRef? (list?)
740 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
741 if ( !aListRef.isNull() )
745 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
746 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
747 aDefV.RemoveAll( ' ' );
748 LDOM_Element foundListItem;
749 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
750 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
752 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
753 foundListItem = aListItem;
756 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
757 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
759 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
760 foundListItem = aLstItem;
763 if ( foundListItem != NULL )
765 // The appropriate list of values is found: store the list name
766 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
767 // Iteration through the list of values
768 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
769 while ( aListItemValue != NULL )
772 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
773 if ( aListValueID.IsIntegerValue() )
775 // Read the text in the element "value"
776 //LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
777 LDOM_Node aNode = aListItemValue.getFirstChild();
778 const LDOM_Text& aText = (const LDOM_Text&) aNode;
779 LDOM_Text aListItemTxt(aText);
780 if ( !aListItemTxt.isNull() )
782 // adding ID and text value to sequence
783 aSeqOfValueID.Append( aListValueID.IntegerValue() );
784 aSeqOfValue.Append( aListItemTxt.getData() );
785 // adding icon file name (optional) to sequence
786 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
787 aSeqOfValueIconName.Append( aListValueIcon );
789 aListItemValue = aListItemValue.GetSiblingByTagName();
797 // Quantity::Description record as the only child of that tag name
798 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
799 if ( !aDescr.isNull() )
801 // short description (#PCDATA)*
802 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
803 if ( !aShDescr.isNull() )
805 // text is always a sub-node of element, containing it
806 //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
807 LDOM_Node aNode = aShDescr.getFirstChild();
808 const LDOM_Text& aText = (const LDOM_Text&) aNode;
809 LDOM_Text aShDescrTxt(aText);
810 if ( !aShDescrTxt.isNull() )
811 aShortD = aShDescrTxt.getData();
814 // long description (#PCDATA)*
815 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
816 if ( !aLDescr.isNull() )
818 // text is always a sub-node of element, containing it
819 //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
820 LDOM_Node aNode = aLDescr.getFirstChild();
821 const LDOM_Text& aText = (const LDOM_Text&) aNode;
822 LDOM_Text aLDescrTxt(aText);
823 if ( !aLDescrTxt.isNull() )
824 aLongD = aLDescrTxt.getData();
829 LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) );
830 if ( !anOpt.isNull() )
832 LDOM_NodeList anOptions = anOpt.GetAttributesList();//anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) );
833 for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ )
835 LDOM_Node node = anOptions.item( oi );
836 LDOM_Node::NodeType t = node.getNodeType();
838 TCollection_AsciiString name;
839 TCollection_ExtendedString value;
841 if( t==LDOM_Node::ELEMENT_NODE )
843 const LDOM_Element& elem = ( const LDOM_Element& )node;
844 name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) );
846 const LDOM_Node aNode = elem.getFirstChild();
847 LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) );
848 if ( !anOptTxt.isNull() )
849 value = anOptTxt.getData();
851 else if( t==LDOM_Node::ATTRIBUTE_NODE )
853 const LDOM_Attr& attr = ( const LDOM_Attr& )node;
854 name = ( Standard_CString )attr.getName().GetString();
855 LDOMString v = attr.getValue();
856 if( v.Type()==LDOMBasicString::LDOM_Integer )
858 Standard_Integer ival;
859 v.GetInteger( ival );
860 value = TCollection_ExtendedString( ival );
863 value = ( Standard_CString )v.GetString();
868 if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) )
869 myOptions.Bind( name, value );
873 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
875 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
877 UnitData& anUnitData = it.ChangeValue();
880 anUnitData.myZero = 0.;
881 anUnitData.myScale = 1.;
883 Standard_CString aUnitDataStr;
884 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
885 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
887 Handle(Units_Dimensions) aDim;
888 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
889 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
890 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
891 if ( !aDimMap.IsBound( it.Key() ) )
892 aDimMap.Bind( it.Key(), aDim );
894 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
895 anUnitData.myScale = 0.01;
897 catch( Standard_Failure ) {
898 anUnitData.myUnits.Clear();
901 Handle(Units_Dimensions) aPrev;
902 Standard_Boolean aStatus = Standard_True;
903 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
904 itr.More() && aStatus; itr.Next() )
906 if ( itr.Value().IsNull() )
909 if ( aPrev.IsNull() )
912 aStatus = aPrev->IsEqual( itr.Value() );
916 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
921 myWarnLevel = aWrongValue;
922 myLabel = aLabel.ToCString();
923 myFilter = aFilter.ToCString();
924 myLongDescr = aLongD.ToCString();
925 myShortDescr = aShortD.ToCString();
928 myDefValue = aRealDefV;
929 myDefString = aDefV.ToCString();
930 myRequired = aRequired.ToCString();
931 myListName = aListName.ToCString();
932 myMinZoom = aMinZoom;
933 myMaxZoom = aMaxZoom;
934 myZoomOrder = aZoomOrder;
937 PrepareFormats( aFormat );
939 const Standard_Integer aLength = aSeqOfValue.Length();
942 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
943 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
944 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
945 for ( Standard_Integer i = aLength; i > 0; i-- )
947 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
948 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
949 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
953 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
954 myDefString = myListRef->Value( myListRef->Lower() );
958 \brief Restore default formats for all the units systems.
960 void DDS_DicItem::GetDefaultFormat()
962 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
964 UnitData& anUnitData = it.ChangeValue();
969 anUnitData.myFormat = "%d";
972 anUnitData.myFormat = "%g";
976 anUnitData.myFormat.Clear();
983 \brief Get format for the string.
984 \param theFlags format flags
985 \param theWidth field width
986 \param thePrecision precision
987 \param theTypePrefix type prefix
988 \param theFormat returning format string
990 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
991 const TCollection_AsciiString& theWidth,
992 const TCollection_AsciiString& thePrecision,
993 const TCollection_AsciiString& theTypePrefix,
994 TCollection_AsciiString& theFormat )
997 theFormat += theFlags;
998 theFormat += theWidth;
1000 if ( !thePrecision.IsEmpty() )
1003 theFormat += thePrecision;
1006 theFormat += theTypePrefix;
1011 \brief Get format for the integer.
1012 \param theFlags format flags
1013 \param theWidth field width
1014 \param thePrecision precision
1015 \param theTypePrefix type prefix
1016 \param theType integer value type
1017 \param theFormat returning format string
1019 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
1020 const TCollection_AsciiString& theWidth,
1021 const TCollection_AsciiString& thePrecision,
1022 const TCollection_AsciiString& theTypePrefix,
1023 const Standard_Character theType,
1024 TCollection_AsciiString& theFormat )
1026 Standard_Integer aPrecision = 0;
1027 if ( !thePrecision.IsEmpty() )
1028 aPrecision = thePrecision.IntegerValue();
1029 Standard_Integer aWidth = 0;
1031 if ( !theWidth.IsEmpty() )
1032 aWidth = theWidth.IntegerValue();
1034 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
1036 // possible value 0.1 will be 10.0
1037 aWidth -= aPrecision;
1041 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1042 aWidth = aPrecision + 2;
1046 theFormat += theFlags;
1047 if ( !theWidth.IsEmpty() )
1048 theFormat += aWidth;
1050 theFormat += theTypePrefix;
1051 theFormat += theType;
1055 \brief Returns format for the float.
1056 \param theFlags format flags
1057 \param theWidth field width
1058 \param thePrecision precision
1059 \param theTypePrefix type prefix
1060 \param theType floating point value type
1061 \param theFormat returning format string
1063 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
1064 const TCollection_AsciiString& theWidth,
1065 const TCollection_AsciiString& thePrecision,
1066 const TCollection_AsciiString& theTypePrefix,
1067 const Standard_Character theType,
1068 TCollection_AsciiString& theFormat )
1070 Standard_Integer aPrecision = 0;
1071 if ( !thePrecision.IsEmpty() )
1072 aPrecision = thePrecision.IntegerValue();
1073 Standard_Integer aWidth = 0;
1075 if (!theWidth.IsEmpty() )
1076 aWidth = theWidth.IntegerValue();
1078 if (!thePrecision.IsEmpty() && aPrecision < 0 )
1080 // possible value 0.1 will be 10.0
1081 aWidth -= aPrecision;
1085 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
1087 aWidth = aPrecision + 2;
1091 theFormat += theFlags;
1093 if ( !theWidth.IsEmpty() )
1094 theFormat += aWidth;
1096 if ( !thePrecision.IsEmpty() )
1099 theFormat += aPrecision;
1102 theFormat += theTypePrefix;
1103 theFormat += theType;
1107 \brief Prepare formats for all units systems.
1108 \param theFormat format string
1110 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
1112 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
1114 UnitData& anUnitData = it.ChangeValue();
1116 anUnitData.myFormat = theFormat;
1117 anUnitData.myPrecision = 0;
1120 TCollection_AsciiString aPrecisionStr;
1121 if ( theFormat.IsEmpty() && myType == List )
1124 // checking % presenting
1125 if ( *theFormat.ToCString() != '%' )
1131 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
1132 Standard_Character aType = aStr.Value( aStr.Length() );
1134 if ( ( aType != 's' && myType == String ) ||
1135 ( aType != 'd' && myType == Integer ) ||
1136 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
1142 // removing type character
1143 aStr.Trunc( aStr.Length() - 1 );
1145 TCollection_AsciiString aFlags;
1146 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
1148 aFlags = aFlags + aStr.Value( 1 );
1152 Standard_Integer aPos = 1;
1153 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
1154 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
1157 TCollection_AsciiString aTypePrefix;
1158 if ( aPos <= aStr.Length() )
1160 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
1161 aStr.Trunc( aPos - 1 );
1164 Standard_Integer aBasePrecision = 0;
1166 // taking width and precision
1167 TCollection_AsciiString aPrecision;
1169 aPos = aStr.Search( "." );
1172 // aPrecision is defined
1173 aPrecision = aStr.Split( aPos );
1174 aStr.Remove( aStr.Length() );
1175 if ( !aPrecision.IsEmpty() )
1177 if ( !aPrecision.IsIntegerValue() )
1184 aPrecisionStr = aPrecision;
1185 aBasePrecision = aPrecision.IntegerValue();
1190 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
1196 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
1201 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1203 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
1204 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
1209 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
1211 UnitData& anUnitData = itr.ChangeValue();
1212 Standard_Integer aAmendment =
1213 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
1214 anUnitData.myPrecision = aBasePrecision + aAmendment;
1215 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
1218 if ( myType == Integer )
1219 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1221 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
1231 \brief Split the string \a theStr separated by spaces.
1232 \param theStr source string
1233 \param aRes returning substrings array
1235 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
1239 if ( theStr.Length() > 0 )
1241 TCollection_AsciiString aStr = theStr;
1242 TColStd_SequenceOfAsciiString aSeq;
1243 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1244 while( anIndex > 1 )
1246 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
1247 tmpStr.RemoveAll( ( Standard_Character )' ' );
1248 if ( tmpStr.Length() > 0 )
1249 aSeq.Append( tmpStr );
1250 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
1253 aStr.RemoveAll( ( Standard_Character )' ' );
1254 if ( aStr.Length() > 0 )
1255 aSeq.Append( aStr );
1257 if ( aSeq.Length() > 0 )
1259 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
1260 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
1261 aRes->ChangeValue( i ) = aSeq( i );
1267 \brief Get units structure for specified units system \a sys.
1268 \param sys units system
1269 \return units system information structure
1271 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
1275 if ( myUnitData.IsBound( sys ) )
1276 unit = (UnitData*)&myUnitData.Find( sys );
1282 \brief Get the active units system.
1283 \return active units system
1285 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
1288 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
1289 if ( !aComponent.IsNull() )
1290 aSystem = aComponent->GetActiveUnitSystem();