Fixed copyright dates, added the STEP file importer, and added the supporting tests.

This commit is contained in:
Jeremy Wright 2014-08-18 14:45:02 -04:00
parent d79b514018
commit 699636d699
18 changed files with 146 additions and 38 deletions

View File

@ -1,5 +1,5 @@
CadQuery
Copyright (C) 2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2014 Parametric Products Intellectual Holdings, LLC
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public

View File

@ -9,6 +9,7 @@ cadquery\workplane.py
cadquery\contrib\__init__.py
cadquery\freecad_impl\__init__.py
cadquery\freecad_impl\exporters.py
cadquery\freecad_impl\importers.py
cadquery\freecad_impl\geom.py
cadquery\freecad_impl\shapes.py
cadquery\plugins\__init__.py
@ -16,5 +17,6 @@ tests\TestCQSelectors.py
tests\TestCadObjects.py
tests\TestCadQuery.py
tests\TestExporters.py
tests\TestImporters.py
tests\TestWorkplanes.py
tests\__init__.py

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -4,6 +4,7 @@
from .freecad_impl.geom import Plane,BoundBox,Vector,Matrix,sortWiresByBuildOrder
from .freecad_impl.shapes import Shape,Vertex,Edge,Face,Wire,Solid,Shell,Compound
from .freecad_impl import exporters
from .freecad_impl import importers
#these items are the common implementation
@ -14,7 +15,7 @@ from .CQ import CQ,CQContext,Workplane
__all__ = [
'CQ','Workplane','plugins','selectors','Plane','BoundBox','Matrix','Vector','sortWiresByBuildOrder',
'Shape','Vertex','Edge','Wire','Solid','Shell','Compound','exporters', 'NearestToPointSelector','ParallelDirSelector','DirectionSelector','PerpendicularDirSelector','TypeSelector','DirectionMinMaxSelector','StringSyntaxSelector','Selector','plugins'
'Shape','Vertex','Edge','Wire','Solid','Shell','Compound','exporters', 'importers', 'NearestToPointSelector','ParallelDirSelector','DirectionSelector','PerpendicularDirSelector','TypeSelector','DirectionMinMaxSelector','StringSyntaxSelector','Selector','plugins'
]
__version__ = 0.9

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -0,0 +1,61 @@
"""
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.
CadQuery 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 2.1 of the License, or (at your option) any later version.
CadQuery 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 this library; If not, see <http://www.gnu.org/licenses/>
An exporter should provide functionality to accept a shape, and return
a string containing the model content.
"""
import cadquery
from .verutil import fc_import
FreeCAD = fc_import("FreeCAD")
Part = fc_import("FreeCAD.Part")
class ImportTypes:
STEP = "STEP"
class UNITS:
MM = "mm"
IN = "in"
def importShape(importType,fileName):
"""
Imports a file based on the type (STEP, STL, etc)
:param importType: The type of file that we're importing
:param fileName: THe name of the file that we're importing
"""
#Check to see what type of file we're working with
if importType == ImportTypes.STEP:
raise RuntimeError("Failed on purpose.")
#Loads a STEP file into a CQ object
def importStep(self,fileName):
"""
Accepts a file name and loads the STEP file into a cadquery shape
:param fileName: The path and name of the STEP file to be imported
"""
#Now read and return the shape
try:
rshape = Part.read(fileName)
r = Shape.cast(rshape)
#print "loadStep: " + str(r)
#print "Faces=%d" % cadquery.CQ(r).solids().size()
return cadquery.CQ(r)
except:
raise ValueError("STEP File Could not be loaded")

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -1,6 +1,6 @@
"""
CadQuery
Copyright (C) 2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2014 Parametric Products Intellectual Holdings, LLC
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.

View File

@ -13,4 +13,5 @@ suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestWorkplanes.TestWo
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCQSelectors.TestCQSelectors))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCadQuery.TestCadQuery))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestExporters.TestExporters))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestImporters.TestImporters))
unittest.TextTestRunner().run(suite)

View File

@ -831,5 +831,3 @@ class TestCadQuery(BaseTest):
result =topOfLid.union(bottom)
self.saveModel(result)

45
tests/TestImporters.py Normal file
View File

@ -0,0 +1,45 @@
"""
Tests file importers such as STEP
"""
#core modules
import StringIO
from cadquery import *
from cadquery import exporters
from cadquery import importers
from tests import BaseTest
#where unit test output will be saved
import sys
if sys.platform.startswith("win"):
OUTDIR = "c:/temp"
else:
OUTDIR = "/tmp"
class TestImporters(BaseTest):
def importBox(importType,fileName):
"""
Exports a simple box to a STEP file and then imports it again
:param importType: The type of file we're importing (STEP, STL, etc)
:param fileName: The path and name of the file to write to
"""
#We're importing a STEP file
if importType == ImportTypes.STEP:
#We first need to build a simple shape to export
shape = Workplane("XY").box(1,2,3).val
#Export the shape to a temporary file
shape.exportStep(fileName)
# Reimport the shape from the new STEP file
importedShape = importShape(importType,fileName)
def testSTEP(self):
"""
Tests STEP file import
"""
importBox(ImportTypes.STEP, OUTDIR + "/tempSTEP.step")
if __name__ == '__main__':
testSTEP()

View File

@ -47,4 +47,4 @@ class BaseTest(unittest.TestCase):
for i,j in zip(actual,expected):
self.assertAlmostEquals(i,j,places)
__all__ = [ 'TestCadObjects','TestCadQuery','TestCQSelectors','TestWorkplanes','TestExporters','TestCQSelectors']
__all__ = [ 'TestCadObjects','TestCadQuery','TestCQSelectors','TestWorkplanes','TestExporters','TestCQSelectors','TestImporters']