1 #include "DDS_DicItem.h"
2 #include "DDS_Dictionary.h"
4 #include <TColStd_SequenceOfInteger.hxx>
5 #include <TColStd_SequenceOfExtendedString.hxx>
7 #include <LDOM_Text.hxx>
8 #include <LDOMString.hxx>
9 #include <LDOM_Element.hxx>
11 #include <UnitsAPI.hxx>
12 #include <Units_Dimensions.hxx>
14 #include <TColStd_MapOfReal.hxx>
15 #include <TColStd_SequenceOfAsciiString.hxx>
17 IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared)
18 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
20 DDS_DicItem::DDS_DicItem()
31 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
35 void DDS_DicItem::operator=( const DDS_DicItem& )
39 TCollection_AsciiString DDS_DicItem::GetId() const
44 DDS_DicItem::Type DDS_DicItem::GetType() const
46 return (DDS_DicItem::Type)myType;
49 TCollection_ExtendedString DDS_DicItem::GetLabel() const
54 TCollection_ExtendedString DDS_DicItem::GetFilter() const
59 TCollection_ExtendedString DDS_DicItem::GetRequired() const
64 DDS_MsgType DDS_DicItem::GetWarningLevel() const
66 return (DDS_MsgType)myWarnLevel;
69 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
74 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
79 TCollection_AsciiString DDS_DicItem::GetComponent() const
81 TCollection_AsciiString aCompName;
82 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
83 if ( !aComponent.IsNull() )
84 aCompName = aComponent->GetName();
88 TCollection_AsciiString DDS_DicItem::GetUnits() const
90 return GetUnits( GetActiveUnitSystem() );
93 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
95 TCollection_AsciiString anUnits;
96 UnitData* unitData = GetUnitData( theSystem );
98 anUnits = unitData->myUnits;
102 Standard_Real DDS_DicItem::GetMinValue() const
104 return GetMinValue( GetActiveUnitSystem() );
107 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
109 return FromSI( myMin, theUnitsSystem );
112 Standard_Real DDS_DicItem::GetMaxValue() const
114 return GetMaxValue( GetActiveUnitSystem() );
117 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
119 return FromSI( myMax, theUnitsSystem );
122 Standard_Integer DDS_DicItem::GetPrecision() const
124 return GetPrecision( GetActiveUnitSystem() );
127 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
129 Standard_Integer aRes = 0;
130 UnitData* unitData = GetUnitData( theSystem );
132 aRes = unitData->myPrecision;
136 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
138 return GetDefaultValue( GetActiveUnitSystem() );
141 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
143 if ( !myDefString.Length() )
146 TCollection_ExtendedString aStr;
152 aStr = FromSI( myDefValue, theSystem );
164 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
166 return GetFormat( GetActiveUnitSystem(), theCanonical );
169 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
170 const Standard_Boolean theCanonical ) const
172 TCollection_AsciiString aFormat;
173 UnitData* unitData = GetUnitData( theSystem );
175 aFormat = unitData->myFormat;
177 if ( theCanonical && aFormat.Length() > 1 )
179 static TCollection_AsciiString f;
181 Standard_Boolean isRemoved = false;
184 char ch = f.Value( f.Length() - 1 );
185 if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
186 f.Remove( f.Length() - 1 );
197 Access valueList:name of the parameter. This string is void if the list is
198 not defined - then use other properties: Type, DefaultValue, MaxValue, MinValue
200 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
206 Access valueList of the parameter. This sequence is empty if the list is
207 not defined - then use other properties: Type, DefaultValue, MaxValue, MinValue
209 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
210 Handle(TColStd_HArray1OfInteger)& theIntegers ) const
212 theStrings = myListRef;
213 theIntegers = myListRefID;
214 return !theIntegers.IsNull() && !theStrings.IsNull();
218 Access valueList of the parameter. This sequence is empty if the list is not
219 defined - then use other properties: Type, DefaultValue, MaxValue, MinValue
221 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
222 Handle(TColStd_HArray1OfInteger)& theIntegers,
223 Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
225 theStrings = myListRef;
226 theIntegers = myListRefID;
227 theIcons = myListRefIcons;
228 return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
231 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
234 if ( !myListRef.IsNull() )
236 for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
238 if ( myListRef->Value( i ).IsAscii() )
240 TCollection_AsciiString aStr( myListRef->Value( i ) );
241 if ( aStr.IsRealValue() )
242 theMap.Add( aStr.RealValue() );
247 return theMap.Extent() > 0;
251 Returns min value of lateral zooming
253 Standard_Real DDS_DicItem::GetMinZoom() const
259 Returns Max Value of lateral zooming
261 Standard_Real DDS_DicItem::GetMaxZoom() const
267 Get Order of lateral zooming
269 Standard_Real DDS_DicItem::GetZoomOrder() const
274 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
276 return ToSI( theVal, GetActiveUnitSystem() );
279 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
281 return FromSI( theVal, GetActiveUnitSystem() );
285 Convert value to default SI units according to current units
287 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
289 Standard_Real aRes = theVal;
290 UnitData* anUnitData = GetUnitData( theUnitsSystem );
292 aRes = anUnitData->myZero + aRes * anUnitData->myScale;
297 Convert value from default SI units according to current units
299 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
301 Standard_Real aRes = theVal;
302 UnitData* anUnitData = GetUnitData( theUnitsSystem );
304 aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
309 Returns 'true' if specified data exist.
311 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
313 return ( myData & flag ) == flag;
317 Parse record in XML file and retrieve information relevant for this data dic item
319 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
320 const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
321 const TColStd_SequenceOfAsciiString& theSystems )
323 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
324 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
325 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
326 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
328 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
330 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
332 UnitSystem anUnitSystem = theSystems.Value( j );
333 if ( !anUnitSystem.Length() )
336 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
338 if ( !myUnitData.IsBound( anUnitSystem ) )
339 myUnitData.Bind( anUnitSystem, UnitData() );
341 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
342 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
345 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
346 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
348 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
349 if ( units.Length() )
350 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
353 TCollection_AsciiString units;
354 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
355 units = iter.Value().myUnits;
357 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
359 UnitData& dataUnits = itr.ChangeValue();
360 if ( dataUnits.myUnits.IsEmpty() )
361 dataUnits.myUnits = units;
364 // 2. Elements ( domain, description )
365 Standard_Real aRealMinV = 0;
366 Standard_Real aRealMaxV = 0;
367 Standard_Real aRealDefV = 0;
369 TCollection_AsciiString aType;
371 DDS_MsgType aWrongValue = DDS_MT_NONE;
372 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
374 TCollection_AsciiString aMinV;
375 TCollection_AsciiString aMaxV;
376 TCollection_AsciiString aDefV;
377 TCollection_AsciiString aListName;
379 TCollection_AsciiString aLongD;
380 TCollection_AsciiString aShortD;
382 TColStd_SequenceOfInteger aSeqOfValueID;
383 TColStd_SequenceOfExtendedString aSeqOfValue;
384 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
387 Standard_Real aMinZoom = 0;
388 Standard_Real aMaxZoom = 0;
389 Standard_Real aZoomOrder = 0;
391 // Datum::Reports tags (if any)
392 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
393 if ( !aWLev.isNull() )
395 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
396 if ( aWrongValWL.IsEqual( "Info" ) )
397 aWrongValue = DDS_MT_INFO;
398 else if ( aWrongValWL.IsEqual( "Warning" ) )
399 aWrongValue = DDS_MT_WARNING;
400 else if ( aWrongValWL.IsEqual( "Alarm" ) )
401 aWrongValue = DDS_MT_ALARM;
402 else if ( aWrongValWL.IsEqual( "Error" ) )
403 aWrongValue = DDS_MT_ERROR;
406 // Datum::Presentation
407 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
408 if ( !aPrs.isNull() )
410 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
411 if ( !aLateralZoom.isNull() )
413 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
414 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
415 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
417 aMinZoomStr.RemoveAll( ' ' );
418 if ( aMinZoomStr.IsRealValue() )
419 aMinZoom = aMinZoomStr.RealValue();
421 aMaxZoomStr.RemoveAll( ' ' );
422 if ( aMaxZoomStr.IsRealValue() )
423 aMaxZoom = aMaxZoomStr.RealValue();
425 aZoomOrderStr.RemoveAll( ' ' );
426 if ( aZoomOrderStr.IsRealValue() )
427 aZoomOrder = aZoomOrderStr.RealValue();
431 // Quantity::Domain record as the only child of that tag name
432 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
433 if ( !aDomain.isNull() )
435 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
436 if ( !aValueDescr.isNull() )
438 // read: valueDescr? (type?,min?,max?,default?)
439 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
440 if ( aType.IsEqual( "String" ) )
442 else if ( aType.IsEqual( "Float" ) )
444 else if ( aType.IsEqual( "Integer" ) )
447 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
449 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
450 aMinV.RemoveAll( ' ' );
451 if ( aMinV.IsRealValue() )
452 aRealMinV = aMinV.RealValue();
453 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
455 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
456 aMaxV.RemoveAll( ' ' );
457 if ( aMaxV.IsRealValue() )
458 aRealMaxV = aMaxV.RealValue();
459 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
460 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
461 myData |= DefaultValue;
463 aDefV.RemoveAll( ' ' );
464 if ( aDefV.IsRealValue() )
465 aRealDefV = aDefV.RealValue();
467 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
468 Split( aSpecVal, myListRef );
472 // read: listRef? (list?)
473 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
474 if ( !aListRef.isNull() )
478 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
479 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
480 aDefV.RemoveAll( ' ' );
481 LDOM_Element foundListItem;
482 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
483 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
485 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
486 foundListItem = aListItem;
489 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
490 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
492 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
493 foundListItem = aLstItem;
496 if ( foundListItem != NULL )
498 // The appropriate list of values is found: store the list name
499 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
500 // Iteration through the list of values
501 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
502 while ( aListItemValue != NULL )
505 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
506 if ( aListValueID.IsIntegerValue() )
508 // Read the text in the element "value"
509 LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
510 if ( !aListItemTxt.isNull() )
512 // adding ID and text value to sequence
513 aSeqOfValueID.Append( aListValueID.IntegerValue() );
514 aSeqOfValue.Append( aListItemTxt.getData() );
515 // adding icon file name (optional) to sequence
516 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
517 aSeqOfValueIconName.Append( aListValueIcon );
519 aListItemValue = aListItemValue.GetSiblingByTagName();
527 // Quantity::Description record as the only child of that tag name
528 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
529 if ( !aDescr.isNull() )
531 // short description (#PCDATA)*
532 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
533 if ( !aShDescr.isNull() )
535 // text is always a sub-node of element, containing it
536 LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
537 if ( !aShDescrTxt.isNull() )
538 aShortD = aShDescrTxt.getData();
541 // long description (#PCDATA)*
542 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
543 if ( !aLDescr.isNull() )
545 // text is always a sub-node of element, containing it
546 LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
547 if ( !aLDescrTxt.isNull() )
548 aLongD = aLDescrTxt.getData();
552 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
554 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
556 UnitData& anUnitData = it.ChangeValue();
559 anUnitData.myZero = 0.;
560 anUnitData.myScale = 1.;
562 Standard_CString aUnitDataStr;
563 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
564 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
566 Handle(Units_Dimensions) aDim;
567 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
568 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
569 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
570 if ( !aDimMap.IsBound( it.Key() ) )
571 aDimMap.Bind( it.Key(), aDim );
573 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
574 anUnitData.myScale = 0.01;
576 catch( Standard_Failure ) {
577 anUnitData.myUnits.Clear();
580 Handle(Units_Dimensions) aPrev;
581 Standard_Boolean aStatus = Standard_True;
582 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
583 itr.More() && aStatus; itr.Next() )
585 if ( itr.Value().IsNull() )
588 if ( aPrev.IsNull() )
591 aStatus = aPrev->IsEqual( itr.Value() );
595 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
600 myWarnLevel = aWrongValue;
601 myLabel = aLabel.ToCString();
602 myFilter = aFilter.ToCString();
603 myLongDescr = aLongD.ToCString();
604 myShortDescr = aShortD.ToCString();
607 myDefValue = aRealDefV;
608 myDefString = aDefV.ToCString();
609 myRequired = aRequired.ToCString();
610 myListName = aListName.ToCString();
611 myMinZoom = aMinZoom;
612 myMaxZoom = aMaxZoom;
613 myZoomOrder = aZoomOrder;
616 PrepareFormats( aFormat );
618 const Standard_Integer aLength = aSeqOfValue.Length();
621 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
622 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
623 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
624 for ( Standard_Integer i = aLength; i > 0; i-- )
626 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
627 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
628 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
632 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
633 myDefString = myListRef->Value( myListRef->Lower() );
637 Returns default formats for each unit systems
639 void DDS_DicItem::GetDefaultFormat()
641 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
643 UnitData& anUnitData = it.ChangeValue();
648 anUnitData.myFormat = "%d";
651 anUnitData.myFormat = "%g";
655 anUnitData.myFormat.Clear();
662 Returns format for the string
664 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
665 const TCollection_AsciiString& theWidth,
666 const TCollection_AsciiString& thePrecision,
667 const TCollection_AsciiString& theTypePrefix,
668 TCollection_AsciiString& theFormat )
671 theFormat += theFlags;
672 theFormat += theWidth;
674 if ( !thePrecision.IsEmpty() )
677 theFormat += thePrecision;
680 theFormat += theTypePrefix;
685 Returns format for the integer
687 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
688 const TCollection_AsciiString& theWidth,
689 const TCollection_AsciiString& thePrecision,
690 const TCollection_AsciiString& theTypePrefix,
691 const Standard_Character theType,
692 TCollection_AsciiString& theFormat )
694 Standard_Integer aPrecision = 0;
695 if ( !thePrecision.IsEmpty() )
696 aPrecision = thePrecision.IntegerValue();
697 Standard_Integer aWidth = 0;
699 if ( !theWidth.IsEmpty() )
700 aWidth = theWidth.IntegerValue();
702 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
704 // possible value 0.1 will be 10.0
705 aWidth -= aPrecision;
709 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
710 aWidth = aPrecision + 2;
714 theFormat += theFlags;
715 if ( !theWidth.IsEmpty() )
718 theFormat += theTypePrefix;
719 theFormat += theType;
723 Returns format for the float
725 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
726 const TCollection_AsciiString& theWidth,
727 const TCollection_AsciiString& thePrecision,
728 const TCollection_AsciiString& theTypePrefix,
729 const Standard_Character theType,
730 TCollection_AsciiString& theFormat )
732 Standard_Integer aPrecision = 0;
733 if ( !thePrecision.IsEmpty() )
734 aPrecision = thePrecision.IntegerValue();
735 Standard_Integer aWidth = 0;
737 if (!theWidth.IsEmpty() )
738 aWidth = theWidth.IntegerValue();
740 if (!thePrecision.IsEmpty() && aPrecision < 0 )
742 // possible value 0.1 will be 10.0
743 aWidth -= aPrecision;
747 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
749 aWidth = aPrecision + 2;
753 theFormat += theFlags;
755 if ( !theWidth.IsEmpty() )
758 if ( !thePrecision.IsEmpty() )
761 theFormat += aPrecision;
764 theFormat += theTypePrefix;
765 theFormat += theType;
769 Prepares three formants for each unit systems
771 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
773 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
775 UnitData& anUnitData = it.ChangeValue();
777 anUnitData.myFormat = theFormat;
778 anUnitData.myPrecision = 0;
781 TCollection_AsciiString aPrecisionStr;
782 if ( theFormat.IsEmpty() && myType == List )
785 // checking % presenting
786 if ( *theFormat.ToCString() != '%' )
792 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
793 Standard_Character aType = aStr.Value( aStr.Length() );
795 if ( ( aType != 's' && myType == String ) ||
796 ( aType != 'd' && myType == Integer ) ||
797 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
803 // removing type character
804 aStr.Trunc( aStr.Length() - 1 );
806 TCollection_AsciiString aFlags;
807 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
809 aFlags = aFlags + aStr.Value( 1 );
813 Standard_Integer aPos = 1;
814 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
815 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
818 TCollection_AsciiString aTypePrefix;
819 if ( aPos <= aStr.Length() )
821 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
822 aStr.Trunc( aPos - 1 );
825 Standard_Integer aBasePrecision = 0;
827 // taking width and precision
828 TCollection_AsciiString aPrecision;
830 aPos = aStr.Search( "." );
833 // aPrecision is defined
834 aPrecision = aStr.Split( aPos );
835 aStr.Remove( aStr.Length() );
836 if ( !aPrecision.IsEmpty() )
838 if ( !aPrecision.IsIntegerValue() )
845 aPrecisionStr = aPrecision;
846 aBasePrecision = aPrecision.IntegerValue();
851 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
857 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
862 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
864 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
865 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
870 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
872 UnitData& anUnitData = itr.ChangeValue();
873 Standard_Integer aAmendment =
874 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
875 anUnitData.myPrecision = aBasePrecision + aAmendment;
876 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
879 if ( myType == Integer )
880 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
882 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
891 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
895 if ( theStr.Length() > 0 )
897 TCollection_AsciiString aStr = theStr;
898 TColStd_SequenceOfAsciiString aSeq;
899 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
902 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
903 tmpStr.RemoveAll( ( Standard_Character )' ' );
904 if ( tmpStr.Length() > 0 )
905 aSeq.Append( tmpStr );
906 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
909 aStr.RemoveAll( ( Standard_Character )' ' );
910 if ( aStr.Length() > 0 )
913 if ( aSeq.Length() > 0 )
915 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
916 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
917 aRes->ChangeValue( i ) = aSeq( i );
922 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
926 if ( myUnitData.IsBound( sys ) )
927 unit = (UnitData*)&myUnitData.Find( sys );
932 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
935 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
936 if ( !aComponent.IsNull() )
937 aSystem = aComponent->GetActiveUnitSystem();