From a97af12c3bf7f23f77f2fb231b394ec9643cce40 Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 16 Jun 2016 16:10:18 +0300 Subject: [PATCH] Add PartSetAPI --- CMakeLists.txt | 1 + src/ModelHighAPI/ModelHighAPI_Macro.h | 8 +++ src/ModelHighAPI/ModelHighAPI_Tools.cpp | 7 +++ src/ModelHighAPI/ModelHighAPI_Tools.h | 4 ++ src/PartSetAPI/CMakeLists.txt | 69 +++++++++++++++++++++++++ src/PartSetAPI/PartSetAPI.h | 20 +++++++ src/PartSetAPI/PartSetAPI.i | 25 +++++++++ src/PartSetAPI/PartSetAPI_Part.cpp | 54 +++++++++++++++++++ src/PartSetAPI/PartSetAPI_Part.h | 64 +++++++++++++++++++++++ src/PartSetAPI/PartSetAPI_swig.h | 14 +++++ src/PythonAPI/model/partset/__init__.py | 2 +- 11 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 src/PartSetAPI/CMakeLists.txt create mode 100644 src/PartSetAPI/PartSetAPI.h create mode 100644 src/PartSetAPI/PartSetAPI.i create mode 100644 src/PartSetAPI/PartSetAPI_Part.cpp create mode 100644 src/PartSetAPI/PartSetAPI_Part.h create mode 100644 src/PartSetAPI/PartSetAPI_swig.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d00323c95..bbfe7510c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ ADD_SUBDIRECTORY (src/ModelHighAPI) ADD_SUBDIRECTORY (src/ConstructionAPI) ADD_SUBDIRECTORY (src/ExchangeAPI) ADD_SUBDIRECTORY (src/FeaturesAPI) +ADD_SUBDIRECTORY (src/PartSetAPI) ADD_SUBDIRECTORY (src/SketchAPI) IF(${HAVE_SALOME}) diff --git a/src/ModelHighAPI/ModelHighAPI_Macro.h b/src/ModelHighAPI/ModelHighAPI_Macro.h index a38bebe7b..4e15701ad 100644 --- a/src/ModelHighAPI/ModelHighAPI_Macro.h +++ b/src/ModelHighAPI/ModelHighAPI_Macro.h @@ -67,6 +67,14 @@ return true; \ } +//-------------------------------------------------------------------------------------- +#define INTERFACE_0(KIND) \ + public: \ + INTERFACE_COMMON(KIND) \ + protected: \ + START_INIT() \ + END_INIT() \ + public: //-------------------------------------------------------------------------------------- #define INTERFACE_1(KIND, \ diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 2c300e15c..ff191e5ca 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -102,6 +102,13 @@ void fillAttribute(const std::list & theValue, it->appendToList(theAttribute); } +//-------------------------------------------------------------------------------------- +void fillAttribute(const std::shared_ptr & theValue, + const std::shared_ptr & theAttribute) +{ + theAttribute->setValue(theValue); +} + //-------------------------------------------------------------------------------------- void fillAttribute(const std::list > & theValue, const std::shared_ptr & theAttribute) diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index f53e37a1b..dc3378df2 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -82,6 +82,10 @@ MODELHIGHAPI_EXPORT void fillAttribute(const std::list & theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +void fillAttribute(const std::shared_ptr & theValue, + const std::shared_ptr & theAttribute); + MODELHIGHAPI_EXPORT void fillAttribute(const std::list > & theValue, const std::shared_ptr & theAttribute); diff --git a/src/PartSetAPI/CMakeLists.txt b/src/PartSetAPI/CMakeLists.txt new file mode 100644 index 000000000..c9cb0637d --- /dev/null +++ b/src/PartSetAPI/CMakeLists.txt @@ -0,0 +1,69 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +INCLUDE(Common) + +SET(PROJECT_HEADERS + PartSetAPI.h + PartSetAPI_Part.h +) + +SET(PROJECT_SOURCES + PartSetAPI_Part.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 PartSetPlugin headers to remove dependency on GeomAPI headers + ${PROJECT_SOURCE_DIR}/src/GeomAPI + # TODO(spo): it is for *_swig.h files. Can we eliminate it? + ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/PartSetPlugin +) + +#TODO(spo): is ${CAS_DEFINITIONS} necessary? +ADD_DEFINITIONS(-DCONSTRUCTIONAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(PartSetAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(PartSetAPI ${PROJECT_LIBRARIES}) + +# SWIG wrapper + +INCLUDE(PythonAPI) + +SET_SOURCE_FILES_PROPERTIES(PartSetAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(PartSetAPI.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 + PartSetAPI + ModelHighAPI + ModelAPI + ${PYTHON_LIBRARIES} +) + +SET(SWIG_MODULE_PartSetAPI_EXTRA_DEPS ${SWIG_MODULE_PartSetAPI_EXTRA_DEPS} + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i + doxyhelp.i + ${PROJECT_HEADERS} +) + +SWIG_ADD_MODULE(PartSetAPI python PartSetAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(PartSetAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_PartSetAPI PROPERTIES DEBUG_OUTPUT_NAME _PartSetAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _PartSetAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS PartSetAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/PartSetAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) diff --git a/src/PartSetAPI/PartSetAPI.h b/src/PartSetAPI/PartSetAPI.h new file mode 100644 index 000000000..8473acb07 --- /dev/null +++ b/src/PartSetAPI/PartSetAPI.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef PARTSETAPI_H +#define PARTSETAPI_H + +#if defined PARTSETAPI_EXPORTS +#if defined WIN32 +#define PARTSETAPI_EXPORT __declspec( dllexport ) +#else +#define PARTSETAPI_EXPORT +#endif +#else +#if defined WIN32 +#define PARTSETAPI_EXPORT __declspec( dllimport ) +#else +#define PARTSETAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/PartSetAPI/PartSetAPI.i b/src/PartSetAPI/PartSetAPI.i new file mode 100644 index 000000000..748fdf027 --- /dev/null +++ b/src/PartSetAPI/PartSetAPI.i @@ -0,0 +1,25 @@ +/* PartSetAPI.i */ + +%module PartSetAPI + +%{ + #include "PartSetAPI_swig.h" +%} + +%include "doxyhelp.i" + +// import other modules +%import "ModelHighAPI.i" + +// to avoid error on this +#define PARTSETAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_shared_ptr.i" + +// shared pointers +%shared_ptr(PartSetAPI_Part) + +// all supported interfaces +%include "PartSetAPI_Part.h" diff --git a/src/PartSetAPI/PartSetAPI_Part.cpp b/src/PartSetAPI/PartSetAPI_Part.cpp new file mode 100644 index 000000000..e55cc920f --- /dev/null +++ b/src/PartSetAPI/PartSetAPI_Part.cpp @@ -0,0 +1,54 @@ +// Name : PartSetAPI_Part.cpp +// Purpose: +// +// History: +// 16/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "PartSetAPI_Part.h" +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +#include +#include +//-------------------------------------------------------------------------------------- +PartSetAPI_Part::PartSetAPI_Part( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +PartSetAPI_Part::~PartSetAPI_Part() +{ +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr PartSetAPI_Part::document() const +{ + return std::dynamic_pointer_cast(defaultResult())->partDoc(); +} + +//-------------------------------------------------------------------------------------- +PartPtr addPart(const std::shared_ptr & thePart) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(PartSetAPI_Part::ID()); + aFeature->execute(); + return PartPtr(new PartSetAPI_Part(aFeature)); +} + +PartPtr duplicatePart(const std::shared_ptr & thePart) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(PartSetPlugin_Duplicate::ID()); + aFeature->execute(); + return PartPtr(new PartSetAPI_Part(aFeature)); +} + +void removePart(const std::shared_ptr & thePart) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(PartSetPlugin_Remove::ID()); + aFeature->execute(); +} diff --git a/src/PartSetAPI/PartSetAPI_Part.h b/src/PartSetAPI/PartSetAPI_Part.h new file mode 100644 index 000000000..b65fce9b9 --- /dev/null +++ b/src/PartSetAPI/PartSetAPI_Part.h @@ -0,0 +1,64 @@ +// Name : PartSetAPI_Part.h +// Purpose: +// +// History: +// 16/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_PARTSETAPI_PARTSETAPI_PART_H_ +#define SRC_PARTSETAPI_PARTSETAPI_PART_H_ + +//-------------------------------------------------------------------------------------- +#include "PartSetAPI.h" + +#include + +#include +#include +//-------------------------------------------------------------------------------------- +class ModelAPI_Document; +//-------------------------------------------------------------------------------------- +/**\class PartSetAPI_Part + * \ingroup CPPHighAPI + * \brief Interface for Part feature + */ +class PartSetAPI_Part : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + PARTSETAPI_EXPORT + explicit PartSetAPI_Part(const std::shared_ptr & theFeature); + /// Destructor + PARTSETAPI_EXPORT + virtual ~PartSetAPI_Part(); + + INTERFACE_0(PartSetPlugin_Part::ID()) + + /// Return document + PARTSETAPI_EXPORT + std::shared_ptr document() const; +}; + +//! Pointer on Part object +typedef std::shared_ptr PartPtr; + +/**\ingroup CPPHighAPI + * \brief Create Part feature + */ +PARTSETAPI_EXPORT +PartPtr addPart(const std::shared_ptr & thePartSet); + +/**\ingroup CPPHighAPI + * \brief Duplicate Part feature + */ +PARTSETAPI_EXPORT +PartPtr duplicatePart(const std::shared_ptr & thePart); + +/**\ingroup CPPHighAPI + * \brief Remove Part feature + */ +PARTSETAPI_EXPORT +void removePart(const std::shared_ptr & thePart); + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_PARTSETAPI_PARTSETAPI_PART_H_ */ diff --git a/src/PartSetAPI/PartSetAPI_swig.h b/src/PartSetAPI/PartSetAPI_swig.h new file mode 100644 index 000000000..adec7516f --- /dev/null +++ b/src/PartSetAPI/PartSetAPI_swig.h @@ -0,0 +1,14 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSetAPI_swig.h +// Created: 16/06/16 +// Author: Sergey POKHODENKO + +#ifndef SRC_PARTSETAPI_PARTSETAPI_SWIG_H_ +#define SRC_PARTSETAPI_PARTSETAPI_SWIG_H_ + + #include + + #include "PartSetAPI_Part.h" + +#endif /* SRC_PARTSETAPI_PARTSETAPI_SWIG_H_ */ diff --git a/src/PythonAPI/model/partset/__init__.py b/src/PythonAPI/model/partset/__init__.py index 33eed0d4b..f66380156 100644 --- a/src/PythonAPI/model/partset/__init__.py +++ b/src/PythonAPI/model/partset/__init__.py @@ -1,4 +1,4 @@ """Package for PartSet plugin for the Parametric Geometry API of the Modeler. """ -from part import addPart, duplicatePart, removePart \ No newline at end of file +from PartSetAPI import addPart, duplicatePart, removePart \ No newline at end of file -- 2.39.2