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 LDOM_Node aNode = aListItemValue.getFirstChild();
511 const LDOM_Text& aText = (const LDOM_Text&) aNode;
512 LDOM_Text aListItemTxt(aText);
513 if ( !aListItemTxt.isNull() )
515 // adding ID and text value to sequence
516 aSeqOfValueID.Append( aListValueID.IntegerValue() );
517 aSeqOfValue.Append( aListItemTxt.getData() );
518 // adding icon file name (optional) to sequence
519 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
520 aSeqOfValueIconName.Append( aListValueIcon );
522 aListItemValue = aListItemValue.GetSiblingByTagName();
530 // Quantity::Description record as the only child of that tag name
531 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
532 if ( !aDescr.isNull() )
534 // short description (#PCDATA)*
535 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
536 if ( !aShDescr.isNull() )
538 // text is always a sub-node of element, containing it
539 //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
540 LDOM_Node aNode = aShDescr.getFirstChild();
541 const LDOM_Text& aText = (const LDOM_Text&) aNode;
542 LDOM_Text aShDescrTxt(aText);
543 if ( !aShDescrTxt.isNull() )
544 aShortD = aShDescrTxt.getData();
547 // long description (#PCDATA)*
548 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
549 if ( !aLDescr.isNull() )
551 // text is always a sub-node of element, containing it
552 //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
553 LDOM_Node aNode = aLDescr.getFirstChild();
554 const LDOM_Text& aText = (const LDOM_Text&) aNode;
555 LDOM_Text aLDescrTxt(aText);
556 if ( !aLDescrTxt.isNull() )
557 aLongD = aLDescrTxt.getData();
561 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
563 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
565 UnitData& anUnitData = it.ChangeValue();
568 anUnitData.myZero = 0.;
569 anUnitData.myScale = 1.;
571 Standard_CString aUnitDataStr;
572 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
573 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
575 Handle(Units_Dimensions) aDim;
576 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
577 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
578 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
579 if ( !aDimMap.IsBound( it.Key() ) )
580 aDimMap.Bind( it.Key(), aDim );
582 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
583 anUnitData.myScale = 0.01;
585 catch( Standard_Failure ) {
586 anUnitData.myUnits.Clear();
589 Handle(Units_Dimensions) aPrev;
590 Standard_Boolean aStatus = Standard_True;
591 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
592 itr.More() && aStatus; itr.Next() )
594 if ( itr.Value().IsNull() )
597 if ( aPrev.IsNull() )
600 aStatus = aPrev->IsEqual( itr.Value() );
604 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
609 myWarnLevel = aWrongValue;
610 myLabel = aLabel.ToCString();
611 myFilter = aFilter.ToCString();
612 myLongDescr = aLongD.ToCString();
613 myShortDescr = aShortD.ToCString();
616 myDefValue = aRealDefV;
617 myDefString = aDefV.ToCString();
618 myRequired = aRequired.ToCString();
619 myListName = aListName.ToCString();
620 myMinZoom = aMinZoom;
621 myMaxZoom = aMaxZoom;
622 myZoomOrder = aZoomOrder;
625 PrepareFormats( aFormat );
627 const Standard_Integer aLength = aSeqOfValue.Length();
630 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
631 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
632 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
633 for ( Standard_Integer i = aLength; i > 0; i-- )
635 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
636 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
637 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
641 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
642 myDefString = myListRef->Value( myListRef->Lower() );
646 Returns default formats for each unit systems
648 void DDS_DicItem::GetDefaultFormat()
650 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
652 UnitData& anUnitData = it.ChangeValue();
657 anUnitData.myFormat = "%d";
660 anUnitData.myFormat = "%g";
664 anUnitData.myFormat.Clear();
671 Returns format for the string
673 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
674 const TCollection_AsciiString& theWidth,
675 const TCollection_AsciiString& thePrecision,
676 const TCollection_AsciiString& theTypePrefix,
677 TCollection_AsciiString& theFormat )
680 theFormat += theFlags;
681 theFormat += theWidth;
683 if ( !thePrecision.IsEmpty() )
686 theFormat += thePrecision;
689 theFormat += theTypePrefix;
694 Returns format for the integer
696 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
697 const TCollection_AsciiString& theWidth,
698 const TCollection_AsciiString& thePrecision,
699 const TCollection_AsciiString& theTypePrefix,
700 const Standard_Character theType,
701 TCollection_AsciiString& theFormat )
703 Standard_Integer aPrecision = 0;
704 if ( !thePrecision.IsEmpty() )
705 aPrecision = thePrecision.IntegerValue();
706 Standard_Integer aWidth = 0;
708 if ( !theWidth.IsEmpty() )
709 aWidth = theWidth.IntegerValue();
711 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
713 // possible value 0.1 will be 10.0
714 aWidth -= aPrecision;
718 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
719 aWidth = aPrecision + 2;
723 theFormat += theFlags;
724 if ( !theWidth.IsEmpty() )
727 theFormat += theTypePrefix;
728 theFormat += theType;
732 Returns format for the float
734 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
735 const TCollection_AsciiString& theWidth,
736 const TCollection_AsciiString& thePrecision,
737 const TCollection_AsciiString& theTypePrefix,
738 const Standard_Character theType,
739 TCollection_AsciiString& theFormat )
741 Standard_Integer aPrecision = 0;
742 if ( !thePrecision.IsEmpty() )
743 aPrecision = thePrecision.IntegerValue();
744 Standard_Integer aWidth = 0;
746 if (!theWidth.IsEmpty() )
747 aWidth = theWidth.IntegerValue();
749 if (!thePrecision.IsEmpty() && aPrecision < 0 )
751 // possible value 0.1 will be 10.0
752 aWidth -= aPrecision;
756 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
758 aWidth = aPrecision + 2;
762 theFormat += theFlags;
764 if ( !theWidth.IsEmpty() )
767 if ( !thePrecision.IsEmpty() )
770 theFormat += aPrecision;
773 theFormat += theTypePrefix;
774 theFormat += theType;
778 Prepares three formants for each unit systems
780 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
782 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
784 UnitData& anUnitData = it.ChangeValue();
786 anUnitData.myFormat = theFormat;
787 anUnitData.myPrecision = 0;
790 TCollection_AsciiString aPrecisionStr;
791 if ( theFormat.IsEmpty() && myType == List )
794 // checking % presenting
795 if ( *theFormat.ToCString() != '%' )
801 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
802 Standard_Character aType = aStr.Value( aStr.Length() );
804 if ( ( aType != 's' && myType == String ) ||
805 ( aType != 'd' && myType == Integer ) ||
806 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
812 // removing type character
813 aStr.Trunc( aStr.Length() - 1 );
815 TCollection_AsciiString aFlags;
816 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
818 aFlags = aFlags + aStr.Value( 1 );
822 Standard_Integer aPos = 1;
823 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
824 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
827 TCollection_AsciiString aTypePrefix;
828 if ( aPos <= aStr.Length() )
830 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
831 aStr.Trunc( aPos - 1 );
834 Standard_Integer aBasePrecision = 0;
836 // taking width and precision
837 TCollection_AsciiString aPrecision;
839 aPos = aStr.Search( "." );
842 // aPrecision is defined
843 aPrecision = aStr.Split( aPos );
844 aStr.Remove( aStr.Length() );
845 if ( !aPrecision.IsEmpty() )
847 if ( !aPrecision.IsIntegerValue() )
854 aPrecisionStr = aPrecision;
855 aBasePrecision = aPrecision.IntegerValue();
860 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
866 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
871 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
873 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
874 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
879 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
881 UnitData& anUnitData = itr.ChangeValue();
882 Standard_Integer aAmendment =
883 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
884 anUnitData.myPrecision = aBasePrecision + aAmendment;
885 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
888 if ( myType == Integer )
889 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
891 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
900 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
904 if ( theStr.Length() > 0 )
906 TCollection_AsciiString aStr = theStr;
907 TColStd_SequenceOfAsciiString aSeq;
908 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
911 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
912 tmpStr.RemoveAll( ( Standard_Character )' ' );
913 if ( tmpStr.Length() > 0 )
914 aSeq.Append( tmpStr );
915 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
918 aStr.RemoveAll( ( Standard_Character )' ' );
919 if ( aStr.Length() > 0 )
922 if ( aSeq.Length() > 0 )
924 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
925 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
926 aRes->ChangeValue( i ) = aSeq( i );
931 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
935 if ( myUnitData.IsBound( sys ) )
936 unit = (UnitData*)&myUnitData.Find( sys );
941 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
944 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
945 if ( !aComponent.IsNull() )
946 aSystem = aComponent->GetActiveUnitSystem();