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

            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)

            step_path = os.path.join(out_dir, ModelName + u'.step')
            if check_Model == True:
                step_path = out_dir + '/' + ModelName + ".step"
                runGeometryCheck(App,
                                 Gui,
                                 step_path,
                                 log,
                                 ModelName,
                                 save_memory=save_memory)
Beispiel #3
0
def export_one_part(modul, variant, configuration, log, with_plug=False):
    if not variant in modul.all_params:
        FreeCAD.Console.PrintMessage(
            "Parameters for %s doesn't exist in 'M.all_params', skipping." %
            variant)
        return
    LIST_license[0] = "Copyright (C) " + datetime.now().strftime(
        "%Y") + ", " + STR_licAuthor

    params = modul.all_params[variant]
    series_params = modul.seriesParams
    series = series_params.series_name

    subseries, connector_style = params.series_name.split('-')
    pitch_mpn = '-{:g}'.format(params.pin_pitch)
    if series[0] == 'MSTB':
        pitch_mpn = ''
        if params.pin_pitch == 5.08:
            pitch_mpn = '-5,08'
        elif params.pin_pitch == 7.62:
            pitch_mpn = '-7,62'
    lib_name = configuration['lib_name_format_str'].format(
        series=series[0], style=series[1], pitch=params.pin_pitch)
    mpn = configuration['mpn_format_string'].format(subseries=subseries,
                                                    style=connector_style,
                                                    rating=series[1],
                                                    num_pins=params.num_pins,
                                                    pitch=pitch_mpn)
    FileName = configuration['fp_name_format_string'].format(
        man=configuration['manufacturer'],
        series=series[0],
        mpn=mpn,
        num_rows=1,
        num_pins=params.num_pins,
        pitch=params.pin_pitch,
        orientation=configuration['orientation_str'][1]
        if params.angled else configuration['orientation_str'][0],
        flanged=configuration['flanged_str'][1]
        if params.flanged else configuration['flanged_str'][0],
        mount_hole=configuration['mount_hole_str'][1]
        if params.mount_hole else configuration['mount_hole_str'][0])

    destination_dir = global_3dpath + lib_name
    if with_plug:
        destination_dir += "__with_plug"
    destination_dir += ".3dshapes"

    ModelName = variant
    ModelName = ModelName.replace(".", "_")
    Newdoc = FreeCAD.newDocument(ModelName)
    App.setActiveDocument(ModelName)
    App.ActiveDocument = App.getDocument(ModelName)
    Gui.ActiveDocument = Gui.getDocument(ModelName)
    #App.setActiveDocument(ModelName)
    #Gui.ActiveDocument=Gui.getDocument(ModelName)
    (pins, body, insert, mount_screw, plug,
     plug_screws) = modul.generate_part(variant, with_plug)

    color_attr = body_color + (0, )
    show(body, color_attr)

    color_attr = pins_color + (0, )
    show(pins, color_attr)

    if insert is not None:
        color_attr = insert_color + (0, )
        show(insert, color_attr)
    if mount_screw is not None:
        color_attr = screw_color + (0, )
        show(mount_screw, color_attr)
    if plug is not None:
        color_attr = body_color + (0, )
        show(plug, color_attr)

        color_attr = screw_color + (0, )
        show(plug_screws, color_attr)

    doc = FreeCAD.ActiveDocument
    doc.Label = ModelName
    objs = FreeCAD.ActiveDocument.Objects
    FreeCAD.Console.PrintMessage(objs)

    i = 0
    objs[i].Label = ModelName + "__body"
    i += 1
    objs[i].Label = ModelName + "__pins"
    i += 1
    if insert is not None:
        objs[i].Label = ModelName + "__thread_insert"
        i += 1
    if mount_screw is not None:
        objs[i].Label = ModelName + "__mount_screw"
        i += 1
    if plug is not None:
        objs[i].Label = ModelName + "__plug"
        i += 1
        objs[i].Label = ModelName + "__plug_screws"
    restore_Main_Tools()

    out_dir = destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = [body_color_key, pins_color_key]
    export_file_name = destination_dir + os.sep + FileName + '.wrl'

    export_objects = []
    i = 0
    export_objects.append(
        expVRML.exportObject(freecad_object=objs[i],
                             shape_color=body_color_key,
                             face_colors=None))
    i += 1
    export_objects.append(
        expVRML.exportObject(freecad_object=objs[i],
                             shape_color=pins_color_key,
                             face_colors=None))
    i += 1
    if insert is not None:
        export_objects.append(
            expVRML.exportObject(freecad_object=objs[i],
                                 shape_color=insert_color_key,
                                 face_colors=None))
        used_color_keys.append(insert_color_key)
        i += 1
    if mount_screw is not None:
        export_objects.append(
            expVRML.exportObject(freecad_object=objs[i],
                                 shape_color=screw_color_key,
                                 face_colors=None))
        used_color_keys.append(screw_color_key)
        i += 1
    if plug is not None:
        export_objects.append(
            expVRML.exportObject(freecad_object=objs[i],
                                 shape_color=body_color_key,
                                 face_colors=None))
        i += 1
        export_objects.append(
            expVRML.exportObject(freecad_object=objs[i],
                                 shape_color=screw_color_key,
                                 face_colors=None))
    scale = 1 / 2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD,
                                   FreeCADGui,
                                   ModelName,
                                   objs,
                                   keepOriginals=True)

    exportSTEP(doc, FileName, out_dir, fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

    L.addLicenseToStep(out_dir, '{:s}.step'.format(FileName), LIST_license,\
        STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc)

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

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, FileName, out_dir)
    if save_memory == True or check_Model == True:
        closeCurrentDoc(ModelName)

    if check_Model == True:
        runGeometryCheck(App,
                         Gui,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
Beispiel #4
0
    def export_one_part(params, mpn, log):
        print('\n##########################################################')

        if LICENCE_Info.LIST_license[0] == "":
            LIST_license = L.LIST_int_license
            # LIST_license.append("")
        else:
            LIST_license = LICENCE_Info.LIST_license

        LIST_license[0] = "Copyright (C) " + datetime.now().strftime(
            "%Y") + ", " + LICENCE_Info.STR_licAuthor

        fp_params = params['footprint']
        mech_params = params['mechanical']
        part_params = params['parts'][mpn]

        if 'id' in mech_params:
            size = str(mech_params['id'])
        elif 'ext_thread' in mech_params:
            size = str(mech_params['ext_thread']['od'])

        if 'M' not in size:
            size = "{}mm".format(size)

        td = ""
        size_prefix = ""
        if 'thread_depth' in part_params:
            td = "_ThreadDepth{}mm".format(part_params['thread_depth'])
        elif 'ext_thread' in mech_params:
            size_prefix = 'External'

        h = part_params['h'] if 'h' in part_params else part_params['h1']

        suffix = ''
        if 'suffix' in params:
            suffix = '_{}'.format(params['suffix'])

        FileName = "Mounting_Wuerth_{series}-{size_prefix}{size}_H{h}mm{td}{suffix}_{mpn}".format(
            size=size,
            h=h,
            mpn=mpn,
            td=td,
            size_prefix=size_prefix,
            series=params['series_prefix'],
            suffix=suffix)

        lib_name = "Mounting_Wuerth"

        ModelName = FileName.replace('.', '').replace('-', '_').replace(
            '(', '').replace(')', '')

        FreeCAD.Console.PrintMessage('\r\n' + FileName + '\r\n')
        #FileName = modul.all_params[variant].file_name
        Newdoc = FreeCAD.newDocument(ModelName)
        print(Newdoc.Label)
        App.setActiveDocument(ModelName)
        App.ActiveDocument = App.getDocument(ModelName)
        Gui.ActiveDocument = Gui.getDocument(ModelName)

        color_keys = ["metal grey pins"]
        colors = [
            shaderColors.named_colors[key].getDiffuseInt()
            for key in color_keys
        ]

        cq_obj_data = generate(id=mech_params.get('id'),
                               od=mech_params['od'],
                               od1=mech_params.get('od1'),
                               h1=mech_params.get('h1',
                                                  part_params.get('h1', 0)),
                               h=part_params.get('h', mech_params.get('h')),
                               td=part_params.get('thread_depth'),
                               dd=part_params.get('drill_depth'),
                               id1=mech_params.get('id1'),
                               t1=mech_params.get('t1', 0),
                               ext_thread=mech_params.get('ext_thread'))

        color_i = colors[0] + (0, )
        show(cq_obj_data, color_i)

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

        objs[0].Label = ModelName

        restore_Main_Tools()

        out_dir = '{:s}{:s}.3dshapes'.format(global_3dpath, lib_name)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        used_color_keys = color_keys
        export_file_name = out_dir + os.sep + FileName + '.wrl'

        export_objects = []
        print('objs')
        print(objs)
        for i in range(len(objs)):
            export_objects.append(
                expVRML.exportObject(freecad_object=objs[i],
                                     shape_color=color_keys[i],
                                     face_colors=None))

        scale = 1 / 2.54
        colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
        expVRML.writeVRMLFile(colored_meshes, export_file_name,
                              used_color_keys, LIST_license)

        exportSTEP(doc, FileName, out_dir, objs[0])

        step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

        L.addLicenseToStep(out_dir, '{:s}.step'.\
            format(FileName), LIST_license,
                LICENCE_Info.STR_licAuthor,
                LICENCE_Info.STR_licEmail,
                LICENCE_Info.STR_licOrgSys,
                LICENCE_Info.STR_licPreProc)

        FreeCAD.activeDocument().recompute()

        saveFCdoc(App, Gui, doc, FileName, 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,
                             step_path,
                             log,
                             ModelName,
                             save_memory=save_memory)
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)
def export_one_part(module, pincount, configuration, log):
    series_definition = module.series_params

    if module.LICENCE_Info.LIST_license[0]=="":
        LIST_license=L.LIST_int_license
        LIST_license.append("")
    else:
        LIST_license=module.LICENCE_Info.LIST_license

    LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + module.LICENCE_Info.STR_licAuthor
    pins_per_row = pincount/series_definition.number_of_rows
    mpn = series_definition.mpn_format_string.format(pincount=pincount, pins_per_row=pins_per_row)


    orientation = configuration['orientation_options'][series_definition.orientation]
    format_string = getattr(series_definition, 'fp_name_format_string',
        configuration[getattr(series_definition, 'fp_name_format', 'fp_name_format_string')])
    FileName = format_string.format(man=series_definition.manufacturer,
            series=series_definition.series,
            mpn=mpn, num_rows=series_definition.number_of_rows, pins_per_row=pins_per_row,
            pins=pincount, pitch=series_definition.pitch, orientation=orientation,
            mount_pin=series_definition.mount_pin)
    FileName = FileName.replace('__', '_')

    lib_name = configuration['lib_name_format_string'].format(man=series_definition.manufacturer)
    fc_mpn = mpn.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')

    ModelName = '{:s}_{:s}'.format(series_definition.manufacturer, fc_mpn) # For some reason the Model name can not start with a number.

    FreeCAD.Console.PrintMessage('\r\n'+FileName+'\r\n')
    #FileName = modul.all_params[variant].file_name
    Newdoc = FreeCAD.newDocument(ModelName)
    print(Newdoc.Label)
    App.setActiveDocument(ModelName)
    App.ActiveDocument=App.getDocument(ModelName)
    Gui.ActiveDocument=Gui.getDocument(ModelName)

    color_keys = series_definition.color_keys
    obj_suffixes = series_definition.obj_suffixes
    colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys]

    cq_obj_data = module.generate_part(pincount)


    for i in range(len(cq_obj_data)):
        color_i = colors[i] + (0,)
        show(cq_obj_data[i], color_i)


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


    for i in range(len(objs)):
        objs[i].Label = ModelName + obj_suffixes[i]


    restore_Main_Tools()

    out_dir='{:s}{:s}.3dshapes'.format(global_3dpath, lib_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = color_keys
    export_file_name=out_dir+os.sep+FileName+'.wrl'

    export_objects = []
    for i in range(len(objs)):
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=color_keys[i],
                face_colors=None))

    scale=1/2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui,
                     ModelName, objs, keepOriginals=True)
    exportSTEP(doc,FileName,out_dir,fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

    L.addLicenseToStep(out_dir, '{:s}.step'.\
        format(FileName), LIST_license,
            module.LICENCE_Info.STR_licAuthor,
            module.LICENCE_Info.STR_licEmail,
            module.LICENCE_Info.STR_licOrgSys,
            module.LICENCE_Info.STR_licPreProc)

    FreeCAD.activeDocument().recompute()

    saveFCdoc(App, Gui, doc, FileName, 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, step_path,
            log, ModelName, save_memory=save_memory)
Beispiel #7
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)
def export_one_part(module, params, configuration, log):
    series_definition = module.series_params

    if module.LICENCE_Info.LIST_license[0]=="":
        LIST_license=L.LIST_int_license
        LIST_license.append("")
    else:
        LIST_license=module.LICENCE_Info.LIST_license

    LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + module.LICENCE_Info.STR_licAuthor

    lib_name = configuration['lib_name_format_string'].format(suffix=lib_suffix)


    FileName = module.getName(params, configuration)
    ModelName = FileName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')

    FreeCAD.Console.PrintMessage('\r\n'+FileName+'\r\n')
    #FileName = modul.all_params[variant].file_name
    Newdoc = FreeCAD.newDocument(ModelName)
    print(Newdoc.Label)
    App.setActiveDocument(ModelName)
    App.ActiveDocument=App.getDocument(ModelName)
    Gui.ActiveDocument=Gui.getDocument(ModelName)

    if hasattr(params, 'color_keys'):
        color_keys = params.color_keys
    else:
        color_keys = series_definition.color_keys
    obj_suffixes = series_definition.obj_suffixes
    colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys]

    cq_obj_data = module.generate_part(params)


    for i in range(len(cq_obj_data)):
        color_i = colors[i] + (0,)
        show(cq_obj_data[i], color_i)


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


    for i in range(len(objs)):
        objs[i].Label = ModelName + obj_suffixes[i]


    restore_Main_Tools()

    if stop_after_coloring:
        return

    out_dir='{:s}{:s}.3dshapes'.format(global_3dpath, lib_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = color_keys
    export_file_name=out_dir+os.sep+FileName+'.wrl'

    export_objects = []
    for i in range(len(objs)):
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=color_keys[i],
                face_colors=None))

    scale=1/2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale, mesh_deviation)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui,
                     ModelName, objs, keepOriginals=True)
    exportSTEP(doc,FileName,out_dir,fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

    L.addLicenseToStep(out_dir, '{:s}.step'.\
        format(FileName), LIST_license,
            module.LICENCE_Info.STR_licAuthor,
            module.LICENCE_Info.STR_licEmail,
            module.LICENCE_Info.STR_licOrgSys,
            module.LICENCE_Info.STR_licPreProc)

    FreeCAD.activeDocument().recompute()

    saveFCdoc(App, Gui, doc, FileName, 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:
        docu = FreeCAD.ActiveDocument
        FreeCAD.Console.PrintMessage('close document {}\r\n'.format(docu.Name))
        FreeCAD.closeDocument(docu.Name)

    if check_Model==True:
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)
Beispiel #9
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])
    casetop = make_case_top(all_params[variant])
    pins = make_pins(all_params[variant])

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

    body_color_key = all_params[variant].body_color_key
    body_top_color_key = all_params[variant].body_top_color_key
    pin_color_key = all_params[variant].pin_color_key


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

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],body_top_color)
    Color_Objects(Gui,objs[2],pin_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_body_top=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]

    material_substitutions={
        col_body[:-1]:body_color_key,
        col_body_top[:-1]:body_top_color_key,
        col_pin[:-1]:pin_color_key
    }

    expVRML.say(material_substitutions)
    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

    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+os.sep+all_params[variant].dest_dir_prefix

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=modelName)
    exportSTEP(doc, modelName, out_dir)


    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")

    Lic.addLicenseToStep(out_dir, '{:s}.step'.format(modelName),
            LIST_license,
            cq_parameters.LICENCE_Info.STR_licAuthor,
            cq_parameters.LICENCE_Info.STR_licEmail,
            cq_parameters.LICENCE_Info.STR_licOrgSys,
            cq_parameters.LICENCE_Info.STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    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)

    # Save the doc in Native FC format
    doc.recompute()
    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:
        FreeCAD.closeDocument(doc.Name)
        os.remove (out_dir+os.sep+modelName+'.FCStd')

    if check_Model==True:
        with open(out_dir+os.sep+check_log_file, 'a+') as log:
            log.write('# Check report for Molex 3d model genration\n')
            runGeometryCheck(App, Gui, step_path, log, modelName, save_memory=save_memory)
            log.close()
Beispiel #10
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)
Beispiel #11
0
def MakeHeader(n, isAngled, log, highDetail=False):
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")

    LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + STR_licAuthor

    name = HeaderName(n, isAngled)
    print('\n############ ' + name + ' #############\n')

    lib_name='Connector_IDC'


    full_path=os.path.realpath(__file__)
    sub_dir_name =full_path.split(os.sep)[-2]
    sub_path = full_path.split(sub_dir_name)[0]
    models_dir=sub_path+"_3Dmodels"+os.sep
    #models_dir=script_dir+"/../_3Dmodels"

    out_dir=models_dir+'{:s}.3dshapes'.format(lib_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

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

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

    base = MakeBase(n, highDetail)

    if (isAngled):
        pins = MakeAnglePinRow(n, -3, 5.94, 12.38, highDetail)
        pins = pins.union(MakeAnglePinRow(n, -3, 3.40, 9.84, highDetail).translate((2.54,0,0)))
        # rotate the base into the angled position
        base = base.rotate((0,0,0),(0,1,0),90).translate((4.13,0,5.94))
    else:
        pins = MakePinRow(n, -3.0, 8.0)
        pins = pins.union(MakePinRow(n, -3.0, 8.0).translate((2.54,0,0)))


    colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys]

    cq_obj_data = [base, pins]
    obj_suffixes = ['__base', '__pins']


    for i in range(len(cq_obj_data)):
        color_i = colors[i] + (0,)
        show(cq_obj_data[i], color_i)


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

    for i in range(len(objs)):
        objs[i].Label = docname + obj_suffixes[i]

    restore_Main_Tools()

    used_color_keys = color_keys
    export_file_name=out_dir+os.sep+name+'.wrl'

    export_objects = []
    for i in range(len(objs)):
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=color_keys[i],
                face_colors=None))

    scale=1/2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui,
                     doc.Label, objs, keepOriginals=True)
    exportSTEP(doc,name,out_dir,fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=name)

    Lic.addLicenseToStep(out_dir, '{:s}.step'.\
        format(name), LIST_license,
            STR_licAuthor,
            STR_licEmail,
            STR_licOrgSys,
            STR_licPreProc)

    FreeCAD.activeDocument().recompute()
    print("Safe to: {}".format(out_dir))
    saveFCdoc(App, Gui, doc, name, 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
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        runGeometryCheck(App, Gui, step_path,
            log, name, save_memory=save_memory)
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 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)
Beispiel #14
0
def export_one_part(module, pincount, configuration, log):
    series_definition = module.series_params

    if module.LICENCE_Info.LIST_license[0] == "":
        LIST_license = L.LIST_int_license
        LIST_license.append("")
    else:
        LIST_license = module.LICENCE_Info.LIST_license

    LIST_license[0] = "Copyright (C) " + datetime.now().strftime(
        "%Y") + ", " + module.LICENCE_Info.STR_licAuthor
    pins_per_row = pincount / series_definition.number_of_rows
    mpn = series_definition.mpn_format_string.format(pincount=pincount,
                                                     pins_per_row=pins_per_row)

    orientation = configuration['orientation_options'][
        series_definition.orientation]
    format_string = getattr(
        series_definition, 'fp_name_format_string',
        configuration[getattr(series_definition, 'fp_name_format',
                              'fp_name_format_string')])
    FileName = format_string.format(man=series_definition.manufacturer,
                                    series=series_definition.series,
                                    mpn=mpn,
                                    num_rows=series_definition.number_of_rows,
                                    pins_per_row=pins_per_row,
                                    pins=pincount,
                                    pitch=series_definition.pitch,
                                    orientation=orientation,
                                    mount_pin=series_definition.mount_pin)
    FileName = FileName.replace('__', '_')

    lib_name = configuration['lib_name_format_string'].format(
        man=series_definition.manufacturer)
    fc_mpn = mpn.replace('.', '').replace('-',
                                          '_').replace('(',
                                                       '').replace(')', '')

    ModelName = '{:s}_{:s}'.format(
        series_definition.manufacturer,
        fc_mpn)  # For some reason the Model name can not start with a number.

    FreeCAD.Console.PrintMessage('\r\n' + FileName + '\r\n')
    #FileName = modul.all_params[variant].file_name
    Newdoc = FreeCAD.newDocument(ModelName)
    print(Newdoc.Label)
    App.setActiveDocument(ModelName)
    App.ActiveDocument = App.getDocument(ModelName)
    Gui.ActiveDocument = Gui.getDocument(ModelName)

    color_keys = series_definition.color_keys
    obj_suffixes = series_definition.obj_suffixes
    colors = [
        shaderColors.named_colors[key].getDiffuseInt() for key in color_keys
    ]

    cq_obj_data = module.generate_part(pincount)

    for i in range(len(cq_obj_data)):
        color_i = colors[i] + (0, )
        show(cq_obj_data[i], color_i)

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

    for i in range(len(objs)):
        objs[i].Label = ModelName + obj_suffixes[i]

    restore_Main_Tools()

    out_dir = '{:s}{:s}.3dshapes'.format(global_3dpath, lib_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = color_keys
    export_file_name = out_dir + os.sep + FileName + '.wrl'

    export_objects = []
    for i in range(len(objs)):
        export_objects.append(
            expVRML.exportObject(freecad_object=objs[i],
                                 shape_color=color_keys[i],
                                 face_colors=None))

    scale = 1 / 2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD,
                                   FreeCADGui,
                                   ModelName,
                                   objs,
                                   keepOriginals=True)
    exportSTEP(doc, FileName, out_dir, fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

    L.addLicenseToStep(out_dir, '{:s}.step'.\
        format(FileName), LIST_license,
            module.LICENCE_Info.STR_licAuthor,
            module.LICENCE_Info.STR_licEmail,
            module.LICENCE_Info.STR_licOrgSys,
            module.LICENCE_Info.STR_licPreProc)

    FreeCAD.activeDocument().recompute()

    saveFCdoc(App, Gui, doc, FileName, 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,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
def export_one_part(module, params, configuration, log):
    series_definition = module.series_params

    if module.LICENCE_Info.LIST_license[0] == "":
        LIST_license = L.LIST_int_license
        LIST_license.append("")
    else:
        LIST_license = module.LICENCE_Info.LIST_license

    LIST_license[0] = "Copyright (C) " + datetime.now().strftime(
        "%Y") + ", " + module.LICENCE_Info.STR_licAuthor

    lib_name = configuration['lib_name_format_string'].format(
        suffix=lib_suffix)

    FileName = module.getName(params, configuration)
    ModelName = FileName.replace('.',
                                 '').replace('-',
                                             '_').replace('(',
                                                          '').replace(')', '')

    FreeCAD.Console.PrintMessage('\r\n' + FileName + '\r\n')
    #FileName = modul.all_params[variant].file_name
    Newdoc = FreeCAD.newDocument(ModelName)
    print(Newdoc.Label)
    App.setActiveDocument(ModelName)
    App.ActiveDocument = App.getDocument(ModelName)
    Gui.ActiveDocument = Gui.getDocument(ModelName)

    if hasattr(params, 'color_keys'):
        color_keys = params.color_keys
    else:
        color_keys = series_definition.color_keys
    obj_suffixes = series_definition.obj_suffixes
    colors = [
        shaderColors.named_colors[key].getDiffuseInt() for key in color_keys
    ]

    cq_obj_data = module.generate_part(params)

    for i in range(len(cq_obj_data)):
        color_i = colors[i] + (0, )
        show(cq_obj_data[i], color_i)

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

    for i in range(len(objs)):
        objs[i].Label = ModelName + obj_suffixes[i]

    restore_Main_Tools()

    if stop_after_coloring:
        return

    out_dir = '{:s}{:s}.3dshapes'.format(global_3dpath, lib_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = color_keys
    export_file_name = out_dir + os.sep + FileName + '.wrl'

    export_objects = []
    for i in range(len(objs)):
        export_objects.append(
            expVRML.exportObject(freecad_object=objs[i],
                                 shape_color=color_keys[i],
                                 face_colors=None))

    scale = 1 / 2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale,
                                            mesh_deviation)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD,
                                   FreeCADGui,
                                   ModelName,
                                   objs,
                                   keepOriginals=True)
    exportSTEP(doc, FileName, out_dir, fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

    L.addLicenseToStep(out_dir, '{:s}.step'.\
        format(FileName), LIST_license,
            module.LICENCE_Info.STR_licAuthor,
            module.LICENCE_Info.STR_licEmail,
            module.LICENCE_Info.STR_licOrgSys,
            module.LICENCE_Info.STR_licPreProc)

    FreeCAD.activeDocument().recompute()

    saveFCdoc(App, Gui, doc, FileName, 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:
        docu = FreeCAD.ActiveDocument
        FreeCAD.Console.PrintMessage('close document {}\r\n'.format(docu.Name))
        FreeCAD.closeDocument(docu.Name)

    if check_Model == True:
        runGeometryCheck(App,
                         Gui,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
def export_one_part(modul, variant, configuration, log, with_plug=False):
    if not variant in modul.all_params:
        FreeCAD.Console.PrintMessage("Parameters for %s doesn't exist in 'M.all_params', skipping." % variant)
        return
    LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + STR_licAuthor

    params = modul.all_params[variant]
    series_params = modul.seriesParams
    series = series_params.series_name

    subseries, connector_style = params.series_name.split('-')
    pitch_mpn = '-{:g}'.format(params.pin_pitch)
    if series[0] == 'MSTB':
        pitch_mpn = ''
        if params.pin_pitch == 5.08:
            pitch_mpn = '-5,08'
        elif params.pin_pitch == 7.62:
            pitch_mpn = '-7,62'
    lib_name = configuration['lib_name_format_str'].format(series=series[0], style=series[1], pitch=params.pin_pitch)
    mpn = configuration['mpn_format_string'].format(subseries=subseries, style = connector_style,
        rating=series[1], num_pins=params.num_pins, pitch=pitch_mpn)
    FileName = configuration['fp_name_format_string'].format(man = configuration['manufacturer'],
        series = series[0], mpn = mpn, num_rows = 1,
        num_pins = params.num_pins, pitch = params.pin_pitch,
        orientation = configuration['orientation_str'][1] if params.angled else configuration['orientation_str'][0],
        flanged = configuration['flanged_str'][1] if params.flanged else configuration['flanged_str'][0],
        mount_hole = configuration['mount_hole_str'][1] if params.mount_hole else configuration['mount_hole_str'][0])

    destination_dir=global_3dpath+lib_name
    if with_plug:
        destination_dir += "__with_plug"
    destination_dir+=".3dshapes"

    ModelName = variant
    ModelName = ModelName.replace(".","_")
    Newdoc = FreeCAD.newDocument(ModelName)
    App.setActiveDocument(ModelName)
    App.ActiveDocument=App.getDocument(ModelName)
    Gui.ActiveDocument=Gui.getDocument(ModelName)
    #App.setActiveDocument(ModelName)
    #Gui.ActiveDocument=Gui.getDocument(ModelName)
    (pins, body, insert, mount_screw, plug, plug_screws) = modul.generate_part(variant, with_plug)

    color_attr = body_color + (0,)
    show(body, color_attr)

    color_attr = pins_color + (0,)
    show(pins, color_attr)

    if insert is not None:
        color_attr = insert_color + (0,)
        show(insert, color_attr)
    if mount_screw is not None:
        color_attr = screw_color + (0,)
        show(mount_screw, color_attr)
    if plug is not None:
        color_attr = body_color + (0,)
        show(plug, color_attr)

        color_attr = screw_color + (0,)
        show(plug_screws, color_attr)

    doc = FreeCAD.ActiveDocument
    doc.Label=ModelName
    objs=FreeCAD.ActiveDocument.Objects
    FreeCAD.Console.PrintMessage(objs)

    i=0
    objs[i].Label = ModelName + "__body"
    i+=1
    objs[i].Label = ModelName + "__pins"
    i+=1
    if insert is not None:
        objs[i].Label = ModelName + "__thread_insert"
        i+=1
    if mount_screw is not None:
        objs[i].Label = ModelName + "__mount_screw"
        i+=1
    if plug is not None:
        objs[i].Label = ModelName + "__plug"
        i+=1
        objs[i].Label = ModelName + "__plug_screws"
    restore_Main_Tools()

    out_dir=destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = [body_color_key, pins_color_key]
    export_file_name=destination_dir+os.sep+FileName+'.wrl'

    export_objects = []
    i=0
    export_objects.append(expVRML.exportObject(freecad_object = objs[i],
            shape_color=body_color_key,
            face_colors=None))
    i+=1
    export_objects.append(expVRML.exportObject(freecad_object = objs[i],
            shape_color=pins_color_key,
            face_colors=None))
    i+=1
    if insert is not None:
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=insert_color_key,
                face_colors=None))
        used_color_keys.append(insert_color_key)
        i+=1
    if mount_screw is not None:
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=screw_color_key,
                face_colors=None))
        used_color_keys.append(screw_color_key)
        i+=1
    if plug is not None:
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=body_color_key,
                face_colors=None))
        i+=1
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=screw_color_key,
                face_colors=None))
    scale=1/2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui,
                     ModelName, objs, keepOriginals=True)

    exportSTEP(doc,FileName,out_dir,fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName)

    L.addLicenseToStep(out_dir, '{:s}.step'.format(FileName), LIST_license,\
        STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc)

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


    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, FileName, out_dir)
    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)
def MakeHeader(n, isAngled, log, highDetail=False):
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")

    LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + STR_licAuthor

    name = HeaderName(n, isAngled)
    print('\n############ ' + name + ' #############\n')

    lib_name='Connector_IDC'


    full_path=os.path.realpath(__file__)
    sub_dir_name =full_path.split(os.sep)[-2]
    sub_path = full_path.split(sub_dir_name)[0]
    models_dir=sub_path+"_3Dmodels"+os.sep
    #models_dir=script_dir+"/../_3Dmodels"

    out_dir=models_dir+'{:s}.3dshapes'.format(lib_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

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

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

    base = MakeBase(n, highDetail)

    if (isAngled):
        pins = MakeAnglePinRow(n, -3, 5.94, 12.38, highDetail)
        pins = pins.union(MakeAnglePinRow(n, -3, 3.40, 9.84, highDetail).translate((2.54,0,0)))
        # rotate the base into the angled position
        base = base.rotate((0,0,0),(0,1,0),90).translate((4.13,0,5.94))
    else:
        pins = MakePinRow(n, -3.0, 8.0)
        pins = pins.union(MakePinRow(n, -3.0, 8.0).translate((2.54,0,0)))


    colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys]

    cq_obj_data = [base, pins]
    obj_suffixes = ['__base', '__pins']


    for i in range(len(cq_obj_data)):
        color_i = colors[i] + (0,)
        show(cq_obj_data[i], color_i)


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

    for i in range(len(objs)):
        objs[i].Label = docname + obj_suffixes[i]

    restore_Main_Tools()

    used_color_keys = color_keys
    export_file_name=out_dir+os.sep+name+'.wrl'

    export_objects = []
    for i in range(len(objs)):
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=color_keys[i],
                face_colors=None))

    scale=1/2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui,
                     doc.Label, objs, keepOriginals=True)
    exportSTEP(doc,name,out_dir,fusion)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=name)

    Lic.addLicenseToStep(out_dir, '{:s}.step'.\
        format(name), LIST_license,
            STR_licAuthor,
            STR_licEmail,
            STR_licOrgSys,
            STR_licPreProc)

    FreeCAD.activeDocument().recompute()
    print("Safe to: {}".format(out_dir))
    saveFCdoc(App, Gui, doc, name, 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
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        runGeometryCheck(App, Gui, step_path,
            log, name, save_memory=save_memory)