예제 #1
0
    def __init__(self,
                 fc_fro_ax,
                 fc_top_ax,
                 base_h = 2,
                 base_l = 0,
                 base_w = 0,
                 bolt_d = 3,
                 bolt_csunk = 0,
                 ref = 1,
                 pos = V0,
                 extra=1,
                 wfco = 1,
                 intol = 0,
                 name = 'belt_clamp' ):

        doc = FreeCAD.ActiveDocument
        self.name = name

        # if more tolerance is needed in the center
        cb_in_w = CB_IW + intol
        self.cb_in_w = cb_in_w
        cb_wall_w = CB_W - intol/2
        self.cb_wall_w = cb_wall_w

        # normalize and get the other base vector
        nfro_ax = DraftVecUtils.scaleTo(fc_fro_ax,1)
        nfro_ax_n = nfro_ax.negative()
        ntop_ax = DraftVecUtils.scaleTo(fc_top_ax,1)
        ntop_ax_n = ntop_ax.negative()
        nsid_ax = nfro_ax.cross(ntop_ax)

        clamponly_l = CB_L + CS + 2 * CCYL_R
        clamponly_w = max((cb_in_w+2*cb_wall_w), (2*CCYL_R))

        bolt2end = 0 # they will change in case they are used
        clamp2end = 0
        if base_h == 0 and bolt_d == 0:
            # No base
            base = 0
            base_l = 0
        else:
            base = 1
            if bolt_d > 0 :
                d_bolt = kcomp.D912[bolt_d]
                bolt_shank_r = d_bolt['shank_r_tol']
                bolt_head_r = d_bolt['head_r_tol']
                bolt_head_l = d_bolt['head_l']
                # there are bolt holes, calculate the extra length needed
                # from the end to the clamp / cylinder
                bolt2end = fcfun.get_bolt_end_sep(bolt_d,hasnut=0)
                # bolt space on one side
                clamp2end = 2 * bolt2end
                base_min_len = clamponly_l + 2 * clamp2end
                if base_l < base_min_len:
                    logger.debug("base_l too short, taking min len %s",
                                  base_min_len)
                    base_l = base_min_len
                else:
                    clamp2end = (base_l - clamponly_l) /2.
                    bolt2end = clamp2end / 2.
                if bolt_csunk > 0:
                    # there are countersunk holes for the bolts
                    if base_h == 0:
                        # minimum height:
                        base_h = bolt_csunk + bolt_head_l
                    else:
                        # check if there is enough base height
                        if base_h < bolt_csunk + bolt_head_l:
                            base_h = bolt_csunk + bolt_head_l
                            logger.debug("base_h too short,taking height %s",
                                  base_h)
                else:
                    if base_h < self.MIN_BASE_H:
                        base_h = self.MIN_BASE_H
                        logger.debug("taking base height %s",
                                  base_h)
            else: # No bolt
                bolt2end = 0
                if base_l < clamponly_l:
                    if base_l > 0:
                        logger.debug("base_l too short, Taking min len %s",
                                      clamponly_l) 
                    base_l = clamponly_l
                    clamp2end = 0
                else: #base larger than clamp
                    clamp2end = (base_l - clamponly_l) /2.
            if base_w == 0:
                base_w = clamponly_w
            elif base_w < clamponly_w:
                logger.debug("base_w too short, Taking min width %s",
                              clamponly_w)
                base_w = clamponly_w

        ###
        cencyl2froclamp = CB_L+CS+CCYL_R
        #vectors to references:
        # from the center of the cylinder to the front clamp
        vec_1to2 = DraftVecUtils.scale(nfro_ax,cencyl2froclamp)
        vec_2to1 = vec_1to2.negative()
        # from the front clamp to the front bolt
        vec_2to3 = DraftVecUtils.scale(nfro_ax, bolt2end)
        vec_3to2 = vec_2to3.negative()
        # Since not always there is a bolt, from the clamp
        vec_2to4 = DraftVecUtils.scale(nfro_ax, clamp2end)
        vec_4to2 = vec_2to4.negative()
        # from the center of the cylinder to the back bolt
        vec_5to1 = DraftVecUtils.scale(nfro_ax,CCYL_R) + vec_2to3
        vec_1to5 = vec_5to1.negative()
        # from the back bolt to the back end
        vec_6to1 = DraftVecUtils.scale(nfro_ax,CCYL_R) + vec_2to4
        vec_1to6 = vec_6to1.negative()

        # default values
        vec_tocencyl = V0
        vec_tofrontclamp = V0
        vec_tofrontbolt = V0
        vec_tofrontbase = V0
        vec_tobackbolt = V0
        vec_tobackbase = V0
        if ref==1: #ref on the center of the cylinder
            vec_tocencyl = V0
            vec_tofrontclamp = vec_1to2 
            vec_tofrontbolt = vec_1to2 + vec_2to3
            vec_tofrontbase = vec_1to2 + vec_2to4
            vec_tobackbolt = vec_1to5
            vec_tobackbase = vec_1to6
        elif ref==2: #ref on the front of the clamps
            vec_tocencyl = vec_2to1
            vec_tofrontclamp = V0
            vec_tofrontbolt = vec_2to3
            vec_tofrontbase = vec_2to4
            vec_tobackbolt = ve_2to1 + vec_1to5
            vec_tobackbase = ve_2to1 + vec_1to6
        elif ref == 3:
            if clamp2end == 0 or bolt2end == 0:
                logger.error('reference on the bolts, there are no bolts')
            else:
                vec_tocencyl = vec_3to2 + vec_2to1
                vec_tofrontclamp = vec_3to2
                vec_tofrontbolt = V0
                vec_tofrontbase = vec_2to3 #same as 3 to 4
                vec_tobackbolt = vec_3to2 + vec_2to1 + vec_1to5
                vec_tobackbase = vec_3to2 + vec_2to1 + vec_1to6
        elif ref == 4:
            if clamp2end == 0:
                logger.debug('reference at the end, same as the clamps')
            vec_tocencyl = vec_4to2 + vec_2to1
            vec_tofrontclamp = vec_4to2
            vec_tofrontbolt = vec_3to2 # same as 4 to 3
            vec_tofrontbase = V0
            vec_tobackbolt = vec_4to2 + vec_2to1 + vec_1to5
            vec_tobackbase = vec_4to2 + vec_2to1 + vec_1to6
        elif ref == 5:
            if clamp2end == 0 or bolt2end == 0:
                logger.error('reference on the bolts, there are no bolts')
            else:
                vec_tocencyl = vec_5to1
                vec_tofrontclamp = vec_5to1 + vec_1to2
                vec_tofrontbolt = vec_5to1 + vec_1to2 + vec_2to3
                vec_tofrontbase = vec_5to1 + vec_1to2 + vec_2to4
                vec_tobackbolt = V0
                vec_tobackbase = vec_3to2 #5to6: same as 3to2
        elif ref == 6:
            if clamp2end == 0:
                logger.debug('reference at the end, same as the clamps')
            vec_tocencyl = vec_6to1
            vec_tofrontclamp = vec_6to1 + vec_1to2
            vec_tofrontbolt = vec_6to1 + vec_1to2 + vec_2to3
            vec_tofrontbase = vec_6to1 + vec_1to2 + vec_2to4
            vec_tobackbolt = vec_2to3 # same as 6 to 5
            vec_tobackbase = V0
        else:
            logger.error('reference out of range')
          


        if extra == 0:
            extra_pos = V0
        else:
            extra_pos = DraftVecUtils.scale(ntop_ax, -extra)
        pos_extra = pos + extra_pos
        base_top_add = DraftVecUtils.scale(ntop_ax, base_h + extra)
        
        
        # total height of the clamp, including the base
        clamp_tot_h = C_H + base_h + extra
        # position of the clamp cylinder:
        clampcyl_pos = pos_extra + vec_tocencyl
        shp_cyl = fcfun.shp_cyl(CCYL_R, clamp_tot_h, ntop_ax, clampcyl_pos)
        # position of the clamp blocks, without going to the side axis
        clampblock_pos = pos_extra + vec_tofrontclamp
        clampblock_side_add = DraftVecUtils.scale(nsid_ax, 
                                                  (cb_in_w + cb_wall_w)/2.)
        clampblock_1_pos = clampblock_pos + clampblock_side_add
        clampblock_2_pos = clampblock_pos - clampblock_side_add
        shp_clampblock_1 = fcfun.shp_box_dir(box_w = cb_wall_w,
                                             box_d = CB_L,
                                             box_h = clamp_tot_h,
                                             fc_axis_h = ntop_ax,
                                             fc_axis_d = nfro_ax_n,
                                             cw=1, cd=0, ch=0,
                                             pos = clampblock_1_pos)
        shp_clampblock_2 = fcfun.shp_box_dir(box_w = cb_wall_w,
                                             box_d = CB_L,
                                             box_h = clamp_tot_h,
                                             fc_axis_h = ntop_ax,
                                             fc_axis_d = nfro_ax_n,
                                             cw=1, cd=0, ch=0,
                                             pos = clampblock_2_pos)

        shp_clamp = shp_cyl.multiFuse([shp_clampblock_1, shp_clampblock_2])


        #position of the base, we will take it on the point 4 and make it not 
        # centered
        if base == 1:
            base_pos = pos_extra + vec_tofrontbase 
            shp_base = fcfun.shp_box_dir(box_w = base_w,
                                         box_d = base_l,
                                         box_h = base_h + extra,
                                         fc_axis_h = ntop_ax,
                                         fc_axis_d = nfro_ax_n,
                                         cw=1, cd=0, ch=0,
                                         pos = base_pos)
            if base_l > clamponly_l: # chamfer
                shp_base = fcfun.shp_filletchamfer_dir (shp_base,
                                              fc_axis=ntop_ax,
                                              fillet=1, radius= 2)

            # shape of the bolt holes, if there are
            if bolt_d > 0:
                pos_bolt_front = pos_extra + vec_tofrontbolt + base_top_add
                pos_bolt_back = pos_extra + vec_tobackbolt + base_top_add
                if bolt_csunk > 0 :
                    shp_bolt_front = fcfun.shp_bolt_dir(
                                              r_shank = bolt_shank_r,
                                              l_bolt = base_h + extra,
                                              r_head = bolt_head_r,
                                              l_head = bolt_head_l,
                                              support=0,
                                              fc_normal = ntop_ax_n,
                                              pos=pos_bolt_front)
                    shp_bolt_back = fcfun.shp_bolt_dir(
                                              r_shank = bolt_shank_r,
                                              l_bolt = base_h + extra,
                                              r_head = bolt_head_r,
                                              l_head = bolt_head_l,
                                              support=0,
                                              fc_normal = ntop_ax_n,
                                              pos=pos_bolt_back)
                else: # no head, just a cylinder:
                    shp_bolt_front = fcfun.shp_cylcenxtr (
                                              r = bolt_shank_r,
                                              h = base_h + extra,
                                              normal = ntop_ax_n,
                                              ch = 0,
                                              xtr_top=1, xtr_bot=1,
                                              pos = pos_bolt_front)
                    shp_bolt_back = fcfun.shp_cylcenxtr (
                                              r = bolt_shank_r,
                                              h = base_h + extra,
                                              normal = ntop_ax_n,
                                              ch = 0,
                                              xtr_top=1, xtr_bot=1,
                                              pos = pos_bolt_back)


                # fuse the bolts:
                shp_bolts = shp_bolt_front.fuse(shp_bolt_back)
                shp_base = shp_base.cut(shp_bolts)
            shp_clamp = shp_base.fuse(shp_clamp)

              
 

        doc.recompute()
        shp_clamp = shp_clamp.removeSplitter()
        self.shp = shp_clamp

        self.wfco = wfco
        if wfco == 1:
            # a freeCAD object is created
            fco_clamp = doc.addObject("Part::Feature", name )
            fco_clamp.Shape = shp_clamp
            self.fco = fco_clamp
    def __init__(self,
                 nema_size=17,
                 base_motor_d=6.,
                 base_d=4.,
                 base_h=16.,
                 wall_thick=4.,
                 motor_thick=4.,
                 reinf_thick=4.,
                 motor_min_h=10.,
                 motor_max_h=20.,
                 motor_xtr_space=2.,
                 bolt_wall_d=4.,
                 bolt1_wall_d=5.,
                 bolt_wall_sep=30.,
                 chmf_r=1.,
                 opt_sides=1,
                 axis_h=VZ,
                 axis_d=VX,
                 axis_w=None,
                 pos_h=1,
                 pos_d=3,
                 pos_w=0,
                 pos=V0,
                 name=''):
        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)  #vector product

        default_name = 'base'
        self.set_name(name, default_name, change=0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        self.motor_w = kcomp.NEMA_W[nema_size]
        self.motor_bolt_sep = kcomp.NEMA_BOLT_SEP[nema_size]
        self.motor_bolt_d = kcomp.NEMA_BOLT_D[nema_size]

        self.base_motor_h = motor_thick + motor_max_h + 2 * bolt_wall_d + 30.

        # calculation of the bolt to hold the base to the profile
        self.boltshank_r_tol = kcomp.D912[bolt1_wall_d]['shank_r_tol']
        self.bolthead_r = kcomp.D912[bolt1_wall_d]['head_l']
        self.bolthead_r_tol = kcomp.D912[bolt1_wall_d]['head_r']
        self.bolthead_l = kcomp.D912[bolt1_wall_d]['head_l']

        # calculation of the bolt wall d
        self.boltwallshank_r_tol = kcomp.D912[bolt_wall_d]['shank_r_tol']
        self.boltwallhead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.boltwallhead_r = kcomp.D912[bolt_wall_d]['head_r']
        self.washer_thick = kcomp.WASH_D125_T[bolt_wall_d]

        # calculation of the bolt wall separation
        self.max_bolt_wall_sep = self.motor_w - 2 * self.boltwallhead_r
        if bolt_wall_sep == 0:
            self.bolt_wall_sep = self.max_bolt_wall_sep
        elif bolt_wall_sep > self.max_bolt_wall_sep:
            logger.debug('bolt separation too large:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.max_bolt_wall_sep
            logger.debug('taking largest value:' + str(self.bolt_wall_sep))
        elif bolt_wall_sep < 4 * self.boltwallhead_r:
            logger.debug('bolt separation too short:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.self.max_bolt_wall_sep
            logger.debug('taking smallest value:' + str(self.bolt_wall_sep))

        # distance from the motor to the inner wall (in axis_d)
        self.motor_inwall_space = motor_xtr_space + self.boltwallhead_l + self.washer_thick

        # making the big box that will contain everything and will be cut
        self.tot_h = wall_thick + base_h + self.base_motor_h
        self.tot_d = base_d + 2 * self.bolthead_r
        if opt_sides == 0:
            self.tot_w = 2 * reinf_thick + self.motor_w + 2 * motor_xtr_space
        else:
            self.tot_w = 2 * reinf_thick + self.motor_w + 2 * motor_xtr_space + 4 * self.bolthead_r_tol + 8.

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.w0_cen = 1  # symmetrical
        self.d0_cen = 0

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(wall_thick)
        self.h_o[2] = self.vec_h(wall_thick + 2 * self.bolthead_r)
        self.h_o[3] = self.vec_h(wall_thick + base_h)
        self.h_o[4] = self.vec_h(wall_thick + base_h + motor_thick)
        self.h_o[5] = self.vec_h(wall_thick + base_h + motor_thick +
                                 motor_min_h)
        self.h_o[6] = self.vec_h(wall_thick + base_h + motor_thick)
        self.h_o[7] = self.vec_h(wall_thick + base_h + motor_thick +
                                 (motor_min_h + motor_max_h) / 4.)
        self.h_o[8] = self.vec_h(wall_thick + base_h + motor_thick + 2 *
                                 (motor_min_h + motor_max_h) / 4.)
        self.h_o[9] = self.vec_h(wall_thick + base_h + motor_thick + 3 *
                                 (motor_min_h + motor_max_h) / 4.)
        self.h_o[10] = self.vec_h(wall_thick + base_h + motor_thick +
                                  (motor_min_h + motor_max_h))
        self.h_o[11] = self.vec_h(wall_thick + base_h + motor_thick + 5 *
                                  (motor_min_h + motor_max_h) / 4.)
        self.h_o[12] = self.vec_h(wall_thick + base_h + motor_thick +
                                  motor_max_h)
        self.h_o[13] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(base_d)
        self.d_o[2] = self.vec_d(base_motor_d)
        self.d_o[3] = self.vec_d(self.tot_d / 2.)
        self.d_o[4] = self.vec_d(base_d + self.bolthead_r_tol)
        self.d_o[5] = self.vec_d(self.tot_d)

        # vectors from the origin to the points along axis_w
        if opt_sides == 0:
            self.w_o[0] = V0
            self.w_o[1] = self.vec_w(-self.bolt_wall_sep / 2.)
            self.w_o[2] = self.vec_w(-self.motor_bolt_sep / 2.)
            self.w_o[3] = self.vec_w(-self.tot_w / 2.)
        else:
            self.w_o[0] = V0
            self.w_o[1] = self.vec_w(-self.bolt_wall_sep / 2.)
            self.w_o[2] = self.vec_w(-self.motor_bolt_sep / 2.)
            self.w_o[3] = self.vec_w(
                -(2 * reinf_thick + self.motor_w + 2 * motor_xtr_space) / 2.)
            self.w_o[4] = self.vec_w(
                -(2 * reinf_thick + self.motor_w + 2 * motor_xtr_space +
                  2 * self.bolthead_r_tol + 4.) / 2.)
            self.w_o[5] = self.vec_w(-self.tot_w / 2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box
        if opt_sides == 0:
            shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=self.tot_h,
                                        fc_axis_h=self.axis_h,
                                        fc_axis_d=self.axis_d,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.pos_o)
            super().add_child(shp_box, 1, 'shp_box')

            shp_box_int = fcfun.shp_box_dir(box_w=self.tot_w,
                                            box_d=self.tot_d,
                                            box_h=base_h,
                                            fc_axis_h=self.axis_h,
                                            fc_axis_d=self.axis_d,
                                            cw=1,
                                            cd=0,
                                            ch=0,
                                            pos=self.get_pos_dwh(1, 0, 1))
            super().add_child(shp_box_int, 0, 'shp_box_int')

            shp_box_ext = fcfun.shp_box_dir(box_w=self.tot_w,
                                            box_d=self.tot_d,
                                            box_h=self.base_motor_h,
                                            fc_axis_h=self.axis_h,
                                            fc_axis_d=self.axis_d,
                                            cw=1,
                                            cd=0,
                                            ch=0,
                                            pos=self.get_pos_dwh(2, 0, 3))
            super().add_child(shp_box_ext, 0, 'shp_box_ext')

            shp_box_init = fcfun.shp_box_dir(box_w=self.tot_w +
                                             2 * self.bolthead_r_tol,
                                             box_d=self.tot_d,
                                             box_h=wall_thick,
                                             fc_axis_h=self.axis_h,
                                             fc_axis_d=self.axis_d,
                                             cw=1,
                                             cd=0,
                                             ch=0,
                                             pos=self.get_pos_dwh(5, 0, 0))
            super().add_child(shp_box_init, 0, 'shp_box_init')

            # holes to hold the profile
            shp_hole1 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                            h=wall_thick,
                                            normal=self.axis_h,
                                            ch=0,
                                            xtr_top=1,
                                            xtr_bot=1,
                                            pos=self.get_pos_dwh(4, -2, 0))
            super().add_child(shp_hole1, 0, 'shp_hole1')
            shp_hole2 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                            h=wall_thick,
                                            normal=self.axis_h,
                                            ch=0,
                                            xtr_top=1,
                                            xtr_bot=1,
                                            pos=self.get_pos_dwh(4, 2, 0))
            super().add_child(shp_hole2, 0, 'shp_hole2')

            # holes to hold the Nema Motor Holder
            shp_cen_bolt1 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 6))
            super().add_child(shp_cen_bolt1, 0, 'shp_cen_bolt1')
            shp_cen_bolt2 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 6))
            super().add_child(shp_cen_bolt2, 0, 'shp_cen_bolt2')
            shp_cen_bolt3 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 7))
            super().add_child(shp_cen_bolt3, 0, 'shp_cen_bolt3')
            shp_cen_bolt4 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 7))
            super().add_child(shp_cen_bolt4, 0, 'shp_cen_bolt4')
            shp_cen_bolt5 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 8))
            super().add_child(shp_cen_bolt5, 0, 'shp_cen_bolt5')
            shp_cen_bolt6 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 8))
            super().add_child(shp_cen_bolt6, 0, 'shp_cen_bolt6')
            shp_cen_bolt7 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 9))
            super().add_child(shp_cen_bolt7, 0, 'shp_cen_bolt7')
            shp_cen_bolt8 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 9))
            super().add_child(shp_cen_bolt8, 0, 'shp_cen_bolt8')
            shp_cen_bolt9 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 10))
            super().add_child(shp_cen_bolt9, 0, 'shp_cen_bolt9')
            shp_cen_bolt10 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 10))
            super().add_child(shp_cen_bolt10, 0, 'shp_cen_bolt10')
            shp_cen_bolt11 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 11))
            super().add_child(shp_cen_bolt11, 0, 'shp_cen_bolt11')
            shp_cen_bolt12 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 11))
            super().add_child(shp_cen_bolt12, 0, 'shp_cen_bolt12')
        else:
            shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=self.tot_h,
                                        fc_axis_h=self.axis_h,
                                        fc_axis_d=self.axis_d,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.pos_o)
            super().add_child(shp_box, 1, 'shp_box')

            shp_box_int = fcfun.shp_box_dir(box_w=self.tot_w,
                                            box_d=self.tot_d,
                                            box_h=base_h,
                                            fc_axis_h=self.axis_h,
                                            fc_axis_d=self.axis_d,
                                            cw=1,
                                            cd=0,
                                            ch=0,
                                            pos=self.get_pos_dwh(1, 0, 1))
            super().add_child(shp_box_int, 0, 'shp_box_int')

            shp_box_ext = fcfun.shp_box_dir(box_w=self.tot_w,
                                            box_d=self.tot_d,
                                            box_h=self.base_motor_h,
                                            fc_axis_h=self.axis_h,
                                            fc_axis_d=self.axis_d,
                                            cw=1,
                                            cd=0,
                                            ch=0,
                                            pos=self.get_pos_dwh(2, 0, 3))
            super().add_child(shp_box_ext, 0, 'shp_box_ext')

            shp_box_init = fcfun.shp_box_dir(box_w=self.tot_w,
                                             box_d=self.tot_d,
                                             box_h=wall_thick,
                                             fc_axis_h=self.axis_h,
                                             fc_axis_d=self.axis_d,
                                             cw=1,
                                             cd=0,
                                             ch=0,
                                             pos=self.get_pos_dwh(5, 0, 0))
            super().add_child(shp_box_init, 0, 'shp_box_init')

            shp_box_lat1 = fcfun.shp_box_dir(box_w=2 * +self.bolthead_r_tol +
                                             4.,
                                             box_d=self.tot_d,
                                             box_h=self.tot_h,
                                             fc_axis_h=self.axis_h,
                                             fc_axis_d=self.axis_d,
                                             cw=1,
                                             cd=0,
                                             ch=0,
                                             pos=self.get_pos_dwh(0, -4, 1))
            super().add_child(shp_box_lat1, 0, 'shp_box_lat1')
            shp_box_lat2 = fcfun.shp_box_dir(box_w=2 * +self.bolthead_r_tol +
                                             4.,
                                             box_d=self.tot_d,
                                             box_h=self.tot_h,
                                             fc_axis_h=self.axis_h,
                                             fc_axis_d=self.axis_d,
                                             cw=1,
                                             cd=0,
                                             ch=0,
                                             pos=self.get_pos_dwh(0, 4, 1))
            super().add_child(shp_box_lat2, 0, 'shp_box_lat2')

            # holes to hold the profile # self.get_d_ab(5,4).x
            shp_hole1 = fcfun.shp_stadium_dir(
                self.tot_d - 2 * ((self.d_o[5] - self.d_o[4]).Length),
                radius=self.boltshank_r_tol,
                height=wall_thick,
                fc_axis_h=self.axis_h,
                fc_axis_l=self.axis_d.negative(),
                fc_axis_s=V0,
                ref_l=2,
                ref_s=1,
                ref_h=2,
                xtr_nh=1,
                pos=self.get_pos_dwh(4, -4, 0))
            super().add_child(shp_hole1, 0, 'shp_hole1')

            shp_hole2 = fcfun.shp_stadium_dir(
                self.tot_d - 2 * ((self.d_o[5] - self.d_o[4]).Length),
                radius=self.boltshank_r_tol,
                height=wall_thick,
                fc_axis_h=self.axis_h,
                fc_axis_l=self.axis_d.negative(),
                fc_axis_s=V0,
                ref_l=2,
                ref_s=1,
                ref_h=2,
                xtr_nh=1,
                pos=self.get_pos_dwh(4, 4, 0))
            super().add_child(shp_hole2, 0, 'shp_hole2')

            shp_hole3 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                            h=wall_thick,
                                            normal=self.axis_h,
                                            ch=0,
                                            xtr_top=1,
                                            xtr_bot=1,
                                            pos=self.get_pos_dwh(4, -2, 0))
            super().add_child(shp_hole3, 0, 'shp_hole3')
            shp_hole4 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                            h=wall_thick,
                                            normal=self.axis_h,
                                            ch=0,
                                            xtr_top=1,
                                            xtr_bot=1,
                                            pos=self.get_pos_dwh(4, 2, 0))
            super().add_child(shp_hole4, 0, 'shp_hole4')

            # holes to hold the Nema Motor Holder
            shp_cen_bolt1 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 6))
            super().add_child(shp_cen_bolt1, 0, 'shp_cen_bolt1')
            shp_cen_bolt2 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 6))
            super().add_child(shp_cen_bolt2, 0, 'shp_cen_bolt2')
            shp_cen_bolt3 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 7))
            super().add_child(shp_cen_bolt3, 0, 'shp_cen_bolt3')
            shp_cen_bolt4 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 7))
            super().add_child(shp_cen_bolt4, 0, 'shp_cen_bolt4')
            shp_cen_bolt5 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 8))
            super().add_child(shp_cen_bolt5, 0, 'shp_cen_bolt5')
            shp_cen_bolt6 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 8))
            super().add_child(shp_cen_bolt6, 0, 'shp_cen_bolt6')
            shp_cen_bolt7 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 9))
            super().add_child(shp_cen_bolt7, 0, 'shp_cen_bolt7')
            shp_cen_bolt8 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 9))
            super().add_child(shp_cen_bolt8, 0, 'shp_cen_bolt8')
            shp_cen_bolt9 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 10))
            super().add_child(shp_cen_bolt9, 0, 'shp_cen_bolt9')
            shp_cen_bolt10 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 10))
            super().add_child(shp_cen_bolt10, 0, 'shp_cen_bolt10')
            shp_cen_bolt11 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, -1, 11))
            super().add_child(shp_cen_bolt11, 0, 'shp_cen_bolt11')
            shp_cen_bolt12 = fcfun.shp_bolt_dir(
                r_shank=self.boltwallshank_r_tol,
                l_bolt=base_motor_d,
                r_head=self.boltwallhead_r,
                l_head=self.boltwallhead_l,
                xtr_head=1,
                xtr_shank=1,
                fc_normal=self.axis_d,
                pos_n=0,
                pos=self.get_pos_dwh(0, 1, 11))
            super().add_child(shp_cen_bolt12, 0, 'shp_cen_bolt12')

        super().make_parent(name)
        chmf_reinf_r = min(base_motor_d - base_d, base_h)
        self.shp = fcfun.shp_filletchamfer_dirpt(self.shp,
                                                 self.axis_w,
                                                 fc_pt=self.get_pos_dwh(
                                                     2, 0, 3),
                                                 fillet=0,
                                                 radius=(chmf_reinf_r - TOL))
        if opt_sides == 0:
            for pt_w in (-3, 3):
                for pt_h in (0, 13):
                    self.shp = fcfun.shp_filletchamfer_dirpt(
                        self.shp,
                        self.axis_d,
                        fc_pt=self.get_pos_dwh(0, pt_w, pt_h),
                        fillet=1,
                        radius=chmf_r)
                self.shp = fcfun.shp_filletchamfer_dirpt(
                    self.shp,
                    self.axis_d,
                    fc_pt=self.get_pos_dwh(5, pt_w, 1),
                    fillet=1,
                    radius=chmf_r)
        else:
            for pt_w in (-5, 5):
                for pt_h in (0, 1):
                    self.shp = fcfun.shp_filletchamfer_dirpt(
                        self.shp,
                        self.axis_d,
                        fc_pt=self.get_pos_dwh(0, pt_w, pt_h),
                        fillet=1,
                        radius=chmf_r)
            for pt_w in (-3, 3):
                for pt_h in (1, 13):
                    self.shp = fcfun.shp_filletchamfer_dirpt(
                        self.shp,
                        self.axis_d,
                        fc_pt=self.get_pos_dwh(0, pt_w, pt_h),
                        fillet=1,
                        radius=chmf_r)

        fuse = []
        fuse.append(self.shp)
        shp_box_ref = fcfun.shp_box_dir(box_w=2 * self.bolthead_r,
                                        box_d=2 * self.bolthead_r,
                                        box_h=2 * self.bolthead_r,
                                        fc_axis_w=self.axis_w,
                                        fc_axis_h=self.axis_h,
                                        fc_axis_d=self.axis_d,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.get_pos_dwh(1, 0, 1))
        shp_box_ref = fcfun.shp_filletchamfer_dirpt(
            shp_box_ref,
            self.axis_w,
            fc_pt=self.get_pos_dwh(5, 0, 2),
            fillet=0,
            radius=2 * self.bolthead_r - TOL)
        fuse.append(shp_box_ref)
        shp_final = fcfun.fuseshplist(fuse)
        self.shp = shp_final

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
예제 #3
0
    def __init__(
            self,
            filter_l=60.,
            filter_w=25.,
            filter_t=2.5,
            base_h=6.,
            hold_d=10.,
            filt_supp_in=2.,
            filt_rim=3.,
            filt_cen_d=0,
            fillet_r=1.,
            # linear guides SEBLV16 y SEBS15, y MGN12H:
            boltcol1_dist=20 / 2.,
            boltcol2_dist=12.5,  #thorlabs breadboard distance
            boltcol3_dist=25,
            boltrow1_h=0,
            boltrow1_2_dist=12.5,
            # linear guide MGN12H
            boltrow1_3_dist=20.,
            # linear guide SEBLV16 and SEBS15
            boltrow1_4_dist=25.,
            bolt_cen_mtr=4,
            bolt_linguide_mtr=3,  # linear guide bolts
            beltclamp_t=3.,  #2.8,
            beltclamp_l=12.,
            beltclamp_h=8.,
            clamp_post_dist=4.,
            sm_beltpost_r=1.,
            tol=kcomp.TOL,
            axis_d=VX,
            axis_w=VY,
            axis_h=VZ,
            pos_d=0,
            pos_w=0,
            pos_h=0,
            pos=V0):

        shp_clss.Obj3D.__init__(self, axis_d, axis_w, axis_h)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        # calculation of the dimensions:
        # hole for the filter, including tolerances:
        # Note that now the dimensions width and length are changed.
        # to depth and width
        # they are relative to the holder, not to the filter
        # no need to have the tolerances here:
        self.filt_hole_d = filter_w  # + tol # depth
        self.filt_hole_w = filter_l  # + tol # width in holder axis
        self.filt_hole_h = filter_t  # + tol/2. # 0.5 tolerance for height

        # The hole under the filter to let the light go through
        # and big enough to hold the filter
        # we could take filter_hole dimensions or filter dimensiones
        # just the tolerance difference
        self.filt_supp_d = self.filt_hole_d - 2 * filt_supp_in
        self.filt_supp_w = self.filt_hole_w - 2 * filt_supp_in

        # look for the largest bolt head in the first row:
        # dictionary of the center bolt and 2nd and 3rd column
        self.bolt_cen_dict = kcomp.D912[bolt_cen_mtr]
        self.bolt_cen_head_r_tol = self.bolt_cen_dict['head_r_tol']
        self.bolt_cen_r_tol = self.bolt_cen_dict['shank_r_tol']
        self.bolt_cen_head_l_tol = self.bolt_cen_dict['head_l_tol']

        # dictionary of the 1st column bolts (for the linear guide)
        self.bolt_linguide_dict = kcomp.D912[bolt_linguide_mtr]
        self.bolt_linguide_head_r_tol = self.bolt_linguide_dict['head_r_tol']
        self.bolt_linguide_r_tol = self.bolt_linguide_dict['shank_r_tol']
        self.bolt_linguide_head_l_tol = self.bolt_linguide_dict['head_l_tol']

        max_row1_head_r_tol = max(self.bolt_linguide_head_r_tol,
                                  self.bolt_cen_head_r_tol)

        if boltrow1_h == 0:
            self.boltrow1_h = 2 * max_row1_head_r_tol
        elif boltrow1_h < 2 * max_row1_head_r_tol:
            self.boltrow1_h = 2 * max_row1_head_r_tol
            msg1 = 'boltrow1_h smaller than bolt head diameter'
            msg2 = 'boltrow1_h will be bolt head diameter'
            logger.warning(msg1 + msg2 + str(self.boltrow1_h))
        # else # it will be as it is

        self.hold_h = (base_h + self.boltrow1_h + boltrow1_4_dist +
                       2 * self.bolt_linguide_head_r_tol)
        self.tot_h = self.hold_h + beltclamp_h

        self.beltclamp_blk_t = (hold_d - beltclamp_t) / 2.

        #self.clamp2cenpost = clamp_post_dist + s_beltclamp_r_sm

        # the large radius of the belt post
        self.lr_beltpost_r = (hold_d - 3) / 2.

        min_filt_cen_d = hold_d + filt_rim + filter_w / 2.
        if filt_cen_d == 0:
            filt_cen_d = hold_d + filt_rim + filter_w / 2.
        elif filt_cen_d < min_filt_cen_d:
            filt_cen_d = hold_d + filt_rim + filter_w / 2.
            msg = 'filt_cen_d is smaller than needed, taking: '
            logger.warning(msg + str(filt_cen_d))
        self.filt_cen_d = filt_cen_d

        self.tot_d = self.filt_cen_d + filter_w / 2. + filt_rim

        # find out if the max width if given by the filter or the holder
        base_w = filter_l + 2 * filt_rim
        hold_w = 2 * boltcol3_dist + 4 * self.bolt_cen_head_r_tol
        self.tot_w = max(base_w, hold_w)

        self.beltpost_l = (3 * self.lr_beltpost_r) + sm_beltpost_r
        self.clamp_lrbeltpostcen_dist = (self.beltpost_l - self.lr_beltpost_r +
                                         self.clamp_post_dist)

        self.d0_cen = 0
        self.w0_cen = 1  # symmetrical
        self.h0_cen = 0

        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(self.beltclamp_blk_t)
        self.d_o[2] = self.vec_d(hold_d / 2.)
        self.d_o[3] = self.vec_d(hold_d - self.beltclamp_blk_t)
        # at the beginning of the bolt head hole for the central bolt
        self.d_o[4] = self.vec_d(hold_d - self.bolt_cen_head_l_tol)
        self.d_o[5] = self.vec_d(hold_d - self.bolt_linguide_head_l_tol)
        self.d_o[6] = self.vec_d(hold_d)
        # at the beginning of the hole of the porta (no tolerance):
        self.d_o[7] = self.vec_d(self.filt_cen_d - filter_w / 2.)
        # inner side of porta thruhole
        self.d_o[8] = self.d_o[7] + self.vec_d(filt_supp_in)
        # at the center of the porta:
        self.d_o[9] = self.vec_d(self.filt_cen_d)
        # outer side of porta thruhole
        self.d_o[10] = self.vec_d(self.filt_cen_d + filter_w / 2. -
                                  filt_supp_in)
        # at the end of the hole of the porta (no tolerance):
        self.d_o[11] = self.vec_d(self.filt_cen_d + filter_w / 2.)
        self.d_o[12] = self.vec_d(self.tot_d)

        # these are negative because actually the pos_w indicates a negative
        # position along axis_w

        self.w_o[0] = V0
        #1: at the first bolt column
        self.w_o[1] = self.vec_w(-boltcol1_dist)
        #2: at the second bolt column
        self.w_o[2] = self.vec_w(-boltcol2_dist)
        #3: at the third bolt column
        self.w_o[3] = self.vec_w(-boltcol3_dist)

        #7: at the end of the piece
        self.w_o[7] = self.vec_w(-self.tot_w / 2.)
        #6: at the inner side of the clamp rails
        # add belt_clamp because  w_o are negative
        self.w_o[6] = self.w_o[7] + self.vec_w(beltclamp_l)
        #5: at the outer side of the clamp post (smaller circle)
        self.w_o[5] = self.w_o[6] + self.vec_w(clamp_post_dist)
        #4: at the inner side of the clamp post (larger circle)
        self.w_o[4] = self.w_o[5] + self.vec_w(self.beltpost_l)

        #0: at the bottom (base)
        self.h_o[0] = V0
        #1: at the base for the porta
        self.h_o[1] = self.vec_h(base_h - self.filt_hole_h)
        #2: at the top of the base
        self.h_o[2] = self.vec_h(base_h)
        #3: first row of bolts
        self.h_o[3] = self.vec_h(base_h + self.boltrow1_h)
        #4: second row of bolts
        self.h_o[4] = self.h_o[3] + self.vec_h(boltrow1_2_dist)
        #5: third row of bolts, taking self.h_o[3]
        self.h_o[5] = self.h_o[3] + self.vec_h(boltrow1_3_dist)
        #6: 4th row of bolts
        self.h_o[6] = self.h_o[3] + self.vec_h(boltrow1_4_dist)
        #7: at the base of the belt clamp
        self.h_o[7] = self.vec_h(self.hold_h)
        #8: at the middle of the belt clamp
        self.h_o[8] = self.vec_h(self.hold_h + self.beltclamp_h / 2.)
        #9: at the top of the piece
        self.h_o[9] = self.vec_h(self.tot_h)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # -------- building of the piece
        # the base
        shp_base = fcfun.shp_box_dir(box_w=self.tot_w,
                                     box_d=self.tot_d,
                                     box_h=base_h,
                                     fc_axis_w=self.axis_w,
                                     fc_axis_d=self.axis_d,
                                     fc_axis_h=self.axis_h,
                                     cw=1,
                                     cd=0,
                                     ch=0,
                                     pos=self.pos_o)

        shp_base = fcfun.shp_filletchamfer_dir(shp_base,
                                               self.axis_h,
                                               fillet=1,
                                               radius=fillet_r)
        shp_base = shp_base.removeSplitter()

        # the holder to attach to a linear guide

        shp_holder = fcfun.shp_boxdir_fillchmfplane(
            box_w=self.tot_w,
            box_d=hold_d,
            box_h=self.hold_h,
            axis_d=self.axis_d,
            axis_h=self.axis_h,
            cw=1,
            cd=0,
            ch=0,
            fillet=1,
            radius=fillet_r,
            plane_fill=self.axis_d.negative(),
            both_planes=0,
            edge_dir=self.axis_h,
            pos=self.pos_o)

        #shp_holder = fcfun.shp_box_dir (box_w = self.tot_w,
        #box_d = hold_d,
        #box_h = self.hold_h,
        #fc_axis_w = self.axis_w,
        #fc_axis_d = self.axis_d,
        #fc_axis_h = self.axis_h,
        #cw = 1, cd = 0, ch = 1,
        #pos = self.pos_o)
        #shp_base = fcfun.shp_filletchamfer_dir (shp_base, self.axis_h,
        #fillet = 1, radius = fillet_r)
        shp_base = shp_base.removeSplitter()

        shp_l = shp_base.fuse(shp_holder)
        shp_l = shp_l.removeSplitter()
        # pos (6,0,2): position at the corner of the L
        shp_l = fcfun.shp_filletchamfer_dirpt(shp_l,
                                              fc_axis=self.axis_w,
                                              fc_pt=self.get_pos_dwh(6, 0, 2),
                                              fillet=0,
                                              radius=fillet_r)
        shp_l = shp_l.removeSplitter()
        # now we have the L shape with its chamfers and fillets

        # ------------------- Holes for the filter
        # include tolerances, along nh: only half of it, along h= 1 to make
        # the cut
        # pos (9,0,1) position at the center of the porta, at its bottom
        shp_filter_hole = fcfun.shp_box_dir_xtr(box_w=self.filt_hole_w,
                                                box_d=self.filt_hole_d,
                                                box_h=self.filt_hole_h,
                                                fc_axis_h=self.axis_h,
                                                fc_axis_d=self.axis_d,
                                                cw=1,
                                                cd=1,
                                                ch=0,
                                                xtr_h=1,
                                                xtr_nh=tol / 2.,
                                                xtr_d=tol,
                                                xtr_nd=tol,
                                                xtr_w=tol,
                                                xtr_nw=tol,
                                                pos=self.get_pos_dwh(9, 0, 1))
        # pos (9,0,0) position at the center of the porta, at the bottom of the
        # piece
        # no extra on top because it will be fused with shp_filter_hole
        shp_filter_thruhole = fcfun.shp_box_dir_xtr(box_w=self.filt_supp_w,
                                                    box_d=self.filt_supp_d,
                                                    box_h=base_h,
                                                    fc_axis_h=self.axis_h,
                                                    fc_axis_d=self.axis_d,
                                                    cw=1,
                                                    cd=1,
                                                    ch=0,
                                                    xtr_h=0,
                                                    xtr_nh=1,
                                                    xtr_d=tol,
                                                    xtr_nd=tol,
                                                    xtr_w=tol,
                                                    xtr_nw=tol,
                                                    pos=self.get_pos_dwh(
                                                        9, 0, 0))
        shp_fuse_filter_hole = shp_filter_hole.fuse(shp_filter_thruhole)
        shp_l = shp_l.cut(shp_fuse_filter_hole)
        shp_l = shp_l.removeSplitter()
        # the L with the hole in the base is done

        # ---------------- Holes for the bolts

        bolt_list = []

        shp_cen_bolt = fcfun.shp_bolt_dir(
            r_shank=self.bolt_cen_r_tol,
            l_bolt=hold_d,
            r_head=self.bolt_cen_head_r_tol,
            l_head=self.bolt_cen_head_l_tol,
            xtr_head=1,
            xtr_shank=1,
            support=0,  #not at printing directi
            fc_normal=self.axis_d.negative(),
            pos_n=2,
            pos=self.get_pos_dwh(0, 0, 3))
        bolt_list.append(shp_cen_bolt)
        # the rest of the bolts come in pairs:
        for w_side in [-1, 1]:
            # the wider bolts (although can be smaller)
            for cen_col, cen_row in zip([2, 3], [4, 3]):
                boltpos = self.get_pos_dwh(0, w_side * cen_col, cen_row)
                shp_cen_bolt = fcfun.shp_bolt_dir(
                    r_shank=self.bolt_cen_r_tol,
                    l_bolt=hold_d,
                    r_head=self.bolt_cen_head_r_tol,
                    l_head=self.bolt_cen_head_l_tol,
                    xtr_head=1,
                    xtr_shank=1,
                    support=0,  #not at printing directi
                    fc_normal=self.axis_d.negative(),
                    pos_n=2,
                    pos=boltpos)
                bolt_list.append(shp_cen_bolt)
            # the smaller bolts (although can be larger). Linear guide
            # first row:
            boltpos = self.get_pos_dwh(0, w_side * 1, 3)
            shp_lin_bolt = fcfun.shp_bolt_dir(
                r_shank=self.bolt_linguide_r_tol,
                l_bolt=hold_d,
                r_head=self.bolt_linguide_head_r_tol,
                l_head=self.bolt_linguide_head_l_tol,
                xtr_head=1,
                xtr_shank=1,
                support=0,  #not at printing directi
                fc_normal=self.axis_d.negative(),
                pos_n=2,
                pos=boltpos)
            bolt_list.append(shp_lin_bolt)
            # 3rd and 4th row. Just 2 shanks and a stadium per side
            for linrow in [5, 6]:
                boltpos = self.get_pos_dwh(0, w_side * 1, linrow)
                shp_lin_shank = fcfun.shp_cylcenxtr(
                    r=self.bolt_linguide_r_tol,
                    h=hold_d,
                    normal=self.axis_d,
                    ch=0,
                    xtr_top=0,  #no need: stadium
                    xtr_bot=1,
                    pos=boltpos)
                bolt_list.append(shp_lin_shank)
            # the stadium for both bolts head (they are too close)
            stadpos = self.get_pos_dwh(6, w_side * 1, 5)
            shp_stad = fcfun.shp_stadium_dir(
                length=boltrow1_4_dist - boltrow1_3_dist,
                radius=self.bolt_linguide_head_r_tol,
                height=self.bolt_linguide_head_l_tol,
                fc_axis_h=self.axis_d.negative(),
                fc_axis_l=self.axis_h,
                ref_l=2,
                ref_h=2,
                xtr_h=0,
                xtr_nh=1,
                pos=stadpos)
            bolt_list.append(shp_stad)

        shp_bolts = fcfun.fuseshplist(bolt_list)
        shp_l = shp_l.cut(shp_bolts)

        # ---------------- Belt clamps
        # at both sides
        clamp_list = []
        for w_side in [-1, 1]:
            clamp_pos = self.get_pos_dwh(0, w_side * 7, 7)
            if w_side == 1:
                clamp_axis_w = self.axis_w.negative()
            else:
                clamp_axis_w = self.axis_w
            shp_clamp = fcfun.shp_box_dir_xtr(box_w=beltclamp_l,
                                              box_d=self.beltclamp_blk_t,
                                              box_h=beltclamp_h,
                                              fc_axis_h=self.axis_h,
                                              fc_axis_d=self.axis_d,
                                              fc_axis_w=clamp_axis_w,
                                              cw=0,
                                              cd=0,
                                              ch=0,
                                              xtr_nh=1,
                                              pos=clamp_pos)

            # fillet the corner
            shp_clamp = fcfun.shp_filletchamfer_dirpt(shp_clamp,
                                                      self.axis_h,
                                                      fc_pt=clamp_pos,
                                                      fillet=1,
                                                      radius=fillet_r)
            shp_clamp = shp_clamp.removeSplitter()
            clamp_list.append(shp_clamp)

            # the other clamp, with no fillet
            clamp_pos = self.get_pos_dwh(6, w_side * 7, 7)
            shp_clamp = fcfun.shp_box_dir_xtr(box_w=beltclamp_l,
                                              box_d=self.beltclamp_blk_t,
                                              box_h=beltclamp_h,
                                              fc_axis_h=self.axis_h,
                                              fc_axis_d=self.axis_d.negative(),
                                              fc_axis_w=clamp_axis_w,
                                              cw=0,
                                              cd=0,
                                              ch=0,
                                              xtr_nh=1,
                                              pos=clamp_pos)
            clamp_list.append(shp_clamp)

            # the belt post
            beltpost_pos = self.get_pos_dwh(2, w_side * 5, 7)
            shp_beltpost = fcfun.shp_belt_dir(center_sep=2 *
                                              self.lr_beltpost_r,
                                              rad1=sm_beltpost_r,
                                              rad2=self.lr_beltpost_r,
                                              height=beltclamp_h,
                                              fc_axis_h=self.axis_h,
                                              fc_axis_l=clamp_axis_w,
                                              ref_l=3,
                                              ref_h=2,
                                              xtr_h=0,
                                              xtr_nh=1,
                                              pos=beltpost_pos)

            clamp_list.append(shp_beltpost)
        shp_filterholder = shp_l.multiFuse(clamp_list)
        shp_filterholder = shp_filterholder.removeSplitter()
        #Part.show (shp_filterholder)

        self.shp = shp_filterholder
    def __init__(self,
                 nema_size=17,
                 base_motor_d=6.,
                 base_d=4.,
                 base_h=16.,
                 wall_thick=4.,
                 motor_thick=4.,
                 reinf_thick=4.,
                 motor_min_h=10.,
                 motor_max_h=20.,
                 motor_xtr_space=2.,
                 bolt_wall_d=4.,
                 bolt1_wall_d=5.,
                 bolt_wall_sep=30.,
                 chmf_r=1.,
                 axis_h=VZ,
                 axis_d=VX,
                 axis_w=None,
                 pos_h=1,
                 pos_d=3,
                 pos_w=0,
                 pos=V0,
                 name=''):
        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)  #vector product

        default_name = 'base'
        self.set_name(name, default_name, change=0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        self.motor_w = kcomp.NEMA_W[nema_size]
        self.motor_bolt_sep = kcomp.NEMA_BOLT_SEP[nema_size]
        self.motor_bolt_d = kcomp.NEMA_BOLT_D[nema_size]

        # calculation of the bolt to hold the base to the profile
        self.boltshank_r_tol = kcomp.D912[bolt1_wall_d]['shank_r_tol']
        self.bolthead_r = kcomp.D912[bolt1_wall_d]['head_l']
        self.bolthead_r_tol = kcomp.D912[bolt1_wall_d]['head_r']
        self.bolthead_l = kcomp.D912[bolt1_wall_d]['head_l']

        # calculation of the bolt wall d
        self.boltwallhead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.boltwallhead_r = kcomp.D912[bolt_wall_d]['head_r']
        self.washer_thick = kcomp.WASH_D125_T[bolt_wall_d]

        # calculation of the bolt wall separation
        self.max_bolt_wall_sep = self.motor_w - 2 * self.boltwallhead_r
        if bolt_wall_sep == 0:
            self.bolt_wall_sep = self.max_bolt_wall_sep
        elif bolt_wall_sep > self.max_bolt_wall_sep:
            logger.debug('bolt separation too large:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.max_bolt_wall_sep
            logger.debug('taking largest value:' + str(self.bolt_wall_sep))
        elif bolt_wall_sep < 4 * self.boltwallhead_r:
            logger.debug('bolt separation too short:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.self.max_bolt_wall_sep
            logger.debug('taking smallest value:' + str(self.bolt_wall_sep))

        # distance from the motor to the inner wall (in axis_d)
        self.motor_inwall_space = motor_xtr_space + self.boltwallhead_l + self.washer_thick

        # making the big box that will contain everything and will be cut
        self.tot_h = wall_thick + base_h + motor_thick + motor_max_h + 2 * bolt_wall_d
        self.tot_w = 2 * reinf_thick + self.motor_w + 2 * motor_xtr_space
        self.tot_d = base_motor_d + wall_thick + self.motor_w + self.motor_inwall_space

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.w0_cen = 1  # symmetrical
        self.d0_cen = 0

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(wall_thick)
        self.h_o[2] = self.vec_h(wall_thick + base_h)
        self.h_o[3] = self.vec_h(wall_thick + base_h + motor_thick)
        self.h_o[4] = self.vec_h(wall_thick + base_h + motor_thick +
                                 motor_min_h)
        self.h_o[5] = self.vec_h(wall_thick + base_h + motor_thick +
                                 motor_max_h)
        self.h_o[6] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(base_d)
        self.d_o[2] = self.vec_d(base_motor_d)
        self.d_o[3] = self.vec_d(base_d + self.bolthead_r_tol)
        self.d_o[4] = self.vec_d(base_d + 2 * self.bolthead_r)

        # vectors from the origin to the points along axis_w
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-self.bolt_wall_sep / 2.)
        self.w_o[2] = self.vec_w(-self.motor_bolt_sep / 2.)
        self.w_o[3] = self.vec_w(-self.tot_w / 2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box
        shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                    box_d=self.tot_d,
                                    box_h=self.tot_h,
                                    fc_axis_h=self.axis_h,
                                    fc_axis_d=self.axis_d,
                                    cw=1,
                                    cd=0,
                                    ch=0,
                                    pos=self.pos_o)
        super().add_child(shp_box, 1, 'shp_box')

        shp_box_int = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=base_h,
                                        fc_axis_h=self.axis_h,
                                        fc_axis_d=self.axis_d,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.get_pos_dwh(1, 0, 1))
        super().add_child(shp_box_int, 0, 'shp_box_int')

        shp_box_ext = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=motor_thick + motor_max_h +
                                        2 * bolt_wall_d,
                                        fc_axis_h=self.axis_h,
                                        fc_axis_d=self.axis_d,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.get_pos_dwh(2, 0, 2))
        super().add_child(shp_box_ext, 0, 'shp_box_ext')

        shp_box_init = fcfun.shp_box_dir(box_w=self.tot_w,
                                         box_d=self.tot_d,
                                         box_h=wall_thick,
                                         fc_axis_h=self.axis_h,
                                         fc_axis_d=self.axis_d,
                                         cw=1,
                                         cd=0,
                                         ch=0,
                                         pos=self.get_pos_dwh(4, 0, 0))
        super().add_child(shp_box_init, 0, 'shp_box_init')

        shp_hole1 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                        h=wall_thick,
                                        normal=self.axis_h,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(3, -2, 0))
        super().add_child(shp_hole1, 0, 'shp_hole1')

        shp_hole2 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                        h=wall_thick,
                                        normal=self.axis_h,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(3, 2, 0))
        super().add_child(shp_hole2, 0, 'shp_hole2')

        super().make_parent(name)
        chmf_reinf_r = min(base_motor_d - base_d, base_h)
        self.shp = fcfun.shp_filletchamfer_dirpt(self.shp,
                                                 self.axis_w,
                                                 fc_pt=self.get_pos_dwh(
                                                     2, 0, 2),
                                                 fillet=0,
                                                 radius=(chmf_reinf_r - TOL))

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
예제 #5
0
    def __init__(self,
                 nema_size=17,
                 base_l=32.,
                 shaft_l=20.,
                 shaft_r=0,
                 circle_r=11.,
                 circle_h=2.,
                 chmf_r=1,
                 rear_shaft_l=0,
                 bolt_depth=3.,
                 bolt_out=2.,
                 cut_extra=0,
                 axis_d=VX,
                 axis_w=None,
                 axis_h=VZ,
                 pos_d=0,
                 pos_w=0,
                 pos_h=0,
                 pos=V0,
                 name=None):

        if name == None:
            name = 'nema' + str(nema_size) + '_motor_l' + str(int(base_l))
        self.name = name

        if (axis_w is None) or (axis_w == V0):
            axis_w = axis_h.cross(axis_d)

        Obj3D.__init__(self, axis_d, axis_w, axis_h, name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.motor_w = kcomp.NEMA_W[nema_size]
        if shaft_r == 0:
            self.shaft_d = kcomp.NEMA_SHAFT_D[nema_size]
            self.shaft_r = self.shaft_d / 2.
            shaft_r = self.shaft_r

        self.shaft_l = shaft_l
        self.base_l = base_l
        self.rear_shaft_l = rear_shaft_l

        self.nemabolt_sep = kcomp.NEMA_BOLT_SEP[nema_size]

        nemabolt_d = kcomp.NEMA_BOLT_D[nema_size]
        self.nemabolt_d = nemabolt_d
        self.nemabolt_r = nemabolt_d / 2.
        mtol = kcomp.TOL - 0.1

        if circle_r == 0 or circle_h == 0:
            # No circle
            circle_r = 0
            circle_h = 0
            self.circle_r = 0
            self.circle_h = 0

        self.h0_cen = 0
        self.d0_cen = 1  # symmetrical
        self.w0_cen = 1  # symmetrical

        # vectors from the origin to the points along axis_h:
        self.h_o[0] = V0  # base of the shaft: origin
        self.h_o[1] = self.vec_h(self.circle_h)
        self.h_o[2] = self.vec_h(self.shaft_l)  #includes circle_h
        self.h_o[3] = self.vec_h(-bolt_depth)
        self.h_o[4] = self.vec_h(-self.base_l)
        self.h_o[5] = self.vec_h(-self.base_l - self.rear_shaft_l)

        # vectors from the origin to the points along axis_d:
        # these are negative because actually the pos_d indicates a negative
        # position along axis_d (this happens when it is symmetrical)
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(-self.shaft_r)
        self.d_o[2] = self.vec_d(-self.circle_r)
        self.d_o[3] = self.vec_d(-self.nemabolt_sep / 2.)
        self.d_o[4] = self.vec_d(-self.motor_w / 2.)

        # position along axis_w (similar to axis_d)
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-self.shaft_r)
        self.w_o[2] = self.vec_w(-self.circle_r)
        self.w_o[3] = self.vec_w(-self.nemabolt_sep / 2.)
        self.w_o[4] = self.vec_w(-self.motor_w / 2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # ---------- building of the piece ------------------

        # -------- base of the motor
        # if cut_extra, there will be extra at each side, since the piece
        # is built from the center of symmetry, it will be equally extended
        # on each side
        shp_base = fcfun.shp_box_dir(box_w=self.motor_w + 2 * cut_extra,
                                     box_d=self.motor_w + 2 * cut_extra,
                                     box_h=self.base_l,
                                     fc_axis_w=self.axis_w,
                                     fc_axis_d=self.axis_d,
                                     fc_axis_h=self.axis_h,
                                     cw=1,
                                     cd=1,
                                     ch=0,
                                     pos=self.get_pos_h(4))

        shp_base = fcfun.shp_filletchamfer_dir(shp_base,
                                               self.axis_h,
                                               fillet=0,
                                               radius=chmf_r)
        shp_base = shp_base.removeSplitter()

        fuse_list = []
        holes_list = []

        # --------- bolts (holes or extensions if cut_extra > 0)
        for pt_d in (-3, 3):
            for pt_w in (-3, 3):
                if cut_extra == 0:  # there will be holes for the bolts
                    # pos_h=3 is at the end of the hole for the bolts
                    bolt_pos = self.get_pos_dwh(pt_d, pt_w, 3)
                    shp_hole = fcfun.shp_cylcenxtr(r=self.nemabolt_r,
                                                   h=bolt_depth,
                                                   normal=self.axis_h,
                                                   ch=0,
                                                   xtr_top=1,
                                                   xtr_bot=0,
                                                   pos=bolt_pos)
                    holes_list.append(shp_hole)
                else:  # the bolts will protude to make holes in the shape to cut
                    # pos_h=0 is at the the base of the shaft
                    bolt_pos = self.get_pos_dwh(pt_d, pt_w, 0)
                    shp_hole = fcfun.shp_cylcenxtr(r=self.nemabolt_r,
                                                   h=bolt_out,
                                                   normal=self.axis_h,
                                                   ch=0,
                                                   xtr_top=0,
                                                   xtr_bot=1,
                                                   pos=bolt_pos)
                    fuse_list.append(shp_hole)

        if cut_extra == 0:
            shp_holes = fcfun.fuseshplist(holes_list)
            shp_base = shp_base.cut(shp_holes)
            shp_base = shp_base.removeSplitter()

        # -------- circle (flat cylinder) at the base of the shaft
        # could add cut_extra to circle_h or circle_r, but it can be
        # set in the arguments
        if circle_r > 0 and circle_h > 0:
            shp_circle = fcfun.shp_cylcenxtr(
                r=circle_r,
                h=circle_h,
                normal=self.axis_h,
                ch=0,  # not centered
                xtr_top=0,  # no extra at top
                xtr_bot=1,  # extra to fuse
                pos=self.pos_o)
            fuse_list.append(shp_circle)

        # ------- Shaft
        shp_shaft = fcfun.shp_cylcenxtr(
            r=self.shaft_r,
            h=self.shaft_l,
            normal=self.axis_h,
            ch=0,  # not centered
            xtr_top=0,  # no extra at top
            xtr_bot=1,  # extra to fuse
            # shaft length stats from the base
            # not from the circle
            pos=self.pos_o)
        fuse_list.append(shp_shaft)

        if rear_shaft_l > 0:
            shp_rearshaft = fcfun.shp_cylcenxtr(
                r=self.shaft_r,
                h=self.rear_shaft_l,
                normal=self.axis_h,
                ch=0,  # not centered
                xtr_top=1,  # to fuse
                xtr_bot=0,  # no extra at bottom
                pos=self.get_pos_h(5))

            fuse_list.append(shp_rearshaft)

        shp_motor = shp_base.multiFuse(fuse_list)
        shp_motor = shp_motor.removeSplitter()
        self.shp = shp_motor

        super().create_fco(self.name)

        # Save the arguments that have not been created yet
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.model_type = 1  # Dimensional model
    def __init__(self,
                 d_endstop,
                 rail_l = 15,
                 base_h = 5.,
                 h = 0,
                 holder_out = 2.,
                 #csunk = 1,
                 mbolt_d = 3.,
                 endstop_nut_dist = 0,
                 min_d = 0,
                 axis_d = VX,
                 axis_w = V0,
                 axis_h = VZ,
                 pos_d = 1,
                 pos_w = 1,
                 pos_h = 1,
                 pos = V0,
                 wfco = 1,
                 name = 'simple_enstop_holder'):

        self.pos = FreeCAD.Vector(0,0,0)
        self.position = pos

        self.wfco = wfco
        self.name = name
        self.base_h = base_h,

        # normalize the axis
        axis_h = DraftVecUtils.scaleTo(axis_h,1)
        axis_d = DraftVecUtils.scaleTo(axis_d,1)
        if axis_w == V0:
            axis_w = axis_h.cross(axis_d)
        else:
            axis_w = DraftVecUtils.scaleTo(axis_w,1)
        axis_h_n = axis_h.negative()
        axis_d_n = axis_d.negative()
        axis_w_n = axis_w.negative()    

        self.axis_h = axis_h
        self.axis_d = axis_d
        self.axis_w = axis_w

        self.d0_cen = 0
        self.w0_cen = 1 # centered
        self.h0_cen = 0

        self.pos_d = pos_d
        self.pos_w = pos_w
        self.pos_h = pos_h

        self.pos = pos

        Obj3D.__init__(self, axis_d, axis_w, axis_h, name)

        # best axis to print, to be pointing up:
        self.axis_print = axis_h

        self.d_endstop = d_endstop

        #                              :holder_out
        #      __:________:____________: :..................
        #     |   _________      |     |                   :
        #     |  (_________) ----| 0   |                   + tot_w
        #     |   _________  ----|     |-----> axis_d      :
        #     |  (_________) ----| 0   |                   :
        #     |__________________|_____|...................:
        #     :  :         : :   : :     :
        #     :  :..rail_l.: :   : :     :
        #     :  :         : :   :.:     :
        #     :bolthead_d  : :   : +estp_bolt_dist
        #                  : :   :       :
        #          bolthead_r:   :.......:
        #                    :      +estp_d
        #                    :           :
        #                    :.estp_tot_d:
        #     :...................._..:  :
        #         tot_d

        #      The width depend which side is larger
        #
        #                     ...... ______________________ ....
        #        mbolt_head_r ......|   ________     |     |    :
        #        mbolt_head_d ......|  (________) ---| 0   |    :
        #mbolt_head_d or more ......|   ________  ---|     |    + estp_w or more
        #        mbolt_head_d ......|  (________) ---| 0   |    :
        #        mbolt_head_r ......|________________|_____|....:


        #   it can have a second hole:
        #                             :  :estop_topbolt_dist
        #                                : holder_out
        #      __:________:______________: :..................
        #     |   _________      |       |                   :
        #     |  (_________) ----| 0  0  |                   + tot_w
        #     |   _________  ----|       |-----> axis_d      :
        #     |  (_________) ----| 0  0  |                   :
        #     |__________________|_______|...................:
        #     :  :     

        # mounting bolt data
        d_mbolt = kcomp.D912[int(mbolt_d)]  #dictionary of the mounting bolt
        #print(str(d_mbolt))
        mbolt_r_tol = d_mbolt['shank_r_tol']
        mbolt_head_r = d_mbolt['head_r']
        mbolt_head_r_tol = d_mbolt['head_r_tol']
        mbolt_head_l = d_mbolt['head_l']
        print (str(mbolt_head_l))
        # endstop data. change h->d, d->h, l->w
        estp_tot_d = d_endstop['HT']
        estp_d = d_endstop['H']
        estp_bolt_dist = d_endstop['BOLT_H']
        estp_bolt_sep = d_endstop['BOLT_SEP']
        estp_bolt_d = d_endstop['BOLT_D']  #diameter, not depth
        estp_w = d_endstop['L']

        # if there is a second bolt 
        if 'BOLT_TOP_H' in d_endstop:
           estop_2ndbolt_topdist = d_endstop['BOLT_TOP_H']
        else:
           estop_2ndbolt_topdist = 0

        # length of the pins:
        estp_pin_d  = estp_tot_d - estp_d
        if min_d == 0:
            tot_d = 3*mbolt_head_r + rail_l + estp_tot_d - holder_out
            # nut axis: (nut axis of the hexagon vertex
            hex_verx = axis_d
        else:
            # Taking the minimum lenght, very tight
            tot_d = (3*mbolt_head_r + rail_l + estp_d - holder_out
                     + estp_pin_d/2.)
            hex_verx = axis_w # less space

        # Total width is the largest value from:
        # - the width(length) of the endstop
        # - the rail width: 2 bolt head diameters, and 2 more: 1 diameter 
        #   between, and a radius to the end
        tot_w = max(estp_w, 8 * mbolt_head_r)
 
        if h== 0:
            tot_h = base_h + mbolt_head_l
        else:
            tot_h = base_h + mbolt_head_l
            if tot_h > h:
                logger.debug('h is smaller that it should, taking: ')
                logger.debug(str(tot_h))
            else:
                tot_h = h

        self.tot_h = tot_h
        self.tot_w = tot_w
        self.tot_d = tot_d

        if endstop_nut_dist == 0:
            endstop_nut_l =  kcomp.NUT_D934_L[estp_bolt_d]+TOL
        else:
            if endstop_nut_dist > tot_h -  kcomp.NUT_D934_L[estp_bolt_d]+TOL:
                logger.debug('endstop_nut_dist: ' + str(endstop_nut_dist)
                             + ' larger than total height - (nut length+tol): '
                             + str(tot_h) + ' - '
                             + str( kcomp.NUT_D934_L[estp_bolt_d] + TOL))
                endstop_nut_l =  kcomp.NUT_D934_L[estp_bolt_d]+TOL
            else:
                endstop_nut_l = tot_h - endstop_nut_dist
            
        # ------------ DISTANCES ON AXIS_D
        # ref_d points:          fc_axis_h
                               
        #  1___2______3_______4__.5.............     ref_h = 2
        #  | :..........:    : : |:.....       + h
        #  |__:________:_____:_:_|:.....base_h.:     ref_h = 1

        # the end it is not on the holder because of -holder_out
        # distance from 1 to 2 in axis_d
        
        # vectors from the origin to the points along axis_d:
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(2* mbolt_head_r)
        self.d_o[2] = self.vec_d(2* mbolt_head_r + rail_l)
        self.d_o[3] = self.vec_d((tot_d + holder_out) - (estp_d - estp_bolt_dist))
        self.d_o[4] = self.vec_d(tot_d + holder_out)
        if estop_2ndbolt_topdist > 0 :
            self.d_o[5] = self.vec_d(tot_d + holder_out - estop_2ndbolt_topdist)
        else:
            self.d_o[5] = self.d_o[3]

        # vectors from the origin to the points along axis_w:
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(estp_bolt_sep/2.)
        self.w_o[2] = self.vec_w(tot_w/2. - 2* mbolt_head_r)
        self.w_o[3] = self.vec_w(tot_w/2.)

        # vectors from the origin to the points along axis_h:
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(tot_h)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # TODO: clear this parts when points d_o, w_o, h_o
        dis_1_2_d = 2* mbolt_head_r # d_o[1]
        dis_1_3_d = dis_1_2_d + rail_l # d_o[2]
        #dis_2_3_d = rail_l
        dis_1_5_d = tot_d + holder_out # d_o[4]
        dis_1_4_d = dis_1_5_d - (estp_d - estp_bolt_dist) # d_o[3]
        # distances to the new point, that is the second bolt hole, if exists
        if estop_2ndbolt_topdist > 0 :
            dis_1_6_d = dis_1_5_d - estop_2ndbolt_topdist
        else:
            # same as 4: (to avoid errors) it will be the same hole
            dis_1_6_d = dis_1_4_d

        fc_1_2_d = self.d_o[1]
        fc_1_3_d = self.d_o[2]
        fc_1_4_d = self.d_o[3]
        fc_1_5_d = self.d_o[4]
        fc_1_6_d = self.d_o[5]
        # vector from the reference point to point 1 on axis_d
        if pos_d == 0: 
            refto_1_d = V0
        elif pos_d == 1:
            refto_1_d = fc_1_2_d.negative()
        elif pos_d == 2:
            refto_1_d = fc_1_3_d.negative()
        elif pos_d == 3:
            refto_1_d = fc_1_4_d.negative()
        elif pos_d == 4:
            refto_1_d = fc_1_5_d.negative()
        elif pos_d == 5:
            refto_1_d = fc_1_6_d.negative()
        else:
            logger.error('wrong reference point')

        # ------------ DISTANCES ON AXIS_W
        # ref_w points
        #                      fc_axis_w
        #  _____________________ :
        # |   ________     |    |:
        # |  (________) ---| 0  |:
        # 1   ________  ---|    |:-----> fc_axis_d.
        # 3  (________) ---| 2  |:
        # 4________________|____|:

        # distance from 1 to 2 on axis_w
        dis_1_2_w = estp_bolt_sep/2.
        dis_1_4_w = tot_w/2.
        dis_1_3_w = dis_1_4_w - 2* mbolt_head_r

        fc_1_2_w = self.w_o[1]
        fc_1_3_w = self.w_o[2]
        fc_1_4_w = self.w_o[3]
        # vector from the reference point to point 1 on axis_w
        if pos_w == 0: 
            refto_1_w = V0
        elif pos_w == 1:
            refto_1_w = fc_1_2_w.negative()
        elif pos_w == 2:
            refto_1_w = fc_1_3_w.negative()
        elif pos_w == 3:
            refto_1_w = fc_1_4_w.negative()
        else:
            logger.error('wrong reference point')

        # ------------ DISTANCES ON AXIS_H
        fc_1_2_h = DraftVecUtils.scale(axis_h, tot_h)
        fc_2_1_h = fc_1_2_h.negative()
        if pos_h == 0: 
            refto_2_h = self.h_o[1]
        elif pos_h == 1:
            refto_2_h = V0
        else:
            logger.error('wrong reference point')


        # Situation of the point on d=1, s=1, h=2
        #       ____________
        #      /
        #     * d1_w1_h2
        #    /____________
        #    |
        #
        # this is an absolute position
        # super().get_pos_dwh(pos_d,pos_w,pos_h)
        d1_w1_h2_pos = self.pos + refto_1_d + refto_1_w + refto_2_h
        d1_w1_h1_pos = d1_w1_h2_pos + fc_2_1_h


        # draw the box from this point d1 s1 h2
        shp_box = fcfun.shp_box_dir(box_w = tot_w,
                                    box_d = tot_d,
                                    box_h = tot_h,
                                    fc_axis_h = axis_h_n,
                                    fc_axis_d = axis_d,
                                    cw = 1, cd = 0, ch = 0,
                                    pos = d1_w1_h2_pos)

        shp_box = fcfun.shp_filletchamfer_dir(shp_box, fc_axis = axis_h,
                                              fillet=1,
                                              radius = 2)

        holes = []
        # holes for the endstop bolts, point: d4 w2 h1
        for fc_1_2_wi in [fc_1_2_w, fc_1_2_w.negative()]:
            pos_estpbolt = d1_w1_h1_pos + fc_1_4_d + fc_1_2_wi
            # hole with the nut hole
            shp_estpbolt = fcfun.shp_bolt_dir (
                             r_shank= (estp_bolt_d+TOL)/2.,
                             l_bolt = tot_h,
                           # 1 TOL didnt fit
                           r_head = (kcomp.NUT_D934_D[estp_bolt_d]+2*TOL)/2.,
                             l_head = endstop_nut_l,
                             hex_head = 1,
                             xtr_head = 1, xtr_shank = 1,
                             fc_normal = axis_h,
                             fc_verx1 = hex_verx,
                             pos = pos_estpbolt)
            holes.append(shp_estpbolt)
            # it can have a second hole
            if estop_2ndbolt_topdist >0:
                pos_estp_top_bolt =  d1_w1_h1_pos + fc_1_6_d + fc_1_2_wi
                # hole with the nut hole
                shp_estpbolt = fcfun.shp_bolt_dir (
                             r_shank= (estp_bolt_d+TOL)/2.,
                             l_bolt = tot_h,
                           # 1 TOL didnt fit
                           r_head = (kcomp.NUT_D934_D[estp_bolt_d]+2*TOL)/2.,
                             l_head = endstop_nut_l,
                             hex_head = 1,
                             xtr_head = 1, xtr_shank = 1,
                             fc_normal = axis_h,
                             fc_verx1 = hex_verx,
                             pos = pos_estp_top_bolt)
                holes.append(shp_estpbolt)



        # holes for the rails, point d2 w3 h2
        for fc_1_3_wi in [fc_1_3_w, fc_1_3_w.negative()]:
            #hole for the rails, use the function stadium
            rail_pos = d1_w1_h2_pos + fc_1_2_d + fc_1_3_wi
            shp_rail_sunk = fcfun.shp_stadium_dir (
                                  length = rail_l,
                                  radius = mbolt_head_r_tol,
                                  height = mbolt_head_l,
                                  fc_axis_l = axis_d,
                                  fc_axis_h = axis_h_n,
                                  ref_l = 2, #at the center of semicircle
                                  ref_s = 1, # symmetrical on the short side
                                  ref_h = 2,
                                  xtr_h = 0,
                                  xtr_nh = 1,
                                  pos = rail_pos)
            shp_rail = fcfun.shp_stadium_dir (
                                  length = rail_l,
                                  radius = mbolt_r_tol,
                                  height = tot_h,
                                  fc_axis_l = axis_d,
                                  fc_axis_h = axis_h_n,
                                  ref_l = 2,
                                  ref_s = 1,
                                  ref_h = 2,
                                  xtr_h = 1,
                                  xtr_nh = 0,
                                  pos = rail_pos)

                                  
                                  
            holes.append(shp_rail)
            holes.append(shp_rail_sunk)

        shp_holes = fcfun.fuseshplist(holes)
        shp_holder = shp_box.cut(shp_holes)
           
        self.shp = shp_holder

        if wfco == 1:
            super().create_fco()
            # Need to set first in (0,0,0) and after that set the real placement.
            # This enable to do rotations without any issue
            self.fco.Placement.Base = FreeCAD.Vector(0,0,0) 
            self.fco.Placement.Base = self.position
    def __init__(self,
                 nema_size=17,
                 base_motor_d=6.,
                 base_d=4.,
                 base_h=16.,
                 wall_thick=4.,
                 motor_thick=4.,
                 reinf_thick=4.,
                 motor_min_h=10.,
                 motor_max_h=20.,
                 motor_xtr_space=2.,
                 bolt_wall_d=4.,
                 bolt1_wall_d=5.,
                 bolt_wall_sep=30.,
                 rail=1,
                 chmf_r=1.,
                 axis_h=VZ,
                 axis_d=VX,
                 axis_w=None,
                 pos_h=1,
                 pos_d=3,
                 pos_w=0,
                 pos=V0,
                 name=''):
        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)  #vector product

        default_name = 'NemaMotorHolder'
        self.set_name(name, default_name, change=0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # save the arguments as attributes
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        self.motor_w = kcomp.NEMA_W[nema_size]
        self.motor_bolt_sep = kcomp.NEMA_BOLT_SEP[nema_size]
        self.motor_bolt_d = kcomp.NEMA_BOLT_D[nema_size]

        # calculation of the bolt wall d
        self.boltwallshank_r_tol = kcomp.D912[bolt_wall_d]['shank_r_tol']
        self.boltwallhead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.boltwallhead_r = kcomp.D912[bolt_wall_d]['head_r']
        self.washer_thick = kcomp.WASH_D125_T[bolt_wall_d]

        # calculation of the bolt wall separation
        self.max_bolt_wall_sep = self.motor_w - 2 * self.boltwallhead_r
        self.min_bolt_wall_sep = 4 * self.boltwallhead_r
        if bolt_wall_sep == 0:
            self.bolt_wall_sep = self.max_bolt_wall_sep
        elif bolt_wall_sep > self.max_bolt_wall_sep:
            logger.debug('bolt separation too large:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.max_bolt_wall_sep
            logger.debug('taking largest value:' + str(self.bolt_wall_sep))
        elif bolt_wall_sep < self.min_bolt_wall_sep:
            #elif bolt_wall_sep < 4 * self.boltwallhead_r:
            logger.debug('bolt separation too short:' + str(bolt_wall_sep))
            #self.bolt_wall_sep = self.self.max_bolt_wall_sep
            self.bolt_wall_sep = self.min_bolt_wall_sep
            logger.debug('taking smallest value:' + str(self.bolt_wall_sep))

        # distance from the motor to the inner wall (in axis_d)
        self.motor_inwall_space = motor_xtr_space + self.boltwallhead_l + self.washer_thick

        # making the big box that will contain everything and will be cut
        self.tot_h = motor_thick + motor_max_h + 2 * bolt_wall_d
        self.tot_w = 2 * reinf_thick + self.motor_w + 2 * motor_xtr_space
        self.tot_d = wall_thick + self.motor_w + self.motor_inwall_space

        # distance from the motor axis to the wall (in axis_d)
        self.motax2wall = wall_thick + self.motor_inwall_space + self.motor_w / 2.

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.w0_cen = 1  # symmetrical
        self.d0_cen = 0

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(motor_thick)
        self.h_o[2] = self.vec_h(motor_thick + motor_min_h)
        self.h_o[3] = self.vec_h(motor_thick + motor_max_h)
        self.h_o[4] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(wall_thick)
        self.d_o[2] = self.vec_d(self.motax2wall - self.motor_bolt_sep / 2.)
        self.d_o[3] = self.vec_d(self.motax2wall)
        self.d_o[4] = self.vec_d(self.motax2wall + self.motor_bolt_sep / 2.)
        self.d_o[5] = self.vec_d(self.tot_d)

        # vectors from the origin to the points along axis_w
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-self.bolt_wall_sep / 2.)
        self.w_o[2] = self.vec_w(-self.motor_bolt_sep / 2.)
        self.w_o[3] = self.vec_w(-self.tot_w / 2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box, extra height and depth to cut all the way back and down
        shp_box1 = fcfun.shp_box_dir(box_w=self.tot_w,
                                     box_d=self.tot_d,
                                     box_h=self.tot_h,
                                     fc_axis_h=self.axis_h,
                                     fc_axis_d=self.axis_d,
                                     cw=1,
                                     cd=0,
                                     ch=0,
                                     pos=self.pos_o)
        # little chamfer at the corners, if fillet there are some problems
        shp_box2 = fcfun.shp_filletchamfer_dir(shp_box1,
                                               self.axis_h,
                                               fillet=0,
                                               radius=chmf_r)
        # chamfer of the box to make a 'triangular' reinforcement
        chmf_reinf_r = min(self.tot_d - wall_thick, self.tot_h - motor_thick)
        shp_box3 = fcfun.shp_filletchamfer_dirpt(shp_box2,
                                                 self.axis_w,
                                                 fc_pt=self.get_pos_dwh(
                                                     5, 0, 4),
                                                 fillet=0,
                                                 radius=chmf_reinf_r)
        super().add_child(shp_box3, 1, 'shp_box3')

        # holes

        # the space for the motor
        shp_motor = fcfun.shp_box_dir(box_w=self.motor_w + 2 * motor_xtr_space,
                                      box_d=self.tot_d + chmf_r,
                                      box_h=self.tot_h,
                                      fc_axis_h=self.axis_h,
                                      fc_axis_d=self.axis_d,
                                      cw=1,
                                      cd=0,
                                      ch=0,
                                      pos=self.get_pos_dwh(1, 0, 1))
        shp_motor = fcfun.shp_filletchamfer_dir(shp_motor,
                                                self.axis_h,
                                                fillet=0,
                                                radius=chmf_r)
        super().add_child(shp_motor, 0, 'shp_motor')

        # central circle of the motor
        shp_hole1 = fcfun.shp_cylcenxtr(
            r=(self.motor_bolt_sep - self.motor_bolt_d) / 2.,
            h=motor_thick,
            normal=self.axis_h,
            ch=0,
            xtr_top=1,
            xtr_bot=1,
            pos=self.get_pos_d(3))
        super().add_child(shp_hole1, 0, 'shp_hole1')

        # motor bolt holes
        shp_hole2 = fcfun.shp_cylcenxtr(r=self.motor_bolt_d / 2. + TOL,
                                        h=motor_thick,
                                        normal=self.axis_h,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(2, -2, 0))
        super().add_child(shp_hole2, 0, 'shp_hole2')
        shp_hole3 = fcfun.shp_cylcenxtr(r=self.motor_bolt_d / 2. + TOL,
                                        h=motor_thick,
                                        normal=self.axis_h,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(2, 2, 0))
        super().add_child(shp_hole3, 0, 'shp_hole3')
        shp_hole4 = fcfun.shp_cylcenxtr(r=self.motor_bolt_d / 2. + TOL,
                                        h=motor_thick,
                                        normal=self.axis_h,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(4, -2, 0))
        super().add_child(shp_hole4, 0, 'shp_hole4')
        shp_hole5 = fcfun.shp_cylcenxtr(r=self.motor_bolt_d / 2. + TOL,
                                        h=motor_thick,
                                        normal=self.axis_h,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(4, 2, 0))
        super().add_child(shp_hole5, 0, 'shp_hole5')

        # rail holes
        if rail == 1:
            shp_hole6 = fcfun.shp_box_dir_xtr(box_w=2 *
                                              self.boltwallshank_r_tol,
                                              box_d=wall_thick,
                                              box_h=motor_max_h - motor_min_h,
                                              fc_axis_h=self.axis_h,
                                              fc_axis_d=self.axis_d,
                                              cw=1,
                                              cd=0,
                                              ch=0,
                                              xtr_d=1,
                                              xtr_nd=1,
                                              pos=self.get_pos_dwh(0, -1, 2))
            super().add_child(shp_hole6, 0, 'shp_hole6')
            shp_hole7 = fcfun.shp_box_dir_xtr(box_w=2 *
                                              self.boltwallshank_r_tol,
                                              box_d=wall_thick,
                                              box_h=motor_max_h - motor_min_h,
                                              fc_axis_h=self.axis_h,
                                              fc_axis_d=self.axis_d,
                                              cw=1,
                                              cd=0,
                                              ch=0,
                                              xtr_d=1,
                                              xtr_nd=1,
                                              pos=self.get_pos_dwh(0, 1, 2))
            super().add_child(shp_hole7, 0, 'shp_hole7')

            # hole for the ending of the rails (4 semicircles)
        shp_hole8 = fcfun.shp_cylcenxtr(r=self.boltwallshank_r_tol,
                                        h=wall_thick,
                                        normal=self.axis_d,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(0, -1, 2))
        super().add_child(shp_hole8, 0, 'shp_hole8')
        shp_hole9 = fcfun.shp_cylcenxtr(r=self.boltwallshank_r_tol,
                                        h=wall_thick,
                                        normal=self.axis_d,
                                        ch=0,
                                        xtr_top=1,
                                        xtr_bot=1,
                                        pos=self.get_pos_dwh(0, 1, 2))
        super().add_child(shp_hole9, 0, 'shp_hole9')
        shp_hole10 = fcfun.shp_cylcenxtr(r=self.boltwallshank_r_tol,
                                         h=wall_thick,
                                         normal=self.axis_d,
                                         ch=0,
                                         xtr_top=1,
                                         xtr_bot=1,
                                         pos=self.get_pos_dwh(0, -1, 3))
        super().add_child(shp_hole10, 0, 'shp_hole10')
        shp_hole11 = fcfun.shp_cylcenxtr(r=self.boltwallshank_r_tol,
                                         h=wall_thick,
                                         normal=self.axis_d,
                                         ch=0,
                                         xtr_top=1,
                                         xtr_bot=1,
                                         pos=self.get_pos_dwh(0, 1, 3))
        super().add_child(shp_hole11, 0, 'shp_hole11')

        super().make_parent(name)

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
예제 #8
0
    def __init__(self,
                 alusize_d=50.,
                 alusize_w=30.,
                 alusize_h=50.,
                 dist_alu=30.,
                 dist_hole=36.,
                 wall_thick=4.,
                 bolt_wall_d=5.,
                 chmf_r=1.,
                 axis_h=VZ,
                 axis_d=VX,
                 axis_w=None,
                 pos_h=1,
                 pos_d=3,
                 pos_w=0,
                 pos=V0,
                 name=''):
        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)  #vector product

        default_name = 'board'
        self.set_name(name, default_name, change=0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        # calculation of the bolt to hold the base to the profile
        self.boltshank_r_tol = kcomp.D912[bolt_wall_d]['shank_r_tol']
        self.bolthead_r = kcomp.D912[bolt_wall_d]['head_l']
        self.bolthead_r_tol = kcomp.D912[bolt_wall_d]['head_r']
        self.bolthead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.bolthead_l_tol = kcomp.D912[bolt_wall_d]['head_l_tol']

        # making the big box that will contain everything and will be cut
        self.tot_w = alusize_w + 4.5
        self.tot_h = wall_thick + alusize_h / 2.
        self.tot_d = 2 * alusize_d - 20. + dist_alu + 8.5

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.d0_cen = 0  # symmetrical
        self.w0_cen = 1  # symmetrical

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(wall_thick)
        self.h_o[2] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(alusize_d / 2. - 10. + 4.25)
        self.d_o[2] = self.vec_d(alusize_d - 10. + 4.25 + TOL)
        self.d_o[3] = self.vec_d(alusize_d - 10. + 4.25 + dist_alu / 2.)
        self.d_o[4] = self.vec_d(alusize_d - 10. + 4.25 + dist_alu - TOL)
        self.d_o[5] = self.vec_d(alusize_d - 10. + 4.25 + dist_alu +
                                 alusize_d / 2.)
        self.d_o[6] = self.vec_d(self.tot_d)

        # vectors from the origin to the points along axis_w
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-(dist_hole / 2.))
        self.w_o[2] = self.vec_w(-self.tot_w / 2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box
        shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                    box_d=self.tot_d,
                                    box_h=self.tot_h,
                                    fc_axis_d=self.axis_d,
                                    fc_axis_h=self.axis_h,
                                    cw=1,
                                    cd=0,
                                    ch=0,
                                    pos=self.pos_o)

        # make the shape of the piece
        cut = []
        cut_box1 = fcfun.shp_box_dir(box_w=self.tot_w,
                                     box_d=alusize_d - 10. + 4.25 + TOL,
                                     box_h=alusize_h,
                                     fc_axis_d=self.axis_d,
                                     fc_axis_h=self.axis_h,
                                     cw=1,
                                     cd=0,
                                     ch=0,
                                     pos=self.get_pos_dwh(0, 0, 1))
        cut.append(cut_box1)
        cut_box2 = fcfun.shp_box_dir(box_w=self.tot_w,
                                     box_d=alusize_d - 10. + 4.25 + TOL,
                                     box_h=alusize_h,
                                     fc_axis_d=self.axis_d,
                                     fc_axis_h=self.axis_h,
                                     cw=1,
                                     cd=0,
                                     ch=0,
                                     pos=self.get_pos_dwh(4, 0, 1))
        cut.append(cut_box2)

        # holes to hold the profile
        cut_hole1 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=wall_thick,
                                       r_head=self.bolthead_r_tol,
                                       l_head=wall_thick / 2.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h,
                                       pos_n=0,
                                       pos=self.get_pos_dwh(1, -1, 0))
        cut.append(cut_hole1)
        cut_hole2 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=wall_thick,
                                       r_head=self.bolthead_r_tol,
                                       l_head=wall_thick / 2.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h,
                                       pos_n=0,
                                       pos=self.get_pos_dwh(1, 1, 0))
        cut.append(cut_hole2)
        cut_hole3 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=wall_thick,
                                       r_head=self.bolthead_r_tol,
                                       l_head=wall_thick / 2.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h,
                                       pos_n=0,
                                       pos=self.get_pos_dwh(5, -1, 0))
        cut.append(cut_hole3)
        cut_hole4 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=wall_thick,
                                       r_head=self.bolthead_r_tol,
                                       l_head=wall_thick / 2.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h,
                                       pos_n=0,
                                       pos=self.get_pos_dwh(5, 1, 0))
        cut.append(cut_hole4)

        # holes to hold de screw
        hole1 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                   l_bolt=self.tot_h,
                                   r_head=self.bolthead_r_tol,
                                   l_head=13 * self.tot_h / 20.,
                                   xtr_head=1,
                                   xtr_shank=1,
                                   fc_normal=self.axis_h.negative(),
                                   pos_n=0,
                                   pos=self.get_pos_dwh(3, -1, 2))
        cut.append(hole1)
        hole2 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                   l_bolt=self.tot_h,
                                   r_head=self.bolthead_r_tol,
                                   l_head=13 * self.tot_h / 20.,
                                   xtr_head=1,
                                   xtr_shank=1,
                                   fc_normal=self.axis_h.negative(),
                                   pos_n=0,
                                   pos=self.get_pos_dwh(3, 1, 2))
        cut.append(hole2)

        shp_cut = fcfun.fuseshplist(cut)
        shp_fuse = shp_box.cut(shp_cut)
        for pt_d in (0, 2, 4, 6):
            for pt_w in (-2, 2):
                shp_fuse = fcfun.shp_filletchamfer_dirpt(
                    shp_fuse,
                    fc_axis=self.axis_h,
                    fc_pt=self.get_pos_dwh(pt_d, pt_w, 1),
                    fillet=1,
                    radius=chmf_r)
        self.shp = shp_fuse

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
    def __init__ (self,
                  nema_size = 17,
                  wall_thick = 4.,
                  motorside_thick = 4.,
                  reinf_thick = 4.,
                  motor_min_h =10.,
                  motor_max_h =20.,
                  rail = 1, # if there is a rail or not at the profile side
                  motor_xtr_space = 2., # counting on one side
                  bolt_wall_d = 4., # Metric of the wall bolts
                  bolt_wall_sep = 0, # optional
                  chmf_r = 1.,
                  axis_h = VZ,
                  axis_d = VX,
                  axis_w = None,
                  pos_h = 1,  # 1: inner wall of the motor side
                  pos_d = 3,  # 3: motor axis
                  pos_w = 0,  # 0: center of symmetry
                  pos = V0,
                  model_type = 3, #to be printed
                  name = None):

        self.pos = FreeCAD.Vector(0,0,0)
        self.position = pos

        if name == None:
            name = 'nema' + str(nema_size) + '_motorholder'

        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)

        NuevaClase.Obj3D.__init__(self, axis_d, axis_w, axis_h, name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self,i):
                setattr(self, i, values[i])

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        self.motor_w = kcomp.NEMA_W[nema_size]
        self.motor_bolt_sep = kcomp.NEMA_BOLT_SEP[nema_size]
        self.motor_bolt_d = kcomp.NEMA_BOLT_D[nema_size]

        self.boltwallshank_r_tol = kcomp.D912[bolt_wall_d]['shank_r_tol']
        self.boltwallhead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.boltwallhead_r = kcomp.D912[bolt_wall_d]['head_r']
        self.washer_thick = kcomp.WASH_D125_T[bolt_wall_d]

        # calculation of the bolt wall separation
        self.max_bolt_wall_sep = self.motor_w - 2 * self.boltwallhead_r
    
        if bolt_wall_sep == 0:
            self.bolt_wall_sep = self.max_bolt_wall_sep
        elif bolt_wall_sep > self.max_bolt_wall_sep:
            logger.debug('bolt wall separtion too large: ' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.max_bolt_wall_sep
            logger.debug('taking larges value: ' + str(self.bolt_wall_sep))
        elif bolt_wall_sep <  4 * self.boltwallhead_r:
            logger.debug('bolt wall separtion too short: ' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.max_bolt_wall_sep
            logger.debug('taking larges value: ' + str(self.bolt_wall_sep))
        # else: the given separation is good

        # distance from the motor to the inner wall (in axis_d)
        self.motor_inwall_space = (  motor_xtr_space
                                   + self.boltwallhead_l + self.washer_thick)
        # making the big box that will contain everything and will be cut
        self.tot_h = motorside_thick + motor_max_h + 2 * bolt_wall_d
        self.tot_w = 2* reinf_thick + self.motor_w + 2 * motor_xtr_space
        self.tot_d = (   wall_thick + self.motor_w + self.motor_inwall_space)
        # distance from the motor axis to the wall (in axis_d)
        self.motax2wall = wall_thick + self.motor_inwall_space + self.motor_w/2.

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.d0_cen = 0
        self.w0_cen = 1 # symmetrical

        # vectors from the origin to the points along axis_h:
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(motorside_thick)
        self.h_o[2] = self.vec_h(motorside_thick + motor_min_h)
        self.h_o[3] = self.vec_h(motorside_thick + motor_max_h)
        self.h_o[4] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(wall_thick) # inner wall
        # distance to the inner bolts of the motor
        self.d_o[2] = self.vec_d(self.motax2wall - self.motor_bolt_sep/2.)
        self.d_o[3] = self.vec_d(self.motax2wall)  # motor axis
        self.d_o[4] = self.vec_d(self.motax2wall + self.motor_bolt_sep/2.)
        self.d_o[5] = self.vec_d(self.tot_d)

        # vectors from the origin to the points along axis_w:
        # these are negative because actually the pos_w indicates a negative
        # position along axis_w (this happens when it is symmetrical)
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-self.bolt_wall_sep/2.)
        self.w_o[2] = self.vec_w(-self.motor_bolt_sep/2.)
        self.w_o[3] = self.vec_w(-self.tot_w/2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box, extra height and depth to cut all the way
        # back and down:
        shp_box = fcfun.shp_box_dir (box_w = self.tot_w,
                                     box_d = self.tot_d,
                                     box_h = self.tot_h,
                                     fc_axis_h = self.axis_h,
                                     fc_axis_d = self.axis_d,
                                     cw=1, cd=0, ch=0, pos = self.pos_o)
        # little chamfer at the corners, if fillet there are some problems
        shp_box = fcfun.shp_filletchamfer_dir(shp_box, self.axis_h,
                                              fillet=0,
                                              radius = chmf_r)
        shp_box = shp_box.removeSplitter()

        # chamfer of the box to make a 'triangular' reinforcement
        chmf_reinf_r = min(self.tot_d- wall_thick, self.tot_h-motorside_thick)
        # chamfer at the lower point (h=4), and the other end of d (d=5)
        shp_box = fcfun.shp_filletchamfer_dirpt(shp_box, self.axis_w,
                                              fc_pt =self.get_pos_dwh(5,0,4),
                                              fillet=0,
                                              radius = chmf_reinf_r)
        shp_box = shp_box.removeSplitter()

        # holes:
        holes = []
        # the space for the motor
        shp_motor = fcfun.shp_box_dir (
                                    box_w = self.motor_w + 2 * motor_xtr_space,
                                    box_d = self.tot_d + chmf_r,
                                    box_h = self.tot_h,
                                    fc_axis_h = self.axis_h,
                                    fc_axis_d = self.axis_d,
                                    cw=1, cd=0, ch=0,
                                    # at the inner walls
                                    pos = self.get_pos_dwh(1,0,1))

        shp_motor = fcfun.shp_filletchamfer_dir(shp_motor, fc_axis=self.axis_h,
                                                fillet=0, radius=chmf_r)
        holes.append(shp_motor)

        # central circle of the motor
        shp_hole = fcfun.shp_cylcenxtr(
                                 r=(self.motor_bolt_sep - self.motor_bolt_d)/2.,
                                 h = motorside_thick,
                                 normal = self.axis_h,
                                 ch = 0,
                                 xtr_top = 1,
                                 xtr_bot = 1,
                                 # position of the motor axis, at the top
                                 pos = self.get_pos_d(3))
        holes.append(shp_hole)

        # motor bolt holes
        for pt_d in (2,4):  # points of the motor holes along axis d
            for pt_w in (-2,2): # points of the motor holes along axis_w
                shp_hole = fcfun.shp_cylcenxtr( r = self.motor_bolt_d/2.+TOL,
                                            h = motorside_thick,
                                            normal = self.axis_h,
                                            ch = 0,
                                            xtr_top = 1,
                                            xtr_bot = 1,
                                            pos = self.get_pos_dwh(pt_d,pt_w,0))
                holes.append(shp_hole)
    
        # rail holes. To mount the motor holder to a profile or whatever
        for pt_w in (-1,1): # points of the holes to attach the holder
            # hole for the rails
            if rail == 1:
                shp_hole = fcfun.shp_box_dir_xtr(
                                       box_w = self.boltwallshank_r_tol * 2.,
                                       box_d = wall_thick,
                                       box_h = motor_max_h - motor_min_h,
                                       fc_axis_h = self.axis_h,
                                       fc_axis_d = self.axis_d,
                                       cw=1, cd=0, ch=0,
                                       xtr_d =1, xtr_nd=1, #to cut
                                       # h:2 the position on top of the rail
                                       pos = self.get_pos_dwh(0,pt_w,2))
                holes.append(shp_hole)
            # hole for the ending of the rails (4 semicircles)
            for pt_h in (2,3) : # both ends of the rail (along axis_h)
                shp_hole = fcfun.shp_cylcenxtr(
                                            r = self.boltwallshank_r_tol,
                                            h = wall_thick,
                                            normal = self.axis_d,
                                            ch = 0,
                                            xtr_top = 1,
                                            xtr_bot = 1,
                                            pos = self.get_pos_dwh(0,pt_w,pt_h))
                holes.append(shp_hole)

        shp_holes = fcfun.fuseshplist(holes)
        shp_motorholder = shp_box.cut(shp_holes)
        shp_bracket =shp_motorholder.removeSplitter()
        self.shp = shp_bracket
        super().create_fco()
        # Need to set first in (0,0,0) and after that set the real placement.
        # This enable to do rotations without any issue
        self.fco.Placement.Base = FreeCAD.Vector(0,0,0) 
        self.fco.Placement.Base = self.position
    def __init__(self, size,
                 fc_axis_h = VZ,
                 fc_axis_d = VX,
                 fc_axis_w = V0,
                 pos_h = 1,
                 pos_w = 1,
                 pos_d = 1,
                 pillow = 0, #make it the same height of a pillow block
                 pos = V0,
                 wfco = 1,
                 tol = 0.3,
                 name= "shaft_holder"):
        self.size = size
        self.wfco = wfco
        self.name = name

        self.pos = FreeCAD.Vector(0,0,0)
        self.position = pos

        self.tol = tol
        self.pos_h = pos_h
        self.pos_w = pos_w
        self.pos_d = pos_d

        doc = FreeCAD.ActiveDocument
        if pillow == 0:
            skdict = kcomp.SK.get(size)
        else:
            skdict = kcomp.PILLOW_SK.get(size)
        if skdict == None:
            logger.error("Sk size %d not supported", size)

        # normalize de axis
        axis_h = DraftVecUtils.scaleTo(fc_axis_h,1)
        axis_d = DraftVecUtils.scaleTo(fc_axis_d,1)
        if fc_axis_w == V0:
            axis_w = axis_h.cross(axis_d)
        else:
            axis_w = DraftVecUtils.scaleTo(fc_axis_w,1)

        axis_h_n = axis_h.negative()
        axis_d_n = axis_d.negative()
        axis_w_n = axis_w.negative()

        NuevaClase.Obj3D.__init__(self, axis_d, axis_w, axis_h, name = name)

        # Total height:
        sk_h = skdict['H']
        self.tot_h = sk_h
        # Total width (Y):
        sk_w = skdict['W']
        self.tot_w = sk_w
        # Total depth (x):
        sk_d = skdict['L']
        self.tot_d = sk_d
        # Base height
        sk_base_h = skdict['g']
        # center width
        sk_center_w = skdict['I']
        # Axis height:
        sk_axis_h = skdict['h']
        # self.axis_h = sk_axis_h
        # Mounting bolts separation
        sk_mbolt_sep = skdict['B']
    
        # tightening bolt with added tolerances:
        tbolt_d = skdict['tbolt']
        # Bolt's head radius
        tbolt_head_r = (self.holtol
                        * kcomp.D912_HEAD_D[skdict['tbolt']])/2.0
        # Bolt's head lenght
        tbolt_head_l = (self.holtol
                        * kcomp.D912_HEAD_L[skdict['tbolt']] )
        # Mounting bolt radius with added tolerance
        mbolt_r = self.holtol * skdict['mbolt']/2.


        self.d0_cen = 0 
        self.w0_cen = 1 # symmetric
        self.h0_cen = 0
        # vectors from the origin to the points along axis_d:
        self.d_o[0] = V0 # origin
        self.d_o[1] = self.vec_d(sk_d/2.)
        self.d_o[2] = self.vec_d(sk_d)
        
        # vectors from the origin to the points along axis_w:
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(sk_mbolt_sep/2)
        self.w_o[2] = self.vec_w(sk_w/2)

        # vectors from the origin to the points along axis_h:
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(sk_axis_h)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # TODO: See how to change this reference points
        if pos_h == 1:  # distance vectors on axis_h
            ref2rod_h = V0 # h_o[0]
            ref2base_h = DraftVecUtils.scale(axis_h, -sk_axis_h) # h_o[1]
        else:
            ref2rod_h = DraftVecUtils.scale(axis_h, sk_axis_h) # h_o[1]
            ref2base_h = V0 # h_o[0]
        if pos_w == 0:  # distance vectors on axis_w
            ref2cen_w = V0 # w_o[0]
            ref2bolt_w = DraftVecUtils.scale(axis_w, -sk_mbolt_sep/2.) # w_o[-1]
            ref2end_w = DraftVecUtils.scale(axis_w, -sk_w/2.) # w_o[2]
        elif pos_w == 1:
            ref2cen_w =  DraftVecUtils.scale(axis_w, sk_mbolt_sep/2.) # w_o[1]
            ref2bolt_w = V0 # w_o[0]
            ref2end_w = DraftVecUtils.scale(axis_w, -(sk_w-sk_mbolt_sep)/2.) # w_o[]
        else: # w_o == -1 at the end on the width dimension
            ref2cen_w =  DraftVecUtils.scale(axis_w, sk_w/2.) # w_o[2]
            ref2bolt_w = DraftVecUtils.scale(axis_w, (sk_w-sk_mbolt_sep)/2.) # w_o[]
        if pos_d == 1:  # distance vectors on axis_d
            ref2cen_d = V0 # d_o[0]
            ref2end_d = DraftVecUtils.scale(axis_d, -sk_d/2.) # d_o[1]
        else:
            ref2cen_d = DraftVecUtils.scale(axis_d, sk_d/2.) # d_o[1]
            ref2end_d = V0 # d_o[0]

        # TODO: Use the newe method:
        # super().get_pos_dwh(pos_d,pos_w,pos_h)
        basecen_pos = self.pos + ref2base_h + ref2cen_w + ref2cen_d
        # Making the tall box:
        shp_tall = fcfun.shp_box_dir (box_w = sk_center_w, 
                                  box_d = sk_d,
                                  box_h = sk_h,
                                  fc_axis_w = axis_w,
                                  fc_axis_h = axis_h,
                                  fc_axis_d = axis_d,
                                  cw = 1, cd= 1, ch=0, pos = basecen_pos)
        # Making the wide box:
        shp_wide = fcfun.shp_box_dir (box_w = sk_w, 
                                  box_d = sk_d,
                                  box_h = sk_base_h,
                                  fc_axis_w = axis_w,
                                  fc_axis_h = axis_h,
                                  fc_axis_d = axis_d,
                                  cw = 1, cd= 1, ch=0, pos = basecen_pos)
        shp_sk = shp_tall.fuse(shp_wide)
        doc.recompute()
        shp_sk = shp_sk.removeSplitter()

        
        holes = []

        # Shaft hole, 
        rodcen_pos = self.pos + ref2rod_h + ref2cen_w + ref2cen_d
        rod_hole = fcfun.shp_cylcenxtr(r= size/2. +self.tol,
                                         h = sk_d,
                                         normal = axis_d,
                                         ch = 1,
                                         xtr_top = 1,
                                         xtr_bot = 1,
                                         pos = rodcen_pos)
        holes.append(rod_hole)

        # the upper sepparation
        shp_topopen = fcfun.shp_box_dir_xtr (
                                  box_w = self.up_sep_dist, 
                                  box_d = sk_d,
                                  box_h = sk_h-sk_axis_h,
                                  fc_axis_w = axis_w,
                                  fc_axis_h = axis_h,
                                  fc_axis_d = axis_d,
                                  cw = 1, cd= 1, ch=0,
                                  xtr_h = 1, xtr_d = 1, xtr_nd = 1,
                                  pos = rodcen_pos)
        holes.append(shp_topopen)

        # Tightening bolt hole
        # tbolt_d is the diameter of the bolt: (M..) M4, ...
        # tbolt_head_r: is the radius of the tightening bolt's head
        # (including tolerance), which its bottom either
        #- is at the middle point between
        #  - A: the total height :sk_h
        #  - B: the top of the shaft hole: axis_h + size/2.
        #  - so the result will be (A + B)/2
        # tot_h - (axis_h + size/2.)
        #       _______..A........................
        #      |  ___  |.B.......+ rodtop2top_dist = sk_h - (axis_h + size/2.) 
        #      | /   \ |.......+ size/2.
        #      | \___/ |       :
        #    __|       |__     + axis_h
        #   |_____________|....:

        rodtop2top_dist = sk_h - (sk_axis_h + size/2.)
        tbolt_pos = (   rodcen_pos
                      + DraftVecUtils.scale(axis_w, sk_center_w/2.)
                      + DraftVecUtils.scale(axis_h, size/2.)
                      + DraftVecUtils.scale(axis_h, rodtop2top_dist/2.))
        shp_tbolt = fcfun.shp_bolt_dir(r_shank= tbolt_d/2.,
                                        l_bolt = sk_center_w,
                                        r_head = tbolt_head_r,
                                        l_head = tbolt_head_l,
                                        hex_head = 0,
                                        xtr_head = 1,
                                        xtr_shank = 1,
                                        support = 0,
                                        fc_normal = axis_w_n,
                                        fc_verx1 = axis_h,
                                        pos = tbolt_pos)
        holes.append(shp_tbolt)
 
        #Mounting bolts
        cen2mbolt_w = DraftVecUtils.scale(axis_w, sk_mbolt_sep/2.)
        for w_pos in [cen2mbolt_w.negative(), cen2mbolt_w]:
            mbolt_pos = basecen_pos + w_pos
            mbolt_hole = fcfun.shp_cylcenxtr(r= mbolt_r,
                                           h = sk_d,
                                           normal = axis_h,
                                           ch = 0,
                                           xtr_top = 1,
                                           xtr_bot = 1,
                                           pos = mbolt_pos)
            holes.append(mbolt_hole)
 

        shp_holes = fcfun.fuseshplist(holes)
        shp_sk = shp_sk.cut(shp_holes)
        self.shp = shp_sk

        if wfco == 1:
            super().create_fco()
            # Need to set first in (0,0,0) and after that set the real placement.
            # This enable to do rotations without any issue
            self.fco.Placement.Base = FreeCAD.Vector(0,0,0) 
            self.fco.Placement.Base = self.position
    def __init__ (self, block_dict, rail_dict,
                  axis_d = VX, axis_w = V0, axis_h = VZ,
                  pos_d = 0, pos_w = 0, pos_h = 0,
                  pos = V0,
                  model_type = 1, # dimensional model
                  name = None):

        self.pos = FreeCAD.Vector(0,0,0)
        self.position = pos

        if name == None:
            self.name = block_dict['name'] + '_block'

        if rail_dict is None:
            self.rail_h = 0
            self.rail_w = 0
        else:
            self.rail_h = rail_dict['rh']
            self.rail_w = rail_dict['rw']

        if (axis_w is None) or (axis_w == V0):
            axis_w = axis_h.cross(axis_d)

        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        self.block_d  = block_dict['bl']
        self.block_ds = block_dict['bls']
        self.block_w  = block_dict['bw']
        self.block_ws = block_dict['bws']
        self.block_h  = block_dict['bh']

        self.linguide_h = block_dict['lh']

        self.bolt_dsep = block_dict['boltlsep']
        self.bolt_wsep = block_dict['boltwsep']
        self.bolt_d    = block_dict['boltd']
        self.bolt_l    = block_dict['boltl']

        linguide_h = block_dict['lh']

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self,i):
                setattr(self, i, values[i])

        self.d0_cen = 1 # symmetric
        self.w0_cen = 1 # symmetric
        self.h0_cen = 0

        if self.bolt_l == 0: # thruhole
            self.bolt_l = self.block_h
            self.thruhole = 1
        else:
            self.thruhole = 0

        if self.rail_h == 0 or linguide_h == 0:
            self.rail_h = 0
            self.linguide_h = 0
            self.rail_ins_h = 0
            self.rail_bot_h = 0
        else:
            self.rail_ins_h = self.block_h - (self.linguide_h - self.rail_h)
            self.rail_bot_h = self.rail_h - self.rail_ins_h


        # vectors from the origin to the points along axis_d:
        self.d_o[0] = V0 # Origin (center symmetric)
        self.d_o[1] = self.vec_d(-self.bolt_dsep/2.)
        self.d_o[2] = self.vec_d(-self.block_ds/2.)
        self.d_o[3] = self.vec_d(-self.block_d/2.)
 
        # vectors from the origin to the points along axis_w:
        self.w_o[0] = V0 # Origin (center symmetric)
        self.w_o[1] = self.vec_w(-self.rail_w/2.)
        self.w_o[2] = self.vec_w(-self.bolt_wsep/2.)
        self.w_o[3] = self.vec_w(-self.block_ws/2.)
        self.w_o[4] = self.vec_w(-self.block_w/2.)
 
        # vectors from the origin to the points along axis_h:
        # could make more sense to have the origin at the top
        self.h_o[0] = V0 # Origin at the bottom
        self.h_o[1] = self.vec_h(self.rail_ins_h)
        self.h_o[2] = self.vec_h(self.block_h - self.bolt_l)
        self.h_o[3] = self.vec_h(self.block_h)
        self.h_o[4] = self.vec_h(-self.rail_bot_h)
 
        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # the main block
        shp_mblock = fcfun.shp_box_dir (box_w = self.block_w,
                                        box_d = self.block_ds,
                                        box_h = self.block_h,
                                        fc_axis_w = self.axis_w,
                                        fc_axis_d = self.axis_d,
                                        fc_axis_h = self.axis_h,
                                        cw = 1, cd = 1, ch = 0,
                                        pos = self.pos_o)

        # the extra block
        shp_exblock = fcfun.shp_box_dir (box_w = self.block_ws,
                                        box_d = self.block_d,
                                        box_h = self.block_h,
                                        fc_axis_w = self.axis_w,
                                        fc_axis_d = self.axis_d,
                                        fc_axis_h = self.axis_h,
                                        cw = 1, cd = 1, ch = 0,
                                        pos = self.pos_o)

        # fusion of these blocks
        shp_block = shp_mblock.fuse(shp_exblock)

        holes_list = []

        # rail hole:
        if self.rail_h > 0 and self.rail_w > 0:
            wire_rail = fcfun.wire_lgrail( rail_w = self.rail_w,
                                           rail_h = self.rail_h,
                                           axis_w = self.axis_w,
                                           axis_h = self.axis_h,
                                           pos_w = 0, pos_h = 0,
                                           pos = self.get_pos_h(4))

            face_rail = Part.Face(wire_rail)
            shp_rail = fcfun.shp_extrud_face (face = face_rail,
                                              length = self.block_d + 2,
                                              vec_extr_axis = self.axis_d,
                                              centered = 1)

            #Part.show(shp_rail)
            holes_list.append(shp_rail)

        # bolt holes:
        for d_i in (-1, 1): # positions of the holes along axis_d
            for w_i in (-2, 2): # positions of the holes along axis_w
                shp_bolt = fcfun.shp_cylcenxtr (
                                        r = self.bolt_d/2.,
                                        h = self.bolt_l,
                                        normal = axis_h,
                                        ch = 0,
                                        xtr_top = 1,
                                        xtr_bot = self.thruhole,
                                        pos = self.get_pos_dwh(d_i, w_i, 2))
                holes_list.append(shp_bolt)

        shp_holes = fcfun.fuseshplist(holes_list)
        shp_block = shp_block.cut(shp_holes)
        shp_block = shp_block.removeSplitter()

        self.shp = shp_block
        super().create_fco(self.name)
        # Need to set first in (0,0,0) and after that set the real placement.
        # This enable to do rotations without any issue
        self.fco.Placement.Base = FreeCAD.Vector(0,0,0) 
        self.fco.Placement.Base = self.position
예제 #12
0
def placa_con_tornillos_fun():
    # generamos una placa de dimensiones 100x100x10
    shp_placa = fcfun.shp_box_dir(box_w=100.,
                                  box_d=100.,
                                  box_h=10.,
                                  fc_axis_w=VX,
                                  fc_axis_d=VY,
                                  fc_axis_h=VZ,
                                  cw=0, cd=0, ch=0,
                                  pos=V0)

    # añadimos un tornillo en la posición 1x1x1
    shp_bolt1 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(10, 10, 0))

    # sustraemos la forma del primer tornillo de la placa
    shp_placa_1hole = shp_placa.cut(shp_bolt1)

    # añadimos un tornillo en la posición 9x1x1
    shp_bolt2 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(90, 10, 0))

    # sustraemos la forma del segundo tornillo de la placa
    shp_placa_2hole = shp_placa_1hole.cut(shp_bolt2)

    # añadimos un tornillo en la posición 9x9x1
    shp_bolt3 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(90, 90, 0))

    # sustraemos la forma del tercero tornillo de la placa
    shp_placa_3hole = shp_placa_2hole.cut(shp_bolt3)

    # añadimos un tornillo en la posición 1x9x1
    shp_bolt4 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(10, 90, 0))

    # sustraemos la forma del cuarto tornillo de la placa
    shp_placa_4hole = shp_placa_3hole.cut(shp_bolt4)

    # convertimos la placa con cuatro tornillos en objeto
    placa_4hole = FreeCAD.ActiveDocument.addObject("Part::Feature", "Placa_perforada")
    placa_4hole.Shape = shp_placa_4hole

    # generamos cuatro tornillos individualmente y los convertimos a objetos individualmente
    tornillo_1 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(10, 10, 10),
                                    model_type=0,
                                    name='bolt1')
    tornillo_2 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(90, 10, 10),
                                    model_type=0,
                                    name='bolt2')
    tornillo_3 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(90, 90, 10),
                                    model_type=0,
                                    name='bolt3')
    tornillo_4 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(10, 90, 10),
                                    model_type=0,
                                    name='bolt4')
    def __init__(self, xtr_lat = 5., xtr_holes = 8., h_bottom = 1., d_bottom = 2., h_rail = 2., h_base = 2., dist_holes = 49., wall_thick = 4., reinf_thick = 3., arduino_w = 53., arduino_d = 105., arduino_h = 5., sides = 10., bolt = 5., chmf_r = 1., axis_h = VZ, axis_d = VX, axis_w = None, pos_h = 1, pos_d = 3, pos_w = 0, pos = V0, name = ''):
        if axis_w is None or axis_w == V0:
           axis_w = axis_h.cross(axis_d) #vector product
        
        default_name = 'bottom_coverplate'
        self.set_name(name, default_name, change = 0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self,i):
                setattr(self, i, values[i])

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        # calculation of the bolt to hold the bottom coverplate to the wood
        self.boltshank_r_tol = kcomp.D912[bolt]['shank_r_tol']
        self.bolthead_r = kcomp.D912[bolt]['head_l']
        self.bolthead_r_tol = kcomp.D912[bolt]['head_r']
        self.bolthead_l = kcomp.D912[bolt]['head_l']

        # making the big box that will contain everything and will be cut
        self.tot_d =  2 * sides + arduino_d + d_bottom
        self.tot_w = arduino_w + 2 * wall_thick - 2. + 2 * xtr_holes
        self.tot_h = h_base + arduino_h + h_bottom

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.w0_cen = 1   # symmetrical 
        self.d0_cen = 0

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(h_base)
        self.h_o[2] = self.vec_h(h_base + arduino_h - h_rail)
        self.h_o[3] = self.vec_h(h_base + arduino_h)
        self.h_o[4] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(sides/2.)
        self.d_o[2] = self.vec_d(sides)
        self.d_o[3] = self.vec_d(sides + xtr_lat)
        self.d_o[4] = self.vec_d(sides + xtr_lat + xtr_holes/2.)
        self.d_o[5] = self.vec_d(sides + xtr_lat + xtr_holes)
        self.d_o[6] = self.vec_d(sides + arduino_d - 3. - xtr_holes)
        self.d_o[7] = self.vec_d(sides + arduino_d - 3. - xtr_lat)
        self.d_o[8] = self.vec_d(sides + arduino_d - 3. - xtr_holes/2)
        self.d_o[9] = self.vec_d(sides + arduino_d + d_bottom - xtr_holes)
        self.d_o[10] = self.vec_d(sides + arduino_d + d_bottom - xtr_holes/2)
        self.d_o[11] = self.vec_d(sides + arduino_d - 3.)
        self.d_o[12] = self.vec_d(sides + arduino_d)
        self.d_o[13] = self.vec_d(sides + arduino_d + d_bottom)
        self.d_o[14] = self.vec_d(sides + arduino_d + d_bottom + sides/2.)
        self.d_o[15] = self.vec_d(self.tot_d)

        # position along axis_w
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-(arduino_w - 2. - 2 * xtr_lat)/2.)
        self.w_o[2] = self.vec_w(-(arduino_w - 2.)/2.)
        self.w_o[3] = self.vec_w(-dist_holes/2.)
        self.w_o[4] = self.vec_w(-(arduino_w + 2 * wall_thick - 2.)/2.)
        self.w_o[5] = self.vec_w(-(arduino_w + 2 * wall_thick - 2. + xtr_holes)/2.)
        self.w_o[6] = self.vec_w(-self.tot_w/2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box
        shp_box = fcfun.shp_box_dir(box_w = self.tot_w, box_d = self.tot_d, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 1, cd = 0, ch = 0, pos = self.pos_o)

        cut = []

        for pt_d in (0, 11):
            shp_lat1 = fcfun.shp_box_dir(box_w = xtr_holes, box_d = sides + xtr_lat, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 0, cd = 0, ch = 0, pos = self.get_pos_dwh(pt_d, -4, 0))
            cut.append(shp_lat1)
            shp_lat2 = fcfun.shp_box_dir(box_w = - xtr_holes, box_d = sides + xtr_lat, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 0, cd = 0, ch = 0, pos = self.get_pos_dwh(pt_d, 4, 0))
            cut.append(shp_lat2)

        shp_cut = fcfun.fuseshplist(cut)
        shp_final = shp_box.cut(shp_cut)

        for pt_d in (0, 15):
            for pt_w in (-4, 4):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = chmf_r)

        cut = []

        for pt_d in (3, 6):
            shp_lat3 = fcfun.shp_box_dir(box_w = xtr_holes, box_d = xtr_holes, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 0, cd = 0, ch = 0, pos = self.get_pos_dwh(pt_d, -4, 1))
            cut.append(shp_lat3)
            shp_lat4 = fcfun.shp_box_dir(box_w = - xtr_holes, box_d = xtr_holes, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 0, cd = 0, ch = 0, pos = self.get_pos_dwh(pt_d, 4, 1))
            cut.append(shp_lat4)

        shp_cut = fcfun.fuseshplist(cut)
        shp_final = shp_final.cut(shp_cut)

        for pt_d in (3, 11):
            for pt_w in (-6, 6):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = chmf_r)

        cut = []

        shp_lat5 = fcfun.shp_box_dir(box_w = xtr_holes, box_d = self.tot_d - 2 * (sides + xtr_lat + xtr_holes), box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 0, cd = 0, ch = 0, pos = self.get_pos_dwh(5, -4, 0))
        cut.append(shp_lat5)
        shp_lat6 = fcfun.shp_box_dir(box_w = - xtr_holes, box_d = self.tot_d - 2 * (sides + xtr_lat + xtr_holes), box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 0, cd = 0, ch = 0, pos = self.get_pos_dwh(5, 4, 0))
        cut.append(shp_lat6)

        shp_cut = fcfun.fuseshplist(cut)
        shp_final = shp_final.cut(shp_cut)

        for pt_d in (5, 6):
            for pt_w in (-6, 6):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = chmf_r)

        cut = []

        for pt_d in (0, 13):
            shp_sides = fcfun.shp_box_dir(box_w = self.tot_w, box_d = sides, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 1, cd = 0, ch = 0, pos = self.get_pos_dwh(pt_d, 0, 1))
            cut.append(shp_sides)

        shp_intern = fcfun.shp_box_dir(box_w = arduino_w - 2., box_d = arduino_d - 3., box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 1, cd = 0, ch = 0, pos = self.get_pos_dwh(2, 0, 1))
        cut.append(shp_intern)

        shp_int = fcfun.shp_box_dir(box_w = arduino_w - 2., box_d = arduino_d, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 1, cd = 0, ch = 0, pos = self.get_pos_dwh(2, 0, 2))
        cut.append(shp_int)

        shp_rail = fcfun.shp_box_dir(box_w = arduino_w + 2 * TOL, box_d = arduino_d, box_h = h_rail, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 1, cd = 0, ch = 0, pos = self.get_pos_dwh(2, 0, 2))
        cut.append(shp_rail)

        trim_mat = fcfun.shp_box_dir(box_w = arduino_w - 2. - 2 * xtr_lat, box_d = arduino_d - 3. - 2 * xtr_lat, box_h = self.tot_h, fc_axis_h = axis_h, fc_axis_d = axis_d, cw = 1, cd = 0, ch = 0, pos = self.get_pos_dwh(3, 0, 0))
        cut.append(trim_mat)

        shp_cut = fcfun.fuseshplist(cut)
        shp_final = shp_final.cut(shp_cut)

        for pt_d in (2, 13):
            for pt_w in (-4, 4):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = chmf_r)
        
        for pt_w in (-2, 2):
            shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(12, pt_w, 3), fillet = 1, radius = chmf_r)
            for pt_h in (1, 3):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(2, pt_w, pt_h), fillet = 1, radius = chmf_r)

        cut = []

        for pt_d in (1, 14):
            for pt_w in (-3, 3):
                shp_hole = fcfun.shp_cylcenxtr(r = self.boltshank_r_tol, h = h_base, normal = self.axis_h, ch = 0, xtr_top = 1, xtr_bot = 1, pos = self.get_pos_dwh(pt_d, pt_w, 0)) 
                cut.append(shp_hole)

        for pt_d in (4, 8):
            for pt_w in (-5, 5):
                shp_hole = fcfun.shp_cylcenxtr(r = self.boltshank_r_tol, h = h_base, normal = self.axis_h, ch = 0, xtr_top = 1, xtr_bot = 1, pos = self.get_pos_dwh(pt_d, pt_w, 0)) 
                cut.append(shp_hole)

        shp_cut = fcfun.fuseshplist(cut)
        shp_final = shp_final.cut(shp_cut)
        shp_final = shp_final.removeSplitter()

        for pt_d in (5, 6):
            for pt_w in (-4, 4):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = chmf_r)
        
        for pt_d in (3, 7):
            for pt_w in (-1, 1):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = 4 * chmf_r)

        for pt_d in (3, 11):
            for pt_w in (-4, 4):
                shp_final = fcfun.shp_filletchamfer_dirpt(shp_final, self.axis_h, fc_pt = self.get_pos_dwh(pt_d, pt_w, 0), fillet = 1, radius = chmf_r)
        
        doc.recompute()
        self.shp = shp_final

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
예제 #14
0
    def __init__(self,
                 alusize_d=50.,
                 alusize_w=30.,
                 alusize_h=50.,
                 dist_alu=30.,
                 wall_thick=4.,
                 bolt_wall_d=4.,
                 opt_sides=1,
                 chmf_r=1.,
                 axis_h=VZ,
                 axis_d=VX,
                 axis_w=None,
                 pos_h=1,
                 pos_d=3,
                 pos_w=0,
                 pos=V0,
                 name=''):
        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)  #vector product

        default_name = 'board'
        self.set_name(name, default_name, change=0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        # calculation of the bolt to hold the base to the profile
        self.boltshank_r_tol = kcomp.D912[bolt_wall_d]['shank_r_tol']
        self.bolthead_r = kcomp.D912[bolt_wall_d]['head_l']
        self.bolthead_r_tol = kcomp.D912[bolt_wall_d]['head_r']
        self.bolthead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.bolthead_l_tol = kcomp.D912[bolt_wall_d]['head_l_tol']

        # making the big box that will contain everything and will be cut
        self.tot_w = alusize_w
        self.tot_h = wall_thick + alusize_h / 2.
        if opt_sides == 0:
            self.tot_d = 2 * alusize_d + dist_alu
        else:
            self.tot_d = 2 * wall_thick + 2 * alusize_d + dist_alu

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.d0_cen = 0  # symmetrical
        self.w0_cen = 1  # symmetrical

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(wall_thick)
        self.h_o[2] = self.vec_h(self.tot_h)

        # position along axis_d
        if opt_sides == 0:
            self.d_o[0] = V0
            self.d_o[1] = self.vec_d(alusize_d / 4.)
            self.d_o[2] = self.vec_d(3 * alusize_d / 4.)
            self.d_o[3] = self.vec_d(alusize_d + TOL)
            self.d_o[4] = self.vec_d(alusize_d + dist_alu / 2.)
            self.d_o[5] = self.vec_d(alusize_d + dist_alu - TOL)
            self.d_o[6] = self.vec_d(alusize_d + dist_alu + alusize_d / 4.)
            self.d_o[7] = self.vec_d(alusize_d + dist_alu + 3 * alusize_d / 4.)
            self.d_o[8] = self.vec_d(self.tot_d)
        else:
            self.d_o[0] = V0
            self.d_o[1] = self.vec_d(wall_thick - TOL)
            self.d_o[2] = self.vec_d(wall_thick + alusize_d / 4.)
            self.d_o[3] = self.vec_d(wall_thick + 3 * alusize_d / 4.)
            self.d_o[4] = self.vec_d(wall_thick + alusize_d + TOL)
            self.d_o[5] = self.vec_d(wall_thick + alusize_d + dist_alu / 2.)
            self.d_o[6] = self.vec_d(wall_thick + alusize_d + dist_alu - TOL)
            self.d_o[7] = self.vec_d(wall_thick + alusize_d + dist_alu +
                                     alusize_d / 4.)
            self.d_o[8] = self.vec_d(wall_thick + alusize_d + dist_alu +
                                     3 * alusize_d / 4.)
            self.d_o[9] = self.vec_d(wall_thick + alusize_d + dist_alu +
                                     alusize_d + TOL)
            self.d_o[10] = self.vec_d(self.tot_d)

        # vectors from the origin to the points along axis_w
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-(alusize_w / 2. - 5.))
        self.w_o[2] = self.vec_w(-self.tot_w / 2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box
        if opt_sides == 0:
            shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=self.tot_h,
                                        fc_axis_d=self.axis_d,
                                        fc_axis_h=self.axis_h,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.pos_o)
            super().add_child(shp_box, 1, 'shp_box')

            # make the shape of the piece
            cut_box1 = fcfun.shp_box_dir(box_w=self.tot_w,
                                         box_d=alusize_d + TOL,
                                         box_h=alusize_h,
                                         fc_axis_d=self.axis_d,
                                         fc_axis_h=self.axis_h,
                                         cw=1,
                                         cd=0,
                                         ch=0,
                                         pos=self.get_pos_dwh(0, 0, 1))
            super().add_child(cut_box1, 0, 'cut_box1')
            cut_box2 = fcfun.shp_box_dir(box_w=self.tot_w,
                                         box_d=alusize_d + TOL,
                                         box_h=alusize_h,
                                         fc_axis_d=self.axis_d,
                                         fc_axis_h=self.axis_h,
                                         cw=1,
                                         cd=0,
                                         ch=0,
                                         pos=self.get_pos_dwh(5, 0, 1))
            super().add_child(cut_box2, 0, 'cut_box2')

            # holes to hold the profile
            cut_hole1 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(1, -1, 0))
            super().add_child(cut_hole1, 0, 'cut_hole1')
            cut_hole2 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(1, 1, 0))
            super().add_child(cut_hole2, 0, 'cut_hole2')
            cut_hole3 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(2, -1, 0))
            super().add_child(cut_hole3, 0, 'cut_hole3')
            cut_hole4 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(2, 1, 0))
            super().add_child(cut_hole4, 0, 'cut_hole4')
            cut_hole5 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(6, -1, 0))
            super().add_child(cut_hole5, 0, 'cut_hole5')
            cut_hole6 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(6, 1, 0))
            super().add_child(cut_hole6, 0, 'cut_hole6')
            cut_hole7 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(7, 1, 0))
            super().add_child(cut_hole7, 0, 'cut_hole7')
            cut_hole8 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(7, -1, 0))
            super().add_child(cut_hole8, 0, 'cut_hole8')

            # holes to hold de screw

            hole1 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=self.tot_h,
                                       r_head=self.bolthead_r_tol,
                                       l_head=13 * self.tot_h / 20.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h.negative(),
                                       pos_n=0,
                                       pos=self.get_pos_dwh(4, -1, 2))
            super().add_child(hole1, 0, 'hole1')
            hole2 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=self.tot_h,
                                       r_head=self.bolthead_r_tol,
                                       l_head=13 * self.tot_h / 20.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h.negative(),
                                       pos_n=0,
                                       pos=self.get_pos_dwh(4, 1, 2))
            super().add_child(hole2, 0, 'hole2')

        else:
            shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=self.tot_h,
                                        fc_axis_d=self.axis_d,
                                        fc_axis_h=self.axis_h,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.pos_o)
            super().add_child(shp_box, 1, 'shp_box')

            # make the shape of the piece
            cut_box1 = fcfun.shp_box_dir(box_w=self.tot_w,
                                         box_d=alusize_d + 2 * TOL,
                                         box_h=alusize_h,
                                         fc_axis_d=self.axis_d,
                                         fc_axis_h=self.axis_h,
                                         cw=1,
                                         cd=0,
                                         ch=0,
                                         pos=self.get_pos_dwh(1, 0, 1))
            super().add_child(cut_box1, 0, 'cut_box1')
            cut_box2 = fcfun.shp_box_dir(box_w=self.tot_w,
                                         box_d=alusize_d + 2 * TOL,
                                         box_h=alusize_h,
                                         fc_axis_d=self.axis_d,
                                         fc_axis_h=self.axis_h,
                                         cw=1,
                                         cd=0,
                                         ch=0,
                                         pos=self.get_pos_dwh(6, 0, 1))
            super().add_child(cut_box2, 0, 'cut_box2')

            # holes to hold the profile
            cut_hole1 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(2, -1, 0))
            super().add_child(cut_hole1, 0, 'cut_hole1')
            cut_hole2 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(2, 1, 0))
            super().add_child(cut_hole2, 0, 'cut_hole2')
            cut_hole3 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(3, -1, 0))
            super().add_child(cut_hole3, 0, 'cut_hole3')
            cut_hole4 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(3, 1, 0))
            super().add_child(cut_hole4, 0, 'cut_hole4')
            cut_hole5 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(7, -1, 0))
            super().add_child(cut_hole5, 0, 'cut_hole5')
            cut_hole6 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(7, 1, 0))
            super().add_child(cut_hole6, 0, 'cut_hole6')
            cut_hole7 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(8, 1, 0))
            super().add_child(cut_hole7, 0, 'cut_hole7')
            cut_hole8 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                           l_bolt=wall_thick,
                                           r_head=self.bolthead_r_tol,
                                           l_head=wall_thick / 2.,
                                           xtr_head=1,
                                           xtr_shank=1,
                                           fc_normal=self.axis_h,
                                           pos_n=0,
                                           pos=self.get_pos_dwh(8, -1, 0))
            super().add_child(cut_hole8, 0, 'cut_hole8')

            # holes to hold de screw
            hole1 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=self.tot_h,
                                       r_head=self.bolthead_r_tol,
                                       l_head=13 * self.tot_h / 20.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h.negative(),
                                       pos_n=0,
                                       pos=self.get_pos_dwh(5, -1, 2))
            super().add_child(hole1, 0, 'hole1')
            hole2 = fcfun.shp_bolt_dir(r_shank=self.boltshank_r_tol,
                                       l_bolt=self.tot_h,
                                       r_head=self.bolthead_r_tol,
                                       l_head=13 * self.tot_h / 20.,
                                       xtr_head=1,
                                       xtr_shank=1,
                                       fc_normal=self.axis_h.negative(),
                                       pos_n=0,
                                       pos=self.get_pos_dwh(5, 1, 2))
            super().add_child(hole2, 0, 'hole2')

        super().make_parent(name)
        if opt_sides == 0:
            for pt_d in (0, 3, 5, 8):
                for pt_w in (-2, 2):
                    self.shp = fcfun.shp_filletchamfer_dirpt(
                        self.shp,
                        fc_axis=self.axis_h,
                        fc_pt=self.get_pos_dwh(pt_d, pt_w, 1),
                        fillet=1,
                        radius=chmf_r)
        else:
            for pt_w in (-2, 2):
                for pt_d in (0, 1, 4, 6, 9, 10):
                    self.shp = fcfun.shp_filletchamfer_dirpt(
                        self.shp,
                        fc_axis=self.axis_h,
                        fc_pt=self.get_pos_dwh(pt_d, pt_w, 2),
                        fillet=1,
                        radius=chmf_r)

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
    def __init__(self, nema_size = 17, wall_thick = 4., motor_thick = 4., reinf_thick = 4., motor_min_h = 10., motor_max_h = 20., motor_xtr_space = 2., xtr_diam_cir = 8., diam_cir = 28.,bolt_wall_d = 3., bolt_wall_d_rail = 4., bolt_wall_sep = 30., rail = 1, chmf_r = 1., angle = 45., axis_h = VZ, axis_d = VX, axis_w = None, pos_h = 1, pos_d = 3, pos_w = 0, pos = V0, name = ''):
        if axis_w is None or axis_w == V0:
           axis_w = axis_h.cross(axis_d) #vector product

        default_name = 'NemaMotorHolder'
        self.set_name(name, default_name, change = 0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        shp_clss.Obj3D.__init__(self, axis_d, axis_w, axis_h)
        
        # save the arguments as attributes
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self,i):
                setattr(self, i, values[i])
        
        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos
        
        # normal axes to print without support
        self.prnt_ax = self.axis_h
        
        self.motor_w = kcomp.NEMA_W[nema_size]
        self.motor_bolt_sep = kcomp.NEMA_BOLT_SEP[nema_size]
        self.motor_bolt_d = kcomp.NEMA_BOLT_D[nema_size]

        # calculation of the bolt wall d
        self.boltwallshank_r_tol = kcomp.D912[bolt_wall_d]['shank_r_tol']
        self.boltwallhead_l = kcomp.D912[bolt_wall_d]['head_l']
        self.boltwallhead_r_tol = kcomp.D912[bolt_wall_d]['head_r_tol']
        self.boltwallhead_r = kcomp.D912[bolt_wall_d]['head_r']
        self.washer_thick = kcomp.WASH_D125_T[bolt_wall_d]

        # calculation of the bolt wall d rail
        self.boltwallshank_r_tol_rail = kcomp.D912[bolt_wall_d_rail]['shank_r_tol']
        self.boltwallhead_l_rail = kcomp.D912[bolt_wall_d_rail]['head_l']
        self.boltwallhead_r_rail = kcomp.D912[bolt_wall_d_rail]['head_r']
        self.washer_thick_rail = kcomp.WASH_D125_T[bolt_wall_d_rail]

        # calculation of the bolt wall separation
        self.max_bolt_wall_sep = self.motor_w - 2 * self.boltwallhead_r
        if bolt_wall_sep == 0:
            self.bolt_wall_sep = self.max_bolt_wall_sep
        elif bolt_wall_sep > self.max_bolt_wall_sep: 
            logger.debug('bolt separation too large:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.max_bolt_wall_sep
            logger.debug('taking largest value:' + str(self.bolt_wall_sep))
        elif bolt_wall_sep < 4 * self.boltwallhead_r:
            logger.debug('bolt separation too short:' + str(bolt_wall_sep))
            self.bolt_wall_sep = self.self.max_bolt_wall_sep
            logger.debug('taking smallest value:' + str(self.bolt_wall_sep))
        
        # distance from the motor to the inner wall (in axis_d)
        self.motor_inwall_space = motor_xtr_space + self.boltwallhead_l + self.washer_thick

        # making the big box that will contain everything and will be cut
        self.tot_h = motor_thick + motor_max_h + 2 * bolt_wall_d
        self.tot_w = 2 * reinf_thick + self.motor_w + 2 * motor_xtr_space
        self.tot_d = wall_thick + self.motor_w + self.motor_inwall_space

        # distance from the motor axis to the wall (in axis_d)
        self.motax2wall = wall_thick + self.motor_inwall_space + self.motor_w/2.

        #
        self.d_circle = math.sin(math.radians(angle))*(diam_cir/2.)
        self.w_circle = math.cos(math.radians(angle))*(diam_cir/2.)

        # definition of which axis is symmetrical
        self.h0_cen = 0
        self.w0_cen = 1   # symmetrical 
        self.d0_cen = 0

        # vectors from the origin to the points along axis_h
        self.h_o[0] = V0
        self.h_o[1] = self.vec_h(motor_thick)
        self.h_o[2] = self.vec_h(motor_thick + motor_min_h)
        self.h_o[3] = self.vec_h(motor_thick + motor_max_h)
        self.h_o[4] = self.vec_h(self.tot_h)

        # position along axis_d
        self.d_o[0] = V0
        self.d_o[1] = self.vec_d(wall_thick)
        self.d_o[2] = self.vec_d(self.motax2wall - self.d_circle)
        self.d_o[3] = self.vec_d(self.motax2wall)
        self.d_o[4] = self.vec_d(self.motax2wall + self.d_circle)
        self.d_o[5] = self.vec_d(self.tot_d)

        # vectors from the origin to the points along axis_w
        self.w_o[0] = V0
        self.w_o[1] = self.vec_w(-self.bolt_wall_sep/2.)
        self.w_o[2] = self.vec_w(self.w_circle + TOL)
        self.w_o[3] = self.vec_w(-self.tot_w/2.)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box, extra height and depth to cut all the way back and down
        shp_box = fcfun.shp_box_dir(box_w = self.tot_w, box_d = self.tot_d, box_h = self.tot_h, fc_axis_h = self.axis_h, fc_axis_d = self.axis_d, cw = 1, cd = 0, ch = 0, pos = self.pos_o)

        # little chamfer at the corners, if fillet there are some problems
        shp_box = fcfun.shp_filletchamfer_dir(shp_box, self.axis_h, fillet = 0, radius = chmf_r)
        shp_box = shp_box.removeSplitter()

        # chamfer of the box to make a 'triangular' reinforcement
        chmf_reinf_r = min(self.tot_d - wall_thick, self.tot_h - motor_thick)
        shp_box = fcfun.shp_filletchamfer_dirpt(shp_box, self.axis_w, fc_pt = self.get_pos_dwh(5, 0, 4), fillet = 0, radius = chmf_reinf_r)
        shp_box = shp_box.removeSplitter()

        # holes
        holes = []

            # the space for the motor
        shp_motor = fcfun.shp_box_dir(box_w = self.motor_w + 2 * motor_xtr_space, box_d = self.tot_d + chmf_r, box_h = self.tot_h, fc_axis_h = self.axis_h, fc_axis_d = self.axis_d, cw = 1, cd = 0, ch = 0, pos = self.get_pos_dwh(1, 0, 1))
        shp_motor = fcfun.shp_filletchamfer_dir(shp_motor, self.axis_h, fillet = 0, radius = chmf_r)
        holes.append(shp_motor)

            # central circle of the motor 
        shp_hole = fcfun.shp_cylcenxtr(r = (self.motor_bolt_sep - self.motor_bolt_d - xtr_diam_cir + TOL)/2., h = motor_thick, normal = self.axis_h, ch = 0, xtr_top = 1, xtr_bot = 1, pos = self.get_pos_d(3))
        holes.append(shp_hole)

            # motor bolt holes
        for pt_d in (2, 4):
            for pt_w in (-2, 2):
                shp_hole = fcfun.shp_bolt_dir(r_shank = self.boltwallshank_r_tol, l_bolt = motor_thick, r_head = self.boltwallhead_r + TOL/3., l_head = 2, xtr_head = 1, xtr_shank = 1, fc_normal = self.axis_h, pos_n = 0, pos = self.get_pos_dwh(pt_d, pt_w, 0))
                #shp_hole = fcfun.shp_cylcenxtr(r = self.boltwallshank_r_tol, h = motor_thick, normal = self.axis_h, ch = 0, xtr_top = 1, xtr_bot = 1, pos = self.get_pos_dwh(pt_d, pt_w, 0))
                holes.append(shp_hole)

            # rail holes
        for pt_w in (-1, 1):
            if rail == 1:
                shp_hole = fcfun.shp_box_dir_xtr(box_w = 2 * self.boltwallshank_r_tol_rail, box_d = wall_thick, box_h = motor_max_h - motor_min_h, fc_axis_h = self.axis_h, fc_axis_d = self.axis_d, cw = 1, cd = 0, ch = 0, xtr_d = 1, xtr_nd = 1, pos = self.get_pos_dwh(0, pt_w, 2))
                holes.append(shp_hole)
            
            # hole for the ending of the rails (4 semicircles)
            for pt_h in (2, 3):
                shp_hole = fcfun.shp_cylcenxtr(r = self.boltwallshank_r_tol_rail, h = wall_thick, normal = self.axis_d, ch = 0, xtr_top = 1, xtr_bot =1, pos = self.get_pos_dwh(0, pt_w, pt_h))
                holes.append(shp_hole)
            
        shp_holes = fcfun.fuseshplist(holes)
        shp_motorholder = shp_box.cut(shp_holes)
        shp_bracket = shp_motorholder.removeSplitter()
        self.shp = shp_bracket

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position
예제 #16
0
    def __init__(self,
                 n_bolt=1,
                 bra_w_1=22.,
                 bra_w_2=17.,
                 bra_d_1=21.,
                 bra_d_2=51.,
                 bra_h_1=21.,
                 bra_h_2=51.,
                 bolt=5.,
                 rail=1,
                 d_rail=10.,
                 reinf_thick_1=3.,
                 reinf_thick_2=5.,
                 wall_thick=6.,
                 chmf_r=1.,
                 dist_bet_nuts=17.,
                 dist_hole=5.,
                 axis_h=VZ,
                 axis_d=VX,
                 axis_w=None,
                 pos_h=1,
                 pos_d=3,
                 pos_w=0,
                 pos=V0,
                 name=''):
        if axis_w is None or axis_w == V0:
            axis_w = axis_h.cross(axis_d)  #vector product

        default_name = 'alu_bracket'
        self.set_name(name, default_name, change=0)
        Obj3D.__init__(self, axis_d, axis_w, axis_h, self.name)

        # save the arguments as attributes:
        frame = inspect.currentframe()
        args, _, _, values = inspect.getargvalues(frame)
        for i in args:
            if not hasattr(self, i):
                setattr(self, i, values[i])

        self.pos = FreeCAD.Vector(0, 0, 0)
        self.position = pos

        # normal axes to print without support
        self.prnt_ax = self.axis_h

        # calculation of the bolt to hold the bottom coverplate to the wood
        self.boltshank_r_tol = kcomp.D912[bolt]['shank_r_tol']
        self.bolthead_r = kcomp.D912[bolt]['head_l']
        self.bolthead_r_tol = kcomp.D912[bolt]['head_r']
        self.bolthead_l = kcomp.D912[bolt]['head_l']

        # making the big box that will contain everything and will be cut
        if n_bolt == 1:
            self.tot_d = bra_d_1 + wall_thick
            self.tot_w = bra_w_1 + 2 * reinf_thick_1
            self.tot_h = bra_h_1 + wall_thick
        else:
            self.tot_d = bra_d_2 + wall_thick
            self.tot_w = bra_w_2 + 2 * reinf_thick_2
            self.tot_h = bra_h_2 + wall_thick

        # definition of which axis is symmetrical
        if n_bolt == 1:
            self.h0_cen = 0
            self.w0_cen = 1  # symmetrical
            self.d0_cen = 0
        else:
            self.h0_cen = 0
            self.w0_cen = 0
            self.d0_cen = 0

        if n_bolt == 1:
            # vectors from the origin to the points along axis_h
            self.h_o[0] = V0
            self.h_o[1] = self.vec_h(wall_thick)
            self.h_o[2] = self.vec_h(wall_thick + dist_hole)
            self.h_o[3] = self.vec_h(wall_thick + bra_h_1 / 2.)
            self.h_o[4] = self.vec_h(wall_thick + dist_hole + d_rail)
            self.h_o[5] = self.vec_h(self.tot_h)
            # position along axis_d
            self.d_o[0] = V0
            self.d_o[1] = self.vec_d(dist_hole)
            self.d_o[2] = self.vec_d(dist_hole + d_rail)
            self.d_o[3] = self.vec_d(bra_d_1 / 2.)
            self.d_o[4] = self.vec_d(bra_d_1)
            self.d_o[5] = self.vec_d(self.tot_d)
            # position along axis_w
            self.w_o[0] = V0
            self.w_o[1] = self.vec_w(-self.boltshank_r_tol)
            self.w_o[2] = self.vec_w(-bra_w_1 / 2.)
            self.w_o[3] = self.vec_w(-self.tot_w / 2.)
        else:
            # vectors from the origin to the points along axis_h
            self.h_o[0] = V0
            self.h_o[1] = self.vec_h(wall_thick)
            self.h_o[2] = self.vec_h(wall_thick + dist_hole)
            self.h_o[3] = self.vec_h(wall_thick + dist_hole + d_rail / 2.)
            self.h_o[4] = self.vec_h(wall_thick + dist_hole + d_rail)
            self.h_o[5] = self.vec_h(wall_thick + dist_hole + d_rail +
                                     dist_bet_nuts)
            self.h_o[6] = self.vec_h(wall_thick + dist_hole + d_rail +
                                     dist_bet_nuts + d_rail / 2.)
            self.h_o[7] = self.vec_h(wall_thick + dist_hole + d_rail +
                                     dist_bet_nuts + d_rail)
            self.h_o[8] = self.vec_h(self.tot_h)
            # position along axis_d
            self.d_o[0] = V0
            self.d_o[1] = self.vec_d(dist_hole)
            self.d_o[2] = self.vec_d(dist_hole + d_rail / 2.)
            self.d_o[3] = self.vec_d(dist_hole + d_rail)
            self.d_o[4] = self.vec_d(dist_hole + d_rail + dist_bet_nuts)
            self.d_o[5] = self.vec_d(dist_hole + d_rail + dist_bet_nuts +
                                     d_rail / 2.)
            self.d_o[6] = self.vec_d(dist_hole + d_rail + dist_bet_nuts +
                                     d_rail)
            self.d_o[7] = self.vec_d(bra_d_2)
            self.d_o[8] = self.vec_d(self.tot_d)
            # position along axis_w
            self.w_o[0] = V0
            self.w_o[1] = self.vec_w(-reinf_thick_2)
            self.w_o[2] = self.vec_w(-(reinf_thick_2 + dist_hole))
            self.w_o[3] = self.vec_w(-(reinf_thick_2 + dist_hole +
                                       self.boltshank_r_tol))
            self.w_o[4] = self.vec_w(-(reinf_thick_2 + dist_hole +
                                       2 * self.boltshank_r_tol))
            self.w_o[5] = self.vec_w(-(reinf_thick_2 + bra_w_2))
            self.w_o[6] = self.vec_w(-self.tot_w)

        # calculates the position of the origin, and keeps it in attribute pos_o
        self.set_pos_o()

        # make the whole box
        if n_bolt == 1:
            shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=self.tot_h,
                                        fc_axis_h=axis_h,
                                        fc_axis_d=axis_d,
                                        cw=1,
                                        cd=0,
                                        ch=0,
                                        pos=self.pos_o)

            cut = []

            shp_box_int = fcfun.shp_box_dir(box_w=bra_w_1,
                                            box_d=bra_d_1,
                                            box_h=bra_h_1,
                                            fc_axis_h=axis_h,
                                            fc_axis_d=axis_d,
                                            cw=1,
                                            cd=0,
                                            ch=0,
                                            pos=self.get_pos_dwh(0, 0, 1))
            cut.append(shp_box_int)

            if rail == 0:
                shp_hole1 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                                h=wall_thick,
                                                normal=self.axis_h,
                                                ch=0,
                                                xtr_top=1,
                                                xtr_bot=1,
                                                pos=self.get_pos_dwh(3, 0, 0))
                cut.append(shp_hole1)
                shp_hole2 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                                h=wall_thick,
                                                normal=self.axis_d,
                                                ch=0,
                                                xtr_top=1,
                                                xtr_bot=1,
                                                pos=self.get_pos_dwh(4, 0, 3))
                cut.append(shp_hole2)
            else:
                shp_hole1 = fcfun.shp_box_dir_xtr(
                    box_w=2 * self.boltshank_r_tol,
                    box_d=d_rail,
                    box_h=wall_thick,
                    fc_axis_h=self.axis_h,
                    fc_axis_d=self.axis_d,
                    cw=1,
                    cd=0,
                    ch=0,
                    xtr_d=0,
                    xtr_nd=0,
                    pos=self.get_pos_dwh(1, 0, 0))
                cut.append(shp_hole1)
                shp_hole2 = fcfun.shp_box_dir_xtr(
                    box_w=2 * self.boltshank_r_tol,
                    box_d=wall_thick,
                    box_h=d_rail,
                    fc_axis_h=self.axis_h,
                    fc_axis_d=self.axis_d,
                    cw=1,
                    cd=0,
                    ch=0,
                    xtr_d=0,
                    xtr_nd=0,
                    pos=self.get_pos_dwh(4, 0, 2))
                cut.append(shp_hole2)

            shp_cut = fcfun.fuseshplist(cut)
            shp_final = shp_box.cut(shp_cut)

            chmf_reinf_r = min(bra_d_1, bra_h_1)
            for pt_w in (-3, 3):
                shp_final = fcfun.shp_filletchamfer_dirpt(
                    shp_final,
                    self.axis_w,
                    fc_pt=self.get_pos_dwh(0, pt_w, 5),
                    fillet=0,
                    radius=chmf_reinf_r)

            shp_final = fcfun.shp_filletchamfer_dirpt(shp_final,
                                                      self.axis_w,
                                                      fc_pt=self.get_pos_dwh(
                                                          0, 0, 0),
                                                      fillet=0,
                                                      radius=chmf_r)
            shp_final = fcfun.shp_filletchamfer_dirpt(shp_final,
                                                      self.axis_w,
                                                      fc_pt=self.get_pos_dwh(
                                                          4, 0, 1),
                                                      fillet=1,
                                                      radius=chmf_r)

            for pt_h in (0, 5):
                shp_final = fcfun.shp_filletchamfer_dirpt(
                    shp_final,
                    self.axis_w,
                    fc_pt=self.get_pos_dwh(5, 0, pt_h),
                    fillet=0,
                    radius=chmf_r)

            if rail == 1:
                for pt_w in (-1, 1):
                    for pt_d in (1, 2):
                        shp_final = fcfun.shp_filletchamfer_dirpt(
                            shp_final,
                            self.axis_h,
                            fc_pt=self.get_pos_dwh(pt_d, pt_w, 0),
                            fillet=1,
                            radius=chmf_r)
                    for pt_h in (2, 4):
                        shp_final = fcfun.shp_filletchamfer_dirpt(
                            shp_final,
                            self.axis_d,
                            fc_pt=self.get_pos_dwh(4, pt_w, pt_h),
                            fillet=1,
                            radius=chmf_r)

        else:
            shp_box = fcfun.shp_box_dir(box_w=self.tot_w,
                                        box_d=self.tot_d,
                                        box_h=self.tot_h,
                                        fc_axis_h=axis_h,
                                        fc_axis_d=axis_d,
                                        cw=0,
                                        cd=0,
                                        ch=0,
                                        pos=self.pos_o)

            cut = []

            shp_box_int = fcfun.shp_box_dir(box_w=bra_w_2 + reinf_thick_2,
                                            box_d=bra_d_2,
                                            box_h=bra_h_2,
                                            fc_axis_h=axis_h,
                                            fc_axis_d=axis_d,
                                            cw=0,
                                            cd=0,
                                            ch=0,
                                            pos=self.get_pos_dwh(0, 1, 1))
            cut.append(shp_box_int)

            if rail == 0:
                for pt_d in (2, 5):
                    shp_hole1 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                                    h=wall_thick,
                                                    normal=self.axis_h,
                                                    ch=0,
                                                    xtr_top=1,
                                                    xtr_bot=1,
                                                    pos=self.get_pos_dwh(
                                                        pt_d, 3, 0))
                    cut.append(shp_hole1)
                for pt_h in (3, 6):
                    shp_hole2 = fcfun.shp_cylcenxtr(r=self.boltshank_r_tol,
                                                    h=wall_thick,
                                                    normal=self.axis_d,
                                                    ch=0,
                                                    xtr_top=1,
                                                    xtr_bot=1,
                                                    pos=self.get_pos_dwh(
                                                        7, 3, pt_h))
                    cut.append(shp_hole2)
            else:
                for pt_d in (1, 4):
                    shp_hole1 = fcfun.shp_box_dir_xtr(
                        box_w=2 * self.boltshank_r_tol,
                        box_d=d_rail,
                        box_h=wall_thick,
                        fc_axis_h=self.axis_h,
                        fc_axis_d=self.axis_d,
                        cw=1,
                        cd=0,
                        ch=0,
                        xtr_d=0,
                        xtr_nd=0,
                        pos=self.get_pos_dwh(pt_d, 3, 0))
                    cut.append(shp_hole1)
                for pt_h in (2, 5):
                    shp_hole2 = fcfun.shp_box_dir_xtr(
                        box_w=2 * self.boltshank_r_tol,
                        box_d=wall_thick,
                        box_h=d_rail,
                        fc_axis_h=self.axis_h,
                        fc_axis_d=self.axis_d,
                        cw=1,
                        cd=0,
                        ch=0,
                        xtr_d=0,
                        xtr_nd=0,
                        pos=self.get_pos_dwh(7, 3, pt_h))
                    cut.append(shp_hole2)

            shp_cut = fcfun.fuseshplist(cut)
            shp_final = shp_box.cut(shp_cut)

            chmf_reinf_r = min(bra_d_2, bra_h_2)
            shp_final = fcfun.shp_filletchamfer_dirpt(shp_final,
                                                      self.axis_w,
                                                      fc_pt=self.get_pos_dwh(
                                                          0, 1, 8),
                                                      fillet=0,
                                                      radius=chmf_reinf_r)

            shp_final = fcfun.shp_filletchamfer_dirpt(shp_final,
                                                      self.axis_w,
                                                      fc_pt=self.get_pos_dwh(
                                                          0, 0, 0),
                                                      fillet=0,
                                                      radius=chmf_r)
            shp_final = fcfun.shp_filletchamfer_dirpt(shp_final,
                                                      self.axis_w,
                                                      fc_pt=self.get_pos_dwh(
                                                          7, 0, 1),
                                                      fillet=1,
                                                      radius=chmf_r)

            for pt_h in (0, 8):
                shp_final = fcfun.shp_filletchamfer_dirpt(
                    shp_final,
                    self.axis_w,
                    fc_pt=self.get_pos_dwh(8, 0, pt_h),
                    fillet=0,
                    radius=chmf_r)

            if rail == 1:
                for pt_w in (2, 4):
                    for pt_d in (1, 3, 4, 6):
                        shp_final = fcfun.shp_filletchamfer_dirpt(
                            shp_final,
                            self.axis_h,
                            fc_pt=self.get_pos_dwh(pt_d, pt_w, 0),
                            fillet=1,
                            radius=chmf_r)
                    for pt_h in (2, 4, 5, 7):
                        shp_final = fcfun.shp_filletchamfer_dirpt(
                            shp_final,
                            self.axis_d,
                            fc_pt=self.get_pos_dwh(7, pt_w, pt_h),
                            fillet=1,
                            radius=chmf_r)

        shp_final = shp_final.removeSplitter()

        self.shp = shp_final

        # Then the Part
        super().create_fco(name)
        self.fco.Placement.Base = FreeCAD.Vector(0, 0, 0)
        self.fco.Placement.Base = self.position