Salome HOME
Time optimization in frame of bos #18939 (Export XAO)
[modules/geom.git] / src / XAOPlugin / XAOPlugin_IOperations.cxx
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "XAOPlugin_IOperations.hxx"
22 #include "XAOPlugin_Driver.hxx"
23 #include "XAOPlugin_IImportExport.hxx"
24
25 // KERNEL includes
26 #include <Basics_DirUtils.hxx>
27 #include <utilities.h>
28 #include <Utils_SALOME_Exception.hxx>
29
30 // GEOM includes
31 #include <GEOM_PythonDump.hxx>
32 #include <GEOMImpl_Types.hxx>
33 #include <GEOMImpl_IGroupOperations.hxx>
34 #include <GEOMImpl_IShapesOperations.hxx>
35 #include <GEOMImpl_IFieldOperations.hxx>
36 #include <GEOM_ISubShape.hxx>
37 #include <GEOM_Object.hxx>
38 #include <GEOM_Field.hxx>
39
40 #include <XAO_Geometry.hxx>
41 #include <XAO_BrepGeometry.hxx>
42 #include <XAO_Xao.hxx>
43 #include <XAO_Group.hxx>
44 #include <XAO_Field.hxx>
45 #include <XAO_BooleanField.hxx>
46 #include <XAO_IntegerField.hxx>
47 #include <XAO_DoubleField.hxx>
48 #include <XAO_StringField.hxx>
49 #include <XAO_DoubleStep.hxx>
50 #include <XAO_StringStep.hxx>
51
52 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
53
54 // OCC includes
55 #include <TColStd_HArray1OfByte.hxx>
56 #include <TColStd_HArray1OfReal.hxx>
57 #include <TDataStd_Integer.hxx>
58
59 #include <TopExp.hxx>
60
61 XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
62 {
63   XAO::Dimension dim;
64   switch( shape ) {
65   case TopAbs_VERTEX:
66     dim = XAO::VERTEX; break;
67   case TopAbs_EDGE:
68     dim = XAO::EDGE; break;
69   case TopAbs_FACE:
70     dim = XAO::FACE; break;
71   case TopAbs_SOLID:
72     dim = XAO::SOLID; break;
73   default:
74     throw SALOME_Exception("Bad type"); // TODO
75   }
76   return dim;
77 }
78
79 TopAbs_ShapeEnum getGroupDimension(XAO::Group* group)
80 {
81   XAO::Dimension dim = group->getDimension();
82   TopAbs_ShapeEnum rdim;
83   switch ( dim )
84   {
85   case XAO::VERTEX:
86     rdim = TopAbs_VERTEX; break;
87   case XAO::EDGE:
88     rdim = TopAbs_EDGE; break;
89   case XAO::FACE:
90     rdim = TopAbs_FACE; break;
91   case XAO::SOLID:
92     rdim = TopAbs_SOLID; break;
93   default:
94     rdim = TopAbs_COMPOUND; break;
95   }
96   return rdim;
97 }
98
99 //=============================================================================
100 /*!
101  *  Constructor
102  */
103 //=============================================================================
104 XAOPlugin_IOperations::XAOPlugin_IOperations( GEOM_Engine* theEngine )
105 : GEOMImpl_IBaseIEOperations( theEngine )
106 {
107   MESSAGE( "XAOPlugin_IOperations::XAOPlugin_IOperations" );
108 }
109
110 //=============================================================================
111 /*!
112  *  Destructor
113  */
114 //=============================================================================
115 XAOPlugin_IOperations::~XAOPlugin_IOperations()
116 {
117   MESSAGE( "XAOPlugin_IOperations::~XAOPlugin_IOperations" );
118 }
119
120 bool XAOPlugin_IOperations::exportGroups( std::list<Handle(GEOM_Object)> groupList,
121                                           XAO::Xao* xaoObject,
122                                           XAO::BrepGeometry* geometry )
123 {
124   // add the groups
125   std::list<Handle(GEOM_Object)>::iterator groupIterator = groupList.begin();
126   while (groupIterator != groupList.end())
127   {
128     Handle(GEOM_Object) currGroup = (*groupIterator++);
129     if (currGroup->GetType() != GEOM_GROUP) {
130       SetErrorCode("Error when export groups: you could perform this operation only with group.");
131       return false;
132     }
133     Handle(TColStd_HArray1OfInteger) groupIds = myGroupOperations->GetObjects(currGroup);
134
135     TopAbs_ShapeEnum shapeGroup = myGroupOperations->GetType(currGroup);
136     XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
137     XAO::Group* group = xaoObject->addGroup(dim, currGroup->GetName().ToCString());
138
139     switch (shapeGroup)
140     {
141     case TopAbs_VERTEX:
142       for (int i = 1; i <= groupIds->Length(); i++)
143       {
144         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
145         int index = geometry->getVertexIndexByReference(ref);
146         group->add(index);
147       }
148       break;
149     case TopAbs_EDGE:
150       for (int i = 1; i <= groupIds->Length(); i++)
151       {
152         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
153         int index = geometry->getEdgeIndexByReference(ref);
154         group->add(index);
155       }
156       break;
157     case TopAbs_FACE:
158       for (int i = 1; i <= groupIds->Length(); i++)
159       {
160         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
161         int index = geometry->getFaceIndexByReference(ref);
162         group->add(index);
163       }
164       break;
165     case TopAbs_SOLID:
166       for (int i = 1; i <= groupIds->Length(); i++)
167       {
168         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
169         int index = geometry->getSolidIndexByReference(ref);
170         group->add(index);
171       }
172       break;
173     default:
174       ;
175     }
176   }
177   return true;
178 }
179
180 void XAOPlugin_IOperations::exportFields( std::list<Handle(GEOM_Field)> fieldList,
181                                           XAO::Xao* xaoObject,
182                                           XAO::BrepGeometry* geometry )
183 {
184   std::list<Handle(GEOM_Field)>::iterator fieldIterator = fieldList.begin();
185   while (fieldIterator != fieldList.end())
186   {
187     Handle(GEOM_Field) currField = (*fieldIterator++);
188
189     int fdim = currField->GetDimension();
190     int ftype = currField->GetDataType();
191     int nbComponents = currField->GetNbComponents();
192     std::string name = currField->GetName().ToCString();
193
194     XAO::Field* field = xaoObject->addField((XAO::Type)ftype, (XAO::Dimension)fdim, nbComponents, name);
195
196     Handle(TColStd_HArray1OfExtendedString) components = currField->GetComponents();
197     for (int i = components->Lower(), j = 0; i <= components->Upper(); ++i, ++j)
198     {
199       field->setComponentName(j, TCollection_AsciiString(components->Value(i)).ToCString());
200     }
201
202     std::list< Handle(GEOM_FieldStep)> steps = currField->GetSteps();
203     std::list<Handle(GEOM_FieldStep)>::iterator stepIterator = steps.begin();
204     while (stepIterator != steps.end())
205     {
206       Handle(GEOM_FieldStep) currStep = (*stepIterator++);
207
208       XAO::Step* step = field->addNewStep(currStep->GetID());
209       step->setStamp(currStep->GetStamp());
210
211       switch (ftype)
212       {
213         case 0: // bool
214         {
215           XAO::BooleanStep* bs = (XAO::BooleanStep*)step;
216           Handle(TColStd_HArray1OfInteger) bvalues = currStep->GetIntValues();
217           std::vector<bool> bv;
218           bv.reserve(bvalues->Upper());
219           for ( int i = bvalues->Lower(), nb = bvalues->Upper(); i <= nb; ++i )
220           {
221             bv.push_back(bvalues->Value(i) != 0);
222           }
223           bs->setValues(bv);
224           break;
225         }
226         case 1: // integer
227         {
228           XAO::IntegerStep* is = (XAO::IntegerStep*)step;
229           Handle(TColStd_HArray1OfInteger) ivalues = currStep->GetIntValues();
230           std::vector<int> iv;
231           iv.reserve(ivalues->Upper());
232           for ( int i = ivalues->Lower(), nb = ivalues->Upper(); i <= nb; ++i )
233           {
234             iv.push_back(ivalues->Value(i));
235           }
236           is->setValues(iv);
237           break;
238         }
239         case 2: // double
240         {
241           XAO::DoubleStep* ds = (XAO::DoubleStep*)step;
242           Handle(TColStd_HArray1OfReal) dvalues = currStep->GetDoubleValues();
243           std::vector<double> dv;
244           dv.reserve(dvalues->Upper());
245           for ( int i = dvalues->Lower(), nb = dvalues->Upper(); i <= nb; ++i )
246           {
247             dv.push_back(dvalues->Value(i));
248           }
249           ds->setValues(dv);
250             break;
251         }
252         case 3: // string
253         {
254           XAO::StringStep* ss = (XAO::StringStep*)step;
255           Handle(TColStd_HArray1OfExtendedString) svalues = currStep->GetStringValues();
256           std::vector<std::string> sv;
257           sv.reserve(svalues->Upper());
258           for ( int i = svalues->Lower(), nb = svalues->Upper(); i <= nb; ++i )
259           {
260             sv.push_back(TCollection_AsciiString(svalues->Value(i)).ToCString());
261           }
262           ss->setValues(sv);
263           break;
264         }
265       }
266     }
267   }
268 }
269
270 void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry )
271 {
272   Handle(TColStd_HSequenceOfTransient) subObjects = myShapesOperations->GetExistingSubObjects( shape, GEOMImpl_IShapesOperations::SubShapes );
273   int nbSubObjects = subObjects->Length();
274   if (!nbSubObjects) return;
275
276   TopoDS_Shape aMainShape = shape->GetValue();
277   if (aMainShape.IsNull()) return;
278   TopTools_IndexedMapOfShape anIndices;
279   TopExp::MapShapes(aMainShape, anIndices);
280
281   // set the names of the sub shapes
282   for (int i = 1; i <= nbSubObjects; i++)
283   {
284     Handle(Standard_Transient) transientSubObject = subObjects->Value(i);
285     if (transientSubObject.IsNull())
286       continue;
287
288     Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast( transientSubObject );
289     if (subObject->GetType() != GEOM_GROUP)
290     {
291       TopoDS_Shape aSubShape = subObject->GetValue();
292       if (aSubShape.IsNull()) continue;
293
294       // Do not call GEOMImpl_IShapesOperations::GetSubShapeIndex() here
295       // for time optimization reason (it invokes TopExp::MapShapes())
296       //int subIndex = myShapesOperations->GetSubShapeIndex( shape, subObject );
297       int subIndex = anIndices.FindIndex(aSubShape);
298       if (!subIndex) continue;
299
300       switch (aSubShape.ShapeType())
301       {
302       case TopAbs_VERTEX:
303         geometry->changeVertexName(subIndex, subObject->GetName().ToCString());
304         break;
305       case TopAbs_EDGE:
306         geometry->changeEdgeName(subIndex, subObject->GetName().ToCString());
307         break;
308       case TopAbs_FACE:
309         geometry->changeFaceName(subIndex, subObject->GetName().ToCString());
310         break;
311       case TopAbs_SOLID:
312         geometry->changeSolidName(subIndex, subObject->GetName().ToCString());
313         break;
314       default:
315         ;
316       }
317     }
318   }
319 }
320
321 //=============================================================================
322 /*!
323  *  Export a shape to XAO format
324  *  \param shape The shape to export
325  *  \param groups The list of groups to export
326  *  \param fields The list of fields to export
327  *  \param fileName The name of the file to exported
328  *  \return boolean indicating if export was succeful.
329  */
330 //=============================================================================
331 bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
332                                        std::list<Handle(GEOM_Object)> groupList,
333                                        std::list<Handle(GEOM_Field)> fieldList,
334                                        const char* author,
335                                        const char* fileName,
336                                        const char* shapeFileName )
337 {
338   SetErrorCode(KO);
339
340   if (shape.IsNull()) return false;
341
342   // add a new shape function with parameters
343   Handle(GEOM_Function) lastFunction = shape->GetLastFunction();
344   if (lastFunction.IsNull()) return false;
345
346   // add a new result object
347   Handle(GEOM_Object) result = GetEngine()->AddObject(GEOM_IMPORT);
348
349   // add an Export function
350   Handle(GEOM_Function) exportFunction = result->AddFunction(XAOPlugin_Driver::GetID(), EXPORT_SHAPE);
351   if (exportFunction.IsNull()) return false;
352   if (exportFunction->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
353
354   // create the XAO object
355   XAO::Xao* xaoObject = new XAO::Xao();
356   xaoObject->setAuthor(author);
357
358   // add the geometry
359   XAO::BrepGeometry* geometry = (XAO::BrepGeometry*)XAO::Geometry::createGeometry(XAO::BREP);
360   TopoDS_Shape topoShape = shape->GetValue();
361   exportFunction->SetValue(topoShape);
362   XAO::BrepGeometry* brep = (XAO::BrepGeometry*)geometry;
363   brep->setTopoDS_Shape(topoShape);
364
365   geometry->setName(shape->GetName().ToCString());
366   exportSubshapes(shape, geometry);
367   xaoObject->setGeometry(geometry);
368
369   if (!exportGroups(groupList, xaoObject, geometry)) return false;
370   exportFields(fieldList, xaoObject, geometry);
371
372   // export the XAO to the file
373   xaoObject->exportXAO(fileName, shapeFileName);
374
375   // make a Python command
376   GEOM::TPythonDump pd(exportFunction);
377   std::string convFileName = Kernel_Utils::BackSlashToSlash(fileName);
378   pd << "exported = geompy.ExportXAO(" << shape;
379
380   // list of groups
381   pd << ", [";
382   if (groupList.size() > 0)
383   {
384     std::list<Handle(GEOM_Object)>::iterator itGroup = groupList.begin();
385     pd << (*itGroup++);
386     while (itGroup != groupList.end())
387     {
388       pd << ", " << (*itGroup++);
389     }
390   }
391
392   // list of fields
393   pd << "], [";
394   if (fieldList.size() > 0)
395   {
396     std::list<Handle(GEOM_Field)>::iterator itField = fieldList.begin();
397     pd << (*itField++);
398     while (itField != fieldList.end())
399     {
400       pd << ", " << (*itField++);
401     }
402   }
403   pd << "], ";
404   pd << "\"" << author << "\", \"" << convFileName.c_str() << "\", \"" << shapeFileName << "\")";
405
406   SetErrorCode(OK);
407   delete xaoObject;
408
409   return true;
410 }
411
412 void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
413                                              Handle(GEOM_Function) function, int shapeType, int dim,
414                                              Handle(TColStd_HSequenceOfTransient)& subShapeList )
415 {
416   Handle(GEOM_Object) subShape;
417   Handle(GEOM_Function) aFunction;
418   Handle(TColStd_HArray1OfInteger) anArray;
419
420   XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin((XAO::Dimension)dim);
421   for (; elementIterator != xaoGeometry->end((XAO::Dimension)dim); elementIterator++)
422   {
423     XAO::GeometricElement element = elementIterator->second;
424     if (!element.hasName())
425       continue;
426
427     std::string name = element.getName();
428     std::string ref = element.getReference();
429     int iref = XAO::XaoUtils::stringToInt(ref);
430
431     anArray = new TColStd_HArray1OfInteger(1, 1);
432     anArray->SetValue(1, iref);
433
434     subShape = GetEngine()->AddObject(GEOM_SUBSHAPE);
435     Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
436     if (aFunction.IsNull())
437       return;
438
439     subShape->SetName(name.c_str());
440     subShape->SetType(shapeType);
441
442     GEOM_ISubShape aSSI(aFunction);
443     aSSI.SetMainShape(function);
444     aSSI.SetIndices(anArray);
445
446     //aFunction->SetValue(aValue);
447     subShapeList->Append(subShape);
448
449     // Put this subshape in the list of sub-shapes of theMainShape
450     function->AddSubShapeReference(aFunction);
451   }
452 }
453
454 //=============================================================================
455 /*!
456  *  Import a shape from XAO format
457  *  \param fileName The name of the file to import
458  *  \param shape The imported shape
459  *  \param subShapes The list of imported groups
460  *  \param groups The list of imported groups
461  *  \param fields The list of imported fields
462  *  \return boolean indicating if import was succeful.
463  */
464 //=============================================================================
465 bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
466                                        Handle(GEOM_Object)& shape,
467                                        Handle(TColStd_HSequenceOfTransient)& subShapes,
468                                        Handle(TColStd_HSequenceOfTransient)& groups,
469                                        Handle(TColStd_HSequenceOfTransient)& fields )
470 {
471   SetErrorCode(KO);
472
473   if (fileName == NULL || groups.IsNull() || fields.IsNull())
474     return false;
475
476   // Read the XAO
477   XAO::Xao* xaoObject = new XAO::Xao();
478   try
479   {
480     xaoObject->importXAO(fileName);
481   }
482   catch (XAO::XAO_Exception& exc)
483   {
484     delete xaoObject;
485     SetErrorCode(exc.what());
486     return false;
487   }
488
489   XAO::Geometry* xaoGeometry = xaoObject->getGeometry();
490   if (xaoGeometry == NULL)
491   {
492     delete xaoObject;
493     SetErrorCode("Cannot import XAO: geometry format not supported.");
494     return false;
495   }
496
497   // create the shape
498   shape = GetEngine()->AddObject(GEOM_IMPORT);
499   Handle(GEOM_Function) function = shape->AddFunction(XAOPlugin_Driver::GetID(), IMPORT_SHAPE);
500   if (function.IsNull()) return false;
501   if (function->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
502
503   function->SetString( XAOPlugin_Driver::GetFileNameTag(), fileName );
504
505   // set the geometry
506   if (xaoGeometry->getFormat() == XAO::BREP)
507   {
508     XAO::BrepGeometry* brep = (XAO::BrepGeometry*)xaoGeometry;
509     TopoDS_Shape geomShape = brep->getTopoDS_Shape();
510     function->SetValue(geomShape);
511     shape->SetName(xaoGeometry->getName().c_str());
512   }
513   else
514   {
515     delete xaoObject;
516     SetErrorCode("Cannot import XAO: geometry format not supported.");
517     return false;
518   }
519
520   // create sub shapes with names
521   importSubShapes(xaoGeometry, function, GEOM_POINT, XAO::VERTEX, subShapes);
522   importSubShapes(xaoGeometry, function, GEOM_EDGE, XAO::EDGE, subShapes);
523   importSubShapes(xaoGeometry, function, GEOM_FACE, XAO::FACE, subShapes);
524   importSubShapes(xaoGeometry, function, GEOM_SOLID, XAO::SOLID, subShapes);
525
526   // create groups
527   int nbGroups = xaoObject->countGroups();
528   for (int i = 0; i < nbGroups; ++i)
529   {
530     XAO::Group* xaoGroup = xaoObject->getGroup(i);
531
532     // build an array with the indexes of the sub shapes
533     int nbElt = xaoGroup->count();
534     Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt);
535     int j = 0;
536     for (std::set<int>::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it)
537     {
538       int index = (*it);
539       std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
540       array->SetValue(++j, XAO::XaoUtils::stringToInt(ref));
541     }
542
543     // create the group with the array of sub shapes indexes
544     Handle(GEOM_Object) group = GetEngine()->AddSubShape(shape, array);
545     group->SetType(GEOM_GROUP);
546     group->SetName(xaoGroup->getName().c_str());
547
548     // Set a sub-shape type
549     TDF_Label freeLabel = group->GetFreeLabel();
550     TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
551     groups->Append(group);
552   }
553
554   // create the fields
555   int nbFields = xaoObject->countFields();
556   for (int i = 0; i < nbFields; ++i)
557   {
558     XAO::Field* xaoField = xaoObject->getField(i);
559
560     Handle(TColStd_HArray1OfExtendedString) components = new TColStd_HArray1OfExtendedString(0, xaoField->countComponents()-1);
561     for (int j = 0; j < xaoField->countComponents(); ++j)
562     {
563         components->SetValue(j, (TCollection_ExtendedString)xaoField->getComponentName(j).c_str());
564     }
565
566     Handle(GEOM_Field) field = myFieldOperations->CreateField(shape,
567                  xaoField->getName().c_str(),
568                  (int)xaoField->getType(),
569                  (int)xaoField->getDimension(),
570                  components);
571
572     switch (xaoField->getType())
573     {
574         case XAO::BOOLEAN:
575         {
576             XAO::BooleanField* bfield = (XAO::BooleanField*)xaoField;
577             for (int j = 0; j < xaoField->countSteps(); ++j)
578             {
579                 XAO::BooleanStep* bstep = bfield->getStep(j);
580                 Handle(GEOM_FieldStep) step = field->AddStep(bstep->getStep(), bstep->getStamp());
581
582                 Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, bstep->countValues()-1);
583                 std::vector<bool> bvalues = bstep->getValues();
584                 for (int k = 0; k < bstep->countValues(); ++k)
585                 {
586                     values->SetValue(k, bvalues[k] ? 1 : 0);
587                 }
588                 step->SetValues(values);
589             }
590             break;
591         }
592         case XAO::INTEGER:
593         {
594             XAO::IntegerField* ifield = (XAO::IntegerField*)xaoField;
595             for (int j = 0; j < xaoField->countSteps(); ++j)
596             {
597                 XAO::IntegerStep* istep = ifield->getStep(j);
598                 Handle(GEOM_FieldStep) step = field->AddStep(istep->getStep(), istep->getStamp());
599
600                 Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, istep->countValues()-1);
601                 std::vector<int> ivalues = istep->getValues();
602                 for (int k = 0; k < istep->countValues(); ++k)
603                 {
604                     values->SetValue(k, ivalues[k]);
605                 }
606                 step->SetValues(values);
607             }
608             break;
609         }
610         case XAO::DOUBLE:
611         {
612             XAO::DoubleField* dfield = (XAO::DoubleField*)xaoField;
613             for (int j = 0; j < xaoField->countSteps(); ++j)
614             {
615                 XAO::DoubleStep* dstep = dfield->getStep(j);
616                 Handle(GEOM_FieldStep) step = field->AddStep(dstep->getStep(), dstep->getStamp());
617
618                 Handle(TColStd_HArray1OfReal) values = new TColStd_HArray1OfReal(0, dstep->countValues()-1);
619                 std::vector<double> dvalues = dstep->getValues();
620                 for (int k = 0; k < dstep->countValues(); ++k)
621                 {
622                     values->SetValue(k, dvalues[k]);
623                 }
624                 step->SetValues(values);
625             }
626             break;
627         }
628         case XAO::STRING:
629         {
630             XAO::StringField* sfield = (XAO::StringField*)xaoField;
631             for (int j = 0; j < xaoField->countSteps(); ++j)
632             {
633                 XAO::StringStep* sstep = sfield->getStep(j);
634                 Handle(GEOM_FieldStep) step = field->AddStep(sstep->getStep(), sstep->getStamp());
635
636                 Handle(TColStd_HArray1OfExtendedString) values = new TColStd_HArray1OfExtendedString(0, sstep->countValues()-1);
637                 std::vector<std::string> svalues = sstep->getValues();
638                 for (int k = 0; k < sstep->countValues(); ++k)
639                 {
640                     values->SetValue(k, TCollection_ExtendedString(svalues[k].c_str()));
641                 }
642                 step->SetValues(values);
643             }
644             break;
645         }
646     }
647
648     fields->Append(field);
649   }
650
651   // make a Python command
652   GEOM::TPythonDump pd(function);
653   pd << "(imported, " << shape << ", ";
654
655   // list of sub shapes
656   pd << "[";
657   int nbSubshapes = subShapes->Length();
658   if (nbSubshapes > 0)
659   {
660     for (int i = 1; i <= nbSubshapes; i++)
661     {
662       Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(subShapes->Value(i));
663       pd << obj << ((i < nbSubshapes) ? ", " : "");
664     }
665   }
666   pd << "], [";
667
668   // list of groups
669   if (nbGroups > 0)
670   {
671     for (int i = 1; i <= nbGroups; i++)
672     {
673       Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(groups->Value(i));
674       pd << obj << ((i < nbGroups) ? ", " : "");
675     }
676   }
677
678   pd << "], [";
679
680   // list of fields
681   if (nbFields > 0)
682   {
683     for (int i = 1; i <= nbFields; i++)
684     {
685       Handle(GEOM_Field) obj = Handle(GEOM_Field)::DownCast(fields->Value(i));
686       pd << obj << ((i < nbFields) ? ", " : "");
687     }
688   }
689   std::string convFileName =  Kernel_Utils::BackSlashToSlash( fileName );
690   pd << "]";
691   pd << ") = geompy.ImportXAO(\"" << convFileName.c_str() << "\")";
692
693   delete xaoObject;
694   SetErrorCode(OK);
695
696   return true;
697 }