3 Unit test of ExchangePlugin_TestExport class
5 #=========================================================================
6 # Initialization of the test
7 #=========================================================================
11 from ModelAPI import *
13 from TestImport import testImport
15 from salome.shaper import model
17 __updated__ = "2015-05-22"
19 aSession = ModelAPI_Session.get()
20 #=========================================================================
22 #=========================================================================
23 def removeFile(theFileName):
24 try: os.remove(theFileName)
26 assert not os.path.exists(theFileName), \
27 "Can not remove file {0}".format(theFileName)
29 #=========================================================================
30 # Common test function
31 #=========================================================================
32 def testExport(theType, theFormat, theFile, theVolume, theDelta):
33 # Import a reference part
34 aSession.startOperation("Add part")
35 aPartFeature = aSession.moduleDocument().addFeature("Part")
36 aSession.finishOperation()
37 aPart = aSession.activeDocument()
39 aSession.startOperation("Import screw")
40 anImportFeature = aPart.addFeature("Import")
41 anImportFeature.string("file_path").setValue("Data/screw.step")
42 aSession.finishOperation()
46 aSession.startOperation("Export part")
47 anExportFeature = aPart.addFeature("Export")
48 anExportFeature.string("file_format").setValue(theFormat)
49 print "theFile=",theFile
50 anExportFeature.string("file_path").setValue(theFile)
51 anExportFeature.string("ExportType").setValue("Regular")
52 aSelectionListAttr = anExportFeature.selectionList("selection_list")
53 aSelectionListAttr.setSelectionType("solids")
54 aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape())
55 aSession.finishOperation()
57 assert os.path.exists(theFile)
59 # Test exported file by importing
60 testImport(theType, theFile, theVolume, theDelta)
63 # Import a reference part
64 aSession.startOperation("Add part")
65 aPartFeature = aSession.moduleDocument().addFeature("Part")
66 aSession.finishOperation()
67 aPart = aSession.activeDocument()
69 aSession.startOperation("Import Box_1")
70 anImportFeature = aPart.addFeature("Import")
71 anImportFeature.string("file_path").setValue("Data/Box_1.brep")
72 aSession.finishOperation()
75 aSession.startOperation("First group")
76 aGroupFeature = aSession.activeDocument().addFeature("Group")
77 aGroupFeature.data().setName("boite_1")
78 aSelectionListAttr = aGroupFeature.selectionList("group_list")
79 aSelectionListAttr.setSelectionType("solid")
80 aSelectionListAttr.append(anImportFeature.lastResult(), None)
81 aSession.finishOperation()
83 aSession.startOperation("Second Group")
84 aGroupFeature = aSession.activeDocument().addFeature("Group")
85 aGroupFeature.data().setName("")
86 aSelectionListAttr = aGroupFeature.selectionList("group_list")
87 aSelectionListAttr.setSelectionType("face")
88 aSelectionListAttr.append("Box_1_1/Shape1")
89 aSelectionListAttr.append("Box_1_1/Shape2")
90 aSession.finishOperation()
92 aSession.startOperation("Create a field")
93 aField = aSession.activeDocument().addFeature("Field")
94 aSelectionListAttr = aField.selectionList("selected")
95 aSelectionListAttr.setSelectionType("face")
96 aSelectionListAttr.append("Box_1_1/Shape1")
97 aSelectionListAttr.append("Box_1_1/Shape2")
98 aComponentNames = aField.stringArray("components_names")
99 aComponentNames.setSize(2) # two components
100 aComponentNames.setValue(0, "temperatue")
101 aComponentNames.setValue(1, "porosity")
102 aStamps = aField.intArray("stamps")
103 aStamps.setSize(1) # one step
104 aStamps.setValue(0, 10)
105 aTables = aField.tables("values")
106 aTables.setType(2) # double
107 aTables.setSize(1 + 2, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
108 aTables.setValue(1., 0, 0, 0) # value, index of selection, index of component, index of step
109 aTables.setValue(2., 1, 0, 0)
110 aTables.setValue(3., 2, 0, 0)
111 aTables.setValue(4., 0, 1, 0)
112 aTables.setValue(5., 1, 1, 0)
113 aTables.setValue(6., 2, 1, 0)
114 aSession.finishOperation()
117 aSession.startOperation("Export to XAO")
118 anExportFeature = aPart.addFeature("Export")
119 anExportFeature.string("xao_file_path").setValue("Data/export.xao")
120 anExportFeature.string("file_format").setValue("XAO")
121 anExportFeature.string("ExportType").setValue("XAO")
122 anExportFeature.string("xao_author").setValue("me")
123 anExportFeature.string("xao_geometry_name").setValue("mygeom")
124 aSession.finishOperation()
126 # Check exported file
128 # assert filecmp.cmp("Data/export.xao", "Data/export_ref.xao")
130 if __name__ == '__main__':
131 #=========================================================================
132 # Export a shape into BREP
133 #=========================================================================
134 aRealVolume = 3.78827401738e-06
135 testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17)
136 testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17)
137 #=========================================================================
138 # Export a shape into STEP
139 #=========================================================================
140 testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.78825807533e-06, 10 ** -17)
141 testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.78825807533e-06, 10 ** -17)
142 #=========================================================================
143 # Export a shape into IGES
144 #=========================================================================
145 testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17)
146 testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17)
147 testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17)
148 testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17)
149 #=========================================================================
150 # Export a shape into XAO
151 #=========================================================================
153 #=========================================================================
155 #=========================================================================
157 assert(model.checkPythonDump())