Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ExportFeature.cpp
1 // Copyright (C) 2014-2020  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_Tools.h>
38 #include <GeomAlgoAPI_XAOExport.h>
39
40 #include <GeomAPI_Shape.h>
41 #include <GeomAPI_ShapeExplorer.h>
42 #include <GeomAPI_Trsf.h>
43
44 #include <Locale_Convert.h>
45
46 #include <ModelAPI_AttributeSelectionList.h>
47 #include <ModelAPI_AttributeString.h>
48 #include <ModelAPI_AttributeStringArray.h>
49 #include <ModelAPI_AttributeIntArray.h>
50 #include <ModelAPI_AttributeTables.h>
51 #include <ModelAPI_Data.h>
52 #include <ModelAPI_Document.h>
53 #include <ModelAPI_Object.h>
54 #include <ModelAPI_ResultBody.h>
55 #include <ModelAPI_ResultPart.h>
56 #include <ModelAPI_ResultGroup.h>
57 #include <ModelAPI_ResultField.h>
58 #include <ModelAPI_Session.h>
59 #include <ModelAPI_Validator.h>
60 #include <ModelAPI_Tools.h>
61
62 #include <Events_InfoMessage.h>
63
64 #include <XAO_Group.hxx>
65 #include <XAO_Field.hxx>
66 #include <XAO_Xao.hxx>
67 #include <XAO_Geometry.hxx>
68
69 #include <ExchangePlugin_Tools.h>
70
71 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
72 {
73 }
74
75 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
76 {
77   // TODO Auto-generated destructor stub
78 }
79
80 /*
81  * Request for initialization of data model of the feature: adding all attributes
82  */
83 void ExchangePlugin_ExportFeature::initAttributes()
84 {
85   data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
86     ModelAPI_AttributeString::typeId());
87   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(),
88     ModelAPI_AttributeString::typeId());
89   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
90     ModelAPI_AttributeString::typeId());
91   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
92     ModelAPI_AttributeString::typeId());
93   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
94     ModelAPI_AttributeSelectionList::typeId());
95   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
96     ModelAPI_AttributeString::typeId());
97   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
98     ModelAPI_AttributeString::typeId());
99   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(),
100     ModelAPI_AttributeSelectionList::typeId());
101
102   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
103     ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
104   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
105     ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
106   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
107     ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
108   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
109     ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
110
111   // to support previous version of document, move the selection list
112   // if the type of export operation is XAO
113   AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
114   if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") {
115     bool aWasBlocked = data()->blockSendAttributeUpdated(true, false);
116     AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
117     AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
118     if (aSelList->size() > 0 && aXAOSelList->size() == 0)
119       aSelList->copyTo(aXAOSelList);
120     aSelList->clear();
121     data()->blockSendAttributeUpdated(aWasBlocked, false);
122   }
123 }
124
125 void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
126 {
127   if (theID == XAO_FILE_PATH_ID()) {
128     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
129       string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
130   }
131 }
132
133 /*
134  * Computes or recomputes the results
135  */
136 void ExchangePlugin_ExportFeature::execute()
137 {
138   AttributeStringPtr aFormatAttr =
139       this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
140   std::string aFormat = aFormatAttr->value();
141
142   AttributeStringPtr aFilePathAttr =
143       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
144   std::string aFilePath = aFilePathAttr->value();
145   if (aFilePath.empty())
146     return;
147
148   exportFile(aFilePath, aFormat);
149 }
150
151 void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
152                                               const std::string& theFormat)
153 {
154   std::string aFormatName = theFormat;
155
156   if (aFormatName.empty()) { // get default format for the extension
157     // ".brep" -> "BREP"
158     std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
159     if (anExtension == "BREP" || anExtension == "BRP") {
160       aFormatName = "BREP";
161     } else if (anExtension == "STEP" || anExtension == "STP") {
162       aFormatName = "STEP";
163     } else if (anExtension == "IGES" || anExtension == "IGS") {
164       aFormatName = "IGES-5.1";
165     } else {
166       aFormatName = anExtension;
167     }
168   }
169
170   if (aFormatName == "XAO") {
171     exportXAO(theFileName);
172     return;
173   }
174
175   // make shape for export from selected shapes
176   AttributeSelectionListPtr aSelectionListAttr =
177       this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
178   std::list<GeomShapePtr> aShapes;
179   for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
180     AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
181     std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
182     if (aCurShape.get() == NULL)
183       aCurShape = anAttrSelection->context()->shape();
184     if (aCurShape.get() != NULL)
185       aShapes.push_back(aCurShape);
186   }
187
188   // Store compound if we have more than one shape.
189   std::shared_ptr<GeomAPI_Shape> aShape =
190     aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
191
192   // Perform the export
193   std::string anError;
194   bool aResult = false;
195   if (aFormatName == "BREP") {
196     aResult = BREPExport(theFileName, aFormatName, aShape, anError);
197   } else if (aFormatName == "STEP") {
198     aResult = STEPExport(theFileName, aFormatName, aShape, anError);
199   } else if (aFormatName.substr(0, 4) == "IGES") {
200     aResult = IGESExport(theFileName, aFormatName, aShape, anError);
201   } else {
202     anError = "Unsupported format: " + aFormatName;
203   }
204
205   if (!aResult || !anError.empty()) {
206     setError("An error occurred while exporting " + theFileName + ": " + anError);
207     return;
208   }
209 }
210
211 /// Returns XAO string by the value from the table
212 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
213   const ModelAPI_AttributeTables::ValueType& theType) {
214   std::ostringstream aStr; // the resulting string value
215   switch(theType) {
216   case ModelAPI_AttributeTables::BOOLEAN:
217     aStr<<(theVal.myBool ? "true" : "false");
218     break;
219   case ModelAPI_AttributeTables::INTEGER:
220     aStr<<theVal.myInt;
221     break;
222   case ModelAPI_AttributeTables::DOUBLE:
223     aStr<<theVal.myDouble;
224     break;
225   case ModelAPI_AttributeTables::STRING:
226     aStr<<theVal.myStr;
227     break;
228   }
229   return aStr.str();
230 }
231
232 /// Returns true if something in selection is presented in the results list
233 static bool isInResults(AttributeSelectionListPtr theSelection,
234                         const std::list<ResultPtr>& theResults,
235                         std::set<ResultPtr>& theCashedResults)
236 {
237   // collect all results into a cashed set
238   if (theCashedResults.empty()) {
239     std::list<ResultPtr>::const_iterator aRes = theResults.cbegin();
240     for(; aRes != theResults.cend(); aRes++) {
241       if (theCashedResults.count(*aRes))
242         continue;
243       else
244         theCashedResults.insert(*aRes);
245       if ((*aRes)->groupName() == ModelAPI_ResultBody::group()) {
246         ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
247         std::list<ResultPtr> aResults;
248         ModelAPI_Tools::allSubs(aResBody, aResults, false);
249         for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
250           theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
251         }
252       } else if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) { // all results of the part
253         ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
254         DocumentPtr aPartDoc = aResPart->partDoc();
255         if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
256           return false;
257         }
258         int aBodyCount = aPartDoc->size(ModelAPI_ResultBody::group());
259         for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
260           ResultBodyPtr aResBody =
261             std::dynamic_pointer_cast<ModelAPI_ResultBody>(
262               aPartDoc->object(ModelAPI_ResultBody::group(), aBodyIndex));
263           if (aResBody.get()) {
264             theCashedResults.insert(aResBody);
265             std::list<ResultPtr> aResults;
266             ModelAPI_Tools::allSubs(aResBody, aResults, false);
267             for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
268               theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
269             }
270           }
271         }
272       }
273     }
274   }
275   // if context is in results, return true
276   for(int a = 0; a < theSelection->size(); a++) {
277     AttributeSelectionPtr anAttr = theSelection->value(a);
278     ResultPtr aContext = anAttr->context();
279     // check is it group selected for groups BOP
280     if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
281       // it is impossible by used results check which result is used in this group result,
282       // so check the results shapes is it in results of this document or not
283       FeaturePtr aSelFeature =
284         std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
285       if (!aSelFeature.get() || aSelFeature->results().empty())
286         continue;
287       GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
288
289       std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
290       for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
291         GeomShapePtr aResultShape = (*allResultsIter)->shape();
292
293         GeomAPI_Shape::ShapeType aType =
294           GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
295         GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
296         for(; aGroupResExp.more(); aGroupResExp.next()) {
297           if (aResultShape->isSubShape(aGroupResExp.current(), false))
298             return true; // at least one shape of the group is in the used results
299         }
300       }
301     }
302     ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
303     if (!aSelected.get()) { // try to get selected feature and all its results
304       FeaturePtr aContextFeature = anAttr->contextFeature();
305       if (aContextFeature.get() && !aContextFeature->results().empty()) {
306         const std::list<ResultPtr>& allResluts = aContextFeature->results();
307         std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
308         for(; aResIter != allResluts.cend(); aResIter++) {
309           if (aResIter->get() && theCashedResults.count(*aResIter))
310             return true;
311         }
312       }
313     } else if (aSelected.get() && theCashedResults.count(aSelected))
314       return true;
315   }
316   return false;
317 }
318
319 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
320 {
321   try {
322
323   std::string anError;
324   XAO::Xao aXao;
325
326   // author
327
328   std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
329   aXao.setAuthor(anAuthor);
330
331   // make shape for export from all results
332   std::list<GeomShapePtr> aShapes;
333   std::list<ResultPtr> aResults;
334   std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
335   std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
336
337   AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
338   bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
339   if (aIsSelection) { // a mode for export to geom result by result
340     for(int a = 0; a < aSelection->size(); a++) {
341       AttributeSelectionPtr anAttr = aSelection->value(a);
342       ResultPtr aBodyContext =
343         std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
344       if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
345         aResults.push_back(aBodyContext);
346         GeomShapePtr aShape = anAttr->value();
347         if (!aShape.get())
348           aShape = aBodyContext->shape();
349         aShapes.push_back(aShape);
350         if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
351           ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
352           DocumentPtr aPartDoc = aResPart->partDoc();
353           if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
354             std::string msg = "Can not export XAO for not loaded part";
355             Events_InfoMessage("ExportFeature", msg, this).send();
356             return;
357           } else {
358             aDocuments.push_back(aPartDoc);
359             aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
360           }
361         }
362       }
363     }
364   } else {
365     int aBodyCount = document()->size(ModelAPI_ResultBody::group());
366     for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
367       ResultBodyPtr aResultBody =
368           std::dynamic_pointer_cast<ModelAPI_ResultBody>(
369               document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
370       if (!aResultBody.get())
371         continue;
372       aShapes.push_back(aResultBody->shape());
373       aResults.push_back(aResultBody);
374     }
375   }
376   if (aShapes.empty()) {
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 (!isInResults(aSelectionList, aResults, 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 && !isInResults(aSelectionList, aResults, allResultsCashed))
477         continue;
478
479       // conversion of dimension
480       std::string aDimensionString =
481         ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
482       XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
483       // get tables and their type
484       std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
485       std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
486       XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
487
488       XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
489         Locale::Convert::toString(aResultField->data()->name()));
490
491
492       try {
493         // set components names
494         AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
495         for(int aComp = 0; aComp < aComponents->size(); aComp++) {
496           std::string aName = aComponents->value(aComp);
497           aXaoField->setComponentName(aComp, aName);
498         }
499
500         AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
501         for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
502           XAO::Step* aStep = aXaoField->addNewStep(aStepIndex + 1);
503           aStep->setStep(aStepIndex + 1);
504           int aStampIndex = aStamps->value(aStepIndex);
505           aStep->setStamp(aStampIndex);
506           int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
507           int aNumComps = aTables->columns();
508           std::set<int> aFilledIDs; // to fill the rest by defaults
509           // omit default values first row
510           for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
511             for(int aCol = 0; aCol < aNumComps; aCol++) {
512               int anElementID = 0;
513               if (!isWholePart) {
514                 // element index actually is the ID of the selection
515                 AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1);
516                 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSel->value());
517                 if (aReferenceID == 0) // selected value does not found in the exported shape
518                   continue;
519
520                 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
521                 anElementID = aXao.getGeometry()->
522                   getElementIndexByReference(aFieldDimension, aReferenceString);
523               }
524
525               ModelAPI_AttributeTables::Value aVal = aTables->value(
526                 isWholePart ? 0 : aRow, aCol, aStepIndex);
527               std::string aStrVal = valToString(aVal, aTables->type());
528               aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
529               aFilledIDs.insert(anElementID);
530             }
531           }
532           if (!isWholePart) { // fill the rest values by default ones
533             XAO::GeometricElementList::iterator allElem =
534               aXao.getGeometry()->begin(aFieldDimension);
535             for(; allElem != aXao.getGeometry()->end(aFieldDimension); allElem++) {
536               if (aFilledIDs.find(allElem->first) != aFilledIDs.end())
537                 continue;
538               for(int aCol = 0; aCol < aNumComps; aCol++) {
539                 // default value
540                 ModelAPI_AttributeTables::Value aVal = aTables->value(0, aCol, aStepIndex);
541                 std::string aStrVal = valToString(aVal, aTables->type());
542                 aStep->setStringValue(allElem->first, aCol, aStrVal);
543               }
544             }
545           }
546         }
547       } catch (XAO::XAO_Exception& e) {
548         // LCOV_EXCL_START
549         std::string msg = "An error occurred while exporting field " +
550           Locale::Convert::toString(aResultField->data()->name());
551         msg += ".\n";
552         msg += e.what();
553         msg += "\n";
554         msg += "=> skipping this field from XAO export.";
555         Events_InfoMessage("ExportFeature", msg, this).send();
556         aXao.removeField(aXaoField);
557         // LCOV_EXCL_STOP
558       }
559     }
560   }
561
562   // exporting
563   XAOExport(theFileName, &aXao, anError);
564
565   if (!anError.empty()) {
566     setError("An error occurred while exporting " + theFileName + ": " + anError);
567     return;
568   }
569
570 // LCOV_EXCL_START
571   } catch (XAO::XAO_Exception& e) {
572     std::string anError = e.what();
573     setError("An error occurred while exporting " + theFileName + ": " + anError);
574     return;
575   }
576 // LCOV_EXCL_STOP
577 }
578
579 bool ExchangePlugin_ExportFeature::isMacro() const
580 {
581   if (!data().get() || !data()->isValid())
582     return false;
583   ExchangePlugin_ExportFeature* aThis = ((ExchangePlugin_ExportFeature*)(this));
584   AttributeStringPtr aFormatAttr = aThis->string(FILE_FORMAT_ID());
585   std::string aFormat(aFormatAttr.get() ? aFormatAttr->value() : "");
586
587   if (aFormat.empty()) { // get default format for the extension
588     AttributeStringPtr aFilePathAttr = aThis->string(FILE_PATH_ID());
589     std::string aFilePath = aFilePathAttr->value();
590     if (!aFilePath.empty()) {
591       std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
592       aFormat = anExtension;
593     }
594   }
595
596   if (aFormat == "XAO") { // on export to GEOM the selection attribute is filled - this is
597                           // an exceptional case where export to XAO feature must be kept
598     AttributeSelectionListPtr aList = aThis->selectionList(XAO_SELECTION_LIST_ID());
599     return !aList->isInitialized() || aList->size() == 0;
600   }
601   return true;
602 }