Salome HOME
Add ModelHighAPI & ConstructionAPI pachages
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 24 May 2016 13:08:19 +0000 (16:08 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:24:14 +0000 (14:24 +0300)
23 files changed:
CMakeLists.txt
src/ConstructionAPI/CMakeLists.txt [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI.h [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI.i [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI_Point.cpp [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI_Point.h [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI_swig.h [new file with mode: 0644]
src/ConstructionAPI/Test/CMakeLists.txt [new file with mode: 0644]
src/ConstructionAPI/Test/MockModelAPI_AttributeDouble.h [new file with mode: 0644]
src/ConstructionAPI/Test/MockModelAPI_Data.h [new file with mode: 0644]
src/ConstructionAPI/Test/MockModelAPI_Feature.h [new file with mode: 0644]
src/ConstructionAPI/Test/MockModelAPI_Object.h [new file with mode: 0644]
src/ConstructionAPI/Test/TestPoint.cpp [new file with mode: 0644]
src/ConstructionAPI/Test/TestPoint.py [new file with mode: 0644]
src/ModelHighAPI/CMakeLists.txt [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI.i [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Double.cpp [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Double.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Interface.cpp [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Interface.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_swig.h [new file with mode: 0644]
src/ModelHighAPI/Test/TestDouble.py [new file with mode: 0644]

index 4a24cfde48c3e721a172bf80bec93ac8b52b5e15..7d29b74ad15ac897f2222446491ebac24b8e38ba 100644 (file)
@@ -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 (file)
index 0000000..6242dd1
--- /dev/null
@@ -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 (file)
index 0000000..31534b9
--- /dev/null
@@ -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 (file)
index 0000000..5d9a794
--- /dev/null
@@ -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 (file)
index 0000000..e6e6922
--- /dev/null
@@ -0,0 +1,86 @@
+// Name   : ConstructionAPI_Point.cpp
+// Purpose: 
+//
+// History:
+// 29/03/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ConstructionAPI_Point.h"
+//--------------------------------------------------------------------------------------
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Feature.h>
+
+#include <ModelHighAPI_Double.h>
+//--------------------------------------------------------------------------------------
+ConstructionAPI_Point::ConstructionAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+ConstructionAPI_Point::ConstructionAPI_Point(
+    const std::shared_ptr<ModelAPI_Feature> & 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<ModelAPI_AttributeDouble> ConstructionAPI_Point::x() const
+{
+  return myX;
+}
+std::shared_ptr<ModelAPI_AttributeDouble> ConstructionAPI_Point::y() const
+{
+  return myY;
+}
+std::shared_ptr<ModelAPI_AttributeDouble> ConstructionAPI_Point::z() const
+{
+  return myZ;
+}
diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h
new file mode 100644 (file)
index 0000000..b7217a6
--- /dev/null
@@ -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 <ModelHighAPI_Interface.h>
+//--------------------------------------------------------------------------------------
+class ModelAPI_AttributeDouble;
+class ModelHighAPI_Double;
+//--------------------------------------------------------------------------------------
+/*
+ *
+ */
+class ConstructionAPI_Point : public ModelHighAPI_Interface
+{
+public:
+  ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+  ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature> & 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<ModelAPI_AttributeDouble> x() const;
+  std::shared_ptr<ModelAPI_AttributeDouble> y() const;
+  std::shared_ptr<ModelAPI_AttributeDouble> z() const;
+
+protected:
+  std::shared_ptr<ModelAPI_AttributeDouble> 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 (file)
index 0000000..cade6c2
--- /dev/null
@@ -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 (file)
index 0000000..ec2e920
--- /dev/null
@@ -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 (file)
index 0000000..a3d1fc0
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockModelAPI_AttributeDouble_H_
+#define MockModelAPI_AttributeDouble_H_
+
+#include <gmock/gmock.h>
+
+#include <ModelAPI_AttributeDouble.h>
+
+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<std::string>& theUsedParameters));
+  MOCK_CONST_METHOD0(usedParameters,
+      std::set<std::string>());
+};
+
+#endif // MockModelAPI_AttributeDouble_H_
diff --git a/src/ConstructionAPI/Test/MockModelAPI_Data.h b/src/ConstructionAPI/Test/MockModelAPI_Data.h
new file mode 100644 (file)
index 0000000..c8f99a7
--- /dev/null
@@ -0,0 +1,98 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockModelAPI_Data_H_
+#define MockModelAPI_Data_H_
+
+#include <gmock/gmock.h>
+
+#include <ModelAPI_Data.h>
+
+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<ModelAPI_AttributeDocRef>(const std::string& theID));
+  MOCK_METHOD1(real,
+      std::shared_ptr<ModelAPI_AttributeDouble>(const std::string& theID));
+  MOCK_METHOD1(integer,
+      std::shared_ptr<ModelAPI_AttributeInteger>(const std::string& theID));
+  MOCK_METHOD1(reference,
+      std::shared_ptr<ModelAPI_AttributeReference>(const std::string& theID));
+  MOCK_METHOD1(selection,
+      std::shared_ptr<ModelAPI_AttributeSelection>(const std::string& theID));
+  MOCK_METHOD1(selectionList,
+      std::shared_ptr<ModelAPI_AttributeSelectionList>(const std::string& theID));
+  MOCK_METHOD1(refattr,
+      std::shared_ptr<ModelAPI_AttributeRefAttr>(const std::string& theID));
+  MOCK_METHOD1(reflist,
+      std::shared_ptr<ModelAPI_AttributeRefList>(const std::string& theID));
+  MOCK_METHOD1(refattrlist,
+      std::shared_ptr<ModelAPI_AttributeRefAttrList>(const std::string& theID));
+  MOCK_METHOD1(boolean,
+      std::shared_ptr<ModelAPI_AttributeBoolean>(const std::string& theID));
+  MOCK_METHOD1(string,
+      std::shared_ptr<ModelAPI_AttributeString>(const std::string& theID));
+  MOCK_METHOD1(intArray,
+      std::shared_ptr<ModelAPI_AttributeIntArray>(const std::string& theID));
+  MOCK_METHOD1(attribute,
+      std::shared_ptr<ModelAPI_Attribute>(const std::string& theID));
+  MOCK_METHOD1(attributes,
+      std::list<std::shared_ptr<ModelAPI_Attribute> >(const std::string& theType));
+  MOCK_METHOD1(attributesIDs,
+      std::list<std::string>(const std::string& theType));
+  MOCK_METHOD1(id,
+      const std::string&(const std::shared_ptr<ModelAPI_Attribute>& theAttr));
+  MOCK_METHOD1(isEqual,
+      bool(const std::shared_ptr<ModelAPI_Data>& theData));
+  MOCK_METHOD0(isValid,
+      bool());
+  MOCK_METHOD2(addAttribute,
+      std::shared_ptr<ModelAPI_Attribute>(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<std::shared_ptr<ModelAPI_Attribute> >&());
+  MOCK_METHOD1(referencesToObjects,
+      void(std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs));
+  MOCK_METHOD1(copyTo,
+      void(std::shared_ptr<ModelAPI_Data> theTarget));
+  MOCK_METHOD0(invalidPtr,
+      std::shared_ptr<ModelAPI_Data>());
+  MOCK_METHOD0(updateID,
+      int());
+  MOCK_METHOD1(setUpdateID,
+      void(const int theID));
+  MOCK_METHOD0(owner,
+      std::shared_ptr<ModelAPI_Object>());
+  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 (file)
index 0000000..47ef1f3
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockModelAPI_Feature_H_
+#define MockModelAPI_Feature_H_
+
+#include <gmock/gmock.h>
+
+#include <ModelAPI_Feature.h>
+
+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_Data>());
+
+  // ModelAPI_Feature
+ public:
+  MOCK_METHOD0(getKind,
+      const std::string&());
+  MOCK_CONST_METHOD0(document,
+      std::shared_ptr<ModelAPI_Document>());
+  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 (file)
index 0000000..ad865af
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockModelAPI_Object_H_
+#define MockModelAPI_Object_H_
+
+#include <gmock/gmock.h>
+
+#include <ModelAPI_Object.h>
+
+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 (file)
index 0000000..bada269
--- /dev/null
@@ -0,0 +1,114 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <Events_Loop.h>
+#include <Events_Error.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelHighAPI_Double.h>
+#include <ConstructionAPI_Point.h>
+
+#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<Events_Message>& 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<ModelAPI_Data>(&aMockData, &null_deleter)));
+
+    ON_CALL(aMockData, real(_))
+      .WillByDefault(Return(std::shared_ptr<ModelAPI_AttributeDouble>(&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 (file)
index 0000000..7c184c5
--- /dev/null
@@ -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 (file)
index 0000000..bd17b71
--- /dev/null
@@ -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 (file)
index 0000000..b04e8a9
--- /dev/null
@@ -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 (file)
index 0000000..413ba1a
--- /dev/null
@@ -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 (file)
index 0000000..ca1f661
--- /dev/null
@@ -0,0 +1,53 @@
+// Name   : ModelHighAPI_Double.cpp
+// Purpose: 
+//
+// History:
+// 29/03/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_Double.h"
+
+#include <ModelAPI_AttributeDouble.h>
+//--------------------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------------------
+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<void>
+{
+  mutable std::shared_ptr<ModelAPI_AttributeDouble> myAttribute;
+
+  fill_visitor(std::shared_ptr<ModelAPI_AttributeDouble> & 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<ModelAPI_AttributeDouble> & 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 (file)
index 0000000..3167034
--- /dev/null
@@ -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 <memory>
+#include <string>
+
+#include <boost/variant.hpp>
+//--------------------------------------------------------------------------------------
+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<ModelAPI_AttributeDouble> & theAttribute) const;
+
+private:
+  boost::variant<double, std::string> 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 (file)
index 0000000..a72146a
--- /dev/null
@@ -0,0 +1,39 @@
+// Name   : ModelHighAPI_Interface.cpp
+// Purpose: 
+//
+// History:
+// 17/05/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_Interface.h"
+//--------------------------------------------------------------------------------------
+#include <Events_Error.h>
+
+#include <ModelAPI_Feature.h>
+//--------------------------------------------------------------------------------------
+ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: myFeature(theFeature)
+{
+
+}
+
+ModelHighAPI_Interface::~ModelHighAPI_Interface()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
+std::shared_ptr<ModelAPI_Feature> 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 (file)
index 0000000..111cbf4
--- /dev/null
@@ -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 <memory>
+#include <string>
+//--------------------------------------------------------------------------------------
+class ModelAPI_Feature;
+//--------------------------------------------------------------------------------------
+/*
+ *
+ */
+class ModelHighAPI_Interface
+{
+public:
+  explicit ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+  virtual ~ModelHighAPI_Interface();
+
+  /// Return ModelAPI_Feature
+  std::shared_ptr<ModelAPI_Feature> feature() const;
+
+  /// Shortcut for feature()->execute()
+  void execute();
+
+  /// Throw exception to event loop.
+  void throwException(const std::string & theDescription);
+
+protected:
+  std::shared_ptr<ModelAPI_Feature> 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 (file)
index 0000000..f5a8471
--- /dev/null
@@ -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 <ModelAPI.h>
+
+  #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 (file)
index 0000000..6009e72
--- /dev/null
@@ -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()