From c2d8b17151d8014acb8ad4150aed63e378fac6d1 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 7 Jun 2016 17:11:52 +0300 Subject: [PATCH] CPP API for FeaturesPlugin_Placement --- src/FeaturesAPI/CMakeLists.txt | 2 + src/FeaturesAPI/FeaturesAPI.i | 2 + src/FeaturesAPI/FeaturesAPI_Placement.cpp | 98 +++++++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Placement.h | 84 +++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_swig.h | 1 + src/PythonAPI/Test/TestFeatures.py | 2 +- 6 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 src/FeaturesAPI/FeaturesAPI_Placement.cpp create mode 100644 src/FeaturesAPI/FeaturesAPI_Placement.h diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index bae756a30..c5701e9ed 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -4,11 +4,13 @@ INCLUDE(Common) SET(PROJECT_HEADERS FeaturesAPI.h + FeaturesAPI_Placement.h FeaturesAPI_Rotation.h FeaturesAPI_Translation.h ) SET(PROJECT_SOURCES + FeaturesAPI_Placement.cpp FeaturesAPI_Rotation.cpp FeaturesAPI_Translation.cpp ) diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index 5879100c8..81ab3f8a6 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -19,9 +19,11 @@ %include "std_shared_ptr.i" // shared pointers +%shared_ptr(FeaturesAPI_Placement) %shared_ptr(FeaturesAPI_Rotation) %shared_ptr(FeaturesAPI_Translation) // all supported interfaces +%include "FeaturesAPI_Placement.h" %include "FeaturesAPI_Rotation.h" %include "FeaturesAPI_Translation.h" diff --git a/src/FeaturesAPI/FeaturesAPI_Placement.cpp b/src/FeaturesAPI/FeaturesAPI_Placement.cpp new file mode 100644 index 000000000..4d0870615 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Placement.cpp @@ -0,0 +1,98 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Placement.cpp +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#include "FeaturesAPI_Placement.h" + +#include + +//================================================================================================== +FeaturesAPI_Placement::FeaturesAPI_Placement(const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +FeaturesAPI_Placement::FeaturesAPI_Placement(const std::shared_ptr & theFeature, + const std::list& theObjects, + const ModelHighAPI_Selection& theStartShape, + const ModelHighAPI_Selection& theEndShape, + const bool theReverseDirection, + const bool theCentering) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setObjects(theObjects); + setStartShape(theStartShape); + setEndShape(theEndShape); + setReverseDirection(theReverseDirection); + setCentering(theCentering); + } +} + +//================================================================================================== +FeaturesAPI_Placement::~FeaturesAPI_Placement() +{ + +} + +//================================================================================================== +void FeaturesAPI_Placement::setObjects(const std::list& theObjects) +{ + fillAttribute(theObjects, myobjects); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Placement::setStartShape(const ModelHighAPI_Selection& theStartShape) +{ + fillAttribute(theStartShape, mystartShape); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Placement::setEndShape(const ModelHighAPI_Selection& theEndShape) +{ + fillAttribute(theEndShape, myendShape); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Placement::setReverseDirection(const bool theReverseDirection) +{ + fillAttribute(theReverseDirection, myreverseDirection); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Placement::setCentering(const bool theCentering) +{ + fillAttribute(theCentering, mycentering); + + execute(); +} + +// TODO(spo): make add* as static functions of the class +//================================================================================================== +PlacementPtr addPlacement(const std::shared_ptr & thePart, + const std::list& theObjects, + const ModelHighAPI_Selection& theStartShape, + const ModelHighAPI_Selection& theEndShape, + const bool theReverseDirection, + const bool theCentering) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Placement::ID()); + return PlacementPtr(new FeaturesAPI_Placement(aFeature, + theObjects, + theStartShape, + theEndShape, + theReverseDirection, + theCentering)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Placement.h b/src/FeaturesAPI/FeaturesAPI_Placement.h new file mode 100644 index 000000000..7d053e9cb --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_Placement.h @@ -0,0 +1,84 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: FeaturesAPI_Placement.h +// Created: 07 June 2016 +// Author: Dmitry Bobylev + +#ifndef FeaturesAPI_Placement_H_ +#define FeaturesAPI_Placement_H_ + +#include "FeaturesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_Placement +/// \ingroup CPPHighAPI +/// \brief Interface for Placement feature. +class FeaturesAPI_Placement : public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_Placement(const std::shared_ptr & theFeature); + + /// Constructor with values. + FEATURESAPI_EXPORT + FeaturesAPI_Placement(const std::shared_ptr & theFeature, + const std::list& theObjects, + const ModelHighAPI_Selection& theStartShape, + const ModelHighAPI_Selection& theEndShape, + const bool theReverseDirection = false, + const bool theCentering = false); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_Placement(); + + INTERFACE_5(FeaturesPlugin_Placement::ID(), + objects, FeaturesPlugin_Placement::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList, /** Main objects */, + startShape, FeaturesPlugin_Placement::START_SHAPE_ID(), ModelAPI_AttributeSelection, /** Start shape */, + endShape, FeaturesPlugin_Placement::END_SHAPE_ID(), ModelAPI_AttributeSelection, /** End shape */, + reverseDirection, FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean, /** Reverse direction flag */, + centering, FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean, /** Centering flag */) + + /// Set objects. + FEATURESAPI_EXPORT + void setObjects(const std::list& theObjects); + + /// Set start shape. + FEATURESAPI_EXPORT + void setStartShape(const ModelHighAPI_Selection& theStartShape); + + /// Set end shape. + FEATURESAPI_EXPORT + void setEndShape(const ModelHighAPI_Selection& theEndShape); + + /// Set reverse direction flag. + FEATURESAPI_EXPORT + void setReverseDirection(const bool theReverseDirection); + + /// Set centering flag. + FEATURESAPI_EXPORT + void setCentering(const bool theCentering); +}; + +/// Pointer on Placement object. +typedef std::shared_ptr PlacementPtr; + +/// \ingroup CPPHighAPI +/// \brief Create Placement feature. +FEATURESAPI_EXPORT +PlacementPtr addPlacement(const std::shared_ptr & thePart, + const std::list& theObjects, + const ModelHighAPI_Selection& theStartShape, + const ModelHighAPI_Selection& theEndShape, + const bool theReverseDirection = false, + const bool theCentering = false); + +#endif // FeaturesAPI_Placement_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h index cbfd4acdf..e73a541b6 100644 --- a/src/FeaturesAPI/FeaturesAPI_swig.h +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -10,6 +10,7 @@ #include #include "FeaturesAPI.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 ac83e141b..d7e613010 100644 --- a/src/PythonAPI/Test/TestFeatures.py +++ b/src/PythonAPI/Test/TestFeatures.py @@ -69,7 +69,7 @@ class FeaturesTestCase(FeaturesFixture): model.features.revolution.Revolution(self.part.addFeature("Revolution")) # 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")) + FeaturesAPI.FeaturesAPI_Placement(self.part.addFeature("Placement")) FeaturesAPI.FeaturesAPI_Rotation(self.part.addFeature("Rotation")) FeaturesAPI.FeaturesAPI_Translation(self.part.addFeature("Translation")) model.features.group.Group(self.part.addFeature("Group")) -- 2.39.2