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