<commit_before>/** Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License */
#ifndef GCODEEXPORT_H
#define GCODEEXPORT_H

#include <stdio.h>
#include <deque> // for extrusionAmountAtPreviousRetractions
#include <sstream> // for stream.str()

#include "settings.h"
#include "utils/intpoint.h"
#include "timeEstimate.h"
#include "MeshGroup.h"
#include "commandSocket.h"

namespace cura {

struct CoastingConfig
{
    bool coasting_enable; 
    double coasting_volume_move; 
    double coasting_speed_move; 
    double coasting_min_volume_move; 

    double coasting_volume_retract;
    double coasting_speed_retract;
    double coasting_min_volume_retract;
};
    
class RetractionConfig
{
public:
    double distance; //!< The distance retracted (in mm)
    double speed; //!< The speed with which to retract (in mm/s)
    double primeSpeed; //!< the speed with which to unretract (in mm/s)
    double prime_volume; //!< the amount of material primed after unretracting (in mm^3)
    int zHop; //!< the amount with which to lift the head during a retraction-travel
    int retraction_min_travel_distance; //!< 
    double retraction_extrusion_window; //!< in mm
    int retraction_count_max;
};

//The GCodePathConfig is the configuration for moves/extrusion actions. This defines at which width the line is printed and at which speed.
class GCodePathConfig
{
private:
    double speed; //!< movement speed (mm/s)
    int line_width; //!< width of the line extruded
    double flow; //!< extrusion flow in %
    int layer_thickness; //!< layer height
    double extrusion_mm3_per_mm;//!< mm^3 filament moved per mm line extruded
public:
    const char* name; //!< name of the feature type
    bool spiralize;
    RetractionConfig *const retraction_config;
    
    // GCodePathConfig() : speed(0), line_width(0), extrusion_mm3_per_mm(0.0), name(nullptr), spiralize(false), retraction_config(nullptr) {}
    GCodePathConfig(RetractionConfig* retraction_config, const char* name) : speed(0), line_width(0), extrusion_mm3_per_mm(0.0), name(name), spiralize(false), retraction_config(retraction_config) {}
    
    /*!
     * Initialize some of the member variables.
     * 
     * Warning! setLayerHeight still has to be called before this object can be used.
     */
    void init(double speed, int line_width, double flow)
    {
        this->speed = speed;
        this->line_width = line_width;
        this->flow = flow;
    }

    /*!
     * Set the layer height and (re)compute the extrusion_per_mm
     */
    void setLayerHeight(int layer_height)
    {
        this->layer_thickness = layer_height;
        calculateExtrusion();
    }
    
    void smoothSpeed(double min_speed, int layer_nr, double max_speed_layer) 
    {
        speed = (speed*layer_nr)/max_speed_layer + (min_speed*(max_speed_layer-layer_nr)/max_speed_layer);
    }

    /*!
     * Can only be called after the layer height has been set (which is done while writing the gcode!)
     */
    double getExtrusionMM3perMM()
    {
        return extrusion_mm3_per_mm;
    }
    
    /*!
     * Get the movement speed in mm/s
     */
    double getSpeed()
    {
        return speed;
    }
    
    int getLineWidth()
    {
        return line_width;
    }
    
    bool isTravelPath()
    {
        return line_width == 0;
    }
    
private:
    void calculateExtrusion()
    {<commit_msg>bugfix: speed was always set to speed_layer_0 (CURA-496)<commit_after>/** Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License */
#ifndef GCODEEXPORT_H
#define GCODEEXPORT_H

#include <stdio.h>
#include <deque> // for extrusionAmountAtPreviousRetractions
#include <sstream> // for stream.str()

#include "settings.h"
#include "utils/intpoint.h"
#include "timeEstimate.h"
#include "MeshGroup.h"
#include "commandSocket.h"

namespace cura {

struct CoastingConfig
{
    bool coasting_enable; 
    double coasting_volume_move; 
    double coasting_speed_move; 
    double coasting_min_volume_move; 

    double coasting_volume_retract;
    double coasting_speed_retract;
    double coasting_min_volume_retract;
};
    
class RetractionConfig
{
public:
    double distance; //!< The distance retracted (in mm)
    double speed; //!< The speed with which to retract (in mm/s)
    double primeSpeed; //!< the speed with which to unretract (in mm/s)
    double prime_volume; //!< the amount of material primed after unretracting (in mm^3)
    int zHop; //!< the amount with which to lift the head during a retraction-travel
    int retraction_min_travel_distance; //!< 
    double retraction_extrusion_window; //!< in mm
    int retraction_count_max;
};

//The GCodePathConfig is the configuration for moves/extrusion actions. This defines at which width the line is printed and at which speed.
class GCodePathConfig
{
private:
    double speed_iconic; //!< movement speed (mm/s) specific to this print feature
    double speed; //!< current movement speed (mm/s) (modified by layer_nr etc.)
    int line_width; //!< width of the line extruded
    double flow; //!< extrusion flow in %
    int layer_thickness; //!< layer height
    double extrusion_mm3_per_mm;//!< mm^3 filament moved per mm line extruded
public:
    const char* name; //!< name of the feature type
    bool spiralize;
    RetractionConfig *const retraction_config;
    
    // GCodePathConfig() : speed(0), line_width(0), extrusion_mm3_per_mm(0.0), name(nullptr), spiralize(false), retraction_config(nullptr) {}
    GCodePathConfig(RetractionConfig* retraction_config, const char* name) : speed_iconic(0), speed(0), line_width(0), extrusion_mm3_per_mm(0.0), name(name), spiralize(false), retraction_config(retraction_config) {}
    
    /*!
     * Initialize some of the member variables.
     * 
     * Warning! setLayerHeight still has to be called before this object can be used.
     */
    void init(double speed, int line_width, double flow)
    {
        speed_iconic = speed;
        this->speed = speed;
        this->line_width = line_width;
        this->flow = flow;
    }

    /*!
     * Set the layer height and (re)compute the extrusion_per_mm
     */
    void setLayerHeight(int layer_height)
    {
        this->layer_thickness = layer_height;
        calculateExtrusion();
    }
    
    /*!
     * Set the speed to somewhere between the @p min_speed and the speed_iconic.
     * 
     * This functions should not be called with @p layer_nr > @p max_speed_layer !
     * 
     * \param min_speed The speed at layer zero
     * \param layer_nr The layer number 
     * \param max_speed_layer The layer number for which the speed_iconic should be used.
     */
    void smoothSpeed(double min_speed, int layer_nr, double max_speed_layer) 
    {
        speed = (speed_iconic*layer_nr)/max_speed_layer + (min_speed*(max_speed_layer-layer_nr)/max_speed_layer);
    }

    /*!
     * Can only be called after the layer height has been set (which is done while writing the gcode!)
     */
    double getExtrusionMM3perMM()
    {
        return extrusion_mm3_per_mm;
    }
    
    /*!
     * Get the movement speed in mm/s
     */
    double getSpeed()
    {
        return speed;
    }
    
    int getLineWidth()
    {
        return line_width;
    }
    
    bool isTravelPath()
    {
        return line_width == 0;
    }
    
private:
    void calculateExtrusion()
    {
{'fraction_non_alphanumeric': 0.09394145677331518, 'fraction_numerical': 0.006398910823689585, 'mean_word_length': 3.042927903137039, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6154929', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2241, 'n_words': 676}