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 anImportFeature.execute()
37 aSession.finishOperation()
40 assert anImportFeature.error() == '', "{0}: The error after execution: {1}".format(theType, anImportFeature.error())
41 assert len(anImportFeature.results()) == 1, "{0}: Wrong number of results: expected = 1, real = {1}".format(theType, len(anImportFeature.results()))
42 aResultBody = modelAPI_ResultBody(anImportFeature.firstResult())
43 assert aResultBody, "{0}: The result is not a body".format(theType)
44 aShape = aResultBody.shape()
45 assert aShape, "{0}: The body does not have a shape".format(theType)
48 aRefVolume = theVolume
49 aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape)
50 assert (math.fabs(aResVolume - aRefVolume) < theDelta), "{0}: The volume is wrong: expected = {1}, real = {2}".format(theType, aRefVolume, aResVolume)
53 # Create a part for import
54 aSession.startOperation("Create part for import")
55 aPartFeature = aSession.moduleDocument().addFeature("Part")
56 aSession.finishOperation()
57 aPart = aSession.activeDocument()
59 aSession.startOperation("Import XAO")
60 anImportFeature = aPart.addFeature("Import")
61 anImportFeature.string("file_path").setValue("Data/test.xao")
62 anImportFeature.execute()
63 aSession.finishOperation()
66 assert anImportFeature.error() == ''
67 assert anImportFeature.name() == "mygeom"
68 assert len(anImportFeature.results()) == 1
69 assert modelAPI_ResultBody(anImportFeature.firstResult())
70 assert anImportFeature.firstResult().data().name() == "mygeom_1"
71 aCompositeFeature = featureToCompositeFeature(anImportFeature)
72 assert aCompositeFeature.numberOfSubs(False) == 2
74 aFeature1 = aCompositeFeature.subFeature(0, False)
75 assert aFeature1.getKind() == "Group"
76 assert aFeature1.name() == "boite_1"
78 aSelectionList = aFeature1.selectionList("group_list")
79 assert aSelectionList.selectionType() == "Solids"
80 assert aSelectionList.size() == 1
81 assert aSelectionList.value(0).namingName("") == "mygeom_1_1"
83 aFeature2 = aCompositeFeature.subFeature(1, False)
84 assert aFeature2.getKind() == "Group"
85 assert aFeature2.name() == "Group_2"
87 aSelectionList = aFeature2.selectionList("group_list")
88 assert aSelectionList.selectionType() == "Faces"
89 assert aSelectionList.size() == 2
90 assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1_1"
91 assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2_1"
93 if __name__ == '__main__':
94 #=========================================================================
95 # Create a shape imported from BREP
96 #=========================================================================
97 testImport("BREP", "Data/solid.brep", 259982.297176, 10 ** -5)
98 testImport("BRP", "Data/solid.brp", 259982.297176, 10 ** -5)
99 #=========================================================================
100 # Create a shape imported from STEP
101 #=========================================================================
102 testImport("STP", "Data/screw.stp", 3.78827401738e-06, 10 ** -17)
103 testImport("STEP", "Data/screw.step", 3.78827401738e-06, 10 ** -17)
104 #=========================================================================
105 # Create a shape imported from IGES
106 #=========================================================================
107 testImport("IGES", "Data/bearing.iges", 6.86970803067e-14, 10 ** -25)
108 testImport("IGS", "Data/bearing.igs", 6.86970803067e-14, 10 ** -25)
109 #=========================================================================
110 # Create a shape imported from XAO
111 #=========================================================================
113 #=========================================================================
115 #=========================================================================