]> SALOME platform Git repositories - modules/gui.git/blob - src/DDS/DDS_DicItem.cxx
Salome HOME
fd59f3cd683a039dbc8493f9bff9508d5a2d0b3b
[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   Parse record in XML file and retrieve information relevant for this data dic item
310 */
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 )
314 {
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" ) );
319
320   TCollection_AsciiString aBaseKeyWord = DDS_Dictionary::KeyWord( "DATUM_UNITS" );
321
322   for ( Standard_Integer j = 1; j <= theSystems.Length(); j++ )
323   {
324     UnitSystem anUnitSystem = theSystems.Value( j );
325     if ( !anUnitSystem.Length() )
326       continue;
327
328     TCollection_AsciiString aUnitKeyword = anUnitSystem + aBaseKeyWord;
329
330     if ( !myUnitData.IsBound( anUnitSystem ) )
331       myUnitData.Bind( anUnitSystem, UnitData() );
332
333     UnitData& anUnitData = myUnitData.ChangeFind( anUnitSystem );
334     anUnitData.myUnits = theDatum.getAttribute( LDOMString( aUnitKeyword.ToCString() ) );
335   }
336
337   if ( theSystems.Length() && myUnitData.IsBound( theSystems.First() ) &&
338        !myUnitData.Find( theSystems.First() ).myUnits.Length() )
339   {
340     TCollection_AsciiString units = theDatum.getAttribute( LDOMString( aBaseKeyWord.ToCString() ) );
341     if ( units.Length() )
342       myUnitData.ChangeFind( theSystems.First() ).myUnits = units;
343   }
344
345   TCollection_AsciiString units;
346   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator iter( myUnitData ); iter.More() && units.IsEmpty(); iter.Next() )
347     units = iter.Value().myUnits;
348
349   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator itr( myUnitData ); itr.More(); itr.Next() )
350   {
351     UnitData& dataUnits = itr.ChangeValue();
352     if ( dataUnits.myUnits.IsEmpty() )
353       dataUnits.myUnits = units;
354   }
355   
356   // 2. Elements ( domain, description )
357   Standard_Real aRealMinV = 0;
358   Standard_Real aRealMaxV = 0;
359   Standard_Real aRealDefV = 0;
360
361   TCollection_AsciiString aType;
362
363   DDS_MsgType aWrongValue = DDS_MT_NONE;
364   DDS_DicItem::Type aEnumType = DDS_DicItem::Unknown;
365
366   TCollection_AsciiString aMinV;
367   TCollection_AsciiString aMaxV;
368   TCollection_AsciiString aDefV;
369   TCollection_AsciiString aListName;
370
371   TCollection_AsciiString aLongD;
372   TCollection_AsciiString aShortD;
373
374   TColStd_SequenceOfInteger aSeqOfValueID;
375   TColStd_SequenceOfExtendedString aSeqOfValue;
376   TColStd_SequenceOfExtendedString aSeqOfValueIconName;
377
378   // Presentation
379   Standard_Real aMinZoom   = 0;
380   Standard_Real aMaxZoom   = 0;
381   Standard_Real aZoomOrder = 0;
382
383   // Datum::Reports tags (if any)
384   LDOM_Element aWLev = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "WARNING_LEVEL" ) );
385   if ( !aWLev.isNull() )
386   {
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;
396   }
397
398   // Datum::Presentation
399   LDOM_Element aPrs = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "PRS" ) );
400   if ( !aPrs.isNull() )
401   {
402     LDOM_Element aLateralZoom = aPrs.GetChildByTagName( DDS_Dictionary::KeyWord( "LATERAL_ZOOM" ) );
403     if ( !aLateralZoom.isNull() )
404     {
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" ) );
408       
409       aMinZoomStr.RemoveAll( ' ' );
410       if ( aMinZoomStr.IsRealValue() )
411         aMinZoom = aMinZoomStr.RealValue();
412
413       aMaxZoomStr.RemoveAll( ' ' );
414       if ( aMaxZoomStr.IsRealValue() )
415         aMaxZoom = aMaxZoomStr.RealValue();
416
417       aZoomOrderStr.RemoveAll( ' ' );
418       if ( aZoomOrderStr.IsRealValue() )
419         aZoomOrder = aZoomOrderStr.RealValue();
420     }
421   }
422
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() )
426   {
427     LDOM_Element aValueDescr = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_DESCR" ) );
428     if ( !aValueDescr.isNull() )
429     {
430       // read: valueDescr? (type?,min?,max?,default?)
431       aType = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_TYPE" ) );
432       if ( aType.IsEqual( "String" ) )
433         aEnumType = String;
434       else if ( aType.IsEqual( "Float" ) )
435         aEnumType = Float;
436       else if ( aType.IsEqual( "Integer" ) )
437         aEnumType = Integer;
438
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();
451
452       TCollection_AsciiString aSpecVal = aValueDescr.getAttribute( DDS_Dictionary::KeyWord( "VD_SPEC" ) );
453       Split( aSpecVal, myListRef );
454     }
455     else
456     {
457       //  read: listRef? (list?)
458       LDOM_Element aListRef = aDomain.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST_REF" ) );
459       if ( !aListRef.isNull() )
460       {
461         aType = "List";
462         aEnumType = List;                       
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() )
469         {
470           if ( aListItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
471             foundListItem = aListItem;
472
473         }
474         for ( LDOM_Element aLstItem = theDocElement.GetChildByTagName( DDS_Dictionary::KeyWord( "VALUE_LIST" ) );
475               aLstItem != NULL && foundListItem == NULL; aLstItem = aLstItem.GetSiblingByTagName() )
476         {
477           if ( aLstItem.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_ID" ) ).equals( aListId ) )
478             foundListItem = aLstItem;
479         }
480
481         if ( foundListItem != NULL )
482         {
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 )
488           {
489             // read value ID
490             TCollection_AsciiString aListValueID = aListItemValue.getAttribute( DDS_Dictionary::KeyWord( "VALUE_LIST_VALUEID" ) );
491             if ( aListValueID.IsIntegerValue() )
492             {
493               //  Read the text in the element "value"
494               LDOM_Text aListItemTxt = (const LDOM_Text&)aListItemValue.getFirstChild();
495               if ( !aListItemTxt.isNull() )
496               {
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 );
503               }
504               aListItemValue = aListItemValue.GetSiblingByTagName();
505             }
506           }
507         }
508       }
509     }
510   }
511
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() )
515   {
516     // short description (#PCDATA)*
517     LDOM_Element aShDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "SHORT_D" ) );
518     if ( !aShDescr.isNull() )
519     {
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();
524     }
525
526     // long description (#PCDATA)*
527     LDOM_Element aLDescr = aDescr.GetChildByTagName( DDS_Dictionary::KeyWord( "LONG_D" ) );
528     if ( !aLDescr.isNull() )
529     {
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();
534     }
535   }
536
537   NCollection_DataMap<UnitSystem, Handle(Units_Dimensions)> aDimMap;
538
539   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
540   {
541     UnitData& anUnitData = it.ChangeValue();
542
543     // check units
544     anUnitData.myZero  = 0.;
545     anUnitData.myScale = 1.;
546     try {
547       Standard_CString aUnitDataStr;
548       aUnitDataStr = (Standard_CString)anUnitData.myUnits.ToCString();
549       if ( anUnitData.myUnits.ToCString()[0] && strcmp( anUnitData.myUnits.ToCString(), "%" ) )
550       {
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 );
557       }
558       else if ( anUnitData.myUnits.ToCString()[0] ) // treat '%' as unit with scale 100
559         anUnitData.myScale = 0.01;
560     }
561           catch( Standard_Failure ) {
562       anUnitData.myUnits.Clear();
563     }
564
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() )
569     {
570       if ( itr.Value().IsNull() )
571         continue;
572
573       if ( aPrev.IsNull() )
574         aPrev = itr.Value();
575
576       aStatus = aPrev->IsEqual( itr.Value() );
577     }
578
579     if ( !aStatus )
580       printf( "Error in DataDictionary: Different dimensions for %s item", theID.ToCString() );
581   }
582
583   myId                = theID;
584   myType              = aEnumType;
585   myWarnLevel         = aWrongValue;
586   myLabel             = aLabel.ToCString();
587   myFilter            = aFilter.ToCString();
588   myLongDescr         = aLongD.ToCString();
589   myShortDescr        = aShortD.ToCString();
590   myMin               = aRealMinV;
591   myMax               = aRealMaxV;
592   myDefValue          = aRealDefV;
593   myDefString         = aDefV.ToCString();
594   myRequired          = aRequired.ToCString();
595   myListName          = aListName.ToCString();
596   myMinZoom           = aMinZoom;
597   myMaxZoom           = aMaxZoom;
598   myZoomOrder         = aZoomOrder;
599
600   // prepare formats
601   PrepareFormats( aFormat );
602
603   const Standard_Integer aLength = aSeqOfValue.Length();
604   if ( aLength > 0 )
605   {
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-- )
610     {
611       myListRef->ChangeValue( i ) = aSeqOfValue.Value( i );
612       myListRefID->ChangeValue( i ) = aSeqOfValueID.Value( i );
613       myListRefIcons->ChangeValue( i ) = aSeqOfValueIconName.Value( i );
614     }
615   }
616
617   if ( myType == List && myDefString == "" && !myListRef.IsNull() && myListRef->Length() > 0 )
618     myDefString = myListRef->Value( myListRef->Lower() );
619 }
620
621 /*!
622   Returns default formats for each unit systems
623 */
624 void DDS_DicItem::GetDefaultFormat()
625 {
626   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
627   {
628     UnitData& anUnitData = it.ChangeValue();
629
630     switch ( myType )
631     {
632     case Integer:
633       anUnitData.myFormat = "%d";
634       break;
635     case Float:
636       anUnitData.myFormat = "%g";
637       break;
638     case String:
639     default:
640       anUnitData.myFormat.Clear();
641       break;;
642     }
643   }
644 }
645
646 /*!
647   Returns format for the string
648 */
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 )
654 {
655   theFormat = "%";
656   theFormat += theFlags;
657   theFormat += theWidth;
658
659   if ( !thePrecision.IsEmpty() ) 
660   {
661     theFormat += ".";
662     theFormat += thePrecision;
663   }
664
665   theFormat += theTypePrefix;
666   theFormat += "s";
667 }
668
669 /*!
670   Returns format for the integer
671 */
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 )
678 {
679   Standard_Integer aPrecision = 0;
680   if ( !thePrecision.IsEmpty() )
681     aPrecision = thePrecision.IntegerValue();
682   Standard_Integer aWidth = 0;
683
684   if ( !theWidth.IsEmpty() )
685     aWidth = theWidth.IntegerValue();
686
687   if ( !thePrecision.IsEmpty() && aPrecision < 0 )
688   {
689     // possible value 0.1 will be 10.0
690     aWidth -= aPrecision;
691     aPrecision = 0;
692   }
693
694   if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
695     aWidth = aPrecision + 2;
696
697   theFormat = "%";
698
699   theFormat += theFlags;
700   if ( !theWidth.IsEmpty() )
701     theFormat += aWidth;
702
703   theFormat += theTypePrefix;
704   theFormat += theType;
705 }
706
707 /*!
708   Returns format for the float
709 */
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 )
716 {
717   Standard_Integer aPrecision = 0;
718   if ( !thePrecision.IsEmpty() )
719     aPrecision = thePrecision.IntegerValue();
720   Standard_Integer aWidth = 0;
721
722   if (!theWidth.IsEmpty() )
723     aWidth = theWidth.IntegerValue();
724
725   if (!thePrecision.IsEmpty() && aPrecision < 0 )
726   {
727     // possible value 0.1 will be 10.0
728     aWidth -= aPrecision;
729     aPrecision = 0;
730   }
731
732   if ( !thePrecision.IsEmpty() && aPrecision > ( aWidth - 2 ) )
733   {
734     aWidth = aPrecision + 2;
735   }
736
737   theFormat = "%";
738   theFormat += theFlags;
739
740   if ( !theWidth.IsEmpty() ) 
741     theFormat += aWidth;
742
743   if ( !thePrecision.IsEmpty() ) 
744   {
745     theFormat += ".";
746     theFormat += aPrecision;
747   }
748
749   theFormat += theTypePrefix;
750   theFormat += theType;
751 }
752
753 /*!
754   Prepares three formants for each unit systems
755 */
756 void DDS_DicItem::PrepareFormats( const TCollection_AsciiString&  theFormat )
757 {
758   for ( NCollection_DataMap<UnitSystem, UnitData>::Iterator it( myUnitData ); it.More(); it.Next() )
759   {
760     UnitData& anUnitData = it.ChangeValue();
761
762     anUnitData.myFormat = theFormat;
763     anUnitData.myPrecision = 0;
764   }
765
766   TCollection_AsciiString aPrecisionStr;
767   if ( theFormat.IsEmpty() && myType == List )
768     return;
769
770   // checking % presenting
771   if ( *theFormat.ToCString() != '%' )
772   {
773     GetDefaultFormat();
774     return;
775   }
776
777   TCollection_AsciiString aStr = ( theFormat.ToCString() + 1 );
778   Standard_Character aType = aStr.Value( aStr.Length() );
779
780   if ( ( aType != 's' && myType == String ) ||
781        ( aType != 'd' && myType == Integer ) ||
782        ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' && myType == Float ) )
783   {
784     GetDefaultFormat();
785     return;
786   }
787
788   // removing type character
789   aStr.Trunc( aStr.Length() - 1 );
790
791   TCollection_AsciiString aFlags;
792   while ( !aStr.IsEmpty() && aStr.Value( 1 ) != '.' && ( aStr.Value( 1 ) < '0' || aStr.Value( 1 ) > '9' ) )
793   {
794     aFlags = aFlags + aStr.Value( 1 );
795     aStr.Remove( 1 );
796   }
797
798   Standard_Integer aPos = 1;
799   while ( aPos <= aStr.Length() && ( aStr.Value( aPos ) == '.' ||
800           ( aStr.Value( aPos ) >= '0' && aStr.Value( aPos ) <= '9' ) ) )
801     aPos++;
802
803   TCollection_AsciiString aTypePrefix;
804   if ( aPos <= aStr.Length() )
805   {
806     aTypePrefix = aStr.SubString( aPos, aStr.Length() );
807     aStr.Trunc( aPos - 1 );
808   }
809
810   Standard_Integer aBasePrecision = 0;
811
812   // taking width and precision
813   TCollection_AsciiString aPrecision;
814
815   aPos = aStr.Search( "." );
816   if ( aPos >= 0 ) 
817   {
818     // aPrecision is defined
819     aPrecision = aStr.Split( aPos );
820     aStr.Remove( aStr.Length() );
821     if ( !aPrecision.IsEmpty() )
822     {
823       if ( !aPrecision.IsIntegerValue() ) 
824       { 
825         GetDefaultFormat();
826         return;
827       }
828       else
829       {
830         aPrecisionStr  = aPrecision;
831         aBasePrecision = aPrecision.IntegerValue();
832       }
833     }
834   }
835
836   if ( !aStr.IsEmpty() && !aStr.IsIntegerValue() )
837   {
838     GetDefaultFormat();
839     return;
840   }
841
842   NCollection_DataMap<UnitSystem, UnitData>::Iterator itr;
843
844   switch ( myType )
845   {
846   case String:
847     for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
848     {
849       if ( aType != 'f' && aType != 'g' && aType != 'e' && aType != 'G' && aType != 'E' )
850         GetStringFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, itr.ChangeValue().myFormat );
851     }
852     break;
853   case Float:
854   case Integer:
855     for ( itr.Initialize( myUnitData ); itr.More(); itr.Next() )
856     {
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 );
862
863       // create a formats
864       if ( myType == Integer )
865         GetIntegerFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
866       else
867         GetFloatFormat( aFlags, aStr, aPrecisionStr, aTypePrefix, aType, anUnitData.myFormat );
868     }
869     break;
870   default:;
871     GetDefaultFormat();
872     break;
873   }
874 }
875
876 void DDS_DicItem::Split( const TCollection_AsciiString& theStr, Handle(TColStd_HArray1OfExtendedString)& aRes )
877 {
878   aRes.Nullify();
879
880   if ( theStr.Length() > 0 )
881   {
882     TCollection_AsciiString aStr = theStr;
883     TColStd_SequenceOfAsciiString aSeq;
884     Standard_Integer anIndex = aStr.SearchFromEnd( (Standard_CString)" " );
885     while( anIndex > 1 )
886     {
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)" " );
892     }
893
894     aStr.RemoveAll( ( Standard_Character )' ' );
895     if ( aStr.Length() > 0 )
896       aSeq.Append( aStr );
897
898     if ( aSeq.Length() > 0 )
899     {
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 );
903     }
904   }
905 }
906
907 DDS_DicItem::UnitData* DDS_DicItem::GetUnitData( const UnitSystem& sys ) const
908 {
909   UnitData* unit = 0;
910
911   if ( myUnitData.IsBound( sys ) )
912     unit = (UnitData*)&myUnitData.Find( sys );
913
914   return unit;
915 }
916
917 DDS_DicItem::UnitSystem DDS_DicItem::GetActiveUnitSystem() const
918 {
919   UnitSystem aSystem;
920   Handle(DDS_DicGroup) aComponent = Handle(DDS_DicGroup)::DownCast(myComponent);
921   if ( !aComponent.IsNull() )
922     aSystem = aComponent->GetActiveUnitSystem();
923   return aSystem;
924 }