diff options
Diffstat (limited to 'src/libslic3r/GCode.hpp')
-rw-r--r-- | src/libslic3r/GCode.hpp | 117 |
1 files changed, 50 insertions, 67 deletions
diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 650fb8860..458eae80a 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -5,23 +5,21 @@ #include "ExPolygon.hpp" #include "GCodeWriter.hpp" #include "Layer.hpp" -#include "MotionPlanner.hpp" #include "Point.hpp" #include "PlaceholderParser.hpp" -#include "Print.hpp" #include "PrintConfig.hpp" +#include "GCode/AvoidCrossingPerimeters.hpp" #include "GCode/CoolingBuffer.hpp" #include "GCode/SpiralVase.hpp" #include "GCode/ToolOrdering.hpp" #include "GCode/WipeTower.hpp" -#include "GCodeTimeEstimator.hpp" +#include "GCode/SeamPlacer.hpp" +#include "GCode/GCodeProcessor.hpp" #include "EdgeGrid.hpp" -#include "GCode/Analyzer.hpp" -#if ENABLE_THUMBNAIL_GENERATOR #include "GCode/ThumbnailData.hpp" -#endif // ENABLE_THUMBNAIL_GENERATOR #include <memory> +#include <map> #include <string> #ifdef HAS_PRESSURE_EQUALIZER @@ -32,35 +30,10 @@ namespace Slic3r { // Forward declarations. class GCode; -class GCodePreviewData; -class AvoidCrossingPerimeters { -public: - - // this flag triggers the use of the external configuration space - bool use_external_mp; - bool use_external_mp_once; // just for the next travel move - - // this flag disables avoid_crossing_perimeters just for the next travel move - // we enable it by default for the first travel move in print - bool disable_once; - - AvoidCrossingPerimeters() : use_external_mp(false), use_external_mp_once(false), disable_once(true) {} - ~AvoidCrossingPerimeters() {} - - void reset() { m_external_mp.reset(); m_layer_mp.reset(); } - void init_external_mp(const Print &print); - void init_layer_mp(const ExPolygons &islands) { m_layer_mp = Slic3r::make_unique<MotionPlanner>(islands); } - - Polyline travel_to(const GCode &gcodegen, const Point &point); - -private: - // For initializing the regions to avoid. - static Polygons collect_contours_all_layers(const PrintObjectPtrs& objects); - - std::unique_ptr<MotionPlanner> m_external_mp; - std::unique_ptr<MotionPlanner> m_layer_mp; -}; +namespace { struct Item; } +struct PrintInstance; +using PrintObjectPtrs = std::vector<PrintObject*>; class OozePrevention { public: @@ -137,28 +110,38 @@ private: double m_last_wipe_tower_print_z = 0.f; }; +class ColorPrintColors +{ + static const std::vector<std::string> Colors; +public: + static const std::vector<std::string>& get() { return Colors; } +}; + class GCode { public: GCode() : m_origin(Vec2d::Zero()), m_enable_loop_clipping(true), m_enable_cooling_markers(false), - m_enable_extrusion_role_markers(false), - m_enable_analyzer(false), - m_last_analyzer_extrusion_role(erNone), + m_enable_extrusion_role_markers(false), + m_last_processor_extrusion_role(erNone), m_layer_count(0), m_layer_index(-1), m_layer(nullptr), m_volumetric_speed(0), m_last_pos_defined(false), m_last_extrusion_role(erNone), - m_last_mm3_per_mm(GCodeAnalyzer::Default_mm3_per_mm), - m_last_width(GCodeAnalyzer::Default_Width), - m_last_height(GCodeAnalyzer::Default_Height), +#if ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE + m_last_width(0.0f), +#endif // ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE +#if ENABLE_GCODE_VIEWER_DATA_CHECKING + m_last_mm3_per_mm(0.0), +#if !ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE + m_last_width(0.0f), +#endif // !ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE +#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING m_brim_done(false), m_second_layer_things_done(false), - m_normal_time_estimator(GCodeTimeEstimator::Normal), - m_silent_time_estimator(GCodeTimeEstimator::Silent), m_silent_time_estimator_enabled(false), m_last_obj_copy(nullptr, Point(std::numeric_limits<coord_t>::max(), std::numeric_limits<coord_t>::max())) {} @@ -166,11 +149,7 @@ public: // throws std::runtime_exception on error, // throws CanceledException through print->throw_if_canceled(). -#if ENABLE_THUMBNAIL_GENERATOR - void do_export(Print* print, const char* path, GCodePreviewData* preview_data = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr); -#else - void do_export(Print *print, const char *path, GCodePreviewData *preview_data = nullptr); -#endif // ENABLE_THUMBNAIL_GENERATOR + void do_export(Print* print, const char* path, GCodeProcessor::Result* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr); // Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests. const Vec2d& origin() const { return m_origin; } @@ -182,6 +161,7 @@ public: const FullPrintConfig &config() const { return m_config; } const Layer* layer() const { return m_layer; } GCodeWriter& writer() { return m_writer; } + const GCodeWriter& writer() const { return m_writer; } PlaceholderParser& placeholder_parser() { return m_placeholder_parser; } const PlaceholderParser& placeholder_parser() const { return m_placeholder_parser; } // Process a template through the placeholder parser, collect error messages to be reported @@ -210,11 +190,7 @@ public: }; private: -#if ENABLE_THUMBNAIL_GENERATOR void _do_export(Print &print, FILE *file, ThumbnailsGeneratorCallback thumbnail_cb); -#else - void _do_export(Print &print, FILE *file); -#endif //ENABLE_THUMBNAIL_GENERATOR static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object); static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print); @@ -305,7 +281,7 @@ private: const size_t single_object_instance_idx); std::string extrude_perimeters(const Print &print, const std::vector<ObjectByExtruder::Island::Region> &by_region, std::unique_ptr<EdgeGrid::Grid> &lower_layer_edge_grid); - std::string extrude_infill(const Print &print, const std::vector<ObjectByExtruder::Island::Region> &by_region); + std::string extrude_infill(const Print &print, const std::vector<ObjectByExtruder::Island::Region> &by_region, bool ironing); std::string extrude_support(const ExtrusionEntityCollection &support_fills); std::string travel_to(const Point &point, ExtrusionRole role, std::string comment); @@ -314,6 +290,9 @@ private: std::string unretract() { return m_writer.unlift() + m_writer.unretract(); } std::string set_extruder(unsigned int extruder_id, double print_z); + // Cache for custom seam enforcers/blockers for each layer. + SeamPlacer m_seam_placer; + /* Origin of print coordinates expressed in unscaled G-code coordinates. This affects the input arguments supplied to the extrude*() and travel_to() methods. */ @@ -321,8 +300,10 @@ private: FullPrintConfig m_config; GCodeWriter m_writer; PlaceholderParser m_placeholder_parser; + // For random number generator etc. + PlaceholderParser::ContextData m_placeholder_parser_context; // Collection of templates, on which the placeholder substitution failed. - std::set<std::string> m_placeholder_parser_failed_templates; + std::map<std::string, std::string> m_placeholder_parser_failed_templates; OozePrevention m_ooze_prevention; Wipe m_wipe; AvoidCrossingPerimeters m_avoid_crossing_perimeters; @@ -334,11 +315,8 @@ private: // Markers for the Pressure Equalizer to recognize the extrusion type. // The Pressure Equalizer removes the markers from the final G-code. bool m_enable_extrusion_role_markers; - // Enableds the G-code Analyzer. - // Extended markers will be added during G-code generation. - // The G-code Analyzer will remove these comments from the final G-code. - bool m_enable_analyzer; - ExtrusionRole m_last_analyzer_extrusion_role; + // Keeps track of the last extrusion role passed to the processor + ExtrusionRole m_last_processor_extrusion_role; // How many times will change_layer() be called? // change_layer() will update the progress bar. unsigned int m_layer_count; @@ -347,14 +325,22 @@ private: // 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* m_layer; - std::map<const PrintObject*,Point> m_seam_position; double m_volumetric_speed; // Support for the extrusion role markers. Which marker is active? ExtrusionRole m_last_extrusion_role; - // Support for G-Code Analyzer + // Support for G-Code Processor + float m_last_height{ 0.0f }; + float m_last_layer_z{ 0.0f }; + float m_max_layer_z{ 0.0f }; +#if ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE + float m_last_width{ 0.0f }; +#endif // ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE +#if ENABLE_GCODE_VIEWER_DATA_CHECKING double m_last_mm3_per_mm; - float m_last_width; - float m_last_height; +#if !ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE + float m_last_width{ 0.0f }; +#endif // !ENABLE_TOOLPATHS_WIDTH_HEIGHT_FROM_GCODE +#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING Point m_last_pos; bool m_last_pos_defined; @@ -375,13 +361,10 @@ private: // Index of a last object copy extruded. std::pair<const PrintObject*, Point> m_last_obj_copy; - // Time estimators - GCodeTimeEstimator m_normal_time_estimator; - GCodeTimeEstimator m_silent_time_estimator; bool m_silent_time_estimator_enabled; - // Analyzer - GCodeAnalyzer m_analyzer; + // Processor + GCodeProcessor m_processor; // Write a string into a file. void _write(FILE* file, const std::string& what) { this->_write(file, what.c_str()); } |