mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Documented perl modules.
This commit is contained in:
		
							parent
							
								
									6dfe4c0b96
								
							
						
					
					
						commit
						b2a6f43923
					
				
					 13 changed files with 107 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -1,9 +1,13 @@
 | 
			
		|||
# A standalone (no C++ implementation) G-code filter, to control cooling of the print.
 | 
			
		||||
# The G-code is processed per layer. Once a layer is collected, fan start / stop commands are edited
 | 
			
		||||
# and the print is modified to stretch over a minimum layer time.
 | 
			
		||||
 | 
			
		||||
package Slic3r::GCode::CoolingBuffer;
 | 
			
		||||
use Moo;
 | 
			
		||||
 | 
			
		||||
has 'config'    => (is => 'ro', required => 1);  # Slic3r::Config::Print
 | 
			
		||||
has 'gcodegen'  => (is => 'ro', required => 1);
 | 
			
		||||
has 'gcode'     => (is => 'rw', default => sub {""});
 | 
			
		||||
has 'gcodegen'  => (is => 'ro', required => 1);  # Slic3r::GCode C++ instance
 | 
			
		||||
has 'gcode'     => (is => 'rw', default => sub {""}); # Cache of a G-code snippet emitted for a single layer.
 | 
			
		||||
has 'elapsed_time' => (is => 'rw', default => sub {0});
 | 
			
		||||
has 'layer_id'  => (is => 'rw');
 | 
			
		||||
has 'last_z'    => (is => 'rw', default => sub { {} });  # obj_id => z (basically a 'last seen' table)
 | 
			
		||||
| 
						 | 
				
			
			@ -20,12 +24,15 @@ sub append {
 | 
			
		|||
    
 | 
			
		||||
    my $return = "";
 | 
			
		||||
    if (exists $self->last_z->{$obj_id} && $self->last_z->{$obj_id} != $print_z) {
 | 
			
		||||
        # A layer was finished, Z of the object's layer changed. Process the layer.
 | 
			
		||||
        $return = $self->flush;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    $self->layer_id($layer_id);
 | 
			
		||||
    $self->last_z->{$obj_id} = $print_z;
 | 
			
		||||
    $self->gcode($self->gcode . $gcode);
 | 
			
		||||
    #FIXME Vojtech: This is a very rough estimate of the print time, 
 | 
			
		||||
    # not taking into account the acceleration profiles generated by the printer firmware.
 | 
			
		||||
    $self->elapsed_time($self->elapsed_time + $self->gcodegen->elapsed_time);
 | 
			
		||||
    $self->gcodegen->set_elapsed_time(0);
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -46,9 +53,12 @@ sub flush {
 | 
			
		|||
    if ($self->config->cooling) {
 | 
			
		||||
        Slic3r::debugf "Layer %d estimated printing time: %d seconds\n", $self->layer_id, $elapsed;
 | 
			
		||||
        if ($elapsed < $self->config->slowdown_below_layer_time) {
 | 
			
		||||
            # Layer time very short. Enable the fan to a full throttle and slow down the print
 | 
			
		||||
            # (stretch the layer print time to slowdown_below_layer_time).
 | 
			
		||||
            $fan_speed = $self->config->max_fan_speed;
 | 
			
		||||
            $speed_factor = $elapsed / $self->config->slowdown_below_layer_time;
 | 
			
		||||
        } elsif ($elapsed < $self->config->fan_below_layer_time) {
 | 
			
		||||
            # Layer time quite short. Enable the fan proportionally according to the current layer time.
 | 
			
		||||
            $fan_speed = $self->config->max_fan_speed - ($self->config->max_fan_speed - $self->config->min_fan_speed)
 | 
			
		||||
                * ($elapsed - $self->config->slowdown_below_layer_time)
 | 
			
		||||
                / ($self->config->fan_below_layer_time - $self->config->slowdown_below_layer_time); #/
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +66,9 @@ sub flush {
 | 
			
		|||
        Slic3r::debugf "  fan = %d%%, speed = %d%%\n", $fan_speed, $speed_factor * 100;
 | 
			
		||||
        
 | 
			
		||||
        if ($speed_factor < 1) {
 | 
			
		||||
            # Adjust feed rate of G1 commands marked with an _EXTRUDE_SET_SPEED
 | 
			
		||||
            # as long as they are not _WIPE moves (they cannot if they are _EXTRUDE_SET_SPEED)
 | 
			
		||||
            # and they are not preceded directly by _BRIDGE_FAN_START (do not adjust bridging speed).
 | 
			
		||||
            $gcode =~ s/^(?=.*?;_EXTRUDE_SET_SPEED)(?!.*?;_WIPE)(?<!;_BRIDGE_FAN_START\n)(G1\sF)(\d+(?:\.\d+)?)/
 | 
			
		||||
                my $new_speed = $2 * $speed_factor;
 | 
			
		||||
                $1 . sprintf("%.3f", $new_speed < $self->min_print_speed ? $self->min_print_speed : $new_speed)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
# A pure perl (no C++ implementation) G-code filter, to control the pressure inside the nozzle.
 | 
			
		||||
 | 
			
		||||
package Slic3r::GCode::PressureRegulator;
 | 
			
		||||
use Moo;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue