]> SALOME platform Git repositories - modules/shaper.git/blob - src/ExchangePlugin/Test/TestExport.py
Salome HOME
ExchangePlugin uses selectionType() like face, solid instead of Faces, Solids...
[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 __updated__ = "2015-05-22"
19
20 aSession = ModelAPI_Session.get()
21 #=========================================================================
22 # Help functions
23 #=========================================================================
24 def removeFile(theFileName):
25     try: os.remove(theFileName)
26     except OSError: pass
27     assert not os.path.exists(theFileName), \
28             "Can not remove file {0}".format(theFileName)
29
30 #=========================================================================
31 # Common test function
32 #=========================================================================
33 def testExport(theType, theFormat, theFile, theVolume, theDelta):
34     # Import a reference part
35     aSession.startOperation("Add part")
36     aPartFeature = aSession.moduleDocument().addFeature("Part")
37     aSession.finishOperation()
38     aPart = aSession.activeDocument()
39
40     aSession.startOperation("Import screw")
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     aFeatureKind = "Export"
50     anExportFeature = aPart.addFeature(aFeatureKind)
51     assert anExportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind)
52
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)
57
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)
62
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())
68
69     anExportFeature.execute()
70     aSession.finishOperation()
71
72     assert os.path.exists(theFile), "{0}: Can not find exported file {1}".format(theType, theFile)
73
74     # Test exported file by importing
75     testImport(theType, theFile, theVolume, theDelta)
76
77 def testExportXAO():
78     # Import a reference part
79     aSession.startOperation("Add part")
80     aPartFeature = aSession.moduleDocument().addFeature("Part")
81     aSession.finishOperation()
82     aPart = aSession.activeDocument()
83
84     aSession.startOperation("Import Box_1")
85     anImportFeature = aPart.addFeature("Import")
86     anImportFeature.string("file_path").setValue("Data/Box_1.brep")
87     anImportFeature.execute()
88     aSession.finishOperation()
89
90     # Create groups
91     aSession.startOperation()
92     aGroupFeature = aSession.activeDocument().addFeature("Group")
93     aGroupFeature.data().setName("boite_1")
94     aSelectionListAttr = aGroupFeature.selectionList("group_list")
95     aSelectionListAttr.setSelectionType("solid")
96     aSelectionListAttr.append(anImportFeature.lastResult(), None)
97     aGroupFeature.execute()
98     aSession.finishOperation()
99
100     aSession.startOperation()
101     aGroupFeature = aSession.activeDocument().addFeature("Group")
102     aGroupFeature.data().setName("")
103     aSelectionListAttr = aGroupFeature.selectionList("group_list")
104     aSelectionListAttr.setSelectionType("face")
105     aSelectionListAttr.append("Box_1_1/Shape1_1")
106     aSelectionListAttr.append("Box_1_1/Shape2_1")
107     aGroupFeature.execute()
108     aSession.finishOperation()
109
110     # Export
111     aSession.startOperation("Export")
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 #=========================================================================