Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Add frame (Export icon)
authorSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 12 May 2015 08:27:38 +0000 (11:27 +0300)
committerSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 19 May 2015 07:58:15 +0000 (10:58 +0300)
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp [new file with mode: 0644]
src/ExchangePlugin/ExchangePlugin_ExportFeature.h [new file with mode: 0644]
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/ExchangePlugin/plugin-Exchange.xml
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/export.png [new file with mode: 0644]

index 6ed972b2bad265f1509011fc48b0be64f20c586c..dc2e3a9179499f8628d81bf74a5d39135d4e4b41 100644 (file)
@@ -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 (file)
index 0000000..7af9d2a
--- /dev/null
@@ -0,0 +1,134 @@
+// 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); 
+}
diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.h b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h
new file mode 100644 (file)
index 0000000..94160a8
--- /dev/null
@@ -0,0 +1,62 @@
+// 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_ */
index 673a6d9509955ac69ccd9298798b1ea936a7f8a7..c0f259f457510583d5cc3a76a3d68bb50dbd6c89 100644 (file)
@@ -56,7 +56,7 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature
 private:
   /// Loads Naming data structure to the document
   void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape, 
-                                       std::shared_ptr<ModelAPI_ResultBody> theResultBody);
+                    std::shared_ptr<ModelAPI_ResultBody> theResultBody);
 };
 
 #endif /* IMPORT_IMPORTFEATURE_H_ */
index 58b214b47c96522dcfcf5df123e5f27b7e1251fe..94a55fd8fee0e46ad8dcdde579f0d1f11e0cd4b6 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ExchangePlugin_Plugin.h>
 #include <ExchangePlugin_ImportFeature.h>
+#include <ExchangePlugin_ExportFeature.h>
 #include <ExchangePlugin_Validators.h>
 
 #include <Config_PropManager.h>
@@ -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();
index 56a87c04b127919bd4f184fd496c175bc3e4d64a..a389bcec15785cb781b0e3983b2291ea4f3fee59 100644 (file)
@@ -4,13 +4,15 @@
   <workbench id="Features" document="Part">
     <group id="Exchange">
       <feature id="Import" title="Import" tooltip="Import a file" icon=":icons/import.png">
-        <file_selector
-          id="import_file_selector"
-          title="Import file"
-          path="">
+        <file_selector id="import_file_selector" title="Import file" path="">
           <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP|STP:STEPImport,IGES:IGESImport" />
         </file_selector>
       </feature>
+      <feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
+        <file_selector id="export_file_selector" title="Export file" path="">
+          <validator id="ExchangePlugin_ExportFormat" parameters="BREgi tP:BREPExport,STEP|STP:STEPExport,IGES:IGESExport" />
+        </file_selector>
+      </feature>
     </group>
   </workbench>
 </plugin>
\ No newline at end of file
index 35d20306a26d72979620aae6d1c0f94ebf4f3d19..efc034cb5ee420db422506a8e656f3bf722389fb 100644 (file)
@@ -20,6 +20,7 @@
      <file>icons/revol.png</file>
      <file>icons/common.png</file>
      <file>icons/import.png</file>
+     <file>icons/export.png</file>
      <file>icons/line.png</file>
      <file>icons/sketch.png</file>
      <file>icons/hand_point.png</file>
diff --git a/src/PartSet/icons/export.png b/src/PartSet/icons/export.png
new file mode 100644 (file)
index 0000000..bd35270
Binary files /dev/null and b/src/PartSet/icons/export.png differ