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& theCompElement, const LDOM_Element& theDocElement,
313 const TColStd_SequenceOfAsciiString& theSystems )
315 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
316 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
317 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
318 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
320 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
322 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
324 UnitSystem anUnitSystem = theSystems.Value( j );
325 if ( !anUnitSystem.Length() )
328 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
330 if ( !myUnitData.IsBound( anUnitSystem ) )
331 myUnitData.Bind( anUnitSystem, UnitData() );
333 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
334 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
337 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
338 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
340 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
341 if ( units.Length() )
342 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
345 TCollection_AsciiString units;
346 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
347 units = iter.Value().myUnits;
349 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
351 UnitData& dataUnits = itr.ChangeValue();
352 if ( dataUnits.myUnits.IsEmpty() )
353 dataUnits.myUnits = units;
356 // 2. Elements ( domain, description )
357 Standard_Real aRealMinV = 0;
358 Standard_Real aRealMaxV = 0;
359 Standard_Real aRealDefV = 0;
361 TCollection_AsciiString aType;
363 DDS_MsgType aWrongValue = DDS_MT_NONE;
364 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
366 TCollection_AsciiString aMinV;
367 TCollection_AsciiString aMaxV;
368 TCollection_AsciiString aDefV;
369 TCollection_AsciiString aListName;
371 TCollection_AsciiString aLongD;
372 TCollection_AsciiString aShortD;
374 TColStd_SequenceOfInteger aSeqOfValueID;
375 TColStd_SequenceOfExtendedString aSeqOfValue;
376 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
379 Standard_Real aMinZoom = 0;
380 Standard_Real aMaxZoom = 0;
381 Standard_Real aZoomOrder = 0;
383 // Datum::Reports tags (if any)
384 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
385 if ( !aWLev.isNull() )
387 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
388 if ( aWrongValWL.IsEqual( "Info" ) )
389 aWrongValue = DDS_MT_INFO;
390 else if ( aWrongValWL.IsEqual( "Warning" ) )
391 aWrongValue = DDS_MT_WARNING;
392 else if ( aWrongValWL.IsEqual( "Alarm" ) )
393 aWrongValue = DDS_MT_ALARM;
394 else if ( aWrongValWL.IsEqual( "Error" ) )
395 aWrongValue = DDS_MT_ERROR;
398 // Datum::Presentation
399 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
400 if ( !aPrs.isNull() )
402 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
403 if ( !aLateralZoom.isNull() )
405 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
406 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
407 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
409 aMinZoomStr.RemoveAll( ' ' );
410 if ( aMinZoomStr.IsRealValue() )
411 aMinZoom = aMinZoomStr.RealValue();
413 aMaxZoomStr.RemoveAll( ' ' );
414 if ( aMaxZoomStr.IsRealValue() )
415 aMaxZoom = aMaxZoomStr.RealValue();
417 aZoomOrderStr.RemoveAll( ' ' );
418 if ( aZoomOrderStr.IsRealValue() )
419 aZoomOrder = aZoomOrderStr.RealValue();
423 // Quantity::Domain record as the only child of that tag name
424 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
425 if ( !aDomain.isNull() )
427 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
428 if ( !aValueDescr.isNull() )
430 // read: valueDescr? (type?,min?,max?,default?)
431 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
432 if ( aType.IsEqual( "String" ) )
434 else if ( aType.IsEqual( "Float" ) )
436 else if ( aType.IsEqual( "Integer" ) )
439 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
440 aMinV.RemoveAll( ' ' );
441 if ( aMinV.IsRealValue() )
442 aRealMinV = aMinV.RealValue();
443 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
444 aMaxV.RemoveAll( ' ' );
445 if ( aMaxV.IsRealValue() )
446 aRealMaxV = aMaxV.RealValue();
447 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
448 aDefV.RemoveAll( ' ' );
449 if ( aDefV.IsRealValue() )
450 aRealDefV = aDefV.RealValue();
452 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
453 Split( aSpecVal, myListRef );
457 // read: listRef? (list?)
458 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
459 if ( !aListRef.isNull() )
463 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
464 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
465 aDefV.RemoveAll( ' ' );
466 LDOM_Element foundListItem;
467 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
468 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
470 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
471 foundListItem = aListItem;
474 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
475 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
477 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
478 foundListItem = aLstItem;
481 if ( foundListItem != NULL )
483 // The appropriate list of values is found: store the list name
484 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
485 // Iteration through the list of values
486 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
487 while ( aListItemValue != NULL )
490 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
491 if ( aListValueID.IsIntegerValue() )
493 // Read the text in the element "value"
494 LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
495 if ( !aListItemTxt.isNull() )
497 // adding ID and text value to sequence
498 aSeqOfValueID.Append( aListValueID.IntegerValue() );
499 aSeqOfValue.Append( aListItemTxt.getData() );
500 // adding icon file name (optional) to sequence
501 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
502 aSeqOfValueIconName.Append( aListValueIcon );
504 aListItemValue = aListItemValue.GetSiblingByTagName();
512 // Quantity::Description record as the only child of that tag name
513 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
514 if ( !aDescr.isNull() )
516 // short description (#PCDATA)*
517 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
518 if ( !aShDescr.isNull() )
520 // text is always a sub-node of element, containing it
521 LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
522 if ( !aShDescrTxt.isNull() )
523 aShortD = aShDescrTxt.getData();
526 // long description (#PCDATA)*
527 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
528 if ( !aLDescr.isNull() )
530 // text is always a sub-node of element, containing it
531 LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
532 if ( !aLDescrTxt.isNull() )
533 aLongD = aLDescrTxt.getData();
537 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
539 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
541 UnitData& anUnitData = it.ChangeValue();
544 anUnitData.myZero = 0.;
545 anUnitData.myScale = 1.;
547 Standard_CString aUnitDataStr;
548 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
549 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
551 Handle(Units_Dimensions) aDim;
552 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
553 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
554 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
555 if ( !aDimMap.IsBound( it.Key() ) )
556 aDimMap.Bind( it.Key(), aDim );
558 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
559 anUnitData.myScale = 0.01;
561 catch( Standard_Failure ) {
562 anUnitData.myUnits.Clear();
565 Handle(Units_Dimensions) aPrev;
566 Standard_Boolean aStatus = Standard_True;
567 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
568 itr.More() && aStatus; itr.Next() )
570 if ( itr.Value().IsNull() )
573 if ( aPrev.IsNull() )
576 aStatus = aPrev->IsEqual( itr.Value() );
580 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
585 myWarnLevel = aWrongValue;
586 myLabel = aLabel.ToCString();
587 myFilter = aFilter.ToCString();
588 myLongDescr = aLongD.ToCString();
589 myShortDescr = aShortD.ToCString();
592 myDefValue = aRealDefV;
593 myDefString = aDefV.ToCString();
594 myRequired = aRequired.ToCString();
595 myListName = aListName.ToCString();
596 myMinZoom = aMinZoom;
597 myMaxZoom = aMaxZoom;
598 myZoomOrder = aZoomOrder;
601 PrepareFormats( aFormat );
603 const Standard_Integer aLength = aSeqOfValue.Length();
606 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
607 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
608 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
609 for ( Standard_Integer i = aLength; i > 0; i-- )
611 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
612 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
613 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
617 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
618 myDefString = myListRef->Value( myListRef->Lower() );
622 Returns default formats for each unit systems
624 void DDS_DicItem::GetDefaultFormat()
626 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
628 UnitData& anUnitData = it.ChangeValue();
633 anUnitData.myFormat = "%d";
636 anUnitData.myFormat = "%g";
640 anUnitData.myFormat.Clear();
647 Returns format for the string
649 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
650 const TCollection_AsciiString& theWidth,
651 const TCollection_AsciiString& thePrecision,
652 const TCollection_AsciiString& theTypePrefix,
653 TCollection_AsciiString& theFormat )
656 theFormat += theFlags;
657 theFormat += theWidth;
659 if ( !thePrecision.IsEmpty() )
662 theFormat += thePrecision;
665 theFormat += theTypePrefix;
670 Returns format for the integer
672 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
673 const TCollection_AsciiString& theWidth,
674 const TCollection_AsciiString& thePrecision,
675 const TCollection_AsciiString& theTypePrefix,
676 const Standard_Character theType,
677 TCollection_AsciiString& theFormat )
679 Standard_Integer aPrecision = 0;
680 if ( !thePrecision.IsEmpty() )
681 aPrecision = thePrecision.IntegerValue();
682 Standard_Integer aWidth = 0;
684 if ( !theWidth.IsEmpty() )
685 aWidth = theWidth.IntegerValue();
687 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
689 // possible value 0.1 will be 10.0
690 aWidth -= aPrecision;
694 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
695 aWidth = aPrecision + 2;
699 theFormat += theFlags;
700 if ( !theWidth.IsEmpty() )
703 theFormat += theTypePrefix;
704 theFormat += theType;
708 Returns format for the float
710 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
711 const TCollection_AsciiString& theWidth,
712 const TCollection_AsciiString& thePrecision,
713 const TCollection_AsciiString& theTypePrefix,
714 const Standard_Character theType,
715 TCollection_AsciiString& theFormat )
717 Standard_Integer aPrecision = 0;
718 if ( !thePrecision.IsEmpty() )
719 aPrecision = thePrecision.IntegerValue();
720 Standard_Integer aWidth = 0;
722 if (!theWidth.IsEmpty() )
723 aWidth = theWidth.IntegerValue();
725 if (!thePrecision.IsEmpty() && aPrecision < 0 )
727 // possible value 0.1 will be 10.0
728 aWidth -= aPrecision;
732 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
734 aWidth = aPrecision + 2;
738 theFormat += theFlags;
740 if ( !theWidth.IsEmpty() )
743 if ( !thePrecision.IsEmpty() )
746 theFormat += aPrecision;
749 theFormat += theTypePrefix;
750 theFormat += theType;
754 Prepares three formants for each unit systems
756 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
758 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
760 UnitData& anUnitData = it.ChangeValue();
762 anUnitData.myFormat = theFormat;
763 anUnitData.myPrecision = 0;
766 TCollection_AsciiString aPrecisionStr;
767 if ( theFormat.IsEmpty() && myType == List )
770 // checking % presenting
771 if ( *theFormat.ToCString() != '%' )
777 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
778 Standard_Character aType = aStr.Value( aStr.Length() );
780 if ( ( aType != 's' && myType == String ) ||
781 ( aType != 'd' && myType == Integer ) ||
782 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
788 // removing type character
789 aStr.Trunc( aStr.Length() - 1 );
791 TCollection_AsciiString aFlags;
792 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
794 aFlags = aFlags + aStr.Value( 1 );
798 Standard_Integer aPos = 1;
799 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
800 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
803 TCollection_AsciiString aTypePrefix;
804 if ( aPos <= aStr.Length() )
806 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
807 aStr.Trunc( aPos - 1 );
810 Standard_Integer aBasePrecision = 0;
812 // taking width and precision
813 TCollection_AsciiString aPrecision;
815 aPos = aStr.Search( "." );
818 // aPrecision is defined
819 aPrecision = aStr.Split( aPos );
820 aStr.Remove( aStr.Length() );
821 if ( !aPrecision.IsEmpty() )
823 if ( !aPrecision.IsIntegerValue() )
830 aPrecisionStr = aPrecision;
831 aBasePrecision = aPrecision.IntegerValue();
836 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
842 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
847 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
849 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
850 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
855 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
857 UnitData& anUnitData = itr.ChangeValue();
858 Standard_Integer aAmendment =
859 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
860 anUnitData.myPrecision = aBasePrecision + aAmendment;
861 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
864 if ( myType == Integer )
865 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
867 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
876 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
880 if ( theStr.Length() > 0 )
882 TCollection_AsciiString aStr = theStr;
883 TColStd_SequenceOfAsciiString aSeq;
884 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
887 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
888 tmpStr.RemoveAll( ( Standard_Character )' ' );
889 if ( tmpStr.Length() > 0 )
890 aSeq.Append( tmpStr );
891 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
894 aStr.RemoveAll( ( Standard_Character )' ' );
895 if ( aStr.Length() > 0 )
898 if ( aSeq.Length() > 0 )
900 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
901 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
902 aRes->ChangeValue( i ) = aSeq( i );
907 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
911 if ( myUnitData.IsBound( sys ) )
912 unit = (UnitData*)&myUnitData.Find( sys );
917 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
920 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
921 if ( !aComponent.IsNull() )
922 aSystem = aComponent->GetActiveUnitSystem();