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 #=========================================================================
30 from tempfile import TemporaryDirectory
32 from ModelAPI import *
34 from TestImport import testImport
36 from salome.shaper import model
38 __updated__ = "2015-05-22"
40 aSession = ModelAPI_Session.get()
41 #=========================================================================
43 #=========================================================================
44 def removeFile(theFileName):
45 try: os.remove(theFileName)
47 assert not os.path.exists(theFileName), \
48 "Can not remove file {0}".format(theFileName)
50 #=========================================================================
51 # Common test function
52 #=========================================================================
53 def testExport(theType, theFormat, theFile, theVolume, theDelta):
54 # Import a reference part
55 aSession.startOperation("Add part")
56 aPartFeature = aSession.moduleDocument().addFeature("Part")
57 aSession.finishOperation()
58 aPart = aSession.activeDocument()
60 aSession.startOperation("Import screw")
61 anImportFeature = aPart.addFeature("Import")
62 aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "screw.step")
63 anImportFeature.string("file_path").setValue(aShapePath)
64 aSession.finishOperation()
68 aSession.startOperation("Export part")
69 anExportFeature = aPart.addFeature("Export")
70 anExportFeature.string("file_format").setValue(theFormat)
71 print("theFile=",theFile)
72 anExportFeature.string("file_path").setValue(theFile)
73 anExportFeature.string("ExportType").setValue("Regular")
74 aSelectionListAttr = anExportFeature.selectionList("selection_list")
75 aSelectionListAttr.setSelectionType("solids")
76 aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape())
77 aSession.finishOperation()
79 assert os.path.exists(theFile)
81 # Test exported file by importing
82 testImport(theType, theFile, theVolume, theDelta)
84 def testExportXAO(theFile):
85 # Import a reference part
86 aSession.startOperation("Add part")
87 aPartFeature = aSession.moduleDocument().addFeature("Part")
88 aSession.finishOperation()
89 aPart = aSession.activeDocument()
91 aSession.startOperation("Import Box_1")
92 anImportFeature = aPart.addFeature("Import")
93 aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Brep", "box1.brep")
94 anImportFeature.string("file_path").setValue(aShapePath)
95 aSession.finishOperation()
98 aSession.startOperation("First group")
99 aGroupFeature = aSession.activeDocument().addFeature("Group")
100 aGroupFeature.data().setName("boite_1")
101 aSelectionListAttr = aGroupFeature.selectionList("group_list")
102 aSelectionListAttr.setSelectionType("solid")
103 aSelectionListAttr.append(anImportFeature.lastResult(), None)
104 aSession.finishOperation()
106 aSession.startOperation("Second Group")
107 aGroupFeature = aSession.activeDocument().addFeature("Group")
108 aGroupFeature.data().setName("")
109 aSelectionListAttr = aGroupFeature.selectionList("group_list")
110 aSelectionListAttr.setSelectionType("face")
111 aSelectionListAttr.append("box1_1/Shape1")
112 aSelectionListAttr.append("box1_1/Shape2")
113 aSession.finishOperation()
115 aSession.startOperation("Create a field")
116 aField = aSession.activeDocument().addFeature("Field")
117 aSelectionListAttr = aField.selectionList("selected")
118 aSelectionListAttr.setSelectionType("face")
119 aSelectionListAttr.append("box1_1/Shape1")
120 aSelectionListAttr.append("box1_1/Shape2")
121 aComponentNames = aField.stringArray("components_names")
122 aComponentNames.setSize(2) # two components
123 aComponentNames.setValue(0, "temperatue")
124 aComponentNames.setValue(1, "porosity")
125 aStamps = aField.intArray("stamps")
126 aStamps.setSize(1) # one step
127 aStamps.setValue(0, 10)
128 aTables = aField.tables("values")
129 aTables.setType(2) # double
130 aTables.setSize(1 + 2, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
131 aTables.setValue(1., 0, 0, 0) # value, index of selection, index of component, index of step
132 aTables.setValue(2., 1, 0, 0)
133 aTables.setValue(3., 2, 0, 0)
134 aTables.setValue(4., 0, 1, 0)
135 aTables.setValue(5., 1, 1, 0)
136 aTables.setValue(6., 2, 1, 0)
137 aSession.finishOperation()
140 aSession.startOperation("Export to XAO")
141 anExportFeature = aPart.addFeature("Export")
142 anExportFeature.string("xao_file_path").setValue(theFile)
143 anExportFeature.string("file_format").setValue("XAO")
144 anExportFeature.string("ExportType").setValue("XAO")
145 anExportFeature.string("xao_author").setValue("me")
146 anExportFeature.string("xao_geometry_name").setValue("mygeom")
147 aSession.finishOperation()
149 # Check exported file
150 aRefPath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Xao", "box2.xao")
152 assert filecmp.cmp(theFile, aRefPath)
154 if __name__ == '__main__':
155 with TemporaryDirectory() as tmp_dir:
156 #=========================================================================
157 # Export a shape into BREP
158 #=========================================================================
159 aRealVolume = 3.78827401738e-06
160 testExport("BREP", "BREP", os.path.join(tmp_dir, "screw_export.brep"), aRealVolume, 10 ** -17)
161 testExport("BRP", "BREP", os.path.join(tmp_dir, "screw_export.brp"), aRealVolume, 10 ** -17)
162 #=========================================================================
163 # Export a shape into STEP
164 #=========================================================================
165 testExport("STEP", "STEP", os.path.join(tmp_dir, "screw_export.step"), 3.78825807533e-06, 10 ** -17)
166 testExport("STP", "STEP", os.path.join(tmp_dir, "screw_export.stp"), 3.78825807533e-06, 10 ** -17)
167 #=========================================================================
168 # Export a shape into IGES
169 #=========================================================================
170 testExport("IGES-5.1", "IGES-5.1", os.path.join(tmp_dir, "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17)
171 testExport("IGS-5.1", "IGES-5.1", os.path.join(tmp_dir, "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17)
172 testExport("IGES-5.3", "IGES-5.3", os.path.join(tmp_dir, "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17)
173 testExport("IGS-5.3", "IGES-5.3", os.path.join(tmp_dir, "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17)
174 #=========================================================================
175 # Export a shape into XAO
176 #=========================================================================
177 testExportXAO(os.path.join(tmp_dir, "export.xao"))
178 #=========================================================================
180 #=========================================================================
182 assert(model.checkPythonDump())