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 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 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()
        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

        ## run()
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