예제 #1
0
    def execute(self, fp):  # fp is FeaturePython
        import math
        props = HolderProperties().getProperties()

        # extrude sketch "Sketch" and get dimensions
        sketchName = fp.ShapeLabel
        sketchObject = FreeCAD.activeDocument().getObject(sketchName)
        sketchObject.ViewObject.Visibility = False
        import Part
        wire = sketchObject.Shape.Wires[0]
        face = Part.Face(wire)
        toolCutout = face.extrude(FreeCAD.Vector(0, 0, -fp.Depth))

        # magnets
        magnetPositions = []
        i = 0
        while i < sketchObject.GeometryCount:
            g = sketchObject.Geometry[i]
            if type(g) is Part.Point:
                magnetPositions.append(FreeCAD.Vector(g.X, g.Y, 0))
            i = i + 1

        for pos in magnetPositions:
            magHole = Part.makeCylinder(
                props.magHoleDiameter / 2, props.magHoleDepth,
                FreeCAD.Vector(pos.x, pos.y, -fp.Depth), vZ * -1)
            toolCutout = toolCutout.fuse(magHole)

        # Scale slighly bigger for tolerance
        #Draft.scale([toolShape],delta=FreeCAD.Vector(1.0,1.0,1.0),center=FreeCAD.Vector(-106.0,-86.0,0.0),copy=False,legacy=False)

        fp.CutoutWidth = toolCutout.BoundBox.XLength
        fp.CutoutHeight = toolCutout.BoundBox.YLength
        fp.CutoutDepth = toolCutout.BoundBox.ZLength

        isRecomputeNeeded, slotWidth, trayHeight, trayDepth = bsh_utils.getSlotSize(
            props, fp)
        bsh_utils.markHolderRecompute(isRecomputeNeeded)

        # center cutout in box horizontally, position vertically with top margin
        xoff = toolCutout.BoundBox.XLength / 2 - toolCutout.BoundBox.XMax + slotWidth / 2
        yoffCenter = toolCutout.BoundBox.YLength / 2 - toolCutout.BoundBox.YMax
        yoff = yoffCenter + trayHeight - props.marginTop - toolCutout.BoundBox.YLength / 2
        toolCutout.translate(FreeCAD.Vector(xoff, yoff, 0))

        bsh_utils.addCutoutObject(fp, toolCutout, 'AnyCutout')

        box = Part.makeBox(slotWidth, trayHeight, trayDepth, vO,
                           FreeCAD.Vector(0, 0, -1))
        box.translate(FreeCAD.Vector(slotWidth, 0, 0))  # todo center
        #holder = box.fuse(toolCutout)  # devel
        holder = box.cut(toolCutout)

        tag = bsh_utils.makeTag(props, fp.Tag, slotWidth)
        holder = holder.fuse(tag)

        fp.Shape = holder
        super(AnyHolder, self).execute(fp)  # perform common operations
예제 #2
0
  def execute(self, fp): # fp is FeaturePython
    import math

    props = HolderProperties().getProperties()
    bitHoleDiameter = fp.Diameter + 2*props.cutoutIncrease 

    # Cutout
    r=bitHoleDiameter/2
    s=0.8660254
    c=0.5
    p1 = FreeCAD.Vector(-r,0,0)
    p2 = FreeCAD.Vector(-r*c,r*s,0)
    p3 = FreeCAD.Vector(r*c,r*s,0)
    p4 = FreeCAD.Vector(r,0,0)
    p5 = FreeCAD.Vector(r*c,-r*s,0)
    p6 = FreeCAD.Vector(-r*c,-r*s,0)
    pointslist = [p1,p2,p3,p4,p5,p6,p1]
    base=Part.Face(Part.Wire(Part.makePolygon(pointslist)))
    bitHole = base.extrude(FreeCAD.Vector(0,0,-1 * fp.Depth))
    x=bitHoleDiameter/2 - props.magHoleDiameter/2 - props.magHoleDiameter*0.13 + props.magHoleOffset
    y=0
    magHole1 = Part.makeCylinder(props.magHoleDiameter/2,props.magHoleDepth,FreeCAD.Vector(x,y,-fp.Depth),vZ*-1)
    magHole2 = Part.makeCylinder(props.magHoleDiameter/2,props.magHoleDepth,FreeCAD.Vector(-x,y,-fp.Depth),vZ*-1)
    bitHole = bitHole.fuse(magHole1)
    bitHole = bitHole.fuse(magHole2)

    bsh_utils.addCutoutObject(fp, bitHole, 'BitCutout')

    fp.CutoutWidth = bitHole.BoundBox.XLength
    fp.CutoutHeight = bitHole.BoundBox.YLength
    fp.CutoutDepth = bitHole.BoundBox.ZLength

    isRecomputeNeeded, slotWidth, trayHeight, trayDepth = bsh_utils.getSlotSize(props, fp)

    bitHole.translate(FreeCAD.Vector(slotWidth/2, trayHeight - props.marginTop - bitHoleDiameter/2, 0))

    box = Part.makeBox(slotWidth, trayHeight, trayDepth, vO, FreeCAD.Vector(0,0,-1))
    box.translate(FreeCAD.Vector(slotWidth, 0, 0))
    #holder = box.fuse(bitHole)  # devel
    holder = box.cut(bitHole)

    tag = bsh_utils.makeTag(props, fp.Tag, slotWidth)
    holder = holder.fuse(tag)

    bsh_utils.markHolderRecompute(isRecomputeNeeded)

    fp.Shape = holder
    super(BitHolder,self).execute(fp) # perform common operations
예제 #3
0
    def accept(self):
        HolderProperties().initDocument()

        propList=[\
          self.form.trayWidth.value(),\
          self.form.trayHeight.value(),\
          self.form.trayDepth.value()\
          ]

        pos = bsh_utils.getNewPosition()
        a = bsh_cmd.makePad(propList, pos)

        a.ViewObject.ShapeColor = (0.5, 0.8, 0.5)
        FreeCADGui.Control.closeDialog()
        FreeCAD.activeDocument().commitTransaction()
        FreeCAD.activeDocument().recompute()
        FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #4
0
    def accept(self):
        HolderProperties().initDocument()

        propList=[\
          self.form.BitTag.text(),\
          self.form.BitDiameter.value(),\
          self.form.BitInsertDepth.value(),\
          self.form.createCutoutObject.isChecked(),\
          self.form.createTagObject.isChecked()\
          ]

        pos = bsh_utils.getNewPosition()
        a = bsh_cmd.makeBitHolder(propList, pos)

        a.ViewObject.ShapeColor = (0.8, 0.8, 0.8)
        print('created obj ' + a.Name + ' ' + a.Label)
        if a.Tag:
            a.Label = 'BitHolder-' + a.Tag
        FreeCADGui.Control.closeDialog()
        FreeCAD.activeDocument().commitTransaction()
        FreeCAD.activeDocument().recompute()
        FreeCADGui.SendMsgToActiveView("ViewFit")
    def execute(self, fp):  # fp is FeaturePython
        import math
        props = HolderProperties().getProperties()

        socketHoleDiameter = fp.Diameter + (
            2 * props.cutoutIncrease
        )  # fp.Diameter is measured diameter of nut

        print("Create Cutout Object: " + str(fp.CutoutObject))  # todo

        # Create nut hole with 4 magholes
        base = Part.Face(Part.Wire(Part.makeCircle((socketHoleDiameter) / 2)))
        socketHole = base.extrude(FreeCAD.Vector(0, 0, -1 * fp.Depth))

        xy = (socketHoleDiameter / 2 - props.magHoleDiameter / 2 +
              props.magHoleOffset) * math.sin(math.radians(45))

        magHole1 = Part.makeCylinder(props.magHoleDiameter / 2,
                                     props.magHoleDepth,
                                     FreeCAD.Vector(xy, xy,
                                                    -fp.Depth), vZ * -1)
        magHole2 = Part.makeCylinder(props.magHoleDiameter / 2,
                                     props.magHoleDepth,
                                     FreeCAD.Vector(-xy, xy,
                                                    -fp.Depth), vZ * -1)
        magHole3 = Part.makeCylinder(props.magHoleDiameter / 2,
                                     props.magHoleDepth,
                                     FreeCAD.Vector(xy, -xy,
                                                    -fp.Depth), vZ * -1)
        magHole4 = Part.makeCylinder(props.magHoleDiameter / 2,
                                     props.magHoleDepth,
                                     FreeCAD.Vector(-xy, -xy,
                                                    -fp.Depth), vZ * -1)
        socketHole = socketHole.fuse(magHole1)
        socketHole = socketHole.fuse(magHole2)
        socketHole = socketHole.fuse(magHole3)
        socketHole = socketHole.fuse(magHole4)

        bsh_utils.addCutoutObject(fp, socketHole, 'SocketCutout')
        fp.CutoutWidth = socketHole.BoundBox.XLength
        fp.CutoutHeight = socketHole.BoundBox.YLength
        fp.CutoutDepth = socketHole.BoundBox.ZLength

        isRecomputeNeeded, slotWidth, trayHeight, trayDepth = bsh_utils.getSlotSize(
            props, fp)
        bsh_utils.markHolderRecompute(isRecomputeNeeded)

        socketHole.translate(
            FreeCAD.Vector(
                slotWidth / 2,
                trayHeight - props.marginTop - socketHoleDiameter / 2, 0))

        box = Part.makeBox(slotWidth, trayHeight, trayDepth, vO,
                           FreeCAD.Vector(0, 0, -1))
        box.translate(FreeCAD.Vector(slotWidth, 0, 0))
        #holder = box.fuse(socketHole)  # devel
        holder = box.cut(socketHole)

        tag = bsh_utils.makeTag(props, fp.Tag, slotWidth)
        holder = holder.fuse(tag)

        fp.Shape = holder
        super(SocketHolder, self).execute(fp)  # perform common operations