1 // Copyright (C) 2014-2024 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ExchangePlugin_ExportFeature.h>
30 #include <Config_Common.h>
31 #include <Config_PropManager.h>
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>
41 #include <GeomAPI_IndexedMapOfShape.h>
42 #include <GeomAPI_Shape.h>
43 #include <GeomAPI_ShapeExplorer.h>
44 #include <GeomAPI_Trsf.h>
46 #include <Locale_Convert.h>
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_AttributeBoolean.h>
55 #include <ModelAPI_Data.h>
56 #include <ModelAPI_Document.h>
57 #include <ModelAPI_Object.h>
58 #include <ModelAPI_ResultBody.h>
59 #include <ModelAPI_ResultPart.h>
60 #include <ModelAPI_ResultGroup.h>
61 #include <ModelAPI_ResultField.h>
62 #include <ModelAPI_Session.h>
63 #include <ModelAPI_Validator.h>
64 #include <ModelAPI_Tools.h>
66 #include <Events_InfoMessage.h>
68 #include <XAO_Group.hxx>
69 #include <XAO_Field.hxx>
70 #include <XAO_Xao.hxx>
71 #include <XAO_Geometry.hxx>
73 #include <ExchangePlugin_Tools.h>
75 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
79 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
81 // TODO Auto-generated destructor stub
85 * Request for initialization of data model of the feature: adding all attributes
87 void ExchangePlugin_ExportFeature::initAttributes()
89 data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
90 ModelAPI_AttributeString::typeId());
91 data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(),
92 ModelAPI_AttributeString::typeId());
93 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
94 ModelAPI_AttributeString::typeId());
95 data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
96 ModelAPI_AttributeString::typeId());
97 data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
98 ModelAPI_AttributeSelectionList::typeId());
99 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
100 ModelAPI_AttributeString::typeId());
101 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
102 ModelAPI_AttributeString::typeId());
103 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(),
104 ModelAPI_AttributeSelectionList::typeId());
105 data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
106 ModelAPI_AttributeString::typeId());
107 data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
108 ModelAPI_AttributeSelection::typeId());
109 data()->addAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
110 ModelAPI_AttributeString::typeId());
111 data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(),
112 ModelAPI_AttributeDouble::typeId());
114 double defelection = Config_PropManager::real("Visualization", "body_deflection");
115 real(ExchangePlugin_ExportFeature::STL_RELATIVE())->setValue(defelection);
117 data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
118 ModelAPI_AttributeDouble::typeId());
119 data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
120 ModelAPI_AttributeString::typeId());
122 // export to memory buffer (implemented for XAO format only)
123 data()->addAttribute(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID(),
124 ModelAPI_AttributeString::typeId());
126 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_PATH_ID(),
127 ModelAPI_AttributeString::typeId());
128 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_SEPARATE_ID(),
129 ModelAPI_AttributeBoolean::typeId());
131 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
132 ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
133 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
134 ExchangePlugin_ExportFeature::STL_FILE_PATH_ID());
135 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
136 ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
137 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
138 ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
139 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
140 ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
141 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
142 ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID());
143 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
144 ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_PATH_ID());
145 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
146 ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_SEPARATE_ID());
148 // to support previous version of document, move the selection list
149 // if the type of export operation is XAO
150 AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
151 if (aTypeAttr->isInitialized() &&
152 (aTypeAttr->value() == "XAO" || aTypeAttr->value() == "XAOMem")) {
153 bool aWasBlocked = data()->blockSendAttributeUpdated(true, false);
154 AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
155 AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
156 if (aSelList->size() > 0 && aXAOSelList->size() == 0)
157 aSelList->copyTo(aXAOSelList);
159 data()->blockSendAttributeUpdated(aWasBlocked, false);
163 void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
165 if (theID == XAO_FILE_PATH_ID()) {
166 string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
167 string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
169 else if (theID == STL_FILE_PATH_ID()) {
170 string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
171 string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value());
176 * Computes or recomputes the results
178 void ExchangePlugin_ExportFeature::execute()
180 AttributeStringPtr aFormatAttr =
181 this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
182 std::string aFormat = aFormatAttr->value();
184 bool isMemoryExport = false;
185 AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
186 if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAOMem")
187 isMemoryExport = true;
189 AttributeStringPtr aFilePathAttr =
190 this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
191 std::string aFilePath = aFilePathAttr->value();
192 if (aFilePath.empty() && !isMemoryExport)
195 exportFile(aFilePath, aFormat, isMemoryExport);
198 void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
199 const std::string& theFormat,
200 const bool isMemoryExport)
202 std::string aFormatName = theFormat;
204 if (aFormatName.empty()) { // get default format for the extension
205 if (isMemoryExport) return;
208 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
209 if (anExtension == "BREP" || anExtension == "BRP") {
210 aFormatName = "BREP";
211 } else if (anExtension == "STEP" || anExtension == "STP") {
212 aFormatName = "STEP";
213 } else if (anExtension == "IGES" || anExtension == "IGS") {
214 aFormatName = "IGES-5.1";
216 aFormatName = anExtension;
220 if (aFormatName == "XAO") {
221 exportXAO(theFileName, isMemoryExport);
223 } else if (aFormatName == "STL") {
224 exportSTL(theFileName);
228 // make shape for export from selected shapes
229 AttributeSelectionListPtr aSelectionListAttr =
230 this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
231 std::list<GeomShapePtr> aShapes;
232 std::list<ResultPtr> aContexts;
233 for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
234 AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
236 /// do not export pictures
237 ResultPtr aBodyContext =
238 std::dynamic_pointer_cast<ModelAPI_Result>(anAttrSelection->context());
239 if (aBodyContext.get() && aBodyContext->hasTexture())
242 std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
243 if (aCurShape.get() == NULL)
244 aCurShape = anAttrSelection->context()->shape();
245 if (aCurShape.get() != NULL)
247 aShapes.push_back(aCurShape);
248 aContexts.push_back(anAttrSelection->context());
252 // Store compound if we have more than one shape.
253 std::shared_ptr<GeomAPI_Shape> aShape =
254 aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
256 // Perform the export
258 bool aResult = false;
259 if (aFormatName == "BREP") {
260 aResult = BREPExport(theFileName, aFormatName, aShape, anError);
261 } else if (aFormatName == "STEP") {
262 aResult = STEPExport(theFileName, aShapes, aContexts, anError);
263 } else if (aFormatName.substr(0, 4) == "IGES") {
264 aResult = IGESExport(theFileName, aFormatName, aShape, anError);
266 anError = "Unsupported format: " + aFormatName;
269 if (!aResult || !anError.empty()) {
270 setError("An error occurred while exporting " + theFileName + ": " + anError);
275 /// Returns XAO string by the value from the table
276 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
277 const ModelAPI_AttributeTables::ValueType& theType)
279 std::ostringstream aStr; // the resulting string value
281 case ModelAPI_AttributeTables::BOOLEAN:
282 aStr<<(theVal.myBool ? "true" : "false");
284 case ModelAPI_AttributeTables::INTEGER:
287 case ModelAPI_AttributeTables::DOUBLE:
288 aStr<<theVal.myDouble;
290 case ModelAPI_AttributeTables::STRING:
297 void ExchangePlugin_ExportFeature::exportSTL(const std::string& theFileName)
300 AttributeSelectionPtr aSelection = selection(STL_OBJECT_SELECTED());
301 GeomShapePtr aShape = aSelection->value();
303 aShape = aSelection->context()->shape();
306 // Get relative value and percent flag.
308 bool anIsRelative = false;
309 bool anIsASCII = false;
311 if (string(STL_DEFLECTION_TYPE())->value() == STL_DEFLECTION_TYPE_RELATIVE()) {
312 aValue = real(STL_RELATIVE())->value();
315 aValue = real(STL_ABSOLUTE())->value();
318 if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) {
321 // Perform the export
323 bool aResult = false;
325 aResult = STLExport(theFileName,
332 if (!aResult || !anError.empty()) {
333 setError("An error occurred while exporting " + theFileName + ": " + anError);
339 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName,
340 const bool isMemoryExport)
349 std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
350 aXao.setAuthor(anAuthor);
352 // make shape for export from all results
353 std::list<GeomShapePtr> aShapes;
354 std::list<ResultPtr> aResults;
355 std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
356 std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
358 bool anExCludedIsImage = false;
359 AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
360 bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
361 if (aIsSelection) { // a mode for export to geom result by result
362 for (int a = 0; a < aSelection->size(); a++) {
363 AttributeSelectionPtr anAttr = aSelection->value(a);
364 ResultPtr aBodyContext =
365 std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
366 if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
367 /// do not export pictures
368 if (aBodyContext->hasTexture()){
369 anExCludedIsImage = true;
372 aResults.push_back(aBodyContext);
373 GeomShapePtr aShape = anAttr->value();
375 aShape = aBodyContext->shape();
376 aShapes.push_back(aShape);
377 if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
378 ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
379 DocumentPtr aPartDoc = aResPart->partDoc();
380 if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
381 std::string msg = "Can not export XAO for not loaded part";
382 Events_InfoMessage("ExportFeature", msg, this).send();
385 aDocuments.push_back(aPartDoc);
386 aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
392 int aBodyCount = document()->size(ModelAPI_ResultBody::group());
393 for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
394 ResultBodyPtr aResultBody =
395 std::dynamic_pointer_cast<ModelAPI_ResultBody>(
396 document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
397 if (!aResultBody.get())
399 aShapes.push_back(aResultBody->shape());
400 aResults.push_back(aResultBody);
403 if (aShapes.empty()) {
404 if(!anExCludedIsImage)
405 setError("No shapes to export");
410 GeomShapePtr aShape = (aShapes.size() == 1)
412 : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
414 SetShapeToXAO(aShape, &aXao, anError);
416 if (!anError.empty()) {
417 setError("An error occurred while exporting " + theFileName + ": " + anError);
422 std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
423 if (aGeometryName.empty() && aResults.size() == 1) {
424 // get the name from the first result
425 ResultPtr aResultBody = *aResults.begin();
426 aGeometryName = Locale::Convert::toString(aResultBody->data()->name());
427 if (isMemoryExport) {
429 string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->setValue(aGeometryName);
431 //data()->setName(Locale::Convert::toWString(aGeometryName));
435 aXao.getGeometry()->setName(aGeometryName);
437 std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
439 // [bos #38360] [CEA] improve performances of exportXAO and PublishToStudy
440 GeomAPI_IndexedMapOfShape aSubShapesMap;
441 bool isSubShapesMap = false; // we will init it only if required (for performance reason)
443 // iterate all documents used
444 if (aDocuments.empty())
445 aDocuments.push_back(document());
446 std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
447 for(; aDoc != aDocuments.end(); aDoc++) {
449 int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
450 for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
451 ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
452 (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
453 if (!aResultGroup.get() || !aResultGroup->shape().get())
456 FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
458 AttributeSelectionListPtr aSelectionList =
459 aGroupFeature->selectionList("group_list");
460 if (!ModelAPI_Tools::isInResults(aSelectionList,
462 allResultsCashed))// skip group not used in result
465 // conversion of dimension
466 std::string aSelectionType = aSelectionList->selectionType();
467 GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
468 std::string aDimensionString =
469 ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
470 XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
472 XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
473 Locale::Convert::toString(aResultGroup->data()->name()));
476 GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
477 for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
478 GeomShapePtr aGroupShape = aGroupResExplorer.current();
479 if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
480 aGroupShape->move(aDocTrsf[*aDoc]);
482 if (!isSubShapesMap) {
483 aSubShapesMap.MapShapes(aShape);
484 isSubShapesMap = true;
486 int aReferenceID = aSubShapesMap.FindIndexEqualLocations(aGroupShape);
487 if (aReferenceID == 0) // selected value does not found in the exported shape
489 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
491 aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
492 aXaoGroup->add(anElementID);
494 } catch (XAO::XAO_Exception& e) {
496 std::string msg = "An error occurred while exporting group " +
497 Locale::Convert::toString(aResultGroup->data()->name());
501 msg += "=> skipping this group from XAO export.";
502 Events_InfoMessage("ExportFeature", msg, this).send();
503 aXao.removeGroup(aXaoGroup);
509 int aFieldCount = (*aDoc)->size(ModelAPI_ResultField::group());
510 for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
511 ResultFieldPtr aResultField = std::dynamic_pointer_cast<ModelAPI_ResultField>(
512 (*aDoc)->object(ModelAPI_ResultField::group(), aFieldIndex));
514 FeaturePtr aFieldFeature = (*aDoc)->feature(aResultField);
516 AttributeSelectionListPtr aSelectionList =
517 aFieldFeature->selectionList("selected");
518 std::string aSelectionType = aSelectionList->selectionType();
519 bool isWholePart = aSelectionType == "part";
520 // skip field not used in results
522 !ModelAPI_Tools::isInResults(aSelectionList, aResults, allResultsCashed))
525 // conversion of dimension
526 std::string aDimensionString =
527 ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
528 XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
529 // get tables and their type
530 std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
531 std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
532 XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
534 XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
535 Locale::Convert::toString(aResultField->data()->name()));
539 // set components names
540 AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
541 for(int aComp = 0; aComp < aComponents->size(); aComp++) {
542 std::string aName = aComponents->value(aComp);
543 aXaoField->setComponentName(aComp, aName);
546 AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
547 for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
548 XAO::Step* aStep = aXaoField->addNewStep(aStepIndex + 1);
549 aStep->setStep(aStepIndex + 1);
550 int aStampIndex = aStamps->value(aStepIndex);
551 aStep->setStamp(aStampIndex);
552 int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
553 int aNumComps = aTables->columns();
554 std::set<int> aFilledIDs; // to fill the rest by defaults
555 // omit default values first row
556 for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
557 for(int aCol = 0; aCol < aNumComps; aCol++) {
560 // element index actually is the ID of the selection
561 AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1);
562 if (!isSubShapesMap) {
563 aSubShapesMap.MapShapes(aShape);
564 isSubShapesMap = true;
566 int aReferenceID = aSubShapesMap.FindIndexEqualLocations(aSel->value());
567 if (aReferenceID == 0) // selected value does not found in the exported shape
570 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
571 anElementID = aXao.getGeometry()->
572 getElementIndexByReference(aFieldDimension, aReferenceString);
575 ModelAPI_AttributeTables::Value aVal = aTables->value(
576 isWholePart ? 0 : aRow, aCol, aStepIndex);
577 std::string aStrVal = valToString(aVal, aTables->type());
578 aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
579 aFilledIDs.insert(anElementID);
582 if (!isWholePart) { // fill the rest values by default ones
583 XAO::GeometricElementList::iterator allElem =
584 aXao.getGeometry()->begin(aFieldDimension);
585 for(; allElem != aXao.getGeometry()->end(aFieldDimension); allElem++) {
586 if (aFilledIDs.find(allElem->first) != aFilledIDs.end())
588 for(int aCol = 0; aCol < aNumComps; aCol++) {
590 ModelAPI_AttributeTables::Value aVal = aTables->value(0, aCol, aStepIndex);
591 std::string aStrVal = valToString(aVal, aTables->type());
592 aStep->setStringValue(allElem->first, aCol, aStrVal);
597 } catch (XAO::XAO_Exception& e) {
599 std::string msg = "An error occurred while exporting field " +
600 Locale::Convert::toString(aResultField->data()->name());
604 msg += "=> skipping this field from XAO export.";
605 Events_InfoMessage("ExportFeature", msg, this).send();
606 aXao.removeField(aXaoField);
613 if (isMemoryExport) {
614 string(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID())->setValue(XAOExportMem(&aXao, anError));
617 std::string aShapeFile ("");
618 AttributeBooleanPtr aShapeSeparateAttr = boolean(XAO_SHAPE_FILE_SEPARATE_ID());
619 if (aShapeSeparateAttr->isInitialized() &&
620 aShapeSeparateAttr->value() == true) {
621 aShapeFile = theFileName + ".brep";
624 AttributeStringPtr aShapeFileAttr = string(XAO_SHAPE_FILE_PATH_ID());
625 if (aShapeFileAttr->isInitialized())
626 aShapeFile = aShapeFileAttr->value();
629 XAOExport(theFileName, &aXao, anError, aShapeFile);
632 if (!anError.empty()) {
633 setError("An error occurred while exporting " + theFileName + ": " + anError);
638 } catch (XAO::XAO_Exception& e) {
639 std::string anError = e.what();
640 setError("An error occurred while exporting " + theFileName + ": " + anError);
646 bool ExchangePlugin_ExportFeature::isMacro() const
648 if (!data().get() || !data()->isValid())
650 ExchangePlugin_ExportFeature* aThis = ((ExchangePlugin_ExportFeature*)(this));
651 AttributeStringPtr aFormatAttr = aThis->string(FILE_FORMAT_ID());
652 std::string aFormat(aFormatAttr.get() ? aFormatAttr->value() : "");
654 if (aFormat.empty()) { // get default format for the extension
655 AttributeStringPtr aFilePathAttr = aThis->string(FILE_PATH_ID());
656 std::string aFilePath = aFilePathAttr->value();
657 if (!aFilePath.empty()) {
658 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
659 aFormat = anExtension;
663 if (aFormat == "XAO") { // on export to GEOM the selection attribute is filled - this is
664 // an exceptional case where export to XAO feature must be kept
665 AttributeSelectionListPtr aList = aThis->selectionList(XAO_SELECTION_LIST_ID());
666 return !aList->isInitialized() || aList->size() == 0;