def MakeHeader(n, params):

    name = HeaderName(n, params)

    #having a period '.' character in the model name REALLY messes with things.
    docname = name.replace(".", "")

    newdoc = FreeCAD.newDocument(docname)
    App.setActiveDocument(docname)
    Gui.ActiveDocument = Gui.getDocument(docname)

    pins = MakePinRow(n, params)

    #duplicate pin rows
    if params.rows > 1:
        for i in range(1, params.rows):
            pins = pins.union(
                MakePinRow(n, params).translate((0, i * params.p, 0)))

    base = MakeBase(n, params)

    #assign some colors
    base_color = (50, 50, 50)
    pins_color = (225, 175, 0)

    show(base, base_color + (0, ))
    show(pins, pins_color + (0, ))

    doc = FreeCAD.ActiveDocument

    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = docname
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = docname
    restore_Main_Tools()

    if (params.rot != 0):
        z_RotateObject(doc, params.rot)

    out_dir = "./generated_pinheaders/"

    doc.Label = docname

    #save the STEP file
    exportSTEP(doc, name, out_dir)

    #save the VRML file
    scale = 0.3937001
    exportVRML(doc, name, scale, out_dir)

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name, out_dir)

    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()

    return 0
def MakeHeader(n, params):
    
    name = HeaderName(n,params)
    
    #having a period '.' character in the model name REALLY messes with things.
    docname = name.replace(".","")
    
    newdoc = FreeCAD.newDocument(docname)
    App.setActiveDocument(docname)
    Gui.ActiveDocument=Gui.getDocument(docname)
    
    pins = MakePinRow(n,params)
    
    #duplicate pin rows
    if params.rows > 1:
        for i in range(1,params.rows):
            pins = pins.union(MakePinRow(n,params).translate((0,i*params.p,0)))
    
    base = MakeBase(n,params)
        
    #assign some colors
    base_color = (50,50,50)
    pins_color = (225,175,0)

    show(base,base_color+(0,))
    show(pins,pins_color+(0,))
    
    doc = FreeCAD.ActiveDocument
        
    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui,
                   doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=docname
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=docname
    restore_Main_Tools()

    if (params.rot !=0):
        z_RotateObject(doc, params.rot)
    
    out_dir = "./generated_pinheaders/"
    
    doc.Label = docname
    
    #save the STEP file
    exportSTEP(doc, name, out_dir)

    #save the VRML file
    scale=0.3937001
    exportVRML(doc,name,scale,out_dir)
    
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name,out_dir)

    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()

    return 0
def main(argmodel_to_build, argcolor_pin_mark):
    global color_pin_mark
    global model_to_build
    global excluded_pins_xmirror
    global excluded_pins_x

    color_pin_mark = argcolor_pin_mark
    model_to_build = argmodel_to_build

    if model_to_build == "all":
        variants = all_params.keys()
    else:
        variants = [model_to_build]
    for variant in variants:
        FreeCAD.Console.PrintMessage("\r\n" + variant)
        if not variant in all_params:
            print("Parameters for %s doesn't exist in 'all_params', skipping." % variant)
            continue
        ModelName = all_params[variant].modelName
        Newdoc = FreeCAD.newDocument(ModelName)
        App.setActiveDocument(ModelName)
        Gui.ActiveDocument = Gui.getDocument(ModelName)
        case, pins = make_dip(all_params[variant])
        color_attr = case_color + (0,)
        show(case, color_attr)
        # FreeCAD.Console.PrintMessage(pins_color)
        color_attr = pins_color + (0,)
        # FreeCAD.Console.PrintMessage(color_attr)
        show(pins, color_attr)
        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
        doc.Label = ModelName
        objs = GetListOfObjects(FreeCAD, doc)
        objs[0].Label = ModelName
        restore_Main_Tools()
        # rotate if required
        if all_params[variant].rotation != 0:
            rot = all_params[variant].rotation
            z_RotateObject(doc, rot)
        out_dir = destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        # out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc, ModelName, out_dir)
        # scale and export Vrml model
        scale = 0.3937001
        exportVRML(doc, ModelName, scale, out_dir)
        # Save the doc in Native FC format
        saveFCdoc(App, Gui, doc, ModelName, out_dir)
        # display BBox

        FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    def make_3D_model(self):
        """ create a 3D model of a WAGO serie 734 connector.  Two parts will be created: plastic body, pins.

        This function will be called from the main_generator script.
        :return: list of the materials used for the 3D model
        :rtype: ``dictionary`` 
        """
        destination_dir = self.get_dest_3D_dir()
        
        case = self.makePlasticCase()
        pins = self.make_pins()
        show(case)
        show(pins)
     
        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)

     
        body_color = shaderColors.named_colors[self.body_color_key].getDiffuseFloat()
        pin_color = shaderColors.named_colors[self.pin_color_key].getDiffuseFloat()

        # must be the same order of the above show(..) calls
        Color_Objects(Gui, objs[0], body_color)
        Color_Objects(Gui, objs[1], pin_color)

        col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        
        material_substitutions={
            col_body[:-1]:self.body_color_key,
            col_pin[:-1]:self.pin_color_key,
        }
        
        expVRML.say(material_substitutions)

        # fuse all parts of model
        while len(objs) > 1:
                FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
                del objs
                objs = GetListOfObjects(FreeCAD, doc)

        #rotate if required
        if (self.rotation != 0):
            z_RotateObject(doc, self.rotation)

        s = objs[0].Shape
        shape = s.copy()
        shape.Placement = s.Placement;
        shape.translate(self.offsets)
        objs[0].Placement = shape.Placement

        return material_substitutions
def build_and_save(i):

    ModelName='pinstrip_p254_'+str(i)+'x1'
    Newdoc = FreeCAD.newDocument(ModelName)
    App.setActiveDocument(ModelName)
    Gui.ActiveDocument=Gui.getDocument(ModelName)

    FreeCAD.Console.PrintMessage('making all pin headers\r\n')
    case, pins = make_pinheader(i)

    color_attr=case_color+(0,)
    show(case, color_attr)
    #FreeCAD.Console.PrintMessage(pins_color)
    color_attr=pins_color+(0,)
    #FreeCAD.Console.PrintMessage(color_attr)
    show(pins, color_attr)
    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui,
                    doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=ModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=ModelName
    restore_Main_Tools()
    #rotate if required
    if (rotation!=0):
        z_RotateObject(doc, rotation)
    out_dir=destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc,ModelName,out_dir)
    # scale and export Vrml model
    scale=0.3937001
    exportVRML(doc,ModelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, ModelName,out_dir)
    #display BBox

    FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    #import ImportGui
    #ImportGui.insert(u"C:/Cad/Progetti_K/FreeCAD-models/scripts/3D-models/CadQuery/reference-block.step","mypin")

    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()

    return 0
def build_and_save(i):

    ModelName = 'pinstrip_p254_' + str(i) + 'x1'
    Newdoc = FreeCAD.newDocument(ModelName)
    App.setActiveDocument(ModelName)
    Gui.ActiveDocument = Gui.getDocument(ModelName)

    FreeCAD.Console.PrintMessage('making all pin headers\r\n')
    case, pins = make_pinheader(i)

    color_attr = case_color + (0, )
    show(case, color_attr)
    #FreeCAD.Console.PrintMessage(pins_color)
    color_attr = pins_color + (0, )
    #FreeCAD.Console.PrintMessage(color_attr)
    show(pins, color_attr)
    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = ModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = ModelName
    restore_Main_Tools()
    #rotate if required
    if (rotation != 0):
        z_RotateObject(doc, rotation)
    out_dir = destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    # scale and export Vrml model
    scale = 0.3937001
    exportVRML(doc, ModelName, scale, out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, ModelName, out_dir)
    #display BBox

    FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    #import ImportGui
    #ImportGui.insert(u"C:/Cad/Progetti_K/FreeCAD-models/scripts/3D-models/CadQuery/reference-block.step","mypin")

    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()

    return 0
def MakeHeader(n, params):
    global formerDOC
    global LIST_license
    name = HeaderName(n, params)

    # destination_dir="/Pin_Headers"

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #having a period '.' character in the model name REALLY messes with things.
    docname = name.replace(".", "")

    newdoc = App.newDocument(docname)
    App.setActiveDocument(docname)
    App.ActiveDocument = App.getDocument(docname)
    Gui.ActiveDocument = Gui.getDocument(docname)

    baseblock = cq.Workplane("XY").rect(params.p, params.w).extrude(
        params.h).edges("|Z").chamfer(params.p / 10).translate(
            (0, 0, params.hb))
    base = baseblock
    for blocks in range(1, n):
        baseblock = baseblock.translate((params.p, 0, 0))
        base = base.union(baseblock)
        #move the base to the 'middle'
    if params.rows > 1:
        offset = params.p * (params.rows - 1) / 2.0
        base = base.translate((0, offset, 0))

    Inner_point = params.pw / sqrt(2)
    Outer_point = (params.pw * 2) / sqrt(2)
    single_pin = cq.Workplane("YZ", (0,0,0,)). \
    moveTo(params.pw/2,params.pa).line(0,-(params.pa-2*params.pw)).threePointArc((-(params.pw*1.5)+Outer_point,params.pw*2-Outer_point),(-(params.pw*1.5), 0)). \
    line(-(params.ph-2*params.pw),0).line(0,params.pw).line((params.ph-2*params.pw),0).threePointArc((-(params.pw*1.5)+Inner_point,params.pw*2-Inner_point), (-(params.pw/2), params.pw*2)). \
    line(0,params.pa-2*params.pw).close().extrude(params.pw).translate((-params.pw/2,0,0))
    single_pin = single_pin.faces(">Z").chamfer(params.pw / 4)
    single_pin = single_pin.faces("<Y").chamfer(params.pw / 4)
    pins = []
    if params.type:
        if params.type == 'Pin1Left':
            single_pin = single_pin.rotate((0, 0, 0), (0, 0, 1), 180)
        for pincount in range(0, n):
            single_pin = single_pin.rotate((0, 0, 0), (0, 0, 1), 180)
            pin = single_pin.translate((params.p * pincount, 0, 0))
            pins.append(pin)
    else:
        for pincount in range(0, n):
            pin = single_pin.translate((params.p * pincount, 0, 0))
            pins.append(pin)
        single_pin = single_pin.rotate((0, 0, 0), (0, 0, 1), 180)
        for pincount in range(0, n):
            pin = single_pin.translate((params.p * pincount, params.p, 0))
            pins.append(pin)

    merged_pins = pins[0]
    for p in pins[1:]:
        merged_pins = merged_pins.union(p)
    pins = merged_pins
    if params.rows > 1:
        row_offset = -params.p / 2
    else:
        row_offset = 0
    pins = pins.translate((-params.p * (n - 1) / 2, row_offset, 0))
    base = base.translate((-params.p * (n - 1) / 2, row_offset, 0))

    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    ##assign some colors
    #base_color = (50,50,50)
    #pins_color = (225,175,0)
    #
    #show(base,base_color+(0,))
    #show(pins,pins_color+(0,))

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = docname
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = docname
    restore_Main_Tools()

    if (params.rot != 0):
        z_RotateObject(doc, params.rot)

    #out_dir = models_dir+"/generated_pinheaders"

    doc.Label = docname

    #save the STEP file
    exportSTEP(doc, name, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + name + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)

    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name, out_dir)
    if save_memory == True:
        closeCurrentDoc(docname)
    return 0
Example #8
0
def MakeHeader(n, model, all_params):
    global formerDOC
    global LIST_license
    ModelName = model.replace('yy', "{n:02}".format(n=n))

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+all_params[model]['output_directory']
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
   
    newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument=App.getDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    
    header_type = all_params[model]['type']
    pitch = all_params[model]['pitch']
    rows = all_params[model]['rows']
    base_width = all_params[model]['base_width']
    base_height = all_params[model]['base_height']
    base_chamfer = all_params[model]['base_chamfer']
    pin_width = all_params[model]['pin_width']
    pin_length_above_base = all_params[model]['pin_length_above_base']
    
    pin_end_chamfer = all_params[model]['pin_end_chamfer']
    rotation = all_params[model]['rotation']
    
    if base_chamfer == 'auto':
        base_chamfer = pitch/10.

    if pin_end_chamfer == 'auto':
        pin_end_chamfer = pin_width/4.

    if header_type == 'Vertical_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base = make_Vertical_THT_base(n, pitch, rows, base_width, base_height, base_chamfer)
        pins = make_Vertical_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, pin_width, pin_end_chamfer)
    elif header_type == 'Horizontal_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base_x_offset = all_params[model]['base_x_offset']
        base = make_Horizontal_THT_base(n, pitch, rows, base_width, base_height, base_x_offset, base_chamfer)
        pins = make_Horizontal_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, base_width, pin_width, pin_end_chamfer, base_x_offset)
    elif header_type == 'Vertical_SMD':
        pin_length_horizontal = all_params[model]['pin_length_horizontal']
        base_z_offset = all_params[model]['base_z_offset']
        if rows == 1:
            pin_1_start = all_params[model]['pin_1_start']
        else:
            pin_1_start = None
        pins = make_Vertical_SMD_pins(n, pitch, rows, pin_length_above_base, pin_length_horizontal, base_height, base_width, pin_width, pin_end_chamfer, base_z_offset, pin_1_start)
        base = make_Vertical_SMD_base(n, pitch, base_width, base_height, base_chamfer, base_z_offset)
    else:
        print 'Header type: '
        print header_type
        print ' is not recognized, please check parameters'
        stop

    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    
    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui,
                   doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName
    restore_Main_Tools()

    if (rotation !=0):
        z_RotateObject(doc, rotation)
    
    #out_dir = models_dir+"/generated_pinheaders"
    
    doc.Label = CheckedModelName
    
    #save the STEP file
    exportSTEP(doc, ModelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    
    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)
    
    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format 
    saveFCdoc(App, Gui, doc, ModelName, out_dir, False) 
    
    check_Model=True
    if save_memory == True or check_Model==True:
        closeCurrentDoc(CheckedModelName)
    step_path=os.path.join(out_dir,ModelName+u'.step')
    if check_Model==True:
        #ImportGui.insert(step_path,ModelName)
        ImportGui.open(step_path)
        docu = FreeCAD.ActiveDocument
        if cq_cad_tools.checkUnion(docu) == True:
            FreeCAD.Console.PrintMessage('step file is correctly Unioned\n')
        else:
            FreeCAD.Console.PrintError('step file is NOT Unioned\n')
            stop
        FC_majorV=int(FreeCAD.Version()[0])
        FC_minorV=int(FreeCAD.Version()[1])
        if FC_majorV == 0 and FC_minorV >= 17:
            for o in docu.Objects:
                if hasattr(o,'Shape'):
                    chks=cq_cad_tools.checkBOP(o.Shape)
                    print 'chks ',chks
                    print cq_cad_tools.mk_string(o.Label)
                    if chks != True:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is INVALID!\n'
                        FreeCAD.Console.PrintError(msg)
                        FreeCAD.Console.PrintWarning(chks[0])
                        stop
                    else:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is valid\n'
                        FreeCAD.Console.PrintMessage(msg)
        else:
            FreeCAD.Console.PrintError('BOP check requires FC 0.17+\n')
            # Save the doc in Native FC format
        saveFCdoc(App, Gui, docu, ModelName,out_dir, False)
        closeCurrentDoc(docu.Label)
        
    return 0
def generateOneModel(params, log):
    excluded_pins_x = ()  ##no pin excluded
    excluded_pins_xmirror = ()  ##no pin excluded
    place_pinMark = True  ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)

    ModelName = params.modelName
    FreeCAD.Console.PrintMessage('\n\n##############  ' + ModelName +
                                 '  ###############\n')
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)
    #case, pins, pinmark = make_case(params)
    case_bot, case, pins, pinmark = make_case(params)

    if case_bot is not None:
        show(case_bot)
    show(case)
    show(pins)
    show(pinmark)
    #stop

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    if case_bot is not None:
        Color_Objects(Gui, objs[0], body_bot_color)
        Color_Objects(Gui, objs[1], body_color)
        Color_Objects(Gui, objs[2], pins_color)
        Color_Objects(Gui, objs[3], marking_color)

        col_body_bot = Gui.ActiveDocument.getObject(
            objs[0].Name).DiffuseColor[0]
        col_body = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_pin = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        col_mark = Gui.ActiveDocument.getObject(objs[3].Name).DiffuseColor[0]
        material_substitutions = {
            col_body_bot[:-1]: body_bot_color_key,
            col_body[:-1]: body_color_key,
            col_pin[:-1]: pins_color_key,
            col_mark[:-1]: marking_color_key
        }
        expVRML.say(material_substitutions)
        if (color_pin_mark == True) and (place_pinMark == True):
            CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[1].Name,
                            objs[3].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[3].Name)
        ###
        #sleep
        del objs
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
    else:
        Color_Objects(Gui, objs[0], body_color)
        Color_Objects(Gui, objs[1], pins_color)
        Color_Objects(Gui, objs[2], marking_color)

        col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        material_substitutions = {
            col_body[:-1]: body_color_key,
            col_pin[:-1]: pins_color_key,
            col_mark[:-1]: marking_color_key
        }
        #expVRML.say(material_substitutions)
        if (color_pin_mark == True) and (place_pinMark == True):
            CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                            objs[2].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[2].Name)
        ###
        #sleep
        del objs
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
    ## objs[0].Label='body'
    ## objs[1].Label='pins'
    ## objs[2].Label='mark'
    ###
    ## print objs[0].Name, objs[1].Name, objs[2].Name

    ## sleep
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (params.rotation != 0):
        rot = params.rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+params.dest_dir_prefix+'/'
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    #expVRML.say(models_dir)
    if len(params.dest_dir_prefix) >= 1:
        out_dir = models_dir + destination_dir + os.sep + params.dest_dir_prefix
    else:
        out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)

    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    #expVRML.writeVRMLFile added creaeAngle
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license, 0.9)
    # Save the doc in Native FC format
    #saveFCdoc(App, Gui, doc, ModelName,out_dir)
    #display BBox
    #FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    if footprints_dir is not None and os.path.isdir(
            footprints_dir
    ) and not save_memory and not check_Model:  #it doesn't make sense to import the footprint right before we close the file.
        #expVRML.say (ModelName)
        #stop
        sys.argv = [
            "fc", "dummy", footprints_dir + os.sep + ModelName, "savememory"
        ]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        if not ksu_present:
            try:
                import kicadStepUptools
                ksu_present = True
                expVRML.say("ksu present!")
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present = False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload_lib(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    #FreeCADGui.insert(u"C:\Temp\FCAD_sg\QFN_packages\QFN-12-1EP_3x3mm_Pitch0_5mm.kicad_mod")
    #FreeCADGui.insert(script_dir+os.sep+"ModelName.kicad_mod")
    if save_memory == False:
        Gui.activateWorkbench("PartWorkbench")
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewBottom()
        #Gui.activeDocument().activeView().viewAxometric()
    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    if save_memory == True or check_Model == True:
        doc = FreeCAD.ActiveDocument
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model == True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App,
                         Gui,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
def generateOneModel(part_params, log):
    place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)

    FreeCAD.Console.PrintMessage(
        '\n\n##############  ' +
        part_params['code_metric'] +
        '  ###############\n')
    dim_params = part_params['param_nominal'] if use_nominal_size else part_params['param_max']
    if dim_params == None:
        if show_all:
            if use_nominal_size:
                dim_params = part_params['param_max']
            else:
                dim_params = part_params['param_nominal']
    if dim_params == None:
        FreeCAD.Console.PrintMessage('No params found for current variant. Skipped\n')
        return

    ModelName = model_name_format_str.format(
      prefix=model_name_prefix,
      code_metric=part_params['code_metric'],
      code_letter=part_params['code_letter'],
      old_name=part_params['modelName_old'],
      maui_name=part_params['modelName_maui']
    )
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    body, pins, mark = make_tantalum(dim_params)

    show(body)
    show(pins)
    show(mark)
    
    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    Color_Objects(Gui,objs[2],mark_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        col_mark[:-1]:mark_color_key
    }
    #expVRML.say(material_substitutions)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    if (color_pin_mark==True) and (place_pinMark==True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (rotation!=0):
        rot = rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/'
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model==False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)
        expVRML.say(material_substitutions)

        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)
        doc.Label = CheckedModelName
        objs=GetListOfObjects(FreeCAD, doc)
        objs[0].Label = CheckedModelName
        restore_Main_Tools()
        #rotate if required
        rotation = all_params[model]['rotation']
        if (rotation!=0):
            z_RotateObject(doc, rotation)

        script_dir=os.path.dirname(os.path.realpath(__file__))
        ## models_dir=script_dir+"/../_3Dmodels"
        expVRML.say(models_dir)
        out_dir=models_dir+destination_dir
        #out_dir=script_dir+os.sep+destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        #out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc, ModelName, out_dir)
        if LIST_license[0]=="":
            LIST_license=Lic.LIST_int_license
            LIST_license.append("")
        Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
Example #12
0
            col_die[:-1]:die_color_key
        }

        expVRML.say(material_substitutions)

        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
        doc.Label = CheckedModelName
        objs=GetListOfObjects(FreeCAD, doc)
        objs[0].Label = CheckedModelName
        restore_Main_Tools()
        #rotate if required
        if (all_params[variant].rotation!=0):
            rot= all_params[variant].rotation
            z_RotateObject(doc, rot)
        #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/'
        script_dir=os.path.dirname(os.path.realpath(__file__))
        ## models_dir=script_dir+"/../_3Dmodels"
        expVRML.say(models_dir)
        out_dir=models_dir+destination_dir
        #out_dir=script_dir+os.sep+destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        #out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc, ModelName, out_dir)
        if LIST_license[0]=="":
            LIST_license=Lic.LIST_int_license
            LIST_license.append("")
        Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
def MakeHeader(n, model, all_params):
    global formerDOC
    global LIST_license
    ModelName = model.replace('yy', "{n:02}".format(n=n))

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+all_params[model]['output_directory']
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
   
    newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument=App.getDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    
    header_type = all_params[model]['type']
    pitch = all_params[model]['pitch']
    rows = all_params[model]['rows']
    base_width = all_params[model]['base_width']
    base_height = all_params[model]['base_height']
    base_chamfer = all_params[model]['base_chamfer']
    pin_width = all_params[model]['pin_width']
    pin_length_above_base = all_params[model]['pin_length_above_base']
    
    pin_end_chamfer = all_params[model]['pin_end_chamfer']
    rotation = all_params[model]['rotation']
    
    if base_chamfer == 'auto':
        base_chamfer = pitch/10.

    if pin_end_chamfer == 'auto':
        pin_end_chamfer = pin_width/4.

    if header_type == 'Vertical_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base = make_Vertical_THT_base(n, pitch, rows, base_width, base_height, base_chamfer)
        pins = make_Vertical_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, pin_width, pin_end_chamfer)
    elif header_type == 'Horizontal_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base_x_offset = all_params[model]['base_x_offset']
        base = make_Horizontal_THT_base(n, pitch, rows, base_width, base_height, base_x_offset, base_chamfer)
        pins = make_Horizontal_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, base_width, pin_width, pin_end_chamfer, base_x_offset)
    elif header_type == 'Vertical_SMD':
        pin_length_horizontal = all_params[model]['pin_length_horizontal']
        base_z_offset = all_params[model]['base_z_offset']
        if rows == 1:
            pin_1_start = all_params[model]['pin_1_start']
        else:
            pin_1_start = None
        pins = make_Vertical_SMD_pins(n, pitch, rows, pin_length_above_base, pin_length_horizontal, base_height, base_width, pin_width, pin_end_chamfer, base_z_offset, pin_1_start)
        base = make_Vertical_SMD_base(n, pitch, base_width, base_height, base_chamfer, base_z_offset)
    else:
        print 'Header type: '
        print header_type
        print ' is not recognized, please check parameters'
        stop

    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    
    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui,
                   doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName
    restore_Main_Tools()

    if (rotation !=0):
        z_RotateObject(doc, rotation)
    
    #out_dir = models_dir+"/generated_pinheaders"
    
    doc.Label = CheckedModelName
    
    #save the STEP file
    exportSTEP(doc, ModelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    
    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)
    
    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format 
    saveFCdoc(App, Gui, doc, ModelName, out_dir, False) 
    
    check_Model=True
    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)
    step_path=os.path.join(out_dir,ModelName+u'.step')
    if check_Model==True:
        #ImportGui.insert(step_path,ModelName)
        ImportGui.open(step_path)
        docu = FreeCAD.ActiveDocument
        if cq_cad_tools.checkUnion(docu) == True:
            FreeCAD.Console.PrintMessage('step file is correctly Unioned\n')
        else:
            FreeCAD.Console.PrintError('step file is NOT Unioned\n')
            stop
        FC_majorV=int(FreeCAD.Version()[0])
        FC_minorV=int(FreeCAD.Version()[1])
        if FC_majorV == 0 and FC_minorV >= 17:
            for o in docu.Objects:
                if hasattr(o,'Shape'):
                    chks=cq_cad_tools.checkBOP(o.Shape)
                    print 'chks ',chks
                    print cq_cad_tools.mk_string(o.Label)
                    if chks != True:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is INVALID!\n'
                        FreeCAD.Console.PrintError(msg)
                        FreeCAD.Console.PrintWarning(chks[0])
                        stop
                    else:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is valid\n'
                        FreeCAD.Console.PrintMessage(msg)
        else:
            FreeCAD.Console.PrintError('BOP check requires FC 0.17+\n')
            # Save the doc in Native FC format
        saveFCdoc(App, Gui, docu, ModelName,out_dir, False)
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)
        
    return 0
def generateOneModel(params, log):
    excluded_pins_x=() ##no pin excluded
    excluded_pins_xmirror=() ##no pin excluded
    place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)


    ModelName = params.modelName
    FreeCAD.Console.PrintMessage(
        '\n\n##############  ' +
        ModelName +
        '  ###############\n')
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    #case, pins, pinmark = make_case(params)
    case_bot, case, pins, pinmark = make_case(params)

    if case_bot is not None:
        show(case_bot)
    show(case)
    show(pins)
    show(pinmark)
    #stop

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)

    if case_bot is not None:
        Color_Objects(Gui,objs[0],body_bot_color)
        Color_Objects(Gui,objs[1],body_color)
        Color_Objects(Gui,objs[2],pins_color)
        Color_Objects(Gui,objs[3],marking_color)

        col_body_bot=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_body=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_pin=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        col_mark=Gui.ActiveDocument.getObject(objs[3].Name).DiffuseColor[0]
        material_substitutions={
            col_body_bot[:-1]:body_bot_color_key,
            col_body[:-1]:body_color_key,
            col_pin[:-1]:pins_color_key,
            col_mark[:-1]:marking_color_key
        }
        expVRML.say(material_substitutions)
        if (color_pin_mark==True) and (place_pinMark==True):
            CutObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[1].Name, objs[3].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[3].Name)
        ###
        #sleep
        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
    else:
        Color_Objects(Gui,objs[0],body_color)
        Color_Objects(Gui,objs[1],pins_color)
        Color_Objects(Gui,objs[2],marking_color)

        col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        material_substitutions={
            col_body[:-1]:body_color_key,
            col_pin[:-1]:pins_color_key,
            col_mark[:-1]:marking_color_key
        }
        #expVRML.say(material_substitutions)
        if (color_pin_mark==True) and (place_pinMark==True):
            CutObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[2].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[2].Name)
        ###
        #sleep
        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
    ## objs[0].Label='body'
    ## objs[1].Label='pins'
    ## objs[2].Label='mark'
    ###
    ## print objs[0].Name, objs[1].Name, objs[2].Name

    ## sleep
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (params.rotation!=0):
        rot= params.rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+params.dest_dir_prefix+'/'
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    #expVRML.say(models_dir)
    if len(params.dest_dir_prefix)>=1:
        out_dir=models_dir+destination_dir+os.sep+params.dest_dir_prefix
    else:
        out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)

    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile added creaeAngle
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license, 0.9)
    # Save the doc in Native FC format
    #saveFCdoc(App, Gui, doc, ModelName,out_dir)
    #display BBox
    #FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    if footprints_dir is not None and os.path.isdir(footprints_dir) and not save_memory and not check_Model: #it doesn't make sense to import the footprint right before we close the file.
        #expVRML.say (ModelName)
        #stop
        sys.argv = ["fc", "dummy", footprints_dir+os.sep+ModelName, "savememory"]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        if not ksu_present:
            try:
                import kicadStepUptools
                ksu_present=True
                expVRML.say("ksu present!")
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present=False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    #FreeCADGui.insert(u"C:\Temp\FCAD_sg\QFN_packages\QFN-12-1EP_3x3mm_Pitch0_5mm.kicad_mod")
    #FreeCADGui.insert(script_dir+os.sep+"ModelName.kicad_mod")
    if save_memory == False:
        Gui.activateWorkbench("PartWorkbench")
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewBottom()
        #Gui.activeDocument().activeView().viewAxometric()
    saveFCdoc(App, Gui, doc, ModelName,out_dir)

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        doc = FreeCAD.ActiveDocument
        objs=GetListOfObjects(FreeCAD, doc)
        objs[1].Label="Fusion2"
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        doc.Label=ModelName
        objs=GetListOfObjects(FreeCAD, doc)
        objs[0].Label=ModelName
        restore_Main_Tools()
        #rotate if required
        if (all_params[variant].rotation!=0):
            rot= all_params[variant].rotation
            z_RotateObject(doc, rot)
        script_dir=os.path.dirname(os.path.realpath(__file__))
        out_dir=script_dir+destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
            #out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc,ModelName,out_dir)

        # scale and export Vrml model
        scale=0.3937001
        exportVRML(doc,ModelName,scale,out_dir)

        # Save the doc in Native FC format
        saveFCdoc(App, Gui, doc, ModelName,out_dir)
        #display BBox
def make_3D_model(models_dir, variant):
                
    LIST_license = ["",]
    modelName = all_params[variant].modelName
        
    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)

    case = make_case(all_params[variant], type, modelName)
    
    if (all_params[variant].type == CASE_THT_TYPE):
        pins = make_pins_tht(all_params[variant], type, modelName)

    if (all_params[variant].type == CASE_SMD_TYPE):
        pins = make_pins_smd(all_params[variant], type, modelName)


        # color_attr=case_color+(0,)
    # show(case, color_attr)
    # #FreeCAD.Console.PrintMessage(pins_color)
    # color_attr=pins_color+(0,)
    # #FreeCAD.Console.PrintMessage(color_attr)
    # show(pins, color_attr)
    #doc = FreeCAD.ActiveDocument
    #objs=GetListOfObjects(FreeCAD, doc)

    show(case)
    show(pins)
    #show(pinmark)
    #stop
    
    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    FuseObjs_wColors(FreeCAD, FreeCADGui,
                    doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedmodelName
    del objs
    #objs=GetListOfObjects(FreeCAD, doc)
    #FuseObjs_wColors(FreeCAD, FreeCADGui,
    #                doc.Name, objs[0].Name, objs[1].Name)
    #doc.Label=modelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    # objs=GetListOfObjects(FreeCAD, doc)
    # objs[0].Label=modelName
    # restore_Main_Tools()
    #rotate if required
    if (all_params[variant].rotation!=0):
        rot= all_params[variant].rotation
        z_RotateObject(doc, rot)
    npins=all_params[variant].npins
    e=all_params[variant].e
    E=all_params[variant].E
    c= 0.254 # lead thickness
    mvY = (npins*e/4-e/2)
    mvX = (E-c)/2
    s = objs[0].Shape
    shape=s.copy()
    shape.Placement=s.Placement;
    shape.translate((+mvX,-mvY,0))
    objs[0].Placement=shape.Placement
    #case = case.translate ((-mvX,-mvY,0))
    #pins = pins.translate ((-mvX,-mvY,0))
    # out_dir=destination_dir
    # if not os.path.exists(out_dir):
    #     os.makedirs(out_dir)
    # #out_dir="./generated_qfp/"
    # # export STEP model
    # exportSTEP(doc,modelName,out_dir)
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+modelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName,out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
Example #17
0
def generateOneModel(part_params, log):
    place_pinMark = True  ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)

    FreeCAD.Console.PrintMessage('\n\n##############  ' +
                                 part_params['code_metric'] +
                                 '  ###############\n')
    dim_params = part_params[
        'param_nominal'] if use_nominal_size else part_params['param_max']
    if dim_params == None:
        if show_all:
            if use_nominal_size:
                dim_params = part_params['param_max']
            else:
                dim_params = part_params['param_nominal']
    if dim_params == None:
        FreeCAD.Console.PrintMessage(
            'No params found for current variant. Skipped\n')
        return

    ModelName = model_name_format_str.format(
        prefix=model_name_prefix,
        code_metric=part_params['code_metric'],
        code_letter=part_params['code_letter'],
        old_name=part_params['modelName_old'],
        maui_name=part_params['modelName_maui'])
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)
    body, pins, mark = make_tantalum(dim_params)

    show(body)
    show(pins)
    show(mark)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    Color_Objects(Gui, objs[2], mark_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        col_mark[:-1]: mark_color_key
    }
    #expVRML.say(material_substitutions)
    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    if (color_pin_mark == True) and (place_pinMark == True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                        objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)
    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (rotation != 0):
        rot = rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/'
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model == False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model == True:
        doc = FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model == True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App,
                         Gui,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
Example #18
0
def export_one_part(params, series_definition, log):
    ModelName = params.modelName
    footprint_dir = series_definition.footprint_dir
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')

    print('\n######################### {:s} ###########################\n'.
          format(ModelName))

    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument = App.getDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)

    color_keys = [
        series_definition.body_color_key, series_definition.pins_color_key,
        series_definition.mark_color_key
    ]
    colors = [
        shaderColors.named_colors[key].getDiffuseInt() for key in color_keys
    ]

    body, pins, mark = make_gw(params)

    show(body, colors[0] + (0, ))
    show(pins, colors[1] + (0, ))
    show(mark, colors[2] + (0, ))

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: series_definition.body_color_key,
        col_pin[:-1]: series_definition.pins_color_key,
        col_mark[:-1]: series_definition.mark_color_key
    }

    if (color_pin_mark == True) and (place_pinMark == True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                        objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)

    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName

    restore_Main_Tools()
    #rotate if required
    if (params.rotation != 0):
        rot = params.rotation
        z_RotateObject(doc, rot)

    if no_export:
        return

    out_dir = '{:s}{:s}.3dshapes'.format(global_3dpath,
                                         series_definition.lib_name)

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                         STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    # Save the doc in Native FC format
    footprint_dir = series_definition.footprint_dir
    if footprint_dir is not None and os.path.isdir(footprint_dir) \
            and not save_memory and not check_Model:
        #expVRML.say (ModelName)
        #stop
        sys.argv = [
            "fc", "dummy", footprint_dir + os.sep + ModelName, "savememory"
        ]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        ksu_already_loaded = False
        ksu_present = False
        for i in QtGui.qApp.topLevelWidgets():
            if i.objectName() == "kicadStepUp":
                ksu_already_loaded = True
        ksu_tab = FreeCADGui.getMainWindow().findChild(
            QtGui.QDockWidget, "kicadStepUp")  #"kicad StepUp 3D tools")
        if ksu_tab:
            ksu_already_loaded = True
        if ksu_already_loaded != True:
            try:
                import kicadStepUptools
                ksu_present = True
                ksu_already_loaded = True
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present = False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model == False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model == True:
        doc = FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model == True:
        runGeometryCheck(App,
                         Gui,
                         out_dir + '/' + ModelName + ".step",
                         log,
                         ModelName,
                         save_memory=save_memory)
        }

        expVRML.say(material_substitutions)

        del objs
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
        doc.Label = CheckedModelName
        objs = GetListOfObjects(FreeCAD, doc)
        objs[0].Label = CheckedModelName
        restore_Main_Tools()
        #rotate if required
        rotation = all_params[model]['rotation']
        if (rotation != 0):
            z_RotateObject(doc, rotation)

        script_dir = os.path.dirname(os.path.realpath(__file__))
        ## models_dir=script_dir+"/../_3Dmodels"
        expVRML.say(models_dir)
        out_dir = models_dir + destination_dir
        #out_dir=script_dir+os.sep+destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        #out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc, ModelName, out_dir)
        if LIST_license[0] == "":
            LIST_license = Lic.LIST_int_license
            LIST_license.append("")
        Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
def MakeHeader(n, params, pinarray):
    global formerDOC
    global LIST_license
    name = HeaderName(n, params)

    # destination_dir="/Pin_Headers"

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #having a period '.' character in the model name REALLY messes with things.
    docname = name.replace(".", "")

    newdoc = App.newDocument(docname)
    App.setActiveDocument(docname)
    App.ActiveDocument = App.getDocument(docname)
    Gui.ActiveDocument = Gui.getDocument(docname)

    pins_output = MakePinRow(n, 0, params, pinarray)

    #duplicate pin rows

    base_output = MakeBase(n, params, pinarray)

    show(base_output)
    show(pins_output)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    ##assign some colors
    #base_color = (50,50,50)
    #pins_color = (225,175,0)
    #
    #show(base,base_color+(0,))
    #show(pins,pins_color+(0,))

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = docname
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = docname
    restore_Main_Tools()

    if (params.rot != 0):
        z_RotateObject(doc, params.rot)

    #out_dir = models_dir+"/generated_pinheaders"

    doc.Label = docname

    #save the STEP file
    exportSTEP(doc, name, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + name + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)

    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name, out_dir)
    if save_memory == True:
        closeCurrentDoc(docname)
    return 0
Example #21
0
def make_3D_model(models_dir, variant):

    LIST_license = [
        "",
    ]
    modelName = all_params[variant].modelName

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

    case = make_case(all_params[variant], type, modelName)

    if (all_params[variant].type == CASE_THT_TYPE):
        pins = make_pins_tht(all_params[variant], type, modelName)

    if (all_params[variant].type == CASE_SMD_TYPE):
        pins = make_pins_smd(all_params[variant], type, modelName)

        # color_attr=case_color+(0,)
    # show(case, color_attr)
    # #FreeCAD.Console.PrintMessage(pins_color)
    # color_attr=pins_color+(0,)
    # #FreeCAD.Console.PrintMessage(color_attr)
    # show(pins, color_attr)
    #doc = FreeCAD.ActiveDocument
    #objs=GetListOfObjects(FreeCAD, doc)

    show(case)
    show(pins)
    #show(pinmark)
    #stop

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedmodelName
    del objs
    #objs=GetListOfObjects(FreeCAD, doc)
    #FuseObjs_wColors(FreeCAD, FreeCADGui,
    #                doc.Name, objs[0].Name, objs[1].Name)
    #doc.Label=modelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    # objs=GetListOfObjects(FreeCAD, doc)
    # objs[0].Label=modelName
    # restore_Main_Tools()
    #rotate if required
    if (all_params[variant].rotation != 0):
        rot = all_params[variant].rotation
        z_RotateObject(doc, rot)
    npins = all_params[variant].npins
    e = all_params[variant].e
    E = all_params[variant].E
    c = 0.254  # lead thickness
    mvY = (npins * e / 4 - e / 2)
    mvX = (E - c) / 2
    s = objs[0].Shape
    shape = s.copy()
    shape.Placement = s.Placement
    shape.translate((+mvX, -mvY, 0))
    objs[0].Placement = shape.Placement
    #case = case.translate ((-mvX,-mvY,0))
    #pins = pins.translate ((-mvX,-mvY,0))
    # out_dir=destination_dir
    # if not os.path.exists(out_dir):
    #     os.makedirs(out_dir)
    # #out_dir="./generated_qfp/"
    # # export STEP model
    # exportSTEP(doc,modelName,out_dir)
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,modelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + modelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName, out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
def export_one_part(params, series_definition, log):
    ModelName = params.modelName
    footprint_dir = series_definition.footprint_dir
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')

    print('\n######################### {:s} ###########################\n'.format(ModelName))

    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument=App.getDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)

    color_keys = [
        series_definition.body_color_key,
        series_definition.pins_color_key,
        series_definition.mark_color_key
    ]
    colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys]

    body, pins, mark = make_gw(params)

    show(body, colors[0]+(0,))
    show(pins, colors[1]+(0,))
    show(mark, colors[2]+(0,))

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:series_definition.body_color_key,
        col_pin[:-1]:series_definition.pins_color_key,
        col_mark[:-1]:series_definition.mark_color_key
    }

    if (color_pin_mark==True) and (place_pinMark==True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)

    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName

    restore_Main_Tools()
    #rotate if required
    if (params.rotation!=0):
        rot= params.rotation
        z_RotateObject(doc, rot)

    if no_export:
        return

    out_dir='{:s}{:s}.3dshapes'.format(global_3dpath, series_definition.lib_name)

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                         STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    # Save the doc in Native FC format
    footprint_dir = series_definition.footprint_dir
    if footprint_dir is not None and os.path.isdir(footprint_dir) \
            and not save_memory and not check_Model:
        #expVRML.say (ModelName)
        #stop
        sys.argv = ["fc", "dummy", footprint_dir+os.sep+ModelName, "savememory"]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        ksu_already_loaded=False
        ksu_present=False
        for i in QtGui.qApp.topLevelWidgets():
            if i.objectName() == "kicadStepUp":
                ksu_already_loaded=True
        ksu_tab = FreeCADGui.getMainWindow().findChild(QtGui.QDockWidget, "kicadStepUp") #"kicad StepUp 3D tools")
        if ksu_tab:
            ksu_already_loaded=True
        if ksu_already_loaded!=True:
            try:
                import kicadStepUptools
                ksu_present=True
                ksu_already_loaded=True
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present=False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    saveFCdoc(App, Gui, doc, ModelName,out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model==False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        runGeometryCheck(App, Gui, out_dir+'/'+ ModelName+".step",
            log, ModelName, save_memory=save_memory)
def main(arg_model_to_build='AKA',arg_color_pin_mark=True):
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')
    model_to_build=arg_model_to_build
    color_pin_mark=arg_color_pin_mark
    global excluded_pins_xmirror
    global excluded_pins_x
## maui     run()
#    ## if (not "modelName" in all_params['AKA']):
#    ##     ModelName = "newModel" # "LQFP64_p05_h12"
#    ## else:
#    ##     ModelName = all_params.modelName
#    color_pin_mark=True
#    if len(sys.argv) < 3:
#        FreeCAD.Console.PrintMessage('No variant name is given! building AKA')
#        model_to_build='AKA'
#    else:
#        model_to_build=sys.argv[2]
#        if len(sys.argv)==4:
#            FreeCAD.Console.PrintMessage(sys.argv[3]+'\r\n')
#            if (sys.argv[3].find('no-pinmark-color')!=-1):
#                color_pin_mark=False
#            else:
#                color_pin_mark=True
#++++++++++++++++++++++++++++++++




#-----------------------

    #FreeCAD.Console.PrintMessage(str(color_pin_mark)+'\r\n')
    #FreeCAD.Console.PrintMessage(str(sys.argv[3].find('no-pinmark-color')))
    
    if model_to_build == "all":
        variants = all_params.keys()
    else:
        variants = [model_to_build]

    for variant in variants:
        if variant == 'SOT23_3' or variant == 'SC70_3':
            excluded_pins_x=(1,) ##used to build sot23-3; sc70 (asimmetrical pins, no pinmark)
            excluded_pins_xmirror=(0,2,)
            place_pinMark=False ##used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)
        elif variant == 'SOT23_5':
            excluded_pins_x=() ##used to build sot23-3; sc70 (asimmetrical pins, no pinmark)
            excluded_pins_xmirror=(1,)
            place_pinMark=False ##used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)
        else:
            excluded_pins_x=() ##no pin excluded
            excluded_pins_xmirror=() ##no pin excluded
            place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)
        
        FreeCAD.Console.PrintMessage('\r\n'+variant)
        if not variant in all_params:
            print("Parameters for %s doesn't exist in 'all_params', skipping." % variant)
            continue
        ModelName = all_params[variant].modelName
        Newdoc = FreeCAD.newDocument(ModelName)
        App.setActiveDocument(ModelName)
        Gui.ActiveDocument=Gui.getDocument(ModelName)
        case, pins, pinmark = make_gw(all_params[variant])

        color_attr=case_color+(0,)
        show(case, color_attr)
        color_attr=pins_color+(0,)
        show(pins, color_attr)
        color_attr=mark_color+(0,)
        show(pinmark, color_attr)

        doc = FreeCAD.ActiveDocument
        objs=GetListOfObjects(FreeCAD, doc)
        ## objs[0].Label='body'
        ## objs[1].Label='pins'
        ## objs[2].Label='mark'
        ###
        ## print objs[0].Name, objs[1].Name, objs[2].Name

        ## sleep
        #if place_pinMark==True:
        if (color_pin_mark==True) and (place_pinMark==True):
            CutObjs_wColors(FreeCAD, FreeCADGui,
                           doc.Name, objs[0].Name, objs[2].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[2].Name)
        ###
        #sleep
        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        doc.Label=ModelName
        objs=GetListOfObjects(FreeCAD, doc)
        objs[0].Label=ModelName
        restore_Main_Tools()
        #rotate if required
        if (all_params[variant].rotation!=0):
            rot= all_params[variant].rotation
            z_RotateObject(doc, rot)
        #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/'
        script_dir=os.path.dirname(os.path.realpath(__file__))
        out_dir=script_dir+destination_dir+all_params[variant].dest_dir_prefix+'/'
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        #out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc,ModelName,out_dir)
        # scale and export Vrml model
        scale=0.3937001
        exportVRML(doc,ModelName,scale,out_dir)
        # Save the doc in Native FC format
        saveFCdoc(App, Gui, doc, ModelName,out_dir)
        #display BBox
        FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()
    def makeModel(self, models_dir, genericName, model, keepDocument=True, verbose=False):
        r"""Creates a model by calling an instance of a model generator class and writes out the model files

        .. note:: normally this method will be called by :func:`makeModels` but may be used directly

        :param models_dir:
            directory to write the created step and wrl files
        :type models_dir: ``str``

        :param genericName:
            the generic name from the base parameter list, may be used to create the model name
        :type  genericName: ``str``

        :param model:
            an instance of the model class to use
        :type   model: ``class instance`` inherited from :class:`cq_base_model.PartBase`

        :param keepDocument:
            * True: the FreeCAD document will shown after it is created, optionally with kicadStepUptools activated
            * False: the document window will be closed
        :type  keepDocument: ``boolean``

        """

        global kicadStepUptools

        modelName = model.makeModelName(genericName)

        FreeCAD.Console.PrintMessage('\r\n' + modelName)

        if model.make_me != True:
            FreeCAD.Console.PrintMessage(' - not made')
            return

        CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
        FreeCAD.newDocument(CheckedmodelName)
        FreeCAD.setActiveDocument(CheckedmodelName)
        Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

        model.make()

        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)

        material_substitutions = {}

        for i in range(0, len(objs)):
            Color_Objects(Gui, objs[i], shaderColors.named_colors[model.color_keys[i]].getDiffuseFloat())
            material_substitutions[Gui.ActiveDocument.getObject(objs[i].Name).DiffuseColor[0][:-1]] = model.color_keys[i]

        if verbose:
            expVRML.say(material_substitutions)
            expVRML.say(model.color_keys)
            expVRML.say(model.offsets)

        doc.Label = CheckedmodelName

        while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)

        objs[0].Label = CheckedmodelName
        restore_Main_Tools()

        #rotate if required
        if (model.rotation != 0):
            z_RotateObject(doc, model.rotation)

        s = objs[0].Shape
        shape = s.copy()
        shape.Placement = s.Placement;
        shape.translate(model.offsets)
        objs[0].Placement = shape.Placement

        out_dir = models_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        # Export STEP model
        exportSTEP(doc, modelName, out_dir)

        license_txt = list(add_license.LIST_int_license if self.license is None else self.license) # make a copy to avoid modifying the original
        license_txt.append("")
        license_txt.append("")
        if self.scriptsource != "" and self.script_dir is not None:
            license_txt.append("Generated by script, source at:")
            license_txt.append(self.scriptsource + self.script_dir.split(os.sep)[-1])
            license_txt.append("")

        if verbose:
            expVRML.say("")

        add_license.addLicenseToStep(out_dir + os.sep, modelName + ".step", license_txt, model.licAuthor, model.licEmail, model.licOrgSys, model.licOrg, model.licPreProc)

        # Scale and export Vrml model
        scale = 1.0 / 2.54
        objs = GetListOfObjects(FreeCAD, doc)
        if verbose:
            expVRML.say("######################################################################")
            expVRML.say(objs)
            expVRML.say("######################################################################")
        export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
        export_file_name = out_dir + os.sep + modelName + '.wrl'
        colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
        expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, license_txt)

        # Save the doc in native FC format
        out_dir = self.models_src_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        saveFCdoc(FreeCAD, Gui, doc, modelName, out_dir)

        # Place on footprint for verification
        if keepDocument and model.footprints_dir is not None and self.footprints_dir is not None:

            sys.argv = ["fc", "dummy", self.footprints_dir + os.sep + model.footprints_dir + os.sep + modelName, "savememory"]

            if verbose:
                expVRML.say('Footprint: ' + sys.argv[2])

            if self.kicadStepUptools is None:
                try:
                    import kicadStepUptools
                    expVRML.say("ksu present!")
                    self.kicadStepUptools = True
                    kicadStepUptools.KSUWidget.close()
                    #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                    #kicadStepUptools.KSUWidget.destroy()
                    #for i in QtGui.qApp.topLevelWidgets():
                    #    if i.objectName() == "kicadStepUp":
                    #        i.deleteLater()
                    #kicadStepUptools.KSUWidget.close()
                except:
                    self.kicadStepUptools = False
                    expVRML.say("ksu not present")

            if not self.kicadStepUptools == False:
                kicadStepUptools.KSUWidget.close()
                reload(kicadStepUptools)
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()

        #display BBox
        if keepDocument:
            Gui.activateWorkbench("PartWorkbench")
            Gui.SendMsgToActiveView("ViewFit")
            Gui.activeDocument().activeView().viewAxometric()
        else:
            doc=FreeCAD.ActiveDocument
            FreeCAD.closeDocument(doc.Name)
Example #25
0
    def makeModel(self,
                  models_dir,
                  genericName,
                  model,
                  keepDocument=True,
                  verbose=False):
        r"""Creates a model by calling an instance of a model generator class and writes out the model files

        .. note:: normally this method will be called by :func:`makeModels` but may be used directly

        :param models_dir:
            directory to write the created step and wrl files
        :type models_dir: ``str``

        :param genericName:
            the generic name from the base parameter list, may be used to create the model name
        :type  genericName: ``str``

        :param model:
            an instance of the model class to use
        :type   model: ``class instance`` inherited from :class:`cq_base_model.PartBase`

        :param keepDocument:
            * True: the FreeCAD document will shown after it is created, optionally with kicadStepUptools activated
            * False: the document window will be closed
        :type  keepDocument: ``boolean``

        """

        global kicadStepUptools

        modelName = model.makeModelName(genericName)

        FreeCAD.Console.PrintMessage('\r\n' + modelName)

        if model.make_me != True:
            FreeCAD.Console.PrintMessage(' - not made')
            return
        CheckedmodelName = modelName.replace('.',
                                             '').replace('-', '_').replace(
                                                 '(', '').replace(')', '')
        FreeCAD.newDocument(CheckedmodelName)
        FreeCAD.setActiveDocument(CheckedmodelName)
        Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

        model.make()

        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)

        material_substitutions = {}

        for i in range(0, len(objs)):
            Color_Objects(
                Gui, objs[i], shaderColors.named_colors[
                    model.color_keys[i]].getDiffuseFloat())
            material_substitutions[Gui.ActiveDocument.getObject(
                objs[i].Name).DiffuseColor[0][:-1]] = model.color_keys[i]

        if verbose:
            expVRML.say(material_substitutions)
            expVRML.say(model.color_keys)
            expVRML.say(model.offsets)

        doc.Label = CheckedmodelName

        while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                             objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)

        objs[0].Label = CheckedmodelName
        restore_Main_Tools()

        #rotate if required
        if (model.rotation != 0):
            z_RotateObject(doc, model.rotation)

        s = objs[0].Shape
        shape = s.copy()
        shape.Placement = s.Placement
        shape.translate(model.offsets)
        objs[0].Placement = shape.Placement

        out_dir = models_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        # Export STEP model
        exportSTEP(doc, modelName, out_dir)

        license_txt = list(
            add_license.LIST_int_license if self.license is None else
            self.license)  # make a copy to avoid modifying the original
        license_txt.append("")
        license_txt.append("")
        if self.scriptsource != "" and self.script_dir is not None:
            license_txt.append("Generated by script, source at:")
            license_txt.append(self.scriptsource +
                               self.script_dir.split(os.sep)[-1])
            license_txt.append("")

        if verbose:
            expVRML.say("")

        add_license.addLicenseToStep(out_dir + os.sep, modelName + ".step",
                                     license_txt, model.licAuthor,
                                     model.licEmail, model.licOrgSys,
                                     model.licOrg, model.licPreProc)

        # Scale and export Vrml model
        scale = 1.0 / 2.54
        objs = GetListOfObjects(FreeCAD, doc)
        if verbose:
            expVRML.say(
                "######################################################################"
            )
            expVRML.say(objs)
            expVRML.say(
                "######################################################################"
            )
        export_objects, used_color_keys = expVRML.determineColors(
            Gui, objs, material_substitutions)
        export_file_name = out_dir + os.sep + modelName + '.wrl'
        colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
        expVRML.writeVRMLFile(colored_meshes, export_file_name,
                              used_color_keys, license_txt)

        # Save the doc in native FC format
        out_dir = self.models_src_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        saveFCdoc(FreeCAD, Gui, doc, modelName, out_dir)

        # Place on footprint for verification
        if keepDocument and model.footprints_dir is not None and self.footprints_dir is not None:

            sys.argv = [
                "fc", "dummy", self.footprints_dir + os.sep +
                model.footprints_dir + os.sep + modelName, "savememory"
            ]

            if verbose:
                expVRML.say('Footprint: ' + sys.argv[2])

            if self.kicadStepUptools is None:
                try:
                    import kicadStepUptools
                    expVRML.say("ksu present!")
                    self.kicadStepUptools = True
                    kicadStepUptools.KSUWidget.close()
                    #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                    #kicadStepUptools.KSUWidget.destroy()
                    #for i in QtGui.qApp.topLevelWidgets():
                    #    if i.objectName() == "kicadStepUp":
                    #        i.deleteLater()
                    #kicadStepUptools.KSUWidget.close()
                except:
                    self.kicadStepUptools = False
                    expVRML.say("ksu not present")

            if not self.kicadStepUptools == False:
                kicadStepUptools.KSUWidget.close()
                reload_lib(kicadStepUptools)
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()

        #display BBox
        if keepDocument:
            Gui.activateWorkbench("PartWorkbench")
            Gui.SendMsgToActiveView("ViewFit")
            Gui.activeDocument().activeView().viewAxometric()
        else:
            doc = FreeCAD.ActiveDocument
            FreeCAD.closeDocument(doc.Name)
def main(arg_model_to_build):
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')
    model_to_build=arg_model_to_build

    if model_to_build == "all":
        variants = all_params.keys()
        FreeCAD.Console.PrintMessage(variants)
        FreeCAD.Console.PrintMessage('\r\n')
    else:
        variants = [model_to_build]
    for variant in variants:
        FreeCAD.Console.PrintMessage('\r\n'+variant)
        if not variant in all_params:
            print("Parameters for %s doesn't exist in 'all_params', skipping." % variant)
            continue
        ModelName = all_params[variant].modelName
        Newdoc = FreeCAD.newDocument(ModelName)
        App.setActiveDocument(ModelName)
        Gui.ActiveDocument=Gui.getDocument(ModelName)
        case, top, pins = make_chip(all_params[variant])
        color_attr=case_color+(0,)
        show(case, color_attr)
        #FreeCAD.Console.PrintMessage(pins_color)

        color_attr=top_color+(0,)
        show(top, color_attr)

        color_attr=pins_color+(0,)
        #FreeCAD.Console.PrintMessage(color_attr)
        show(pins, color_attr)
        doc = FreeCAD.ActiveDocument
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        doc = FreeCAD.ActiveDocument
        objs=GetListOfObjects(FreeCAD, doc)
        objs[1].Label="Fusion2"
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        doc.Label=ModelName
        objs=GetListOfObjects(FreeCAD, doc)
        objs[0].Label=ModelName
        restore_Main_Tools()
        #rotate if required
        if (all_params[variant].rotation!=0):
            rot= all_params[variant].rotation
            z_RotateObject(doc, rot)
        script_dir=os.path.dirname(os.path.realpath(__file__))
        out_dir=script_dir+destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
            #out_dir="./generated_qfp/"
        # export STEP model
        exportSTEP(doc,ModelName,out_dir)

        # scale and export Vrml model
        scale=0.3937001
        exportVRML(doc,ModelName,scale,out_dir)

        # Save the doc in Native FC format
        saveFCdoc(App, Gui, doc, ModelName,out_dir)
        #display BBox

        FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True