1 # Copyright (C) 2014-2024 CEA, EDF
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 email : webmaster.salome@opencascade.com
22 Unit test of ExchangePlugin_TestExport class
24 #=========================================================================
25 # Initialization of the test
26 #=========================================================================
33 from tempfile import TemporaryDirectory
37 from ModelAPI import *
39 from salome.shaper import model
41 from salome.geom import geomBuilder
43 from GeomAlgoAPI import *
45 __updated__ = "2015-05-22"
48 geompy = geomBuilder.New()
50 #=========================================================================
52 #=========================================================================
53 def removeFile(theFileName):
54 try: os.remove(theFileName)
56 assert not os.path.exists(theFileName), \
57 "Can not remove file {0}".format(theFileName)
59 #=========================================================================
61 #=========================================================================
62 def testExportSTL(theFile, theDelta, theErrorExpected = False):
65 partSet = model.moduleDocument()
66 Part_1 = model.addPart(partSet)
67 Part_1_doc = Part_1.document()
68 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
69 Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
72 # First export to GEOM
73 model.exportToGEOM(Part_1_doc)
78 print("theFile=",theFile)
80 # deflection relative 0.0001 et Ascii
81 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID","Box_1_1"),0.0001, 0.5, True,False)
83 #== assert os.path.exists(theFile)
86 test_stl_1 = geompy.ImportSTL(theFile)
87 Props = geompy.BasicProperties(test_stl_1)
88 print("\nBasic Properties:")
89 print(" Wires length: ", Props[0])
90 print(" Surface area: ", Props[1])
91 print(" Volume : ", Props[2])
93 aRefSurface = theSurface
94 aResSurface = Props[1]
95 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
100 # deflection relative 0.0001 et binaire
101 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, True,True)
104 test_stl_1 = geompy.ImportSTL(theFile)
105 Props = geompy.BasicProperties(test_stl_1)
106 print("\nBasic Properties:")
107 print(" Wires length: ", Props[0])
108 print(" Surface area: ", Props[1])
109 print(" Volume : ", Props[2])
111 aRefSurface = theSurface
112 aResSurface = Props[1]
113 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
118 # deflection absolue et AScii
119 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False, False)
122 test_stl_1 = geompy.ImportSTL(theFile)
123 Props = geompy.BasicProperties(test_stl_1)
124 print("\nBasic Properties:")
125 print(" Wires length: ", Props[0])
126 print(" Surface area: ", Props[1])
127 print(" Volume : ", Props[2])
129 aRefSurface = theSurface
130 aResSurface = Props[1]
131 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
134 # deflection absolue et binaire
135 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False,True)
138 test_stl_1 = geompy.ImportSTL(theFile)
139 Props = geompy.BasicProperties(test_stl_1)
140 print("\nBasic Properties:")
141 print(" Wires length: ", Props[0])
142 print(" Surface area: ", Props[1])
143 print(" Volume : ", Props[2])
145 aRefSurface = theSurface
146 aResSurface = Props[1]
147 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
151 if __name__ == '__main__':
152 with TemporaryDirectory() as tmp_dir:
153 aRealSurface = 0.00192878
154 #=========================================================================
155 # Export a shape into STL
156 #=========================================================================
157 testExportSTL(os.path.join(tmp_dir, "export.stl"), 10 ** -5, True)
158 #=========================================================================
160 #=========================================================================