]> SALOME platform Git repositories - modules/gui.git/blob - src/DDS/DDS_DicItem.cxx
Salome HOME
0c8b01c6d03d97a55a7544c32cfd215e6257be09
[modules/gui.git] / src / DDS / DDS_DicItem.cxx
1 #include "DDS_DicItem.h"
2 #include "DDS_Dictionary.h"
3
4 #include <TColStd_SequenceOfInteger.hxx>
5 #include <TColStd_SequenceOfExtendedString.hxx>
6
7 #include <LDOM_Text.hxx>
8 #include <LDOMString.hxx>
9 #include <LDOM_Element.hxx>
10
11 #include <UnitsAPI.hxx>
12 #include <Units_Dimensions.hxx>
13
14 #include <TColStd_MapOfReal.hxx>
15 #include <TColStd_SequenceOfAsciiString.hxx>
16
17 IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared)
18 IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared)
19
20 DDS_DicItem::DDS_DicItem()
21 : myType( 0 ),
22 myDefValue( 0 ),
23 myMax( 0 ),
24 myMin( 0 ),
25 myMinZoom( 0.1 ),
26 myMaxZoom( 10 ),
27 myZoomOrder( 2 )
28 {
29 }
30
31 DDS_DicItem::DDS_DicItem( const DDS_DicItem& )
32 {
33 }
34
35 void DDS_DicItem::operator=( const DDS_DicItem& )
36 {
37 }
38
39 TCollection_AsciiString DDS_DicItem::GetId() const
40 {
41   return myId;
42 }
43
44 DDS_DicItem::Type DDS_DicItem::GetType() const
45 {
46   return (DDS_DicItem::Type)myType;
47 }
48
49 TCollection_ExtendedString DDS_DicItem::GetLabel() const
50 {
51   return myLabel;
52 }
53
54 TCollection_ExtendedString DDS_DicItem::GetFilter() const
55 {
56   return myFilter;
57 }
58
59 TCollection_ExtendedString DDS_DicItem::GetRequired() const
60 {
61   return myRequired;
62 }
63
64 DDS_MsgType DDS_DicItem::GetWarningLevel() const
65 {
66   return (DDS_MsgType)myWarnLevel;
67 }
68
69 TCollection_ExtendedString DDS_DicItem::GetLongDescription() const
70 {
71   return myLongDescr;
72 }
73
74 TCollection_ExtendedString DDS_DicItem::GetShortDescription() const
75 {
76   return myShortDescr;
77 }
78
79 TCollection_AsciiString DDS_DicItem::GetComponent() const
80 {
81   TCollection_AsciiString aCompName;
82   Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
83   if ( !aComponent.IsNull() )
84     aCompName = aComponent->GetName();
85   return aCompName;
86 }
87
88 TCollection_AsciiString DDS_DicItem::GetUnits() const
89 {
90   return GetUnits( GetActiveUnitSystem() );
91 }
92
93 TCollection_AsciiString DDS_DicItem::GetUnits( const UnitSystem& theSystem ) const
94 {
95   TCollection_AsciiString anUnits;
96   UnitData* unitData = GetUnitData( theSystem );
97   if ( unitData )
98     anUnits = unitData->myUnits;
99   return anUnits;
100 }
101
102 Standard_Real DDS_DicItem::GetMinValue() const
103 {
104   return GetMinValue( GetActiveUnitSystem() );
105 }
106
107 Standard_Real DDS_DicItem::GetMinValue( const UnitSystem& theUnitsSystem ) const
108 {
109   return FromSI( myMin, theUnitsSystem );
110 }
111
112 Standard_Real DDS_DicItem::GetMaxValue() const
113 {
114   return GetMaxValue( GetActiveUnitSystem() );
115 }
116
117 Standard_Real DDS_DicItem::GetMaxValue( const UnitSystem& theUnitsSystem ) const
118 {
119   return FromSI( myMax, theUnitsSystem );
120 }
121
122 Standard_Integer DDS_DicItem::GetPrecision() const
123 {
124   return GetPrecision( GetActiveUnitSystem() );
125 }
126
127 Standard_Integer DDS_DicItem::GetPrecision( const UnitSystem& theSystem ) const
128 {
129   Standard_Integer aRes = 0;
130   UnitData* unitData = GetUnitData( theSystem );
131   if ( unitData )
132     aRes = unitData->myPrecision;
133   return aRes;
134 }
135
136 TCollection_ExtendedString DDS_DicItem::GetDefaultValue() const
137 {
138   return GetDefaultValue( GetActiveUnitSystem() );
139 }
140
141 TCollection_ExtendedString DDS_DicItem::GetDefaultValue( const UnitSystem& theSystem ) const
142 {
143   if ( !myDefString.Length() )
144     return myDefString;
145
146   TCollection_ExtendedString aStr;
147
148   switch ( myType )
149   {
150   case Float:
151   case Integer:
152     aStr = FromSI( myDefValue, theSystem );
153     break;
154   case List:
155   case String:
156     aStr = myDefString;
157     break;
158   default:
159     break;
160   }
161   return aStr;
162 }
163
164 TCollection_AsciiString DDS_DicItem::GetFormat( const Standard_Boolean theCanonical ) const
165 {
166   return GetFormat( GetActiveUnitSystem(), theCanonical );
167 }
168
169 TCollection_AsciiString DDS_DicItem::GetFormat( const UnitSystem& theSystem,
170                                                 const Standard_Boolean theCanonical ) const
171 {
172   TCollection_AsciiString aFormat;
173   UnitData* unitData = GetUnitData( theSystem );
174   if ( unitData )
175     aFormat = unitData->myFormat;
176
177   if ( theCanonical && aFormat.Length() > 1 )
178   {
179     static TCollection_AsciiString f;
180     f = aFormat;
181     Standard_Boolean isRemoved = false;
182     while ( !isRemoved )
183     {
184       char ch = f.Value( f.Length() - 1 );
185       if ( ( ch != '%' && ch != '.' && !IsDigit( ch ) ) && f.Length() > 1 )
186         f.Remove( f.Length() - 1 );
187       else
188         isRemoved = true;
189     }
190     aFormat = f;
191   }
192
193   return aFormat;
194 }
195
196 /*!
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
199 */
200 TCollection_ExtendedString DDS_DicItem::GetNameOfValues() const
201 {
202   return myListName;
203 }
204
205 /*!
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
208 */
209 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
210                                                Handle(TColStd_HArray1OfInteger)& theIntegers ) const
211 {
212   theStrings  = myListRef;
213   theIntegers = myListRefID;
214   return !theIntegers.IsNull() && !theStrings.IsNull();
215 }
216
217 /*!
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
220 */
221 Standard_Boolean DDS_DicItem::GetListOfValues( Handle(TColStd_HArray1OfExtendedString)& theStrings,
222                                                Handle(TColStd_HArray1OfInteger)& theIntegers,
223                                                Handle(TColStd_HArray1OfExtendedString)& theIcons ) const
224 {
225   theStrings  = myListRef;
226   theIntegers = myListRefID;
227   theIcons    = myListRefIcons;
228   return !theIntegers.IsNull() && !theStrings.IsNull() && !theIcons.IsNull();
229 }
230
231 Standard_Boolean DDS_DicItem::GetSpecialValues( TColStd_MapOfReal& theMap ) const
232 {
233   theMap.Clear();
234   if ( !myListRef.IsNull() )
235   {
236     for ( Standard_Integer i = myListRef->Lower(); i <= myListRef->Upper(); i++ )
237     {
238       if ( myListRef->Value( i ).IsAscii() )
239       {
240         TCollection_AsciiString aStr( myListRef->Value( i ) );
241         if ( aStr.IsRealValue() )
242           theMap.Add( aStr.RealValue() );
243       }
244     }
245   }
246
247   return theMap.Extent() > 0;
248 }
249
250 /*!
251   Returns min value of lateral zooming
252 */
253 Standard_Real DDS_DicItem::GetMinZoom() const
254 {
255   return myMinZoom;
256 }
257
258 /*!
259   Returns Max Value of lateral zooming
260 */
261 Standard_Real DDS_DicItem::GetMaxZoom() const
262 {
263   return myMaxZoom;
264 }
265
266 /*!
267   Get Order of lateral zooming
268 */
269 Standard_Real DDS_DicItem::GetZoomOrder() const
270 {
271   return myZoomOrder;
272 }
273
274 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal ) const
275 {
276   return ToSI( theVal, GetActiveUnitSystem() );
277 }
278
279 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal ) const
280 {
281   return FromSI( theVal, GetActiveUnitSystem() );
282 }
283
284 /*!
285   Convert value to default SI units according to current units
286 */
287 Standard_Real DDS_DicItem::ToSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
288 {
289   Standard_Real aRes = theVal;
290   UnitData* anUnitData = GetUnitData( theUnitsSystem );
291   if ( anUnitData )
292     aRes = anUnitData->myZero + aRes * anUnitData->myScale;
293   return aRes;
294 }
295
296 /*!
297   Convert value from default SI units according to current units
298 */
299 Standard_Real DDS_DicItem::FromSI( const Standard_Real theVal, const UnitSystem& theUnitsSystem ) const
300 {
301   Standard_Real aRes = theVal;
302   UnitData* anUnitData = GetUnitData( theUnitsSystem );
303   if ( anUnitData )
304     aRes = ( aRes - anUnitData->myZero ) / anUnitData->myScale;
305   return aRes;
306 }
307
308 /*!
309   Returns 'true' if specified data exist.
310 */
311 Standard_Boolean DDS_DicItem::HasData( const Standard_Integer flag ) const
312 {
313   return ( myData & flag ) == flag;
314 }
315
316 /*!
317   Parse record in XML file and retrieve information relevant for this data dic item
318 */
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 )
322 {
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" ) );
327
328   TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
329
330   for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
331   {
332     UnitSystem anUnitSystem = theSystems.Value( j );
333     if ( !anUnitSystem.Length() )
334       continue;
335
336     TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
337
338     if ( !myUnitData.IsBound( anUnitSystem ) )
339       myUnitData.Bind( anUnitSystem, UnitData() );
340
341     UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
342     anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
343   }
344
345   if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
346        !myUnitData.Find( theSystems.First() ).myUnits.Length() )
347   {
348     TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
349     if ( units.Length() )
350       myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
351   }
352
353   TCollection_AsciiString units;
354   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
355     units = iter.Value().myUnits;
356
357   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
358   {
359     UnitData& dataUnits = itr.ChangeValue();
360     if ( dataUnits.myUnits.IsEmpty() )
361       dataUnits.myUnits = units;
362   }
363   
364   // 2. Elements ( domain, description )
365   Standard_Real aRealMinV = 0;
366   Standard_Real aRealMaxV = 0;
367   Standard_Real aRealDefV = 0;
368
369   TCollection_AsciiString aType;
370
371   DDS_MsgType aWrongValue = DDS_MT_NONE;
372   DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
373
374   TCollection_AsciiString aMinV;
375   TCollection_AsciiString aMaxV;
376   TCollection_AsciiString aDefV;
377   TCollection_AsciiString aListName;
378
379   TCollection_AsciiString aLongD;
380   TCollection_AsciiString aShortD;
381
382   TColStd_SequenceOfInteger aSeqOfValueID;
383   TColStd_SequenceOfExtendedString aSeqOfValue;
384   TColStd_SequenceOfExtendedString aSeqOfValueIconName;
385
386   // Presentation
387   Standard_Real aMinZoom   = 0;
388   Standard_Real aMaxZoom   = 0;
389   Standard_Real aZoomOrder = 0;
390
391   // Datum::Reports tags (if any)
392   LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
393   if ( !aWLev.isNull() )
394   {
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;
404   }
405
406   // Datum::Presentation
407   LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
408   if ( !aPrs.isNull() )
409   {
410     LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
411     if ( !aLateralZoom.isNull() )
412     {
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" ) );
416       
417       aMinZoomStr.RemoveAll( ' ' );
418       if ( aMinZoomStr.IsRealValue() )
419         aMinZoom = aMinZoomStr.RealValue();
420
421       aMaxZoomStr.RemoveAll( ' ' );
422       if ( aMaxZoomStr.IsRealValue() )
423         aMaxZoom = aMaxZoomStr.RealValue();
424
425       aZoomOrderStr.RemoveAll( ' ' );
426       if ( aZoomOrderStr.IsRealValue() )
427         aZoomOrder = aZoomOrderStr.RealValue();
428     }
429   }
430
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() )
434   {
435     LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
436     if ( !aValueDescr.isNull() )
437     {
438       // read: valueDescr? (type?,min?,max?,default?)
439       aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
440       if ( aType.IsEqual( "String" ) )
441         aEnumType = String;
442       else if ( aType.IsEqual( "Float" ) )
443         aEnumType = Float;
444       else if ( aType.IsEqual( "Integer" ) )
445         aEnumType = Integer;
446
447       if ( !aValueDescr.getAttributeNode( DDS_Dictionary::KeyWord( "VD_MINV" ) ).isNull() )
448         myData |= MinValue;
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() )
454         myData |= MaxValue;
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;
462
463       aDefV.RemoveAll( ' ' );
464       if ( aDefV.IsRealValue() )
465         aRealDefV = aDefV.RealValue();
466
467       TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
468       Split( aSpecVal, myListRef );
469     }
470     else
471     {
472       //  read: listRef? (list?)
473       LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
474       if ( !aListRef.isNull() )
475       {
476         aType = "List";
477         aEnumType = List;                       
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() )
484         {
485           if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
486             foundListItem = aListItem;
487
488         }
489         for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
490               aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
491         {
492           if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
493             foundListItem = aLstItem;
494         }
495
496         if ( foundListItem != NULL )
497         {
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 )
503           {
504             // read value ID
505             TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
506             if ( aListValueID.IsIntegerValue() )
507             {
508               //  Read the text in the element "value"
509               LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
510               if ( !aListItemTxt.isNull() )
511               {
512                 // adding ID and text value to sequence
513                 aSeqOfValueID.Append( aListValueID.IntegerValue() );
514                 aSeqOfValue.Append( aListItemTxt.getData() );
515                 // adding icon file name (optional) to sequence
516                 TCollection_ExtendedString aListValueIcon = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEICON" ) );
517                 aSeqOfValueIconName.Append( aListValueIcon );
518               }
519               aListItemValue = aListItemValue.GetSiblingByTagName();
520             }
521           }
522         }
523       }
524     }
525   }
526
527   // Quantity::Description record as the only child of that tag name
528   LDOM_Element aDescr = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "DESCR" ) );
529   if ( !aDescr.isNull() )
530   {
531     // short description (#PCDATA)*
532     LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
533     if ( !aShDescr.isNull() )
534     {
535       // text is always a sub-node of element, containing it
536       LDOM_Text aShDescrTxt = (const LDOM_Text&)aShDescr.getFirstChild();
537       if ( !aShDescrTxt.isNull() )
538         aShortD = aShDescrTxt.getData();
539     }
540
541     // long description (#PCDATA)*
542     LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
543     if ( !aLDescr.isNull() )
544     {
545       // text is always a sub-node of element, containing it
546       LDOM_Text aLDescrTxt = (const LDOM_Text&)aLDescr.getFirstChild();
547       if ( !aLDescrTxt.isNull() )
548         aLongD = aLDescrTxt.getData();
549     }
550   }
551
552   NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
553
554   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
555   {
556     UnitData& anUnitData = it.ChangeValue();
557
558     // check units
559     anUnitData.myZero  = 0.;
560     anUnitData.myScale = 1.;
561     try {
562       Standard_CString aUnitDataStr;
563       aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
564       if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
565       {
566         Handle(Units_Dimensions) aDim;
567         anUnitData.myZero  = UnitsAPI::AnyToSI( 0.0, aUnitDataStr, aDim );
568         anUnitData.myScale = UnitsAPI::AnyToSI( 1.0, aUnitDataStr, aDim ) - anUnitData.myZero;
569         UnitsAPI::AnyFromSI( 1.0, aUnitDataStr );
570         if ( !aDimMap.IsBound( it.Key() ) )
571           aDimMap.Bind( it.Key(), aDim );
572       }
573       else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
574         anUnitData.myScale = 0.01;
575     }
576           catch( Standard_Failure ) {
577       anUnitData.myUnits.Clear();
578     }
579
580     Handle(Units_Dimensions) aPrev;
581     Standard_Boolean aStatus = Standard_True;
582     for ( NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)>::Iterator itr( aDimMap );
583           itr.More() && aStatus; itr.Next() )
584     {
585       if ( itr.Value().IsNull() )
586         continue;
587
588       if ( aPrev.IsNull() )
589         aPrev = itr.Value();
590
591       aStatus = aPrev->IsEqual( itr.Value() );
592     }
593
594     if ( !aStatus )
595       printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
596   }
597
598   myId                = theID;
599   myType              = aEnumType;
600   myWarnLevel         = aWrongValue;
601   myLabel             = aLabel.ToCString();
602   myFilter            = aFilter.ToCString();
603   myLongDescr         = aLongD.ToCString();
604   myShortDescr        = aShortD.ToCString();
605   myMin               = aRealMinV;
606   myMax               = aRealMaxV;
607   myDefValue          = aRealDefV;
608   myDefString         = aDefV.ToCString();
609   myRequired          = aRequired.ToCString();
610   myListName          = aListName.ToCString();
611   myMinZoom           = aMinZoom;
612   myMaxZoom           = aMaxZoom;
613   myZoomOrder         = aZoomOrder;
614
615   // prepare formats
616   PrepareFormats( aFormat );
617
618   const Standard_Integer aLength = aSeqOfValue.Length();
619   if ( aLength > 0 )
620   {
621     myListRef      = new TColStd_HArray1OfExtendedString( 1, aLength );
622     myListRefID    = new TColStd_HArray1OfInteger( 1, aLength );
623     myListRefIcons = new TColStd_HArray1OfExtendedString( 1, aLength );
624     for ( Standard_Integer i = aLength; i > 0; i-- )
625     {
626       myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
627       myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
628       myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
629     }
630   }
631
632   if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
633     myDefString = myListRef->Value( myListRef->Lower() );
634 }
635
636 /*!
637   Returns default formats for each unit systems
638 */
639 void DDS_DicItem::GetDefaultFormat()
640 {
641   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
642   {
643     UnitData& anUnitData = it.ChangeValue();
644
645     switch ( myType )
646     {
647     case Integer:
648       anUnitData.myFormat = "%d";
649       break;
650     case Float:
651       anUnitData.myFormat = "%g";
652       break;
653     case String:
654     default:
655       anUnitData.myFormat.Clear();
656       break;;
657     }
658   }
659 }
660
661 /*!
662   Returns format for the string
663 */
664 void DDS_DicItem::GetStringFormat( const TCollection_AsciiString& theFlags,
665                                    const TCollection_AsciiString& theWidth,
666                                    const TCollection_AsciiString& thePrecision,
667                                    const TCollection_AsciiString& theTypePrefix,
668                                    TCollection_AsciiString& theFormat )
669 {
670   theFormat = "%";
671   theFormat += theFlags;
672   theFormat += theWidth;
673
674   if ( !thePrecision.IsEmpty() ) 
675   {
676     theFormat += ".";
677     theFormat += thePrecision;
678   }
679
680   theFormat += theTypePrefix;
681   theFormat += "s";
682 }
683
684 /*!
685   Returns format for the integer
686 */
687 void DDS_DicItem::GetIntegerFormat( const TCollection_AsciiString& theFlags,
688                                     const TCollection_AsciiString& theWidth,
689                                     const TCollection_AsciiString& thePrecision,
690                                     const TCollection_AsciiString& theTypePrefix,
691                                     const Standard_Character theType,
692                                     TCollection_AsciiString& theFormat )
693 {
694   Standard_Integer aPrecision = 0;
695   if ( !thePrecision.IsEmpty() )
696     aPrecision = thePrecision.IntegerValue();
697   Standard_Integer aWidth = 0;
698
699   if ( !theWidth.IsEmpty() )
700     aWidth = theWidth.IntegerValue();
701
702   if ( !thePrecision.IsEmpty() && aPrecision < 0 )
703   {
704     // possible value 0.1 will be 10.0
705     aWidth -= aPrecision;
706     aPrecision = 0;
707   }
708
709   if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
710     aWidth = aPrecision + 2;
711
712   theFormat = "%";
713
714   theFormat += theFlags;
715   if ( !theWidth.IsEmpty() )
716     theFormat += aWidth;
717
718   theFormat += theTypePrefix;
719   theFormat += theType;
720 }
721
722 /*!
723   Returns format for the float
724 */
725 void DDS_DicItem::GetFloatFormat( const TCollection_AsciiString& theFlags,
726                                   const TCollection_AsciiString& theWidth,
727                                   const TCollection_AsciiString& thePrecision,
728                                   const TCollection_AsciiString& theTypePrefix,
729                                   const Standard_Character theType,
730                                   TCollection_AsciiString& theFormat )
731 {
732   Standard_Integer aPrecision = 0;
733   if ( !thePrecision.IsEmpty() )
734     aPrecision = thePrecision.IntegerValue();
735   Standard_Integer aWidth = 0;
736
737   if (!theWidth.IsEmpty() )
738     aWidth = theWidth.IntegerValue();
739
740   if (!thePrecision.IsEmpty() && aPrecision < 0 )
741   {
742     // possible value 0.1 will be 10.0
743     aWidth -= aPrecision;
744     aPrecision = 0;
745   }
746
747   if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
748   {
749     aWidth = aPrecision + 2;
750   }
751
752   theFormat = "%";
753   theFormat += theFlags;
754
755   if ( !theWidth.IsEmpty() ) 
756     theFormat += aWidth;
757
758   if ( !thePrecision.IsEmpty() ) 
759   {
760     theFormat += ".";
761     theFormat += aPrecision;
762   }
763
764   theFormat += theTypePrefix;
765   theFormat += theType;
766 }
767
768 /*!
769   Prepares three formants for each unit systems
770 */
771 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString&  theFormat )
772 {
773   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
774   {
775     UnitData& anUnitData = it.ChangeValue();
776
777     anUnitData.myFormat = theFormat;
778     anUnitData.myPrecision = 0;
779   }
780
781   TCollection_AsciiString aPrecisionStr;
782   if ( theFormat.IsEmpty() && myType == List )
783     return;
784
785   // checking % presenting
786   if ( *theFormat.ToCString() != '%' )
787   {
788     GetDefaultFormat();
789     return;
790   }
791
792   TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
793   Standard_Character aType = aStr.Value( aStr.Length() );
794
795   if ( ( aType != 's' && myType == String ) ||
796        ( aType != 'd' && myType == Integer ) ||
797        ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
798   {
799     GetDefaultFormat();
800     return;
801   }
802
803   // removing type character
804   aStr.Trunc( aStr.Length() - 1 );
805
806   TCollection_AsciiString aFlags;
807   while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
808   {
809     aFlags = aFlags + aStr.Value( 1 );
810     aStr.Remove( 1 );
811   }
812
813   Standard_Integer aPos = 1;
814   while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
815           ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
816     aPos++;
817
818   TCollection_AsciiString aTypePrefix;
819   if ( aPos <= aStr.Length() )
820   {
821     aTypePrefix = aStr.SubString( aPos, aStr.Length() );
822     aStr.Trunc( aPos - 1 );
823   }
824
825   Standard_Integer aBasePrecision = 0;
826
827   // taking width and precision
828   TCollection_AsciiString aPrecision;
829
830   aPos = aStr.Search( "." );
831   if ( aPos >= 0 ) 
832   {
833     // aPrecision is defined
834     aPrecision = aStr.Split( aPos );
835     aStr.Remove( aStr.Length() );
836     if ( !aPrecision.IsEmpty() )
837     {
838       if ( !aPrecision.IsIntegerValue() ) 
839       { 
840         GetDefaultFormat();
841         return;
842       }
843       else
844       {
845         aPrecisionStr  = aPrecision;
846         aBasePrecision = aPrecision.IntegerValue();
847       }
848     }
849   }
850
851   if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
852   {
853     GetDefaultFormat();
854     return;
855   }
856
857   NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
858
859   switch ( myType )
860   {
861   case String:
862     for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
863     {
864       if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
865         GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
866     }
867     break;
868   case Float:
869   case Integer:
870     for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
871     {
872       UnitData& anUnitData = itr.ChangeValue();
873       Standard_Integer aAmendment =
874         (Standard_Integer)log10( 10.0 / DDS_Dictionary::FromSI( 10.0, anUnitData.myUnits.ToCString() ) );
875       anUnitData.myPrecision = aBasePrecision + aAmendment;
876       aPrecisionStr = TCollection_AsciiString( anUnitData.myPrecision );
877
878       // create a formats
879       if ( myType == Integer )
880         GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
881       else
882         GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
883     }
884     break;
885   default:;
886     GetDefaultFormat();
887     break;
888   }
889 }
890
891 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
892 {
893   aRes.Nullify();
894
895   if ( theStr.Length() > 0 )
896   {
897     TCollection_AsciiString aStr = theStr;
898     TColStd_SequenceOfAsciiString aSeq;
899     Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
900     while( anIndex > 1 )
901     {
902       TCollection_AsciiString tmpStr = aStr.Split( anIndex - 1 );
903       tmpStr.RemoveAll( ( Standard_Character )' ' );
904       if ( tmpStr.Length() > 0 )
905         aSeq.Append( tmpStr );
906       anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
907     }
908
909     aStr.RemoveAll( ( Standard_Character )' ' );
910     if ( aStr.Length() > 0 )
911       aSeq.Append( aStr );
912
913     if ( aSeq.Length() > 0 )
914     {
915       aRes = new TColStd_HArray1OfExtendedString( 1, aSeq.Length() );
916       for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
917         aRes->ChangeValue( i ) = aSeq( i );
918     }
919   }
920 }
921
922 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
923 {
924   UnitData* unit = 0;
925
926   if ( myUnitData.IsBound( sys ) )
927     unit = (UnitData*)&myUnitData.Find( sys );
928
929   return unit;
930 }
931
932 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
933 {
934   UnitSystem aSystem;
935   Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
936   if ( !aComponent.IsNull() )
937     aSystem = aComponent->GetActiveUnitSystem();
938   return aSystem;
939 }