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