代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/pythonocc-core 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python
##Copyright 2009 Thomas Paviot (tpaviot@gmail.com)
##
##This file is part of pythonOCC.
##
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
import os
import unittest
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.Core.TopoDS import TopoDS_Compound
from OCC.Extend.DataExchange import (
read_step_file,
read_step_file_with_names_colors,
read_stl_file,
read_iges_file,
write_step_file,
write_stl_file,
write_iges_file,
export_shape_to_svg,
)
from OCC.Extend.TopologyUtils import TopologyExplorer
SAMPLES_DIRECTORY = os.path.join(".", "test_io")
def get_test_fullname(filename):
return os.path.join(SAMPLES_DIRECTORY, filename)
# the sample files
STEP_AP203_SAMPLE_FILE = get_test_fullname("as1_pe_203.stp")
STEP_AP214_SAMPLE_FILE = get_test_fullname("as1-oc-214.stp")
STEP_MULTIPLE_ROOT = get_test_fullname("stp_multiple_shp_at_root.stp")
IGES_SAMPLE_FILE = get_test_fullname("sunglasses_lens.igs")
IGES_45_FACES = get_test_fullname("example_45_faces.iges")
STL_ASCII_SAMPLE_FILE = get_test_fullname("bottle_ascii.stl")
STL_BINARY_SAMPLE_FILE = get_test_fullname("cube_binary.stl")
# the basic geometry to test exporters
A_TOPODS_SHAPE = BRepPrimAPI_MakeTorus(200, 50).Shape()
class TestExtendDataExchange(unittest.TestCase):
def test_read_step_file(self):
read_step_file(STEP_AP203_SAMPLE_FILE)
read_step_file(STEP_AP214_SAMPLE_FILE)
def test_read_step_file_multiple_shape_as_root(self):
t = read_step_file(STEP_MULTIPLE_ROOT, as_compound=True)
self.assertTrue(isinstance(t, TopoDS_Compound))
l = read_step_file(STEP_MULTIPLE_ROOT, as_compound=False)
self.assertEqual(len(l), 3)
def test_read_step_file_names_colors(self):
read_step_file_with_names_colors(STEP_AP203_SAMPLE_FILE)
read_step_file_with_names_colors(STEP_AP214_SAMPLE_FILE)
def test_read_iges_file(self):
read_iges_file(IGES_SAMPLE_FILE)
def test_read_iges_45_shapes(self):
all_shapes = read_iges_file(
IGES_45_FACES, return_as_shapes=True, verbosity=True
)
self.assertEqual(len(all_shapes), 1)
topo_explorer = TopologyExplorer(all_shapes[0])
self.assertEqual(topo_explorer.number_of_faces(), 45)
def test_read_stl_file(self):
read_stl_file(STL_ASCII_SAMPLE_FILE)
read_stl_file(STL_BINARY_SAMPLE_FILE)
def test_export_shape_to_svg(self):
svg_filename = get_test_fullname("sample.svg")
export_shape_to_svg(A_TOPODS_SHAPE, svg_filename)
self.assertTrue(os.path.isfile(svg_filename))
def test_write_step_ap203(self):
ap203_filename = get_test_fullname("sample_ap_203.stp")
write_step_file(A_TOPODS_SHAPE, ap203_filename, application_protocol="AP203")
self.assertTrue(os.path.isfile(ap203_filename))
def test_write_step_ap214(self):
as214_filename = get_test_fullname("sample_214.stp")
write_step_file(A_TOPODS_SHAPE, as214_filename, application_protocol="AP214IS")
self.assertTrue(os.path.isfile(as214_filename))
def test_write_step_ap242(self):
ap242_filename = get_test_fullname("sample_242.stp")
write_step_file(A_TOPODS_SHAPE, ap242_filename, application_protocol="AP242DIS")
self.assertTrue(os.path.isfile(ap242_filename))
def test_write_iges(self):
iges_filename = get_test_fullname("sample.igs")
write_iges_file(A_TOPODS_SHAPE, iges_filename)
self.assertTrue(os.path.isfile(iges_filename))
def test_stl_ascii(self):
stl_ascii_filename = get_test_fullname("sample_ascii.stl")
write_stl_file(A_TOPODS_SHAPE, stl_ascii_filename, mode="ascii")
self.assertTrue(os.path.isfile(stl_ascii_filename))
def test_stl_binary(self):
stl_binary_filename = get_test_fullname("sample_binary.stl")
write_stl_file(A_TOPODS_SHAPE, stl_binary_filename, mode="binary")
self.assertTrue(os.path.isfile(stl_binary_filename))
def suite():
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(TestExtendDataExchange))
return test_suite
if __name__ == "__main__":
unittest.main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。