From 699636d699ec7c22f94b3847e7cf87038954ec56 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 14:45:02 -0400 Subject: [PATCH 01/14] Fixed copyright dates, added the STEP file importer, and added the supporting tests. --- LICENSE | 4 +- MANIFEST | 2 + cadquery/CQ.py | 18 ++++----- cadquery/__init__.py | 5 ++- cadquery/contrib/__init__.py | 6 +-- cadquery/freecad_impl/__init__.py | 4 +- cadquery/freecad_impl/exporters.py | 2 +- cadquery/freecad_impl/geom.py | 2 +- cadquery/freecad_impl/importers.py | 61 ++++++++++++++++++++++++++++++ cadquery/freecad_impl/shapes.py | 2 +- cadquery/plugins/__init__.py | 2 +- cadquery/selectors.py | 4 +- cadquery/workplane.py | 4 +- runtests.py | 3 +- tests/TestCadQuery.py | 2 - tests/TestExporters.py | 16 ++++---- tests/TestImporters.py | 45 ++++++++++++++++++++++ tests/__init__.py | 2 +- 18 files changed, 146 insertions(+), 38 deletions(-) create mode 100644 cadquery/freecad_impl/importers.py create mode 100644 tests/TestImporters.py diff --git a/LICENSE b/LICENSE index 1416a50b..f6a82743 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 05f89aab..56913476 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 e44a65cd..e4b870fe 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 67edb26c..f04e0f7e 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 26b29f8f..61403517 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 306de0e1..61403517 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 a774a844..1b05ef1d 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 a036d627..c581e5da 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 00000000..fd477422 --- /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 0f97b41b..1a78fe79 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 7965eb3d..227406fb 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 6df08056..95bd1963 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 ebb35cb8..90e621c9 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 7020ef46..ea9ec1f7 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 4c2c655c..4f70e2a1 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 0d8249b5..2c7b9f43 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 00000000..5af0f9b8 --- /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 21b96464..b814629c 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'] From f76139e72c87d6b699c5104a736b47c3120cfa5a Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 14:48:25 -0400 Subject: [PATCH 02/14] Incremented version number. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d16a97e5..40de6e55 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='cadquery', - version='0.1.5', + version='0.1.6', url='https://github.com/dcowden/cadquery', license='LGPL', author='David Cowden', From 5ad9cd9b94d9d1d21cebf62733ff38a65f9709ef Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:00:33 -0400 Subject: [PATCH 03/14] Removed placeholder raise statement. --- cadquery/freecad_impl/importers.py | 2 +- tests/TestImporters.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index fd477422..55d67fe1 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -40,7 +40,7 @@ def importShape(importType,fileName): #Check to see what type of file we're working with if importType == ImportTypes.STEP: - raise RuntimeError("Failed on purpose.") + importStep(fileName) #Loads a STEP file into a CQ object def importStep(self,fileName): diff --git a/tests/TestImporters.py b/tests/TestImporters.py index 5af0f9b8..6ede15f7 100644 --- a/tests/TestImporters.py +++ b/tests/TestImporters.py @@ -18,28 +18,29 @@ else: class TestImporters(BaseTest): - def importBox(importType,fileName): + def importBox(self, 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: + if importType == importers.ImportTypes.STEP: #We first need to build a simple shape to export - shape = Workplane("XY").box(1,2,3).val + 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) + importedShape = importers.importShape(importType,fileName) def testSTEP(self): """ Tests STEP file import """ - importBox(ImportTypes.STEP, OUTDIR + "/tempSTEP.step") + self.importBox(importers.ImportTypes.STEP, OUTDIR + "/tempSTEP.step") if __name__ == '__main__': - testSTEP() + import unittest + unittest.main() From bb62067cd27200dc18ab33d0afe96b0f20f7721b Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:01:53 -0400 Subject: [PATCH 04/14] Fixing error in ImportShape. --- cadquery/freecad_impl/importers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 55d67fe1..61047756 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -40,7 +40,7 @@ def importShape(importType,fileName): #Check to see what type of file we're working with if importType == ImportTypes.STEP: - importStep(fileName) + importStep(self,fileName) #Loads a STEP file into a CQ object def importStep(self,fileName): From d82f6120c867ea30324b3b692247755b0de607a5 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:02:49 -0400 Subject: [PATCH 05/14] Fixing error in ImportShape. --- cadquery/freecad_impl/importers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 61047756..b2e8344b 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -40,7 +40,7 @@ def importShape(importType,fileName): #Check to see what type of file we're working with if importType == ImportTypes.STEP: - importStep(self,fileName) + self.importStep(fileName) #Loads a STEP file into a CQ object def importStep(self,fileName): From a21fc64f8c37dc3fadb000cb7e7dbabbb9b553fa Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:04:22 -0400 Subject: [PATCH 06/14] Fixing self errors when not inside a class in ImportShape. --- cadquery/freecad_impl/importers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index b2e8344b..1b362f44 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -40,10 +40,10 @@ def importShape(importType,fileName): #Check to see what type of file we're working with if importType == ImportTypes.STEP: - self.importStep(fileName) + importStep(fileName) #Loads a STEP file into a CQ object -def importStep(self,fileName): +def importStep(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 From eab2338cf36c2937f725933e4daa871ef5ee41e0 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:16:05 -0400 Subject: [PATCH 07/14] Attempting to track down an exception with importing a STEP file that's masked by the try/except. --- cadquery/freecad_impl/importers.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 1b362f44..e6a000bd 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -50,12 +50,12 @@ def importStep(fileName): """ #Now read and return the shape - try: - rshape = Part.read(fileName) + # 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") + 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") From 7b3b02133ff0faa5808bd610ecfb8efd7cfcb374 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:19:52 -0400 Subject: [PATCH 08/14] Attempting to track down an exception with importing a STEP file. --- cadquery/freecad_impl/importers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index e6a000bd..8ce30143 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -21,6 +21,7 @@ """ import cadquery from .verutil import fc_import +from .freecad_impl.shapes import Shape FreeCAD = fc_import("FreeCAD") Part = fc_import("FreeCAD.Part") From f096136da9c8c3d3ba75ab01e43415e50312a64b Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:21:39 -0400 Subject: [PATCH 09/14] Removed unneeded freecad_impl reference. --- cadquery/freecad_impl/importers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 8ce30143..1698a331 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -21,7 +21,7 @@ """ import cadquery from .verutil import fc_import -from .freecad_impl.shapes import Shape +from .shapes import Shape FreeCAD = fc_import("FreeCAD") Part = fc_import("FreeCAD.Part") From ceadc87bde5822eca4b64ed74449fcca79692d49 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:25:04 -0400 Subject: [PATCH 10/14] Attempting to fix importers.py. --- cadquery/freecad_impl/importers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 1698a331..4cb7b7cd 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -20,8 +20,8 @@ a string containing the model content. """ import cadquery -from .verutil import fc_import from .shapes import Shape +from .verutil import fc_import FreeCAD = fc_import("FreeCAD") Part = fc_import("FreeCAD.Part") @@ -60,3 +60,7 @@ def importStep(fileName): return cadquery.CQ(r) # except: # raise ValueError("STEP File Could not be loaded") + +if __name__ == '__main__': + import unittest + unittest.main() From 8994493b7b38712adab5431aaf8438b3c1c6839d Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 15:50:07 -0400 Subject: [PATCH 11/14] importShape in importers.py was not returning anything. --- cadquery/CQ.py | 8 ++++++++ cadquery/freecad_impl/importers.py | 22 +++++++++------------- tests/TestImporters.py | 3 +++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index e4b870fe..8b5f4207 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -637,6 +637,14 @@ class CQ(object): """ exporters.exportSVG(self,fileName) + def importStep(self,fileName): + """ + Reads and imports a solid(s) from a STEP file + + :param fileName: The location and name of the STEP file to load + """ + importers.importStep(self, fileName) + def rotateAboutCenter(self,axisEndPoint,angleDegrees): """ Rotates all items on the stack by the specified angle, about the specified axis diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 4cb7b7cd..44c6c325 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -41,7 +41,7 @@ def importShape(importType,fileName): #Check to see what type of file we're working with if importType == ImportTypes.STEP: - importStep(fileName) + return importStep(fileName) #Loads a STEP file into a CQ object def importStep(fileName): @@ -51,16 +51,12 @@ def importStep(fileName): """ #Now read and return the shape - # try: - rshape = Part.read(fileName) + 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") - -if __name__ == '__main__': - import unittest - unittest.main() + 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/tests/TestImporters.py b/tests/TestImporters.py index 6ede15f7..52c3cd08 100644 --- a/tests/TestImporters.py +++ b/tests/TestImporters.py @@ -35,6 +35,9 @@ class TestImporters(BaseTest): # Reimport the shape from the new STEP file importedShape = importers.importShape(importType,fileName) + #Check to make sure we got a shape back + if not importedShape.ShapeType: + raise TypeError("Wrong type imported from STEP file.") def testSTEP(self): """ Tests STEP file import From 952935f09d31ea65bb2f9459c57f158c6f069bc0 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 16:14:55 -0400 Subject: [PATCH 12/14] Finished up the test for importers.py . --- tests/TestImporters.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/TestImporters.py b/tests/TestImporters.py index 52c3cd08..cdb8d151 100644 --- a/tests/TestImporters.py +++ b/tests/TestImporters.py @@ -35,9 +35,19 @@ class TestImporters(BaseTest): # Reimport the shape from the new STEP file importedShape = importers.importShape(importType,fileName) - #Check to make sure we got a shape back - if not importedShape.ShapeType: - raise TypeError("Wrong type imported from STEP file.") + #Check to make sure we got a solid back + self.assertTrue(importedShape.val().ShapeType() == "Solid") + + #Check the number of vertices per face to make sure we have a box shape + self.assertTrue(importedShape.faces("+X").vertices().size() == 4) + self.assertTrue(importedShape.faces("+Y").vertices().size() == 4) + self.assertTrue(importedShape.faces("+Z").vertices().size() == 4) + + #Check the faces per selection on an axis to make sure we have a box shape + self.assertTrue(importedShape.faces("+X").size() == 1) + self.assertTrue(importedShape.faces("+Y").size() == 1) + self.assertTrue(importedShape.faces("+Z").size() == 1) + def testSTEP(self): """ Tests STEP file import From 0e5980400a4f36416cbd887479b901bbaf254595 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 18 Aug 2014 16:33:34 -0400 Subject: [PATCH 13/14] Should not have put a method call for importStep in CQ.py. Took it back out. --- cadquery/CQ.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 8b5f4207..e4b870fe 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -637,14 +637,6 @@ class CQ(object): """ exporters.exportSVG(self,fileName) - def importStep(self,fileName): - """ - Reads and imports a solid(s) from a STEP file - - :param fileName: The location and name of the STEP file to load - """ - importers.importStep(self, fileName) - def rotateAboutCenter(self,axisEndPoint,angleDegrees): """ Rotates all items on the stack by the specified angle, about the specified axis From 55b70c882cf02c987537d97a1a60dd1f9bbe256c Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Tue, 19 Aug 2014 08:10:46 -0400 Subject: [PATCH 14/14] Cleaned up a few of the assert statements and fixed the findall line in exporters.py based on a FutureWarning. --- cadquery/freecad_impl/exporters.py | 2 +- tests/TestImporters.py | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cadquery/freecad_impl/exporters.py b/cadquery/freecad_impl/exporters.py index 1b05ef1d..5c09db8a 100644 --- a/cadquery/freecad_impl/exporters.py +++ b/cadquery/freecad_impl/exporters.py @@ -239,7 +239,7 @@ def getPaths(freeCadSVG): #yuk, freecad returns svg fragments. stupid stupid fullDoc = "%s" % freeCadSVG e = ET.ElementTree(ET.fromstring(fullDoc)) - segments = e.findall("//g") + segments = e.findall(".//g") for s in segments: paths = s.findall("path") diff --git a/tests/TestImporters.py b/tests/TestImporters.py index cdb8d151..6cb83904 100644 --- a/tests/TestImporters.py +++ b/tests/TestImporters.py @@ -38,15 +38,10 @@ class TestImporters(BaseTest): #Check to make sure we got a solid back self.assertTrue(importedShape.val().ShapeType() == "Solid") - #Check the number of vertices per face to make sure we have a box shape - self.assertTrue(importedShape.faces("+X").vertices().size() == 4) - self.assertTrue(importedShape.faces("+Y").vertices().size() == 4) - self.assertTrue(importedShape.faces("+Z").vertices().size() == 4) - - #Check the faces per selection on an axis to make sure we have a box shape - self.assertTrue(importedShape.faces("+X").size() == 1) - self.assertTrue(importedShape.faces("+Y").size() == 1) - self.assertTrue(importedShape.faces("+Z").size() == 1) + #Check the number of faces and vertices per face to make sure we have a box shape + self.assertTrue(importedShape.faces("+X").size() == 1 and importedShape.faces("+X").vertices().size() == 4) + self.assertTrue(importedShape.faces("+Y").size() == 1 and importedShape.faces("+Y").vertices().size() == 4) + self.assertTrue(importedShape.faces("+Z").size() == 1 and importedShape.faces("+Z").vertices().size() == 4) def testSTEP(self): """