From 8aeafcb2f4bcd9c2e6308d98b1c29920a01ee06b Mon Sep 17 00:00:00 2001 From: Thomas Rahm <67757218+ThomasRahm@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:49:12 +0100 Subject: [PATCH 1/5] Changed when fan speed is added to the Gcode to better handle fan speeds changed in plugin. Added some code to clean up plugin output, and set first_travel_destination if it was changed. --- src/LayerPlan.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 52305a9521..80a2ac9cb0 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -1920,7 +1920,11 @@ void LayerPlan::writeGCode(GCodeExport& gcode) } } } - gcode.writeFanCommand(extruder_plan.getFanSpeed()); + // Fan speed may already be set by plugin. Prevents two fan speed commands without move in between. + if(!extruder_plan.paths.empty() && extruder_plan.paths.front().fan_speed == -1) + { + gcode.writeFanCommand(extruder_plan.getFanSpeed()); + } std::vector& paths = extruder_plan.paths; extruder_plan.inserts.sort(); @@ -1943,6 +1947,14 @@ void LayerPlan::writeGCode(GCodeExport& gcode) GCodePath& path = paths[path_idx]; + // Fans need time to reach the new setting. Adjust fan speed as early as possible. If travel paths have a non default fan speed for some reason set it as fan speed. + // As such modification could be made by a plugin. + if(!path.isTravelPath() || path.fan_speed < 0) + { + const double path_fan_speed = path.getFanSpeed(); + gcode.writeFanCommand(path_fan_speed != GCodePathConfig::FAN_SPEED_DEFAULT ? path_fan_speed : extruder_plan.getFanSpeed()); + } + if (path.perform_prime) { gcode.writePrimeTrain(extruder.settings.get("speed_travel")); @@ -2095,9 +2107,6 @@ void LayerPlan::writeGCode(GCodeExport& gcode) bool spiralize = path.spiralize; if (! spiralize) // normal (extrusion) move (with coasting) { - // if path provides a valid (in range 0-100) fan speed, use it - const double path_fan_speed = path.getFanSpeed(); - gcode.writeFanCommand(path_fan_speed != GCodePathConfig::FAN_SPEED_DEFAULT ? path_fan_speed : extruder_plan.getFanSpeed()); bool coasting = extruder.settings.get("coasting_enable"); if (coasting) @@ -2373,6 +2382,7 @@ bool LayerPlan::writePathWithCoasting( void LayerPlan::applyModifyPlugin() { + bool handled_initial_travel = false; for (auto& extruder_plan : extruder_plans) { scripta::log( @@ -2395,6 +2405,40 @@ void LayerPlan::applyModifyPlugin() extruder_plan.paths = slots::instance().modify(extruder_plan.paths, extruder_plan.extruder_nr, layer_nr); + // Check if the plugin changed first_travel_destination and update it accordingly if it has + if (! handled_initial_travel) + { + for (auto& path : extruder_plan.paths) + { + if (path.isTravelPath() && path.points.size() > 0) + { + if (path.points.front() != first_travel_destination) + { + first_travel_destination = path.points.front(); + first_travel_destination_is_inside = current_mesh->layers[layer_nr].getOutlines().inside(path.points.front()); + } + handled_initial_travel = true; + } + } + } + + size_t removed_count = std::erase_if( + extruder_plan.paths, + [](GCodePath& path) + { + return path.points.empty(); + }); + if (removed_count > 0) + { + spdlog::warn("Removed {} empty paths after plugin slot GCODE_PATHS_MODIFY was executed", removed_count); + } + // Ensure that the output is at least valid enough to not cause crashes. + if (extruder_plan.paths.size() == 0) + { + GCodePath* reinstated_path = getLatestPathWithConfig(configs_storage.travel_config_per_extruder[getExtruder()], SpaceFillType::None); + addTravel_simple(first_travel_destination.value_or(getLastPlannedPositionOrStartingPosition()), reinstated_path); + } + scripta::log( "extruder_plan_1", extruder_plan.paths, @@ -2413,6 +2457,7 @@ void LayerPlan::applyModifyPlugin() scripta::CellVDI{ "is_travel_path", &GCodePath::isTravelPath }, scripta::CellVDI{ "extrusion_mm3_per_mm", &GCodePath::getExtrusionMM3perMM }); } + } void LayerPlan::applyBackPressureCompensation() From 64467ecf196b9681f72e0dd3880e56a8e2a386c4 Mon Sep 17 00:00:00 2001 From: Thomas Rahm <67757218+ThomasRahm@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:28:06 +0100 Subject: [PATCH 2/5] Fix issues with first_travel_destination detection after plugins were applied --- src/LayerPlan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 80a2ac9cb0..b026482b9b 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -2415,9 +2415,9 @@ void LayerPlan::applyModifyPlugin() if (path.points.front() != first_travel_destination) { first_travel_destination = path.points.front(); - first_travel_destination_is_inside = current_mesh->layers[layer_nr].getOutlines().inside(path.points.front()); } handled_initial_travel = true; + break; } } } From 404c35d68715c93a0d5c186b0c1724f54058be4d Mon Sep 17 00:00:00 2001 From: Thomas Rahm <67757218+ThomasRahm@users.noreply.github.com> Date: Wed, 8 Nov 2023 03:54:03 +0100 Subject: [PATCH 3/5] Fix per object settings not sent to plugin. Added "mesh_name" field so that the objects can be later identified. --- src/plugins/converters.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/plugins/converters.cpp b/src/plugins/converters.cpp index 72a8166de7..31ee0aa394 100644 --- a/src/plugins/converters.cpp +++ b/src/plugins/converters.cpp @@ -49,12 +49,28 @@ broadcast_settings_request::value_type broadcast_settings_request::operator()(co } auto* object_settings = message.mutable_object_settings(); - for (const auto& object : slice_message.object_lists()) + for (const auto& mesh_group : slice_message.object_lists()) { - auto* settings = object_settings->Add()->mutable_settings(); - for (const auto& setting : object.settings()) + std::unordered_map mesh_group_settings; + for (const auto& setting : mesh_group.settings()) { - settings->emplace(setting.name(), setting.value()); + mesh_group_settings[setting.name()] = setting.value(); + } + for (const auto& object : mesh_group.objects()) + { + std::unordered_map per_object_settings = mesh_group_settings; + for (const auto& setting : object.settings()) + { + per_object_settings[setting.name()] = setting.value(); + } + + per_object_settings["mesh_name"] = object.name(); + + auto* settings = object_settings->Add()->mutable_settings(); + for (const auto& key_value_pair : per_object_settings) + { + settings->emplace(key_value_pair.first, key_value_pair.second); + } } } From 3bae85189e69585a055d5dc1fbdac73397b06464 Mon Sep 17 00:00:00 2001 From: Thomas Rahm <67757218+ThomasRahm@users.noreply.github.com> Date: Wed, 8 Nov 2023 14:27:54 +0100 Subject: [PATCH 4/5] Fix final travel move using default fan speed --- src/LayerPlan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index b026482b9b..6fa21391a7 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -1949,7 +1949,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) // Fans need time to reach the new setting. Adjust fan speed as early as possible. If travel paths have a non default fan speed for some reason set it as fan speed. // As such modification could be made by a plugin. - if(!path.isTravelPath() || path.fan_speed < 0) + if(!path.isTravelPath() || path.fan_speed >= 0) { const double path_fan_speed = path.getFanSpeed(); gcode.writeFanCommand(path_fan_speed != GCodePathConfig::FAN_SPEED_DEFAULT ? path_fan_speed : extruder_plan.getFanSpeed()); From 8b91a8844ffcc5aa5b3cdb2c9b17d1294c299003 Mon Sep 17 00:00:00 2001 From: Thomas Rahm <67757218+ThomasRahm@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:01:41 +0200 Subject: [PATCH 5/5] Fixed issues caused by merge and improved comments --- src/LayerPlan.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 29a568838c..48b0d926e7 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -2088,8 +2088,8 @@ void LayerPlan::writeGCode(GCodeExport& gcode) } } } - // Fan speed may already be set by plugin. Prevents two fan speed commands without move in between. - if(!extruder_plan.paths.empty() && extruder_plan.paths.front().fan_speed == -1) + // Fan speed may already be set by a plugin. Prevents two fan speed commands without move in between. + if(!extruder_plan.paths_.empty() && extruder_plan.paths_.front().fan_speed == -1) { gcode.writePrepareFansForExtrusion(extruder_plan.getFanSpeed()); } @@ -2115,8 +2115,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) GCodePath& path = paths[path_idx]; - // Fans need time to reach the new setting. Adjust fan speed as early as possible. If travel paths have a non default fan speed for some reason set it as fan speed. - // As such modification could be made by a plugin. + // If travel paths have a non default fan speed for some reason set it as fan speed as such modification could be made by a plugin. if(!path.isTravelPath() || path.fan_speed >= 0) { const double path_fan_speed = path.getFanSpeed(); @@ -2603,13 +2602,13 @@ void LayerPlan::applyModifyPlugin() // Check if the plugin changed first_travel_destination and update it accordingly if it has if (! handled_initial_travel) { - for (auto& path : extruder_plan.paths) + for (auto& path : extruder_plan.paths_) { if (path.isTravelPath() && path.points.size() > 0) { - if (path.points.front() != first_travel_destination) + if (path.points.front() != first_travel_destination_) { - first_travel_destination = path.points.front(); + first_travel_destination_ = path.points.front(); } handled_initial_travel = true; break; @@ -2618,7 +2617,7 @@ void LayerPlan::applyModifyPlugin() } size_t removed_count = std::erase_if( - extruder_plan.paths, + extruder_plan.paths_, [](GCodePath& path) { return path.points.empty(); @@ -2628,10 +2627,10 @@ void LayerPlan::applyModifyPlugin() spdlog::warn("Removed {} empty paths after plugin slot GCODE_PATHS_MODIFY was executed", removed_count); } // Ensure that the output is at least valid enough to not cause crashes. - if (extruder_plan.paths.size() == 0) + if (extruder_plan.paths_.size() == 0) { - GCodePath* reinstated_path = getLatestPathWithConfig(configs_storage.travel_config_per_extruder[getExtruder()], SpaceFillType::None); - addTravel_simple(first_travel_destination.value_or(getLastPlannedPositionOrStartingPosition()), reinstated_path); + GCodePath* reinstated_path = getLatestPathWithConfig(configs_storage_.travel_config_per_extruder[getExtruder()], SpaceFillType::None); + addTravel_simple(first_travel_destination_.value_or(getLastPlannedPositionOrStartingPosition()), reinstated_path); } scripta::log( @@ -2652,7 +2651,6 @@ void LayerPlan::applyModifyPlugin() scripta::CellVDI{ "is_travel_path", &GCodePath::isTravelPath }, scripta::CellVDI{ "extrusion_mm3_per_mm", &GCodePath::getExtrusionMM3perMM }); } - } void LayerPlan::applyBackPressureCompensation()