From 61b52539f8a46dddf55715e3c294e7247fecee3c Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 8 Jun 2016 15:49:52 +0300 Subject: [PATCH] CPP API for FeaturesPlugin_Boolean --- src/FeaturesAPI/CMakeLists.txt | 2 + src/FeaturesAPI/FeaturesAPI.i | 2 + src/FeaturesAPI/FeaturesAPI_Boolean.cpp | 111 ++++++++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Boolean.h | 89 +++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Placement.h | 1 - src/FeaturesAPI/FeaturesAPI_swig.h | 1 + src/PythonAPI/Test/TestFeatures.py | 4 +- 7 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 src/FeaturesAPI/FeaturesAPI_Boolean.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_Boolean.h diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index c5701e9ed..4daaa9f5f 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -4,12 +4,14 @@ INCLUDE(Common) SET(PROJECT_HEADERS FeaturesAPI.h + FeaturesAPI_Boolean.h FeaturesAPI_Placement.h FeaturesAPI_Rotation.h FeaturesAPI_Translation.h ) SET(PROJECT_SOURCES + FeaturesAPI_Boolean.cpp FeaturesAPI_Placement.cpp FeaturesAPI_Rotation.cpp FeaturesAPI_Translation.cpp diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index 81ab3f8a6..226d74492 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -19,11 +19,13 @@ %include "std_shared_ptr.i" // shared pointers +%shared_ptr(FeaturesAPI_Boolean) %shared_ptr(FeaturesAPI_Placement) %shared_ptr(FeaturesAPI_Rotation) %shared_ptr(FeaturesAPI_Translation) // all supported interfaces +%include "FeaturesAPI_Boolean.h" %include "FeaturesAPI_Placement.h" %include "FeaturesAPI_Rotation.h" %include "FeaturesAPI_Translation.h" diff --git a/src/FeaturesAPI/FeaturesAPI_Boolean.cpp b/src/FeaturesAPI/FeaturesAPI_Boolean.cpp new file mode 100644 index 000000000..83e65fe47 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Boolean.cpp @@ -0,0 +1,111 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Boolean.cpp +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#include "FeaturesAPI_Boolean.h" + +#include +#include +#include + +//================================================================================================== +FeaturesAPI_Boolean::FeaturesAPI_Boolean(const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +FeaturesAPI_Boolean::FeaturesAPI_Boolean(const std::shared_ptr & theFeature, + const ModelHighAPI_Integer& theBoolType, + const std::list& theMainObjects, + const std::list& theToolObjects) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setBoolType(theBoolType); + setMainObjects(theMainObjects); + setToolObjects(theToolObjects); + } +} + +//================================================================================================== +FeaturesAPI_Boolean::~FeaturesAPI_Boolean() +{ + +} + +//================================================================================================== +void FeaturesAPI_Boolean::setBoolType(const ModelHighAPI_Integer& theBoolType) +{ + fillAttribute(theBoolType, myboolType); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Boolean::setMainObjects(const std::list& theMainObjects) +{ + fillAttribute(theMainObjects, mymainObjects); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Boolean::setToolObjects(const std::list& theToolObjects) +{ + fillAttribute(theToolObjects, mytoolObjects); + + execute(); +} + +// TODO(spo): make add* as static functions of the class +//================================================================================================== +BooleanPtr addCut(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const std::list& theToolObjects) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID()); + return BooleanPtr(new FeaturesAPI_Boolean(aFeature, + FeaturesPlugin_Boolean::BOOL_CUT, + theMainObjects, + theToolObjects)); +} + +//================================================================================================== +BooleanPtr addFuse(const std::shared_ptr & thePart, + const std::list& theObjects) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID()); + std::list aToolObjects; + return BooleanPtr(new FeaturesAPI_Boolean(aFeature, + FeaturesPlugin_Boolean::BOOL_FUSE, + theObjects, + aToolObjects)); +} + +//================================================================================================== +BooleanPtr addFuse(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const std::list& theToolObjects) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID()); + return BooleanPtr(new FeaturesAPI_Boolean(aFeature, + FeaturesPlugin_Boolean::BOOL_FUSE, + theMainObjects, + theToolObjects)); +} + +//================================================================================================== +BooleanPtr addCommon(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const std::list& theToolObjects) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID()); + return BooleanPtr(new FeaturesAPI_Boolean(aFeature, + FeaturesPlugin_Boolean::BOOL_COMMON, + theMainObjects, + theToolObjects)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Boolean.h b/src/FeaturesAPI/FeaturesAPI_Boolean.h new file mode 100644 index 000000000..bcbd40f25 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Boolean.h @@ -0,0 +1,89 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Boolean.h +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#ifndef FeaturesAPI_Boolean_H_ +#define FeaturesAPI_Boolean_H_ + +#include "FeaturesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Integer; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_Boolean +/// \ingroup CPPHighAPI +/// \brief Interface for Boolean feature. +class FeaturesAPI_Boolean : public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Boolean(const std::shared_ptr & theFeature); + + /// Constructor with values. + FEATURESAPI_EXPORT + FeaturesAPI_Boolean(const std::shared_ptr & theFeature, + const ModelHighAPI_Integer& theBoolType, + const std::list& theMainObjects, + const std::list& theToolObjects); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_Boolean(); + + INTERFACE_3(FeaturesPlugin_Boolean::ID(), + boolType, FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger, /** Operation type */, + mainObjects, FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList, /** Main objects */, + toolObjects, FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList, /** Tool objects*/) + + /// Set operation type. + FEATURESAPI_EXPORT + void setBoolType(const ModelHighAPI_Integer& theBoolType); + + /// Set main objects. + FEATURESAPI_EXPORT + void setMainObjects(const std::list& theMainObjects); + + /// Set tool objects. + FEATURESAPI_EXPORT + void setToolObjects(const std::list& theToolObjects); +}; + +/// Pointer on Boolean object. +typedef std::shared_ptr BooleanPtr; + +/// \ingroup CPPHighAPI +/// \brief Create Boolean Cut feature. +FEATURESAPI_EXPORT +BooleanPtr addCut(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const std::list& theToolObjects); + +/// \ingroup CPPHighAPI +/// \brief Create Boolean Fuse feature. +FEATURESAPI_EXPORT +BooleanPtr addFuse(const std::shared_ptr & thePart, + const std::list& theObjects); + +/// \ingroup CPPHighAPI +/// \brief Create Boolean Fuse feature. +FEATURESAPI_EXPORT +BooleanPtr addFuse(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const std::list& theToolObjects); + +/// \ingroup CPPHighAPI +/// \brief Create Boolean Common feature. +FEATURESAPI_EXPORT +BooleanPtr addCommon(const std::shared_ptr & thePart, + const std::list& theMainObjects, + const std::list& theToolObjects); + +#endif // FeaturesAPI_Boolean_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_Placement.h b/src/FeaturesAPI/FeaturesAPI_Placement.h index 7d053e9cb..691fd509b 100644 --- a/src/FeaturesAPI/FeaturesAPI_Placement.h +++ b/src/FeaturesAPI/FeaturesAPI_Placement.h @@ -14,7 +14,6 @@ #include #include -class ModelHighAPI_Double; class ModelHighAPI_Selection; /// \class FeaturesAPI_Placement diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h index e73a541b6..61571735a 100644 --- a/src/FeaturesAPI/FeaturesAPI_swig.h +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -10,6 +10,7 @@ #include #include "FeaturesAPI.h" + #include "FeaturesAPI_Boolean.h" #include "FeaturesAPI_Placement.h" #include "FeaturesAPI_Rotation.h" #include "FeaturesAPI_Translation.h" diff --git a/src/PythonAPI/Test/TestFeatures.py b/src/PythonAPI/Test/TestFeatures.py index d7e613010..a5e98ba65 100644 --- a/src/PythonAPI/Test/TestFeatures.py +++ b/src/PythonAPI/Test/TestFeatures.py @@ -32,7 +32,7 @@ class FeaturesTestCase(FeaturesFixture): # "addImport", "exportToFile", "addAxis", - "addAddition", "addSubtraction", "addIntersection", + "addCut", "addFuse", "addCommon", "addExtrusion", # "addExtrusionCut", "addExtrusionFuse", "addRevolution", @@ -62,7 +62,7 @@ class FeaturesTestCase(FeaturesFixture): ExchangeAPI.ExchangeAPI_Export(self.part.addFeature("Export")) import FeaturesAPI - model.features.boolean.Boolean(self.part.addFeature("Boolean")) + FeaturesAPI.FeaturesAPI_Boolean(self.part.addFeature("Boolean")) model.features.extrusion.Extrusion(self.part.addFeature("Extrusion")) # model.features.extrusion_boolean.ExtrusionBoolean(self.part.addFeature("ExtrusionCut")) # model.features.extrusion_boolean.ExtrusionBoolean(self.part.addFeature("ExtrusionFuse")) -- 2.39.2