1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## Lesser General Public License for more details.
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
23 Unit test of ExchangePlugin_TestExport class
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
31 from ModelAPI import *
33 from TestImport import testImport
35 from salome.shaper import model
37 __updated__ = "2015-05-22"
39 aSession = ModelAPI_Session.get()
40 #=========================================================================
42 #=========================================================================
43 def removeFile(theFileName):
44 try: os.remove(theFileName)
46 assert not os.path.exists(theFileName), \
47 "Can not remove file {0}".format(theFileName)
49 #=========================================================================
50 # Common test function
51 #=========================================================================
52 def testExport(theType, theFormat, theFile, theVolume, theDelta):
53 # Import a reference part
54 aSession.startOperation("Add part")
55 aPartFeature = aSession.moduleDocument().addFeature("Part")
56 aSession.finishOperation()
57 aPart = aSession.activeDocument()
59 aSession.startOperation("Import screw")
60 anImportFeature = aPart.addFeature("Import")
61 anImportFeature.string("file_path").setValue("Data/screw.step")
62 aSession.finishOperation()
66 aSession.startOperation("Export part")
67 anExportFeature = aPart.addFeature("Export")
68 anExportFeature.string("file_format").setValue(theFormat)
69 print "theFile=",theFile
70 anExportFeature.string("file_path").setValue(theFile)
71 anExportFeature.string("ExportType").setValue("Regular")
72 aSelectionListAttr = anExportFeature.selectionList("selection_list")
73 aSelectionListAttr.setSelectionType("solids")
74 aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape())
75 aSession.finishOperation()
77 assert os.path.exists(theFile)
79 # Test exported file by importing
80 testImport(theType, theFile, theVolume, theDelta)
83 # Import a reference part
84 aSession.startOperation("Add part")
85 aPartFeature = aSession.moduleDocument().addFeature("Part")
86 aSession.finishOperation()
87 aPart = aSession.activeDocument()
89 aSession.startOperation("Import Box_1")
90 anImportFeature = aPart.addFeature("Import")
91 anImportFeature.string("file_path").setValue("Data/Box_1.brep")
92 aSession.finishOperation()
95 aSession.startOperation("First group")
96 aGroupFeature = aSession.activeDocument().addFeature("Group")
97 aGroupFeature.data().setName("boite_1")
98 aSelectionListAttr = aGroupFeature.selectionList("group_list")
99 aSelectionListAttr.setSelectionType("solid")
100 aSelectionListAttr.append(anImportFeature.lastResult(), None)
101 aSession.finishOperation()
103 aSession.startOperation("Second Group")
104 aGroupFeature = aSession.activeDocument().addFeature("Group")
105 aGroupFeature.data().setName("")
106 aSelectionListAttr = aGroupFeature.selectionList("group_list")
107 aSelectionListAttr.setSelectionType("face")
108 aSelectionListAttr.append("Box_1_1/Shape1")
109 aSelectionListAttr.append("Box_1_1/Shape2")
110 aSession.finishOperation()
112 aSession.startOperation("Create a field")
113 aField = aSession.activeDocument().addFeature("Field")
114 aSelectionListAttr = aField.selectionList("selected")
115 aSelectionListAttr.setSelectionType("face")
116 aSelectionListAttr.append("Box_1_1/Shape1")
117 aSelectionListAttr.append("Box_1_1/Shape2")
118 aComponentNames = aField.stringArray("components_names")
119 aComponentNames.setSize(2) # two components
120 aComponentNames.setValue(0, "temperatue")
121 aComponentNames.setValue(1, "porosity")
122 aStamps = aField.intArray("stamps")
123 aStamps.setSize(1) # one step
124 aStamps.setValue(0, 10)
125 aTables = aField.tables("values")
126 aTables.setType(2) # double
127 aTables.setSize(1 + 2, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
128 aTables.setValue(1., 0, 0, 0) # value, index of selection, index of component, index of step
129 aTables.setValue(2., 1, 0, 0)
130 aTables.setValue(3., 2, 0, 0)
131 aTables.setValue(4., 0, 1, 0)
132 aTables.setValue(5., 1, 1, 0)
133 aTables.setValue(6., 2, 1, 0)
134 aSession.finishOperation()
137 aSession.startOperation("Export to XAO")
138 anExportFeature = aPart.addFeature("Export")
139 anExportFeature.string("xao_file_path").setValue("Data/export.xao")
140 anExportFeature.string("file_format").setValue("XAO")
141 anExportFeature.string("ExportType").setValue("XAO")
142 anExportFeature.string("xao_author").setValue("me")
143 anExportFeature.string("xao_geometry_name").setValue("mygeom")
144 aSession.finishOperation()
146 # Check exported file
148 # assert filecmp.cmp("Data/export.xao", "Data/export_ref.xao")
150 if __name__ == '__main__':
151 #=========================================================================
152 # Export a shape into BREP
153 #=========================================================================
154 aRealVolume = 3.78827401738e-06
155 testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17)
156 testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17)
157 #=========================================================================
158 # Export a shape into STEP
159 #=========================================================================
160 testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.78825807533e-06, 10 ** -17)
161 testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.78825807533e-06, 10 ** -17)
162 #=========================================================================
163 # Export a shape into IGES
164 #=========================================================================
165 testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17)
166 testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17)
167 testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17)
168 testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17)
169 #=========================================================================
170 # Export a shape into XAO
171 #=========================================================================
173 #=========================================================================
175 #=========================================================================
177 assert(model.checkPythonDump())