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 Parse record in XML file and retrieve information relevant for this data dic item
311 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
312 const LDOM_Element& theDocElement, const TColStd_SequenceOfAsciiString& theSystems )
314 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
315 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
316 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
317 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
319 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
321 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
323 UnitSystem anUnitSystem = theSystems.Value( j );
324 if ( !anUnitSystem.Length() )
327 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
329 if ( !myUnitData.IsBound( anUnitSystem ) )
330 myUnitData.Bind( anUnitSystem, UnitData() );
332 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
333 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
336 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
337 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
339 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
340 if ( units.Length() )
341 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
344 TCollection_AsciiString units;
345 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
346 units = iter.Value().myUnits;
348 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
350 UnitData& dataUnits = itr.ChangeValue();
351 if ( dataUnits.myUnits.IsEmpty() )
352 dataUnits.myUnits = units;
355 // 2. Elements ( domain, description )
356 Standard_Real aRealMinV = 0;
357 Standard_Real aRealMaxV = 0;
358 Standard_Real aRealDefV = 0;
360 TCollection_AsciiString aType;
362 DDS_MsgType aWrongValue = DDS_MT_NONE;
363 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
365 TCollection_AsciiString aMinV;
366 TCollection_AsciiString aMaxV;
367 TCollection_AsciiString aDefV;
368 TCollection_AsciiString aListName;
370 TCollection_AsciiString aLongD;
371 TCollection_AsciiString aShortD;
373 TColStd_SequenceOfInteger aSeqOfValueID;
374 TColStd_SequenceOfExtendedString aSeqOfValue;
375 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
378 Standard_Real aMinZoom = 0;
379 Standard_Real aMaxZoom = 0;
380 Standard_Real aZoomOrder = 0;
382 // Datum::Reports tags (if any)
383 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
384 if ( !aWLev.isNull() )
386 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
387 if ( aWrongValWL.IsEqual( "Info" ) )
388 aWrongValue = DDS_MT_INFO;
389 else if ( aWrongValWL.IsEqual( "Warning" ) )
390 aWrongValue = DDS_MT_WARNING;
391 else if ( aWrongValWL.IsEqual( "Alarm" ) )
392 aWrongValue = DDS_MT_ALARM;
393 else if ( aWrongValWL.IsEqual( "Error" ) )
394 aWrongValue = DDS_MT_ERROR;
397 // Datum::Presentation
398 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
399 if ( !aPrs.isNull() )
401 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
402 if ( !aLateralZoom.isNull() )
404 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
405 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
406 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
408 aMinZoomStr.RemoveAll( ' ' );
409 if ( aMinZoomStr.IsRealValue() )
410 aMinZoom = aMinZoomStr.RealValue();
412 aMaxZoomStr.RemoveAll( ' ' );
413 if ( aMaxZoomStr.IsRealValue() )
414 aMaxZoom = aMaxZoomStr.RealValue();
416 aZoomOrderStr.RemoveAll( ' ' );
417 if ( aZoomOrderStr.IsRealValue() )
418 aZoomOrder = aZoomOrderStr.RealValue();
422 // Quantity::Domain record as the only child of that tag name
423 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
424 if ( !aDomain.isNull() )
426 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
427 if ( !aValueDescr.isNull() )
429 // read: valueDescr? (type?,min?,max?,default?)
430 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
431 if ( aType.IsEqual( "String" ) )
433 else if ( aType.IsEqual( "Float" ) )
435 else if ( aType.IsEqual( "Integer" ) )
438 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
439 aMinV.RemoveAll( ' ' );
440 if ( aMinV.IsRealValue() )
441 aRealMinV = aMinV.RealValue();
442 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
443 aMaxV.RemoveAll( ' ' );
444 if ( aMaxV.IsRealValue() )
445 aRealMaxV = aMaxV.RealValue();
446 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
447 aDefV.RemoveAll( ' ' );
448 if ( aDefV.IsRealValue() )
449 aRealDefV = aDefV.RealValue();
451 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
452 Split( aSpecVal, myListRef );
456 // read: listRef? (list?)
457 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
458 if ( !aListRef.isNull() )
462 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
463 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
464 aDefV.RemoveAll( ' ' );
465 for ( LDOM_Element aListItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
466 aListItem != NULL; aListItem = aListItem.GetSiblingByTagName() )
468 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
470 // The appropriate list of values is found: store the list name
471 aListName = aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
472 // Iteration through the list of values
473 LDOM_Element aListItemValue = aListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
474 while ( aListItemValue != NULL )
477 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
478 if ( aListValueID.IsIntegerValue() )
480 // Read the text in the element "value"
481 LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
482 if ( !aListItemTxt.isNull() )
484 // adding ID and text value to sequence
485 aSeqOfValueID.Append( aListValueID.IntegerValue() );
486 aSeqOfValue.Append( aListItemTxt.getData() );
487 // adding icon file name (optional) to sequence
488 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
489 aSeqOfValueIconName.Append( aListValueIcon );
492 aListItemValue = aListItemValue.GetSiblingByTagName();
500 // Quantity::Description record as the only child of that tag name
501 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
502 if ( !aDescr.isNull() )
504 // short description (#PCDATA)*
505 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
506 if ( !aShDescr.isNull() )
508 // text is always a sub-node of element, containing it
509 LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
510 if ( !aShDescrTxt.isNull() )
511 aShortD = aShDescrTxt.getData();
514 // long description (#PCDATA)*
515 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
516 if ( !aLDescr.isNull() )
518 // text is always a sub-node of element, containing it
519 LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
520 if ( !aLDescrTxt.isNull() )
521 aLongD = aLDescrTxt.getData();
525 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
527 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
529 UnitData& anUnitData = it.ChangeValue();
532 anUnitData.myZero = 0.;
533 anUnitData.myScale = 1.;
535 Standard_CString aUnitDataStr;
536 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
537 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
539 Handle(Units_Dimensions) aDim;
540 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
541 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
542 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
543 if ( !aDimMap.IsBound( it.Key() ) )
544 aDimMap.Bind( it.Key(), aDim );
546 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
547 anUnitData.myScale = 0.01;
549 catch( Standard_Failure ) {
550 anUnitData.myUnits.Clear();
553 Handle(Units_Dimensions) aPrev;
554 Standard_Boolean aStatus = Standard_True;
555 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
556 itr.More() && aStatus; itr.Next() )
558 if ( itr.Value().IsNull() )
561 if ( aPrev.IsNull() )
564 aStatus = aPrev->IsEqual( itr.Value() );
568 printf( "Error in DataDictionary: Different dimensions for %s item", theID );
573 myWarnLevel = aWrongValue;
574 myLabel = aLabel.ToCString();
575 myFilter = aFilter.ToCString();
576 myLongDescr = aLongD.ToCString();
577 myShortDescr = aShortD.ToCString();
580 myDefValue = aRealDefV;
581 myDefString = aDefV.ToCString();
582 myRequired = aRequired.ToCString();
583 myListName = aListName.ToCString();
584 myMinZoom = aMinZoom;
585 myMaxZoom = aMaxZoom;
586 myZoomOrder = aZoomOrder;
589 PrepareFormats( aFormat );
591 const Standard_Integer aLength = aSeqOfValue.Length();
594 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
595 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
596 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
597 for ( Standard_Integer i = aLength; i > 0; i-- )
599 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
600 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
601 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
605 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
606 myDefString = myListRef->Value( myListRef->Lower() );
610 Returns default formats for each unit systems
612 void DDS_DicItem::GetDefaultFormat()
614 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
616 UnitData& anUnitData = it.ChangeValue();
621 anUnitData.myFormat = "%d";
624 anUnitData.myFormat = "%g";
628 anUnitData.myFormat.Clear();
635 Returns format for the string
637 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
638 const TCollection_AsciiString& theWidth,
639 const TCollection_AsciiString& thePrecision,
640 const TCollection_AsciiString& theTypePrefix,
641 TCollection_AsciiString& theFormat )
644 theFormat += theFlags;
645 theFormat += theWidth;
647 if ( !thePrecision.IsEmpty() )
650 theFormat += thePrecision;
653 theFormat += theTypePrefix;
658 Returns format for the integer
660 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
661 const TCollection_AsciiString& theWidth,
662 const TCollection_AsciiString& thePrecision,
663 const TCollection_AsciiString& theTypePrefix,
664 const Standard_Character theType,
665 TCollection_AsciiString& theFormat )
667 Standard_Integer aPrecision = 0;
668 if ( !thePrecision.IsEmpty() )
669 aPrecision = thePrecision.IntegerValue();
670 Standard_Integer aWidth = 0;
672 if ( !theWidth.IsEmpty() )
673 aWidth = theWidth.IntegerValue();
675 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
677 // possible value 0.1 will be 10.0
678 aWidth -= aPrecision;
682 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
683 aWidth = aPrecision + 2;
687 theFormat += theFlags;
688 if ( !theWidth.IsEmpty() )
691 theFormat += theTypePrefix;
692 theFormat += theType;
696 Returns format for the float
698 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
699 const TCollection_AsciiString& theWidth,
700 const TCollection_AsciiString& thePrecision,
701 const TCollection_AsciiString& theTypePrefix,
702 const Standard_Character theType,
703 TCollection_AsciiString& theFormat )
705 Standard_Integer aPrecision = 0;
706 if ( !thePrecision.IsEmpty() )
707 aPrecision = thePrecision.IntegerValue();
708 Standard_Integer aWidth = 0;
710 if (!theWidth.IsEmpty() )
711 aWidth = theWidth.IntegerValue();
713 if (!thePrecision.IsEmpty() && aPrecision < 0 )
715 // possible value 0.1 will be 10.0
716 aWidth -= aPrecision;
720 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
722 aWidth = aPrecision + 2;
726 theFormat += theFlags;
728 if ( !theWidth.IsEmpty() )
731 if ( !thePrecision.IsEmpty() )
734 theFormat += aPrecision;
737 theFormat += theTypePrefix;
738 theFormat += theType;
742 Prepares three formants for each unit systems
744 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
746 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
748 UnitData& anUnitData = it.ChangeValue();
750 anUnitData.myFormat = theFormat;
751 anUnitData.myPrecision = 0;
754 TCollection_AsciiString aPrecisionStr;
755 if ( theFormat.IsEmpty() && myType == List )
758 // checking % presenting
759 if ( *theFormat.ToCString() != '%' )
765 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
766 Standard_Character aType = aStr.Value( aStr.Length() );
768 if ( ( aType != 's' && myType == String ) ||
769 ( aType != 'd' && myType == Integer ) ||
770 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
776 // removing type character
777 aStr.Trunc( aStr.Length() - 1 );
779 TCollection_AsciiString aFlags;
780 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
782 aFlags = aFlags + aStr.Value( 1 );
786 Standard_Integer aPos = 1;
787 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
788 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
791 TCollection_AsciiString aTypePrefix;
792 if ( aPos <= aStr.Length() )
794 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
795 aStr.Trunc( aPos - 1 );
798 Standard_Integer aBasePrecision = 0;
800 // taking width and precision
801 TCollection_AsciiString aPrecision;
803 aPos = aStr.Search( "." );
806 // aPrecision is defined
807 aPrecision = aStr.Split( aPos );
808 aStr.Remove( aStr.Length() );
809 if ( !aPrecision.IsEmpty() )
811 if ( !aPrecision.IsIntegerValue() )
818 aPrecisionStr = aPrecision;
819 aBasePrecision = aPrecision.IntegerValue();
824 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
830 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
835 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
837 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
838 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
843 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
845 UnitData& anUnitData = itr.ChangeValue();
846 Standard_Integer aAmendment =
847 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
848 anUnitData.myPrecision = aBasePrecision + aAmendment;
849 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
852 if ( myType == Integer )
853 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
855 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
864 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
868 if ( theStr.Length() > 0 )
870 TCollection_AsciiString aStr = theStr;
871 TColStd_SequenceOfAsciiString aSeq;
872 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
875 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
876 tmpStr.RemoveAll( ( Standard_Character )' ' );
877 if ( tmpStr.Length() > 0 )
878 aSeq.Append( tmpStr );
879 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
882 aStr.RemoveAll( ( Standard_Character )' ' );
883 if ( aStr.Length() > 0 )
886 if ( aSeq.Length() > 0 )
888 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
889 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
890 aRes->ChangeValue( i ) = aSeq( i );
895 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
899 if ( myUnitData.IsBound( sys ) )
900 unit = (UnitData*)&myUnitData.Find( sys );
905 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
908 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
909 if ( !aComponent.IsNull() )
910 aSystem = aComponent->GetActiveUnitSystem();