1 # Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
22 Unit test of ExchangePlugin_TestExport class
24 #=========================================================================
25 # Initialization of the test
26 #=========================================================================
32 from tempfile import TemporaryDirectory
36 from ModelAPI import *
38 from salome.shaper import model
40 from salome.geom import geomBuilder
42 from GeomAlgoAPI import *
44 __updated__ = "2015-05-22"
47 geompy = geomBuilder.New()
49 #=========================================================================
51 #=========================================================================
52 def removeFile(theFileName):
53 try: os.remove(theFileName)
55 assert not os.path.exists(theFileName), \
56 "Can not remove file {0}".format(theFileName)
58 #=========================================================================
60 #=========================================================================
61 def testExportSTL(theFile, theDelta, theErrorExpected = False):
64 partSet = model.moduleDocument()
65 Part_1 = model.addPart(partSet)
66 Part_1_doc = Part_1.document()
67 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
68 Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
71 # First export to GEOM
72 model.exportToGEOM(Part_1_doc)
77 print("theFile=",theFile)
79 # deflection relative 0.0001 et Ascii
80 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID","Box_1_1"),0.0001, 0.5, True,False)
82 #== assert os.path.exists(theFile)
85 test_stl_1 = geompy.ImportSTL(theFile)
86 Props = geompy.BasicProperties(test_stl_1)
87 print("\nBasic Properties:")
88 print(" Wires length: ", Props[0])
89 print(" Surface area: ", Props[1])
90 print(" Volume : ", Props[2])
92 aRefSurface = theSurface
93 aResSurface = Props[1]
94 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
99 # deflection relative 0.0001 et binaire
100 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, True,True)
103 test_stl_1 = geompy.ImportSTL(theFile)
104 Props = geompy.BasicProperties(test_stl_1)
105 print("\nBasic Properties:")
106 print(" Wires length: ", Props[0])
107 print(" Surface area: ", Props[1])
108 print(" Volume : ", Props[2])
110 aRefSurface = theSurface
111 aResSurface = Props[1]
112 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
117 # deflection absolue et AScii
118 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False, False)
121 test_stl_1 = geompy.ImportSTL(theFile)
122 Props = geompy.BasicProperties(test_stl_1)
123 print("\nBasic Properties:")
124 print(" Wires length: ", Props[0])
125 print(" Surface area: ", Props[1])
126 print(" Volume : ", Props[2])
128 aRefSurface = theSurface
129 aResSurface = Props[1]
130 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
133 # deflection absolue et binaire
134 model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False,True)
137 test_stl_1 = geompy.ImportSTL(theFile)
138 Props = geompy.BasicProperties(test_stl_1)
139 print("\nBasic Properties:")
140 print(" Wires length: ", Props[0])
141 print(" Surface area: ", Props[1])
142 print(" Volume : ", Props[2])
144 aRefSurface = theSurface
145 aResSurface = Props[1]
146 assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
150 if __name__ == '__main__':
151 with TemporaryDirectory() as tmp_dir:
152 aRealSurface = 0.00192878
153 #=========================================================================
154 # Export a shape into STL
155 #=========================================================================
156 testExportSTL(os.path.join(tmp_dir, "export.stl"), 10 ** -5, True)
157 #=========================================================================
159 #=========================================================================