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