3 Unit test of FeaturesPlugin_Boolean class
5 class FeaturesPlugin_Boolean
6 static const std::string MY_ID("Boolean");
7 static const std::string MY_OBJECT_ID("main_object");
8 static const std::string MY_TOOL_ID("tool_object");
9 static const std::string MY_TYPE_ID("bool_type");
11 data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::typeId());
12 data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::typeId());
13 data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
15 #=========================================================================
16 # Initialization of the test
17 #=========================================================================
18 from ModelAPI import *
19 from GeomDataAPI import *
20 from GeomAlgoAPI import *
23 __updated__ = "2014-12-16"
25 aSession = ModelAPI_Session.get()
26 # Create a part for extrusions & boolean
27 aSession.startOperation()
28 aPartFeature = aSession.moduleDocument().addFeature("Part")
29 aSession.finishOperation()
30 aPart = aSession.activeDocument()
31 #=========================================================================
32 # Create a sketch with circle to extrude
33 #=========================================================================
34 aSession.startOperation()
35 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
36 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
37 origin.setValue(0, 0, 0)
38 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
39 dirx.setValue(1, 0, 0)
40 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
41 norm.setValue(0, 0, 1)
42 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
43 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
44 aCircleRadius = aSketchCircle.real("CircleRadius")
45 anCircleCentr.setValue(10., 10.)
46 aCircleRadius.setValue(50.)
47 aSession.finishOperation()
48 #=========================================================================
49 # Create a sketch with triangle to extrude
50 #=========================================================================
51 aSession.startOperation()
52 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
53 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
54 origin.setValue(0, 0, 0)
55 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
56 dirx.setValue(1, 0, 0)
57 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
58 norm.setValue(0, 0, 1)
59 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
60 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
61 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
62 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
63 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
64 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
65 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
66 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
67 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
68 aLineAStartPoint.setValue(25., 25.)
69 aLineAEndPoint.setValue(100., 25.)
70 aLineBStartPoint.setValue(100., 25.)
71 aLineBEndPoint.setValue(60., 75.)
72 aLineCStartPoint.setValue(60., 75.)
73 aLineCEndPoint.setValue(25., 25.)
74 aSession.finishOperation()
75 #=========================================================================
76 # Make extrusion on circle (cylinder) and triangle (prism)
77 #=========================================================================
78 # Build shape from sketcher results
79 aSession.startOperation()
81 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
83 aSketchResult = eachSketchFeature.firstResult()
84 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
85 origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
86 dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
87 norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
88 aSketchFaces = ShapeList()
89 GeomAlgoAPI_SketchBuilder.createFaces(
90 origin, dirX, norm, aSketchEdges, aSketchFaces)
91 # Create extrusion on them
92 anExtrusionFt = aPart.addFeature("Extrusion")
93 anExtrusionFt.selectionList("base").append(
94 aSketchResult, aSketchFaces[0])
95 anExtrusionFt.string("CreationMethod").setValue("BySizes")
96 anExtrusionFt.real("from_size").setValue(0)
97 anExtrusionFt.real("to_size").setValue(50)
98 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
99 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
100 anExtrusionFt.execute()
101 extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
102 aSession.finishOperation()
103 #=========================================================================
104 # Create a pacman as boolean cut of the prism from the cylinder
105 #=========================================================================
106 aSession.startOperation()
107 aBooleanFt = aPart.addFeature("Boolean")
108 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
109 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
111 aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
113 aSession.finishOperation()
115 assert (len(aBooleanFt.results()) > 0)
116 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
117 assert (aBooleanResult is not None)
118 #=========================================================================
120 #=========================================================================
125 partSet = model.moduleDocument()
126 Part_1 = model.addPart(partSet)
127 Part_1_doc = Part_1.document()
128 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
129 SketchCircle_1 = Sketch_1.addCircle(-353.344768439108, 0.857632933105, 175.14200032067)
131 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
132 SketchCircle_2 = Sketch_2.addCircle(-126.929674099485, -2.572898799314, 176.971885556791)
134 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 10, 0)
135 Boolean_1 = model.addCommon(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_1_2")])
137 assert(len(Boolean_1.result()) > 0)
140 partSet = model.moduleDocument()
141 Part_1 = model.addPart(partSet)
142 Part_1_doc = Part_1.document()
143 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
144 SketchCircle_1 = Sketch_1.addCircle(-353.344768439108, 0.857632933105, 175.14200032067)
146 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
147 SketchCircle_2 = Sketch_2.addCircle(-126.929674099485, -2.572898799314, 176.971885556791)
149 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 10, 0)
150 Boolean_1 = model.addSmash(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_1_2")])
152 assert(len(Boolean_1.result()) > 0)
154 assert(model.checkPythonDump())