diff options
author | bubnikv <bubnikv@gmail.com> | 2017-05-03 19:28:22 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2017-05-03 19:28:22 +0300 |
commit | e90279c513a1fb1fb50bf78d7e58a74e4889d7af (patch) | |
tree | 8aa1de52f2571bc93d47524b852ff65abd7005e9 /xs/src/libslic3r/GCode.hpp | |
parent | 72ae3585e415189286cdb85f6e02e4ec150084ee (diff) |
Ported the G-code generator from Perl to C++.
Removed GCode.pm
Removed the Perl bindigns for AvoidCrossingPerimeters, OozePrevention, SpiralVase, Wipe
Changed the std::set of extruder IDs to vector of IDs.
Removed some MSVC compiler warnings, removed obnoxious compiler warnings when compiling the Perl bindings.
Diffstat (limited to 'xs/src/libslic3r/GCode.hpp')
-rw-r--r-- | xs/src/libslic3r/GCode.hpp | 173 |
1 files changed, 121 insertions, 52 deletions
diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index 5e05455c3..71af58b6a 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -10,16 +10,20 @@ #include "PlaceholderParser.hpp" #include "Print.hpp" #include "PrintConfig.hpp" +#include "GCode/CoolingBuffer.hpp" +#include "GCode/PressureEqualizer.hpp" +#include "GCode/SpiralVase.hpp" +#include "EdgeGrid.hpp" + #include <string> namespace Slic3r { // Forward declarations. class GCode; -namespace EdgeGrid { class Grid; } class AvoidCrossingPerimeters { - public: +public: // this flag triggers the use of the external configuration space bool use_external_mp; @@ -35,7 +39,7 @@ class AvoidCrossingPerimeters { void init_layer_mp(const ExPolygons &islands); Polyline travel_to(GCode &gcodegen, Point point); - private: +private: MotionPlanner* _external_mp; MotionPlanner* _layer_mp; }; @@ -65,76 +69,141 @@ public: }; class GCode { - public: - +public: + GCode() : + m_enable_loop_clipping(true), + m_enable_cooling_markers(false), + m_enable_extrusion_role_markers(false), + m_enable_analyzer_markers(false), + m_layer_count(0), + m_layer_index(-1), + m_layer(nullptr), + m_first_layer(false), + m_elapsed_time(0.0), + m_volumetric_speed(0), + m_last_pos_defined(false), + m_last_extrusion_role(erNone), + m_brim_done(false), + m_second_layer_things_done(false), + m_last_obj_copy(Point(std::numeric_limits<coord_t>::max(), std::numeric_limits<coord_t>::max())) + {} + ~GCode() {} + + bool do_export(FILE *file, Print &print); + + // Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests. + const Pointf& origin() const { return m_origin; } + void set_origin(const Pointf &pointf); + void set_origin(const coordf_t x, const coordf_t y) { this->set_origin(Pointf(x, y)); } + const Point& last_pos() const { return m_last_pos; } + Pointf point_to_gcode(const Point &point) const; + const FullPrintConfig &config() const { return m_config; } + const Layer* layer() const { return m_layer; } + GCodeWriter& writer() { return m_writer; } + bool enable_cooling_markers() const { return m_enable_cooling_markers; } + float get_reset_elapsed_time() { float t = m_elapsed_time; m_elapsed_time = 0.f; return t; } + + // For Perl bindings, to be used exclusively by unit tests. + unsigned int layer_count() const { return m_layer_count; } + void set_layer_count(unsigned int value) { m_layer_count = value; } + float elapsed_time() const { return m_elapsed_time; } + void set_elapsed_time(float value) { m_elapsed_time = value; } + void apply_print_config(const PrintConfig &print_config); + +private: + void process_layer(FILE *file, const Print &print, const Layer &layer, const Points &object_copies); + + void set_last_pos(const Point &pos) { m_last_pos = pos; m_last_pos_defined = true; } + bool last_pos_defined() const { return m_last_pos_defined; } + void set_extruders(const std::vector<unsigned int> &extruder_ids); + std::string preamble(); + std::string change_layer(const Layer &layer); + std::string extrude(const ExtrusionEntity &entity, std::string description = "", double speed = -1); + std::string extrude(ExtrusionLoop loop, std::string description = "", double speed = -1); + std::string extrude(ExtrusionMultiPath multipath, std::string description = "", double speed = -1); + std::string extrude(ExtrusionPath path, std::string description = "", double speed = -1); + + struct ByExtruder + { + struct ToExtrude { + ExtrusionEntityCollection perimeters; + ExtrusionEntityCollection infills; + }; + std::vector<ToExtrude> by_region; + }; + std::string extrude_perimeters(const Print &print, const std::vector<ByExtruder::ToExtrude> &by_region); + std::string extrude_infill(const Print &print, const std::vector<ByExtruder::ToExtrude> &by_region); + std::string extrude_support(const ExtrusionEntityCollection &support_fills, unsigned int extruder_id); + + std::string travel_to(const Point &point, ExtrusionRole role, std::string comment); + bool needs_retraction(const Polyline &travel, ExtrusionRole role = erNone); + std::string retract(bool toolchange = false); + std::string unretract(); + std::string set_extruder(unsigned int extruder_id); + /* Origin of print coordinates expressed in unscaled G-code coordinates. This affects the input arguments supplied to the extrude*() and travel_to() methods. */ - Pointf origin; - FullPrintConfig config; - GCodeWriter writer; - PlaceholderParser* placeholder_parser; - OozePrevention ooze_prevention; - Wipe wipe; - AvoidCrossingPerimeters avoid_crossing_perimeters; - bool enable_loop_clipping; + Pointf m_origin; + FullPrintConfig m_config; + GCodeWriter m_writer; + PlaceholderParser m_placeholder_parser; + OozePrevention m_ooze_prevention; + Wipe m_wipe; + AvoidCrossingPerimeters m_avoid_crossing_perimeters; + bool m_enable_loop_clipping; // If enabled, the G-code generator will put following comments at the ends // of the G-code lines: _EXTRUDE_SET_SPEED, _WIPE, _BRIDGE_FAN_START, _BRIDGE_FAN_END // Those comments are received and consumed (removed from the G-code) by the CoolingBuffer.pm Perl module. - bool enable_cooling_markers; + bool m_enable_cooling_markers; // Markers for the Pressure Equalizer to recognize the extrusion type. // The Pressure Equalizer removes the markers from the final G-code. - bool enable_extrusion_role_markers; + bool m_enable_extrusion_role_markers; // Extended markers for the G-code Analyzer. // The G-code Analyzer will remove these comments from the final G-code. - bool enable_analyzer_markers; + bool m_enable_analyzer_markers; // How many times will change_layer() be called? // change_layer() will update the progress bar. - size_t layer_count; + unsigned int m_layer_count; // Progress bar indicator. Increments from -1 up to layer_count. - int layer_index; + int m_layer_index; // Current layer processed. Insequential printing mode, only a single copy will be printed. // In non-sequential mode, all its copies will be printed. - const Layer* layer; - std::map<const PrintObject*,Point> _seam_position; + const Layer* m_layer; + std::map<const PrintObject*,Point> m_seam_position; // Distance Field structure to - EdgeGrid::Grid *_lower_layer_edge_grid; - bool first_layer; // this flag triggers first layer speeds - // Used by the CoolingBuffer.pm Perl module to calculate time spent per layer change. + std::unique_ptr<EdgeGrid::Grid> m_lower_layer_edge_grid; + // this flag triggers first layer speeds + bool m_first_layer; + // Used by the CoolingBuffer G-code filter to calculate time spent per layer change. // This value is not quite precise. First it only accouts for extrusion moves and travel moves, // it does not account for wipe, retract / unretract moves. // second it does not account for the velocity profiles of the printer. - float elapsed_time; // seconds - double volumetric_speed; + float m_elapsed_time; // seconds + double m_volumetric_speed; // Support for the extrusion role markers. Which marker is active? - ExtrusionRole _last_extrusion_role; - - GCode(); - ~GCode(); - const Point& last_pos() const; - void set_last_pos(const Point &pos); - bool last_pos_defined() const; - void apply_print_config(const PrintConfig &print_config); - void set_extruders(const std::vector<unsigned int> &extruder_ids); - void set_origin(const Pointf &pointf); - std::string preamble(); - std::string change_layer(const Layer &layer); - std::string extrude(const ExtrusionEntity &entity, std::string description = "", double speed = -1); - std::string extrude(ExtrusionLoop loop, std::string description = "", double speed = -1); - std::string extrude(ExtrusionMultiPath multipath, std::string description = "", double speed = -1); - std::string extrude(ExtrusionPath path, std::string description = "", double speed = -1); - std::string extrude_support(const ExtrusionEntityCollection *support_fills, unsigned int extruder_id); - std::string travel_to(const Point &point, ExtrusionRole role, std::string comment); - bool needs_retraction(const Polyline &travel, ExtrusionRole role = erNone); - std::string retract(bool toolchange = false); - std::string unretract(); - std::string set_extruder(unsigned int extruder_id); - Pointf point_to_gcode(const Point &point); - - private: - Point _last_pos; - bool _last_pos_defined; + ExtrusionRole m_last_extrusion_role; + + Point m_last_pos; + bool m_last_pos_defined; + + std::unique_ptr<CoolingBuffer> m_cooling_buffer; + std::unique_ptr<SpiralVase> m_spiral_vase; + std::unique_ptr<PressureEqualizer> m_pressure_equalizer; + + // Heights at which the skirt has already been extruded. + std::set<coordf_t> m_skirt_done; + // Has the brim been extruded already? Brim is being extruded only for the first object of a multi-object print. + bool m_brim_done; + // Flag indicating whether the nozzle temperature changes from 1st to 2nd layer were performed. + bool m_second_layer_things_done; + // Index of a last object copy extruded. -1 for not set yet. + Point m_last_obj_copy; + std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1); + void _print_first_layer_extruder_temperatures(FILE *file, Print &print, bool wait); + + std::string filter(std::string &&gcode, bool flush); }; } |