Salome HOME
Unit test of basic SketchPlugin functionality added.
authorsbh <sergey.belash@opencascade.com>
Wed, 23 Jul 2014 11:28:40 +0000 (15:28 +0400)
committersbh <sergey.belash@opencascade.com>
Wed, 23 Jul 2014 11:28:40 +0000 (15:28 +0400)
CMakeCommon/FindPython.cmake
CMakeLists.txt
src/GeomDataAPI/GeomDataAPI.i
src/ModelAPI/ModelAPI.i
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/TestSketchBasics.py [new file with mode: 0644]

index 0a63c5b9d367161861d0f0da85ae23e04ec53ed9..6af6239ebb9bbdd399238bcb06bc629f2b4e69a0 100644 (file)
@@ -12,6 +12,7 @@ ENDIF()
 FILE(TO_CMAKE_PATH "$ENV{PYTHON_LIB_DIR}/${PYTHON_LIBRARY_FILE}" PYTHON_LIBRARY)
 FILE(TO_CMAKE_PATH $ENV{PYTHON_INC_DIR} PYTHON_INCLUDE_DIR)
 FIND_PACKAGE(PythonLibs)
+FIND_PACKAGE(PythonInterp REQUIRED)
 
 INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR})
 MESSAGE(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
index 496b3f5f14400b263cf20ce3399ecff26e0b3652..b4b8c4783a1dd76efa676f1c77feceb2adea0110 100644 (file)
@@ -63,5 +63,4 @@ IF(${HAVE_SALOME})
        ADD_SUBDIRECTORY (src/NewGeom)
 ENDIF(${HAVE_SALOME})
 
-FIND_PACKAGE(PythonInterp REQUIRED)
 ENABLE_TESTING()
index 455e0122e642146eaa073e5176c52bd11564da39..60383198362fa802548a38065d33f5d3219486ef 100644 (file)
@@ -1,28 +1,43 @@
 /* GeomDataAPI.i */
 %module GeomDataAPI
 %{
+  #include <boost/shared_ptr.hpp>
+
+  #include "ModelAPI_Attribute.h"
   #include "GeomDataAPI.h"
   #include "GeomDataAPI_Point.h"
   #include "GeomDataAPI_Dir.h"
   #include "GeomDataAPI_Point2D.h"
-  #include <boost/shared_ptr.hpp>
+  
+  template<class T> boost::shared_ptr<T> castTo(boost::shared_ptr<ModelAPI_Attribute> theObject) 
+  { 
+    return boost::dynamic_pointer_cast<T>(theObject); 
+  } 
 %}
 
 // to avoid error on this
 #define GEOMDATAAPI_EXPORT
+#define MODELAPI_EXPORT
 
 // standard definitions
 %include "typemaps.i"
 %include "std_string.i"
-//%include <std_shared_ptr.i>
+%include "std_list.i"
 
 // boost pointers
 %include <boost_shared_ptr.i>
+%shared_ptr(ModelAPI_Attribute)
 %shared_ptr(GeomDataAPI_Point)
 %shared_ptr(GeomDataAPI_Dir)
 %shared_ptr(GeomDataAPI_Point2D)
 
 // all supported interfaces
+%include "ModelAPI_Attribute.h"
 %include "GeomDataAPI_Point.h"
 %include "GeomDataAPI_Dir.h"
 %include "GeomDataAPI_Point2D.h"
+
+template<class T> boost::shared_ptr<T> castTo(boost::shared_ptr<ModelAPI_Attribute> theObject);
+%template(geomDataAPI_Point) castTo<GeomDataAPI_Point>;
+%template(geomDataAPI_Dir) castTo<GeomDataAPI_Dir>;
+%template(geomDataAPI_Point2D) castTo<GeomDataAPI_Point2D>;
index 44e9dd81ea4a7c424c5384a3c9033351267082b2..b6a337d3e38ba0d3b448b52e2463649b3d88333f 100644 (file)
@@ -13,6 +13,8 @@
   #include "ModelAPI_AttributeReference.h"
   #include "ModelAPI_AttributeRefAttr.h"
   #include "ModelAPI_Validator.h"
+  #include "ModelAPI_AttributeRefList.h"
+  #include "ModelAPI_Result.h"
 %}
 
 // to avoid error on this
@@ -21,7 +23,7 @@
 // standard definitions
 %include "typemaps.i"
 %include "std_string.i"
-//%include <std_shared_ptr.i>
+%include "std_list.i"
 
 // boost pointers
 %include <boost_shared_ptr.i>
@@ -35,6 +37,8 @@
 %shared_ptr(ModelAPI_AttributeDouble)
 %shared_ptr(ModelAPI_AttributeReference)
 %shared_ptr(ModelAPI_AttributeRefAttr)
+%shared_ptr(ModelAPI_AttributeRefList)
+%shared_ptr(ModelAPI_Result)
 
 // all supported interfaces
 %include "ModelAPI_Document.h"
@@ -47,4 +51,8 @@
 %include "ModelAPI_AttributeDouble.h"
 %include "ModelAPI_AttributeReference.h"
 %include "ModelAPI_AttributeRefAttr.h"
-%include "ModelAPI_Validator.h"
\ No newline at end of file
+%include "ModelAPI_Validator.h"
+%include "ModelAPI_AttributeRefList.h"
+%include "ModelAPI_Result.h"
+
+%template(ObjectList) std::list<boost::shared_ptr<ModelAPI_Object> >;
index 1f5228ffd5211df9269fb9271963cfbf7d8f605e..79404ee70f22a917b10ad15bdb75d71963374f8f 100644 (file)
@@ -1,4 +1,5 @@
 INCLUDE(Common)
+INCLUDE(UnitTest)
 
 SET(PROJECT_HEADERS
     SketchPlugin.h
@@ -59,3 +60,5 @@ INCLUDE_DIRECTORIES(
 
 INSTALL(TARGETS SketchPlugin DESTINATION plugins)
 INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
+
+ADD_UNIT_TESTS(TestSketchBasics.py)
diff --git a/src/SketchPlugin/Test/TestSketchBasics.py b/src/SketchPlugin/Test/TestSketchBasics.py
new file mode 100644 (file)
index 0000000..2d68e89
--- /dev/null
@@ -0,0 +1,120 @@
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from GeomDataAPI import *
+from ModelAPI import *
+
+__updated__ = "2014-07-23"
+
+aPluginManager = ModelAPI_PluginManager.get()
+aDocument = aPluginManager.rootDocument()
+aDocument.startOperation()
+#===============================================================================
+# Test ModelAPI static methods
+# TODO: Move this test in the ModelAPI progect 
+#===============================================================================
+assert (ModelAPI_Feature.group() == "Features")
+assert (ModelAPI_AttributeDocRef.type() == "DocRef")
+assert (ModelAPI_AttributeDouble.type() == "Double")
+assert (ModelAPI_AttributeReference.type() == "Reference")
+assert (ModelAPI_AttributeRefAttr.type() == "RefAttr")
+assert (ModelAPI_AttributeRefList.type() == "RefList")
+#===============================================================================
+# Test GeomDataAPI static methods
+# TODO: Move this test in the GeomDataAPI progect 
+#===============================================================================
+assert (GeomDataAPI_Point.type() == "Point")
+assert (GeomDataAPI_Dir.type() == "Dir")  
+assert (GeomDataAPI_Point2D.type() == "Point2D")  
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSketchFeature = aDocument.addFeature("Sketch")
+assert (aSketchFeature.getKind() == "Sketch")
+aSketchFeatureData = aSketchFeature.data()
+origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry.setValue(0, 1, 0)
+norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm.setValue(0, 0, 1)
+# check that values have been changed
+origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+assert (origin.x() == 0)
+assert (origin.y() == 0)
+assert (origin.z() == 0)
+dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+assert (dirx.x() == 1)
+assert (dirx.y() == 0)
+assert (dirx.z() == 0)
+diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+assert (diry.x() == 0)
+assert (diry.y() == 1)
+assert (diry.z() == 0)
+norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+assert (norm.x() == 0)
+assert (norm.y() == 0)
+assert (norm.z() == 1)
+#=========================================================================
+# Creation of a point
+#=========================================================================
+aSketchReflist = aSketchFeatureData.reflist("Features")
+assert (not aSketchReflist.isInitialized())
+assert(aSketchReflist.size() == 0)
+assert (len(aSketchReflist.list()) == 0)
+aSketchPoint = aDocument.addFeature("SketchPoint")
+assert (aSketchPoint.getKind() == "SketchPoint")
+aSketchReflist.append(aSketchPoint)
+aSketchPointData = aSketchPoint.data()
+coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
+assert (coords.x() == 0)
+assert (coords.y() == 0)
+assert (not coords.isInitialized())
+# Simulate SketchPlugin_Point::move(...)
+coords.setValue(10., 10.)
+assert (coords.isInitialized())
+# check that values have been changed
+aSketchReflist = aSketchFeatureData.reflist("Features")
+assert (aSketchReflist.size() == 1)
+assert (len(aSketchReflist.list()) == 1)
+aSketchPointData = aSketchPoint.data()
+coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
+assert (coords.x() == 10.0)
+assert (coords.y() == 10.0)
+#===============================================================================
+# Creation of a line
+#===============================================================================
+aSketchLine = aDocument.addFeature("SketchLine")
+aSketchReflist.append(aSketchLine)
+assert (aSketchReflist.size() == 2)
+assert (len(aSketchReflist.list()) == 2)
+aSketchLineData = aSketchLine.data()
+aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
+aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+assert (aLineStartPoint.x() == 0)
+assert (aLineStartPoint.y() == 0)
+assert (not aLineStartPoint.isInitialized())
+assert (aLineEndPoint.x() == 0)
+assert (aLineEndPoint.y() == 0)
+assert (not aLineEndPoint.isInitialized())
+# Simulate SketchPlugin_Line::move(...)
+aLineStartPoint.setValue(50., 50.)
+aLineEndPoint.setValue(60., 60.)
+assert (aLineStartPoint.isInitialized())
+assert (aLineEndPoint.isInitialized())
+# check that values have been changed
+aSketchLineData = aSketchLine.data()
+aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
+aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+assert (aLineStartPoint.x() == 50.0)
+assert (aLineStartPoint.y() == 50.0)
+assert (aLineEndPoint.x() == 60.0)
+assert (aLineEndPoint.y() == 60.0)
+aSketchLine.firstResult()
+ #==============================================================================
+ # Finish the test
+ #==============================================================================
+aDocument.finishOperation()
+