Salome HOME
Use independent attribute for the shapes exported to XAO for correct processing the...
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ExportFeature.cpp
1 // Copyright (C) 2014-2019  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 <ModelAPI_AttributeSelectionList.h>
45 #include <ModelAPI_AttributeString.h>
46 #include <ModelAPI_AttributeStringArray.h>
47 #include <ModelAPI_AttributeIntArray.h>
48 #include <ModelAPI_AttributeTables.h>
49 #include <ModelAPI_Data.h>
50 #include <ModelAPI_Document.h>
51 #include <ModelAPI_Object.h>
52 #include <ModelAPI_ResultBody.h>
53 #include <ModelAPI_ResultPart.h>
54 #include <ModelAPI_ResultGroup.h>
55 #include <ModelAPI_ResultField.h>
56 #include <ModelAPI_Session.h>
57 #include <ModelAPI_Validator.h>
58 #include <ModelAPI_Tools.h>
59
60 #include <Events_InfoMessage.h>
61
62 #include <XAO_Group.hxx>
63 #include <XAO_Field.hxx>
64 #include <XAO_Xao.hxx>
65 #include <XAO_Geometry.hxx>
66
67 #include <ExchangePlugin_Tools.h>
68
69 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
70 {
71 }
72
73 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
74 {
75   // TODO Auto-generated destructor stub
76 }
77
78 /*
79  * Request for initialization of data model of the feature: adding all attributes
80  */
81 void ExchangePlugin_ExportFeature::initAttributes()
82 {
83   data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
84     ModelAPI_AttributeString::typeId());
85   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(),
86     ModelAPI_AttributeString::typeId());
87   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
88     ModelAPI_AttributeString::typeId());
89   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
90     ModelAPI_AttributeString::typeId());
91   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
92     ModelAPI_AttributeSelectionList::typeId());
93   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
94     ModelAPI_AttributeString::typeId());
95   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
96     ModelAPI_AttributeString::typeId());
97   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(),
98     ModelAPI_AttributeSelectionList::typeId());
99
100   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
101     ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
102   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
103     ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
104   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
105     ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
106   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
107     ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
108
109   // to support previous version of document, move the selection list
110   // if the type of export operation is XAO
111   AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
112   if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") {
113     AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
114     int aSelListSize = aSelList->size();
115     AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
116     if (aSelListSize > 0 && aXAOSelList->size() == 0) {
117       for (int i = 0; i < aSelListSize; ++i) {
118         AttributeSelectionPtr aSelection = aSelList->value(i);
119         aXAOSelList->append(aSelection->context(), aSelection->value());
120       }
121       aXAOSelList->setSelectionType(aSelList->selectionType());
122     }
123     aSelList->clear();
124   }
125 }
126
127 void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
128 {
129   if (theID == XAO_FILE_PATH_ID()) {
130     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
131       string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
132   }
133 }
134
135 /*
136  * Computes or recomputes the results
137  */
138 void ExchangePlugin_ExportFeature::execute()
139 {
140   AttributeStringPtr aFormatAttr =
141       this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
142   std::string aFormat = aFormatAttr->value();
143
144   AttributeStringPtr aFilePathAttr =
145       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
146   std::string aFilePath = aFilePathAttr->value();
147   if (aFilePath.empty())
148     return;
149
150   exportFile(aFilePath, aFormat);
151 }
152
153 void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
154                                               const std::string& theFormat)
155 {
156   std::string aFormatName = theFormat;
157
158   if (aFormatName.empty()) { // get default format for the extension
159     // ".brep" -> "BREP"
160     std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
161     if (anExtension == "BREP" || anExtension == "BRP") {
162       aFormatName = "BREP";
163     } else if (anExtension == "STEP" || anExtension == "STP") {
164       aFormatName = "STEP";
165     } else if (anExtension == "IGES" || anExtension == "IGS") {
166       aFormatName = "IGES-5.1";
167     } else {
168       aFormatName = anExtension;
169     }
170   }
171
172   if (aFormatName == "XAO") {
173     exportXAO(theFileName);
174     return;
175   }
176
177   // make shape for export from selected shapes
178   AttributeSelectionListPtr aSelectionListAttr =
179       this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
180   std::list<GeomShapePtr> aShapes;
181   for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
182     AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
183     std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
184     if (aCurShape.get() == NULL)
185       aCurShape = anAttrSelection->context()->shape();
186     if (aCurShape.get() != NULL)
187       aShapes.push_back(aCurShape);
188   }
189
190   // Store compound if we have more than one shape.
191   std::shared_ptr<GeomAPI_Shape> aShape =
192     aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
193
194   // Perform the export
195   std::string anError;
196   bool aResult = false;
197   if (aFormatName == "BREP") {
198     aResult = BREPExport(theFileName, aFormatName, aShape, anError);
199   } else if (aFormatName == "STEP") {
200     aResult = STEPExport(theFileName, aFormatName, aShape, anError);
201   } else if (aFormatName.substr(0, 4) == "IGES") {
202     aResult = IGESExport(theFileName, aFormatName, aShape, anError);
203   } else {
204     anError = "Unsupported format: " + aFormatName;
205   }
206
207   if (!anError.empty()) {
208     setError("An error occurred while exporting " + theFileName + ": " + anError);
209     return;
210   }
211 }
212
213 /// Returns XAO string by the value from the table
214 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
215   const ModelAPI_AttributeTables::ValueType& theType) {
216   std::ostringstream aStr; // the resulting string value
217   switch(theType) {
218   case ModelAPI_AttributeTables::BOOLEAN:
219     aStr<<(theVal.myBool ? "true" : "false");
220     break;
221   case ModelAPI_AttributeTables::INTEGER:
222     aStr<<theVal.myInt;
223     break;
224   case ModelAPI_AttributeTables::DOUBLE:
225     aStr<<theVal.myDouble;
226     break;
227   case ModelAPI_AttributeTables::STRING:
228     aStr<<theVal.myStr;
229     break;
230   }
231   return aStr.str();
232 }
233
234 /// Returns true if something in selection is presented in the results list
235 static bool isInResults(AttributeSelectionListPtr theSelection,
236                         const std::list<ResultPtr>& theResults,
237                         std::set<ResultPtr>& theCashedResults)
238 {
239   // collect all results into a cashed set
240   if (theCashedResults.empty()) {
241     std::list<ResultPtr> aResults;
242     std::list<ResultPtr>::const_iterator aRes = theResults.cbegin();
243     for(; aRes != theResults.cend(); aRes++) {
244       if (theCashedResults.count(*aRes))
245         continue;
246       else
247         theCashedResults.insert(*aRes);
248       if ((*aRes)->groupName() == ModelAPI_ResultBody::group()) {
249         ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
250         std::list<ResultPtr> aResults;
251         ModelAPI_Tools::allSubs(aResBody, aResults, false);
252         for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
253           theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
254         }
255       } else if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) { // all results of the part
256         ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
257         DocumentPtr aPartDoc = aResPart->partDoc();
258         if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
259           return false;
260         }
261         int aBodyCount = aPartDoc->size(ModelAPI_ResultBody::group());
262         for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
263           ResultBodyPtr aResBody =
264             std::dynamic_pointer_cast<ModelAPI_ResultBody>(
265               aPartDoc->object(ModelAPI_ResultBody::group(), aBodyIndex));
266           if (aResBody.get()) {
267             theCashedResults.insert(aResBody);
268             std::list<ResultPtr> aResults;
269             ModelAPI_Tools::allSubs(aResBody, aResults, false);
270             for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
271               theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
272             }
273           }
274         }
275       }
276     }
277   }
278   // if context is in results, return true
279   for(int a = 0; a < theSelection->size(); a++) {
280     AttributeSelectionPtr anAttr = theSelection->value(a);
281     ResultPtr aContext = anAttr->context();
282     // check is it group selected for groups BOP
283     if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
284       // it is impossible by used results check which result is used in this group result,
285       // so check the results shapes is it in results of this document or not
286       FeaturePtr aSelFeature =
287         std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
288       if (!aSelFeature.get() || aSelFeature->results().empty())
289         continue;
290       GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
291
292       std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
293       for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
294         GeomShapePtr aResultShape = (*allResultsIter)->shape();
295
296         GeomAPI_Shape::ShapeType aType =
297           GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
298         GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
299         for(; aGroupResExp.more(); aGroupResExp.next()) {
300           if (aResultShape->isSubShape(aGroupResExp.current(), false))
301             return true; // at least one shape of the group is in the used results
302         }
303       }
304     }
305     ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
306     if (!aSelected.get()) { // try to get selected feature and all its results
307       FeaturePtr aContextFeature = anAttr->contextFeature();
308       if (aContextFeature.get() && !aContextFeature->results().empty()) {
309         const std::list<ResultPtr>& allResluts = aContextFeature->results();
310         std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
311         for(; aResIter != allResluts.cend(); aResIter++) {
312           if (aResIter->get() && theCashedResults.count(*aResIter))
313             return true;
314         }
315       }
316     } else if (aSelected.get() && theCashedResults.count(aSelected))
317       return true;
318   }
319   return false;
320 }
321
322 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
323 {
324   try {
325
326   std::string anError;
327   XAO::Xao aXao;
328
329   // author
330
331   std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
332   aXao.setAuthor(anAuthor);
333
334   // make shape for export from all results
335   std::list<GeomShapePtr> aShapes;
336   std::list<ResultPtr> aResults;
337   std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
338   std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
339
340   AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
341   bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
342   if (aIsSelection) { // a mode for export to geom result by result
343     for(int a = 0; a < aSelection->size(); a++) {
344       AttributeSelectionPtr anAttr = aSelection->value(a);
345       ResultPtr aBodyContext =
346         std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
347       if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
348         aResults.push_back(aBodyContext);
349         GeomShapePtr aShape = anAttr->value();
350         if (!aShape.get())
351           aShape = aBodyContext->shape();
352         aShapes.push_back(aShape);
353         if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
354           ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
355           DocumentPtr aPartDoc = aResPart->partDoc();
356           if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
357             std::string msg = "Can not export XAO for not loaded part";
358             Events_InfoMessage("ExportFeature", msg, this).send();
359             return;
360           } else {
361             aDocuments.push_back(aPartDoc);
362             aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
363           }
364         }
365       }
366     }
367   } else {
368     int aBodyCount = document()->size(ModelAPI_ResultBody::group());
369     for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
370       ResultBodyPtr aResultBody =
371           std::dynamic_pointer_cast<ModelAPI_ResultBody>(
372               document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
373       if (!aResultBody.get())
374         continue;
375       aShapes.push_back(aResultBody->shape());
376       aResults.push_back(aResultBody);
377     }
378   }
379   if (aShapes.empty()) {
380     setError("No shapes to export");
381     return;
382   }
383
384
385   GeomShapePtr aShape = (aShapes.size() == 1)
386       ? *aShapes.begin()
387       : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
388
389   SetShapeToXAO(aShape, &aXao, anError);
390
391   if (!anError.empty()) {
392     setError("An error occurred while exporting " + theFileName + ": " + anError);
393     return;
394   }
395
396   // geometry name
397   std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
398   if (aGeometryName.empty() && aResults.size() == 1) {
399     // get the name from the first result
400     ResultPtr aResultBody = *aResults.begin();
401     aGeometryName = aResultBody->data()->name();
402   }
403
404   aXao.getGeometry()->setName(aGeometryName);
405
406   std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
407
408   // iterate all documents used
409   if (aDocuments.empty())
410     aDocuments.push_back(document());
411   std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
412   for(; aDoc != aDocuments.end(); aDoc++) {
413     // groups
414     int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
415     for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
416       ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
417           (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
418       if (!aResultGroup.get() || !aResultGroup->shape().get())
419         continue;
420
421       FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
422
423       AttributeSelectionListPtr aSelectionList =
424           aGroupFeature->selectionList("group_list");
425       if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in result
426         continue;
427
428       // conversion of dimension
429       std::string aSelectionType = aSelectionList->selectionType();
430       GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
431       std::string aDimensionString =
432         ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
433       XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
434
435       XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
436                                             aResultGroup->data()->name());
437
438       try {
439         GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
440         for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
441           GeomShapePtr aGroupShape = aGroupResExplorer.current();
442           if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
443             aGroupShape->move(aDocTrsf[*aDoc]);
444           int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
445           if (aReferenceID == 0) // selected value does not found in the exported shape
446             continue;
447           std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
448           int anElementID =
449             aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
450           aXaoGroup->add(anElementID);
451         }
452       } catch (XAO::XAO_Exception& e) {
453         // LCOV_EXCL_START
454         std::string msg = "An error occurred while exporting group " +
455           aResultGroup->data()->name();
456         msg += ".\n";
457         msg += e.what();
458         msg += "\n";
459         msg += "=> skipping this group from XAO export.";
460         Events_InfoMessage("ExportFeature", msg, this).send();
461         aXao.removeGroup(aXaoGroup);
462         // LCOV_EXCL_STOP
463       }
464     }
465
466     // fields
467     int aFieldCount = (*aDoc)->size(ModelAPI_ResultField::group());
468     for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
469       ResultFieldPtr aResultField = std::dynamic_pointer_cast<ModelAPI_ResultField>(
470         (*aDoc)->object(ModelAPI_ResultField::group(), aFieldIndex));
471
472       FeaturePtr aFieldFeature = (*aDoc)->feature(aResultField);
473
474       AttributeSelectionListPtr aSelectionList =
475           aFieldFeature->selectionList("selected");
476       std::string aSelectionType = aSelectionList->selectionType();
477       bool isWholePart = aSelectionType == "part";
478       // skip field not used in results
479       if (!isWholePart && !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                                             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 aSelection = aSelectionList->value(aRow - 1);
519                 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->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           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 }