1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ExchangePlugin_ExportFeature.cpp
6 * Created on: May 14, 2015
10 #include <ExchangePlugin_ExportFeature.h>
12 #include <ExchangePlugin_Tools.h>
14 #include <GeomAlgoAPI_BREPExport.h>
15 #include <GeomAlgoAPI_STEPExport.h>
16 #include <GeomAlgoAPI_IGESExport.h>
18 #include <Config_Common.h>
19 #include <Config_PropManager.h>
21 #include <GeomAlgoAPI_CompoundBuilder.h>
23 #include <GeomAPI_Shape.h>
25 #include <ModelAPI_AttributeSelectionList.h>
26 #include <ModelAPI_AttributeString.h>
27 #include <ModelAPI_Data.h>
28 #include <ModelAPI_Document.h>
29 #include <ModelAPI_Object.h>
30 #include <ModelAPI_ResultBody.h>
32 #include <TCollection_AsciiString.hxx>
33 #include <TDF_Label.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <OSD_Path.hxx>
45 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
49 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
51 // TODO Auto-generated destructor stub
55 * Returns the unique kind of a feature
57 const std::string& ExchangePlugin_ExportFeature::getKind()
59 return ExchangePlugin_ExportFeature::ID();
63 * Request for initialization of data model of the feature: adding all attributes
65 void ExchangePlugin_ExportFeature::initAttributes()
67 data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
68 data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
69 data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
73 * Computes or recomputes the results
75 void ExchangePlugin_ExportFeature::execute()
77 AttributeStringPtr aFormatAttr =
78 this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
79 std::string aFormat = aFormatAttr->value();
83 AttributeStringPtr aFilePathAttr =
84 this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
85 std::string aFilePath = aFilePathAttr->value();
86 if (aFilePath.empty())
89 AttributeSelectionListPtr aSelectionListAttr =
90 this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
91 std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
92 for ( int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i ) {
93 aShapes.push_back(aSelectionListAttr->value(i)->value());
95 std::shared_ptr<GeomAPI_Shape> aShape =
96 GeomAlgoAPI_CompoundBuilder::compound(aShapes);
98 exportFile(aFilePath, aFormat, aShape);
101 std::list<std::string> ExchangePlugin_ExportFeature::getFormats() const
103 // This value is a copy of string_list attribute of format_choice in plugin-Exchange.xml
104 // XPath:plugin-Exchange.xml:string(//*[@id="format_choice"]/@string_list)
105 std::string aFormats = "BREP STEP IGES-5.1 IGES-5.3";
106 return ExchangePlugin_Tools::split(aFormats, ' ');
109 bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
110 const std::string& theFormat,
111 std::shared_ptr<GeomAPI_Shape> theShape)
113 // retrieve the file and plugin library names
114 TCollection_AsciiString aFileName(theFileName.c_str());
115 OSD_Path aPath(aFileName);
116 TCollection_AsciiString aFormatName(theFormat.c_str());
118 // Perform the export
119 TCollection_AsciiString anError;
120 TDF_Label anUnknownLabel = TDF_Label();
122 TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
123 bool aResult = false;
124 if (aFormatName == "BREP") {
125 aResult = BREPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
126 } else if (aFormatName == "STEP") {
127 aResult = STEPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
128 } else if (aFormatName.SubString(1, 4) == "IGES") {
129 aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
131 anError = TCollection_AsciiString("Unsupported format ") + aFormatName;
135 std::string aShapeError =
136 "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
137 setError(aShapeError);