)
-ADD_UNIT_TESTS(TestPointName.py
- )
+ADD_UNIT_TESTS(TestAxisCreation.py
+ TestPointName.py)
--- /dev/null
+#=========================================================================
+# 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)
TestRevolution.py
TestRevolutionCut.py
TestRevolutionFuse.py
+ TestPartition.py
TestMovement.py
TestRotation.py
TestBoolean.py
--- /dev/null
+#=========================================================================
+# 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)
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
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 ()) {
}
// 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 ()) {