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