コード例 #1
0
ファイル: gcode_pre.py プロジェクト: mikeprice99/FreeCAD
def insert(filename, docname):
    """called when freecad imports a file"""
    PathLog.track(filename)
    gfile = pythonopen(filename)
    gcode = gfile.read()
    gfile.close()

    # Regular expression to match tool changes in the format 'M6 Tn'
    p = re.compile("[mM]+?\s?0?6\s?T\d*\s")

    # split the gcode on tool changes
    paths = re.split("([mM]+?\s?0?6\s?T\d*\s)", gcode)

    # iterate the gcode sections and add customs for each
    toolnumber = 0

    for path in paths:

        # if the section is a tool change, extract the tool number
        m = p.match(path)
        if m:
            toolnumber = int(m.group().split("T")[-1])
            continue

        # Parse the gcode and throw away any empty lists
        gcode = parse(path)
        if len(gcode) == 0:
            continue

        # Create a custom and viewobject
        obj = PathCustom.Create("Custom")
        res = PathOpGui.CommandResources(
            "Custom",
            PathCustom.Create,
            PathCustomGui.TaskPanelOpPage,
            "Path_Custom",
            QT_TRANSLATE_NOOP("Path_Custom", "Custom"),
            "",
            "",
        )
        obj.ViewObject.Proxy = PathOpGui.ViewProvider(obj.ViewObject, res)
        obj.ViewObject.Proxy.setDeleteObjectsOnReject(False)

        # Set the gcode and try to match a tool controller
        obj.Gcode = gcode
        obj.ToolController = matchToolController(obj, toolnumber)

    FreeCAD.ActiveDocument.recompute()
コード例 #2
0
def SetupOperation(name,
                   resName,
                   objFactory,
                   opPageClass,
                   pixmap,
                   menuText,
                   toolTip,
                   accelKey=None):
    '''SetupOperation(name, objFactory, opPageClass, pixmap, menuText, toolTip, accelKey=None)
    Creates an instance of CommandPathOp with the given parameters and registers the command with FreeCAD.
    When activated it creates a model with proxy (by invoking objFactory), assigns a view provider to it
    (see ViewProvider in this module) and starts the editor specifically for this operation (driven by opPageClass).
    This is an internal function that is automatically called by the initialisation code for each operation.
    It is not expected to be called manually.
    '''

    import Adaptive2_rc
    import PathScripts.PathOpGui as PathOpGui
    res = PathOpGui.CommandResources(resName, objFactory, opPageClass, pixmap, menuText, accelKey, toolTip)

    command = PathOpGui.CommandPathOp(res)
    FreeCADGui.addCommand("Path_%s" % name.replace(' ', '_'), command)
    return command