From 9667dc480f815e484bdf45ef9d269ff2fc04012d Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 24 May 2016 16:08:19 +0300 Subject: [PATCH] Add ModelHighAPI & ConstructionAPI pachages --- CMakeLists.txt | 3 + src/ConstructionAPI/CMakeLists.txt | 69 +++++++++++ src/ConstructionAPI/ConstructionAPI.h | 20 +++ src/ConstructionAPI/ConstructionAPI.i | 17 +++ src/ConstructionAPI/ConstructionAPI_Point.cpp | 86 +++++++++++++ src/ConstructionAPI/ConstructionAPI_Point.h | 47 ++++++++ src/ConstructionAPI/ConstructionAPI_swig.h | 15 +++ src/ConstructionAPI/Test/CMakeLists.txt | 45 +++++++ .../Test/MockModelAPI_AttributeDouble.h | 36 ++++++ src/ConstructionAPI/Test/MockModelAPI_Data.h | 98 +++++++++++++++ .../Test/MockModelAPI_Feature.h | 46 +++++++ .../Test/MockModelAPI_Object.h | 24 ++++ src/ConstructionAPI/Test/TestPoint.cpp | 114 ++++++++++++++++++ src/ConstructionAPI/Test/TestPoint.py | 37 ++++++ src/ModelHighAPI/CMakeLists.txt | 64 ++++++++++ src/ModelHighAPI/ModelHighAPI.h | 20 +++ src/ModelHighAPI/ModelHighAPI.i | 34 ++++++ src/ModelHighAPI/ModelHighAPI_Double.cpp | 53 ++++++++ src/ModelHighAPI/ModelHighAPI_Double.h | 38 ++++++ src/ModelHighAPI/ModelHighAPI_Interface.cpp | 39 ++++++ src/ModelHighAPI/ModelHighAPI_Interface.h | 40 ++++++ src/ModelHighAPI/ModelHighAPI_swig.h | 15 +++ src/ModelHighAPI/Test/TestDouble.py | 20 +++ 23 files changed, 980 insertions(+) create mode 100644 src/ConstructionAPI/CMakeLists.txt create mode 100644 src/ConstructionAPI/ConstructionAPI.h create mode 100644 src/ConstructionAPI/ConstructionAPI.i create mode 100644 src/ConstructionAPI/ConstructionAPI_Point.cpp create mode 100644 src/ConstructionAPI/ConstructionAPI_Point.h create mode 100644 src/ConstructionAPI/ConstructionAPI_swig.h create mode 100644 src/ConstructionAPI/Test/CMakeLists.txt create mode 100644 src/ConstructionAPI/Test/MockModelAPI_AttributeDouble.h create mode 100644 src/ConstructionAPI/Test/MockModelAPI_Data.h create mode 100644 src/ConstructionAPI/Test/MockModelAPI_Feature.h create mode 100644 src/ConstructionAPI/Test/MockModelAPI_Object.h create mode 100644 src/ConstructionAPI/Test/TestPoint.cpp create mode 100644 src/ConstructionAPI/Test/TestPoint.py create mode 100644 src/ModelHighAPI/CMakeLists.txt create mode 100644 src/ModelHighAPI/ModelHighAPI.h create mode 100644 src/ModelHighAPI/ModelHighAPI.i create mode 100644 src/ModelHighAPI/ModelHighAPI_Double.cpp create mode 100644 src/ModelHighAPI/ModelHighAPI_Double.h create mode 100644 src/ModelHighAPI/ModelHighAPI_Interface.cpp create mode 100644 src/ModelHighAPI/ModelHighAPI_Interface.h create mode 100644 src/ModelHighAPI/ModelHighAPI_swig.h create mode 100644 src/ModelHighAPI/Test/TestDouble.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 30d8f301d..97bb0f6a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,9 @@ ADD_SUBDIRECTORY (src/InitializationPlugin) ADD_SUBDIRECTORY (src/ParametersPlugin) ADD_SUBDIRECTORY (src/PythonAddons) ADD_SUBDIRECTORY (src/PythonAPI) +# High Level C++/Python API +ADD_SUBDIRECTORY (src/ModelHighAPI) +ADD_SUBDIRECTORY (src/ConstructionAPI) IF(${HAVE_SALOME}) ADD_SUBDIRECTORY (src/SHAPERGUI) diff --git a/src/ConstructionAPI/CMakeLists.txt b/src/ConstructionAPI/CMakeLists.txt new file mode 100644 index 000000000..6242dd18c --- /dev/null +++ b/src/ConstructionAPI/CMakeLists.txt @@ -0,0 +1,69 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +INCLUDE(Common) +INCLUDE(UnitTest) + +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + + +SET(PROJECT_HEADERS + ConstructionAPI.h + ConstructionAPI_Point.h +) + +SET(PROJECT_SOURCES + ConstructionAPI_Point.cpp +) + +SET(PROJECT_LIBRARIES + ModelAPI + ModelHighAPI +) + +ADD_DEFINITIONS(-DCONSTRUCTIONAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(ConstructionAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) + +SET(CMAKE_SWIG_FLAGS "-Wall") + +SET_SOURCE_FILES_PROPERTIES(ConstructionAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(ConstructionAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI +) + +TARGET_LINK_LIBRARIES(ConstructionAPI ${PROJECT_LIBRARIES}) + +SET(SWIG_SCRIPTS + ${CMAKE_CURRENT_BINARY_DIR}/ConstructionAPI.py +) + +SET(SWIG_LINK_LIBRARIES + ConstructionAPI + ModelHighAPI + ModelAPI + ${PYTHON_LIBRARIES} +) + +SET(SWIG_MODULE_ConstructionAPI_EXTRA_DEPS ${SWIG_MODULE_ConstructionAPI_EXTRA_DEPS} + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i) + +SWIG_ADD_MODULE(ConstructionAPI python ConstructionAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(ConstructionAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_ConstructionAPI PROPERTIES DEBUG_OUTPUT_NAME _ConstructionAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _ConstructionAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS ConstructionAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) + +ADD_UNIT_TESTS( + TestPoint.py + ) + +ADD_SUBDIRECTORY (Test) diff --git a/src/ConstructionAPI/ConstructionAPI.h b/src/ConstructionAPI/ConstructionAPI.h new file mode 100644 index 000000000..31534b9fd --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef CONSTRUCTIONAPI_H +#define CONSTRUCTIONAPI_H + +#if defined CONSTRUCTIONAPI_EXPORTS +#if defined WIN32 +#define CONSTRUCTIONAPI_EXPORT __declspec( dllexport ) +#else +#define CONSTRUCTIONAPI_EXPORT +#endif +#else +#if defined WIN32 +#define CONSTRUCTIONAPI_EXPORT __declspec( dllimport ) +#else +#define CONSTRUCTIONAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/ConstructionAPI/ConstructionAPI.i b/src/ConstructionAPI/ConstructionAPI.i new file mode 100644 index 000000000..5d9a79484 --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI.i @@ -0,0 +1,17 @@ +/* ConstructionAPI.i */ +%module ConstructionAPI +%{ + #include "ConstructionAPI_swig.h" +%} + +// import other modules +%import "ModelHighAPI.i" + +// to avoid error on this +#define CONSTRUCTIONAPI_EXPORT + +// standard definitions +%include "typemaps.i" + +// all supported interfaces +%include "ConstructionAPI_Point.h" diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp new file mode 100644 index 000000000..e6e6922ae --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -0,0 +1,86 @@ +// Name : ConstructionAPI_Point.cpp +// Purpose: +// +// History: +// 29/03/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ConstructionAPI_Point.h" +//-------------------------------------------------------------------------------------- +#include +#include + +#include +//-------------------------------------------------------------------------------------- +ConstructionAPI_Point::ConstructionAPI_Point( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +ConstructionAPI_Point::ConstructionAPI_Point( + const std::shared_ptr & theFeature, + const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setPoint(theX, theY, theZ); + execute(); + } +} + +ConstructionAPI_Point::~ConstructionAPI_Point() +{ + +} + +//-------------------------------------------------------------------------------------- +bool ConstructionAPI_Point::initialize() +{ + if (!myFeature) { + throwException("ConstructionAPI_Point exception: The feature is NULL."); + return false; + } + + if (feature()->getKind() != "Point") { + throwException("ConstructionAPI_Point exception: Wrong feature kind."); + return false; + } + + // data() throws exceptions if the attribute is invalid + myX = feature()->real("x"); + myY = feature()->real("y"); + myZ = feature()->real("z"); + + if (!myX || !myY || !myZ) + return false; + + return true; +} + +//-------------------------------------------------------------------------------------- +void ConstructionAPI_Point::setPoint(const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ) +{ + theX.fillAttribute(myX); + theY.fillAttribute(myY); + theZ.fillAttribute(myZ); +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr ConstructionAPI_Point::x() const +{ + return myX; +} +std::shared_ptr ConstructionAPI_Point::y() const +{ + return myY; +} +std::shared_ptr ConstructionAPI_Point::z() const +{ + return myZ; +} diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h new file mode 100644 index 000000000..b7217a62c --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -0,0 +1,47 @@ +// Name : ConstructionAPI_Point.h +// Purpose: +// +// History: +// 29/03/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ +#define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ + +//-------------------------------------------------------------------------------------- +#include "ConstructionAPI.h" + +#include +//-------------------------------------------------------------------------------------- +class ModelAPI_AttributeDouble; +class ModelHighAPI_Double; +//-------------------------------------------------------------------------------------- +/* + * + */ +class ConstructionAPI_Point : public ModelHighAPI_Interface +{ +public: + ConstructionAPI_Point(const std::shared_ptr & theFeature); + ConstructionAPI_Point(const std::shared_ptr & theFeature, + const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ); + virtual ~ConstructionAPI_Point(); + + void setPoint(const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ); + + std::shared_ptr x() const; + std::shared_ptr y() const; + std::shared_ptr z() const; + +protected: + std::shared_ptr myX, myY, myZ; + + bool initialize(); +}; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */ diff --git a/src/ConstructionAPI/ConstructionAPI_swig.h b/src/ConstructionAPI/ConstructionAPI_swig.h new file mode 100644 index 000000000..cade6c2c7 --- /dev/null +++ b/src/ConstructionAPI/ConstructionAPI_swig.h @@ -0,0 +1,15 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ConstructionAPI_swig.h +// Created: Mar 29, 2016 +// Author: Sergey POKHODENKO + +#ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_SWIG_H_ +#define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_SWIG_H_ + + #include "ModelHighAPI_swig.h" + + #include "ConstructionAPI.h" + #include "ConstructionAPI_Point.h" + +#endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_SWIG_H_ */ diff --git a/src/ConstructionAPI/Test/CMakeLists.txt b/src/ConstructionAPI/Test/CMakeLists.txt new file mode 100644 index 000000000..ec2e920da --- /dev/null +++ b/src/ConstructionAPI/Test/CMakeLists.txt @@ -0,0 +1,45 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +add_definitions(-DGTEST_LANG_CXX11=0) + +INCLUDE(FindGTest) +#FIND_PACKAGE(GTest REQUIRED) +#INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) + +#FIND_PACKAGE(GMock REQUIRED) +#INCLUDE_DIRECTORIES(${GMOCK_INCLUDE_DIRS}) + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI + + $ENV{GTEST_ROOT}/googletest/include + $ENV{GTEST_ROOT}/googlemock/include + ) + +SET(TEST_LIBRARIES + ModelAPI + ModelHighAPI + ConstructionAPI + ) + +SET(PACKAGE_NAME "ConstructionAPI") +SET(TEST_NAME "${PACKAGE_NAME}_GTest") +SET(TARGET_NAME "Test${PACKAGE_NAME}") + +ADD_EXECUTABLE(${TARGET_NAME} + TestPoint.cpp + ) + +TARGET_LINK_LIBRARIES(${TARGET_NAME} + ${TEST_LIBRARIES} + + $ENV{GTEST_ROOT}/googlemock/make/gmock_main.a + ) + +GET_TARGET_PROPERTY(TEST_SOURCES ${TARGET_NAME} SOURCES) +GTEST_ADD_TESTS(${CMAKE_BINARY_DIR}/bin/${TARGET_NAME} + "" + ${TEST_SOURCES} + ) \ No newline at end of file diff --git a/src/ConstructionAPI/Test/MockModelAPI_AttributeDouble.h b/src/ConstructionAPI/Test/MockModelAPI_AttributeDouble.h new file mode 100644 index 000000000..a3d1fc070 --- /dev/null +++ b/src/ConstructionAPI/Test/MockModelAPI_AttributeDouble.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MockModelAPI_AttributeDouble_H_ +#define MockModelAPI_AttributeDouble_H_ + +#include + +#include + +class MockModelAPI_AttributeDouble : public ModelAPI_AttributeDouble { + public: + MOCK_METHOD1(setValue, + void(const double theValue)); + MOCK_METHOD0(value, + double()); + MOCK_METHOD1(setCalculatedValue, + void(const double theValue)); + MOCK_METHOD1(setText, + void(const std::string& theText)); + MOCK_METHOD0(text, + std::string()); + MOCK_METHOD1(setExpressionInvalid, + void(const bool theFlag)); + MOCK_METHOD0(expressionInvalid, + bool()); + MOCK_METHOD1(setExpressionError, + void(const std::string& theError)); + MOCK_METHOD0(expressionError, + std::string()); + MOCK_METHOD1(setUsedParameters, + void(const std::set& theUsedParameters)); + MOCK_CONST_METHOD0(usedParameters, + std::set()); +}; + +#endif // MockModelAPI_AttributeDouble_H_ diff --git a/src/ConstructionAPI/Test/MockModelAPI_Data.h b/src/ConstructionAPI/Test/MockModelAPI_Data.h new file mode 100644 index 000000000..c8f99a77c --- /dev/null +++ b/src/ConstructionAPI/Test/MockModelAPI_Data.h @@ -0,0 +1,98 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MockModelAPI_Data_H_ +#define MockModelAPI_Data_H_ + +#include + +#include + +class MockModelAPI_Data : public ModelAPI_Data { + public: + MOCK_METHOD0(name, + std::string()); + MOCK_METHOD1(setName, + void(const std::string& theName)); + MOCK_METHOD1(document, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(real, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(integer, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(reference, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(selection, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(selectionList, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(refattr, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(reflist, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(refattrlist, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(boolean, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(string, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(intArray, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(attribute, + std::shared_ptr(const std::string& theID)); + MOCK_METHOD1(attributes, + std::list >(const std::string& theType)); + MOCK_METHOD1(attributesIDs, + std::list(const std::string& theType)); + MOCK_METHOD1(id, + const std::string&(const std::shared_ptr& theAttr)); + MOCK_METHOD1(isEqual, + bool(const std::shared_ptr& theData)); + MOCK_METHOD0(isValid, + bool()); + MOCK_METHOD2(addAttribute, + std::shared_ptr(const std::string& theID, const std::string theAttrType)); + MOCK_METHOD1(sendAttributeUpdated, + void(ModelAPI_Attribute* theAttr)); + MOCK_METHOD1(blockSendAttributeUpdated, + void(const bool theBlock)); + MOCK_METHOD0(erase, + void()); + MOCK_METHOD1(execState, + void(const ModelAPI_ExecState theState)); + MOCK_METHOD0(execState, + ModelAPI_ExecState()); + MOCK_METHOD2(setError, + void(const std::string& theError, bool theSend)); + MOCK_CONST_METHOD0(error, + std::string()); + MOCK_CONST_METHOD0(featureId, + int()); + MOCK_METHOD0(refsToMe, + const std::set >&()); + MOCK_METHOD1(referencesToObjects, + void(std::list > > >& theRefs)); + MOCK_METHOD1(copyTo, + void(std::shared_ptr theTarget)); + MOCK_METHOD0(invalidPtr, + std::shared_ptr()); + MOCK_METHOD0(updateID, + int()); + MOCK_METHOD1(setUpdateID, + void(const int theID)); + MOCK_METHOD0(owner, + std::shared_ptr()); + MOCK_METHOD0(isDeleted, + bool()); + MOCK_METHOD1(setIsDeleted, + void(const bool theFlag)); + MOCK_METHOD0(isInHistory, + bool()); + MOCK_METHOD1(setIsInHistory, + void(const bool theFlag)); + MOCK_METHOD0(isDisplayed, + bool()); + MOCK_METHOD1(setDisplayed, + void(const bool theDisplay)); +}; + +#endif // MockModelAPI_Data_H_ diff --git a/src/ConstructionAPI/Test/MockModelAPI_Feature.h b/src/ConstructionAPI/Test/MockModelAPI_Feature.h new file mode 100644 index 000000000..47ef1f319 --- /dev/null +++ b/src/ConstructionAPI/Test/MockModelAPI_Feature.h @@ -0,0 +1,46 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MockModelAPI_Feature_H_ +#define MockModelAPI_Feature_H_ + +#include + +#include + +class MockModelAPI_Feature : public ModelAPI_Feature { + // ModelAPI_Object + public: + MOCK_METHOD0(groupName, + std::string()); + MOCK_METHOD0(initAttributes, + void()); + MOCK_METHOD0(isDisabled, + bool()); + MOCK_METHOD3(colorConfigInfo, + void(std::string& theSection, std::string& theName, std::string& theDefault)); + MOCK_METHOD0(init, + void()); + MOCK_CONST_METHOD0(data, + std::shared_ptr()); + + // ModelAPI_Feature + public: + MOCK_METHOD0(getKind, + const std::string&()); + MOCK_CONST_METHOD0(document, + std::shared_ptr()); + MOCK_METHOD0(execute, + void()); + MOCK_METHOD1(compute, + bool(const std::string& theAttributeId)); + MOCK_METHOD2(setError, + void(std::string, bool)); + MOCK_CONST_METHOD0(error, + std::string()); + MOCK_METHOD0(isPersistentResult, + bool()); + MOCK_METHOD0(isAction, + bool()); +}; + +#endif // MockModelAPI_Feature_H_ diff --git a/src/ConstructionAPI/Test/MockModelAPI_Object.h b/src/ConstructionAPI/Test/MockModelAPI_Object.h new file mode 100644 index 000000000..ad865af5c --- /dev/null +++ b/src/ConstructionAPI/Test/MockModelAPI_Object.h @@ -0,0 +1,24 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MockModelAPI_Object_H_ +#define MockModelAPI_Object_H_ + +#include + +#include + +class MockModelAPI_Object : public ModelAPI_Object { + public: + MOCK_METHOD0(groupName, + std::string()); + MOCK_METHOD0(initAttributes, + void()); + MOCK_METHOD0(isDisabled, + bool()); + MOCK_METHOD3(colorConfigInfo, + void(std::string& theSection, std::string& theName, std::string& theDefault)); + MOCK_METHOD0(init, + virtual void MODELAPI_EXPORT()); +}; + +#endif // MockModelAPI_Object_H_ diff --git a/src/ConstructionAPI/Test/TestPoint.cpp b/src/ConstructionAPI/Test/TestPoint.cpp new file mode 100644 index 000000000..bada269f8 --- /dev/null +++ b/src/ConstructionAPI/Test/TestPoint.cpp @@ -0,0 +1,114 @@ +#include +#include + +#include +#include + +#include +#include +#include + +#include "MockModelAPI_AttributeDouble.h" +#include "MockModelAPI_Data.h" +#include "MockModelAPI_Feature.h" + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRefOfCopy; +using ::testing::Test; + +void null_deleter(void *) {} + +class MockEvents_Listener : public Events_Listener { +public: + MOCK_METHOD1(processEvent, + void(const std::shared_ptr& theMessage)); +}; + +class ConstructionAPI_Point_Constructor_Test : public Test { +public: + MockEvents_Listener aErrorListener; + MockModelAPI_AttributeDouble aMockAttributeDouble; + MockModelAPI_Data aMockData; + MockModelAPI_Feature aMockFeature; + + ConstructionAPI_Point_Constructor_Test() { + ON_CALL(aMockFeature, getKind()) + .WillByDefault(ReturnRefOfCopy(std::string("Point"))); + + ON_CALL(aMockFeature, data()) + .WillByDefault(Return(std::shared_ptr(&aMockData, &null_deleter))); + + ON_CALL(aMockData, real(_)) + .WillByDefault(Return(std::shared_ptr(&aMockAttributeDouble, &null_deleter))); + + Events_Loop::loop()->registerListener(&aErrorListener, Events_Error::errorID()); + } + + ~ConstructionAPI_Point_Constructor_Test() { + Events_Loop::loop()->removeListener(&aErrorListener); + } + + void testUsingAttributes() { + EXPECT_CALL(aMockFeature, getKind()); + + EXPECT_CALL(aMockFeature, data()) + .Times(3); + + EXPECT_CALL(aMockData, real("x")); + EXPECT_CALL(aMockData, real("y")); + EXPECT_CALL(aMockData, real("z")); + } + +}; + +TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeature_SendException) { + FeaturePtr aFeature; + + EXPECT_CALL(aErrorListener, processEvent(_)); + + ConstructionAPI_Point aPoint(aFeature); +} + +TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeatureAndValues_SendException) { + FeaturePtr aFeature; + + EXPECT_CALL(aErrorListener, processEvent(_)); + + ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30")); +} + +TEST_F(ConstructionAPI_Point_Constructor_Test, GetWrongFeature_SendException) { + FeaturePtr aFeature(&aMockFeature, &null_deleter); + + ON_CALL(aMockFeature, getKind()) + .WillByDefault(ReturnRefOfCopy(std::string("WrongKind"))); + + EXPECT_CALL(aMockFeature, getKind()); + EXPECT_CALL(aErrorListener, processEvent(_)); + + ConstructionAPI_Point aPoint(aFeature); +} + + +TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) { + FeaturePtr aFeature(&aMockFeature, &null_deleter); + + testUsingAttributes(); + + ConstructionAPI_Point aPoint(aFeature); +} + +TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) { + FeaturePtr aFeature(&aMockFeature, &null_deleter); + + testUsingAttributes(); + + EXPECT_CALL(aMockAttributeDouble, setValue(10)); + EXPECT_CALL(aMockAttributeDouble, setText("20")); + EXPECT_CALL(aMockAttributeDouble, setText("x + 30")); + + EXPECT_CALL(aMockFeature, execute()); + + ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30")); +} diff --git a/src/ConstructionAPI/Test/TestPoint.py b/src/ConstructionAPI/Test/TestPoint.py new file mode 100644 index 000000000..7c184c5c5 --- /dev/null +++ b/src/ConstructionAPI/Test/TestPoint.py @@ -0,0 +1,37 @@ +import unittest + +import ModelAPI +import ConstructionAPI + +class PointTestCase(unittest.TestCase): + + def setUp(self): + self.session = ModelAPI.ModelAPI_Session.get() + self.doc = self.session.moduleDocument() + self.session.startOperation() + self.feature = self.doc.addFeature("Point") + self.feature.execute() + self.session.finishOperation() + + def tearDown(self): + self.session.closeAll() + + def test_ConstructorWithValues(self): + point = ConstructionAPI.ConstructionAPI_Point(self.feature, 10, "20", "x + 30") + self.assertEqual(10, point.x().value()) + self.assertEqual("20", point.y().text()) + self.assertEqual("x + 30", point.z().text()) + + def test_setValue(self): + point = ConstructionAPI.ConstructionAPI_Point(self.feature) + self.assertEqual(0, point.x().value()) + self.assertEqual(0, point.y().value()) + self.assertEqual(0, point.z().value()) + + point.setPoint(10, "20", "x + 30") + self.assertEqual(10, point.x().value()) + self.assertEqual("20", point.y().text()) + self.assertEqual("x + 30", point.z().text()) + +if __name__ == "__main__": + unittest.main() diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt new file mode 100644 index 000000000..bd17b71b7 --- /dev/null +++ b/src/ModelHighAPI/CMakeLists.txt @@ -0,0 +1,64 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE(UnitTest) + +SET(PROJECT_HEADERS + ModelHighAPI.h + ModelHighAPI_Double.h + ModelHighAPI_Interface.h + ) + +SET(PROJECT_SOURCES + ModelHighAPI_Double.cpp + ModelHighAPI_Interface.cpp + ) + +SET(PROJECT_LIBRARIES + Config + Events + ) + +SET(CMAKE_SWIG_FLAGS -threads -Wall) +ADD_DEFINITIONS(-DModelHighAPI_EXPORTS) + +ADD_LIBRARY(ModelHighAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +SET_TARGET_PROPERTIES(ModelHighAPI PROPERTIES LINKER_LANGUAGE CXX) +TARGET_LINK_LIBRARIES(ModelHighAPI ${PROJECT_LIBRARIES}) + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/ModelAPI +# ${PROJECT_SOURCE_DIR}/src/GeomAPI +# ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI +) + + +SET_SOURCE_FILES_PROPERTIES(ModelHighAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(ModelHighAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +SET(SWIG_SCRIPTS + ${CMAKE_CURRENT_BINARY_DIR}/ModelHighAPI.py + ) + +SET(SWIG_LINK_LIBRARIES + ModelHighAPI + ${PYTHON_LIBRARIES} + ) + +SWIG_ADD_MODULE(ModelHighAPI python ModelHighAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(ModelHighAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_ModelHighAPI PROPERTIES DEBUG_OUTPUT_NAME _ModelHighAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _ModelHighAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS ModelHighAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) + +ADD_UNIT_TESTS( + TestDouble.py + ) diff --git a/src/ModelHighAPI/ModelHighAPI.h b/src/ModelHighAPI/ModelHighAPI.h new file mode 100644 index 000000000..b04e8a93e --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef MODELHIGHAPI_H +#define MODELHIGHAPI_H + +#if defined MODELHIGHAPI_EXPORTS +#if defined WIN32 +#define MODELHIGHAPI_EXPORT __declspec( dllexport ) +#else +#define MODELHIGHAPI_EXPORT +#endif +#else +#if defined WIN32 +#define MODELHIGHAPI_EXPORT __declspec( dllimport ) +#else +#define MODELHIGHAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i new file mode 100644 index 000000000..413ba1a94 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -0,0 +1,34 @@ +/* ModelHighAPI.i */ +%module ModelHighAPI +%{ + #include "ModelHighAPI_swig.h" +%} + +// to avoid error on this +#define ModelHighAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_string.i" + +// all supported interfaces +%include "ModelHighAPI_Double.h" + +// typemaps +%typemap(in) const ModelHighAPI_Double & (ModelHighAPI_Double temp) { + if (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) { + temp = ModelHighAPI_Double(PyFloat_AsDouble($input)); + $1 = &temp; + } else if (PyString_Check($input)) { + temp = ModelHighAPI_Double(PyString_AsString($input)); + $1 = &temp; + } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { + } else { + PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Double, float, int or string."); + return NULL; + } +} + +%typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Double, const ModelHighAPI_Double & { + $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input)) ? 1 : 0; +} diff --git a/src/ModelHighAPI/ModelHighAPI_Double.cpp b/src/ModelHighAPI/ModelHighAPI_Double.cpp new file mode 100644 index 000000000..ca1f661a9 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Double.cpp @@ -0,0 +1,53 @@ +// Name : ModelHighAPI_Double.cpp +// Purpose: +// +// History: +// 29/03/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ModelHighAPI_Double.h" + +#include +//-------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------- +ModelHighAPI_Double::ModelHighAPI_Double() +{ +} + +ModelHighAPI_Double::ModelHighAPI_Double(double theValue) +: myValue(theValue) +{ +} + +ModelHighAPI_Double::ModelHighAPI_Double(const std::string & theValue) +: myValue(theValue) +{ +} + +ModelHighAPI_Double::ModelHighAPI_Double(const char * theValue) +: myValue(theValue) +{ +} + +ModelHighAPI_Double::~ModelHighAPI_Double() +{ +} + +//-------------------------------------------------------------------------------------- +struct fill_visitor : boost::static_visitor +{ + mutable std::shared_ptr myAttribute; + + fill_visitor(std::shared_ptr & theAttribute) + : myAttribute(theAttribute) {} + + void operator()(double theValue) const { myAttribute->setValue(theValue); } + void operator()(const std::string & theValue) const { myAttribute->setText(theValue); } +}; + +void ModelHighAPI_Double::fillAttribute( + std::shared_ptr & theAttribute) const +{ + boost::apply_visitor(fill_visitor(theAttribute), myValue); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Double.h b/src/ModelHighAPI/ModelHighAPI_Double.h new file mode 100644 index 000000000..316703405 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Double.h @@ -0,0 +1,38 @@ +// Name : ModelHighAPI_Double.h +// Purpose: +// +// History: +// 29/03/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_DOUBLE_H_ +#define SRC_MODELHIGHAPI_MODELHIGHAPI_DOUBLE_H_ + +//-------------------------------------------------------------------------------------- +#include +#include + +#include +//-------------------------------------------------------------------------------------- +class ModelAPI_AttributeDouble; +//-------------------------------------------------------------------------------------- +/* + * + */ +class ModelHighAPI_Double +{ +public: + ModelHighAPI_Double(); + ModelHighAPI_Double(double theValue); + ModelHighAPI_Double(const std::string & theValue); + ModelHighAPI_Double(const char * theValue); + virtual ~ModelHighAPI_Double(); + + virtual void fillAttribute(std::shared_ptr & theAttribute) const; + +private: + boost::variant myValue; +}; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_DOUBLE_H_ */ diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp new file mode 100644 index 000000000..a72146ab6 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -0,0 +1,39 @@ +// Name : ModelHighAPI_Interface.cpp +// Purpose: +// +// History: +// 17/05/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ModelHighAPI_Interface.h" +//-------------------------------------------------------------------------------------- +#include + +#include +//-------------------------------------------------------------------------------------- +ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr & theFeature) +: myFeature(theFeature) +{ + +} + +ModelHighAPI_Interface::~ModelHighAPI_Interface() +{ + +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr ModelHighAPI_Interface::feature() const +{ + return myFeature; +} + +void ModelHighAPI_Interface::execute() +{ + feature()->execute(); +} + +void ModelHighAPI_Interface::throwException(const std::string & theDescription) +{ + Events_Error::send(theDescription); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.h b/src/ModelHighAPI/ModelHighAPI_Interface.h new file mode 100644 index 000000000..111cbf456 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Interface.h @@ -0,0 +1,40 @@ +// Name : ModelHighAPI_Interface.h +// Purpose: +// +// History: +// 17/05/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_ +#define SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_ + +//-------------------------------------------------------------------------------------- +#include +#include +//-------------------------------------------------------------------------------------- +class ModelAPI_Feature; +//-------------------------------------------------------------------------------------- +/* + * + */ +class ModelHighAPI_Interface +{ +public: + explicit ModelHighAPI_Interface(const std::shared_ptr & theFeature); + virtual ~ModelHighAPI_Interface(); + + /// Return ModelAPI_Feature + std::shared_ptr feature() const; + + /// Shortcut for feature()->execute() + void execute(); + + /// Throw exception to event loop. + void throwException(const std::string & theDescription); + +protected: + std::shared_ptr myFeature; +}; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_ */ diff --git a/src/ModelHighAPI/ModelHighAPI_swig.h b/src/ModelHighAPI/ModelHighAPI_swig.h new file mode 100644 index 000000000..f5a8471c9 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_swig.h @@ -0,0 +1,15 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelHighAPI_swig.h +// Created: Mar 29, 2016 +// Author: Sergey POKHODENKO + +#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_ +#define SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_ + + #include + + #include "ModelHighAPI.h" + #include "ModelHighAPI_Double.h" + +#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_ */ diff --git a/src/ModelHighAPI/Test/TestDouble.py b/src/ModelHighAPI/Test/TestDouble.py new file mode 100644 index 000000000..6009e720a --- /dev/null +++ b/src/ModelHighAPI/Test/TestDouble.py @@ -0,0 +1,20 @@ +import unittest + +import ModelHighAPI + +class DoubleTestCase(unittest.TestCase): + + def test_create_default(self): + default = ModelHighAPI.ModelHighAPI_Double() + + def test_create_from_double(self): + from_double = ModelHighAPI.ModelHighAPI_Double(100.) + self.assertEqual(100., from_double.value()) + + def test_create_from_text(self): + from_string = ModelHighAPI.ModelHighAPI_Double("200 + x") + self.assertEqual("200 + x", from_string.text()) + + +if __name__ == "__main__": + unittest.main() -- 2.39.2