From b5c69e55e6ed395008f01acee54daaeeb8da308e Mon Sep 17 00:00:00 2001 From: Peter Boin Date: Tue, 20 Feb 2018 22:42:02 +1100 Subject: [PATCH 1/2] Plane more inheritance friendly --- cadquery/freecad_impl/geom.py | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/cadquery/freecad_impl/geom.py b/cadquery/freecad_impl/geom.py index 20cd16c..81a2056 100644 --- a/cadquery/freecad_impl/geom.py +++ b/cadquery/freecad_impl/geom.py @@ -325,18 +325,18 @@ def named(cls, stdName, origin=(0, 0, 0)): namedPlanes = { # origin, xDir, normal - 'XY': Plane(origin, (1, 0, 0), (0, 0, 1)), - 'YZ': Plane(origin, (0, 1, 0), (1, 0, 0)), - 'ZX': Plane(origin, (0, 0, 1), (0, 1, 0)), - 'XZ': Plane(origin, (1, 0, 0), (0, -1, 0)), - 'YX': Plane(origin, (0, 1, 0), (0, 0, -1)), - 'ZY': Plane(origin, (0, 0, 1), (-1, 0, 0)), - 'front': Plane(origin, (1, 0, 0), (0, 0, 1)), - 'back': Plane(origin, (-1, 0, 0), (0, 0, -1)), - 'left': Plane(origin, (0, 0, 1), (-1, 0, 0)), - 'right': Plane(origin, (0, 0, -1), (1, 0, 0)), - 'top': Plane(origin, (1, 0, 0), (0, 1, 0)), - 'bottom': Plane(origin, (1, 0, 0), (0, -1, 0)) + 'XY': cls(origin, (1, 0, 0), (0, 0, 1)), + 'YZ': cls(origin, (0, 1, 0), (1, 0, 0)), + 'ZX': cls(origin, (0, 0, 1), (0, 1, 0)), + 'XZ': cls(origin, (1, 0, 0), (0, -1, 0)), + 'YX': cls(origin, (0, 1, 0), (0, 0, -1)), + 'ZY': cls(origin, (0, 0, 1), (-1, 0, 0)), + 'front': cls(origin, (1, 0, 0), (0, 0, 1)), + 'back': cls(origin, (-1, 0, 0), (0, 0, -1)), + 'left': cls(origin, (0, 0, 1), (-1, 0, 0)), + 'right': cls(origin, (0, 0, -1), (1, 0, 0)), + 'top': cls(origin, (1, 0, 0), (0, 1, 0)), + 'bottom': cls(origin, (1, 0, 0), (0, -1, 0)) } try: @@ -347,73 +347,73 @@ def named(cls, stdName, origin=(0, 0, 0)): @classmethod def XY(cls, origin=(0, 0, 0), xDir=Vector(1, 0, 0)): - plane = Plane.named('XY', origin) + plane = cls.named('XY', origin) plane._setPlaneDir(xDir) return plane @classmethod def YZ(cls, origin=(0, 0, 0), xDir=Vector(0, 1, 0)): - plane = Plane.named('YZ', origin) + plane = cls.named('YZ', origin) plane._setPlaneDir(xDir) return plane @classmethod def ZX(cls, origin=(0, 0, 0), xDir=Vector(0, 0, 1)): - plane = Plane.named('ZX', origin) + plane = cls.named('ZX', origin) plane._setPlaneDir(xDir) return plane @classmethod def XZ(cls, origin=(0, 0, 0), xDir=Vector(1, 0, 0)): - plane = Plane.named('XZ', origin) + plane = cls.named('XZ', origin) plane._setPlaneDir(xDir) return plane @classmethod def YX(cls, origin=(0, 0, 0), xDir=Vector(0, 1, 0)): - plane = Plane.named('YX', origin) + plane = cls.named('YX', origin) plane._setPlaneDir(xDir) return plane @classmethod def ZY(cls, origin=(0, 0, 0), xDir=Vector(0, 0, 1)): - plane = Plane.named('ZY', origin) + plane = cls.named('ZY', origin) plane._setPlaneDir(xDir) return plane @classmethod def front(cls, origin=(0, 0, 0), xDir=Vector(1, 0, 0)): - plane = Plane.named('front', origin) + plane = cls.named('front', origin) plane._setPlaneDir(xDir) return plane @classmethod def back(cls, origin=(0, 0, 0), xDir=Vector(-1, 0, 0)): - plane = Plane.named('back', origin) + plane = cls.named('back', origin) plane._setPlaneDir(xDir) return plane @classmethod def left(cls, origin=(0, 0, 0), xDir=Vector(0, 0, 1)): - plane = Plane.named('left', origin) + plane = cls.named('left', origin) plane._setPlaneDir(xDir) return plane @classmethod def right(cls, origin=(0, 0, 0), xDir=Vector(0, 0, -1)): - plane = Plane.named('right', origin) + plane = cls.named('right', origin) plane._setPlaneDir(xDir) return plane @classmethod def top(cls, origin=(0, 0, 0), xDir=Vector(1, 0, 0)): - plane = Plane.named('top', origin) + plane = cls.named('top', origin) plane._setPlaneDir(xDir) return plane @classmethod def bottom(cls, origin=(0, 0, 0), xDir=Vector(1, 0, 0)): - plane = Plane.named('bottom', origin) + plane = cls.named('bottom', origin) plane._setPlaneDir(xDir) return plane @@ -595,7 +595,7 @@ def rotated(self, rotate=(0, 0, 0)): newXdir = Vector(m.multiply(self.xDir.wrapped)) newZdir = Vector(m.multiply(self.zDir.wrapped)) - return Plane(self.origin, newXdir, newZdir) + return type(self)(self.origin, newXdir, newZdir) def rotateShapes(self, listOfShapes, rotationMatrix): """Rotate the listOfShapes by the supplied rotationMatrix From 396c9c05db59d8f9eb4f99f9e737e7dfc6719f7b Mon Sep 17 00:00:00 2001 From: Peter Boin Date: Tue, 20 Feb 2018 22:57:05 +1100 Subject: [PATCH 2/2] inheritance friendlyness --- cadquery/cq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cadquery/cq.py b/cadquery/cq.py index 2d5cc4c..0210aa7 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -239,7 +239,7 @@ def add(self, obj): """ if type(obj) == list: self.objects.extend(obj) - elif type(obj) == CQ or type(obj) == Workplane: + elif isinstance(obj, CQ): self.objects.extend(obj.objects) else: self.objects.append(obj) @@ -2131,7 +2131,7 @@ def union(self, toUnion=None, combine=True, clean=True): """ #first collect all of the items together - if type(toUnion) == CQ or type(toUnion) == Workplane: + if isinstance(toUnion, CQ): solids = toUnion.solids().vals() if len(solids) < 1: raise ValueError("CQ object must have at least one solid on the stack to union!")