예제 #1
0
    def execute(self, obj):
        import Part, math, DraftGeomUtils
        pl = obj.Placement
        self.baseface = None

        base = None
        if obj.Base and obj.Angle:
            w = None
            if obj.Base.isDerivedFrom("Part::Feature"):
                if (obj.Base.Shape.Faces and obj.Face):
                    w = obj.Base.Shape.Faces[obj.Face - 1].Wires[0]
                elif obj.Base.Shape.Wires:
                    w = obj.Base.Shape.Wires[0]
            if w:
                if w.isClosed():
                    f = Part.Face(w)
                    self.baseface = f.copy()
                    norm = f.normalAt(0, 0)
                    c = round(math.tan(math.radians(obj.Angle)),
                              Draft.precision())
                    d = f.BoundBox.DiagonalLength
                    edges = DraftGeomUtils.sortEdges(f.Edges)
                    l = len(edges)
                    edges.append(edges[0])
                    shps = []
                    for i in range(l):
                        v = DraftGeomUtils.vec(
                            DraftGeomUtils.angleBisection(
                                edges[i], edges[i + 1]))
                        v.normalize()
                        bis = v.getAngle(DraftGeomUtils.vec(edges[i]))
                        delta = 1 / math.cos(bis)
                        v.multiply(delta)
                        n = (FreeCAD.Vector(norm)).multiply(c)
                        dv = v.add(n)
                        dv.normalize()
                        dv.scale(d, d, d)
                        shps.append(f.extrude(dv))
                    base = shps.pop()
                    for s in shps:
                        base = base.common(s)
                    base = base.removeSplitter()
                    if not base.isNull():
                        if not DraftGeomUtils.isNull(pl):
                            base.Placement = pl

        base = self.processSubShapes(obj, base)
        if base:
            if not base.isNull():
                obj.Shape = base
예제 #2
0
    def execute(self,obj):
        import Part, math, DraftGeomUtils
        pl = obj.Placement
        self.baseface = None

        base = None
        if obj.Base and obj.Angle:
            w = None
            if obj.Base.isDerivedFrom("Part::Feature"):
                if (obj.Base.Shape.Faces and obj.Face):
                    w = obj.Base.Shape.Faces[obj.Face-1].Wires[0]
                elif obj.Base.Shape.Wires:
                    w = obj.Base.Shape.Wires[0]
            if w:
                if w.isClosed():
                    f = Part.Face(w)
                    self.baseface = f.copy()
                    norm = f.normalAt(0,0)
                    c = round(math.tan(math.radians(obj.Angle)),Draft.precision())
                    d = f.BoundBox.DiagonalLength
                    edges = DraftGeomUtils.sortEdges(f.Edges)
                    l = len(edges)
                    edges.append(edges[0])
                    shps = []
                    for i in range(l):
                        v = DraftGeomUtils.vec(DraftGeomUtils.angleBisection(edges[i],edges[i+1]))
                        v.normalize()
                        bis = v.getAngle(DraftGeomUtils.vec(edges[i]))
                        delta = 1/math.cos(bis)
                        v.multiply(delta)
                        n = (FreeCAD.Vector(norm)).multiply(c)
                        dv = v.add(n)
                        dv.normalize()
                        dv.scale(d,d,d)
                        shps.append(f.extrude(dv))
                    base = shps.pop()
                    for s in shps:
                        base = base.common(s)
                    base = base.removeSplitter()
                    if not base.isNull():
                        if not DraftGeomUtils.isNull(pl):
                            base.Placement = pl
                            
        base = self.processSubShapes(obj,base)
        if base:
            if not base.isNull():
                obj.Shape = base