From 49aae0203d4c89a9cd5409451c3e4208b799e004 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 7 Jun 2016 14:10:21 +0300 Subject: [PATCH] CPP API for FeaturesPlugin_Translation, FeaturesPlugin_Rotation --- src/FeaturesAPI/CMakeLists.txt | 77 +++++++++++++++++++++ src/FeaturesAPI/FeaturesAPI.h | 20 ++++++ src/FeaturesAPI/FeaturesAPI.i | 27 ++++++++ src/FeaturesAPI/FeaturesAPI_Rotation.cpp | 71 +++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Rotation.h | 70 +++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Translation.cpp | 71 +++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Translation.h | 70 +++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_swig.h | 16 +++++ src/PythonAPI/Test/TestFeatures.py | 5 +- 9 files changed, 425 insertions(+), 2 deletions(-) create mode 100644 src/FeaturesAPI/CMakeLists.txt create mode 100644 src/FeaturesAPI/FeaturesAPI.h create mode 100644 src/FeaturesAPI/FeaturesAPI.i create mode 100644 src/FeaturesAPI/FeaturesAPI_Rotation.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_Rotation.h create mode 100644 src/FeaturesAPI/FeaturesAPI_Translation.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_Translation.h create mode 100644 src/FeaturesAPI/FeaturesAPI_swig.h diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt new file mode 100644 index 000000000..bae756a30 --- /dev/null +++ b/src/FeaturesAPI/CMakeLists.txt @@ -0,0 +1,77 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +INCLUDE(Common) + +SET(PROJECT_HEADERS + FeaturesAPI.h + FeaturesAPI_Rotation.h + FeaturesAPI_Translation.h +) + +SET(PROJECT_SOURCES + FeaturesAPI_Rotation.cpp + FeaturesAPI_Translation.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( + ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI + ${PROJECT_SOURCE_DIR}/src/FeaturesPlugin +) + +#TODO(spo): is ${CAS_DEFINITIONS} necessary? +ADD_DEFINITIONS(-DFEATURESAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(FeaturesAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(FeaturesAPI ${PROJECT_LIBRARIES}) + +# SWIG wrapper + +INCLUDE(PythonAPI) + +SET_SOURCE_FILES_PROPERTIES(FeaturesAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(FeaturesAPI.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 + FeaturesAPI + ModelHighAPI + ModelAPI + ${PYTHON_LIBRARIES} +) + +SET(SWIG_MODULE_FeaturesAPI_EXTRA_DEPS ${SWIG_MODULE_FeaturesAPI_EXTRA_DEPS} + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i + doxyhelp.i + ${PROJECT_HEADERS} +) + +SWIG_ADD_MODULE(FeaturesAPI python FeaturesAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(FeaturesAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_FeaturesAPI PROPERTIES DEBUG_OUTPUT_NAME _FeaturesAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _FeaturesAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS FeaturesAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/FeaturesAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) + +# Tests +INCLUDE(UnitTest) + +ADD_UNIT_TESTS( +) + +# ADD_SUBDIRECTORY (Test) diff --git a/src/FeaturesAPI/FeaturesAPI.h b/src/FeaturesAPI/FeaturesAPI.h new file mode 100644 index 000000000..63a7ca66a --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef FEATURESAPI_H +#define FEATURESAPI_H + +#if defined FEATURESAPI_EXPORTS +#if defined WIN32 +#define FEATURESAPI_EXPORT __declspec( dllexport ) +#else +#define FEATURESAPI_EXPORT +#endif +#else +#if defined WIN32 +#define FEATURESAPI_EXPORT __declspec( dllimport ) +#else +#define FEATURESAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i new file mode 100644 index 000000000..5879100c8 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -0,0 +1,27 @@ +/* FeaturesAPI.i */ + +%module FeaturesAPI + +%{ + #include "FeaturesAPI_swig.h" +%} + +%include "doxyhelp.i" + +// import other modules +%import "ModelHighAPI.i" + +// to avoid error on this +#define FEATURESAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_shared_ptr.i" + +// shared pointers +%shared_ptr(FeaturesAPI_Rotation) +%shared_ptr(FeaturesAPI_Translation) + +// all supported interfaces +%include "FeaturesAPI_Rotation.h" +%include "FeaturesAPI_Translation.h" diff --git a/src/FeaturesAPI/FeaturesAPI_Rotation.cpp b/src/FeaturesAPI/FeaturesAPI_Rotation.cpp new file mode 100644 index 000000000..a043f5928 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Rotation.cpp @@ -0,0 +1,71 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Rotation.cpp +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#include "FeaturesAPI_Rotation.h" + +#include + +//================================================================================================== +FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr & theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theAngle) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setMainObjects(theMainObjects); + setAxisObject(theAxisObject); + setAngle(theAngle); + } +} + +//================================================================================================== +FeaturesAPI_Rotation::~FeaturesAPI_Rotation() +{ + +} + +//================================================================================================== +void FeaturesAPI_Rotation::setMainObjects(const std::list& theMainObjects) +{ + fillAttribute(theMainObjects, mymainObjects); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Rotation::setAxisObject(const ModelHighAPI_Selection& theAxisObject) +{ + fillAttribute(theAxisObject, myaxisObject); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Rotation::setAngle(const ModelHighAPI_Double& theAngle) +{ + fillAttribute(theAngle, myangle); + + execute(); +} + +// TODO(spo): make add* as static functions of the class +//================================================================================================== +RotationPtr addRotation(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID()); + return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theAxisObject, theDistance)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Rotation.h b/src/FeaturesAPI/FeaturesAPI_Rotation.h new file mode 100644 index 000000000..0267cc94c --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Rotation.h @@ -0,0 +1,70 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Rotation.h +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#ifndef FeaturesAPI_Rotation_H_ +#define FeaturesAPI_Rotation_H_ + +#include "FeaturesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_Rotation +/// \ingroup CPPHighAPI +/// \brief Interface for Rotation feature. +class FeaturesAPI_Rotation : public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Rotation(const std::shared_ptr & theFeature); + + /// Constructor with values. + FEATURESAPI_EXPORT + FeaturesAPI_Rotation(const std::shared_ptr & theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theAngle); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_Rotation(); + + INTERFACE_3(FeaturesPlugin_Rotation::ID(), + mainObjects, FeaturesPlugin_Rotation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList, /** Main objects */, + axisObject, FeaturesPlugin_Rotation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection, /** Axis object */, + angle, FeaturesPlugin_Rotation::ANGLE_ID(), ModelAPI_AttributeDouble, /** Angle */) + + /// Set main objects. + FEATURESAPI_EXPORT + void setMainObjects(const std::list& theMainObjects); + + /// Set axis object. + FEATURESAPI_EXPORT + void setAxisObject(const ModelHighAPI_Selection& theAxisObject); + + /// Set angle. + FEATURESAPI_EXPORT + void setAngle(const ModelHighAPI_Double& theAngle); +}; + +/// Pointer on Rotation object. +typedef std::shared_ptr RotationPtr; + +/// \ingroup CPPHighAPI +/// \brief Create Rotation feature. +FEATURESAPI_EXPORT +RotationPtr addRotation(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance); + +#endif // FeaturesAPI_Rotation_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.cpp b/src/FeaturesAPI/FeaturesAPI_Translation.cpp new file mode 100644 index 000000000..5c3fa0632 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Translation.cpp @@ -0,0 +1,71 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Translation.cpp +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#include "FeaturesAPI_Translation.h" + +#include + +//================================================================================================== +FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr & theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setMainObjects(theMainObjects); + setAxisObject(theAxisObject); + setDistance(theDistance); + } +} + +//================================================================================================== +FeaturesAPI_Translation::~FeaturesAPI_Translation() +{ + +} + +//================================================================================================== +void FeaturesAPI_Translation::setMainObjects(const std::list& theMainObjects) +{ + fillAttribute(theMainObjects, mymainObjects); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Translation::setAxisObject(const ModelHighAPI_Selection& theAxisObject) +{ + fillAttribute(theAxisObject, myaxisObject); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Translation::setDistance(const ModelHighAPI_Double& theDistance) +{ + fillAttribute(theDistance, mydistance); + + execute(); +} + +// TODO(spo): make add* as static functions of the class +//================================================================================================== +TranslationPtr addTranslation(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Translation::ID()); + return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theAxisObject, theDistance)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.h b/src/FeaturesAPI/FeaturesAPI_Translation.h new file mode 100644 index 000000000..fef95b503 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Translation.h @@ -0,0 +1,70 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Translation.h +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#ifndef FeaturesAPI_Translation_H_ +#define FeaturesAPI_Translation_H_ + +#include "FeaturesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_Translation +/// \ingroup CPPHighAPI +/// \brief Interface for Translation feature. +class FeaturesAPI_Translation : public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Translation(const std::shared_ptr & theFeature); + + /// Constructor with values. + FEATURESAPI_EXPORT + FeaturesAPI_Translation(const std::shared_ptr & theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_Translation(); + + INTERFACE_3(FeaturesPlugin_Translation::ID(), + mainObjects, FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList, /** Main objects */, + axisObject, FeaturesPlugin_Translation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection, /** Axis object */, + distance, FeaturesPlugin_Translation::DISTANCE_ID(), ModelAPI_AttributeDouble, /** Distance */) + + /// Set main objects. + FEATURESAPI_EXPORT + void setMainObjects(const std::list& theMainObjects); + + /// Set axis object. + FEATURESAPI_EXPORT + void setAxisObject(const ModelHighAPI_Selection& theAxisObject); + + /// Set distance. + FEATURESAPI_EXPORT + void setDistance(const ModelHighAPI_Double& theDistance); +}; + +/// Pointer on Translation object. +typedef std::shared_ptr TranslationPtr; + +/// \ingroup CPPHighAPI +/// \brief Create Translation feature. +FEATURESAPI_EXPORT +TranslationPtr addTranslation(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance); + +#endif // FeaturesAPI_Translation_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h new file mode 100644 index 000000000..cbfd4acdf --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -0,0 +1,16 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesAPI_swig.h +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#ifndef FeaturesAPI_swig_H_ +#define FeaturesAPI_swig_H_ + + #include + + #include "FeaturesAPI.h" + #include "FeaturesAPI_Rotation.h" + #include "FeaturesAPI_Translation.h" + +#endif // FeaturesAPI_swig_H_ diff --git a/src/PythonAPI/Test/TestFeatures.py b/src/PythonAPI/Test/TestFeatures.py index d749018ca..ac83e141b 100644 --- a/src/PythonAPI/Test/TestFeatures.py +++ b/src/PythonAPI/Test/TestFeatures.py @@ -61,6 +61,7 @@ class FeaturesTestCase(FeaturesFixture): ExchangeAPI.ExchangeAPI_Import(self.part.addFeature("Import")) ExchangeAPI.ExchangeAPI_Export(self.part.addFeature("Export")) + import FeaturesAPI model.features.boolean.Boolean(self.part.addFeature("Boolean")) model.features.extrusion.Extrusion(self.part.addFeature("Extrusion")) # model.features.extrusion_boolean.ExtrusionBoolean(self.part.addFeature("ExtrusionCut")) @@ -69,8 +70,8 @@ class FeaturesTestCase(FeaturesFixture): # model.features.revolution_boolean.RevolutionBoolean(self.part.addFeature("RevolutionCut")) # model.features.revolution_boolean.RevolutionBoolean(self.part.addFeature("RevolutionFuse")) model.features.placement.Placement(self.part.addFeature("Placement")) - model.features.rotation.Rotation(self.part.addFeature("Rotation")) - model.features.translation.Translation(self.part.addFeature("Translation")) + FeaturesAPI.FeaturesAPI_Rotation(self.part.addFeature("Rotation")) + FeaturesAPI.FeaturesAPI_Translation(self.part.addFeature("Translation")) model.features.group.Group(self.part.addFeature("Group")) model.parameter.Parameter(self.part.addFeature("Parameter")) -- 2.39.2