Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #119 from galou/unicode
Browse files Browse the repository at this point in the history
Improve unicode support
  • Loading branch information
jmwright committed Oct 12, 2015
2 parents 459c708 + 4f043c0 commit bdf2be9
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions cadquery/CQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
License along with this library; If not, see <http://www.gnu.org/licenses/>
"""

import time, math
import time
import math
from cadquery import *
from cadquery import selectors
from cadquery import exporters
Expand All @@ -38,6 +39,7 @@ def __init__(self):
self.firstPoint = None
self.tolerance = 0.0001 # user specified tolerance


class CQ(object):
"""
Provides enhanced functionality for a wrapped CAD primitive.
Expand Down Expand Up @@ -94,9 +96,9 @@ def _collectProperty(self, propName):
all = {}
for o in self.objects:

#tricky-- if an object is a compound of solids,
#do not return all of the solids underneath-- typically
#then we'll keep joining to ourself
# tricky-- if an object is a compound of solids,
# do not return all of the solids underneath-- typically
# then we'll keep joining to ourself
if propName == 'Solids' and isinstance(o, Solid) and o.ShapeType() == 'Compound':
for i in getattr(o, 'Compounds')():
all[i.hashCode()] = i
Expand Down Expand Up @@ -139,11 +141,11 @@ def split(self, keepTop=False, keepBottom=False):
bottom = solid.cut(topCutBox)

if keepTop and keepBottom:
#put both on the stack, leave original unchanged
# Put both on the stack, leave original unchanged.
return self.newObject([top, bottom])
else:
# put the one we are keeping on the stack, and also update the context solid
#to the one we kept
# Put the one we are keeping on the stack, and also update the
# context solidto the one we kept.
if keepTop:
solid.wrapped = top.wrapped
return self.newObject([top])
Expand Down Expand Up @@ -467,7 +469,7 @@ def _selectObjects(self, objType, selector=None):
toReturn = self._collectProperty(objType)

if selector is not None:
if type(selector) == str:
if isinstance(selector, str) or isinstance(selector, unicode):
selectorObj = selectors.StringSyntaxSelector(selector)
else:
selectorObj = selector
Expand Down Expand Up @@ -818,7 +820,7 @@ def fillet(self, radius):
solid.wrapped = s.wrapped
return self.newObject([s])

def chamfer(self, length, length2 = None):
def chamfer(self, length, length2=None):
"""
Chamfers a solid on the selected edges.
Expand Down Expand Up @@ -857,6 +859,7 @@ def chamfer(self, length, length2 = None):
solid.wrapped = s.wrapped
return self.newObject([s])


class Workplane(CQ):
"""
Defines a coordinate system in space, in which 2-d coordinates can be used.
Expand Down Expand Up @@ -909,13 +912,14 @@ def __init__(self, inPlane, origin=(0, 0, 0), obj=None):

if inPlane.__class__.__name__ == 'Plane':
tmpPlane = inPlane
elif type(inPlane) == str:
elif isinstance(inPlane, str) or isinstance(inPlane, unicode):
tmpPlane = Plane.named(inPlane, origin)
else:
tmpPlane = None

if tmpPlane is None:
raise ValueError(" Provided value %s is not a valid work plane." % str(inPlane))
raise ValueError(
'Provided value {} is not a valid work plane'.format(inPlane))

self.obj = obj
self.plane = tmpPlane
Expand Down Expand Up @@ -1118,7 +1122,7 @@ def lineTo(self, x, y, forConstruction=False):

return self.newObject([p])

#line a specified incremental amount from current point
# line a specified incremental amount from current point
def line(self, xDist, yDist, forConstruction=False):
"""
Make a line from the current point to the provided point, using
Expand Down Expand Up @@ -2077,7 +2081,7 @@ def union(self, toUnion=None, combine=True, clean=True):
elif type(toUnion) == Solid:
newS = toUnion
else:
raise ValueError("Cannot union Type '%s' " % str(type(toUnion)))
raise ValueError("Cannot union type '{}'".format(type(toUnion)))

#now combine with existing solid, if there is one
# look for parents to cut from
Expand Down Expand Up @@ -2110,14 +2114,14 @@ def cut(self, toCut, combine=True, clean=True):
solidRef = self.findSolid(searchStack=True, searchParents=True)

if solidRef is None:
raise ValueError("Cannot find solid to cut from!!!")
raise ValueError("Cannot find solid to cut from")
solidToCut = None
if type(toCut) == CQ or type(toCut) == Workplane:
solidToCut = toCut.val()
elif type(toCut) == Solid:
solidToCut = toCut
else:
raise ValueError("Cannot cut Type '%s' " % str(type(toCut)))
raise ValueError("Cannot cut type '{}'".formatr(type(toCut)))

newS = solidRef.cut(solidToCut)

Expand Down

0 comments on commit bdf2be9

Please sign in to comment.