# High Level C++/Python API
ADD_SUBDIRECTORY (src/ModelHighAPI)
ADD_SUBDIRECTORY (src/ConstructionAPI)
+ADD_SUBDIRECTORY (src/ExchangeAPI)
IF(${HAVE_SALOME})
ADD_SUBDIRECTORY (src/SHAPERGUI)
--- /dev/null
+## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+INCLUDE(Common)
+
+SET(PROJECT_HEADERS
+ ExchangeAPI.h
+ ExchangeAPI_Export.h
+ ExchangeAPI_Import.h
+)
+
+SET(PROJECT_SOURCES
+ ExchangeAPI_Export.cpp
+ ExchangeAPI_Import.cpp
+)
+
+SET(PROJECT_LIBRARIES
+ ModelAPI
+ ModelHighAPI
+)
+
+INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/Events
+ ${PROJECT_SOURCE_DIR}/src/ModelAPI
+ ${PROJECT_SOURCE_DIR}/src/ModelHighAPI
+)
+
+# Plugin headers dependency
+INCLUDE_DIRECTORIES(
+ # TODO(spo): modify ConstructionPlugin headers to remove dependency on GeomAPI headers
+ ${PROJECT_SOURCE_DIR}/src/GeomAPI
+ ${PROJECT_SOURCE_DIR}/src/ExchangePlugin
+)
+
+#TODO(spo): is ${CAS_DEFINITIONS} necessary?
+ADD_DEFINITIONS(-DCONSTRUCTIONAPI_EXPORTS ${CAS_DEFINITIONS})
+ADD_LIBRARY(ExchangeAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+TARGET_LINK_LIBRARIES(ExchangeAPI ${PROJECT_LIBRARIES})
+
+# SWIG wrapper
+
+INCLUDE(PythonAPI)
+
+SET_SOURCE_FILES_PROPERTIES(ExchangeAPI.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(ExchangeAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+
+#TODO(spo): is ModelAPI necessary or it could be received by INTERFACE_ (may require modern CMake)?
+SET(SWIG_LINK_LIBRARIES
+ ExchangeAPI
+ ModelHighAPI
+ ModelAPI
+ ${PYTHON_LIBRARIES}
+)
+
+SET(SWIG_MODULE_ExchangeAPI_EXTRA_DEPS ${SWIG_MODULE_ExchangeAPI_EXTRA_DEPS}
+ ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i
+ doxyhelp.i
+ ${PROJECT_HEADERS}
+)
+
+SWIG_ADD_MODULE(ExchangeAPI python ExchangeAPI.i ${PROJECT_HEADERS})
+SWIG_LINK_LIBRARIES(ExchangeAPI ${SWIG_LINK_LIBRARIES})
+
+IF(WIN32)
+ SET_TARGET_PROPERTIES(_ExchangeAPI PROPERTIES DEBUG_OUTPUT_NAME _ExchangeAPI_d)
+ENDIF(WIN32)
+
+INSTALL(TARGETS _ExchangeAPI DESTINATION ${SHAPER_INSTALL_SWIG})
+INSTALL(TARGETS ExchangeAPI DESTINATION ${SHAPER_INSTALL_BIN})
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ExchangeAPI.py DESTINATION ${SHAPER_INSTALL_SWIG})
+
+# Tests
+
+INCLUDE(UnitTest)
+
+ADD_UNIT_TESTS(
+ TestExchange.py
+)
+
+# ADD_SUBDIRECTORY (Test)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef EXCHANGEAPI_H
+#define EXCHANGEAPI_H
+
+#if defined EXCHANGEAPI_EXPORTS
+#if defined WIN32
+#define EXCHANGEAPI_EXPORT __declspec( dllexport )
+#else
+#define EXCHANGEAPI_EXPORT
+#endif
+#else
+#if defined WIN32
+#define EXCHANGEAPI_EXPORT __declspec( dllimport )
+#else
+#define EXCHANGEAPI_EXPORT
+#endif
+#endif
+
+#endif
--- /dev/null
+/* ExchangeAPI.i */
+
+%module ExchangeAPI
+
+%{
+ #include "ExchangeAPI_swig.h"
+%}
+
+%include "doxyhelp.i"
+
+// import other modules
+%import "ModelHighAPI.i"
+
+// to avoid error on this
+#define EXCHANGEAPI_EXPORT
+
+// standard definitions
+%include "typemaps.i"
+%include "std_list.i"
+%include "std_shared_ptr.i"
+
+// shared pointers
+%shared_ptr(ExchangeAPI_Export)
+%shared_ptr(ExchangeAPI_Import)
+
+// all supported interfaces
+%include "ExchangeAPI_Export.h"
+%include "ExchangeAPI_Import.h"
--- /dev/null
+// Name : ExchangeAPI_Export.cpp
+// Purpose:
+//
+// History:
+// 07/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ExchangeAPI_Export.h"
+
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+ExchangeAPI_Export::ExchangeAPI_Export(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+ExchangeAPI_Export::ExchangeAPI_Export(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theFilePath,
+ const std::string & theFileFormat,
+ const std::list<ModelHighAPI_Selection> & theSelectionList)
+: ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ setFilePath(theFilePath);
+ setFileFormat(theFileFormat);
+ setSelectionList(theSelectionList);
+ execute();
+ }
+}
+
+ExchangeAPI_Export::~ExchangeAPI_Export()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
+void ExchangeAPI_Export::setFilePath(const std::string & theFilePath)
+{
+ fillAttribute(theFilePath, myfilePath);
+}
+
+void ExchangeAPI_Export::setFileFormat(const std::string & theFileFormat)
+{
+ fillAttribute(theFileFormat, myfileFormat);
+}
+
+void ExchangeAPI_Export::setSelectionList(
+ const std::list<ModelHighAPI_Selection> & theSelectionList)
+{
+ fillAttribute(theSelectionList, myselectionList);
+}
+
+//--------------------------------------------------------------------------------------
+ExportPtr exportToFile(
+ const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const std::string & theFileFormat,
+ const std::list<ModelHighAPI_Selection> & theSelectionList)
+{
+ // TODO(spo): check that thePart is not empty
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ExchangeAPI_Export::ID());
+ return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theFileFormat, theSelectionList));
+}
--- /dev/null
+// Name : ExchangeAPI_Export.h
+// Purpose:
+//
+// History:
+// 07/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_
+#define SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_
+
+//--------------------------------------------------------------------------------------
+#include "ExchangeAPI.h"
+
+#include <list>
+#include <string>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+#include <ExchangePlugin_ExportFeature.h>
+//--------------------------------------------------------------------------------------
+class ModelHighAPI_Selection;
+//--------------------------------------------------------------------------------------
+/**\class ExchangeAPI_Export
+ * \ingroup CPPHighAPI
+ * \brief Interface for Export feature
+ */
+class ExchangeAPI_Export : public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values
+ EXCHANGEAPI_EXPORT
+ explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+ /// Constructor with values
+ EXCHANGEAPI_EXPORT
+ ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theFilePath,
+ const std::string & theFileFormat,
+ const std::list<ModelHighAPI_Selection> & theSelectionList);
+ /// Destructor
+ EXCHANGEAPI_EXPORT
+ virtual ~ExchangeAPI_Export();
+
+ INTERFACE_3(ExchangePlugin_ExportFeature::ID(),
+ filePath, ExchangePlugin_ExportFeature::FILE_PATH_ID(), String, /** File path */,
+ fileFormat, ExchangePlugin_ExportFeature::FILE_FORMAT_ID(), String, /** File format */,
+ selectionList, ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), SelectionList, /** Selection list */
+ )
+
+ /// Set file path (without execute)
+ EXCHANGEAPI_EXPORT
+ void setFilePath(const std::string & theFilePath);
+
+ /// Set file format (without execute)
+ EXCHANGEAPI_EXPORT
+ void setFileFormat(const std::string & theFileFormat);
+
+
+ /// Set selection list (without execute)
+ EXCHANGEAPI_EXPORT
+ void setSelectionList(const std::list<ModelHighAPI_Selection> & theSelectionList);
+};
+
+//! Pointer on Export object
+typedef std::shared_ptr<ExchangeAPI_Export> ExportPtr;
+
+/**\ingroup CPPHighAPI
+ * \brief Create Export feature
+ */
+EXCHANGEAPI_EXPORT
+ExportPtr exportToFile(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath,
+ const std::string & theFileFormat,
+ const std::list<ModelHighAPI_Selection> & theSelectionList);
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_ */
--- /dev/null
+// Name : ExchangeAPI_Import.cpp
+// Purpose:
+//
+// History:
+// 07/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ExchangeAPI_Import.h"
+
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+ExchangeAPI_Import::ExchangeAPI_Import(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+ExchangeAPI_Import::ExchangeAPI_Import(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theFilePath)
+: ModelHighAPI_Interface(theFeature)
+{
+ if (initialize())
+ setFilePath(theFilePath);
+}
+
+ExchangeAPI_Import::~ExchangeAPI_Import()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
+void ExchangeAPI_Import::setFilePath(const std::string & theFilePath)
+{
+ fillAttribute(theFilePath, myfilePath);
+
+ execute();
+}
+
+//--------------------------------------------------------------------------------------
+// TODO(spo): make add* as static functions of the class
+ImportPtr addImport(
+ const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath)
+{
+ // TODO(spo): check that thePart is not empty
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ExchangeAPI_Import::ID());
+ return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath));
+}
--- /dev/null
+// Name : ExchangeAPI_Import.h
+// Purpose:
+//
+// History:
+// 07/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_EXCHANGEAPI_EXCHANGEAPI_IMPORT_H_
+#define SRC_EXCHANGEAPI_EXCHANGEAPI_IMPORT_H_
+
+//--------------------------------------------------------------------------------------
+#include "ExchangeAPI.h"
+
+#include <string>
+
+#include <ExchangePlugin_ImportFeature.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+//--------------------------------------------------------------------------------------
+/**\class ExchangeAPI_Import
+ * \ingroup CPPHighAPI
+ * \brief Interface for Import feature
+ */
+class ExchangeAPI_Import : public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values
+ EXCHANGEAPI_EXPORT
+ explicit ExchangeAPI_Import(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+ /// Constructor with values
+ EXCHANGEAPI_EXPORT
+ ExchangeAPI_Import(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theFilePath);
+ /// Destructor
+ EXCHANGEAPI_EXPORT
+ virtual ~ExchangeAPI_Import();
+
+ INTERFACE_1(ExchangePlugin_ImportFeature::ID(),
+ filePath, ExchangePlugin_ImportFeature::FILE_PATH_ID(), String, /** File path */)
+
+ /// Set point values
+ EXCHANGEAPI_EXPORT
+ void setFilePath(const std::string & theFilePath);
+};
+
+//! Importer on Import object
+typedef std::shared_ptr<ExchangeAPI_Import> ImportPtr;
+
+/**\ingroup CPPHighAPI
+ * \brief Create Import feature
+ */
+EXCHANGEAPI_EXPORT
+ImportPtr addImport(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const std::string & theFilePath);
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_IMPORT_H_ */
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ExchangeAPI_swig.h
+// Created: 07/06/16
+// Author: Sergey POKHODENKO
+
+#ifndef SRC_EXCHANGEAPI_EXCHANGEAPI_SWIG_H_
+#define SRC_EXCHANGEAPI_EXCHANGEAPI_SWIG_H_
+
+ #include <ModelHighAPI_swig.h>
+ #include "ExchangeAPI.h"
+
+ #include "ExchangeAPI_Export.h"
+ #include "ExchangeAPI_Import.h"
+
+#endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_SWIG_H_ */
--- /dev/null
+import unittest
+
+import ModelAPI
+import ExchangeAPI
+
+class PointTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.session = ModelAPI.ModelAPI_Session.get()
+ self.doc = self.session.moduleDocument()
+
+ def tearDown(self):
+ self.session.closeAll()
+
+ def test_addImport(self):
+ self.session.startOperation()
+ self.feature = ExchangeAPI.addImport(self.doc, "file_path")
+ self.session.finishOperation()
+
+ def test_addExport(self):
+ self.session.startOperation()
+ self.feature = ExchangeAPI.exportToFile(self.doc, "file_path", "file_format", [])
+ self.session.finishOperation()
+
+if __name__ == "__main__":
+ unittest.main()
ModelHighAPI_Interface.h
ModelHighAPI_Macro.h
ModelHighAPI_Selection.h
+ ModelHighAPI_Tools.h
)
SET(PROJECT_SOURCES
ModelHighAPI_Double.cpp
ModelHighAPI_Interface.cpp
ModelHighAPI_Selection.cpp
+ ModelHighAPI_Tools.cpp
)
SET(PROJECT_LIBRARIES
// standard definitions
%include "typemaps.i"
+%include "std_list.i"
%include "std_string.i"
%include "std_shared_ptr.i"
%include "ModelHighAPI_Double.h"
%include "ModelHighAPI_Interface.h"
%include "ModelHighAPI_Macro.h"
+%include "ModelHighAPI_Selection.h"
+%include "ModelHighAPI_Tools.h"
+
+// std::list -> []
+%template(SelectionList) std::list<ModelHighAPI_Selection>;
#include "ModelHighAPI_Selection.h"
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
{
mutable std::shared_ptr<ModelAPI_AttributeSelection> myAttribute;
- fill_visitor(std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
+ fill_visitor(const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
: myAttribute(theAttribute) {}
void operator()(const ResultSubShapePair & thePair) const { myAttribute->setValue(thePair.first, thePair.second); }
};
void ModelHighAPI_Selection::fillAttribute(
- std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
+ const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
{
boost::apply_visitor(fill_visitor(theAttribute), myValue);
}
+
+//--------------------------------------------------------------------------------------
+struct append_visitor : boost::static_visitor<void>
+{
+ mutable std::shared_ptr<ModelAPI_AttributeSelectionList> myAttribute;
+
+ append_visitor(const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
+ : myAttribute(theAttribute) {}
+
+ void operator()(const ResultSubShapePair & thePair) const { myAttribute->append(thePair.first, thePair.second); }
+ void operator()(const TypeSubShapeNamePair & thePair) const {
+ // Note: the reverse order (first - type, second - sub-shape name)
+ myAttribute->append(thePair.second, thePair.first);
+ }
+};
+
+void ModelHighAPI_Selection::appendToList(
+ const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
+{
+ boost::apply_visitor(append_visitor(theAttribute), myValue);
+}
#define SRC_MODELHIGHAPI_MODELHIGHAPI_SELECTION_H_
//--------------------------------------------------------------------------------------
+#include "ModelHighAPI.h"
+
#include <memory>
#include <string>
#include <utility>
//--------------------------------------------------------------------------------------
class GeomAPI_Shape;
class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
class ModelAPI_Result;
//--------------------------------------------------------------------------------------
typedef std::pair<std::shared_ptr<ModelAPI_Result>, std::shared_ptr<GeomAPI_Shape> > ResultSubShapePair;
{
public:
/// Constructor for result and sub-shape
+ MODELHIGHAPI_EXPORT
ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext = std::shared_ptr<ModelAPI_Result>(),
const std::shared_ptr<GeomAPI_Shape>& theSubShape = std::shared_ptr<GeomAPI_Shape>());
/// Constructor for sub-shape by the textual Name
+ MODELHIGHAPI_EXPORT
ModelHighAPI_Selection(const std::string& theType,
const std::string& theSubShapeName);
/// Destructor
+ MODELHIGHAPI_EXPORT
virtual ~ModelHighAPI_Selection();
/// Fill attribute values
- virtual void fillAttribute(std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const;
+ MODELHIGHAPI_EXPORT
+ virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const;
+
+ /// Append to list attribute
+ MODELHIGHAPI_EXPORT
+ virtual void appendToList(const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const;
private:
boost::variant<ResultSubShapePair, TypeSubShapeNamePair> myValue;
--- /dev/null
+// Name : ModelHighAPI_Tools.cpp
+// Purpose:
+//
+// History:
+// 07/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_Tools.h"
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+
+#include "ModelHighAPI_Selection.h"
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
+ const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
+{
+ theAttribute->clear();
+ for (auto it = theValue.begin(); it != theValue.end(); ++it)
+ it->appendToList(theAttribute);
+}
+
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::string & theValue,
+ const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
+{
+ theAttribute->setValue(theValue);
+}
+//--------------------------------------------------------------------------------------
--- /dev/null
+// Name : ModelHighAPI_Tools.h
+// Purpose:
+//
+// History:
+// 07/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_TOOLS_H_
+#define SRC_MODELHIGHAPI_MODELHIGHAPI_TOOLS_H_
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI.h"
+
+#include <list>
+#include <memory>
+#include <string>
+//--------------------------------------------------------------------------------------
+class ModelAPI_AttributeSelectionList;
+class ModelAPI_AttributeString;
+//--------------------------------------------------------------------------------------
+class ModelHighAPI_Selection;
+//--------------------------------------------------------------------------------------
+MODELHIGHAPI_EXPORT
+void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
+ const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute);
+
+MODELHIGHAPI_EXPORT
+void fillAttribute(const std::string & theValue,
+ const std::shared_ptr<ModelAPI_AttributeString> & theAttribute);
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_TOOLS_H_ */
#include "ModelHighAPI_Double.h"
#include "ModelHighAPI_Interface.h"
#include "ModelHighAPI_Macro.h"
+ #include "ModelHighAPI_Selection.h"
+ #include "ModelHighAPI_Tools.h"
#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_ */