3 Unit test of ExchangePlugin_TestExport class
5 #=========================================================================
6 # Initialization of the test
7 #=========================================================================
11 from ModelAPI import *
12 from GeomDataAPI import *
13 from GeomAlgoAPI import *
16 from TestImport import testImport
18 __updated__ = "2015-05-22"
20 aSession = ModelAPI_Session.get()
21 #=========================================================================
23 #=========================================================================
24 def removeFile(theFileName):
25 try: os.remove(theFileName)
27 assert not os.path.exists(theFileName), \
28 "Can not remove file {0}".format(theFileName)
30 #=========================================================================
31 # Common test function
32 #=========================================================================
33 def testExport(theType, theFormat, theFile, theVolume, theDelta):
34 # Import a reference part
35 aSession.startOperation()
36 aPartFeature = aSession.moduleDocument().addFeature("Part")
37 aSession.finishOperation()
38 aPart = aSession.activeDocument()
40 aSession.startOperation()
41 anImportFeature = aPart.addFeature("Import")
42 anImportFeature.string("file_path").setValue("Data/screw.step")
43 anImportFeature.execute()
44 aSession.finishOperation()
48 aSession.startOperation()
49 aFeatureKind = "Export"
50 anExportFeature = aPart.addFeature(aFeatureKind)
51 assert anExportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind)
53 aFormatAttrName = "file_format"
54 aFormatAttr = anExportFeature.string(aFormatAttrName)
55 assert aFormatAttr, "{0}: Can not receive string field {1}".format(theType, aFormatAttrName)
56 aFormatAttr.setValue(theFormat)
58 aFileAttrName = "file_path"
59 aFileAttr = anExportFeature.string(aFileAttrName)
60 assert aFileAttr, "{0}: Can not receive string field {1}".format(theType, aFileAttrName)
61 aFileAttr.setValue(theFile)
63 aSelectionListAttrName = "selection_list"
64 aSelectionListAttr = anExportFeature.selectionList(aSelectionListAttrName)
65 assert aSelectionListAttr, "{0}: Can not receive selection list field {1}".format(theType, aSelectionListAttrName)
66 aSelectionListAttr.setSelectionType("solids")
67 aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape())
69 anExportFeature.execute()
70 aSession.finishOperation()
72 assert os.path.exists(theFile), "{0}: Can not find exported file {1}".format(theType, theFile)
74 # Test exported file by importing
75 testImport(theType, theFile, theVolume, theDelta)
77 if __name__ == '__main__':
78 #=========================================================================
79 # Export a shape into BREP
80 #=========================================================================
81 aRealVolume = 3.78827059338e-06
82 testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17)
83 testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17)
84 #=========================================================================
85 # Export a shape into STEP
86 #=========================================================================
87 testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.7882546512e-06, 10 ** -17)
88 testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.7882546512e-06, 10 ** -17)
89 #=========================================================================
90 # Export a shape into IGES
91 #=========================================================================
92 testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78827190923e-06, 10 ** -17)
93 testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78827190923e-06, 10 ** -17)
94 testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827060085e-06, 10 ** -17)
95 testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827060085e-06, 10 ** -17)
96 #=========================================================================
98 #=========================================================================