]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConnectorAPI/Test/TestImportSTEP.py
Salome HOME
84b6d90ce96b8cab3f7426adcc290379fe05adc3
[modules/shaper.git] / src / ConnectorAPI / Test / TestImportSTEP.py
1 # Copyright (C) 2014-2020  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       TestImportStep.py
22       Unit test of ExchangePlugin_ImportFeature class for STEP 
23 """
24 #=========================================================================
25 # Initialization of the test
26 #=========================================================================
27
28 import salome
29
30 import os
31 import math
32 from tempfile import TemporaryDirectory
33
34 import GEOM
35
36 from ModelAPI import *
37
38 from salome.shaper import model
39
40 from salome.geom import geomBuilder
41
42 from GeomAPI import GeomAPI_Shape
43
44 from GeomAlgoAPI import *
45
46 __updated__ = "2015-05-22"
47
48 salome.salome_init(1)
49 geompy = geomBuilder.New()
50
51 #=========================================================================
52 # Help functions
53 #=========================================================================
54 def removeFile(theFileName):
55     try: os.remove(theFileName)
56     except OSError: pass
57     assert not os.path.exists(theFileName), \
58             "Can not remove file {0}".format(theFileName)
59
60 #=========================================================================
61 # test Import STEP 
62 #=========================================================================
63 def testImportSTEP():
64
65     model.begin()
66     partSet = model.moduleDocument()
67     Part_1 = model.addPart(partSet)
68     Part_1_doc = Part_1.document()
69     aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "black_and_white.step")
70     print("aShapePath=",aShapePath)
71     Import_1 = model.addImportSTEP(Part_1_doc,aShapePath, True, True, True)
72
73     model.do()
74
75     # Check results
76     Import_1_Feature = Import_1.feature()
77     assert Import_1_Feature.error() == ''
78     assert Import_1_Feature.name() == "black_and_white"
79     assert len(Import_1_Feature.results()) == 1
80     model.testNbSubShapes(Import_1, GeomAPI_Shape.SOLID, [2])
81
82     aCompositeFeature = featureToCompositeFeature(Import_1_Feature)
83     assert aCompositeFeature.numberOfSubs(False) == 4
84
85     aFeature1 = aCompositeFeature.subFeature(0, False)
86     assert aFeature1.getKind() == "Group"
87     assert aFeature1.name() == "Color_1"
88
89     aSelectionList = aFeature1.selectionList("group_list")
90     assert aSelectionList.size() == 1
91
92     aFeature1 = aCompositeFeature.subFeature(1, False)
93     assert aFeature1.getKind() == "Group"
94     assert aFeature1.name() == "Color_2"
95
96     aSelectionList = aFeature1.selectionList("group_list")
97     assert aSelectionList.size() == 1
98
99     aFeature1 = aCompositeFeature.subFeature(2, False)
100     assert aFeature1.getKind() == "Group"
101     assert aFeature1.name() == "Material_black"
102
103     aSelectionList = aFeature1.selectionList("group_list")
104     assert aSelectionList.size() == 1
105
106
107     aFeature1 = aCompositeFeature.subFeature(3, False)
108     assert aFeature1.getKind() == "Group"
109     assert aFeature1.name() == "Material_white"
110
111     aSelectionList = aFeature1.selectionList("group_list")
112     assert aSelectionList.size() == 1
113
114     model.end()
115
116 if __name__ == '__main__':
117     with TemporaryDirectory() as tmp_dir:
118         #=========================================================================
119         # Export a shape into STL
120         #=========================================================================
121         testImportSTEP()
122         #=========================================================================
123         # End of test
124         #=========================================================================