Salome HOME
de927057b2ad0fe8e505b44cf7b0d8e566d1602b
[modules/shaper.git] / src / CollectionPlugin / Test / TestField.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22       TestBoolean.py
23       Unit test of FeaturesPlugin_Group class
24
25       class FeaturesPlugin_Group
26         static const std::string MY_GROUP_ID("Group");
27         static const std::string MY_GROUP_LIST_ID("group_list");
28
29         data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
30 """
31 #=========================================================================
32 # Initialization of the test
33 #=========================================================================
34 from ModelAPI import *
35 from GeomDataAPI import *
36 from GeomAlgoAPI import *
37 from GeomAPI import *
38
39 __updated__ = "2014-12-16"
40
41 aSession = ModelAPI_Session.get()
42 # Create a part for extrusions & boolean
43 aSession.startOperation()
44 aPartFeature = aSession.moduleDocument().addFeature("Part")
45 aSession.finishOperation()
46 aPart = aSession.activeDocument()
47 #=========================================================================
48 # Create a sketch with triangle and extrude it
49 #=========================================================================
50 aSession.startOperation()
51 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
52 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
53 origin.setValue(0, 0, 0)
54 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
55 dirx.setValue(1, 0, 0)
56 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
57 norm.setValue(0, 0, 1)
58 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
59 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
60 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
61 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
62 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
63 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
64 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
65 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
66 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
67 aLineAStartPoint.setValue(-100., 0.)
68 aLineAEndPoint.setValue(100., 0.)
69 aLineBStartPoint.setValue(100., 0.)
70 aLineBEndPoint.setValue(0., 173.2)
71 aLineCStartPoint.setValue(0., 173.2)
72 aLineCEndPoint.setValue(-100., 0.)
73 aSession.finishOperation()
74 # Build sketch faces
75 aSession.startOperation()
76 aSketchResult = modelAPI_ResultConstruction(aTriangleSketchFeature.firstResult())
77 # Create extrusion on them
78 anExtrusionFt = aPart.addFeature("Extrusion")
79 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchResult.face(0))
80 anExtrusionFt.string("CreationMethod").setValue("BySizes")
81 anExtrusionFt.real("to_size").setValue(50)
82 anExtrusionFt.real("from_size").setValue(50)
83 anExtrusionFt.real("to_offset").setValue(0)
84 anExtrusionFt.real("from_offset").setValue(0)
85 anExtrusionFt.execute()
86 aSession.finishOperation()
87 anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
88 #=========================================================================
89 # Create doubles field on vertices
90 #=========================================================================
91 aSession.startOperation()
92 aField = aSession.activeDocument().addFeature("Field")
93 aSelectionListAttr = aField.selectionList("selected")
94 aSelectionListAttr.setSelectionType("vertex")
95 aSelectionListAttr.append("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]")
96 aSelectionListAttr.append("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]")
97 aSelectionListAttr.append("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/From_Face]")
98 aComponentNames = aField.stringArray("components_names")
99 aComponentNames.setSize(2) # two components
100 aComponentNames.setValue(0, "temperatue")
101 aComponentNames.setValue(1, "porosity")
102 aStamps = aField.intArray("stamps")
103 aStamps.setSize(1) # one step
104 aStamps.setValue(0, 10)
105 aTables = aField.tables("values")
106 aTables.setType(2) # double
107 aTables.setSize(1 + 3, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
108 aTables.setValue(20, 0, 0, 0) # value, index of selection, index of component, index of step
109 aTables.setValue(35, 1, 0, 0)
110 aTables.setValue(27, 2, 0, 0)
111 aTables.setValue(28, 3, 0, 0)
112 aTables.setValue(0.5, 0, 1, 0)
113 aTables.setValue(0.55, 1, 1, 0)
114 aTables.setValue(0.39, 2, 1, 0)
115 aTables.setValue(0.40, 3, 1, 0)
116 aSession.finishOperation()
117 #=========================================================================
118 # Create strings field on faces
119 #=========================================================================
120 aSession.startOperation()
121 aField = aSession.activeDocument().addFeature("Field")
122 aSelectionListAttr = aField.selectionList("selected")
123 aSelectionListAttr.setSelectionType("face")
124 aSelectionListAttr.append("Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1")
125 aComponentNames = aField.stringArray("components_names")
126 aComponentNames.setSize(1) # one component
127 aComponentNames.setValue(0, "description")
128 aStamps = aField.intArray("stamps")
129 aStamps.setSize(2) # two steps
130 aStamps.setValue(0, 1)
131 aStamps.setValue(1, 3)
132 aTables = aField.tables("values")
133 aTables.setType(3) # string
134 aTables.setSize(1 + 1, 1, 2) # default row + number of selected, number of compoents, number of steps (tables)
135 aTables.setValue("-default-", 0, 0, 0) # value, index of selection, index of component, index of step
136 aTables.setValue("-default-", 0, 0, 1)
137 aTables.setValue("Face one", 1, 0, 0)
138 aTables.setValue("Face two", 1, 0, 1)
139 aSession.finishOperation()
140
141 aFieldResult = aField.firstResult()
142 assert(aFieldResult)
143 #=========================================================================
144 # Create integer field on faces
145 #=========================================================================
146 aSession.startOperation()
147 aField = aSession.activeDocument().addFeature("Field")
148 aSelectionListAttr = aField.selectionList("selected")
149 aSelectionListAttr.setSelectionType("face")
150 aSelectionListAttr.append("Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1")
151 aComponentNames = aField.stringArray("components_names")
152 aComponentNames.setSize(1) # one component
153 aComponentNames.setValue(0, "description")
154 aStamps = aField.intArray("stamps")
155 aStamps.setSize(1) # one step
156 aStamps.setValue(0, 0)
157 aTables = aField.tables("values")
158 aTables.setType(1) # integer
159 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
160 aTables.setValue(0, 0, 0, 0) # value, index of selection, index of component, index of step
161 aTables.setValue(2, 1, 0, 0)
162 aSession.finishOperation()
163
164 aFieldResult = aField.firstResult()
165 assert(aFieldResult)
166
167 #=========================================================================
168 # Create Boolean field on faces
169 #=========================================================================
170 aSession.startOperation()
171 aField = aSession.activeDocument().addFeature("Field")
172 aSelectionListAttr = aField.selectionList("selected")
173 aSelectionListAttr.setSelectionType("face")
174 aSelectionListAttr.append("Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1")
175 aComponentNames = aField.stringArray("components_names")
176 aComponentNames.setSize(1) # one component
177 aComponentNames.setValue(0, "description")
178 aStamps = aField.intArray("stamps")
179 aStamps.setSize(1) # one step
180 aStamps.setValue(0, 0)
181 aTables = aField.tables("values")
182 aTables.setType(0) # boolean
183 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
184 aTables.setValue(True, 0, 0, 0) # value, index of selection, index of component, index of step
185 aTables.setValue(False, 1, 0, 0)
186 aSession.finishOperation()
187
188 aFieldResult = aField.firstResult()
189 assert(aFieldResult)
190
191 from salome.shaper import model
192 assert(model.checkPythonDump())