Salome HOME
Fix for Export test
[modules/shaper.git] / src / ExchangePlugin / Test / TestExport.py
1 """
2       TestExport.py
3       Unit test of ExchangePlugin_TestExport class
4 """
5 #=========================================================================
6 # Initialization of the test
7 #=========================================================================
8 import os
9 import math
10
11 from ModelAPI import *
12
13 from TestImport import testImport
14
15 import model
16
17 __updated__ = "2015-05-22"
18
19 aSession = ModelAPI_Session.get()
20 #=========================================================================
21 # Help functions
22 #=========================================================================
23 def removeFile(theFileName):
24     try: os.remove(theFileName)
25     except OSError: pass
26     assert not os.path.exists(theFileName), \
27             "Can not remove file {0}".format(theFileName)
28
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()
38
39     aSession.startOperation("Import screw")
40     anImport = model.addImport(aPart, "Data/screw.step")
41 #     anImportFeature = aPart.addFeature("Import")
42 #     anImportFeature.string("file_path").setValue("Data/screw.step")
43 #     anImportFeature.execute()
44     aSession.finishOperation()
45
46     removeFile(theFile)
47     # Export a part
48     aSession.startOperation("Export part")
49     model.exportToFile(aPart, theFile, anImport.result(), theFormat)
50 #     anExportFeature = aPart.addFeature("Export")
51 #     anExportFeature.string("file_format").setValue(theFormat)
52 #     anExportFeature.string("file_path").setValue(theFile)
53 #     aSelectionListAttr = anExportFeature.selectionList("selection_list")
54 #     aSelectionListAttr.setSelectionType("solids")
55 #     aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape())
56 #     anExportFeature.execute()
57     aSession.finishOperation()
58
59     assert os.path.exists(theFile)
60
61     # Test exported file by importing
62     testImport(theType, theFile, theVolume, theDelta)
63
64 def testExportXAO():
65     # Import a reference part
66     aSession.startOperation("Add part")
67     aPartFeature = aSession.moduleDocument().addFeature("Part")
68     aSession.finishOperation()
69     aPart = aSession.activeDocument()
70
71     aSession.startOperation("Import Box_1")
72     anImport = model.addImport(aPart, "Data/Box_1.brep")
73 #     anImportFeature = aPart.addFeature("Import")
74 #     anImportFeature.string("file_path").setValue("Data/Box_1.brep")
75 #     anImportFeature.execute()
76     aSession.finishOperation()
77
78     # Create groups
79     aSession.startOperation()
80     aGroup = model.addGroup(aPart, anImport.result())
81     aGroup.defaultResult().data().setName("boite_1")
82     aGroup.groupList().setSelectionType("solid")
83 #     aGroupFeature = aSession.activeDocument().addFeature("Group")
84 #     aGroupFeature.data().setName("boite_1")
85 #     aSelectionListAttr = aGroupFeature.selectionList("group_list")
86 #     aSelectionListAttr.setSelectionType("solid")
87 #     aSelectionListAttr.append(anImport.feature().lastResult(), None)
88 #     aGroupFeature.execute()
89     aSession.finishOperation()
90
91     aSession.startOperation()
92     aGroup = model.addGroup(aPart, [])
93     aGroup.groupList().setSelectionType("face")
94     aGroup.groupList().append("Box_1_1/Shape1_1")
95     aGroup.groupList().append("Box_1_1/Shape2_1")
96     aGroup.defaultResult().data().setName("")
97 #     aGroupFeature = aSession.activeDocument().addFeature("Group")
98 #     aGroupFeature.data().setName("")
99 #     aSelectionListAttr = aGroupFeature.selectionList("group_list")
100 #     aSelectionListAttr.setSelectionType("face")
101 #     aSelectionListAttr.append("Box_1_1/Shape1_1")
102 #     aSelectionListAttr.append("Box_1_1/Shape2_1")
103 #     aGroupFeature.execute()
104     aSession.finishOperation()
105
106     # Export
107     aSession.startOperation("Export")
108     model.exportToXAO(aPart, "Data/export.xao", "me", "mygeom")
109 #     anExportFeature = aPart.addFeature("Export")
110 # #     anExportFeature.string("ExportType").setValue("XAO")
111 #     anExportFeature.string("file_path").setValue("Data/export.xao")
112 # #     anExportFeature.string("file_format").setValue("XAO")
113 #     anExportFeature.string("xao_author").setValue("me")
114 #     anExportFeature.string("xao_geometry_name").setValue("mygeom")
115 #     anExportFeature.execute()
116     aSession.finishOperation()
117
118     # Check exported file
119 #    import filecmp
120 #    assert filecmp.cmp("Data/export.xao", "Data/export_ref.xao")
121
122 if __name__ == '__main__':
123 #=========================================================================
124 # Export a shape into BREP
125 #=========================================================================
126     aRealVolume = 3.78827401738e-06
127     testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17)
128     testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17)
129 #=========================================================================
130 # Export a shape into STEP
131 #=========================================================================
132     testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.78825807533e-06, 10 ** -17)
133     testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.78825807533e-06, 10 ** -17)
134 #=========================================================================
135 # Export a shape into IGES
136 #=========================================================================
137     testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17)
138     testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17)
139     testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17)
140     testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17)
141 #=========================================================================
142 # Export a shape into XAO
143 #=========================================================================
144     testExportXAO()
145 #=========================================================================
146 # End of test
147 #=========================================================================
148
149 assert(model.checkPythonDump())