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
@ -180,4 +180,4 @@ General Public License ever published by the Free Software Foundation.
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
Library.

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,8 +1,8 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
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
@ -848,10 +848,10 @@ class Workplane(CQ):
#old api accepted a vector, so we'll check for that.
if rotate.__class__.__name__ == 'Vector':
rotate = rotate.toTuple()
if offset.__class__.__name__ == 'Vector':
offset = offset.toTuple()
p = self.plane.rotated(rotate)
p.setOrigin3d(self.plane.toWorldCoords(offset ))
ns = self.newObject([p.origin])
@ -1223,10 +1223,10 @@ class Workplane(CQ):
Future Enhancements:
faster implementation: this one transforms 3 times to accomplish the result
"""
#convert edges to a wire, if there are pending edges
n = self.wire(forConstruction=False)
@ -1234,7 +1234,7 @@ class Workplane(CQ):
consolidated = n.consolidateWires()
rotatedWires = self.plane.rotateShapes(consolidated.wires().vals(),matrix)
for w in rotatedWires:
consolidated.objects.append(w)
consolidated._addPendingWire(w)
@ -2167,4 +2167,4 @@ class Workplane(CQ):
else:
#combine everything
return self.union(boxes)

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
__version__ = 0.9

View File

@ -1,8 +1,8 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
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
@ -15,4 +15,4 @@
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/>
"""
"""

View File

@ -1,8 +1,8 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
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

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,8 +1,8 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
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

View File

@ -1,8 +1,8 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
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

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))
unittest.TextTestRunner().run(suite)
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)

View File

@ -13,31 +13,31 @@ class TestExporters(BaseTest):
def _exportBox(self,eType,stringsToFind):
"""
Exports a test object, and then looks for
Exports a test object, and then looks for
all of the supplied strings to be in the result
returns the result in case the case wants to do more checks also
"""
p = Workplane("XY").box(1,2,3)
p = Workplane("XY").box(1,2,3)
s = StringIO.StringIO()
exporters.exportShape(p,eType,s,0.1)
result = s.getvalue()
#print result
for q in stringsToFind:
self.assertTrue(result.find(q) > -1 )
return result
def testSTL(self):
self._exportBox(exporters.ExportTypes.STL,['facet normal'])
def testSVG(self):
self._exportBox(exporters.ExportTypes.SVG,['<svg','<g transform'])
def testAMF(self):
self._exportBox(exporters.ExportTypes.AMF,['<amf units','</object>'])
self._exportBox(exporters.ExportTypes.AMF,['<amf units','</object>'])
def testSTEP(self):
self._exportBox(exporters.ExportTypes.STEP,['FILE_SCHEMA'])
self._exportBox(exporters.ExportTypes.STEP,['FILE_SCHEMA'])
def testTJS(self):
self._exportBox(exporters.ExportTypes.TJS,['vertices','formatVersion','faces'])
self._exportBox(exporters.ExportTypes.TJS,['vertices','formatVersion','faces'])

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']