]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make XAO export
authorspo <sergey.pokhodenko@opencascade.com>
Fri, 27 Nov 2015 13:31:17 +0000 (16:31 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Wed, 22 Jun 2016 11:06:01 +0000 (14:06 +0300)
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/export_widget.xml [new file with mode: 0644]
src/ExchangePlugin/plugin-Exchange.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_XAOImport.cpp

index 17c0489777d527a78cdb1c19aad7e3dcb88ff21b..53a8974fb4113097a978554fdbcc3b37030c4f11 100644 (file)
@@ -29,6 +29,7 @@ SET(PROJECT_SOURCES
 )
 
 SET(XML_RESOURCES
+    export_widget.xml
     plugin-Exchange.xml
 )
 
index f4ff3d3ad9fa976278264117b9b8005ad04e6db5..a341a001558d9372717de629895419307edff34c 100644 (file)
@@ -6,16 +6,23 @@
 
 #include <ExchangePlugin_ExportFeature.h>
 
-#include <ExchangePlugin_Tools.h>
+#include <algorithm>
+#include <iterator>
+#include <string>
+#ifdef _DEBUG
+#include <iostream>
+#include <ostream>
+#endif
+
+#include <Config_Common.h>
+#include <Config_PropManager.h>
 
 #include <GeomAlgoAPI_BREPExport.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_IGESExport.h>
 #include <GeomAlgoAPI_STEPExport.h>
 #include <GeomAlgoAPI_Tools.h>
-
-#include <Config_Common.h>
-#include <Config_PropManager.h>
+#include <GeomAlgoAPI_XAOExport.h>
 
 #include <GeomAPI_Shape.h>
 
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 
-#include <algorithm>
-#include <iterator>
-#include <string>
-#ifdef _DEBUG
-#include <iostream>
-#include <ostream>
-#endif
+#include <XAO_Xao.hxx>
+
+#include <ExchangePlugin_Tools.h>
 
 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
 {
@@ -43,22 +48,18 @@ 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::EXPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(), ModelAPI_AttributeString::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
 }
 
 /*
@@ -102,14 +103,13 @@ void ExchangePlugin_ExportFeature::execute()
   exportFile(aFilePath, aFormat, aShape);
 }
 
-bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
+void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
                                               const std::string& theFormat,
                                               std::shared_ptr<GeomAPI_Shape> theShape)
 {
-  // retrieve the file and plugin library names
   std::string aFormatName = theFormat;
 
-  if (theFormat.empty()) { // look at extension
+  if (aFormatName.empty()) { // get default format for the extension
     // ".brep" -> "BREP"
     std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
     if (anExtension == "BREP" || anExtension == "BRP") {
@@ -118,11 +118,18 @@ bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
       aFormatName = "STEP";
     } else if (anExtension == "IGES" || anExtension == "IGS") {
       aFormatName = "IGES-5.1";
+    } else if (anExtension == "XAO") {
+      aFormatName = "XAO";
     } else {
       aFormatName = anExtension;
     }
   }
 
+  if (aFormatName == "XAO") {
+    exportXAO(theFileName, theShape);
+    return;
+  }
+
   // Perform the export
   std::string anError;
   bool aResult = false;
@@ -133,15 +140,28 @@ bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
   } else if (aFormatName.substr(0, 4) == "IGES") {
     aResult = IGESExport(theFileName, aFormatName, theShape, anError);
   } else {
-    anError = "Unsupported format " + aFormatName;
+    anError = "Unsupported format: " + aFormatName;
   }
 
-  if (!aResult) {
-    std::string aShapeError =
-        "An error occurred while exporting " + theFileName + ": " + anError;
-    setError(aShapeError);
-    return false;
+  if (!anError.empty()) {
+    setError("An error occurred while exporting " + theFileName + ": " + anError);
+    return;
   }
+}
+
+void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName,
+                                             std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
+
+  XAO::Xao aXao(anAuthor, "1.0");
 
-  return true;
+  std::string anError;
+  XAOExport(theFileName, theShape, &aXao, anError);
+
+  if (!anError.empty()) {
+    setError("An error occurred while exporting " + theFileName + ": " + anError);
+    return;
+  }
 }
+
index 87727711e52951cf0e18d2a57dce317c1cc04a0e..9a71b05618ae5106b7e886a78b94b10a995c7618 100644 (file)
@@ -29,6 +29,12 @@ public:
     static const std::string MY_EXPORT_ID("Export");
     return MY_EXPORT_ID;
   }
+  /// attribute name for file format
+  inline static const std::string& EXPORT_TYPE_ID()
+  {
+    static const std::string MY_EXPORT_TYPE_ID("ExportType");
+    return MY_EXPORT_TYPE_ID;
+  }
   /// attribute name of file path
   inline static const std::string& FILE_PATH_ID()
   {
@@ -47,17 +53,26 @@ public:
     static const std::string MY_SELECTION_LIST_ID("selection_list");
     return MY_SELECTION_LIST_ID;
   }
+  /// attribute name of author for XAO format
+  inline static const std::string& XAO_AUTHOR_ID()
+  {
+    static const std::string MY_XAO_AUTHOR_ID("xao_author");
+    return MY_XAO_AUTHOR_ID;
+  }
   /// Default constructor
   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
   /// Default destructor
   EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ExportFeature();
 
+  /// Returns the unique kind of a feature
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    return ExchangePlugin_ExportFeature::ID();
+  }
+
   /// 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();
 
@@ -68,10 +83,14 @@ public:
   EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
 
 protected:
-  /// Performs the export of the file
-  EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName,
+  /// Performs export of the file
+  EXCHANGEPLUGIN_EXPORT void exportFile(const std::string& theFileName,
                                         const std::string& theFormat,
                                         std::shared_ptr<GeomAPI_Shape> theShape);
+
+  /// Performs export to XAO file
+  EXCHANGEPLUGIN_EXPORT void exportXAO(const std::string& theFileName,
+                                       std::shared_ptr<GeomAPI_Shape> theShape);
 };
 
 #endif /* EXPORT_EXPORTFEATURE_H_ */
index 143bad9ac47863521e1b3bb1c805ab28e69db8e5..8e50157e647fc1966aac1aaa37f2bf75f579c951 100644 (file)
@@ -19,8 +19,8 @@
 #include <GeomAlgoAPI_BREPImport.h>
 #include <GeomAlgoAPI_IGESImport.h>
 #include <GeomAlgoAPI_STEPImport.h>
-#include <GeomAlgoAPI_XAOImport.h>
 #include <GeomAlgoAPI_Tools.h>
+#include <GeomAlgoAPI_XAOImport.h>
 
 #include <GeomAPI_Shape.h>
 
@@ -104,7 +104,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   } else if (anExtension == "IGES" || anExtension == "IGS") {
     aGeomShape = IGESImport(theFileName, anExtension, anError);
   } else {
-    anError = "Cann't read files with extension: " + anExtension;
+    anError = "Unsupported format: " + anExtension;
   }
 
   // Check if shape is valid
@@ -133,10 +133,14 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
   }
 
   XAO::Geometry* aXaoGeometry = aXao.getGeometry();
-  data()->setName(aXaoGeometry->getName());
 
-  std::shared_ptr<ModelAPI_ResultBody> aResultBody = createResultBody(aGeomShape);
-  aResultBody->data()->setName(aXaoGeometry->getName());
+  // use the geometry name or the file name for the feature
+  std::string aBodyName = aXaoGeometry->getName().empty()
+      ? GeomAlgoAPI_Tools::File_Tools::name(theFileName)
+      : aXaoGeometry->getName();
+  data()->setName(aBodyName);
+
+  ResultBodyPtr aResultBody = createResultBody(aGeomShape);
   setResult(aResultBody);
 
   // Process groups
diff --git a/src/ExchangePlugin/export_widget.xml b/src/ExchangePlugin/export_widget.xml
new file mode 100644 (file)
index 0000000..1444d46
--- /dev/null
@@ -0,0 +1,33 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+  <switch id="ExportType">
+    <case id="Regular" title="BREP, STEP, IGES">
+      <export_file_selector id="file_path"
+                            type="save"
+                            title="Export file"
+                            path="">
+        <validator id="ExchangePlugin_ExportFormat"
+                   parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES-5.1,IGES|IGS:IGES-5.3" />
+      </export_file_selector>
+    </case>
+    <case id="XAO" title="XAO">
+      <export_file_selector id="file_path"
+                            type="save"
+                            title="Export file"
+                            path="">
+        <validator id="ExchangePlugin_ExportFormat"
+                   parameters="XAO:XAO" />
+      </export_file_selector>
+      <stringvalue id="xao_author"
+                   label="Author"
+                   placeholder="Please input the author">
+      </stringvalue>
+    </case>
+  </switch>
+  <multi_selector id="selection_list" 
+                  tooltip="Select a set of objects" 
+                  type_choice="Vertices Edges Faces Solids Objects">
+    <validator id="GeomValidators_Finite"/>
+  </multi_selector>
+</source>
index 05bc6c68d292f8aeb2a09243e8b407b6a46bad0f..f75602ca606def5f48acd00d394e94bc91d1cf52 100644 (file)
@@ -9,14 +9,8 @@
         </file_selector>
       </feature>
       <feature id="Export" title="Export" tooltip="Export to file" icon="icons/Exchange/export.png">
-        <export_file_selector id="file_path" type="save" title="Export file" path="">
-          <validator id="ExchangePlugin_ExportFormat" parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES-5.1,IGES|IGS:IGES-5.3,XAO:XAO" />
-        </export_file_selector>
-        <multi_selector id="selection_list" tooltip="Select a set of objects"
-                        type_choice="Vertices Edges Faces Solids Objects" use_choice="true">
-          <validator id="GeomValidators_Finite"/>
-        </multi_selector>
+        <source path="export_widget.xml" />
       </feature>
     </group>
   </workbench>
-</plugin>
\ No newline at end of file
+</plugin>
index b40fcd76e22d3a9b503409b216ca3c59f16f15f7..7d05409ac4146915be14970d60eed8df079296a8 100644 (file)
@@ -39,6 +39,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_WireBuilder.h
     GeomAlgoAPI_Sewing.h
     GeomAlgoAPI_ShapeBuilder.h
+    GeomAlgoAPI_XAOExport.h
     GeomAlgoAPI_XAOImport.h
 )
 
@@ -75,6 +76,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_WireBuilder.cpp
     GeomAlgoAPI_Sewing.cpp
     GeomAlgoAPI_ShapeBuilder.cpp
+    GeomAlgoAPI_XAOExport.cpp
     GeomAlgoAPI_XAOImport.cpp
 )
 
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.cpp
new file mode 100644 (file)
index 0000000..6bd8127
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:    GEOMALGOAPI_XAOExport.cpp
+// Created: Nov 27, 2015
+// Author:  Sergey POKHODENKO
+
+#include <GeomAlgoAPI_XAOExport.h>
+
+#include "GeomAlgoAPI_Tools.h"
+
+#include <TopoDS_Shape.hxx>
+
+#include <XAO_XaoExporter.hxx>
+#include <XAO_BrepGeometry.hxx>
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool XAOExport(const std::string& theFileName,
+               const std::shared_ptr<GeomAPI_Shape>& theShape,
+               XAO::Xao* theXao,
+               std::string& theError)
+{
+  #ifdef _DEBUG
+  std::cout << "Export XAO into file " << theFileName << std::endl;
+  #endif
+
+  if (theFileName.empty() || !theShape.get() || !theXao) {
+    theError = "An invalid argument.";
+    return false;
+  }
+
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  try {
+    XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
+    theXao->setGeometry(aGeometry);
+    aGeometry->setTopoDS_Shape(aShape);
+    XAO::XaoExporter::saveToFile(theXao, theFileName);
+  } catch (XAO::XAO_Exception& e) {
+    theError = e.what();
+    return false;
+  }
+  return true;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_XAOExport.h
new file mode 100644 (file)
index 0000000..5f535cf
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:    GEOMALGOAPI_XAOExport.h
+// Created: Nov 27, 2015
+// Author:  Sergey POKHODENKO
+
+#ifndef GEOMALGOAPI_XAOEXPORT_H_
+#define GEOMALGOAPI_XAOEXPORT_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <string>
+
+#include <GeomAPI_Shape.h>
+
+namespace XAO {
+class Xao;
+} // namespace XAO
+
+/// Implementation of the export XAO files algorithms
+GEOMALGOAPI_EXPORT
+bool XAOExport(const std::string& theFileName,
+               const std::shared_ptr<GeomAPI_Shape>& theShape,
+               XAO::Xao* theXao,
+               std::string& theError);
+
+#endif /* GEOMALGOAPI_XAOEXPORT_H_ */
index b0309c2739b565b51c555a4d373d8236ae3ee271..7647f71227d11368c6f34ad96ab366005e3c30e2 100644 (file)
@@ -6,8 +6,6 @@
 
 #include <GeomAlgoAPI_XAOImport.h>
 
-#include <cassert>
-
 #include <TopoDS_Shape.hxx>
 
 #include <XAO_XaoExporter.hxx>
@@ -22,11 +20,14 @@ std::shared_ptr<GeomAPI_Shape> XAOImport(const std::string& theFileName,
                                          std::string& theError,
                                          XAO::Xao* theXao)
 {
-  assert(theXao);
-
   #ifdef _DEBUG
   std::cout << "Import XAO from file " << theFileName << std::endl;
   #endif
+  if (theFileName.empty() || !theXao) {
+    theError = "An invalid argument.";
+    return std::shared_ptr<GeomAPI_Shape>();
+  }
+
   TopoDS_Shape aShape;
   try {
     if (XAO::XaoExporter::readFromFile(theFileName, theXao)) {