From b751d83b0e8dc6026cc3fa56c05b5518f2f4543f Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Fri, 16 Sep 2016 09:18:20 +0200 Subject: [PATCH] Update test for primitive Box. --- .../Test/TestAPI_Box.py} | 22 ++- src/PrimitivesPlugin/Test/TestBox.py | 53 ++++++ src/PrimitivesPlugin/Test/UnitTestBox.py | 168 ------------------ 3 files changed, 74 insertions(+), 169 deletions(-) rename src/{PrimitivesPlugin/Test/APIDirectTestBox.py => GeomAlgoAPI/Test/TestAPI_Box.py} (56%) create mode 100644 src/PrimitivesPlugin/Test/TestBox.py delete mode 100644 src/PrimitivesPlugin/Test/UnitTestBox.py diff --git a/src/PrimitivesPlugin/Test/APIDirectTestBox.py b/src/GeomAlgoAPI/Test/TestAPI_Box.py similarity index 56% rename from src/PrimitivesPlugin/Test/APIDirectTestBox.py rename to src/GeomAlgoAPI/Test/TestAPI_Box.py index 57927ac00..01103fafe 100644 --- a/src/PrimitivesPlugin/Test/APIDirectTestBox.py +++ b/src/GeomAlgoAPI/Test/TestAPI_Box.py @@ -1,3 +1,9 @@ +# Copyright (C) 2014-2016 CEA/DEN, EDF R&D + +# File: TestAPI_Box.py +# Created: 16 Sept 2016 +# Author: Clarisse Genrault (CEA) + from GeomAlgoAPI import GeomAlgoAPI_ShapeAPI as shaperpy from GeomAlgoAPI import GeomAlgoAPI_Exception as myExcept from GeomAPI import GeomAPI_Pnt as pnt @@ -18,10 +24,24 @@ try : except myExcept,ec: print ec.what() - # Create a box with null dimensions try : box3 = shaperpy.makeBox(0.,0.,0.) +except myExcept,ec: + print ec.what() + +# Create a box with negative dimensions +try : + box4 = shaperpy.makeBox(-5.,15.,5.) + +except myExcept,ec: + print ec.what() + +# Create a box with two same points +try : + pnt1 = pnt(0.,0.,0.) + box5 = shaperpy.makeBox(pnt1,pnt1) + except myExcept,ec: print ec.what() \ No newline at end of file diff --git a/src/PrimitivesPlugin/Test/TestBox.py b/src/PrimitivesPlugin/Test/TestBox.py new file mode 100644 index 000000000..fcbf21aa3 --- /dev/null +++ b/src/PrimitivesPlugin/Test/TestBox.py @@ -0,0 +1,53 @@ +""" +Test case for Primitive Box feature. +Written on High API. +""" +from ModelAPI import * +from GeomAPI import * + +import model + +# Get session +aSession = ModelAPI_Session.get() + +# Create a part +aDocument = aSession.activeDocument() +aSession.startOperation() +model.addPart(aDocument) +aDocument = aSession.activeDocument() +aSession.finishOperation() + +# Create a box with dimensions +aSession.startOperation() +aBox1 = model.addBox(aDocument, 10, 10, 10) +aSession.finishOperation() +assert (len(aBox1.result()) > 0) + +# Create a first point +aSession.startOperation() +aFirstPoint = model.addPoint(aDocument, 0, 0, 0) +aSession.finishOperation() + +# Create a second point +aSession.startOperation() +aSecondPoint = model.addPoint(aDocument, 50, 50, 50) +aSession.finishOperation() + +# Create a box with 2 points +aSession.startOperation() +aBox2 = model.addBox(aDocument, aFirstPoint.result()[0], aSecondPoint.result()[0]) +aSession.finishOperation() +assert (len(aBox2.result()) > 0) + +# Create a box with dimensions (error) +aSession.startOperation() +aBox3 = model.addBox(aDocument, -10, 10, 10) +aSession.finishOperation() +assert (len(aBox3.result()) == 0) + +# Create a box with 2 points (error) +aSession.startOperation() +aBox4 = model.addBox(aDocument, aFirstPoint.result()[0], aFirstPoint.result()[0]) +aSession.finishOperation() +assert (len(aBox4.result()) == 0) + diff --git a/src/PrimitivesPlugin/Test/UnitTestBox.py b/src/PrimitivesPlugin/Test/UnitTestBox.py deleted file mode 100644 index 8735244d4..000000000 --- a/src/PrimitivesPlugin/Test/UnitTestBox.py +++ /dev/null @@ -1,168 +0,0 @@ -""" - UnitTestBox.py - Unit Test of PrimitivesPlugin_Box class - -class PrimitivesPlugin_Box : public ModelAPI_Feature - static const std::string MY_BOX_ID("Box"); - static const std::string METHOD_ATTR("CreationMethod"); - static const std::string MY_POINT_FIRST("FirstPoint"); - static const std::string MY_POINT_SECOND("SecondPoint"); - static const std::string MY_DX("dx"); - static const std::string MY_DY("dy"); - static const std::string MY_DZ("dz"); - - data()->addAttribute(METHOD(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(POINT_FIRST(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(POINT_SECOND(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(DX(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(DY(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(DZ(), ModelAPI_AttributeDouble::typeId()); - -""" - -#========================================================================= -# Initialization of the test -#========================================================================= -from ModelAPI import * -from GeomDataAPI import * -from GeomAlgoAPI import * -from GeomAPI import * -import math - -__updated__ = "2016-01-04" - -aSession = ModelAPI_Session.get() -aDocument = aSession.moduleDocument() -# Create a part for creation of a box -aSession.startOperation() -aPartFeature = aDocument.addFeature("Part") -aSession.finishOperation() -assert (len(aPartFeature.results()) == 1) - -aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) -aPart = aPartResult.partDoc() -#========================================================================= -# Creation of a Box by coordinates -#========================================================================= -aSession.startOperation() -aBoxBy3Dims = aPart.addFeature("Box") -assert (aBoxBy3Dims.getKind() == "Box") - -aBoxBy3Dims.string("CreationMethod").setValue("BoxByDimensions") -aBoxBy3Dims.real("dx").setValue(1.6) -aBoxBy3Dims.real("dy").setValue(1.6) -aBoxBy3Dims.real("dz").setValue(1.6) -aBoxBy3Dims.execute() - -# Check box results -assert (len(aBoxBy3Dims.results()) > 0) -aBoxResult = modelAPI_ResultBody(aBoxBy3Dims.firstResult()) -assert (aBoxResult is not None) - -# Check box volume -aRefVolume = 1.6 * 1.6 * 1.6 -aResVolume = GeomAlgoAPI_ShapeTools_volume(aBoxResult.shape()) -assert (math.fabs(aResVolume - aRefVolume) < 10 ** -5) - - -#Check the naming by selecting a face and making a plane out of it -aPlaneTop = aPart.addFeature("Plane") -assert(aPlaneTop.getKind() == "Plane") -aPlaneTop.string("creation_method").setValue("by_other_plane") -aSelectionAttr = aPlaneTop.selection("plane") -aSelectionAttr.selectSubShape("face", "Box_1_1/Top_1") -aPlaneTop.string("by_other_plane_option").setValue("by_distance_from_other") -aPlaneTop.real("distance").setValue(0.4) -aPlaneTop.execute() - -#The face should be at 1.6, so the plane should be at 1.6 + 0.4 = 2. -aRefPlaneTopLocation = 2. - -#location() is a method from GeomAPI_Face that returns a GeomAPI_Pnt, from which we can extract the z coordinate -aPlaneTopResult = aPlaneTop.firstResult() -aPlaneTopFace = GeomAPI_Face(aPlaneTopResult.shape()) -aPlaneTestLocation = aPlaneTopFace.getPlane() -aPlaneLocation = aPlaneTestLocation.location().z() -assert(math.fabs(aPlaneLocation - aRefPlaneTopLocation) < 10 ** -5) - -aSession.finishOperation() - -#========================================================================= -# Creation of a Box by two points -#========================================================================= - -aSession.startOperation() - -#Create two points -aPoint1 = aPart.addFeature("Point") -aPoint2 = aPart.addFeature("Point") -assert(aPoint1.getKind() == "Point") -assert(aPoint2.getKind() == "Point") -<<<<<<< HEAD -aPoint1.string("creation_method").setValue("by_xyz") -aPoint1.real("x").setValue(2.0) -aPoint1.real("y").setValue(2.0) -aPoint1.real("z").setValue(2.0) -aPoint2.string("creation_method").setValue("by_xyz") -======= -# aPoint1.string("creation_method").setValue("by_xyz") -aPoint1.real("x").setValue(2.0) -aPoint1.real("y").setValue(2.0) -aPoint1.real("z").setValue(2.0) -# aPoint2.string("creation_method").setValue("by_xyz") ->>>>>>> master -aPoint2.real("x").setValue(2.5) -aPoint2.real("y").setValue(2.5) -aPoint2.real("z").setValue(2.5) -aPoint1.execute() -aPoint2.execute() -aPoint1Result = aPoint1.firstResult() -aPoint2Result = aPoint2.firstResult() -aPoint1Vertex = aPoint1Result.shape() -aPoint2Vertex = aPoint2Result.shape() - -aBoxBy2Pts = aPart.addFeature("Box") -assert (aBoxBy2Pts.getKind() == "Box") -aBoxBy2Pts.string("CreationMethod").setValue("BoxByTwoPoints") -aBoxBy2Pts.selection("FirstPoint").setValue(aPoint1Result, aPoint1Vertex) -aBoxBy2Pts.selection("SecondPoint").setValue(aPoint2Result, aPoint2Vertex) -aBoxBy2Pts.execute() - -# Check box volume -aBoxResult2 = modelAPI_ResultBody(aBoxBy2Pts.firstResult()) -aRefVolume2 = 0.5 * 0.5 * 0.5 -aResVolume2 = GeomAlgoAPI_ShapeTools_volume(aBoxResult2.shape()) -assert (math.fabs(aResVolume2 - aRefVolume2) < 10 ** -5) - -#Check the naming by selecting a face and making a plane out of it -aPlaneRight = aPart.addFeature("Plane") -assert(aPlaneRight.getKind() == "Plane") -<<<<<<< HEAD -aPlaneRight.string("CreationMethod").setValue("PlaneByFaceAndDistance") -aSelectionAttr = aPlaneRight.selection("planeFace") -aSelectionAttr.selectSubShape("face", "Box_2_1/Right_1") -======= -aPlaneRight.string("creation_method").setValue("by_other_plane") -aSelectionAttr = aPlaneRight.selection("plane") -aSelectionAttr.selectSubShape("face", "Box_2_1/Right_1") -aPlaneRight.string("by_other_plane_option").setValue("by_distance_from_other") ->>>>>>> master -aPlaneRight.real("distance").setValue(0.5) -aPlaneRight.execute() - -#The face should be at 2.5, so the plane should be at 2.5 + 0.5 = 3. -aRefPlaneRightLocation = 3. - -#location() is a method from GeomAPI_Face that returns a GeomAPI_Pnt, -#from which we can extract the y coordinate -aPlaneRightResult = aPlaneRight.firstResult() -aPlaneRightFace = GeomAPI_Face(aPlaneRightResult.shape()) -aPlaneTestLocation = aPlaneRightFace.getPlane() -aPlaneLocation = aPlaneTestLocation.location().y() -assert(math.fabs(aPlaneLocation - aRefPlaneRightLocation) < 10 ** -5) - -aSession.finishOperation() - -#========================================================================= -# End of test -#========================================================================= -- 2.39.2