Salome HOME
Add ModelHighAPI_Selection & ConstructionAPI_Plane
authorspo <sergey.pokhodenko@opencascade.com>
Mon, 6 Jun 2016 09:22:12 +0000 (12:22 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:03 +0000 (14:41 +0300)
12 files changed:
src/ConstructionAPI/CMakeLists.txt
src/ConstructionAPI/ConstructionAPI.i
src/ConstructionAPI/ConstructionAPI_Plane.cpp [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI_Plane.h [new file with mode: 0644]
src/ConstructionAPI/ConstructionAPI_swig.h
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/Mock/MockModelAPI_AttributeSelection.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Selection.cpp [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Selection.h [new file with mode: 0644]
src/ModelHighAPI/Test/CMakeLists.txt
src/ModelHighAPI/Test/TestDouble.cpp
src/ModelHighAPI/Test/TestSelection.cpp [new file with mode: 0644]

index ec44137b4b90cf1993e58ab3426c2a0d27cafd60..5a416970993e415969926b3d558aad1c33f4804e 100644 (file)
@@ -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
 )
 
index 0ba605b9c6977b1a9b451fe3d38a0cb8695e26fb..d09f8d516484be5cc5986d6e2e19b007e02bc000 100644 (file)
@@ -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 (file)
index 0000000..103d9d6
--- /dev/null
@@ -0,0 +1,69 @@
+// Name   : ConstructionAPI_Plane.cpp
+// Purpose: 
+//
+// History:
+// 27/05/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ConstructionAPI_Plane.h"
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Selection.h>
+//--------------------------------------------------------------------------------------
+ConstructionAPI_Plane::ConstructionAPI_Plane(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+ConstructionAPI_Plane::ConstructionAPI_Plane(
+    const std::shared_ptr<ModelAPI_Feature> & 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<ModelAPI_Feature> & 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 (file)
index 0000000..a71c23e
--- /dev/null
@@ -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 <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+//--------------------------------------------------------------------------------------
+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<ModelAPI_Feature> & theFeature);
+  /// Constructor with values
+  ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                        const ModelHighAPI_Selection & theFace,
+                        const ModelHighAPI_Double & theDistance);
+  /// Constructor with values
+  ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature> & 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<ConstructionAPI_Plane> PlanePtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_PLANE_H_ */
index 4cdc3fb817cb261e8cb76df6527c630d02a9ee6e..84dc5195843ea9f222d9018781f60313d91139c0 100644 (file)
@@ -9,6 +9,7 @@
 
   #include <ModelHighAPI_swig.h>
 
+  #include "ConstructionAPI_Plane.h"
   #include "ConstructionAPI_Point.h"
 
 #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_SWIG_H_ */
index c9fa67ca823bd7492d017a34236fd308c08aa018..c7fed3344dc890f37e76041b6286d00bfbcd7e2a 100644 (file)
@@ -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 (file)
index 0000000..ace9493
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockModelAPI_AttributeSelection_H_
+#define MockModelAPI_AttributeSelection_H_
+
+#include <gmock/gmock.h>
+
+#include <ModelAPI_AttributeSelection.h>
+
+class MockModelAPI_AttributeSelection : public ModelAPI_AttributeSelection {
+ public:
+  MOCK_METHOD3(setValue,
+      void(const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+           const bool theTemporarily));
+  MOCK_METHOD0(value,
+      std::shared_ptr<GeomAPI_Shape>());
+  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 (file)
index 0000000..1c2cca5
--- /dev/null
@@ -0,0 +1,46 @@
+// Name   : ModelHighAPI_Selection.cpp
+// Purpose: 
+//
+// History:
+// 06/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_Selection.h"
+
+#include <ModelAPI_AttributeSelection.h>
+//--------------------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------------------
+ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
+                                               const std::shared_ptr<GeomAPI_Shape>& 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<void>
+{
+  mutable std::shared_ptr<ModelAPI_AttributeSelection> myAttribute;
+
+  fill_visitor(std::shared_ptr<ModelAPI_AttributeSelection> & 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<ModelAPI_AttributeSelection> & 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 (file)
index 0000000..a397004
--- /dev/null
@@ -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 <memory>
+#include <string>
+#include <utility>
+
+#include <boost/variant.hpp>
+//--------------------------------------------------------------------------------------
+class GeomAPI_Shape;
+class ModelAPI_AttributeSelection;
+class ModelAPI_Result;
+//--------------------------------------------------------------------------------------
+typedef std::pair<std::shared_ptr<ModelAPI_Result>, std::shared_ptr<GeomAPI_Shape> > ResultSubShapePair;
+typedef std::pair<std::string, std::string> 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<ModelAPI_Result>& theContext = std::shared_ptr<ModelAPI_Result>(),
+                         const std::shared_ptr<GeomAPI_Shape>& theSubShape = std::shared_ptr<GeomAPI_Shape>());
+  /// 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<ModelAPI_AttributeSelection> & theAttribute) const;
+
+private:
+  boost::variant<ResultSubShapePair, TypeSubShapeNamePair> myValue;
+};
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SELECTION_H_ */
index 2af368b68fa406b5972aa32b8923d062fd1e3d2e..b99ca948e5d8ba7a084e6f2658f9ad6d74b81452 100644 (file)
@@ -4,6 +4,7 @@ include(GTest)
 
 set(PROJECT_SOURCES
   TestDouble.cpp
+  TestSelection.cpp
 )
 
 include_directories(
index 546db2d73f96a479e17f453f6fc4ea61722447c5..dcba7f35d0ff9b0ba328af275bcb5ead963e59db 100644 (file)
@@ -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 (file)
index 0000000..11ac67e
--- /dev/null
@@ -0,0 +1,53 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <ModelHighAPI_Selection.h>
+
+#include <MockModelAPI_AttributeSelection.h>
+
+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<ModelAPI_AttributeSelection> anAttributeSelection;
+
+  HighModelAPI_Selection_Test() {
+    anAttributeSelection = std::shared_ptr<ModelAPI_AttributeSelection>(&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<ModelAPI_Result> aResult;
+  std::shared_ptr<GeomAPI_Shape> 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);
+}