From: Sergey POKHODENKO Date: Tue, 12 May 2015 08:27:38 +0000 (+0300) Subject: Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Add frame (Export icon) X-Git-Tag: V_1.2.0~145^2~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bb0072beffb5e17b0d2a02b326dc6402b9f5fb93;p=modules%2Fshaper.git Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Add frame (Export icon) --- diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index 6ed972b2b..dc2e3a917 100644 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -14,12 +14,14 @@ SET(PROJECT_HEADERS ExchangePlugin.h ExchangePlugin_Plugin.h ExchangePlugin_ImportFeature.h + ExchangePlugin_ExportFeature.h ExchangePlugin_Validators.h ) SET(PROJECT_SOURCES ExchangePlugin_Plugin.cpp ExchangePlugin_ImportFeature.cpp + ExchangePlugin_ExportFeature.cpp ExchangePlugin_Validators.cpp ) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp new file mode 100644 index 000000000..7af9d2af8 --- /dev/null +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -0,0 +1,134 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +/* + * ExchangePlugin_ExportFeature.cpp + * + * Created on: Aug 28, 2014 + * Author: sbh + */ + +#include +//#include +//#include +//#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#ifdef _DEBUG +#include +#include +#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( + 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 aResultBody = document()->createBody(data()); +// std::shared_ptr 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 theGeomShape, + std::shared_ptr 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); +} diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.h b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h new file mode 100644 index 000000000..94160a860 --- /dev/null +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h @@ -0,0 +1,62 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef EXCHANGEPLUGIN_EXPORTFEATURE_H_ +#define EXCHANGEPLUGIN_EXPORTFEATURE_H_ + +#include +#include +#include + +#include + +/**\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 theGeomShape, + std::shared_ptr theResultBody); +}; + +#endif /* EXPORT_EXPORTFEATURE_H_ */ diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h index 673a6d950..c0f259f45 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h @@ -56,7 +56,7 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature private: /// Loads Naming data structure to the document void loadNamingDS(std::shared_ptr theGeomShape, - std::shared_ptr theResultBody); + std::shared_ptr theResultBody); }; #endif /* IMPORT_IMPORTFEATURE_H_ */ diff --git a/src/ExchangePlugin/ExchangePlugin_Plugin.cpp b/src/ExchangePlugin/ExchangePlugin_Plugin.cpp index 58b214b47..94a55fd8f 100644 --- a/src/ExchangePlugin/ExchangePlugin_Plugin.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Plugin.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -38,6 +39,9 @@ FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID) { if (theFeatureID == ExchangePlugin_ImportFeature::ID()) { return FeaturePtr(new ExchangePlugin_ImportFeature); + } else + if (theFeatureID == ExchangePlugin_ExportFeature::ID()) { + return FeaturePtr(new ExchangePlugin_ExportFeature); } // feature of such kind is not found return FeaturePtr(); diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index 56a87c04b..a389bcec1 100644 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -4,13 +4,15 @@ - + + + + + + \ No newline at end of file diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 35d20306a..efc034cb5 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -20,6 +20,7 @@ icons/revol.png icons/common.png icons/import.png + icons/export.png icons/line.png icons/sketch.png icons/hand_point.png diff --git a/src/PartSet/icons/export.png b/src/PartSet/icons/export.png new file mode 100644 index 000000000..bd35270f4 Binary files /dev/null and b/src/PartSet/icons/export.png differ