From d15c97ac359a341a8b663318433e121b4c800ec7 Mon Sep 17 00:00:00 2001 From: Ruslan Panasiuk Date: Mon, 1 Jan 2018 00:33:24 +0300 Subject: [PATCH] Fixes importing binary stl + test; cleanup; --- .gitignore | 1 + pycam/Importers/STLImporter.py | 17 ++++++++-- pycam/Test/assets/cube_binary.stl | Bin 0 -> 684 bytes pycam/Test/test_stl_loader.py | 51 ++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 pycam/Test/assets/cube_binary.stl create mode 100644 pycam/Test/test_stl_loader.py diff --git a/.gitignore b/.gitignore index dd44fc82..669f3bf3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ eggs .svn .coverage .idea +.ropeproject/ .DS_Store* ehthumbs.db diff --git a/pycam/Importers/STLImporter.py b/pycam/Importers/STLImporter.py index 24415dc9..e054d997 100644 --- a/pycam/Importers/STLImporter.py +++ b/pycam/Importers/STLImporter.py @@ -32,6 +32,10 @@ import pycam.Utils log = pycam.Utils.log.get_logger() +# The amount of bytes in the header field +HEADER_SIZE = 80 +# The amount of bytes in the count field +COUNT_SIZE = 4 vertices = 0 edges = 0 @@ -66,7 +70,11 @@ def get_facet_count_if_binary_format(source): """ # read data (without consuming it) raw_header_data = source.peek(400) - facet_count = unpack("s41_y?Ll_n@&fp5Zn3%W%o4J}C_=O5Q+Qb~~{n&=>I*&crUp3{RxYWFP zHS?dCwl^C&P=a!~iph1SJ|PS!75~t?R(7P;D`5w-INpqG9AHUmZ_(5{c)x1h&=h%J oB_eL1_vjs@R9>5*fF1R{LzC8lih1eTjw$)5d&B|b9i)hR07pe6HUIzs literal 0 HcmV?d00001 diff --git a/pycam/Test/test_stl_loader.py b/pycam/Test/test_stl_loader.py new file mode 100644 index 00000000..f4afd45c --- /dev/null +++ b/pycam/Test/test_stl_loader.py @@ -0,0 +1,51 @@ +""" +Copyright 2018 Ruslan Panasiuk + +This file is part of PyCAM. + +PyCAM is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +PyCAM 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with PyCAM. If not, see . +""" + +import os + +import pycam.Test +from pycam.Importers.STLImporter import import_model + +cwd = os.path.dirname(os.path.abspath(__file__)) + +ASSETS_DIR = 'assets' + + +def path_to_asset(asset_name: str) -> str: + """ + Returns abs path for given `asset_name` + :param asset_name: file name of the asset from 'Tests/assets' + :returns: str - abs path to asset + """ + return os.path.join(cwd, ASSETS_DIR, asset_name) + + +# Placeholder +class TestASCIILoader(pycam.Test.PycamTestCase): + pass + + +class TestBinaryLoader(pycam.Test.PycamTestCase): + """ + Checks ability to load binary .stl files correctly + """ + + def test_load_binary_file(self): + model = import_model(path_to_asset('cube_binary.stl')) + self.assertEqual(len(model), 12)