Salome HOME
5a1a66aba182835484e39c4f80456e1e1e394773
[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) #TODO: remove
70 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
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 aField.integer("components_nb").setValue(2) # two components
85 aComponentNames = aField.stringArray("components_names")
86 aComponentNames.setSize(2)
87 aComponentNames.setValue(0, "temperatue")
88 aComponentNames.setValue(1, "porosity")
89 aField.integer("type").setValue(2) # double
90 aField.integer("steps_nb").setValue(1) # one step
91 aStamps = aField.intArray("stamps")
92 aStamps.setSize(1)
93 aStamps.setValue(0, 10)
94 aTables = aField.tables("values")
95 aTables.setType(2)
96 aTables.setSize(1 + 3, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
97 aTables.setValue(20, 0, 0, 0) # value, index of selection, index of component, index of step
98 aTables.setValue(35, 1, 0, 0)
99 aTables.setValue(27, 2, 0, 0)
100 aTables.setValue(28, 3, 0, 0)
101 aTables.setValue(0.5, 0, 1, 0)
102 aTables.setValue(0.55, 1, 1, 0)
103 aTables.setValue(0.39, 2, 1, 0)
104 aTables.setValue(0.40, 3, 1, 0)
105 aSession.finishOperation()
106 #=========================================================================
107 # Create strings field on faces
108 #=========================================================================
109 aSession.startOperation()
110 aField = aSession.activeDocument().addFeature("Field")
111 aSelectionListAttr = aField.selectionList("selected")
112 aSelectionListAttr.setSelectionType("face")
113 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
114 aField.integer("components_nb").setValue(1) # one component
115 aComponentNames = aField.stringArray("components_names")
116 aComponentNames.setSize(1)
117 aComponentNames.setValue(0, "description")
118 aField.integer("type").setValue(3) # string
119 aField.integer("steps_nb").setValue(2) # two steps
120 aStamps = aField.intArray("stamps")
121 aStamps.setSize(2)
122 aStamps.setValue(0, 1)
123 aStamps.setValue(1, 3)
124 aTables = aField.tables("values")
125 aTables.setType(3)
126 aTables.setSize(1 + 1, 1, 2) # default row + number of selected, number of compoents, number of steps (tables)
127 aTables.setValue("-default-", 0, 0, 0) # value, index of selection, index of component, index of step
128 aTables.setValue("-default-", 0, 0, 1)
129 aTables.setValue("Face one", 1, 0, 0)
130 aTables.setValue("Face two", 1, 0, 1)
131 aSession.finishOperation()
132
133 aFieldResult = aField.firstResult()
134 assert(aFieldResult)
135 #=========================================================================
136 # Create integer field on faces
137 #=========================================================================
138 aSession.startOperation()
139 aField = aSession.activeDocument().addFeature("Field")
140 aSelectionListAttr = aField.selectionList("selected")
141 aSelectionListAttr.setSelectionType("face")
142 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
143 aField.integer("components_nb").setValue(1) # one component
144 aComponentNames = aField.stringArray("components_names")
145 aComponentNames.setSize(1)
146 aComponentNames.setValue(0, "description")
147 aField.integer("type").setValue(1) # integer
148 aField.integer("steps_nb").setValue(1) # one step
149 aStamps = aField.intArray("stamps")
150 aStamps.setSize(1)
151 aStamps.setValue(0, 0)
152 aTables = aField.tables("values")
153 aTables.setType(1)
154 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
155 aTables.setValue(0, 0, 0, 0) # value, index of selection, index of component, index of step
156 aTables.setValue(2, 1, 0, 0)
157 aSession.finishOperation()
158
159 aFieldResult = aField.firstResult()
160 assert(aFieldResult)
161
162 #=========================================================================
163 # Create Boolean field on faces
164 #=========================================================================
165 aSession.startOperation()
166 aField = aSession.activeDocument().addFeature("Field")
167 aSelectionListAttr = aField.selectionList("selected")
168 aSelectionListAttr.setSelectionType("face")
169 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
170 aField.integer("components_nb").setValue(1) # one component
171 aComponentNames = aField.stringArray("components_names")
172 aComponentNames.setSize(1)
173 aComponentNames.setValue(0, "description")
174 aField.integer("type").setValue(0) # boolean
175 aField.integer("steps_nb").setValue(1) # one step
176 aStamps = aField.intArray("stamps")
177 aStamps.setSize(1)
178 aStamps.setValue(0, 0)
179 aTables = aField.tables("values")
180 aTables.setType(0)
181 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
182 aTables.setValue(True, 0, 0, 0) # value, index of selection, index of component, index of step
183 aTables.setValue(False, 1, 0, 0)
184 aSession.finishOperation()
185
186 aFieldResult = aField.firstResult()
187 assert(aFieldResult)
188
189 import model
190 assert(model.checkPythonDump())