예제 #1
0
def save_code():
    output_file = v.filename.replace(".gcode", ".mcf.gcode")

    comment("saving output to " + output_file)

    header = omegaheader()
    comment(" number of lines: {}".format(len(header) + len(v.output_code)))

    try:
        opf = open(output_file, "w", encoding='utf-8')
    except TypeError:
        try:
            opf = open(output_file, "w")
        except IOError:
            error("Could not open output file {}".format(output_file))
            return
    except IOError:
        error("Could not read open output {}".format(output_file))
        return
    opf.writelines(header)
    opf.writelines(v.output_code)
    opf.close()
    pass
예제 #2
0
def p2pp_command(command, parameter):
    command = command.upper()

    if command == "LINEARPINGLENGTH":
        v.pinglength = float(parameter)
        v.pingincrease = 1

    if command == "WIPESPEED":
        v.wipe_feedrate = int(parameter)

    if command == "LAYERONEWIPESPEED":
        v.wipe_feedrate1 = int(parameter)

    if command == "TOWERDELTA":
        v.towerdelta = float(parameter)

    if command == "PRINTERPROFILE":
        v.printerid = parameter
        gui.set_printer_id(v.printerid)

    if command == "AUTOTOWER":
        v.autotower = True

    if command == "MAXTOWERDELTA":
        v.towerdelta = float(parameter)

    if command == "EXTRAENDFILAMENT":
        v.extra_extrusion_at_end = float(parameter)

    if command == "SPLICEOFFSET":
        unit = "mm"
        if parameter.endswith("%"):
            parameter = parameter.replace("%", "")
            v.splice_procent = True
            unit = "% of purge length"
        v.spliceoffset = float(parameter)

        comment("Splice offset is {}{}.".format(v.spliceoffset, unit))

    if command == "AUTOEXPANDTOWER":
        v.expand_tower = True

    if command in ["TOOL_0", "TOOL_1", "TOOL_2", "TOOL_3"]:
        m = v.regex_purge_info.match(parameter)
        if m:
            tool = int(command[-1])
            v.filament_type[tool] = m.group(1).upper()
            v.loadinfo[tool] = int(m.group(2))
            v.unloadinfo[tool] = int(m.group(3))

    if command.startswith("MATERIAL"):
        _deflt = "MATERIAL_DEFAULT_(\d+)_(\d+)_(\d+)"
        _algo = "MATERIAL_(\w+_\w+)_(\d+)_(\d+)_(\d+)"

        m = re.search(_algo, command)
        if m:
            v.algorithm["{}".format(m.group(1))] = (int(m.group(2)), int(m.group(3)), int(m.group(4)))
        else:
            m = re.search(_deflt, command)
            if m:
                v.algorithm["DEFAULT"] = (int(m.group(1)), int(m.group(2)), int(m.group(3)))
예제 #3
0
def usage():
    comment("Use:  p2pp_s3d [filename]")
예제 #4
0
    mcf.process_file()


def usage():
    comment("Use:  p2pp_s3d [filename]")


if __name__ == "__main__":

    number_of_args = len(sys.argv)

    if number_of_args == 1:

        platformD = platform.system()
        if platformD == 'Darwin':
            comment('{}/p2pp_s3d.command "[output_filepath]"'.format(
                os.path.dirname(sys.argv[0])))
        elif platformD == 'Windows':
            if " " in os.path.dirname(sys.argv[0]):
                warning("Your path contains spaces!!!")
                comment('"{}\\p2pp_s3d.bat" "[output_filepath]"'.format(
                    os.path.dirname(sys.argv[0])))
            else:
                comment('{}\\p2pp_s3d.bat "[output_filepath]"'.format(
                    os.path.dirname(sys.argv[0])))

    elif number_of_args == 2:
        main(filename=sys.argv[1])

    else:
        error("[err {}] - Invalid usage:".format(number_of_args))
        usage()
예제 #5
0
def process_gcode():
    gui.comment("Processing " + v.filename)
    line_count = len(v.rawfile)
    line_idx = 0
    for line in v.rawfile:
        line_idx += 1
        gui.setprogress(int(50 * line_idx / line_count))

        # skip fully empty lines
        if len(line) == 0:
            continue

        # parse comments
        if line.startswith(";"):
            line = parameters.parse_comment(line)

        tmp = gcode.GCodeCommand(line)

        # we calculate the purge for tower position
        # afterwards this code is removed
        #########################################################
        if v.mode == parameters.MODE_PURGE:
            if tmp.E:
                v.purge_minx = min(v.purge_minx, tmp.get_parameter("X", 9999))
                v.purge_maxx = max(v.purge_maxx, tmp.get_parameter("X", -9999))
                v.purge_miny = min(v.purge_miny, tmp.get_parameter("Y", 9999))
                v.purge_maxy = max(v.purge_maxy, tmp.get_parameter("Y", -9999))

            if tmp.is_comment() and tmp.comment.startswith(' process'):
                v.gcodes.append(tmp)
        else:
            v.gcodes.append(tmp)

        toolchange = tmp.is_toolchange()
        if toolchange in [0, 1, 2, 3]:
            # keep track of the tools used
            if not v.toolsused[toolchange]:
                if not v.filament_type[toolchange]:
                    error(
                        "TOOL_{} setting command missing - output file cannot be created"
                        .format(toolchange))
            v.toolsused[toolchange] = True

            # calculate the purge
            if not (v.parse_curtool == -1):
                v.layer_toolchange_count[-1] += 1
                if v.filament_type[toolchange] and v.filament_type[
                        v.parse_curtool] and not (v.parse_curtool
                                                  == toolchange):
                    v.layer_purge_volume[-1] += purgetower.calc_purge_length(
                        v.parse_curtool, toolchange)
                    v.parse_prevtool = v.parse_curtool
                    v.parse_curtool = toolchange
            else:
                v.parse_curtool = v.parse_prevtool = toolchange

    comment("filament Info: " + v.filament_type.__str__())
    comment("Tool unload info: " + v.unloadinfo.__str__())
    comment("Tool load info: " + v.loadinfo.__str__())
    comment("Algorithms:" + v.algorithm.__str__())
    comment("Maximum purge needed per layer: {}mm".format(
        max(v.layer_purge_volume)))
    comment("Autotower function active: {}".format(v.autotower))
    if v.autotower:
        autotower.init_autotower()
        _x = 0.0
        _y = 0.0
        for g in v.gcodes:

            if g.is_movement_command():
                _ux = g.get_parameter("X", _x)
                _uy = g.get_parameter("Y", _y)
                _ue = g.get_parameter("E", 0)

                if _ue > 0:
                    autotower.filament_mark(_x, _y, _ux, _uy)
                _x = _ux
                _y = _uy

        autotower.calculate_purgevolume()
        tower_fits = False
        while not tower_fits:
            purgetower.purge_create_layers(
                autotower.purge_minx - 1, autotower.purge_miny - 1,
                autotower.purge_maxx - autotower.purge_minx + 2,
                autotower.purge_maxy - autotower.purge_miny + 2)
            tower_fits = purgetower.simulate_tower(
                purgetower.sequence_length_solid,
                purgetower.sequence_length_empty,
                purgetower.sequence_length_fill, 5)
            if not tower_fits:
                if not autotower.tower_expand():
                    error("COULD NOT GENERATE SUITABLE TOWER")
                    tower_fits = True

        v.purge_minx = autotower.purge_minx
        v.purge_miny = autotower.purge_miny
        v.purge_maxx = autotower.purge_maxx
        v.purge_maxy = autotower.purge_maxy

    else:
        expand = 0
        tower_fits = False
        while not tower_fits:
            purgetower.purge_create_layers(v.purge_minx - 1, v.purge_miny - 1,
                                           v.purge_maxx - v.purge_minx + 2,
                                           v.purge_maxy - v.purge_miny + 2)
            tower_fits = purgetower.simulate_tower(
                purgetower.sequence_length_solid,
                purgetower.sequence_length_empty,
                purgetower.sequence_length_fill, 5)
            if not tower_fits:
                purgetower.tower_auto_expand(10)
                expand += 10

        if expand > 0:
            warning("Tower expanded by {}mm".format(expand))

    comment('Calculated purge volume : {:.3f},{:.3f} -> {:.3f},{:.3f}'.format(
        v.purge_minx, v.purge_miny, v.purge_maxx, v.purge_maxy))

    line_idx = 0
    line_count = len(v.gcodes)
    layer = -1
    for g in v.gcodes:
        if g.layer != layer:
            layer = g.layer
            purgetower.checkfill(g.layer, v.maxtowerdelta / v.layer_height)

        line_idx += 1
        gui.setprogress(50 + int(50 * line_idx / line_count))
        if g.command in ["M220"]:
            g.move_to_comment("IGNORED COMMAND")
            g.issue_command()
            continue  # no further mcf required

        if g.command == "M221":
            v.extrusion_multiplier = g.get_parameter(
                "S", v.extrusion_multiplier * 100) / 100
            g.issue_command()
            continue  # no further mcf required

        if g.command in ["T0", "T1", "T2", "T3"]:
            gcode.GCodeCommand(";---- {} TOOLCHANGE -----".format(
                g.command)).issue_command()
            process_tool_change(g)
            g.issue_command()
            continue  # no further mcf required

        if g.command in [
                "M104", "M106", "M109", "M140", "M190", "M73", "M900", "M84"
        ]:
            g.issue_command()
            continue  # no further mcf required

        if g.is_movement_command():
            v.current_position_x = g.get_parameter("X", v.current_position_x)
            v.current_position_y = g.get_parameter("Y", v.current_position_y)
            v.current_position_z = g.get_parameter("Z", v.current_position_z)
            if purgetower.moveintower():
                error("MODEL COLLIDES WITH TOWER.")
        g.issue_command()

    process_tool_change(None)

    if v.maxdelta > 1 or v.mindelta < -1:
        warning(
            "Tower hight deviates {:.2f}mm above and {:.2f}mm below print level"
            .format(-v.mindelta, v.maxdelta))
        warning(
            "Make sure to keep enough distance between tower and object to avoid collisions"
        )
        warning(
            "If the tower grows over the print height, consider increasing the prime pillar width in S3D"
        )

    gui.completed()