Salome HOME
Merge branch 'cadbld'
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ExportFeature.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
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 #include <ExchangePlugin_ExportFeature.h>
21
22 #include <algorithm>
23 #include <iterator>
24 #include <string>
25 #ifdef _DEBUG
26 #include <iostream>
27 #include <ostream>
28 #endif
29
30
31 #include <Config_Common.h>
32 #include <Config_PropManager.h>
33
34 #include <GeomAlgoAPI_BREPExport.h>
35 #include <GeomAlgoAPI_CompoundBuilder.h>
36 #include <GeomAlgoAPI_IGESExport.h>
37 #include <GeomAlgoAPI_STEPExport.h>
38 #include <GeomAlgoAPI_STLExport.h>
39 #include <GeomAlgoAPI_Tools.h>
40 #include <GeomAlgoAPI_XAOExport.h>
41
42 #include <GeomAPI_Shape.h>
43 #include <GeomAPI_ShapeExplorer.h>
44 #include <GeomAPI_Trsf.h>
45
46 #include <Locale_Convert.h>
47
48 #include <ModelAPI_AttributeSelectionList.h>
49 #include <ModelAPI_AttributeString.h>
50 #include <ModelAPI_AttributeStringArray.h>
51 #include <ModelAPI_AttributeIntArray.h>
52 #include <ModelAPI_AttributeTables.h>
53 #include <ModelAPI_AttributeDouble.h>
54 #include <ModelAPI_Data.h>
55 #include <ModelAPI_Document.h>
56 #include <ModelAPI_Object.h>
57 #include <ModelAPI_ResultBody.h>
58 #include <ModelAPI_ResultPart.h>
59 #include <ModelAPI_ResultGroup.h>
60 #include <ModelAPI_ResultField.h>
61 #include <ModelAPI_Session.h>
62 #include <ModelAPI_Validator.h>
63 #include <ModelAPI_Tools.h>
64
65 #include <Events_InfoMessage.h>
66
67 #include <XAO_Group.hxx>
68 #include <XAO_Field.hxx>
69 #include <XAO_Xao.hxx>
70 #include <XAO_Geometry.hxx>
71
72 #include <ExchangePlugin_Tools.h>
73
74 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
75 {
76 }
77
78 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
79 {
80   // TODO Auto-generated destructor stub
81 }
82
83 /*
84  * Request for initialization of data model of the feature: adding all attributes
85  */
86 void ExchangePlugin_ExportFeature::initAttributes()
87 {
88   data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
89     ModelAPI_AttributeString::typeId());
90   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(),
91     ModelAPI_AttributeString::typeId());
92   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
93     ModelAPI_AttributeString::typeId());
94   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
95     ModelAPI_AttributeString::typeId());
96   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
97     ModelAPI_AttributeSelectionList::typeId());
98   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
99     ModelAPI_AttributeString::typeId());
100   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
101     ModelAPI_AttributeString::typeId());
102   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(),
103     ModelAPI_AttributeSelectionList::typeId());
104   data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
105     ModelAPI_AttributeString::typeId());
106   data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
107     ModelAPI_AttributeSelection::typeId());
108   data()->addAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
109    ModelAPI_AttributeString::typeId());
110   data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(),
111     ModelAPI_AttributeDouble::typeId());
112
113   double defelection = Config_PropManager::real("Visualization", "body_deflection");
114   real(ExchangePlugin_ExportFeature::STL_RELATIVE())->setValue(defelection);
115
116   data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
117     ModelAPI_AttributeDouble::typeId());
118   data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
119    ModelAPI_AttributeString::typeId());
120
121   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
122     ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
123   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
124     ExchangePlugin_ExportFeature::STL_FILE_PATH_ID());
125   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
126     ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
127   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
128     ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
129   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
130     ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
131
132   // to support previous version of document, move the selection list
133   // if the type of export operation is XAO
134   AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
135   if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") {
136     bool aWasBlocked = data()->blockSendAttributeUpdated(true, false);
137     AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
138     AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
139     if (aSelList->size() > 0 && aXAOSelList->size() == 0)
140       aSelList->copyTo(aXAOSelList);
141     aSelList->clear();
142     data()->blockSendAttributeUpdated(aWasBlocked, false);
143   }
144 }
145
146 void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
147 {
148   if (theID == XAO_FILE_PATH_ID()) {
149     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
150       string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
151   }
152   else if (theID == STL_FILE_PATH_ID()) {
153     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
154       string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value());
155   }
156
157 }
158
159 /*
160  * Computes or recomputes the results
161  */
162 void ExchangePlugin_ExportFeature::execute()
163 {
164   AttributeStringPtr aFormatAttr =
165       this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
166   std::string aFormat = aFormatAttr->value();
167
168   AttributeStringPtr aFilePathAttr =
169       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
170   std::string aFilePath = aFilePathAttr->value();
171   if (aFilePath.empty())
172     return;
173
174   exportFile(aFilePath, aFormat);
175 }
176
177 void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
178                                               const std::string& theFormat)
179 {
180   std::string aFormatName = theFormat;
181
182   if (aFormatName.empty()) { // get default format for the extension
183     // ".brep" -> "BREP"
184     std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
185     if (anExtension == "BREP" || anExtension == "BRP") {
186       aFormatName = "BREP";
187     } else if (anExtension == "STEP" || anExtension == "STP") {
188       aFormatName = "STEP";
189     } else if (anExtension == "IGES" || anExtension == "IGS") {
190       aFormatName = "IGES-5.1";
191     } else {
192       aFormatName = anExtension;
193     }
194   }
195
196   if (aFormatName == "XAO") {
197     exportXAO(theFileName);
198     return;
199   }else if (aFormatName == "STL") {
200     exportSTL(theFileName);
201     return;
202   }
203
204   // make shape for export from selected shapes
205   AttributeSelectionListPtr aSelectionListAttr =
206       this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
207   std::list<GeomShapePtr> aShapes;
208   for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
209     AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
210
211     /// do not export pictures
212     ResultPtr aBodyContext =
213       std::dynamic_pointer_cast<ModelAPI_Result>(anAttrSelection->context());
214     if (aBodyContext.get() && aBodyContext->hasTexture())
215       continue;
216
217     std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
218     if (aCurShape.get() == NULL)
219       aCurShape = anAttrSelection->context()->shape();
220     if (aCurShape.get() != NULL)
221       aShapes.push_back(aCurShape);
222   }
223
224   // Store compound if we have more than one shape.
225   std::shared_ptr<GeomAPI_Shape> aShape =
226     aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
227
228   // Perform the export
229   std::string anError;
230   bool aResult = false;
231   if (aFormatName == "BREP") {
232     aResult = BREPExport(theFileName, aFormatName, aShape, anError);
233   } else if (aFormatName == "STEP") {
234     aResult = STEPExport(theFileName, aFormatName, aShape, anError);
235   } else if (aFormatName.substr(0, 4) == "IGES") {
236     aResult = IGESExport(theFileName, aFormatName, aShape, anError);
237   } else {
238     anError = "Unsupported format: " + aFormatName;
239   }
240
241   if (!aResult || !anError.empty()) {
242     setError("An error occurred while exporting " + theFileName + ": " + anError);
243     return;
244   }
245 }
246
247 /// Returns XAO string by the value from the table
248 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
249   const ModelAPI_AttributeTables::ValueType& theType) {
250   std::ostringstream aStr; // the resulting string value
251   switch(theType) {
252   case ModelAPI_AttributeTables::BOOLEAN:
253     aStr<<(theVal.myBool ? "true" : "false");
254     break;
255   case ModelAPI_AttributeTables::INTEGER:
256     aStr<<theVal.myInt;
257     break;
258   case ModelAPI_AttributeTables::DOUBLE:
259     aStr<<theVal.myDouble;
260     break;
261   case ModelAPI_AttributeTables::STRING:
262     aStr<<theVal.myStr;
263     break;
264   }
265   return aStr.str();
266 }
267
268 void ExchangePlugin_ExportFeature::exportSTL(const std::string& theFileName)
269 {
270   // Get shape.
271   AttributeSelectionPtr aSelection = selection(STL_OBJECT_SELECTED());
272   GeomShapePtr aShape = aSelection->value();
273   if (!aShape.get()) {
274     aShape = aSelection->context()->shape();
275   }
276
277   // Get relative value and percent flag.
278   double aValue;
279   bool anIsRelative = false;
280   bool anIsASCII = false;
281
282   if (string(STL_DEFLECTION_TYPE())->value() == STL_DEFLECTION_TYPE_RELATIVE()) {
283     aValue = real(STL_RELATIVE())->value();
284     anIsRelative = true;
285   } else {
286     aValue = real(STL_ABSOLUTE())->value();
287   }
288
289   if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) {
290     anIsASCII = true;
291   }
292   // Perform the export
293   std::string anError;
294   bool aResult = false;
295
296   aResult = STLExport(theFileName,
297                       aShape,
298                       aValue,
299                       anIsRelative,
300                       anIsASCII,
301                       anError);
302
303   if (!aResult || !anError.empty()) {
304     setError("An error occurred while exporting " + theFileName + ": " + anError);
305     return;
306   }
307 }
308
309
310 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
311 {
312   try {
313
314   std::string anError;
315   XAO::Xao aXao;
316
317   // author
318
319   std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
320   aXao.setAuthor(anAuthor);
321
322   // make shape for export from all results
323   std::list<GeomShapePtr> aShapes;
324   std::list<ResultPtr> aResults;
325   std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
326   std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
327
328   bool anExCludedIsImage = false;
329   AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
330   bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
331   if (aIsSelection) { // a mode for export to geom result by result
332     for (int a = 0; a < aSelection->size(); a++) {
333       AttributeSelectionPtr anAttr = aSelection->value(a);
334       ResultPtr aBodyContext =
335         std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
336       if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
337           /// do not export pictures
338           if (aBodyContext->hasTexture()){
339             anExCludedIsImage = true;
340             continue;
341           }
342         aResults.push_back(aBodyContext);
343         GeomShapePtr aShape = anAttr->value();
344         if (!aShape.get())
345           aShape = aBodyContext->shape();
346         aShapes.push_back(aShape);
347         if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
348           ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
349           DocumentPtr aPartDoc = aResPart->partDoc();
350           if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
351             std::string msg = "Can not export XAO for not loaded part";
352             Events_InfoMessage("ExportFeature", msg, this).send();
353             return;
354           } else {
355             aDocuments.push_back(aPartDoc);
356             aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
357           }
358         }
359       }
360     }
361   } else {
362     int aBodyCount = document()->size(ModelAPI_ResultBody::group());
363     for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
364       ResultBodyPtr aResultBody =
365           std::dynamic_pointer_cast<ModelAPI_ResultBody>(
366               document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
367       if (!aResultBody.get())
368         continue;
369       aShapes.push_back(aResultBody->shape());
370       aResults.push_back(aResultBody);
371     }
372   }
373   if (aShapes.empty()) {
374     if(!anExCludedIsImage)
375       setError("No shapes to export");
376     return;
377   }
378
379
380   GeomShapePtr aShape = (aShapes.size() == 1)
381       ? *aShapes.begin()
382       : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
383
384   SetShapeToXAO(aShape, &aXao, anError);
385
386   if (!anError.empty()) {
387     setError("An error occurred while exporting " + theFileName + ": " + anError);
388     return;
389   }
390
391   // geometry name
392   std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
393   if (aGeometryName.empty() && aResults.size() == 1) {
394     // get the name from the first result
395     ResultPtr aResultBody = *aResults.begin();
396     aGeometryName = Locale::Convert::toString(aResultBody->data()->name());
397   }
398
399   aXao.getGeometry()->setName(aGeometryName);
400
401   std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
402
403   // iterate all documents used
404   if (aDocuments.empty())
405     aDocuments.push_back(document());
406   std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
407   for(; aDoc != aDocuments.end(); aDoc++) {
408     // groups
409     int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
410     for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
411       ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
412           (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
413       if (!aResultGroup.get() || !aResultGroup->shape().get())
414         continue;
415
416       FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
417
418       AttributeSelectionListPtr aSelectionList =
419           aGroupFeature->selectionList("group_list");
420       if (!ModelAPI_Tools::isInResults(aSelectionList,
421                                        aResults,
422                                        allResultsCashed))// skip group not used in result
423         continue;
424
425       // conversion of dimension
426       std::string aSelectionType = aSelectionList->selectionType();
427       GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
428       std::string aDimensionString =
429         ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
430       XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
431
432       XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
433         Locale::Convert::toString(aResultGroup->data()->name()));
434
435       try {
436         GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
437         for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
438           GeomShapePtr aGroupShape = aGroupResExplorer.current();
439           if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
440             aGroupShape->move(aDocTrsf[*aDoc]);
441           int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
442           if (aReferenceID == 0) // selected value does not found in the exported shape
443             continue;
444           std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
445           int anElementID =
446             aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
447           aXaoGroup->add(anElementID);
448         }
449       } catch (XAO::XAO_Exception& e) {
450         // LCOV_EXCL_START
451         std::string msg = "An error occurred while exporting group " +
452           Locale::Convert::toString(aResultGroup->data()->name());
453         msg += ".\n";
454         msg += e.what();
455         msg += "\n";
456         msg += "=> skipping this group from XAO export.";
457         Events_InfoMessage("ExportFeature", msg, this).send();
458         aXao.removeGroup(aXaoGroup);
459         // LCOV_EXCL_STOP
460       }
461     }
462
463     // fields
464     int aFieldCount = (*aDoc)->size(ModelAPI_ResultField::group());
465     for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
466       ResultFieldPtr aResultField = std::dynamic_pointer_cast<ModelAPI_ResultField>(
467         (*aDoc)->object(ModelAPI_ResultField::group(), aFieldIndex));
468
469       FeaturePtr aFieldFeature = (*aDoc)->feature(aResultField);
470
471       AttributeSelectionListPtr aSelectionList =
472           aFieldFeature->selectionList("selected");
473       std::string aSelectionType = aSelectionList->selectionType();
474       bool isWholePart = aSelectionType == "part";
475       // skip field not used in results
476       if (!isWholePart &&
477           !ModelAPI_Tools::isInResults(aSelectionList, aResults, allResultsCashed))
478         continue;
479
480       // conversion of dimension
481       std::string aDimensionString =
482         ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
483       XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
484       // get tables and their type
485       std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
486       std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
487       XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
488
489       XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
490         Locale::Convert::toString(aResultField->data()->name()));
491
492
493       try {
494         // set components names
495         AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
496         for(int aComp = 0; aComp < aComponents->size(); aComp++) {
497           std::string aName = aComponents->value(aComp);
498           aXaoField->setComponentName(aComp, aName);
499         }
500
501         AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
502         for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
503           XAO::Step* aStep = aXaoField->addNewStep(aStepIndex + 1);
504           aStep->setStep(aStepIndex + 1);
505           int aStampIndex = aStamps->value(aStepIndex);
506           aStep->setStamp(aStampIndex);
507           int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
508           int aNumComps = aTables->columns();
509           std::set<int> aFilledIDs; // to fill the rest by defaults
510           // omit default values first row
511           for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
512             for(int aCol = 0; aCol < aNumComps; aCol++) {
513               int anElementID = 0;
514               if (!isWholePart) {
515                 // element index actually is the ID of the selection
516                 AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1);
517                 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSel->value());
518                 if (aReferenceID == 0) // selected value does not found in the exported shape
519                   continue;
520
521                 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
522                 anElementID = aXao.getGeometry()->
523                   getElementIndexByReference(aFieldDimension, aReferenceString);
524               }
525
526               ModelAPI_AttributeTables::Value aVal = aTables->value(
527                 isWholePart ? 0 : aRow, aCol, aStepIndex);
528               std::string aStrVal = valToString(aVal, aTables->type());
529               aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
530               aFilledIDs.insert(anElementID);
531             }
532           }
533           if (!isWholePart) { // fill the rest values by default ones
534             XAO::GeometricElementList::iterator allElem =
535               aXao.getGeometry()->begin(aFieldDimension);
536             for(; allElem != aXao.getGeometry()->end(aFieldDimension); allElem++) {
537               if (aFilledIDs.find(allElem->first) != aFilledIDs.end())
538                 continue;
539               for(int aCol = 0; aCol < aNumComps; aCol++) {
540                 // default value
541                 ModelAPI_AttributeTables::Value aVal = aTables->value(0, aCol, aStepIndex);
542                 std::string aStrVal = valToString(aVal, aTables->type());
543                 aStep->setStringValue(allElem->first, aCol, aStrVal);
544               }
545             }
546           }
547         }
548       } catch (XAO::XAO_Exception& e) {
549         // LCOV_EXCL_START
550         std::string msg = "An error occurred while exporting field " +
551           Locale::Convert::toString(aResultField->data()->name());
552         msg += ".\n";
553         msg += e.what();
554         msg += "\n";
555         msg += "=> skipping this field from XAO export.";
556         Events_InfoMessage("ExportFeature", msg, this).send();
557         aXao.removeField(aXaoField);
558         // LCOV_EXCL_STOP
559       }
560     }
561   }
562
563   // exporting
564   XAOExport(theFileName, &aXao, anError);
565
566   if (!anError.empty()) {
567     setError("An error occurred while exporting " + theFileName + ": " + anError);
568     return;
569   }
570
571 // LCOV_EXCL_START
572   } catch (XAO::XAO_Exception& e) {
573     std::string anError = e.what();
574     setError("An error occurred while exporting " + theFileName + ": " + anError);
575     return;
576   }
577 // LCOV_EXCL_STOP
578 }
579
580 bool ExchangePlugin_ExportFeature::isMacro() const
581 {
582   if (!data().get() || !data()->isValid())
583     return false;
584   ExchangePlugin_ExportFeature* aThis = ((ExchangePlugin_ExportFeature*)(this));
585   AttributeStringPtr aFormatAttr = aThis->string(FILE_FORMAT_ID());
586   std::string aFormat(aFormatAttr.get() ? aFormatAttr->value() : "");
587
588   if (aFormat.empty()) { // get default format for the extension
589     AttributeStringPtr aFilePathAttr = aThis->string(FILE_PATH_ID());
590     std::string aFilePath = aFilePathAttr->value();
591     if (!aFilePath.empty()) {
592       std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
593       aFormat = anExtension;
594     }
595   }
596
597   if (aFormat == "XAO") { // on export to GEOM the selection attribute is filled - this is
598                           // an exceptional case where export to XAO feature must be kept
599     AttributeSelectionListPtr aList = aThis->selectionList(XAO_SELECTION_LIST_ID());
600     return !aList->isInitialized() || aList->size() == 0;
601   }
602   return true;
603 }