From 5c2ba91e54934c258b5c5caffd3adf347c5c1180 Mon Sep 17 00:00:00 2001 From: spo Date: Mon, 6 Jun 2016 12:22:12 +0300 Subject: [PATCH] Add ModelHighAPI_Selection & ConstructionAPI_Plane --- src/ConstructionAPI/CMakeLists.txt | 2 + src/ConstructionAPI/ConstructionAPI.i | 2 + src/ConstructionAPI/ConstructionAPI_Plane.cpp | 69 +++++++++++++++++++ src/ConstructionAPI/ConstructionAPI_Plane.h | 67 ++++++++++++++++++ src/ConstructionAPI/ConstructionAPI_swig.h | 1 + src/ModelHighAPI/CMakeLists.txt | 3 + .../Mock/MockModelAPI_AttributeSelection.h | 31 +++++++++ src/ModelHighAPI/ModelHighAPI_Selection.cpp | 46 +++++++++++++ src/ModelHighAPI/ModelHighAPI_Selection.h | 49 +++++++++++++ src/ModelHighAPI/Test/CMakeLists.txt | 1 + src/ModelHighAPI/Test/TestDouble.cpp | 2 +- src/ModelHighAPI/Test/TestSelection.cpp | 53 ++++++++++++++ 12 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 src/ConstructionAPI/ConstructionAPI_Plane.cpp create mode 100644 src/ConstructionAPI/ConstructionAPI_Plane.h create mode 100644 src/ModelHighAPI/Mock/MockModelAPI_AttributeSelection.h create mode 100644 src/ModelHighAPI/ModelHighAPI_Selection.cpp create mode 100644 src/ModelHighAPI/ModelHighAPI_Selection.h create mode 100644 src/ModelHighAPI/Test/TestSelection.cpp diff --git a/src/ConstructionAPI/CMakeLists.txt b/src/ConstructionAPI/CMakeLists.txt index ec44137b4..5a4169709 100644 --- a/src/ConstructionAPI/CMakeLists.txt +++ b/src/ConstructionAPI/CMakeLists.txt @@ -4,10 +4,12 @@ INCLUDE(Common) SET(PROJECT_HEADERS ConstructionAPI.h + ConstructionAPI_Plane.h ConstructionAPI_Point.h ) SET(PROJECT_SOURCES + ConstructionAPI_Plane.cpp ConstructionAPI_Point.cpp ) diff --git a/src/ConstructionAPI/ConstructionAPI.i b/src/ConstructionAPI/ConstructionAPI.i index 0ba605b9c..d09f8d516 100644 --- a/src/ConstructionAPI/ConstructionAPI.i +++ b/src/ConstructionAPI/ConstructionAPI.i @@ -19,7 +19,9 @@ %include "std_shared_ptr.i" // shared pointers +%shared_ptr(ConstructionAPI_Plane) %shared_ptr(ConstructionAPI_Point) // all supported interfaces +%include "ConstructionAPI_Plane.h" %include "ConstructionAPI_Point.h" diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.cpp b/src/ConstructionAPI/ConstructionAPI_Plane.cpp new file mode 100644 index 000000000..103d9d6eb --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI_Plane.cpp @@ -0,0 +1,69 @@ +// Name : ConstructionAPI_Plane.cpp +// Purpose: +// +// History: +// 27/05/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ConstructionAPI_Plane.h" +//-------------------------------------------------------------------------------------- +#include +#include +//-------------------------------------------------------------------------------------- +ConstructionAPI_Plane::ConstructionAPI_Plane( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +ConstructionAPI_Plane::ConstructionAPI_Plane( + const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theFace, + const ModelHighAPI_Double & theDistance) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + setFaceAndDistance(theFace, theDistance); +} + +ConstructionAPI_Plane::ConstructionAPI_Plane( + const std::shared_ptr & theFeature, + const ModelHighAPI_Double & theA, + const ModelHighAPI_Double & theB, + const ModelHighAPI_Double & theC, + const ModelHighAPI_Double & theD) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + setGeneralEquation(theA, theB, theC, theD); +} + +ConstructionAPI_Plane::~ConstructionAPI_Plane() +{ + +} + +void ConstructionAPI_Plane::setFaceAndDistance( + const ModelHighAPI_Selection & theFace, + const ModelHighAPI_Double & theDistance) +{ + theFace.fillAttribute(myface); + theDistance.fillAttribute(mydistance); + + execute(); +} + +void ConstructionAPI_Plane::setGeneralEquation( + const ModelHighAPI_Double & theA, + const ModelHighAPI_Double & theB, + const ModelHighAPI_Double & theC, + const ModelHighAPI_Double & theD) +{ + theA.fillAttribute(myA); + theB.fillAttribute(myB); + theC.fillAttribute(myC); + theD.fillAttribute(myD); + + execute(); +} diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.h b/src/ConstructionAPI/ConstructionAPI_Plane.h new file mode 100644 index 000000000..a71c23e14 --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI_Plane.h @@ -0,0 +1,67 @@ +// Name : ConstructionAPI_Plane.h +// Purpose: +// +// History: +// 27/05/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_PLANE_H_ +#define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_PLANE_H_ + +//-------------------------------------------------------------------------------------- +#include "ConstructionAPI.h" + +#include +#include +//-------------------------------------------------------------------------------------- +class ModelHighAPI_Double; +class ModelHighAPI_Selection; +//-------------------------------------------------------------------------------------- +/**\class ConstructionAPI_Plane + * \ingroup CPPHighAPI + * \brief Interface for Plane feature + */ +class ConstructionAPI_Plane : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + explicit ConstructionAPI_Plane(const std::shared_ptr & theFeature); + /// Constructor with values + ConstructionAPI_Plane(const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theFace, + const ModelHighAPI_Double & theDistance); + /// Constructor with values + ConstructionAPI_Plane(const std::shared_ptr & theFeature, + const ModelHighAPI_Double & theA, + const ModelHighAPI_Double & theB, + const ModelHighAPI_Double & theC, + const ModelHighAPI_Double & theD); + /// Destructor + virtual ~ConstructionAPI_Plane(); + + INTERFACE_7("Plane", + creationMethod, "CreationMethod", String, /** Creation method */, + face, "planeFace", Selection, /** Plane face */, + distance, "distance", Double, /** Distance */, + A, "A", Double, /** Parameter A for general equation */, + B, "B", Double, /** Parameter B for general equation */, + C, "C", Double, /** Parameter C for general equation */, + D, "D", Double, /** Parameter D for general equation */ + ) + + /// Set face and distance + void setFaceAndDistance(const ModelHighAPI_Selection & theFace, + const ModelHighAPI_Double & theDistance); + + /// Set GeneralEquation parameters of the feature + void setGeneralEquation(const ModelHighAPI_Double & theA, + const ModelHighAPI_Double & theB, + const ModelHighAPI_Double & theC, + const ModelHighAPI_Double & theD); +}; + +//! Pointer on Plane object +typedef std::shared_ptr PlanePtr; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_PLANE_H_ */ diff --git a/src/ConstructionAPI/ConstructionAPI_swig.h b/src/ConstructionAPI/ConstructionAPI_swig.h index 4cdc3fb81..84dc51958 100644 --- a/src/ConstructionAPI/ConstructionAPI_swig.h +++ b/src/ConstructionAPI/ConstructionAPI_swig.h @@ -9,6 +9,7 @@ #include + #include "ConstructionAPI_Plane.h" #include "ConstructionAPI_Point.h" #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_SWIG_H_ */ diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index c9fa67ca8..c7fed3344 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -7,11 +7,13 @@ SET(PROJECT_HEADERS ModelHighAPI_Double.h ModelHighAPI_Interface.h ModelHighAPI_Macro.h + ModelHighAPI_Selection.h ) SET(PROJECT_SOURCES ModelHighAPI_Double.cpp ModelHighAPI_Interface.cpp + ModelHighAPI_Selection.cpp ) SET(PROJECT_LIBRARIES @@ -40,6 +42,7 @@ SET(SWIG_LINK_LIBRARIES INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/ModelAPI ) diff --git a/src/ModelHighAPI/Mock/MockModelAPI_AttributeSelection.h b/src/ModelHighAPI/Mock/MockModelAPI_AttributeSelection.h new file mode 100644 index 000000000..ace94937d --- /dev/null +++ b/src/ModelHighAPI/Mock/MockModelAPI_AttributeSelection.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MockModelAPI_AttributeSelection_H_ +#define MockModelAPI_AttributeSelection_H_ + +#include + +#include + +class MockModelAPI_AttributeSelection : public ModelAPI_AttributeSelection { + public: + MOCK_METHOD3(setValue, + void(const ResultPtr& theContext, const std::shared_ptr& theSubShape, + const bool theTemporarily)); + MOCK_METHOD0(value, + std::shared_ptr()); + MOCK_METHOD0(context, + ResultPtr()); + MOCK_METHOD0(update, + bool()); + MOCK_METHOD1(namingName, + std::string(const std::string& theDefaultValue)); + MOCK_METHOD0(Id, + int()); + MOCK_METHOD2(selectSubShape, + void(const std::string& theType, const std::string& theSubShapeName)); + MOCK_METHOD0(isInvalid, + bool()); +}; + +#endif // MockModelAPI_AttributeSelection_H_ diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp new file mode 100644 index 000000000..1c2cca5bf --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -0,0 +1,46 @@ +// Name : ModelHighAPI_Selection.cpp +// Purpose: +// +// History: +// 06/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ModelHighAPI_Selection.h" + +#include +//-------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------- +ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr& theContext, + const std::shared_ptr& theSubShape) +: myValue(ResultSubShapePair(theContext, theSubShape)) +{ +} + +ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, + const std::string& theSubShapeName) +: myValue(TypeSubShapeNamePair(theType, theSubShapeName)) +{ +} + +ModelHighAPI_Selection::~ModelHighAPI_Selection() +{ +} + +//-------------------------------------------------------------------------------------- +struct fill_visitor : boost::static_visitor +{ + mutable std::shared_ptr myAttribute; + + fill_visitor(std::shared_ptr & theAttribute) + : myAttribute(theAttribute) {} + + void operator()(const ResultSubShapePair & thePair) const { myAttribute->setValue(thePair.first, thePair.second); } + void operator()(const TypeSubShapeNamePair & thePair) const { myAttribute->selectSubShape(thePair.first, thePair.second); } +}; + +void ModelHighAPI_Selection::fillAttribute( + std::shared_ptr & theAttribute) const +{ + boost::apply_visitor(fill_visitor(theAttribute), myValue); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h new file mode 100644 index 000000000..a39700465 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -0,0 +1,49 @@ +// Name : ModelHighAPI_Selection.h +// Purpose: +// +// History: +// 06/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_SELECTION_H_ +#define SRC_MODELHIGHAPI_MODELHIGHAPI_SELECTION_H_ + +//-------------------------------------------------------------------------------------- +#include +#include +#include + +#include +//-------------------------------------------------------------------------------------- +class GeomAPI_Shape; +class ModelAPI_AttributeSelection; +class ModelAPI_Result; +//-------------------------------------------------------------------------------------- +typedef std::pair, std::shared_ptr > ResultSubShapePair; +typedef std::pair TypeSubShapeNamePair; +//-------------------------------------------------------------------------------------- +/**\class ModelHighAPI_Selection + * \ingroup CPPHighAPI + * \brief Class for filling ModelAPI_AttributeSelection + */ +class ModelHighAPI_Selection +{ +public: + /// Constructor for result and sub-shape + ModelHighAPI_Selection(const std::shared_ptr& theContext = std::shared_ptr(), + const std::shared_ptr& theSubShape = std::shared_ptr()); + /// Constructor for sub-shape by the textual Name + ModelHighAPI_Selection(const std::string& theType, + const std::string& theSubShapeName); + /// Destructor + virtual ~ModelHighAPI_Selection(); + + /// Fill attribute values + virtual void fillAttribute(std::shared_ptr & theAttribute) const; + +private: + boost::variant myValue; +}; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SELECTION_H_ */ diff --git a/src/ModelHighAPI/Test/CMakeLists.txt b/src/ModelHighAPI/Test/CMakeLists.txt index 2af368b68..b99ca948e 100644 --- a/src/ModelHighAPI/Test/CMakeLists.txt +++ b/src/ModelHighAPI/Test/CMakeLists.txt @@ -4,6 +4,7 @@ include(GTest) set(PROJECT_SOURCES TestDouble.cpp + TestSelection.cpp ) include_directories( diff --git a/src/ModelHighAPI/Test/TestDouble.cpp b/src/ModelHighAPI/Test/TestDouble.cpp index 546db2d73..dcba7f35d 100644 --- a/src/ModelHighAPI/Test/TestDouble.cpp +++ b/src/ModelHighAPI/Test/TestDouble.cpp @@ -11,7 +11,7 @@ using ::testing::ReturnRefOfCopy; using ::testing::Test; // TODO(spo): should be common function -void null_deleter(void *) {} +static void null_deleter(void *) {} class HighModelAPI_Double_Test : public Test { public: diff --git a/src/ModelHighAPI/Test/TestSelection.cpp b/src/ModelHighAPI/Test/TestSelection.cpp new file mode 100644 index 000000000..11ac67e59 --- /dev/null +++ b/src/ModelHighAPI/Test/TestSelection.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include + +#include + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRefOfCopy; +using ::testing::Test; + +// TODO(spo): should be common function +static void null_deleter(void *) {} + +class HighModelAPI_Selection_Test : public Test { +public: + MockModelAPI_AttributeSelection aMockAttributeSelection; + std::shared_ptr anAttributeSelection; + + HighModelAPI_Selection_Test() { + anAttributeSelection = std::shared_ptr(&aMockAttributeSelection, &null_deleter); + } + + ~HighModelAPI_Selection_Test() { + } +}; + +TEST_F(HighModelAPI_Selection_Test, Default) { + ModelHighAPI_Selection aValue; + + EXPECT_CALL(aMockAttributeSelection, setValue(_, _, false)); + + aValue.fillAttribute(anAttributeSelection); +} + +TEST_F(HighModelAPI_Selection_Test, ResultAndSubShape) { + std::shared_ptr aResult; + std::shared_ptr aShape; + ModelHighAPI_Selection aValue(aResult, aShape); + + EXPECT_CALL(aMockAttributeSelection, setValue(_, _, false)); + + aValue.fillAttribute(anAttributeSelection); +} + +TEST_F(HighModelAPI_Selection_Test, TypeAndSubShapeName) { + ModelHighAPI_Selection aValue("Type", "SubShapeName"); + + EXPECT_CALL(aMockAttributeSelection, selectSubShape("Type", "SubShapeName")); + + aValue.fillAttribute(anAttributeSelection); +} -- 2.39.2