Salome HOME
A unit test for the issue #1799
[modules/shaper.git] / src / CollectionPlugin / Test / TestField.py
1 """
2       TestBoolean.py
3       Unit test of FeaturesPlugin_Group class
4
5       class FeaturesPlugin_Group
6         static const std::string MY_GROUP_ID("Group");
7         static const std::string MY_GROUP_LIST_ID("group_list");
8
9         data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
10 """
11 #=========================================================================
12 # Initialization of the test
13 #=========================================================================
14 from ModelAPI import *
15 from GeomDataAPI import *
16 from GeomAlgoAPI import *
17 from GeomAPI import *
18
19 __updated__ = "2014-12-16"
20
21 aSession = ModelAPI_Session.get()
22 # Create a part for extrusions & boolean
23 aSession.startOperation()
24 aPartFeature = aSession.moduleDocument().addFeature("Part")
25 aSession.finishOperation()
26 aPart = aSession.activeDocument()
27 #=========================================================================
28 # Create a sketch with triangle and extrude it
29 #=========================================================================
30 aSession.startOperation()
31 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
32 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
33 origin.setValue(0, 0, 0)
34 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
35 dirx.setValue(1, 0, 0)
36 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
37 norm.setValue(0, 0, 1)
38 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
39 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
40 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
41 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
42 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
43 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
44 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
45 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
46 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
47 aLineAStartPoint.setValue(-100., 0.)
48 aLineAEndPoint.setValue(100., 0.)
49 aLineBStartPoint.setValue(100., 0.)
50 aLineBEndPoint.setValue(0., 173.2)
51 aLineCStartPoint.setValue(0., 173.2)
52 aLineCEndPoint.setValue(-100., 0.)
53 aSession.finishOperation()
54 # Build sketch faces
55 aSession.startOperation()
56 aSketchResult = aTriangleSketchFeature.firstResult()
57 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
58 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")).pnt()
59 dirX = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")).dir()
60 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")).dir()
61 aSketchFaces = ShapeList()
62 GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, norm, aSketchEdges, aSketchFaces)
63 # Create extrusion on them
64 anExtrusionFt = aPart.addFeature("Extrusion")
65 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchFaces[0])
66 anExtrusionFt.string("CreationMethod").setValue("BySizes")
67 anExtrusionFt.real("to_size").setValue(50)
68 anExtrusionFt.real("from_size").setValue(50)
69 anExtrusionFt.real("to_offset").setValue(0)
70 anExtrusionFt.real("from_offset").setValue(0)
71 anExtrusionFt.execute()
72 aSession.finishOperation()
73 anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
74 #=========================================================================
75 # Create doubles field on vertices
76 #=========================================================================
77 aSession.startOperation()
78 aField = aSession.activeDocument().addFeature("Field")
79 aSelectionListAttr = aField.selectionList("selected")
80 aSelectionListAttr.setSelectionType("vertex")
81 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
82 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
83 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/From_Face_1_1")
84 aComponentNames = aField.stringArray("components_names")
85 aComponentNames.setSize(2) # two components
86 aComponentNames.setValue(0, "temperatue")
87 aComponentNames.setValue(1, "porosity")
88 aStamps = aField.intArray("stamps")
89 aStamps.setSize(1) # one step
90 aStamps.setValue(0, 10)
91 aTables = aField.tables("values")
92 aTables.setType(2) # double
93 aTables.setSize(1 + 3, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
94 aTables.setValue(20, 0, 0, 0) # value, index of selection, index of component, index of step
95 aTables.setValue(35, 1, 0, 0)
96 aTables.setValue(27, 2, 0, 0)
97 aTables.setValue(28, 3, 0, 0)
98 aTables.setValue(0.5, 0, 1, 0)
99 aTables.setValue(0.55, 1, 1, 0)
100 aTables.setValue(0.39, 2, 1, 0)
101 aTables.setValue(0.40, 3, 1, 0)
102 aSession.finishOperation()
103 #=========================================================================
104 # Create strings field on faces
105 #=========================================================================
106 aSession.startOperation()
107 aField = aSession.activeDocument().addFeature("Field")
108 aSelectionListAttr = aField.selectionList("selected")
109 aSelectionListAttr.setSelectionType("face")
110 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
111 aComponentNames = aField.stringArray("components_names")
112 aComponentNames.setSize(1) # one component
113 aComponentNames.setValue(0, "description")
114 aStamps = aField.intArray("stamps")
115 aStamps.setSize(2) # two steps
116 aStamps.setValue(0, 1)
117 aStamps.setValue(1, 3)
118 aTables = aField.tables("values")
119 aTables.setType(3) # string
120 aTables.setSize(1 + 1, 1, 2) # default row + number of selected, number of compoents, number of steps (tables)
121 aTables.setValue("-default-", 0, 0, 0) # value, index of selection, index of component, index of step
122 aTables.setValue("-default-", 0, 0, 1)
123 aTables.setValue("Face one", 1, 0, 0)
124 aTables.setValue("Face two", 1, 0, 1)
125 aSession.finishOperation()
126
127 aFieldResult = aField.firstResult()
128 assert(aFieldResult)
129 #=========================================================================
130 # Create integer field on faces
131 #=========================================================================
132 aSession.startOperation()
133 aField = aSession.activeDocument().addFeature("Field")
134 aSelectionListAttr = aField.selectionList("selected")
135 aSelectionListAttr.setSelectionType("face")
136 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
137 aComponentNames = aField.stringArray("components_names")
138 aComponentNames.setSize(1) # one component
139 aComponentNames.setValue(0, "description")
140 aStamps = aField.intArray("stamps")
141 aStamps.setSize(1) # one step
142 aStamps.setValue(0, 0)
143 aTables = aField.tables("values")
144 aTables.setType(1) # integer
145 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
146 aTables.setValue(0, 0, 0, 0) # value, index of selection, index of component, index of step
147 aTables.setValue(2, 1, 0, 0)
148 aSession.finishOperation()
149
150 aFieldResult = aField.firstResult()
151 assert(aFieldResult)
152
153 #=========================================================================
154 # Create Boolean field on faces
155 #=========================================================================
156 aSession.startOperation()
157 aField = aSession.activeDocument().addFeature("Field")
158 aSelectionListAttr = aField.selectionList("selected")
159 aSelectionListAttr.setSelectionType("face")
160 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
161 aComponentNames = aField.stringArray("components_names")
162 aComponentNames.setSize(1) # one component
163 aComponentNames.setValue(0, "description")
164 aStamps = aField.intArray("stamps")
165 aStamps.setSize(1) # one step
166 aStamps.setValue(0, 0)
167 aTables = aField.tables("values")
168 aTables.setType(0) # boolean
169 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
170 aTables.setValue(True, 0, 0, 0) # value, index of selection, index of component, index of step
171 aTables.setValue(False, 1, 0, 0)
172 aSession.finishOperation()
173
174 aFieldResult = aField.firstResult()
175 assert(aFieldResult)
176
177 import model
178 assert(model.checkPythonDump())