From: dbv Date: Tue, 8 Sep 2015 08:06:37 +0000 (+0300) Subject: Test update X-Git-Tag: V_1.4.0_beta4~81^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=39318e10d9345c5b596d16c89469ee5e68ee734a;p=modules%2Fshaper.git Test update --- diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 1c4aa2e68..8633f1f7b 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -47,5 +47,5 @@ INCLUDE_DIRECTORIES( ) -ADD_UNIT_TESTS(TestPointName.py - ) +ADD_UNIT_TESTS(TestAxisCreation.py + TestPointName.py) diff --git a/src/ConstructionPlugin/Test/TestAxisCreation.py b/src/ConstructionPlugin/Test/TestAxisCreation.py new file mode 100644 index 000000000..22040ad59 --- /dev/null +++ b/src/ConstructionPlugin/Test/TestAxisCreation.py @@ -0,0 +1,134 @@ +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * +import math +from ModelAPI import * + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() + +# Create a part +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +assert (len(aPartFeature.results()) == 1) +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +#========================================================================= +# Create a first point +#========================================================================= +aSession.startOperation() +aPointFeature = aPart.addFeature("Point") +aPointFeatureData = aPointFeature.data() +assert(aPointFeatureData is not None) +aPointFeatureData.real("x").setValue(0.) +aPointFeatureData.real("y").setValue(0.) +aPointFeatureData.real("z").setValue(0.) +aPointFeature.execute() +aSession.finishOperation() +aPoint1Result = aPointFeature.firstResult(); + +#========================================================================= +# Create a second point +#========================================================================= +aSession.startOperation() +aPointFeature = aPart.addFeature("Point") +aPointFeatureData = aPointFeature.data() +assert(aPointFeatureData is not None) +aPointFeatureData.real("x").setValue(0.) +aPointFeatureData.real("y").setValue(0.) +aPointFeatureData.real("z").setValue(100.) +aPointFeature.execute() +aSession.finishOperation() +aPoint2Result = aPointFeature.firstResult(); + +#========================================================================= +# Create axis by two points +#========================================================================= +aSession.startOperation() +anAxisFeature = aPart.addFeature("Axis") +anAxisFeatureData = anAxisFeature.data() +assert(anAxisFeatureData is not None) +anAxisFeatureData.string("CreationMethod").setValue("AxisByPointsCase") +anAxisFeatureData.selection("FirstPoint").setValue(aPoint1Result, aPoint1Result.shape()) +anAxisFeatureData.selection("SecondPoint").setValue(aPoint2Result, aPoint2Result.shape()) +anAxisFeature.execute() +aSession.finishOperation() + +assert (len(anAxisFeature.results()) > 0) +anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult()) +assert (anAxisResult is not None) + +#========================================================================= +# Create a sketch circle to extrude +#========================================================================= +aSession.startOperation() +aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +# Create circle +aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(0, 0) +aCircleRadius.setValue(50) +aSession.finishOperation() + +#========================================================================= +# Make extrusion on circle +#========================================================================= +# Build shape from sketcher results +aCircleSketchResult = aCircleSketchFeature.firstResult() +aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape() +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt() +dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir() +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir() +aCircleSketchFaces = ShapeList() +GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces) +assert (len(aCircleSketchFaces) > 0) +assert (aCircleSketchFaces[0] is not None) + +# Create extrusion +aSession.startOperation() +anExtrusionFt = aPart.addFeature("Extrusion") +assert (anExtrusionFt.getKind() == "Extrusion") +# selection type FACE=4 +anExtrusionFt.selectionList("base").append(aCircleSketchResult, aCircleSketchFaces[0]) +anExtrusionFt.string("CreationMethod").setValue("BySizes") +anExtrusionFt.real("to_size").setValue(100) +anExtrusionFt.real("from_size").setValue(0) +anExtrusionFt.real("to_offset").setValue(0) #TODO: remove +anExtrusionFt.real("from_offset").setValue(0) #TODO: remove +anExtrusionFt.execute() +aSession.finishOperation() +assert (anExtrusionFt.real("to_size").value() == 100.0) + +# Check extrusion results +assert (len(anExtrusionFt.results()) > 0) +anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult()) +assert (anExtrusionResult is not None) + +#========================================================================= +# Create axis by cylinder +#========================================================================= +aSession.startOperation() +anAxisFeature = aPart.addFeature("Axis") +anAxisFeatureData = anAxisFeature.data() +assert(anAxisFeatureData is not None) +anAxisFeatureData.string("CreationMethod").setValue("AxisByCylindricalFaceCase") +anAxisFeatureData.selection("CylindricalFace").selectSubShape("face", "Extrusion_1_1/LateralFace_1") +anAxisFeature.execute() +aSession.finishOperation() + +assert (len(anAxisFeature.results()) > 0) +anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult()) +assert (anAxisResult is not None) diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 1fa7948da..c475ee87d 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -85,6 +85,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestRevolution.py TestRevolutionCut.py TestRevolutionFuse.py + TestPartition.py TestMovement.py TestRotation.py TestBoolean.py diff --git a/src/FeaturesPlugin/Test/TestPartition.py b/src/FeaturesPlugin/Test/TestPartition.py new file mode 100644 index 000000000..84c70c49c --- /dev/null +++ b/src/FeaturesPlugin/Test/TestPartition.py @@ -0,0 +1,92 @@ +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * +import math + +__updated__ = "2014-12-16" + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +# Create a part for extrusion +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +assert (len(aPartFeature.results()) == 1) +# Another way is: +# aPart = aSession.activeDocument() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +#========================================================================= +# Create a sketch circle to extrude +#========================================================================= +aSession.startOperation() +aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +# Create circle +aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(0, 0) +aCircleRadius.setValue(50) +aSession.finishOperation() + +#========================================================================= +# Make extrusion on circle +#========================================================================= +# Build shape from sketcher results +aCircleSketchResult = aCircleSketchFeature.firstResult() +aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape() +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt() +dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir() +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir() +aCircleSketchFaces = ShapeList() +GeomAlgoAPI_SketchBuilder.createFaces( + origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces) +assert (len(aCircleSketchFaces) > 0) +assert (aCircleSketchFaces[0] is not None) +# Create extrusion +aSession.startOperation() +anExtrusionFt = aPart.addFeature("Extrusion") +assert (anExtrusionFt.getKind() == "Extrusion") +# selection type FACE=4 +anExtrusionFt.selectionList("base").append( + aCircleSketchResult, aCircleSketchFaces[0]) +anExtrusionFt.string("CreationMethod").setValue("BySizes") +anExtrusionFt.real("to_size").setValue(50) +anExtrusionFt.real("from_size").setValue(0) +anExtrusionFt.real("to_offset").setValue(0) #TODO: remove +anExtrusionFt.real("from_offset").setValue(0) #TODO: remove +anExtrusionFt.execute() +aSession.finishOperation() +assert (anExtrusionFt.real("to_size").value() == 50) + +# Check extrusion results +assert (len(anExtrusionFt.results()) > 0) +anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult()) +assert (anExtrusionResult is not None) + +#========================================================================= +# Create a partition +#========================================================================= +aXOZPlane = modelAPI_Result(aDocument.objectByName("Construction", "XOZ")) +aSession.startOperation() +aPartitionFt = aPart.addFeature("Partition") +assert (aPartitionFt.getKind() == "Partition") +aPartitionFt.selectionList("main_objects").append(anExtrusionResult, anExtrusionResult.shape()) +aPartitionFt.selectionList("tool_objects").append(aXOZPlane, None) +aPartitionFt.execute() +aSession.finishOperation() + +assert (len(aPartitionFt.results()) > 0) +aPartitionResult = modelAPI_ResultBody(aPartitionFt.firstResult()) +assert (aPartitionResult is not None) diff --git a/src/FeaturesPlugin/Test/TestRevolution.py b/src/FeaturesPlugin/Test/TestRevolution.py index 7a6b0c408..1dd1ee277 100644 --- a/src/FeaturesPlugin/Test/TestRevolution.py +++ b/src/FeaturesPlugin/Test/TestRevolution.py @@ -127,3 +127,56 @@ assert (len(aRevolFt.results()) > 0) aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult()) assert (aRevolResult is not None) +#========================================================================= +# Create a first plane +#========================================================================= +aXOYPlane = modelAPI_Result(aDocument.objectByName("Construction", "XOY")) +aSession.startOperation() +aPlaneFeature = aPart.addFeature("Plane") +aPlaneFeatureData = aPlaneFeature.data() +assert(aPlaneFeatureData is not None) +aPlaneFeatureData.string("CreationMethod").setValue("PlaneByFaceAndDistance") +aPlaneFeatureData.selection("planeFace").setValue(aXOYPlane, None) +aPlaneFeatureData.real("distance").setValue(50) +aPlaneFeature.execute() +aSession.finishOperation() +aPlane1Result = aPlaneFeature.firstResult(); + +#========================================================================= +# Create a second plane +#========================================================================= +aSession.startOperation() +aPlaneFeature = aPart.addFeature("Plane") +aPlaneFeatureData = aPlaneFeature.data() +assert(aPlaneFeatureData is not None) +aPlaneFeatureData.string("CreationMethod").setValue("PlaneByFaceAndDistance") +aPlaneFeatureData.selection("planeFace").setValue(aXOYPlane, None) +aPlaneFeatureData.real("distance").setValue(-50) +aPlaneFeature.execute() +aSession.finishOperation() +aPlane2Result = aPlaneFeature.firstResult(); + +#========================================================================= +# Test revol between bounding planes +#========================================================================= +aSession.startOperation() +aRevolFt = aPart.addFeature("Revolution") +assert (aRevolFt.getKind() == "Revolution") +# selection type FACE=4 +aRevolFt.selectionList("base").append( + aCircleSketchResult, aCircleSketchFaces[0]) +aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge) +aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets") +aRevolFt.real("from_angle").setValue(0) #TODO: remove +aRevolFt.real("to_angle").setValue(0) #TODO: remove +aRevolFt.selection("to_object").setValue(aPlane1Result, None) +aRevolFt.real("to_offset").setValue(0) +aRevolFt.selection("from_object").setValue(aPlane2Result, None) +aRevolFt.real("from_offset").setValue(0) +aRevolFt.execute() +aSession.finishOperation() + +# Check revol results +assert (len(aRevolFt.results()) > 0) +aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult()) +assert (aRevolResult is not None) \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index d47fbbd46..544ff79b8 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -332,7 +332,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi aResult = aToCutBuilder->Shape(); // If after cut we got more than one solids then take closest to the center of mass of the base face. - //aResult = findClosest(aResult, aBasisCentre); + aResult = findClosest(aResult, aBasisCentre); // Setting naming. for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) { @@ -474,7 +474,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi } // If after cut we got more than one solids then take closest to the center of mass of the base face. - //aResult = findClosest(aResult, aBasisCentr); + aResult = findClosest(aResult, aBasisCentr); // Setting naming. for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) {