3 Unit test of ExchangePlugin_TestImport class
5 #=========================================================================
6 # Initialization of the test
7 #=========================================================================
9 from GeomDataAPI import *
10 from GeomAlgoAPI import *
15 __updated__ = "2015-05-22"
17 aSession = ModelAPI_Session.get()
18 #=========================================================================
19 # Common test function
20 #=========================================================================
21 def testImport(theType, theFile, theVolume, theDelta):
22 # Create a part for import
23 aSession.startOperation("Create part for import")
24 aPartFeature = aSession.moduleDocument().addFeature("Part")
25 aSession.finishOperation()
26 aPart = aSession.activeDocument()
28 aSession.startOperation("Import file")
29 aFeatureKind = "Import"
30 anImportFeature = aPart.addFeature(aFeatureKind)
31 assert anImportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind)
32 aFieldName = "file_path"
33 file = anImportFeature.string(aFieldName)
34 assert file, "{0}: Can not receive string field {1}".format(theType, aFieldName)
35 file.setValue(theFile)
36 aSession.finishOperation()
39 assert anImportFeature.error() == '', "{0}: The error after execution: {1}".format(theType, anImportFeature.error())
40 assert len(anImportFeature.results()) == 1, "{0}: Wrong number of results: expected = 1, real = {1}".format(theType, len(anImportFeature.results()))
41 aResultBody = modelAPI_ResultBody(anImportFeature.firstResult())
42 assert aResultBody, "{0}: The result is not a body".format(theType)
43 aShape = aResultBody.shape()
44 assert aShape, "{0}: The body does not have a shape".format(theType)
47 aRefVolume = theVolume
48 aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape)
49 assert (math.fabs(aResVolume - aRefVolume) < theDelta), "{0}: The volume is wrong: expected = {1}, real = {2}".format(theType, aRefVolume, aResVolume)
52 # Create a part for import
53 aSession.startOperation("Create part for import")
54 aPartFeature = aSession.moduleDocument().addFeature("Part")
55 aSession.finishOperation()
56 aPart = aSession.activeDocument()
58 aSession.startOperation("Import XAO")
59 anImportFeature = aPart.addFeature("Import")
60 anImportFeature.string("file_path").setValue("Data/test.xao")
61 aSession.finishOperation()
64 assert anImportFeature.error() == ''
65 assert anImportFeature.name() == "mygeom"
66 assert len(anImportFeature.results()) == 1
67 assert modelAPI_ResultBody(anImportFeature.firstResult())
68 assert anImportFeature.firstResult().data().name() == "mygeom_1"
69 aCompositeFeature = featureToCompositeFeature(anImportFeature)
70 assert aCompositeFeature.numberOfSubs(False) == 2
72 aFeature1 = aCompositeFeature.subFeature(0, False)
73 assert aFeature1.getKind() == "Group"
74 assert aFeature1.name() == "boite_1"
76 aSelectionList = aFeature1.selectionList("group_list")
77 assert aSelectionList.selectionType() == "Solids"
78 assert aSelectionList.size() == 1
79 assert aSelectionList.value(0).namingName("") == "mygeom_1_1"
81 aFeature2 = aCompositeFeature.subFeature(1, False)
82 assert aFeature2.getKind() == "Group"
83 assert aFeature2.name() == "Group_2"
85 aSelectionList = aFeature2.selectionList("group_list")
86 assert aSelectionList.selectionType() == "Faces"
87 assert aSelectionList.size() == 2
88 assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1_1"
89 assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2_1"
91 if __name__ == '__main__':
92 #=========================================================================
93 # Create a shape imported from BREP
94 #=========================================================================
95 testImport("BREP", "Data/solid.brep", 259982.297176, 10 ** -5)
96 testImport("BRP", "Data/solid.brp", 259982.297176, 10 ** -5)
97 #=========================================================================
98 # Create a shape imported from STEP
99 #=========================================================================
100 testImport("STP", "Data/screw.stp", 3.78827401738e-06, 10 ** -17)
101 testImport("STEP", "Data/screw.step", 3.78827401738e-06, 10 ** -17)
102 #=========================================================================
103 # Create a shape imported from IGES
104 #=========================================================================
105 testImport("IGES", "Data/bearing.iges", 6.86970803067e-14, 10 ** -25)
106 testImport("IGS", "Data/bearing.igs", 6.86970803067e-14, 10 ** -25)
107 #=========================================================================
108 # Create a shape imported from XAO
109 #=========================================================================
111 #=========================================================================
113 #=========================================================================