1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
23 Unit test of ExchangePlugin_TestImport class
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
28 from ModelAPI import *
29 from GeomAlgoAPI import *
32 __updated__ = "2015-05-22"
34 aSession = ModelAPI_Session.get()
35 #=========================================================================
36 # Common test function
37 #=========================================================================
38 def testImport(theType, theFile, theVolume, theDelta):
39 # Create a part for import
40 aSession.startOperation("Create part for import")
41 aPartFeature = aSession.moduleDocument().addFeature("Part")
42 aSession.finishOperation()
43 aPart = aSession.activeDocument()
45 aSession.startOperation("Import file")
46 aFeatureKind = "Import"
47 anImportFeature = aPart.addFeature(aFeatureKind)
48 assert anImportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind)
49 aFieldName = "file_path"
50 file = anImportFeature.string(aFieldName)
51 assert file, "{0}: Can not receive string field {1}".format(theType, aFieldName)
52 file.setValue(theFile)
53 aSession.finishOperation()
56 assert anImportFeature.error() == '', "{0}: The error after execution: {1}".format(theType, anImportFeature.error())
57 assert len(anImportFeature.results()) == 1, "{0}: Wrong number of results: expected = 1, real = {1}".format(theType, len(anImportFeature.results()))
58 aResultBody = modelAPI_ResultBody(anImportFeature.firstResult())
59 assert aResultBody, "{0}: The result is not a body".format(theType)
60 aShape = aResultBody.shape()
61 assert aShape, "{0}: The body does not have a shape".format(theType)
64 aRefVolume = theVolume
65 aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape)
66 assert (math.fabs(aResVolume - aRefVolume) < theDelta), "{0}: The volume is wrong: expected = {1}, real = {2}".format(theType, aRefVolume, aResVolume)
69 # Create a part for import
70 aSession.startOperation("Create part for import")
71 aPartFeature = aSession.moduleDocument().addFeature("Part")
72 aSession.finishOperation()
73 aPart = aSession.activeDocument()
75 aSession.startOperation("Import XAO")
76 anImportFeature = aPart.addFeature("Import")
77 anImportFeature.string("file_path").setValue("Data/test.xao")
78 aSession.finishOperation()
81 assert anImportFeature.error() == ''
82 assert anImportFeature.name() == "mygeom"
83 assert len(anImportFeature.results()) == 1
84 assert modelAPI_ResultBody(anImportFeature.firstResult())
85 assert anImportFeature.firstResult().data().name() == "mygeom_1"
86 aCompositeFeature = featureToCompositeFeature(anImportFeature)
87 # Two groups and one field
88 assert aCompositeFeature.numberOfSubs(False) == 3
90 aFeature1 = aCompositeFeature.subFeature(0, False)
91 assert aFeature1.getKind() == "Group"
92 assert aFeature1.name() == "boite_1"
94 aSelectionList = aFeature1.selectionList("group_list")
95 assert aSelectionList.selectionType() == "solid"
96 assert aSelectionList.size() == 1
97 assert aSelectionList.value(0).namingName("") == "mygeom_1"
99 aFeature2 = aCompositeFeature.subFeature(1, False)
100 assert aFeature2.getKind() == "Group"
101 assert aFeature2.name() == "Group_2"
103 aSelectionList = aFeature2.selectionList("group_list")
104 assert aSelectionList.selectionType() == "face"
105 assert aSelectionList.size() == 2
106 assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1"
107 print aSelectionList.value(1).namingName("")
108 assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2"
110 aFeature3 = aCompositeFeature.subFeature(2, False)
111 assert aFeature3.getKind() == "Field"
112 assert aFeature3.name() == "color"
113 assert aFeature3.intArray("stamps").size() == 2
114 assert aFeature3.tables("values").rows() == 2
115 assert aFeature3.tables("values").columns() == 3
116 assert aFeature3.tables("values").tables() == 2
117 assert aFeature3.tables("values").type() == 1 # integer
118 assert aFeature3.selectionList("selected").size() == 1
120 if __name__ == '__main__':
121 #=========================================================================
122 # Create a shape imported from BREP
123 #=========================================================================
124 testImport("BREP", "Data/solid.brep", 259982.297176, 10 ** -5)
125 testImport("BRP", "Data/solid.brp", 259982.297176, 10 ** -5)
126 #=========================================================================
127 # Create a shape imported from STEP
128 #=========================================================================
129 testImport("STP", "Data/screw.stp", 3.78827401738e-06, 10 ** -17)
130 testImport("STEP", "Data/screw.step", 3.78827401738e-06, 10 ** -17)
131 #=========================================================================
132 # Create a shape imported from IGES
133 #=========================================================================
134 testImport("IGES", "Data/bearing.iges", 6.86970803067e-14, 10 ** -25)
135 testImport("IGS", "Data/bearing.igs", 6.86970803067e-14, 10 ** -25)
136 #=========================================================================
137 # Create a shape imported from XAO
138 #=========================================================================
140 #=========================================================================
142 #=========================================================================
144 from salome.shaper import model
145 assert(model.checkPythonDump())