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