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