diff --git a/LICENSE b/LICENSE index 1416a50..f6a8274 100644 --- a/LICENSE +++ b/LICENSE @@ -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. \ No newline at end of file +Library. diff --git a/MANIFEST b/MANIFEST index 05f89aa..5691347 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 diff --git a/cadquery/CQ.py b/cadquery/CQ.py index e44a65c..e4b870f 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -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) - + diff --git a/cadquery/__init__.py b/cadquery/__init__.py index 67edb26..f04e0f7 100644 --- a/cadquery/__init__.py +++ b/cadquery/__init__.py @@ -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 \ No newline at end of file +__version__ = 0.9 diff --git a/cadquery/contrib/__init__.py b/cadquery/contrib/__init__.py index 26b29f8..6140351 100644 --- a/cadquery/contrib/__init__.py +++ b/cadquery/contrib/__init__.py @@ -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 -""" \ No newline at end of file +""" diff --git a/cadquery/freecad_impl/__init__.py b/cadquery/freecad_impl/__init__.py index 306de0e..6140351 100644 --- a/cadquery/freecad_impl/__init__.py +++ b/cadquery/freecad_impl/__init__.py @@ -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 diff --git a/cadquery/freecad_impl/exporters.py b/cadquery/freecad_impl/exporters.py index a774a84..1b05ef1 100644 --- a/cadquery/freecad_impl/exporters.py +++ b/cadquery/freecad_impl/exporters.py @@ -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. diff --git a/cadquery/freecad_impl/geom.py b/cadquery/freecad_impl/geom.py index a036d62..c581e5d 100644 --- a/cadquery/freecad_impl/geom.py +++ b/cadquery/freecad_impl/geom.py @@ -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. diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py new file mode 100644 index 0000000..fd47742 --- /dev/null +++ b/cadquery/freecad_impl/importers.py @@ -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 + + 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") diff --git a/cadquery/freecad_impl/shapes.py b/cadquery/freecad_impl/shapes.py index 0f97b41..1a78fe7 100644 --- a/cadquery/freecad_impl/shapes.py +++ b/cadquery/freecad_impl/shapes.py @@ -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. diff --git a/cadquery/plugins/__init__.py b/cadquery/plugins/__init__.py index 7965eb3..227406f 100644 --- a/cadquery/plugins/__init__.py +++ b/cadquery/plugins/__init__.py @@ -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 diff --git a/cadquery/selectors.py b/cadquery/selectors.py index 6df0805..95bd196 100644 --- a/cadquery/selectors.py +++ b/cadquery/selectors.py @@ -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 diff --git a/cadquery/workplane.py b/cadquery/workplane.py index ebb35cb..90e621c 100644 --- a/cadquery/workplane.py +++ b/cadquery/workplane.py @@ -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 diff --git a/runtests.py b/runtests.py index 7020ef4..ea9ec1f 100644 --- a/runtests.py +++ b/runtests.py @@ -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) \ No newline at end of file +suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestImporters.TestImporters)) +unittest.TextTestRunner().run(suite) diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index 4c2c655..4f70e2a 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -831,5 +831,3 @@ class TestCadQuery(BaseTest): result =topOfLid.union(bottom) self.saveModel(result) - - diff --git a/tests/TestExporters.py b/tests/TestExporters.py index 0d8249b..2c7b9f4 100644 --- a/tests/TestExporters.py +++ b/tests/TestExporters.py @@ -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,['']) + self._exportBox(exporters.ExportTypes.AMF,['']) 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']) diff --git a/tests/TestImporters.py b/tests/TestImporters.py new file mode 100644 index 0000000..5af0f9b --- /dev/null +++ b/tests/TestImporters.py @@ -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() diff --git a/tests/__init__.py b/tests/__init__.py index 21b9646..b814629 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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']