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