Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 = aTriangleSketchFeature.firstResult()
77 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
78 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")).pnt()
79 dirX = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")).dir()
80 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")).dir()
81 aSketchFaces = ShapeList()
82 GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, norm, aSketchEdges, aSketchFaces)
83 # Create extrusion on them
84 anExtrusionFt = aPart.addFeature("Extrusion")
85 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchFaces[0])
86 anExtrusionFt.string("CreationMethod").setValue("BySizes")
87 anExtrusionFt.real("to_size").setValue(50)
88 anExtrusionFt.real("from_size").setValue(50)
89 anExtrusionFt.real("to_offset").setValue(0)
90 anExtrusionFt.real("from_offset").setValue(0)
91 anExtrusionFt.execute()
92 aSession.finishOperation()
93 anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
94 #=========================================================================
95 # Create doubles field on vertices
96 #=========================================================================
97 aSession.startOperation()
98 aField = aSession.activeDocument().addFeature("Field")
99 aSelectionListAttr = aField.selectionList("selected")
100 aSelectionListAttr.setSelectionType("vertex")
101 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
102 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
103 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/From_Face_1_1")
104 aComponentNames = aField.stringArray("components_names")
105 aComponentNames.setSize(2) # two components
106 aComponentNames.setValue(0, "temperatue")
107 aComponentNames.setValue(1, "porosity")
108 aStamps = aField.intArray("stamps")
109 aStamps.setSize(1) # one step
110 aStamps.setValue(0, 10)
111 aTables = aField.tables("values")
112 aTables.setType(2) # double
113 aTables.setSize(1 + 3, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
114 aTables.setValue(20, 0, 0, 0) # value, index of selection, index of component, index of step
115 aTables.setValue(35, 1, 0, 0)
116 aTables.setValue(27, 2, 0, 0)
117 aTables.setValue(28, 3, 0, 0)
118 aTables.setValue(0.5, 0, 1, 0)
119 aTables.setValue(0.55, 1, 1, 0)
120 aTables.setValue(0.39, 2, 1, 0)
121 aTables.setValue(0.40, 3, 1, 0)
122 aSession.finishOperation()
123 #=========================================================================
124 # Create strings field on faces
125 #=========================================================================
126 aSession.startOperation()
127 aField = aSession.activeDocument().addFeature("Field")
128 aSelectionListAttr = aField.selectionList("selected")
129 aSelectionListAttr.setSelectionType("face")
130 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
131 aComponentNames = aField.stringArray("components_names")
132 aComponentNames.setSize(1) # one component
133 aComponentNames.setValue(0, "description")
134 aStamps = aField.intArray("stamps")
135 aStamps.setSize(2) # two steps
136 aStamps.setValue(0, 1)
137 aStamps.setValue(1, 3)
138 aTables = aField.tables("values")
139 aTables.setType(3) # string
140 aTables.setSize(1 + 1, 1, 2) # default row + number of selected, number of compoents, number of steps (tables)
141 aTables.setValue("-default-", 0, 0, 0) # value, index of selection, index of component, index of step
142 aTables.setValue("-default-", 0, 0, 1)
143 aTables.setValue("Face one", 1, 0, 0)
144 aTables.setValue("Face two", 1, 0, 1)
145 aSession.finishOperation()
146
147 aFieldResult = aField.firstResult()
148 assert(aFieldResult)
149 #=========================================================================
150 # Create integer field on faces
151 #=========================================================================
152 aSession.startOperation()
153 aField = aSession.activeDocument().addFeature("Field")
154 aSelectionListAttr = aField.selectionList("selected")
155 aSelectionListAttr.setSelectionType("face")
156 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
157 aComponentNames = aField.stringArray("components_names")
158 aComponentNames.setSize(1) # one component
159 aComponentNames.setValue(0, "description")
160 aStamps = aField.intArray("stamps")
161 aStamps.setSize(1) # one step
162 aStamps.setValue(0, 0)
163 aTables = aField.tables("values")
164 aTables.setType(1) # integer
165 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
166 aTables.setValue(0, 0, 0, 0) # value, index of selection, index of component, index of step
167 aTables.setValue(2, 1, 0, 0)
168 aSession.finishOperation()
169
170 aFieldResult = aField.firstResult()
171 assert(aFieldResult)
172
173 #=========================================================================
174 # Create Boolean field on faces
175 #=========================================================================
176 aSession.startOperation()
177 aField = aSession.activeDocument().addFeature("Field")
178 aSelectionListAttr = aField.selectionList("selected")
179 aSelectionListAttr.setSelectionType("face")
180 aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
181 aComponentNames = aField.stringArray("components_names")
182 aComponentNames.setSize(1) # one component
183 aComponentNames.setValue(0, "description")
184 aStamps = aField.intArray("stamps")
185 aStamps.setSize(1) # one step
186 aStamps.setValue(0, 0)
187 aTables = aField.tables("values")
188 aTables.setType(0) # boolean
189 aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
190 aTables.setValue(True, 0, 0, 0) # value, index of selection, index of component, index of step
191 aTables.setValue(False, 1, 0, 0)
192 aSession.finishOperation()
193
194 aFieldResult = aField.firstResult()
195 assert(aFieldResult)
196
197 from salome.shaper import model
198 assert(model.checkPythonDump())