From 28dfabc017ae38edd699d80ff679cd65971136b8 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 24 Jul 2014 14:17:58 +0400 Subject: [PATCH] Added a way to extract and check ResultConstruction from a ModelAPI_Feature in python scripts --- src/GeomAPI/GeomAPI_Shape.cpp | 9 +++++++-- src/GeomAPI/GeomAPI_Shape.h | 6 ++++++ src/ModelAPI/CMakeLists.txt | 4 +++- src/ModelAPI/ModelAPI.i | 15 +++++++++++++++ src/ModuleBase/ModuleBase_Tools.cpp | 10 +++------- src/SketchPlugin/Test/TestSketchBasics.py | 21 ++++++++++++++++----- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index e662ea254..ded200837 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -9,5 +9,10 @@ #define MY_PNT static_cast(myImpl) GeomAPI_Shape::GeomAPI_Shape() - : GeomAPI_Interface(new TopoDS_Shape()) -{} + : GeomAPI_Interface(new TopoDS_Shape()) { +} + +bool GeomAPI_Shape::isNull() +{ + return MY_SHAPE->IsNull(); +} diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 8a9d3b26c..514287a03 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -11,12 +11,18 @@ * \ingroup DataModel * \brief Interface to the topological shape object */ +class TopoDS_Shape; + +#define MY_SHAPE static_cast(myImpl) class GEOMAPI_EXPORT GeomAPI_Shape: public GeomAPI_Interface { public: /// Creation of empty (null) shape GeomAPI_Shape(); + + bool isNull(); + }; #endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 8f02b77ab..731a449c7 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -43,7 +43,9 @@ SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX) TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES}) INCLUDE_DIRECTORIES( - ../Config ../Events + ../Config + ../Events + ../GeomAPI ) SET(CMAKE_SWIG_FLAGS "") diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index b6a337d3e..456a52775 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -15,10 +15,19 @@ #include "ModelAPI_Validator.h" #include "ModelAPI_AttributeRefList.h" #include "ModelAPI_Result.h" + #include "ModelAPI_ResultConstruction.h" + + template boost::shared_ptr castTo(boost::shared_ptr theObject) + { + return boost::dynamic_pointer_cast(theObject); + } + + %} // to avoid error on this #define MODELAPI_EXPORT +#define GEOMAPI_EXPORT // standard definitions %include "typemaps.i" @@ -39,6 +48,7 @@ %shared_ptr(ModelAPI_AttributeRefAttr) %shared_ptr(ModelAPI_AttributeRefList) %shared_ptr(ModelAPI_Result) +%shared_ptr(ModelAPI_ResultConstruction) // all supported interfaces %include "ModelAPI_Document.h" @@ -54,5 +64,10 @@ %include "ModelAPI_Validator.h" %include "ModelAPI_AttributeRefList.h" %include "ModelAPI_Result.h" +%include "ModelAPI_ResultConstruction.h" %template(ObjectList) std::list >; +%template(ResultList) std::list >; + +template boost::shared_ptr castTo(boost::shared_ptr theObject); +%template(modelAPI_ResultConstruction) castTo; diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 3f0069eca..dfd282ea3 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -13,14 +13,10 @@ namespace ModuleBase_Tools boost::shared_ptr shape(ResultPtr theResult) { ResultBodyPtr aBody = boost::dynamic_pointer_cast(theResult); - if (aBody) - return aBody->shape(); - + if (aBody) return aBody->shape(); ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast(theResult); - if (aConstruct) - return aConstruct->shape(); - + if (aConstruct) return aConstruct->shape(); return boost::shared_ptr(); } -} \ No newline at end of file +} diff --git a/src/SketchPlugin/Test/TestSketchBasics.py b/src/SketchPlugin/Test/TestSketchBasics.py index 2d68e8921..22df6ce62 100644 --- a/src/SketchPlugin/Test/TestSketchBasics.py +++ b/src/SketchPlugin/Test/TestSketchBasics.py @@ -4,11 +4,10 @@ from GeomDataAPI import * from ModelAPI import * -__updated__ = "2014-07-23" +__updated__ = "2014-07-24" aPluginManager = ModelAPI_PluginManager.get() aDocument = aPluginManager.rootDocument() -aDocument.startOperation() #=============================================================================== # Test ModelAPI static methods # TODO: Move this test in the ModelAPI progect @@ -29,6 +28,7 @@ assert (GeomDataAPI_Point2D.type() == "Point2D") #========================================================================= # Creation of a sketch #========================================================================= +aDocument.startOperation() aSketchFeature = aDocument.addFeature("Sketch") assert (aSketchFeature.getKind() == "Sketch") aSketchFeatureData = aSketchFeature.data() @@ -57,9 +57,11 @@ norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) assert (norm.x() == 0) assert (norm.y() == 0) assert (norm.z() == 1) +aDocument.finishOperation() #========================================================================= # Creation of a point #========================================================================= +aDocument.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") assert (not aSketchReflist.isInitialized()) assert(aSketchReflist.size() == 0) @@ -83,9 +85,11 @@ aSketchPointData = aSketchPoint.data() coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates")) assert (coords.x() == 10.0) assert (coords.y() == 10.0) +aDocument.finishOperation() #=============================================================================== # Creation of a line #=============================================================================== +aDocument.startOperation() aSketchLine = aDocument.addFeature("SketchLine") aSketchReflist.append(aSketchLine) assert (aSketchReflist.size() == 2) @@ -112,9 +116,16 @@ assert (aLineStartPoint.x() == 50.0) assert (aLineStartPoint.y() == 50.0) assert (aLineEndPoint.x() == 60.0) assert (aLineEndPoint.y() == 60.0) -aSketchLine.firstResult() +aDocument.finishOperation() +#=============================================================================== +# Check results +#=============================================================================== +aResult = aSketchLine.firstResult() +assert (aResult is not None) +aResultConstruction = modelAPI_ResultConstruction(aResult) +aShape = aResult.shape() +assert (aShape is not None) +assert (not aShape.isNull()) #============================================================================== # Finish the test #============================================================================== -aDocument.finishOperation() - -- 2.39.2