Exemple #1
0
    def generate(self):
        """Returns a ComponentModel."""
        # prepare parameters for easier access
        D = self.D
        E = self.E
        D1 = self.D1
        E1 = self.E1
        A1 = self.A1
        A2 = self.A2
        b = self.b
        e = self.e
        npx = self.npx
        npy = self.npy
        epad = self.epad

        the = self.the
        tb_s = self.tb_s

        c = self.c
        R1 = self.R1
        R2 = self.R2
        S = self.S

        fp_r = self.fp_r
        fp_d = self.fp_d
        fp_z = self.fp_z
        ef = self.ef
        max_cc1 = self.max_cc1

        if self.epad:
            D2 = self.epad[0]
            E2 = self.epad[1]

        # calculated dimensions for body
        A = A1 + A2
        A2_t = (A2-c)/2 # body top part height
        A2_b = A2_t     # body bottom part height
        D1_b = D1-2*tan(radians(the))*A2_b # bottom width
        E1_b = E1-2*tan(radians(the))*A2_b # bottom length
        D1_t1 = D1-tb_s # top part bottom width
        E1_t1 = E1-tb_s # top part bottom length
        D1_t2 = D1_t1-2*tan(radians(the))*A2_t # top part upper width
        E1_t2 = E1_t1-2*tan(radians(the))*A2_t # top part upper length

        # calculate chamfers
        totpinwidthx = (npx-1)*e+b # total width of all pins on the X side
        totpinwidthy = (npy-1)*e+b # total width of all pins on the Y side

        cc1 = min((D1-totpinwidthx)/2., (E1-totpinwidthy)/2.) - 0.5*tb_s
        cc1 = min(cc1, max_cc1)
        cc = cc1/2.

        def crect(wp, rw, rh, cv1, cv):
            """
            Creates a rectangle with chamfered corners.
            wp: workplane object
            rw: rectangle width
            rh: rectangle height
            cv1: chamfer value for 1st corner (lower left)
            cv: chamfer value for other corners
            """
            points = [
                (-rw/2., -rh/2.+cv1),
                (-rw/2., rh/2.-cv),
                (-rw/2.+cv, rh/2.),
                (rw/2.-cv, rh/2.),
                (rw/2., rh/2.-cv),
                (rw/2., -rh/2.+cv),
                (rw/2.-cv, -rh/2.),
                (-rw/2.+cv1, -rh/2.),
                (-rw/2., -rh/2.+cv1)
            ]
            return wp.polyline(points)

        # start drawing with case model
        case = cq.Workplane(cq.Plane.XY()).workplane(offset=A1)
        case = crect(case, D1_b, E1_b, cc1-(D1-D1_b)/4., cc-(D1-D1_b)/4.)  # bottom edges
        case = case.pushPoints([(0,0)]).workplane(offset=A2_b)
        case = crect(case, D1, E1, cc1, cc)     # center (lower) outer edges
        case = case.pushPoints([(0,0)]).workplane(offset=c)
        case = crect(case, D1,E1,cc1, cc)       # center (upper) outer edges
        case = crect(case, D1_t1,E1_t1, cc1-(D1-D1_t1)/4., cc-(D1-D1_t1)/4.) # center (upper) inner edges
        case = case.pushPoints([(0,0)]).workplane(offset=A2_t)
        cc1_t = cc1-(D1-D1_t2)/4. # this one is defined because we use it later
        case = crect(case, D1_t2,E1_t2, cc1_t, cc-(D1-D1_t2)/4.) # top edges
        case = case.loft(ruled=True).faces(">Z").fillet(ef)

        # first pin indicator is created with a spherical pocket
        sphere_r = (fp_r*fp_r/2 + fp_z*fp_z) / (2*fp_z)
        sphere_z = A + sphere_r * 2 - fp_z - sphere_r
        sphere_x = -D1_t2/2.+cc1_t/2.+(fp_d+fp_r)/sqrt(2)
        sphere_y = -E1_t2/2.+cc1_t/2.+(fp_d+fp_r)/sqrt(2)
        sphere = cq.Workplane("XY", (sphere_x, sphere_y, sphere_z)). \
                 sphere(sphere_r)
        case = case.cut(sphere)

        # calculated dimensions for pin
        R1_o = R1+c # pin upper corner, outer radius
        R2_o = R2+c # pin lower corner, outer radius
        L = (D-D1)/2.-R1-R2-S

        # Create a pin object at the center of top side.
        bpin = cq.Workplane("YZ", (0,E1/2,0)). \
               moveTo(-tb_s, A1+A2_b). \
               line(S+tb_s, 0). \
               threePointArc((S+R1/sqrt(2), A1+A2_b-R1*(1-1/sqrt(2))),
                             (S+R1, A1+A2_b-R1)). \
               line(0, -(A1+A2_b-R1-R2_o)). \
               threePointArc((S+R1+R2_o*(1-1/sqrt(2)), R2_o*(1-1/sqrt(2))),
                             (S+R1+R2_o, 0)). \
               line(L-R2_o, 0). \
               line(0, c). \
               line(-(L-R2_o), 0). \
               threePointArc((S+R1+R2_o-R2/sqrt(2), c+R2*(1-1/sqrt(2))),
                             (S+R1+R2_o-R1, c+R2)). \
               lineTo(S+R1+c, A1+A2_b-R1). \
               threePointArc((S+R1_o/sqrt(2), A1+A2_b+c-R1_o*(1-1/sqrt(2))),
                             (S, A1+A2_b+c)). \
               line(-S-tb_s, 0).close().extrude(b).translate((-b/2,0,0))

        pins = []
        # create top, bottom side pins
        first_pos = -(npx-1)*e/2
        for i in range(npx):
            pin = bpin.translate((first_pos+i*e, 0, 0))
            pins.append(pin)
            pin = bpin.translate((first_pos+i*e, 0, 0)).\
                  rotate((0,0,0), (0,0,1), 180)
            pins.append(pin)

        # create right, left side pins
        first_pos = -(npy-1)*e/2
        for i in range(npy):
            pin = bpin.translate((first_pos+i*e, (D1-E1)/2, 0)).\
                  rotate((0,0,0), (0,0,1), 90)
            pins.append(pin)
            pin = bpin.translate((first_pos+i*e, (D1-E1)/2, 0)).\
                  rotate((0,0,0), (0,0,1), 270)
            pins.append(pin)

        # create exposed thermal pad if requested
        if self.epad:
            pins.append(cq.Workplane("XY").box(D2, E2, A1).translate((0,0,A1/2)))

        # merge all pins to a single object
        merged_pins = pins[0]
        for p in pins[1:]:
            merged_pins = merged_pins.union(p)
        pins = merged_pins

        # extract pins from case
        case = case.cut(pins)

        model = ComponentModel()
        model.addPart(case, self.case_color, "body")
        model.addPart(pins, self.pins_color, "pins")

        return model
Exemple #2
0
    def generate(self):
        # extract parameters to local namespace
        D = self.D
        E1 = self.E1
        E = self.E
        A1 = self.A1
        A2 = self.A2
        b1 = self.b1
        b = self.b
        e = self.e
        npins = self.npins
        L = self.L
        c = self.c
        fp_r = self.fp_r
        fp_d = self.fp_d
        fp_t = self.fp_t
        ef = self.ef
        ti_r = self.ti_r
        ti_d = self.ti_d
        the = self.the
        tb_s = self.tb_s

        # calculated dimensions

        A = A1 + A2

        A2_t = (A2 - c) / 2.  # body top part height
        A2_b = A2_t  # body bottom part height
        D_b = D - 2 * tan(radians(the)) * A2_b  # bottom length
        E1_b = E1 - 2 * tan(radians(the)) * A2_b  # bottom width
        D_t1 = D - tb_s  # top part bottom length
        E1_t1 = E1 - tb_s  # top part bottom width
        D_t2 = D_t1 - 2 * tan(radians(the)) * A2_t  # top part upper length
        E1_t2 = E1_t1 - 2 * tan(radians(the)) * A2_t  # top part upper width

        # start drawing with case
        case = cq.Workplane(cq.Plane.XY()).workplane(offset=A1).rect(D_b, E1_b). \
               workplane(offset=A2_b).rect(D, E1).workplane(offset=c).rect(D,E1). \
               rect(D_t1,E1_t1).workplane(offset=A2_t).rect(D_t2,E1_t2). \
               loft(ruled=True)

        # draw top indicator
        case = case.faces(">Z").center(D_b / 2., 0).hole(ti_r * 2, ti_d)

        # draw 1st pin (side pin shape)
        x = e * (npins / 4. - 0.5)  # center x position of first pin
        ty = (A2 + c) / 2. + A1  # top point (max z) of pin

        # draw the side part of the pin
        pin = cq.Workplane("XZ", (x, E/2., 0)).\
              moveTo(+b/2., ty).line(0, -(L+ty-b)).line(-b/4.,-b).line(-b/2.,0).\
              line(-b/4.,b).line(0,L-b).line(-(b1-b)/2.,0).line(0,ty).close().extrude(c)

        # draw the top part of the pin
        pin = pin.faces(">Z").workplane().center(-(b1+b)/4.,c/2.).\
              rect((b1+b)/2.,-E/2.,centered=False).extrude(-c)

        # fillet the corners
        def fillet_corner(pina):
            BS = cq.selectors.BoxSelector
            return pina.edges(BS((1000, E/2.-c-0.001, ty-c-0.001), (-1000, E/2.-c+0.001, ty-c+0.001))).\
                fillet(c/2.).\
                edges(BS((1000, E/2.-0.001, ty-0.001), (-1000, E/2.+0.001, ty+0.001))).\
                fillet(1.5*c)

        pin = fillet_corner(pin)

        # draw the 2nd pin (regular pin shape)
        x = e * (npins / 4. - 0.5 - 1)  # center x position of 2nd pin
        pin2 = cq.Workplane("XZ", (x, E/2., 0)).\
               moveTo(b1/2., ty).line(0, -ty).line(-(b1-b)/2.,0).line(0,-L+b).\
               line(-b/4.,-b).line(-b/2.,0).line(-b/4.,b).line(0,L-b).\
               line(-(b1-b)/2.,0).line(0,ty).\
               close().extrude(c)

        # draw the top part of the pin
        pin2 = pin2.faces(">Z").workplane().center(0, -E / 4.).rect(
            b1, -E / 2.).extrude(-c)
        pin2 = fillet_corner(pin2)

        # create other pins (except last one)
        pins = [pin, pin2]
        for i in range(2, npins / 2 - 1):
            pin_i = pin2.translate((-e * (i - 1), 0, 0))
            pins.append(pin_i)

        # create last pin (mirrored 1st pin)
        x = -e * (npins / 4. - 0.5)
        pinl = cq.Workplane("XZ", (x, E/2., 0)).\
               moveTo(-b/2., ty).line(0, -(L+ty-b)).line(b/4.,-b).line(b/2.,0).\
               line(b/4.,b).line(0,L-b).line((b1-b)/2.,0).line(0,ty).close().\
               extrude(c).\
               faces(">Z").workplane().center(-(b1+b)/4.,c/2.).\
               rect((b1+b)/2.,-E/2.,centered=False).extrude(-c)
        pinl = fillet_corner(pinl)

        pins.append(pinl)

        def union_all(objects):
            o = objects[0]
            for i in range(1, len(objects)):
                o = o.union(objects[i])
            return o

        # union all pins
        pins = union_all(pins)

        # create other side of the pins (mirror would be better but there
        # is no solid mirror API)
        pins = pins.union(pins.rotate((0, 0, 0), (0, 0, 1), 180))

        # finishing touches
        BS = cq.selectors.BoxSelector
        case = case.edges(
            BS((D_t2 / 2. + 0.1, E1_t2 / 2., 0),
               (D / 2. + 0.1, E1 / 2. + 0.1, A2))).fillet(ef)
        case = case.edges(
            BS((-D_t2 / 2., E1_t2 / 2., 0),
               (-D / 2. - 0.1, E1 / 2. + 0.1, A2))).fillet(ef)
        case = case.edges(
            BS((-D_t2 / 2., -E1_t2 / 2., 0),
               (-D / 2. - 0.1, -E1 / 2. - 0.1, A2))).fillet(ef)
        case = case.edges(
            BS((D_t2 / 2., -E1_t2 / 2., 0),
               (D / 2. + 0.1, -E1 / 2. - 0.1, A2))).fillet(ef)
        case = case.edges(
            BS((D / 2., E1 / 2., A - ti_d - 0.001),
               (-D / 2., -E1 / 2., A + 0.1))).fillet(ef)

        # add first pin indicator
        case = case.faces(">Z").workplane().center(D_t2/2.-fp_r-fp_t,E1_t2/2.-fp_r-fp_t).\
               hole(fp_r*2, fp_d)

        # extract pins from the case
        case = case.cut(pins)

        model = ComponentModel()
        model.addPart(case, self.case_color, "body")
        model.addPart(pins, self.pins_color, "pins")
        return model
Exemple #3
0
    def generate(self):
        # extract parameters to local namespace
        D = self.D
        E1 = self.E1
        E = self.E
        A1 = self.A1
        A2 = self.A2
        b1 = self.b1
        b = self.b
        e = self.e
        npins = self.npins
        L = self.L
        c = self.c
        fp_r = self.fp_r
        fp_d = self.fp_d
        fp_t = self.fp_t
        ef = self.ef
        ti_r = self.ti_r
        ti_d = self.ti_d
        the = self.the
        tb_s = self.tb_s

        # calculated dimensions

        A = A1 + A2

        A2_t = (A2 - c) / 2.0  # body top part height
        A2_b = A2_t  # body bottom part height
        D_b = D - 2 * tan(radians(the)) * A2_b  # bottom length
        E1_b = E1 - 2 * tan(radians(the)) * A2_b  # bottom width
        D_t1 = D - tb_s  # top part bottom length
        E1_t1 = E1 - tb_s  # top part bottom width
        D_t2 = D_t1 - 2 * tan(radians(the)) * A2_t  # top part upper length
        E1_t2 = E1_t1 - 2 * tan(radians(the)) * A2_t  # top part upper width

        # start drawing with case
        case = (
            cq.Workplane(cq.Plane.XY())
            .workplane(offset=A1)
            .rect(D_b, E1_b)
            .workplane(offset=A2_b)
            .rect(D, E1)
            .workplane(offset=c)
            .rect(D, E1)
            .rect(D_t1, E1_t1)
            .workplane(offset=A2_t)
            .rect(D_t2, E1_t2)
            .loft(ruled=True)
        )

        # draw top indicator
        case = case.faces(">Z").center(D_b / 2.0, 0).hole(ti_r * 2, ti_d)

        # draw 1st pin (side pin shape)
        x = e * (npins / 4.0 - 0.5)  # center x position of first pin
        ty = (A2 + c) / 2.0 + A1  # top point (max z) of pin

        # draw the side part of the pin
        pin = (
            cq.Workplane("XZ", (x, E / 2.0, 0))
            .moveTo(+b / 2.0, ty)
            .line(0, -(L + ty - b))
            .line(-b / 4.0, -b)
            .line(-b / 2.0, 0)
            .line(-b / 4.0, b)
            .line(0, L - b)
            .line(-(b1 - b) / 2.0, 0)
            .line(0, ty)
            .close()
            .extrude(c)
        )

        # draw the top part of the pin
        pin = (
            pin.faces(">Z")
            .workplane()
            .center(-(b1 + b) / 4.0, c / 2.0)
            .rect((b1 + b) / 2.0, -E / 2.0, centered=False)
            .extrude(-c)
        )

        # fillet the corners
        def fillet_corner(pina):
            BS = cq.selectors.BoxSelector
            return (
                pina.edges(
                    BS((1000, E / 2.0 - c - 0.001, ty - c - 0.001), (-1000, E / 2.0 - c + 0.001, ty - c + 0.001))
                )
                .fillet(c / 2.0)
                .edges(BS((1000, E / 2.0 - 0.001, ty - 0.001), (-1000, E / 2.0 + 0.001, ty + 0.001)))
                .fillet(1.5 * c)
            )

        pin = fillet_corner(pin)

        # draw the 2nd pin (regular pin shape)
        x = e * (npins / 4.0 - 0.5 - 1)  # center x position of 2nd pin
        pin2 = (
            cq.Workplane("XZ", (x, E / 2.0, 0))
            .moveTo(b1 / 2.0, ty)
            .line(0, -ty)
            .line(-(b1 - b) / 2.0, 0)
            .line(0, -L + b)
            .line(-b / 4.0, -b)
            .line(-b / 2.0, 0)
            .line(-b / 4.0, b)
            .line(0, L - b)
            .line(-(b1 - b) / 2.0, 0)
            .line(0, ty)
            .close()
            .extrude(c)
        )

        # draw the top part of the pin
        pin2 = pin2.faces(">Z").workplane().center(0, -E / 4.0).rect(b1, -E / 2.0).extrude(-c)
        pin2 = fillet_corner(pin2)

        # create other pins (except last one)
        pins = [pin, pin2]
        for i in range(2, npins / 2 - 1):
            pin_i = pin2.translate((-e * (i - 1), 0, 0))
            pins.append(pin_i)

        # create last pin (mirrored 1st pin)
        x = -e * (npins / 4.0 - 0.5)
        pinl = (
            cq.Workplane("XZ", (x, E / 2.0, 0))
            .moveTo(-b / 2.0, ty)
            .line(0, -(L + ty - b))
            .line(b / 4.0, -b)
            .line(b / 2.0, 0)
            .line(b / 4.0, b)
            .line(0, L - b)
            .line((b1 - b) / 2.0, 0)
            .line(0, ty)
            .close()
            .extrude(c)
            .faces(">Z")
            .workplane()
            .center(-(b1 + b) / 4.0, c / 2.0)
            .rect((b1 + b) / 2.0, -E / 2.0, centered=False)
            .extrude(-c)
        )
        pinl = fillet_corner(pinl)

        pins.append(pinl)

        def union_all(objects):
            o = objects[0]
            for i in range(1, len(objects)):
                o = o.union(objects[i])
            return o

        # union all pins
        pins = union_all(pins)

        # create other side of the pins (mirror would be better but there
        # is no solid mirror API)
        pins = pins.union(pins.rotate((0, 0, 0), (0, 0, 1), 180))

        # finishing touches
        BS = cq.selectors.BoxSelector
        case = case.edges(BS((D_t2 / 2.0 + 0.1, E1_t2 / 2.0, 0), (D / 2.0 + 0.1, E1 / 2.0 + 0.1, A2))).fillet(ef)
        case = case.edges(BS((-D_t2 / 2.0, E1_t2 / 2.0, 0), (-D / 2.0 - 0.1, E1 / 2.0 + 0.1, A2))).fillet(ef)
        case = case.edges(BS((-D_t2 / 2.0, -E1_t2 / 2.0, 0), (-D / 2.0 - 0.1, -E1 / 2.0 - 0.1, A2))).fillet(ef)
        case = case.edges(BS((D_t2 / 2.0, -E1_t2 / 2.0, 0), (D / 2.0 + 0.1, -E1 / 2.0 - 0.1, A2))).fillet(ef)
        case = case.edges(BS((D / 2.0, E1 / 2.0, A - ti_d - 0.001), (-D / 2.0, -E1 / 2.0, A + 0.1))).fillet(ef)

        # add first pin indicator
        case = (
            case.faces(">Z")
            .workplane()
            .center(D_t2 / 2.0 - fp_r - fp_t, E1_t2 / 2.0 - fp_r - fp_t)
            .hole(fp_r * 2, fp_d)
        )

        # extract pins from the case
        case = case.cut(pins)

        model = ComponentModel()
        model.addPart(case, self.case_color, "body")
        model.addPart(pins, self.pins_color, "pins")
        return model
    def generate(self):
        """Returns a ComponentModel."""
        # prepare parameters for easier access
        D = self.D
        E = self.E
        D1 = self.D1
        E1 = self.E1
        A1 = self.A1
        A2 = self.A2
        b = self.b
        e = self.e
        npx = self.npx
        npy = self.npy
        epad = self.epad

        the = self.the
        tb_s = self.tb_s

        c = self.c
        R1 = self.R1
        R2 = self.R2
        S = self.S

        fp_r = self.fp_r
        fp_d = self.fp_d
        fp_z = self.fp_z
        ef = self.ef
        max_cc1 = self.max_cc1

        if self.epad:
            D2 = self.epad[0]
            E2 = self.epad[1]

        # calculated dimensions for body
        A = A1 + A2
        A2_t = (A2 - c) / 2  # body top part height
        A2_b = A2_t  # body bottom part height
        D1_b = D1 - 2 * tan(radians(the)) * A2_b  # bottom width
        E1_b = E1 - 2 * tan(radians(the)) * A2_b  # bottom length
        D1_t1 = D1 - tb_s  # top part bottom width
        E1_t1 = E1 - tb_s  # top part bottom length
        D1_t2 = D1_t1 - 2 * tan(radians(the)) * A2_t  # top part upper width
        E1_t2 = E1_t1 - 2 * tan(radians(the)) * A2_t  # top part upper length

        # calculate chamfers
        totpinwidthx = (npx -
                        1) * e + b  # total width of all pins on the X side
        totpinwidthy = (npy -
                        1) * e + b  # total width of all pins on the Y side

        cc1 = min((D1 - totpinwidthx) / 2.,
                  (E1 - totpinwidthy) / 2.) - 0.5 * tb_s
        cc1 = min(cc1, max_cc1)
        cc = cc1 / 2.

        def crect(wp, rw, rh, cv1, cv):
            """
            Creates a rectangle with chamfered corners.
            wp: workplane object
            rw: rectangle width
            rh: rectangle height
            cv1: chamfer value for 1st corner (lower left)
            cv: chamfer value for other corners
            """
            points = [(-rw / 2., -rh / 2. + cv1), (-rw / 2., rh / 2. - cv),
                      (-rw / 2. + cv, rh / 2.), (rw / 2. - cv, rh / 2.),
                      (rw / 2., rh / 2. - cv), (rw / 2., -rh / 2. + cv),
                      (rw / 2. - cv, -rh / 2.), (-rw / 2. + cv1, -rh / 2.),
                      (-rw / 2., -rh / 2. + cv1)]
            return wp.polyline(points)

        # start drawing with case model
        case = cq.Workplane(cq.Plane.XY()).workplane(offset=A1)
        case = crect(case, D1_b, E1_b, cc1 - (D1 - D1_b) / 4.,
                     cc - (D1 - D1_b) / 4.)  # bottom edges
        case = case.pushPoints([(0, 0)]).workplane(offset=A2_b)
        case = crect(case, D1, E1, cc1, cc)  # center (lower) outer edges
        case = case.pushPoints([(0, 0)]).workplane(offset=c)
        case = crect(case, D1, E1, cc1, cc)  # center (upper) outer edges
        case = crect(case, D1_t1, E1_t1, cc1 - (D1 - D1_t1) / 4.,
                     cc - (D1 - D1_t1) / 4.)  # center (upper) inner edges
        case = case.pushPoints([(0, 0)]).workplane(offset=A2_t)
        cc1_t = cc1 - (
            D1 - D1_t2) / 4.  # this one is defined because we use it later
        case = crect(case, D1_t2, E1_t2, cc1_t,
                     cc - (D1 - D1_t2) / 4.)  # top edges
        case = case.loft(ruled=True).faces(">Z").fillet(ef)

        # first pin indicator is created with a spherical pocket
        sphere_r = (fp_r * fp_r / 2 + fp_z * fp_z) / (2 * fp_z)
        sphere_z = A + sphere_r * 2 - fp_z - sphere_r
        sphere_x = -D1_t2 / 2. + cc1_t / 2. + (fp_d + fp_r) / sqrt(2)
        sphere_y = -E1_t2 / 2. + cc1_t / 2. + (fp_d + fp_r) / sqrt(2)
        sphere = cq.Workplane("XY", (sphere_x, sphere_y, sphere_z)). \
                 sphere(sphere_r)
        case = case.cut(sphere)

        # calculated dimensions for pin
        R1_o = R1 + c  # pin upper corner, outer radius
        R2_o = R2 + c  # pin lower corner, outer radius
        L = (D - D1) / 2. - R1 - R2 - S

        # Create a pin object at the center of top side.
        bpin = cq.Workplane("YZ", (0,E1/2,0)). \
               moveTo(-tb_s, A1+A2_b). \
               line(S+tb_s, 0). \
               threePointArc((S+R1/sqrt(2), A1+A2_b-R1*(1-1/sqrt(2))),
                             (S+R1, A1+A2_b-R1)). \
               line(0, -(A1+A2_b-R1-R2_o)). \
               threePointArc((S+R1+R2_o*(1-1/sqrt(2)), R2_o*(1-1/sqrt(2))),
                             (S+R1+R2_o, 0)). \
               line(L-R2_o, 0). \
               line(0, c). \
               line(-(L-R2_o), 0). \
               threePointArc((S+R1+R2_o-R2/sqrt(2), c+R2*(1-1/sqrt(2))),
                             (S+R1+R2_o-R1, c+R2)). \
               lineTo(S+R1+c, A1+A2_b-R1). \
               threePointArc((S+R1_o/sqrt(2), A1+A2_b+c-R1_o*(1-1/sqrt(2))),
                             (S, A1+A2_b+c)). \
               line(-S-tb_s, 0).close().extrude(b).translate((-b/2,0,0))

        pins = []
        # create top, bottom side pins
        first_pos = -(npx - 1) * e / 2
        for i in range(npx):
            pin = bpin.translate((first_pos + i * e, 0, 0))
            pins.append(pin)
            pin = bpin.translate((first_pos+i*e, 0, 0)).\
                  rotate((0,0,0), (0,0,1), 180)
            pins.append(pin)

        # create right, left side pins
        first_pos = -(npy - 1) * e / 2
        for i in range(npy):
            pin = bpin.translate((first_pos+i*e, (D1-E1)/2, 0)).\
                  rotate((0,0,0), (0,0,1), 90)
            pins.append(pin)
            pin = bpin.translate((first_pos+i*e, (D1-E1)/2, 0)).\
                  rotate((0,0,0), (0,0,1), 270)
            pins.append(pin)

        # create exposed thermal pad if requested
        if self.epad:
            pins.append(
                cq.Workplane("XY").box(D2, E2, A1).translate((0, 0, A1 / 2)))

        # merge all pins to a single object
        merged_pins = pins[0]
        for p in pins[1:]:
            merged_pins = merged_pins.union(p)
        pins = merged_pins

        # extract pins from case
        case = case.cut(pins)

        model = ComponentModel()
        model.addPart(case, self.case_color, "body")
        model.addPart(pins, self.pins_color, "pins")

        return model
Exemple #5
0
 def generate(self):
     """Returns a ComponentModel."""
     b = cq.Workplane("XY").box(self.l, self.w, self.h)
     model = ComponentModel()
     model.addPart(b, self.color, "Body")
     return model
Exemple #6
0
    def generate(self):
        D = self.D
        E = self.E
        A = self.A
        A1 = self.A1
        b = self.b
        e = self.e
        npx = self.npx
        npy = self.npy

        A3 = self.A3
        L = self.L
        ef = self.ef
        fp_r = self.fp_r
        fp_d = self.fp_d
        fp_t = self.fp_t
        ecc = self.ecc

        if self.epad:
            if type(self.epad) == tuple:
                D2 = self.epad[0]
                E2 = self.epad[1]
            else: # assuming type(self.epad) float or int
                E2 = D2 = self.epad

        if self.flanged:
            D1 = self.D1
            E1 = self.E1
            the = self.the
            P = self.P

        # calculated dimensions
        A2 = A - A1

        # draw the case
        cw = D-A1*2
        cl = E-A1*2
        if not self.flanged: # standard simple box style case
            case = cq.Workplane("XY").workplane(offset=A1). \
                   box(cw, cl, A2, centered=(True,True,False)) # margin (A1) to see fused pins
            case = case.edges("|Z").fillet(ef)
            case = case.faces(">Z").fillet(ef)
            # draw first pin indicator
            fp_x = -(cw/2)+fp_t+fp_r
            fp_y = -(cl/2)+fp_t+fp_r
            case = case.faces(">Z").workplane().center(fp_x, fp_y).hole(fp_r*2, fp_d)
        else: # molded case type
            D1_t = D1-2*tan(radians(the))*(A-A3)
            E1_t = E1-2*tan(radians(the))*(A-A3)
            case = cq.Workplane("XY").workplane(offset=A1)
            case = crect(case, cw, cl, P, P)
            case = case.extrude(A3-A1)
            case = case.faces(">Z").workplane()
            case = crect(case, D1, E1, P*0.8, P*0.8).\
                   workplane(offset=A-A3)
            case = crect(case, D1_t, E1_t, P*0.6, P*0.6).\
                   loft(ruled=True)

            # fillet the bottom vertical edges
            case = case.edges("|Z").fillet(ef)

            # fillet top and side faces of the top molded part
            BS = cq.selectors.BoxSelector
            case = case.edges(BS((-D1/2, -E1/2, A3+0.001), (D1/2, E1/2, A+0.001))).fillet(ef)

            # draw first pin indicator
            fp_x = -(D1_t/2)+fp_t+fp_r
            fp_y = -(E1_t/2)+fp_t+fp_r
            case = case.faces(">Z").workplane().center(fp_x, fp_y).hole(fp_r*2, fp_d)

        # draw pins
        bpin = cq.Workplane("XY").\
                moveTo(b, 0). \
                lineTo(b, L-b/2). \
                threePointArc((b/2,L),(0, L-b/2)). \
                lineTo(0, 0). \
                close().extrude(A3).translate((b/2,E/2,0)). \
                rotate((b/2,E/2,0), (0,0,1), 180)

        pins = []

        # create top and bottom side pins
        first_pos = -(npx-1)*e/2
        for i in range(npx):
            pin = bpin.translate((first_pos+i*e, 0, 0))
            pins.append(pin)
            pin = bpin.translate((first_pos+i*e, 0, 0)).\
                  rotate((0,0,0), (0,0,1), 180)
            pins.append(pin)

        # create right and left side pins
        for i in range(npy):
            pin = bpin.translate((first_pos+i*e, (D-E)/2, 0)).\
                  rotate((0,0,0), (0,0,1), 90)
            pins.append(pin)
            pin = bpin.translate((first_pos+i*e, (D-E)/2, 0)).\
                  rotate((0,0,0), (0,0,1), 270)
            pins.append(pin)

        # draw exposed pad
        if self.epad:
            #pins.append(cq.Workplane("XY").box(D2, E2, A1+A1/10).translate((0,0,A1+A1/10)))
            epad = cq.Workplane("XY"). \
                   moveTo(-D2/2+ecc, -E2/2). \
                   lineTo(D2/2, -E2/2). \
                   lineTo(D2/2, E2/2). \
                   lineTo(-D2/2, E2/2). \
                   lineTo(-D2/2, -E2/2+ecc). \
                   close().extrude(A1)
            pins.append(epad)

        # merge all pins to a single object
        merged_pins = pins[0]
        for p in pins[1:]:
            merged_pins = merged_pins.union(p)
        pins = merged_pins

        # extract pins from case
        case = case.cut(pins)

        model = ComponentModel()
        model.addPart(case, self.case_color, "body")
        model.addPart(pins, self.pins_color, "pins")

        return model
                   lineTo(-D2/2, -E2/2+ecc). \
                   close().extrude(A1)
            pins.append(epad)

        # merge all pins to a single object
        merged_pins = pins[0]
        for p in pins[1:]:
            merged_pins = merged_pins.union(p)
        pins = merged_pins

        # extract pins from case
        case = case.cut(pins)

        model = ComponentModel()
        model.addPart(case, self.case_color, "body")
        model.addPart(pins, self.pins_color, "pins")

        return model


class QFNGen(BaseQFNGen):
    def __init__(self, D, E, A, A1, b, e, np, epad):
        BaseQFNGen.__init__(self, D, E, A, A1, b, e, np / 4, np / 4, epad)


class MQFNGen(BaseQFNGen):
    def __init__(self, D, E, D1, E1, A, A1, P, b, e, np, epad):
        BaseQFNGen.__init__(self,
                            D,
                            E,
                            A,
Exemple #8
0
    def generate(self):
        L = self.L     # overall height of the body
        D = self.D     # body diameter
        d = self.d     # lead diameter
        F = self.F     # lead separation (center to center)
        ll = self.ll   # lead length
        la = self.la   # extra lead length of the anode

        bs = self.bs     # board separation

        bt = self.bt      # flat part before belt
        bd = self.bd      # depth of the belt
        bh = self.bh      # height of the belt
        bf = self.bf      # belt fillet

        tc = self.tc      # cut thickness for the bottom
        dc = self.dc    # diameter of the bottom cut
        ts = self.ts      # thickness of the slots at the top in the shape of (+)
        ws = self.ws      # width of the slots

        ef = self.ef      # top and bottom edges fillet

        bpt = 0.1        # bottom plastic thickness (not visual)
        tmt = ts*2       # top metallic part thickness (not visual)

        # TODO: calculate width of the cathode marker bar from the body size
        ciba = 45.  # angle of the cathode identification bar

        # TODO: calculate marker sizes according to the body size
        mmb_h = 2.       # lenght of the (-) marker on the cathode bar
        mmb_w = 0.5      # rough width of the marker

        ef_s2 = ef/sqrt(2)
        ef_x = ef-ef/sqrt(2)

        def bodyp():
            return cq.Workplane("XZ").move(0, bs).\
                   move(0, tc+bpt).\
                   line(dc/2., 0).\
                   line(0, -(tc+bpt)).\
                   line(D/2.-dc/2.-ef, 0).\
                   threePointArc((D/2.-(ef_x), bs+(ef_x)), (D/2., bs+ef)).\
                   line(0, bt).\
                   threePointArc((D/2.-bd, bs+bt+bh/2.), (D/2., bs+bt+bh)).\
                   lineTo(D/2., L+bs-ef).\
                   threePointArc((D/2.-(ef_x), L+bs-(ef_x)), (D/2.-ef, L+bs)).\
                   lineTo(dc/2., L+bs).\
                   line(0, -(tc+tmt)).\
                   line(-dc/2., 0).\
                   close()

        body = bodyp().revolve(360-ciba, (0,0,0), (0,1,0))
        bar = bodyp().revolve(ciba, (0,0,0), (0,1,0))

        # # fillet the belt edges
        BS = cq.selectors.BoxSelector
        # note that edges are selected from their centers
        body = body.edges(BS((-0.5,-0.5, bs+bt-0.01), (0.5, 0.5, bs+bt+bh+0.01))).\
               fillet(bf)
        b_r = D/2.-bd # inner radius of the belt
        bar = bar.edges(BS((b_r/sqrt(2), 0, bs+bt-0.01),(b_r, -b_r/sqrt(2), bs+bt+bh+0.01))).\
              fillet(bf)

        body = body.rotate((0,0,0), (0,0,1), 180-ciba/2)
        bar = bar.rotate((0,0,0), (0,0,1), 180+ciba/2)

        # draw the plastic at the bottom
        bottom = cq.Workplane("XY").workplane(offset=bs+tc).\
                 circle(dc/2).extrude(bpt)

        # draw the metallic part at the top
        top = cq.Workplane("XY").workplane(offset=bs+L-tc-ts).\
             circle(dc/2).extrude(tmt)

        # draw the slots on top in the shape of plus (+)
        top = top.faces(">Z").workplane().move(ws/2,ws/2).\
              line(0,D).line(-ws,0).line(0,-D).\
              line(-D,0).line(0,-ws).line(D,0).\
              line(0,-D).line(ws,0).line(0,D).\
              line(D,0).line(0,ws).close().cutBlind(-ts)

        # draw the (-) marks on the bar
        n = int(L/(2*mmb_h)) # number of (-) marks to draw
        points = []
        first_z = (L-(2*n-1)*mmb_h)/2
        for i in range(n):
            points.append((0, (i+0.25)*2*mmb_h+first_z))
        mmb = cq.Workplane("YZ", (-D/2,0,bs)).pushPoints(points).\
              box(mmb_w, mmb_h, 2).\
              edges("|X").fillet(mmb_w/2.-0.001)

        mmb = mmb.cut(mmb.translate((0,0,0)).cut(bar))
        bar = bar.cut(mmb)

        # draw the leads
        leads = cq.Workplane("XY").workplane(offset=bs+tc).\
                center(-F/2,0).circle(d/2).extrude(-(ll+tc)).\
                center(F,0).circle(d/2).extrude(-(ll+tc+la))

        model = ComponentModel()
        model.addPart(body, self.body_color, "body")
        model.addPart(mmb, self.body_color, "marks")
        model.addPart(top, self.top_color, "top")
        model.addPart(bottom, self.bottom_color, "bottom")
        model.addPart(bar, self.bar_color, "bar")
        model.addPart(leads, self.lead_color, "pins")

        return model
Exemple #9
0
    def generate(self):

        L = self.L    # overall height
        D = self.D    # diameter
        A = self.A    # base width (x&y)
        H = self.H    # max width (x) with pins
        P = self.P    # distance between pins
        W = self.W    # pin width

        c = self.c  # pin thickness

        bh = self.bh # belt start height
        br = self.br # belt radius
        bf = self.bf # belt fillet

        D2 = self.D2  # cut diameter

        h1 = self.h1  # bottom plastic height, cathode side
        h2 = self.h2  # bottom plastic base height, mid side
        h3 = self.h3  # bottom plastic height, anode side

        cf = self.cf  # cathode side corner fillet
        ac = self.ac  # anode side chamfer

        ef = self.ef

        cimw = D/2.*0.7 # cathode identification mark width

        # draw aluminium the body
        body = cq.Workplane("XZ", (0,0,c+h2)).\
               lineTo(D/2., 0).\
               line(0, bh).\
               threePointArc((D/2.-br, bh+br), (D/2., bh+2*br)).\
               lineTo(D/2., L-c-h2).\
               line(-D/2, 0).\
               close().revolve()

        # fillet the belt edges
        BS = cq.selectors.BoxSelector
        body = body.edges(BS((-0.1,-0.1,c+h2+0.1), (0.1,0.1,L-0.1))).\
               fillet(bf)

        # fillet the top and bottom
        body = body.faces(">Z").fillet(ef).\
               faces("<Z").fillet(ef)

        # draw the plastic base
        base = cq.Workplane("XY", (0,0,c)).\
               moveTo(-A/2.,-A/2.).\
               line(A-ac, 0).\
               line(ac, ac).\
               line(0, A-2*ac).\
               line(-ac, ac).\
               line(-A+ac, 0).\
               close().extrude(h1)

        # fillet cathode side
        base = base.edges(BS((-A,-A,0), (-A/2.+0.01,-A/2.+0.01,c+h1+0.01))).\
               fillet(cf).\
               edges(BS((-A,A,0), (-A/2.+0.01,A/2.-0.01,c+h1+0.01))).\
               fillet(cf)

        # cut base center
        base = base.cut(
            cq.Workplane("XY", (0,0,c+h2)).\
            circle(D2/2.).extrude(h1-h2))

        # cut anode side of the base
        base = base.cut(
            cq.Workplane("XY", (0,-A/2.,c+h3)).\
            box(A/2., A, h1-h3, centered=(False, False, False)))

        # draw pins
        pins = cq.Workplane("XY").\
               moveTo(H/2., -W/2.).\
               line(0, W).\
               lineTo(P/2.+W/2., W/2.).\
               threePointArc((P/2.,0), (P/2.+W/2., -W/2)).\
               close().extrude(c)

        pins = pins.union(pins.rotate((0,0,0), (0,0,1), 180))

        # draw the cathode identification mark
        cim = cq.Workplane("XY", (-D/2.,0,L-ef)).\
              box(cimw, D, ef, centered=(False, True, False))

        # do intersection
        cim = cim.cut(cim.translate((0,0,0)).cut(body))

        body.cut(cim)

        model = ComponentModel()
        model.addPart(body, self.body_color, "body")
        model.addPart(base, self.base_color, "base")
        model.addPart(pins, self.body_color, "pins")
        model.addPart(cim, (0.,0.,0.), "mark")
        return model
Exemple #10
0
 def generate(self):
     """Returns a ComponentModel."""
     b = cq.Workplane("XY").box(self.l, self.w, self.h)
     model = ComponentModel()
     model.addPart(b, self.color, "Body")
     return model