From f9dd251276c997b503c845ea9678291c1e3239b2 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 5 Feb 2018 13:16:08 +0100 Subject: [PATCH] GCode Preview - Added feature type for wipe tower --- lib/Slic3r/GUI/Plater/3DPreview.pm | 2 +- xs/src/libslic3r/ExtrusionEntity.hpp | 1 + xs/src/libslic3r/GCode.cpp | 2 ++ xs/src/libslic3r/GCode/Analyzer.cpp | 37 ++++++++++++--------- xs/src/libslic3r/GCode/Analyzer.hpp | 2 ++ xs/src/libslic3r/GCode/WipeTowerPrusaMM.cpp | 17 ++++++++++ 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index ed84135e2..af0cb16c8 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -77,7 +77,7 @@ sub new { $combochecklist_features->UseAltPopupWindow(); $combochecklist_features->EnablePopupAnimation(0); my $feature_text = "Feature types"; - my $feature_items = "Perimeter|External perimeter|Overhang perimeter|Internal infill|Solid infill|Top solid infill|Bridge infill|Gap fill|Skirt|Support material|Support material interface"; + my $feature_items = "Perimeter|External perimeter|Overhang perimeter|Internal infill|Solid infill|Top solid infill|Bridge infill|Gap fill|Skirt|Support material|Support material interface|Wipe tower"; Slic3r::GUI::create_combochecklist($combochecklist_features, $feature_text, $feature_items, 1); my $checkbox_travel = Wx::CheckBox->new($self, -1, "Travel"); diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index a85ccda06..650a806f6 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -25,6 +25,7 @@ enum ExtrusionRole { erSkirt, erSupportMaterial, erSupportMaterialInterface, + erWipeTower, // Extrusion role for a collection with multiple extrusion roles. erMixed, }; diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 14402a1e1..c256268e5 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -1454,7 +1454,9 @@ static inline const char* ExtrusionRole2String(const ExtrusionRole role) case erSkirt: return "erSkirt"; case erSupportMaterial: return "erSupportMaterial"; case erSupportMaterialInterface: return "erSupportMaterialInterface"; + case erWipeTower: return "erWipeTower"; case erMixed: return "erMixed"; + default: return "erInvalid"; }; } diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 2ddb319fc..b4d7f2596 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -195,19 +195,20 @@ GCodeAnalyzer::PreviewData::LegendItem::LegendItem(const std::string& text, cons const GCodeAnalyzer::PreviewData::Color GCodeAnalyzer::PreviewData::Extrusion::Default_Extrusion_Role_Colors[Num_Extrusion_Roles] = { - Color(0.0f, 0.0f, 0.0f, 1.0f), // erNone - Color(1.0f, 0.0f, 0.0f, 1.0f), // erPerimeter - Color(0.0f, 1.0f, 0.0f, 1.0f), // erExternalPerimeter - Color(0.0f, 0.0f, 1.0f, 1.0f), // erOverhangPerimeter - Color(1.0f, 1.0f, 0.0f, 1.0f), // erInternalInfill - Color(1.0f, 0.0f, 1.0f, 1.0f), // erSolidInfill - Color(0.0f, 1.0f, 1.0f, 1.0f), // erTopSolidInfill - Color(0.5f, 0.5f, 0.5f, 1.0f), // erBridgeInfill - Color(1.0f, 1.0f, 1.0f, 1.0f), // erGapFill - Color(0.5f, 0.0f, 0.0f, 1.0f), // erSkirt - Color(0.0f, 0.5f, 0.0f, 1.0f), // erSupportMaterial - Color(0.0f, 0.0f, 0.5f, 1.0f), // erSupportMaterialInterface - Color(0.0f, 0.0f, 0.0f, 1.0f) // erMixed + Color(0.0f, 0.0f, 0.0f, 1.0f), // erNone + Color(1.0f, 0.0f, 0.0f, 1.0f), // erPerimeter + Color(0.0f, 1.0f, 0.0f, 1.0f), // erExternalPerimeter + Color(0.0f, 0.0f, 1.0f, 1.0f), // erOverhangPerimeter + Color(1.0f, 1.0f, 0.0f, 1.0f), // erInternalInfill + Color(1.0f, 0.0f, 1.0f, 1.0f), // erSolidInfill + Color(0.0f, 1.0f, 1.0f, 1.0f), // erTopSolidInfill + Color(0.5f, 0.5f, 0.5f, 1.0f), // erBridgeInfill + Color(1.0f, 1.0f, 1.0f, 1.0f), // erGapFill + Color(0.5f, 0.0f, 0.0f, 1.0f), // erSkirt + Color(0.0f, 0.5f, 0.0f, 1.0f), // erSupportMaterial + Color(0.0f, 0.0f, 0.5f, 1.0f), // erSupportMaterialInterface + Color(0.7f, 0.89f, 0.67f, 1.0f), // erWipeTower + Color(0.0f, 0.0f, 0.0f, 1.0f) // erMixed }; // todo: merge with Slic3r::ExtrusionRole2String() from GCode.cpp @@ -225,6 +226,7 @@ const std::string GCodeAnalyzer::PreviewData::Extrusion::Default_Extrusion_Role_ "Skirt", "Support material", "Support material interface", + "Wipe tower", "Mixed" }; @@ -258,7 +260,7 @@ bool GCodeAnalyzer::PreviewData::Extrusion::is_role_flag_set(ExtrusionRole role) bool GCodeAnalyzer::PreviewData::Extrusion::is_role_flag_set(unsigned int flags, ExtrusionRole role) { - if ((role < erPerimeter) || (erSupportMaterialInterface < role)) + if (!is_valid_extrusion_role(role)) return false; unsigned int flag = (unsigned int)::exp2((double)(role - erPerimeter)); @@ -458,6 +460,11 @@ void GCodeAnalyzer::calc_gcode_preview_data(Print& print) _calc_gcode_preview_unretractions(print); } +bool GCodeAnalyzer::is_valid_extrusion_role(ExtrusionRole role) +{ + return ((erPerimeter <= role) && (role < erMixed)); +} + void GCodeAnalyzer::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line) { // processes 'special' comments contained in line @@ -597,7 +604,7 @@ void GCodeAnalyzer::_processG1(const GCodeReader::GCodeLine& line) type = GCodeMove::Move; ExtrusionRole role = _get_extrusion_role(); - if ((type == GCodeMove::Extrude) && ((_get_width() == 0.0f) || (_get_height() == 0.0f) || (role < erPerimeter) || (erSupportMaterialInterface < role))) + if ((type == GCodeMove::Extrude) && ((_get_width() == 0.0f) || (_get_height() == 0.0f) || !is_valid_extrusion_role(role))) type = GCodeMove::Move; // updates axis positions diff --git a/xs/src/libslic3r/GCode/Analyzer.hpp b/xs/src/libslic3r/GCode/Analyzer.hpp index a72874a35..1671c35ca 100644 --- a/xs/src/libslic3r/GCode/Analyzer.hpp +++ b/xs/src/libslic3r/GCode/Analyzer.hpp @@ -293,6 +293,8 @@ public: // Calculates all data needed for gcode visualization void calc_gcode_preview_data(Print& print); + static bool is_valid_extrusion_role(ExtrusionRole role); + private: // Processes the given gcode line void _process_gcode_line(GCodeReader& reader, const GCodeReader::GCodeLine& line); diff --git a/xs/src/libslic3r/GCode/WipeTowerPrusaMM.cpp b/xs/src/libslic3r/GCode/WipeTowerPrusaMM.cpp index 858845e3d..99c6c757f 100644 --- a/xs/src/libslic3r/GCode/WipeTowerPrusaMM.cpp +++ b/xs/src/libslic3r/GCode/WipeTowerPrusaMM.cpp @@ -6,6 +6,8 @@ #include #include +#include "Analyzer.hpp" + #if defined(__linux) || defined(__GNUC__ ) #include #endif /* __linux */ @@ -419,6 +421,11 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::prime( // Increase the extruder driver current to allow fast ramming. .set_extruder_trimpot(750); + // adds tag for analyzer + char buf[32]; + sprintf(buf, ";%s%d\n", GCodeAnalyzer::Extrusion_Role_Tag.c_str(), erWipeTower); + writer.append(buf); + if (purpose == PURPOSE_EXTRUDE || purpose == PURPOSE_MOVE_TO_TOWER_AND_EXTRUDE) { float y_end = 0.f; for (size_t idx_tool = 0; idx_tool < tools.size(); ++ idx_tool) { @@ -554,6 +561,11 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::tool_change(unsigned int tool, boo writer.set_initial_position(initial_position); } + // adds tag for analyzer + char buf[32]; + sprintf(buf, ";%s%d\n", GCodeAnalyzer::Extrusion_Role_Tag.c_str(), erWipeTower); + writer.append(buf); + if (purpose == PURPOSE_EXTRUDE || purpose == PURPOSE_MOVE_TO_TOWER_AND_EXTRUDE) { // Increase the extruder driver current to allow fast ramming. writer.set_extruder_trimpot(750); @@ -637,6 +649,11 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::toolchange_Brim(Purpose purpose, b else writer.set_initial_position(initial_position); + // adds tag for analyzer + char buf[32]; + sprintf(buf, ";%s%d\n", GCodeAnalyzer::Extrusion_Role_Tag.c_str(), erWipeTower); + writer.append(buf); + if (purpose == PURPOSE_EXTRUDE || purpose == PURPOSE_MOVE_TO_TOWER_AND_EXTRUDE) { // Prime the extruder 10*m_perimeter_width left along the vertical edge of the wipe tower. writer.extrude_explicit(wipeTower_box.ld - xy(m_perimeter_width * 6.f, 0),