--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ExchangePlugin_ExportFeature.cpp
+ *
+ * Created on: Aug 28, 2014
+ * Author: sbh
+ */
+
+#include <ExchangePlugin_ExportFeature.h>
+//#include <GeomAlgoAPI_BREPExport.h>
+//#include <GeomAlgoAPI_STEPExport.h>
+//#include <GeomAlgoAPI_IGESExport.h>
+
+#include <GeomAPI_Shape.h>
+#include <Config_Common.h>
+#include <Config_PropManager.h>
+
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultBody.h>
+#include <TCollection_AsciiString.hxx>
+#include <TDF_Label.hxx>
+#include <TopoDS_Shape.hxx>
+#include <OSD_Path.hxx>
+
+#include <algorithm>
+#include <string>
+#ifdef _DEBUG
+#include <iostream>
+#include <ostream>
+#endif
+
+ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
+{
+}
+
+ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
+{
+ // TODO Auto-generated destructor stub
+}
+
+/*
+ * Returns the unique kind of a feature
+ */
+const std::string& ExchangePlugin_ExportFeature::getKind()
+{
+ return ExchangePlugin_ExportFeature::ID();
+}
+
+/*
+ * Request for initialization of data model of the feature: adding all attributes
+ */
+void ExchangePlugin_ExportFeature::initAttributes()
+{
+ data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
+}
+
+/*
+ * Computes or recomputes the results
+ */
+void ExchangePlugin_ExportFeature::execute()
+{
+ AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
+ data()->attribute(ExchangePlugin_ExportFeature::FILE_PATH_ID()));
+ std::string aFilePath = aFilePathAttr->value();
+ if(aFilePath.empty())
+ return;
+ exportFile(aFilePath);
+}
+
+bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName)
+{
+ // retrieve the file and plugin library names
+ TCollection_AsciiString aFileName (theFileName.c_str());
+ OSD_Path aPath(aFileName);
+ TCollection_AsciiString aFormatName = aPath.Extension();
+ // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
+ aFormatName = aFormatName.SubString(2, aFormatName.Length());
+ aFormatName.UpperCase();
+
+ // Perform the export
+ TCollection_AsciiString anError;
+ TDF_Label anUnknownLabel = TDF_Label();
+
+ TopoDS_Shape aShape;
+// if (aFormatName == "BREP") {
+// aShape = BREPExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
+// } else if (aFormatName == "STEP" || aFormatName == "STP") {
+// aShape = STEPExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
+// } else if (aFormatName == "IGES") {
+// aShape = IGESExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
+// }
+// // Check if shape is valid
+// if ( aShape.IsNull() ) {
+// const static std::string aShapeError =
+// "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
+// setError(aShapeError);
+// return false;
+// }
+//
+// // Pass the results into the model
+// std::string anObjectName = aPath.Name().ToCString();
+// data()->setName(anObjectName);
+// std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+// std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+// aGeomShape->setImpl(new TopoDS_Shape(aShape));
+//
+// //LoadNamingDS of the exported shape
+// loadNamingDS(aGeomShape, aResultBody);
+//
+// setResult(aResultBody);
+
+ return true;
+}
+
+//============================================================================
+void ExchangePlugin_ExportFeature::loadNamingDS(
+ std::shared_ptr<GeomAPI_Shape> theGeomShape,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody)
+{
+ //load result
+ theResultBody->store(theGeomShape);
+
+ int aTag(1);
+ std::string aNameMS = "Shape";
+ theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
+ //std::string aNameDE = "DiscEdges";
+ //theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag);
+ //std::string aNameDV = "DiscVertexes";
+ //theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef EXCHANGEPLUGIN_EXPORTFEATURE_H_
+#define EXCHANGEPLUGIN_EXPORTFEATURE_H_
+
+#include <ExchangePlugin.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
+
+#include <map>
+
+/**\class ExchangePlugin_ExportFeature
+ * \ingroup Plugins
+ * \brief Feature for export shapes to the external files in CAD formats.
+ *
+ * The set of supported formats is defined in the configuration file.
+ */
+class ExchangePlugin_ExportFeature : public ModelAPI_Feature
+{
+ public:
+ /// Extrusion kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_EXPORT_ID("Export");
+ return MY_EXPORT_ID;
+ }
+ /// attribute name of referenced face
+ inline static const std::string& FILE_PATH_ID()
+ {
+ static const std::string MY_FILE_PATH_ID("export_file_selector");
+ return MY_FILE_PATH_ID;
+ }
+ /// default constructor
+ EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
+ /// default destructor
+ EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ExportFeature();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Returns the unique kind of a feature
+ EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind();
+
+ /// Computes or recomputes the results
+ EXCHANGEPLUGIN_EXPORT virtual void execute();
+
+ /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+ EXCHANGEPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+ /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
+ MODELAPI_EXPORT virtual bool isPreviewNeeded() const { return false; }
+
+ protected:
+ /// Performs the export of the file
+ EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName);
+
+private:
+ /// Loads Naming data structure to the document
+ void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody);
+};
+
+#endif /* EXPORT_EXPORTFEATURE_H_ */