mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Implemented filament start / g-codes.
https://github.com/prusa3d/Slic3r/issues/265
https://github.com/prusa3d/Slic3r/issues/319
Based on the implementation by @lordofhyphens
19eea19d91
			
			
This commit is contained in:
		
							parent
							
								
									b5f38dd23f
								
							
						
					
					
						commit
						ad3be1a69e
					
				
					 5 changed files with 68 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -229,8 +229,10 @@ inline void write(FILE *file, const std::string &what)
 | 
			
		|||
 | 
			
		||||
inline void writeln(FILE *file, const std::string &what)
 | 
			
		||||
{
 | 
			
		||||
    write(file, what);
 | 
			
		||||
    fprintf(file, "\n");
 | 
			
		||||
    if (! what.empty()) {
 | 
			
		||||
        write(file, what);
 | 
			
		||||
        fprintf(file, "\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Collect pairs of object_layer + support_layer sorted by print_z.
 | 
			
		||||
| 
						 | 
				
			
			@ -486,7 +488,10 @@ bool GCode::do_export(FILE *file, Print &print)
 | 
			
		|||
    this->_print_first_layer_extruder_temperatures(file, print, initial_extruder_id, false);
 | 
			
		||||
    // Let the start-up script prime the 1st printing tool.
 | 
			
		||||
    m_placeholder_parser.set("initial_tool", initial_extruder_id);
 | 
			
		||||
    fprintf(file, "%s\n", m_placeholder_parser.process(print.config.start_gcode.value).c_str());
 | 
			
		||||
    writeln(file, m_placeholder_parser.process(print.config.start_gcode.value));
 | 
			
		||||
    // Process filament-specific gcode in extruder order.
 | 
			
		||||
    for (const std::string &start_gcode : print.config.start_filament_gcode.values)
 | 
			
		||||
        writeln(file, m_placeholder_parser.process(start_gcode));
 | 
			
		||||
    this->_print_first_layer_extruder_temperatures(file, print, initial_extruder_id, true);
 | 
			
		||||
    
 | 
			
		||||
    // Set other general things.
 | 
			
		||||
| 
						 | 
				
			
			@ -623,14 +628,17 @@ bool GCode::do_export(FILE *file, Print &print)
 | 
			
		|||
            write(file, m_wipe_tower->finalize(*this));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // write end commands to file
 | 
			
		||||
    // Write end commands to file.
 | 
			
		||||
    write(file, this->retract());
 | 
			
		||||
    write(file, m_writer.set_fan(false));
 | 
			
		||||
    // Process filament-specific gcode in extruder order.
 | 
			
		||||
    for (const std::string &end_gcode : print.config.end_filament_gcode.values)
 | 
			
		||||
        writeln(file, m_placeholder_parser.process(end_gcode));
 | 
			
		||||
    writeln(file, m_placeholder_parser.process(print.config.end_gcode));
 | 
			
		||||
    write(file, m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100%
 | 
			
		||||
    write(file, m_writer.postamble());
 | 
			
		||||
 | 
			
		||||
    // get filament stats
 | 
			
		||||
    // Get filament stats.
 | 
			
		||||
    print.filament_stats.clear();
 | 
			
		||||
    print.total_used_filament    = 0.;
 | 
			
		||||
    print.total_extruded_volume  = 0.;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,6 +91,7 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
 | 
			
		|||
        steps_ignore.insert("disable_fan_first_layers");
 | 
			
		||||
        steps_ignore.insert("duplicate_distance");
 | 
			
		||||
        steps_ignore.insert("end_gcode");
 | 
			
		||||
        steps_ignore.insert("end_filament_gcode");
 | 
			
		||||
        steps_ignore.insert("extrusion_axis");
 | 
			
		||||
        steps_ignore.insert("extruder_clearance_height");
 | 
			
		||||
        steps_ignore.insert("extruder_clearance_radius");
 | 
			
		||||
| 
						 | 
				
			
			@ -140,6 +141,7 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
 | 
			
		|||
        steps_ignore.insert("slowdown_below_layer_time");
 | 
			
		||||
        steps_ignore.insert("standby_temperature_delta");
 | 
			
		||||
        steps_ignore.insert("start_gcode");
 | 
			
		||||
        steps_ignore.insert("start_filament_gcode");
 | 
			
		||||
        steps_ignore.insert("toolchange_gcode");
 | 
			
		||||
        steps_ignore.insert("threads");
 | 
			
		||||
        steps_ignore.insert("travel_speed");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -156,6 +156,19 @@ PrintConfigDef::PrintConfigDef()
 | 
			
		|||
    def->height = 120;
 | 
			
		||||
    def->default_value = new ConfigOptionString("M104 S0 ; turn off temperature\nG28 X0  ; home X axis\nM84     ; disable motors\n");
 | 
			
		||||
 | 
			
		||||
    def = this->add("end_filament_gcode", coStrings);
 | 
			
		||||
    def->label = "End G-code";
 | 
			
		||||
    def->tooltip = "This end procedure is inserted at the end of the output file, before the printer end gcode. Note that you can use placeholder variables for all Slic3r settings. If you have multiple extruders, the gcode is processed in extruder order.";
 | 
			
		||||
    def->cli = "end-filament-gcode=s@";
 | 
			
		||||
    def->multiline = true;
 | 
			
		||||
    def->full_width = true;
 | 
			
		||||
    def->height = 120;
 | 
			
		||||
    {
 | 
			
		||||
        ConfigOptionStrings* opt = new ConfigOptionStrings();
 | 
			
		||||
        opt->values.push_back("; Filament-specific end gcode \n;END gcode for filament\n");
 | 
			
		||||
        def->default_value = opt;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def = this->add("ensure_vertical_shell_thickness", coBool);
 | 
			
		||||
    def->label = "Ensure vertical shell thickness";
 | 
			
		||||
    def->category = "Layers and Perimeters";
 | 
			
		||||
| 
						 | 
				
			
			@ -1235,6 +1248,19 @@ PrintConfigDef::PrintConfigDef()
 | 
			
		|||
    def->height = 120;
 | 
			
		||||
    def->default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n");
 | 
			
		||||
 | 
			
		||||
    def = this->add("start_filament_gcode", coStrings);
 | 
			
		||||
    def->label = "Start G-code";
 | 
			
		||||
    def->tooltip = "This start procedure is inserted at the beginning, after any printer start gcode. This is used to override settings for a specific filament. If Slic3r detects M104, M109, M140 or M190 in your custom codes, such commands will not be prepended automatically so you're free to customize the order of heating commands and other custom actions. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want. If you have multiple extruders, the gcode is processed in extruder order.";
 | 
			
		||||
    def->cli = "start-filament-gcode=s@";
 | 
			
		||||
    def->multiline = true;
 | 
			
		||||
    def->full_width = true;
 | 
			
		||||
    def->height = 120;
 | 
			
		||||
    {
 | 
			
		||||
        ConfigOptionStrings* opt = new ConfigOptionStrings();
 | 
			
		||||
        opt->values.push_back("; Filament gcode\n");
 | 
			
		||||
        def->default_value = opt;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def = this->add("single_extruder_multi_material", coBool);
 | 
			
		||||
    def->label = "Single Extruder Multi Material";
 | 
			
		||||
    def->tooltip = "The printer multiplexes filaments into a single hot end.";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -326,6 +326,7 @@ public:
 | 
			
		|||
    ConfigOptionString              before_layer_gcode;
 | 
			
		||||
    ConfigOptionFloats              deretract_speed;
 | 
			
		||||
    ConfigOptionString              end_gcode;
 | 
			
		||||
    ConfigOptionStrings             end_filament_gcode;
 | 
			
		||||
    ConfigOptionString              extrusion_axis;
 | 
			
		||||
    ConfigOptionFloats              extrusion_multiplier;
 | 
			
		||||
    ConfigOptionFloats              filament_diameter;
 | 
			
		||||
| 
						 | 
				
			
			@ -351,6 +352,7 @@ public:
 | 
			
		|||
    ConfigOptionFloats              retract_restart_extra_toolchange;
 | 
			
		||||
    ConfigOptionFloats              retract_speed;
 | 
			
		||||
    ConfigOptionString              start_gcode;
 | 
			
		||||
    ConfigOptionStrings             start_filament_gcode;
 | 
			
		||||
    ConfigOptionBool                single_extruder_multi_material;
 | 
			
		||||
    ConfigOptionString              toolchange_gcode;
 | 
			
		||||
    ConfigOptionFloat               travel_speed;
 | 
			
		||||
| 
						 | 
				
			
			@ -369,6 +371,7 @@ public:
 | 
			
		|||
        OPT_PTR(before_layer_gcode);
 | 
			
		||||
        OPT_PTR(deretract_speed);
 | 
			
		||||
        OPT_PTR(end_gcode);
 | 
			
		||||
        OPT_PTR(end_filament_gcode);
 | 
			
		||||
        OPT_PTR(extrusion_axis);
 | 
			
		||||
        OPT_PTR(extrusion_multiplier);
 | 
			
		||||
        OPT_PTR(filament_diameter);
 | 
			
		||||
| 
						 | 
				
			
			@ -395,6 +398,7 @@ public:
 | 
			
		|||
        OPT_PTR(retract_speed);
 | 
			
		||||
        OPT_PTR(single_extruder_multi_material);
 | 
			
		||||
        OPT_PTR(start_gcode);
 | 
			
		||||
        OPT_PTR(start_filament_gcode);
 | 
			
		||||
        OPT_PTR(toolchange_gcode);
 | 
			
		||||
        OPT_PTR(travel_speed);
 | 
			
		||||
        OPT_PTR(use_firmware_retraction);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue