1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "DDS_DicItem.h"
20 #include "DDS_Dictionary.h"
22 #include <TColStd_SequenceOfInteger.hxx>
23 #include <TColStd_SequenceOfExtendedString.hxx>
25 #include <LDOM_Text.hxx>
26 #include <LDOMString.hxx>
27 #include <LDOM_Element.hxx>
29 #include <UnitsAPI.hxx>
30 #include <Units_Dimensions.hxx>
32 #include <TColStd_MapOfReal.hxx>
33 #include <TColStd_SequenceOfAsciiString.hxx>
35 IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared)
36 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
38 DDS_DicItem::DDS_DicItem()
49 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
53 void DDS_DicItem::operator=( const DDS_DicItem& )
57 TCollection_AsciiString DDS_DicItem::GetId() const
62 DDS_DicItem::Type DDS_DicItem::GetType() const
64 return (DDS_DicItem::Type)myType;
67 TCollection_ExtendedString DDS_DicItem::GetLabel() const
72 TCollection_ExtendedString DDS_DicItem::GetFilter() const
77 TCollection_ExtendedString DDS_DicItem::GetRequired() const
82 DDS_MsgType DDS_DicItem::GetWarningLevel() const
84 return (DDS_MsgType)myWarnLevel;
87 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
92 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
97 TCollection_AsciiString DDS_DicItem::GetComponent() const
99 TCollection_AsciiString aCompName;
100 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
101 if ( !aComponent.IsNull() )
102 aCompName = aComponent->GetName();
106 TCollection_AsciiString DDS_DicItem::GetUnits() const
108 return GetUnits( GetActiveUnitSystem() );
111 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
113 TCollection_AsciiString anUnits;
114 UnitData* unitData = GetUnitData( theSystem );
116 anUnits = unitData->myUnits;
120 Standard_Real DDS_DicItem::GetMinValue() const
122 return GetMinValue( GetActiveUnitSystem() );
125 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
127 return FromSI( myMin, theUnitsSystem );
130 Standard_Real DDS_DicItem::GetMaxValue() const
132 return GetMaxValue( GetActiveUnitSystem() );
135 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
137 return FromSI( myMax, theUnitsSystem );
140 Standard_Integer DDS_DicItem::GetPrecision() const
142 return GetPrecision( GetActiveUnitSystem() );
145 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
147 Standard_Integer aRes = 0;
148 UnitData* unitData = GetUnitData( theSystem );
150 aRes = unitData->myPrecision;
154 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
156 return GetDefaultValue( GetActiveUnitSystem() );
159 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
161 if ( !myDefString.Length() )
164 TCollection_ExtendedString aStr;
170 aStr = FromSI( myDefValue, theSystem );
182 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
184 return GetFormat( GetActiveUnitSystem(), theCanonical );
187 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
188 const Standard_Boolean theCanonical ) const
190 TCollection_AsciiString aFormat;
191 UnitData* unitData = GetUnitData( theSystem );
193 aFormat = unitData->myFormat;
195 if ( theCanonical && aFormat.Length() > 1 )
197 static TCollection_AsciiString f;
199 Standard_Boolean isRemoved = false;
202 char ch = f.Value( f.Length() - 1 );
203 if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
204 f.Remove( f.Length() - 1 );
215 Access valueList:name of the parameter. This string is void if the list is
216 not defined - then use other properties: Type, DefaultValue, MaxValue, MinValue
218 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
224 Access valueList of the parameter. This sequence is empty if the list is
225 not defined - then use other properties: Type, DefaultValue, MaxValue, MinValue
227 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
228 Handle(TColStd_HArray1OfInteger)& theIntegers ) const
230 theStrings = myListRef;
231 theIntegers = myListRefID;
232 return !theIntegers.IsNull() && !theStrings.IsNull();
236 Access valueList of the parameter. This sequence is empty if the list is not
237 defined - then use other properties: Type, DefaultValue, MaxValue, MinValue
239 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
240 Handle(TColStd_HArray1OfInteger)& theIntegers,
241 Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
243 theStrings = myListRef;
244 theIntegers = myListRefID;
245 theIcons = myListRefIcons;
246 return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
249 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
252 if ( !myListRef.IsNull() )
254 for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
256 if ( myListRef->Value( i ).IsAscii() )
258 TCollection_AsciiString aStr( myListRef->Value( i ) );
259 if ( aStr.IsRealValue() )
260 theMap.Add( aStr.RealValue() );
265 return theMap.Extent() > 0;
269 Returns min value of lateral zooming
271 Standard_Real DDS_DicItem::GetMinZoom() const
277 Returns Max Value of lateral zooming
279 Standard_Real DDS_DicItem::GetMaxZoom() const
285 Get Order of lateral zooming
287 Standard_Real DDS_DicItem::GetZoomOrder() const
292 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
294 return ToSI( theVal, GetActiveUnitSystem() );
297 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
299 return FromSI( theVal, GetActiveUnitSystem() );
303 Convert value to default SI units according to current units
305 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
307 Standard_Real aRes = theVal;
308 UnitData* anUnitData = GetUnitData( theUnitsSystem );
310 aRes = anUnitData->myZero + aRes * anUnitData->myScale;
315 Convert value from default SI units according to current units
317 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
319 Standard_Real aRes = theVal;
320 UnitData* anUnitData = GetUnitData( theUnitsSystem );
322 aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
327 Returns 'true' if specified data exist.
329 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
331 return ( myData & flag ) == flag;
335 Parse record in XML file and retrieve information relevant for this data dic item
337 void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element& theDatum,
338 const LDOM_Element& theCompElement, const LDOM_Element& theDocElement,
339 const TColStd_SequenceOfAsciiString& theSystems )
341 TCollection_AsciiString aLabel = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_LABEL" ) );
342 TCollection_AsciiString aFormat = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FORMAT" ) );
343 TCollection_AsciiString aFilter = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_FILTER" ) );
344 TCollection_AsciiString aRequired = theDatum.getAttribute( DDS_Dictionary::KeyWord( "DATUM_REQUIRED" ) );
346 TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
348 for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
350 UnitSystem anUnitSystem = theSystems.Value( j );
351 if ( !anUnitSystem.Length() )
354 TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
356 if ( !myUnitData.IsBound( anUnitSystem ) )
357 myUnitData.Bind( anUnitSystem, UnitData() );
359 UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
360 anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
363 if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
364 !myUnitData.Find( theSystems.First() ).myUnits.Length() )
366 TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
367 if ( units.Length() )
368 myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
371 TCollection_AsciiString units;
372 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
373 units = iter.Value().myUnits;
375 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
377 UnitData& dataUnits = itr.ChangeValue();
378 if ( dataUnits.myUnits.IsEmpty() )
379 dataUnits.myUnits = units;
382 // 2. Elements ( domain, description )
383 Standard_Real aRealMinV = 0;
384 Standard_Real aRealMaxV = 0;
385 Standard_Real aRealDefV = 0;
387 TCollection_AsciiString aType;
389 DDS_MsgType aWrongValue = DDS_MT_NONE;
390 DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
392 TCollection_AsciiString aMinV;
393 TCollection_AsciiString aMaxV;
394 TCollection_AsciiString aDefV;
395 TCollection_AsciiString aListName;
397 TCollection_AsciiString aLongD;
398 TCollection_AsciiString aShortD;
400 TColStd_SequenceOfInteger aSeqOfValueID;
401 TColStd_SequenceOfExtendedString aSeqOfValue;
402 TColStd_SequenceOfExtendedString aSeqOfValueIconName;
405 Standard_Real aMinZoom = 0;
406 Standard_Real aMaxZoom = 0;
407 Standard_Real aZoomOrder = 0;
409 // Datum::Reports tags (if any)
410 LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
411 if ( !aWLev.isNull() )
413 TCollection_AsciiString aWrongValWL = aWLev.getAttribute( DDS_Dictionary::KeyWord( "WRONG_VALUE" ) );
414 if ( aWrongValWL.IsEqual( "Info" ) )
415 aWrongValue = DDS_MT_INFO;
416 else if ( aWrongValWL.IsEqual( "Warning" ) )
417 aWrongValue = DDS_MT_WARNING;
418 else if ( aWrongValWL.IsEqual( "Alarm" ) )
419 aWrongValue = DDS_MT_ALARM;
420 else if ( aWrongValWL.IsEqual( "Error" ) )
421 aWrongValue = DDS_MT_ERROR;
424 // Datum::Presentation
425 LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
426 if ( !aPrs.isNull() )
428 LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
429 if ( !aLateralZoom.isNull() )
431 TCollection_AsciiString aMinZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MINV" ) );
432 TCollection_AsciiString aMaxZoomStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_MAXV" ) );
433 TCollection_AsciiString aZoomOrderStr = aLateralZoom.getAttribute( DDS_Dictionary::KeyWord( "LZ_ORDER" ) );
435 aMinZoomStr.RemoveAll( ' ' );
436 if ( aMinZoomStr.IsRealValue() )
437 aMinZoom = aMinZoomStr.RealValue();
439 aMaxZoomStr.RemoveAll( ' ' );
440 if ( aMaxZoomStr.IsRealValue() )
441 aMaxZoom = aMaxZoomStr.RealValue();
443 aZoomOrderStr.RemoveAll( ' ' );
444 if ( aZoomOrderStr.IsRealValue() )
445 aZoomOrder = aZoomOrderStr.RealValue();
449 // Quantity::Domain record as the only child of that tag name
450 LDOM_Element aDomain = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DY_DOMAIN" ) );
451 if ( !aDomain.isNull() )
453 LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
454 if ( !aValueDescr.isNull() )
456 // read: valueDescr? (type?,min?,max?,default?)
457 aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
458 if ( aType.IsEqual( "String" ) )
460 else if ( aType.IsEqual( "Float" ) )
462 else if ( aType.IsEqual( "Integer" ) )
465 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
467 aMinV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MINV" ) );
468 aMinV.RemoveAll( ' ' );
469 if ( aMinV.IsRealValue() )
470 aRealMinV = aMinV.RealValue();
471 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MAXV" ) ).isNull() )
473 aMaxV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_MAXV" ) );
474 aMaxV.RemoveAll( ' ' );
475 if ( aMaxV.IsRealValue() )
476 aRealMaxV = aMaxV.RealValue();
477 aDefV = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
478 if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_DEFV" ) ).isNull() )
479 myData |= DefaultValue;
481 aDefV.RemoveAll( ' ' );
482 if ( aDefV.IsRealValue() )
483 aRealDefV = aDefV.RealValue();
485 TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
486 Split( aSpecVal, myListRef );
490 // read: listRef? (list?)
491 LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
492 if ( !aListRef.isNull() )
496 LDOMString aListId = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VLR_LIST" ) );
497 aDefV = aListRef.getAttribute( DDS_Dictionary::KeyWord( "VD_DEFV" ) );
498 aDefV.RemoveAll( ' ' );
499 LDOM_Element foundListItem;
500 for ( LDOM_Element aListItem = theCompElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
501 aListItem != NULL && foundListItem == NULL; aListItem = aListItem.GetSiblingByTagName() )
503 if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
504 foundListItem = aListItem;
507 for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
508 aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
510 if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
511 foundListItem = aLstItem;
514 if ( foundListItem != NULL )
516 // The appropriate list of values is found: store the list name
517 aListName = foundListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_NAME" ) );
518 // Iteration through the list of values
519 LDOM_Element aListItemValue = foundListItem.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUE" ) );
520 while ( aListItemValue != NULL )
523 TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
524 if ( aListValueID.IsIntegerValue() )
526 // Read the text in the element "value"
527 //LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
528 LDOM_Node aNode = aListItemValue.getFirstChild();
529 const LDOM_Text& aText = (const LDOM_Text&) aNode;
530 LDOM_Text aListItemTxt(aText);
531 if ( !aListItemTxt.isNull() )
533 // adding ID and text value to sequence
534 aSeqOfValueID.Append( aListValueID.IntegerValue() );
535 aSeqOfValue.Append( aListItemTxt.getData() );
536 // adding icon file name (optional) to sequence
537 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
538 aSeqOfValueIconName.Append( aListValueIcon );
540 aListItemValue = aListItemValue.GetSiblingByTagName();
548 // Quantity::Description record as the only child of that tag name
549 LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
550 if ( !aDescr.isNull() )
552 // short description (#PCDATA)*
553 LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
554 if ( !aShDescr.isNull() )
556 // text is always a sub-node of element, containing it
557 //LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
558 LDOM_Node aNode = aShDescr.getFirstChild();
559 const LDOM_Text& aText = (const LDOM_Text&) aNode;
560 LDOM_Text aShDescrTxt(aText);
561 if ( !aShDescrTxt.isNull() )
562 aShortD = aShDescrTxt.getData();
565 // long description (#PCDATA)*
566 LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
567 if ( !aLDescr.isNull() )
569 // text is always a sub-node of element, containing it
570 //LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
571 LDOM_Node aNode = aLDescr.getFirstChild();
572 const LDOM_Text& aText = (const LDOM_Text&) aNode;
573 LDOM_Text aLDescrTxt(aText);
574 if ( !aLDescrTxt.isNull() )
575 aLongD = aLDescrTxt.getData();
579 NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
581 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
583 UnitData& anUnitData = it.ChangeValue();
586 anUnitData.myZero = 0.;
587 anUnitData.myScale = 1.;
589 Standard_CString aUnitDataStr;
590 aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
591 if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
593 Handle(Units_Dimensions) aDim;
594 anUnitData.myZero = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
595 anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
596 UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
597 if ( !aDimMap.IsBound( it.Key() ) )
598 aDimMap.Bind( it.Key(), aDim );
600 else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
601 anUnitData.myScale = 0.01;
603 catch( Standard_Failure ) {
604 anUnitData.myUnits.Clear();
607 Handle(Units_Dimensions) aPrev;
608 Standard_Boolean aStatus = Standard_True;
609 for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
610 itr.More() && aStatus; itr.Next() )
612 if ( itr.Value().IsNull() )
615 if ( aPrev.IsNull() )
618 aStatus = aPrev->IsEqual( itr.Value() );
622 printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
627 myWarnLevel = aWrongValue;
628 myLabel = aLabel.ToCString();
629 myFilter = aFilter.ToCString();
630 myLongDescr = aLongD.ToCString();
631 myShortDescr = aShortD.ToCString();
634 myDefValue = aRealDefV;
635 myDefString = aDefV.ToCString();
636 myRequired = aRequired.ToCString();
637 myListName = aListName.ToCString();
638 myMinZoom = aMinZoom;
639 myMaxZoom = aMaxZoom;
640 myZoomOrder = aZoomOrder;
643 PrepareFormats( aFormat );
645 const Standard_Integer aLength = aSeqOfValue.Length();
648 myListRef = new TColStd_HArray1OfExtendedString( 1, aLength );
649 myListRefID = new TColStd_HArray1OfInteger( 1, aLength );
650 myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
651 for ( Standard_Integer i = aLength; i > 0; i-- )
653 myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
654 myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
655 myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
659 if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
660 myDefString = myListRef->Value( myListRef->Lower() );
664 Returns default formats for each unit systems
666 void DDS_DicItem::GetDefaultFormat()
668 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
670 UnitData& anUnitData = it.ChangeValue();
675 anUnitData.myFormat = "%d";
678 anUnitData.myFormat = "%g";
682 anUnitData.myFormat.Clear();
689 Returns format for the string
691 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
692 const TCollection_AsciiString& theWidth,
693 const TCollection_AsciiString& thePrecision,
694 const TCollection_AsciiString& theTypePrefix,
695 TCollection_AsciiString& theFormat )
698 theFormat += theFlags;
699 theFormat += theWidth;
701 if ( !thePrecision.IsEmpty() )
704 theFormat += thePrecision;
707 theFormat += theTypePrefix;
712 Returns format for the integer
714 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
715 const TCollection_AsciiString& theWidth,
716 const TCollection_AsciiString& thePrecision,
717 const TCollection_AsciiString& theTypePrefix,
718 const Standard_Character theType,
719 TCollection_AsciiString& theFormat )
721 Standard_Integer aPrecision = 0;
722 if ( !thePrecision.IsEmpty() )
723 aPrecision = thePrecision.IntegerValue();
724 Standard_Integer aWidth = 0;
726 if ( !theWidth.IsEmpty() )
727 aWidth = theWidth.IntegerValue();
729 if ( !thePrecision.IsEmpty() && aPrecision < 0 )
731 // possible value 0.1 will be 10.0
732 aWidth -= aPrecision;
736 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
737 aWidth = aPrecision + 2;
741 theFormat += theFlags;
742 if ( !theWidth.IsEmpty() )
745 theFormat += theTypePrefix;
746 theFormat += theType;
750 Returns format for the float
752 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
753 const TCollection_AsciiString& theWidth,
754 const TCollection_AsciiString& thePrecision,
755 const TCollection_AsciiString& theTypePrefix,
756 const Standard_Character theType,
757 TCollection_AsciiString& theFormat )
759 Standard_Integer aPrecision = 0;
760 if ( !thePrecision.IsEmpty() )
761 aPrecision = thePrecision.IntegerValue();
762 Standard_Integer aWidth = 0;
764 if (!theWidth.IsEmpty() )
765 aWidth = theWidth.IntegerValue();
767 if (!thePrecision.IsEmpty() && aPrecision < 0 )
769 // possible value 0.1 will be 10.0
770 aWidth -= aPrecision;
774 if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
776 aWidth = aPrecision + 2;
780 theFormat += theFlags;
782 if ( !theWidth.IsEmpty() )
785 if ( !thePrecision.IsEmpty() )
788 theFormat += aPrecision;
791 theFormat += theTypePrefix;
792 theFormat += theType;
796 Prepares three formants for each unit systems
798 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString& theFormat )
800 for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
802 UnitData& anUnitData = it.ChangeValue();
804 anUnitData.myFormat = theFormat;
805 anUnitData.myPrecision = 0;
808 TCollection_AsciiString aPrecisionStr;
809 if ( theFormat.IsEmpty() && myType == List )
812 // checking % presenting
813 if ( *theFormat.ToCString() != '%' )
819 TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
820 Standard_Character aType = aStr.Value( aStr.Length() );
822 if ( ( aType != 's' && myType == String ) ||
823 ( aType != 'd' && myType == Integer ) ||
824 ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
830 // removing type character
831 aStr.Trunc( aStr.Length() - 1 );
833 TCollection_AsciiString aFlags;
834 while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
836 aFlags = aFlags + aStr.Value( 1 );
840 Standard_Integer aPos = 1;
841 while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
842 ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
845 TCollection_AsciiString aTypePrefix;
846 if ( aPos <= aStr.Length() )
848 aTypePrefix = aStr.SubString( aPos, aStr.Length() );
849 aStr.Trunc( aPos - 1 );
852 Standard_Integer aBasePrecision = 0;
854 // taking width and precision
855 TCollection_AsciiString aPrecision;
857 aPos = aStr.Search( "." );
860 // aPrecision is defined
861 aPrecision = aStr.Split( aPos );
862 aStr.Remove( aStr.Length() );
863 if ( !aPrecision.IsEmpty() )
865 if ( !aPrecision.IsIntegerValue() )
872 aPrecisionStr = aPrecision;
873 aBasePrecision = aPrecision.IntegerValue();
878 if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
884 NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
889 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
891 if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
892 GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
897 for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
899 UnitData& anUnitData = itr.ChangeValue();
900 Standard_Integer aAmendment =
901 (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
902 anUnitData.myPrecision = aBasePrecision + aAmendment;
903 aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
906 if ( myType == Integer )
907 GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
909 GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
918 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
922 if ( theStr.Length() > 0 )
924 TCollection_AsciiString aStr = theStr;
925 TColStd_SequenceOfAsciiString aSeq;
926 Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
929 TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
930 tmpStr.RemoveAll( ( Standard_Character )' ' );
931 if ( tmpStr.Length() > 0 )
932 aSeq.Append( tmpStr );
933 anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
936 aStr.RemoveAll( ( Standard_Character )' ' );
937 if ( aStr.Length() > 0 )
940 if ( aSeq.Length() > 0 )
942 aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
943 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
944 aRes->ChangeValue( i ) = aSeq( i );
949 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
953 if ( myUnitData.IsBound( sys ) )
954 unit = (UnitData*)&myUnitData.Find( sys );
959 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
962 Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
963 if ( !aComponent.IsNull() )
964 aSystem = aComponent->GetActiveUnitSystem();