diff --git a/cadquery.egg-info/SOURCES.txt b/cadquery.egg-info/SOURCES.txt index 2e88412..0f7a1ec 100644 --- a/cadquery.egg-info/SOURCES.txt +++ b/cadquery.egg-info/SOURCES.txt @@ -18,7 +18,6 @@ cadquery/freecad_impl/exporters.py cadquery/freecad_impl/geom.py cadquery/freecad_impl/importers.py cadquery/freecad_impl/shapes.py -cadquery/freecad_impl/verutil.py cadquery/plugins/__init__.py tests/TestCQSelectors.py tests/TestCadObjects.py diff --git a/cadquery/__init__.py b/cadquery/__init__.py index 0ffdf6d..def64bc 100644 --- a/cadquery/__init__.py +++ b/cadquery/__init__.py @@ -1,5 +1,3 @@ - - #these items point to the freecad implementation from .freecad_impl.geom import Plane,BoundBox,Vector,Matrix,sortWiresByBuildOrder from .freecad_impl.shapes import Shape,Vertex,Edge,Face,Wire,Solid,Shell,Compound @@ -14,8 +12,8 @@ from .CQ import CQ,CQContext,Workplane __all__ = [ - 'CQ','Workplane','plugins','selectors','Plane','BoundBox','Matrix','Vector','sortWiresByBuildOrder', - 'Shape','Vertex','Edge','Wire','Solid','Shell','Compound','exporters', 'importers', 'NearestToPointSelector','ParallelDirSelector','DirectionSelector','PerpendicularDirSelector','TypeSelector','DirectionMinMaxSelector','StringSyntaxSelector','Selector','plugins' + 'CQ','Workplane','plugins','selectors','Plane','BoundBox','Matrix','Vector','sortWiresByBuildOrder', + 'Shape','Vertex','Edge','Wire','Solid','Shell','Compound','exporters', 'importers', 'NearestToPointSelector','ParallelDirSelector','DirectionSelector','PerpendicularDirSelector','TypeSelector','DirectionMinMaxSelector','StringSyntaxSelector','Selector','plugins' ] -__version__ = "0.1.7" +__version__ = "0.1.7" \ No newline at end of file diff --git a/cadquery/freecad_impl/__init__.py b/cadquery/freecad_impl/__init__.py index 6140351..22773b4 100644 --- a/cadquery/freecad_impl/__init__.py +++ b/cadquery/freecad_impl/__init__.py @@ -1,18 +1,88 @@ """ - Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC + Copyright (C) 2011-2014 Parametric Products Intellectual Holdings, LLC - This file is part of CadQuery. + 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 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. + 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 + You should have received a copy of the GNU Lesser General Public + License along with this library; If not, see """ +import os, sys + + +def _fc_path(): + """Find FreeCAD""" + _PATH = "" + if _PATH: + return _PATH + + #look for FREECAD_LIB env variable + if os.environ.has_key('FREECAD_LIB'): + _PATH = os.environ.get('FREECAD_LIB') + if os.path.exists( _PATH): + return _PATH + + if sys.platform.startswith('linux'): + #Make some dangerous assumptions... + for _PATH in [ + os.path.join(os.path.expanduser("~"), "lib/freecad/lib"), + "/usr/local/lib/freecad/lib", + "/usr/lib/freecad/lib", + ]: + if os.path.exists(_PATH): + return _PATH + + elif sys.platform.startswith('win'): + #try all the usual suspects + for _PATH in [ + "c:/Program Files/FreeCAD0.12/bin", + "c:/Program Files/FreeCAD0.13/bin", + "c:/Program Files/FreeCAD0.14/bin", + "c:/Program Files/FreeCAD0.15/bin", + "c:/Program Files/FreeCAD0.16/bin", + "c:/Program Files/FreeCAD0.17/bin", + "c:/Program Files (x86)/FreeCAD0.12/bin", + "c:/Program Files (x86)/FreeCAD0.13/bin", + "c:/Program Files (x86)/FreeCAD0.14/bin", + "c:/Program Files (x86)/FreeCAD0.15/bin", + "c:/Program Files (x86)/FreeCAD0.16/bin", + "c:/Program Files (x86)/FreeCAD0.17/bin", + "c:/apps/FreeCAD0.12/bin", + "c:/apps/FreeCAD0.13/bin", + "c:/apps/FreeCAD0.14/bin", + "c:/apps/FreeCAD0.15/bin", + "c:/apps/FreeCAD0.16/bin", + "c:/apps/FreeCAD0.17/bin", + "c:/Program Files/FreeCAD 0.12/bin", + "c:/Program Files/FreeCAD 0.13/bin", + "c:/Program Files/FreeCAD 0.14/bin", + "c:/Program Files/FreeCAD 0.15/bin", + "c:/Program Files/FreeCAD 0.16/bin", + "c:/Program Files/FreeCAD 0.17/bin", + "c:/Program Files (x86)/FreeCAD 0.12/bin", + "c:/Program Files (x86)/FreeCAD 0.13/bin", + "c:/Program Files (x86)/FreeCAD 0.14/bin", + "c:/Program Files (x86)/FreeCAD 0.15/bin", + "c:/Program Files (x86)/FreeCAD 0.16/bin", + "c:/Program Files (x86)/FreeCAD 0.17/bin", + "c:/apps/FreeCAD 0.12/bin", + "c:/apps/FreeCAD 0.13/bin", + "c:/apps/FreeCAD 0.14/bin", + "c:/apps/FreeCAD 0.15/bin", + "c:/apps/FreeCAD 0.16/bin", + "c:/apps/FreeCAD 0.17/bin", + ]: + if os.path.exists(_PATH): + return _PATH + +#Make sure that the correct FreeCAD path shows up in Python's system path +sys.path.insert(0, _fc_path()) \ No newline at end of file diff --git a/cadquery/freecad_impl/exporters.py b/cadquery/freecad_impl/exporters.py index 5c09db8..0633b4d 100644 --- a/cadquery/freecad_impl/exporters.py +++ b/cadquery/freecad_impl/exporters.py @@ -21,11 +21,13 @@ """ import cadquery -from .verutil import fc_import -FreeCAD = fc_import("FreeCAD") +#from .verutil import fc_import +#FreeCAD = fc_import("FreeCAD") +import FreeCAD import tempfile,os,StringIO -Drawing = fc_import("FreeCAD.Drawing") +import Drawing +#Drawing = fc_import("FreeCAD.Drawing") #_FCVER = freecad_version() #if _FCVER>=(0,13): #import Drawing as FreeCADDrawing #It's in FreeCAD lib path diff --git a/cadquery/freecad_impl/geom.py b/cadquery/freecad_impl/geom.py index dfafb7c..1818693 100644 --- a/cadquery/freecad_impl/geom.py +++ b/cadquery/freecad_impl/geom.py @@ -19,8 +19,9 @@ import math,sys #import FreeCAD -from .verutil import fc_import -FreeCAD = fc_import("FreeCAD") +#from .verutil import fc_import +#FreeCAD = fc_import("FreeCAD") +import FreeCAD #Turns out we don't need the Part module here. def sortWiresByBuildOrder(wireList,plane,result=[]): diff --git a/cadquery/freecad_impl/importers.py b/cadquery/freecad_impl/importers.py index 44c6c32..c959fb9 100644 --- a/cadquery/freecad_impl/importers.py +++ b/cadquery/freecad_impl/importers.py @@ -21,9 +21,11 @@ """ import cadquery from .shapes import Shape -from .verutil import fc_import -FreeCAD = fc_import("FreeCAD") -Part = fc_import("FreeCAD.Part") +#from .verutil import fc_import +# FreeCAD = fc_import("FreeCAD") +# Part = fc_import("FreeCAD.Part") +import FreeCAD +import Part class ImportTypes: STEP = "STEP" diff --git a/cadquery/freecad_impl/shapes.py b/cadquery/freecad_impl/shapes.py index b0a268e..b6c1f8a 100644 --- a/cadquery/freecad_impl/shapes.py +++ b/cadquery/freecad_impl/shapes.py @@ -50,9 +50,10 @@ from cadquery import Vector, BoundBox import FreeCAD -from .verutil import fc_import +#from .verutil import fc_import -FreeCADPart = fc_import("FreeCAD.Part") +#FreeCADPart = fc_import("FreeCAD.Part") +import Part as FreeCADPart class Shape(object): diff --git a/cadquery/freecad_impl/verutil.py b/cadquery/freecad_impl/verutil.py deleted file mode 100644 index b3802a5..0000000 --- a/cadquery/freecad_impl/verutil.py +++ /dev/null @@ -1,155 +0,0 @@ -""" - 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 re -from importlib import import_module -import os -import sys - -MEMO_VERSION = None -SUBMODULES = None -_PATH = None - -def _figure_out_version(freecadversion): - """Break this out for testability.""" - return tuple( - ((int(re.sub("([0-9]*).*", "\\1", part) or 0)) - for part in freecadversion[:3])) - - -def _fc_path(): - """Find FreeCAD""" - global _PATH - if _PATH: - return _PATH - - #look for FREECAD_LIB env variable - if os.environ.has_key('FREECAD_LIB'): - _PATH = os.environ.get('FREECAD_LIB') - if os.path.exists( _PATH): - return _PATH - - if sys.platform.startswith('linux'): - #Make some dangerous assumptions... - for _PATH in [ - os.path.join(os.path.expanduser("~"), "lib/freecad/lib"), - "/usr/local/lib/freecad/lib", - "/usr/lib/freecad/lib", - ]: - if os.path.exists(_PATH): - return _PATH - - elif sys.platform.startswith('win'): - #try all the usual suspects - for _PATH in [ - "c:/Program Files/FreeCAD0.12/bin", - "c:/Program Files/FreeCAD0.13/bin", - "c:/Program Files/FreeCAD0.14/bin", - "c:/Program Files/FreeCAD0.15/bin", - "c:/Program Files/FreeCAD0.16/bin", - "c:/Program Files/FreeCAD0.17/bin", - "c:/Program Files (x86)/FreeCAD0.12/bin", - "c:/Program Files (x86)/FreeCAD0.13/bin", - "c:/Program Files (x86)/FreeCAD0.14/bin", - "c:/Program Files (x86)/FreeCAD0.15/bin", - "c:/Program Files (x86)/FreeCAD0.16/bin", - "c:/Program Files (x86)/FreeCAD0.17/bin", - "c:/apps/FreeCAD0.12/bin", - "c:/apps/FreeCAD0.13/bin", - "c:/apps/FreeCAD0.14/bin", - "c:/apps/FreeCAD0.15/bin", - "c:/apps/FreeCAD0.16/bin", - "c:/apps/FreeCAD0.17/bin", - "c:/Program Files/FreeCAD 0.12/bin", - "c:/Program Files/FreeCAD 0.13/bin", - "c:/Program Files/FreeCAD 0.14/bin", - "c:/Program Files/FreeCAD 0.15/bin", - "c:/Program Files/FreeCAD 0.16/bin", - "c:/Program Files/FreeCAD 0.17/bin", - "c:/Program Files (x86)/FreeCAD 0.12/bin", - "c:/Program Files (x86)/FreeCAD 0.13/bin", - "c:/Program Files (x86)/FreeCAD 0.14/bin", - "c:/Program Files (x86)/FreeCAD 0.15/bin", - "c:/Program Files (x86)/FreeCAD 0.16/bin", - "c:/Program Files (x86)/FreeCAD 0.17/bin", - "c:/apps/FreeCAD 0.12/bin", - "c:/apps/FreeCAD 0.13/bin", - "c:/apps/FreeCAD 0.14/bin", - "c:/apps/FreeCAD 0.15/bin", - "c:/apps/FreeCAD 0.16/bin", - "c:/apps/FreeCAD 0.17/bin", - ]: - if os.path.exists(_PATH): - return _PATH - -def freecad_version(): - """Determine the freecad version and return it as a simple - comparable tuple""" - #If we cannot find freecad, we append it to the path if possible - _pthtmp = _fc_path() - if not _pthtmp in sys.path: - sys.path.append(_pthtmp) - import FreeCAD - global MEMO_VERSION - if not MEMO_VERSION: - MEMO_VERSION = _figure_out_version(FreeCAD.Version()) - return MEMO_VERSION - -def _find_submodules(): - """Find the list of allowable submodules in fc13""" - global SUBMODULES - searchpath = _fc_path() - if not SUBMODULES: - SUBMODULES = [ - re.sub("(.*)\\.(py|so)","\\1", filename) - for filename in os.listdir(searchpath) - if ( - filename.endswith(".so") or - filename.endswith(".py") or - filename.endswith(".dll") )] #Yes, complex. Sorry. - return SUBMODULES - - -def fc_import(modulename): - """Intelligent import of freecad components. - If we are in 0.12, we can import FreeCAD.Drawing - If we are in 0.13, we need to set sys.path and import Drawing as toplevel. - This may or may not be a FreeCAD bug though. - This is ludicrously complex and feels awful. Kinda like a lot of OCC. - """ - #Note that this also sets the path as a side effect. - - _fcver = freecad_version() - - if _fcver[0:2] >= (0, 13): - if modulename in _find_submodules(): - return import_module(modulename) - elif re.sub("^FreeCAD\\.", "", modulename) in _find_submodules(): - return import_module(re.sub("^FreeCAD\\.", "", modulename)) - else: - raise ImportError, "Module %s not found/allowed in %s" % ( - modulename, _PATH) - elif _fcver[0:2] == (0, 12): - return import_module(modulename) - else: - raise RuntimeError, "Invalid freecad version: %s" % \ - str(".".join(_fcver)) - -__ALL__ = ['fc_import', 'freecad_version'] diff --git a/tests/TestCadObjects.py b/tests/TestCadObjects.py index 7cb0863..a188e36 100644 --- a/tests/TestCadObjects.py +++ b/tests/TestCadObjects.py @@ -4,10 +4,12 @@ import sys import unittest from tests import BaseTest -from cadquery.freecad_impl.verutil import fc_import -FreeCAD = fc_import("FreeCAD") -if not hasattr(FreeCAD, 'Part'): - FreeCAD.Part = fc_import("FreeCAD.Part") +#from cadquery.freecad_impl.verutil import fc_import +# FreeCAD = fc_import("FreeCAD") +# if not hasattr(FreeCAD, 'Part'): +# FreeCAD.Part = fc_import("FreeCAD.Part") +import FreeCAD +import Part from cadquery import * diff --git a/tests/TestImports.py b/tests/TestImports.py index 2c7d04f..243357d 100644 --- a/tests/TestImports.py +++ b/tests/TestImports.py @@ -4,26 +4,26 @@ #core modules #my modules -from cadquery.freecad_impl import verutil -from tests import BaseTest +#from cadquery.freecad_impl import verutil +#from tests import BaseTest -class TestVersionsForImport(BaseTest): - """Test version checks.""" - - def test_013_version(self): - """Make sure various 0.13 Version calls work correctly""" - self.assertEquals(verutil._figure_out_version( - ['0', '13', '2055 (Git)', - 'git://git.code.sf.net/p/free-cad/code', - '2013/04/18 13:48:49', 'master', - '3511a807a30cf41909aaf12a1efe1db6c53db577']), - (0,13,2055)) - self.assertEquals(verutil._figure_out_version( - ['0', '13', '12345']), - (0,13,12345)) - self.assertEquals(verutil._figure_out_version( - ['0', '13', 'SOMETAGTHATBREAKSSTUFF']), - (0,13,0)) +# class TestVersionsForImport(BaseTest): +# """Test version checks.""" +# +# def test_013_version(self): +# """Make sure various 0.13 Version calls work correctly""" +# self.assertEquals(verutil._figure_out_version( +# ['0', '13', '2055 (Git)', +# 'git://git.code.sf.net/p/free-cad/code', +# '2013/04/18 13:48:49', 'master', +# '3511a807a30cf41909aaf12a1efe1db6c53db577']), +# (0,13,2055)) +# self.assertEquals(verutil._figure_out_version( +# ['0', '13', '12345']), +# (0,13,12345)) +# self.assertEquals(verutil._figure_out_version( +# ['0', '13', 'SOMETAGTHATBREAKSSTUFF']), +# (0,13,0)) diff --git a/tests/__init__.py b/tests/__init__.py index b814629..2cbd99d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -3,11 +3,16 @@ import unittest import sys import os -from cadquery.freecad_impl.verutil import fc_import -FreeCAD = fc_import("FreeCAD") +#from cadquery.freecad_impl.verutil import fc_import +#FreeCAD = fc_import("FreeCAD") +#import cadquery.freecad_impl +import FreeCAD -P = fc_import("FreeCAD.Part") -V = fc_import("FreeCAD").Base.Vector +# P = fc_import("FreeCAD.Part") +# V = fc_import("FreeCAD").Base.Vector + +import Part as P +from FreeCAD import Vector as V def readFileAsString(fileName): f= open(fileName,'r')