mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-05 03:08:00 -05:00
Merge branch 'main' into fix/ams-sync-preset-override
This commit is contained in:
commit
abe28edbe7
70 files changed
+1837
-373
No files matched your search
@@ -650,6 +650,9 @@ jobs:
|
||||
chmod +x "$appimage"
|
||||
"$appimage" --appimage-extract
|
||||
./scripts/build_preset_cache.sh -b build build/package/resources/profiles squashfs-root/resources/profiles
|
||||
# The runtime extracts every directory as 0700, and appimagetool (continuous
|
||||
# build 333 onwards) refuses to pack a tree other users cannot read.
|
||||
chmod -R a+rX squashfs-root
|
||||
appimagetool=$(find build -name "appimagetool.AppImage" | head -1)
|
||||
ARCH=$(uname -m) "$appimagetool" --appimage-extract-and-run squashfs-root "$appimage"
|
||||
rm -rf squashfs-root
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
name: Stale issues and PRs
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
actions: write # save the run state in the actions cache
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v11
|
||||
with:
|
||||
# Each new stale label costs about 2 operations. Runs that stop early
|
||||
# continue from the same place the next day.
|
||||
operations-per-run: 300
|
||||
ascending: true
|
||||
stale-issue-label: stale
|
||||
stale-pr-label: stale
|
||||
remove-stale-when-updated: true
|
||||
|
||||
# Issues
|
||||
days-before-issue-stale: 90
|
||||
days-before-issue-close: 14
|
||||
close-issue-reason: not_planned
|
||||
exempt-issue-labels: enhancement
|
||||
exempt-all-issue-assignees: true
|
||||
exempt-all-issue-milestones: true
|
||||
stale-issue-message: |
|
||||
This issue has had no activity for 90 days, so it will be closed in 14 days.
|
||||
|
||||
If it still happens on the latest OrcaSlicer release, please leave a comment with the version you tested and it will stay open.
|
||||
close-issue-message: |
|
||||
This issue was closed because there was no activity after the reminder.
|
||||
|
||||
If it still happens on the latest release, leave a comment here and a team member can reopen it, or open a new issue with the details.
|
||||
|
||||
# PRs: only PRs where we asked the author for something
|
||||
only-pr-labels: "wait for response"
|
||||
days-before-pr-stale: 90
|
||||
days-before-pr-close: 14
|
||||
exempt-draft-pr: true
|
||||
exempt-all-pr-assignees: true
|
||||
exempt-all-pr-milestones: true
|
||||
delete-branch: false
|
||||
stale-pr-message: |
|
||||
We asked for changes or more information on this PR, and there has been no activity for 90 days. It will be closed in 14 days.
|
||||
|
||||
To keep it open, leave a comment. If you push new commits, please also leave a short comment, because a push alone does not reset this. If you no longer have time for it, that is fine, just let us know.
|
||||
close-pr-message: |
|
||||
This PR was closed because we did not hear back after the reminder. Thank you for the work you put into it.
|
||||
|
||||
If you want to continue, push your changes and reopen it, or open a new PR.
|
||||
Vendored
+1
-1
@@ -32,7 +32,7 @@ endif ()
|
||||
orcaslicer_add_cmake_project(
|
||||
wxWidgets
|
||||
GIT_REPOSITORY "https://github.com/OrcaSlicer/Orca-deps-wxWidgets"
|
||||
GIT_TAG 5b7e8c0cde6b975d63613188d2ac6c1ab8769fbc
|
||||
GIT_TAG b44c39c100975a0ac0e46f937aa3f3eae5e18631
|
||||
GIT_SHALLOW ON
|
||||
GIT_SUBMODULES 3rdparty/catch 3rdparty/pcre 3rdparty/libwebp
|
||||
DEPENDS ${PNG_PKG} ${ZLIB_PKG} ${EXPAT_PKG} ${JPEG_PKG}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Creality",
|
||||
"version": "02.03.02.87",
|
||||
"version": "02.03.02.88",
|
||||
"force_update": "0",
|
||||
"description": "Creality configurations",
|
||||
"machine_model_list": [
|
||||
|
||||
@@ -150,7 +150,8 @@
|
||||
"fan_speedup_overhangs": "1",
|
||||
"fan_speedup_time": "0",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_load_filament_time": "119",
|
||||
|
||||
@@ -152,7 +152,8 @@
|
||||
"fan_speedup_overhangs": "1",
|
||||
"fan_speedup_time": "0",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_load_filament_time": "119",
|
||||
|
||||
@@ -152,7 +152,8 @@
|
||||
"fan_speedup_overhangs": "1",
|
||||
"fan_speedup_time": "0",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_load_filament_time": "119",
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
"fan_speedup_time": "0",
|
||||
"gcode_flavor": "klipper",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_end_gcode": "END_PRINT",
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
"fan_speedup_time": "0",
|
||||
"gcode_flavor": "klipper",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_end_gcode": "END_PRINT",
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
"fan_speedup_time": "0",
|
||||
"gcode_flavor": "klipper",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_end_gcode": "END_PRINT",
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
"fan_speedup_time": "0",
|
||||
"gcode_flavor": "klipper",
|
||||
"high_current_on_filament_swap": "0",
|
||||
"host_type": "octoprint",
|
||||
"host_type": "crealityprint",
|
||||
"printer_agent": "crealityprint",
|
||||
"layer_change_gcode": ";AFTER_LAYER_CHANGE\n;[layer_z]",
|
||||
"machine_LED_light_exist": "1",
|
||||
"machine_end_gcode": "END_PRINT",
|
||||
|
||||
@@ -118,9 +118,9 @@ modules:
|
||||
# Use git instead of archive: wxWidgets 3.3 relies on multiple git
|
||||
# submodules (PCRE2, etc.) that are not included in GitHub tarballs.
|
||||
- type: git
|
||||
url: https://github.com/SoftFever/Orca-deps-wxWidgets.git
|
||||
tag: orca-3.3.2
|
||||
commit: db1005db3dea2c37a46fb455a9a02e37aa360751
|
||||
url: https://github.com/OrcaSlicer/Orca-deps-wxWidgets.git
|
||||
branch: v3.3.2
|
||||
commit: b44c39c100975a0ac0e46f937aa3f3eae5e18631
|
||||
|
||||
# OrcaSlicer C++ dependencies (built offline with pre-downloaded archives)
|
||||
- name: orca_deps
|
||||
|
||||
@@ -496,16 +496,20 @@ void ConfigBase::apply_only(const ConfigBase &other, const t_config_option_keys
|
||||
auto opt_key2 = opt_key.substr(0, n);
|
||||
auto my_opt2 = dynamic_cast<ConfigOptionVectorBase*>(this->option(opt_key2));
|
||||
auto other_opt = other.option(opt_key2);
|
||||
if (my_opt2 == nullptr && other_opt) {
|
||||
if (my_opt2 == nullptr && other_opt)
|
||||
my_opt2 = dynamic_cast<ConfigOptionVectorBase *>(this->option(opt_key2, true));
|
||||
if (my_opt2->empty()) {
|
||||
my_opt2->resize(1, other_opt);
|
||||
}
|
||||
}
|
||||
if (my_opt2) {
|
||||
int index = std::atoi(opt_key.c_str() + n + 1);
|
||||
if (other_opt)
|
||||
auto other_vec = dynamic_cast<const ConfigOptionVectorBase *>(other_opt);
|
||||
if (other_vec && other_vec->empty()) {
|
||||
// An empty source list has no entry at any index to copy.
|
||||
my_opt2->set(other_opt);
|
||||
} else if (other_opt) {
|
||||
// set_at() pads from the first value, which an empty vector lacks.
|
||||
if (my_opt2->empty())
|
||||
my_opt2->resize(1, other_opt);
|
||||
int index = std::atoi(opt_key.c_str() + n + 1);
|
||||
my_opt2->set_at(other_opt, index, index);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8808,7 +8808,7 @@ bool _BBS_3MF_Exporter::_add_model_config_file_to_archive(mz_zip_archive& archiv
|
||||
|
||||
if (plate_data->limit_filament_maps.size() > 0) {
|
||||
stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << LIMIT_FILAMENT_MAP_ATTR << "\" " << VALUE_ATTR << "=\"";
|
||||
add_vector<int>(stream, plate_data->limit_filament_maps);
|
||||
add_vector<uint64_t>(stream, plate_data->limit_filament_maps);
|
||||
stream << "\"/>\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "libslic3r/ProjectTask.hpp"
|
||||
#include "libslic3r/GCode/GCodeProcessor.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <set>
|
||||
@@ -140,12 +141,8 @@ struct PlateData
|
||||
std::vector<MultiNozzleUtils::NozzleInfo> nozzles_info;
|
||||
std::optional<MultiNozzleUtils::LayeredNozzleGroupResult> nozzle_group_result;
|
||||
|
||||
// Hexadecimal number,
|
||||
// the 0th digit corresponds to extruder 1
|
||||
// the 1th digit corresponds to extruder 2
|
||||
// ... and so on.
|
||||
// 0 means can be print on this extruder, 1 means cannot
|
||||
std::vector<int> limit_filament_maps;
|
||||
// Per filament, bit i is set when extruder i + 1 can't print it.
|
||||
std::vector<uint64_t> limit_filament_maps;
|
||||
|
||||
std::vector<GCodeProcessorResult::SliceWarning> warnings;
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
#include <regex>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/find.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
@@ -1259,6 +1260,17 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||
|
||||
end_filament_gcode_str = toolchange_retract_str + object_end_label_temp + end_filament_gcode_str;
|
||||
|
||||
// Lift to the layer Z so the toolchange can't hit taller printed parts. Only a custom macro or
|
||||
// a switch to another physical extruder (whose firmware Tn may dock) can travel. The
|
||||
// compacted_below_object descent below brings Z back down once over the tower.
|
||||
const bool tool_may_travel = !change_filament_gcode.empty()
|
||||
|| (gcodegen.writer().filament() != nullptr && gcodegen.writer().filament()->extruder_id() != unsigned(new_extruder_id));
|
||||
std::string restore_layer_z_str;
|
||||
if (compacted_below_object && tool_may_travel && gcodegen.writer().get_position().z() < current_z - EPSILON) {
|
||||
restore_layer_z_str += gcodegen.writer().travel_to_z(current_z, "Restore layer Z before toolchange");
|
||||
check_add_eol(restore_layer_z_str);
|
||||
}
|
||||
|
||||
std::string wipe_next_start_point_str;
|
||||
bool need_travel_after_change_filament_gcode = false; // travel need be after the filament changed to get the correct "m_curr_extruder_id"
|
||||
if (! change_filament_gcode.empty()) {
|
||||
@@ -1613,6 +1625,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||
// Insert the end filament, toolchange, and start filament gcode into the generated gcode.
|
||||
DynamicConfig config;
|
||||
config.set_key_value("filament_end_gcode", new ConfigOptionString(end_filament_gcode_str));
|
||||
config.set_key_value("restore_layer_z_before_toolchange", new ConfigOptionString(restore_layer_z_str));
|
||||
config.set_key_value("change_filament_gcode", new ConfigOptionString(toolchange_gcode_str));
|
||||
config.set_key_value("filament_start_gcode", new ConfigOptionString(start_filament_gcode_str));
|
||||
std::string tcr_gcode, tcr_escaped_gcode = gcodegen.placeholder_parser_process("tcr_rotated_gcode", tcr_rotated_gcode, new_filament_id, &config);
|
||||
@@ -1746,6 +1759,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||
|
||||
std::string toolchange_gcode_str;
|
||||
std::string deretraction_str;
|
||||
std::string restore_layer_z_str;
|
||||
int toolchange_temp_override = -1;
|
||||
int interface_temp = -1;
|
||||
if (tcr.priming || (new_extruder_id >= 0 && needs_toolchange)) {
|
||||
@@ -1757,6 +1771,15 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||
interface_temp = gcodegen.config().nozzle_temperature_range_high.get_at(gcodegen.get_filament_config_index(new_extruder_id));
|
||||
toolchange_temp_override = interface_temp;
|
||||
}
|
||||
// Lift to the layer Z so the toolchange can't hit taller printed parts. Only a custom macro
|
||||
// or a switch to another physical extruder (whose firmware Tn may dock) can travel.
|
||||
const bool tool_may_travel = !gcodegen.config().change_filament_gcode.value.empty()
|
||||
|| (gcodegen.writer().filament() != nullptr
|
||||
&& gcodegen.writer().filament()->extruder_id() != get_extruder_index(*m_print_config, new_extruder_id));
|
||||
if (will_go_down && tool_may_travel && gcodegen.config().enable_prime_tower) {
|
||||
restore_layer_z_str += gcodegen.writer().travel_to_z(current_z, "Restore layer Z before toolchange");
|
||||
check_add_eol(restore_layer_z_str);
|
||||
}
|
||||
toolchange_gcode_str = gcodegen.set_extruder(new_extruder_id, tcr.print_z, false, toolchange_temp_override,
|
||||
WipeTower2::wait_for_temp_enabled(gcodegen.m_config)); // TODO: toolchange_z vs print_z
|
||||
if (!travel_to_tower_now && !tcr.priming && WipeTower2::use_gap_wall(gcodegen.m_config)) {
|
||||
@@ -1914,6 +1937,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||
DynamicConfig config;
|
||||
config.set_key_value("change_filament_gcode", new ConfigOptionString(toolchange_gcode_str));
|
||||
config.set_key_value("deretraction_from_wipe_tower_generator", new ConfigOptionString(deretraction_str));
|
||||
config.set_key_value("restore_layer_z_before_toolchange", new ConfigOptionString(restore_layer_z_str));
|
||||
config.set_key_value("layer_num", new ConfigOptionInt(gcodegen.m_layer_index));
|
||||
config.set_key_value("layer_z", new ConfigOptionFloat(tcr.print_z));
|
||||
config.set_key_value("toolchange_z", new ConfigOptionFloat(z));
|
||||
@@ -3713,6 +3737,20 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
||||
this->placeholder_parser().set("first_filaments", new ConfigOptionInts(first_filaments));
|
||||
this->placeholder_parser().set("initial_tool", initial_extruder_id);
|
||||
this->placeholder_parser().set("initial_extruder", initial_extruder_id);
|
||||
// Orca: filament types really extruded on this plate, deduplicated, in filament id order.
|
||||
// Joined with '_': safe in URLs and on print hosts, and unlike '-' it does not clash with
|
||||
// types that already contain a hyphen (PLA-CF, TPU-95A).
|
||||
std::string printing_filament_types;
|
||||
{
|
||||
std::vector<std::string> types;
|
||||
for (const Extruder &extruder : m_writer.extruders()) {
|
||||
std::string type = m_config.filament_type.get_at(extruder.id());
|
||||
if (std::find(types.begin(), types.end(), type) == types.end())
|
||||
types.emplace_back(std::move(type));
|
||||
}
|
||||
printing_filament_types = boost::algorithm::join(types, "_");
|
||||
}
|
||||
this->placeholder_parser().set("printing_filament_types", printing_filament_types);
|
||||
//BBS
|
||||
match_physical_extruder_for_each_filament(first_non_support_filaments, m_config);
|
||||
|
||||
@@ -4914,6 +4952,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
||||
print.tool_ordering()));
|
||||
print.m_print_statistics.initial_tool = initial_extruder_id;
|
||||
print.m_print_statistics.initial_no_support_tool = initial_non_support_extruder_id;
|
||||
// Set again here: update_print_stats_and_format_filament_stats() above cleared the statistics.
|
||||
print.m_print_statistics.printing_filament_types = printing_filament_types;
|
||||
if (!is_bbl_printers) {
|
||||
file.write_format("; total filament used [g] = %.2lf\n",
|
||||
print.m_print_statistics.total_weight);
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <deque>
|
||||
@@ -3022,11 +3023,11 @@ bool GCodeProcessor::check_multi_extruder_gcode_valid(const int
|
||||
auto unprintable_extruders = [&unprintable_areas, &unprintable_bboxes, &plate_offset](const BoundingBox &path_bbox) {
|
||||
BoundingBox bbox = path_bbox.inflated(SCALED_EPSILON);
|
||||
bbox.translate(-plate_offset);
|
||||
int mask = 0;
|
||||
uint64_t mask = 0;
|
||||
for (size_t i = 0; i < unprintable_areas.size(); ++i)
|
||||
if (!unprintable_areas[i].empty() && unprintable_bboxes[i].overlap(bbox) &&
|
||||
!intersection(unprintable_areas[i], bbox.polygon()).empty())
|
||||
mask |= 1 << i;
|
||||
mask |= uint64_t(1) << i;
|
||||
return mask;
|
||||
};
|
||||
|
||||
@@ -3084,9 +3085,9 @@ bool GCodeProcessor::check_multi_extruder_gcode_valid(const int
|
||||
//BoundingBox bbox_custom = path_poly_custom.bounding_box();
|
||||
//bbox_custom.offset(-scale_(1.0)); // Narrow the range to provide a tolerance for the custom gcode
|
||||
//bbox.merge(bbox_custom); // merge the custom gcode pos with other pos*/
|
||||
const int unprintable_mask = unprintable_extruders(bbox);
|
||||
const uint64_t unprintable_mask = unprintable_extruders(bbox);
|
||||
// check printable area
|
||||
if ((extruder_id < unprintable_areas.size()) && (unprintable_mask & (1 << extruder_id))) {
|
||||
if ((extruder_id < unprintable_areas.size()) && (unprintable_mask & (uint64_t(1) << extruder_id))) {
|
||||
m_result.gcode_check_result.error_code |= 1;
|
||||
std::pair<int, int> filament_to_object_id;
|
||||
filament_to_object_id.first = iter->first;
|
||||
@@ -3102,7 +3103,7 @@ bool GCodeProcessor::check_multi_extruder_gcode_valid(const int
|
||||
filament_to_object_id.first = iter->first;
|
||||
filament_to_object_id.second = object_label_id;
|
||||
m_result.gcode_check_result.print_height_error_infos[extruder_id].push_back(filament_to_object_id);
|
||||
m_result.limit_filament_maps[iter->first] |= (1 << extruder_id);
|
||||
m_result.limit_filament_maps[iter->first] |= uint64_t(1) << extruder_id;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
@@ -3115,7 +3116,7 @@ bool GCodeProcessor::check_multi_extruder_gcode_valid(const int
|
||||
for (int extruder_id = 0; extruder_id < unprintable_filament_types.size(); ++extruder_id) {
|
||||
const std::set<int> &filament_ids = unprintable_filament_types[extruder_id];
|
||||
for (int filament_id : filament_ids) {
|
||||
m_result.limit_filament_maps[filament_id] |= (1 << extruder_id);
|
||||
m_result.limit_filament_maps[filament_id] |= uint64_t(1) << extruder_id;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -389,7 +389,8 @@ inline constexpr float DEFAULT_FILAMENT_DENSITY = 1.245f;
|
||||
std::vector<float> filament_costs;
|
||||
std::vector<int> filament_vitrification_temperature;
|
||||
std::vector<int> filament_maps;
|
||||
std::vector<int> limit_filament_maps;
|
||||
// Per filament, bit i is set when extruder i + 1 can't print it.
|
||||
std::vector<uint64_t> limit_filament_maps;
|
||||
PrintEstimatedStatistics print_statistics;
|
||||
std::vector<CustomGCode::Item> custom_gcode_per_print_z;
|
||||
bool spiral_vase_mode;
|
||||
|
||||
@@ -2723,6 +2723,8 @@ void WipeTower::toolchange_Change(
|
||||
// This is where we want to place the custom gcodes. We will use placeholders for this.
|
||||
// These will be substituted by the actual gcodes when the gcode is generated.
|
||||
writer.append("[filament_end_gcode]\n");
|
||||
// Lift to the layer Z so change_filament_gcode can't hit taller printed parts.
|
||||
writer.append("[restore_layer_z_before_toolchange]\n");
|
||||
writer.append("[change_filament_gcode]\n");
|
||||
|
||||
// BBS: do travel in GCode::append_tcr() for lazy_lift
|
||||
|
||||
@@ -1734,6 +1734,8 @@ void WipeTower2::toolchange_Change(
|
||||
// This is where we want to place the custom gcodes. We will use placeholders for this.
|
||||
// These will be substituted by the actual gcodes when the gcode is generated.
|
||||
//writer.append("[end_filament_gcode]\n");
|
||||
// Lift to the layer Z so change_filament_gcode can't hit taller printed parts.
|
||||
writer.append("[restore_layer_z_before_toolchange]\n");
|
||||
writer.append("[change_filament_gcode]\n");
|
||||
|
||||
if (m_is_mk4mmu3)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -376,4 +377,38 @@ ImexZoneLayout compute_imex_zone_layout(const DynamicPrintConfig& printer_cfg,
|
||||
return out;
|
||||
}
|
||||
|
||||
bool update_imex_layout_key(std::optional<ImexLayoutKey>& key, const DynamicPrintConfig* printer_cfg, const std::string& mode)
|
||||
{
|
||||
static const std::string no_mode;
|
||||
static const std::vector<std::string> no_strings;
|
||||
const auto* is_imex = printer_cfg != nullptr ? printer_cfg->option<ConfigOptionBool>("is_imex") : nullptr;
|
||||
|
||||
ImexLayoutKey::Scalars s;
|
||||
const ConfigOptionStrings* names = nullptr;
|
||||
const ConfigOptionStrings* tools = nullptr;
|
||||
if (is_imex != nullptr && is_imex->value) {
|
||||
// The same accessors compute_imex_zone_layout() uses, so the key holds the values it lays
|
||||
// out from.
|
||||
s.imex = true;
|
||||
s.gantry_count = imex_cfg_int(*printer_cfg, "imex_gantry_count");
|
||||
s.tools_per_gantry = imex_cfg_int(*printer_cfg, "imex_tools_per_gantry");
|
||||
s.tool_layout = int(imex_cfg_enum<ImexToolLayout>(*printer_cfg, "imex_tool_layout"));
|
||||
s.clearance_x = imex_cfg_float(*printer_cfg, "imex_nozzle_clearance_x");
|
||||
s.clearance_y = imex_cfg_float(*printer_cfg, "imex_nozzle_clearance_y");
|
||||
s.carriage_margin = imex_cfg_float(*printer_cfg, "imex_carriage_margin");
|
||||
s.firmware_managed = imex_cfg_bool(*printer_cfg, "imex_firmware_managed_zones");
|
||||
names = printer_cfg->option<ConfigOptionStrings>("imex_mode_names");
|
||||
tools = printer_cfg->option<ConfigOptionStrings>("imex_mode_active_tools");
|
||||
}
|
||||
const std::string& resolved_mode = s.imex ? mode : no_mode;
|
||||
const std::vector<std::string>& mode_names = names != nullptr ? names->values : no_strings;
|
||||
const std::vector<std::string>& mode_tools = tools != nullptr ? tools->values : no_strings;
|
||||
|
||||
if (key.has_value() && key->s == s && key->mode == resolved_mode && key->mode_names == mode_names &&
|
||||
key->mode_active_tools == mode_tools)
|
||||
return false;
|
||||
key = ImexLayoutKey{ s, resolved_mode, mode_names, mode_tools };
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "libslic3r/BoundingBox.hpp"
|
||||
@@ -91,4 +93,46 @@ ImexZoneLayout compute_imex_zone_layout(const DynamicPrintConfig& printer_cfg,
|
||||
const std::string& process_mode,
|
||||
const BoundingBoxf& bed_extents);
|
||||
|
||||
// Every config input to a plate's IMEX zones and ghosts: what compute_imex_zone_layout() reads from
|
||||
// the printer preset, plus the plate's resolved mode and imex_firmware_managed_zones, which decides
|
||||
// whether the plate draws ghosts. The bed is left out because a plate rebuilds its zones in
|
||||
// set_shape(). An option that moves a zone or a ghost must be added here, or they go stale silently.
|
||||
struct ImexLayoutKey
|
||||
{
|
||||
// Every other field stays at its default while imex is false.
|
||||
struct Scalars
|
||||
{
|
||||
bool imex = false;
|
||||
int gantry_count = 0;
|
||||
int tools_per_gantry = 0;
|
||||
int tool_layout = -1;
|
||||
double clearance_x = 0.0;
|
||||
double clearance_y = 0.0;
|
||||
double carriage_margin = 0.0;
|
||||
bool firmware_managed = false;
|
||||
|
||||
bool operator==(const Scalars& rhs) const
|
||||
{
|
||||
// A clearance field accepts "nan", so NaN equals itself here, or the key would change
|
||||
// every frame.
|
||||
auto same = [](double a, double b) { return a == b || (std::isnan(a) && std::isnan(b)); };
|
||||
return std::tie(imex, gantry_count, tools_per_gantry, tool_layout, firmware_managed) ==
|
||||
std::tie(rhs.imex, rhs.gantry_count, rhs.tools_per_gantry, rhs.tool_layout, rhs.firmware_managed) &&
|
||||
same(clearance_x, rhs.clearance_x) && same(clearance_y, rhs.clearance_y) &&
|
||||
same(carriage_margin, rhs.carriage_margin);
|
||||
}
|
||||
};
|
||||
Scalars s;
|
||||
// The resolved mode and the printer's whole mode table. A name doesn't identify a roster: two
|
||||
// presets can give one name different rosters, and editing a roster keeps its name.
|
||||
std::string mode;
|
||||
std::vector<std::string> mode_names;
|
||||
std::vector<std::string> mode_active_tools;
|
||||
};
|
||||
|
||||
// Brings `key` up to date with `printer_cfg` and the plate's resolved `mode`, and returns
|
||||
// whether it changed. A null `printer_cfg` reads as IMEX off. Plates and the G-code preview call
|
||||
// this every frame, so it compares against the live config and copies only when something changed.
|
||||
bool update_imex_layout_key(std::optional<ImexLayoutKey>& key, const DynamicPrintConfig* printer_cfg, const std::string& mode);
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -4106,6 +4106,16 @@ void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys&
|
||||
}
|
||||
}
|
||||
|
||||
bool is_edited_as_whole_list(const ConfigDef *def, const std::string &opt_key)
|
||||
{
|
||||
if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "compatible_prints" ||
|
||||
opt_key == "compatible_printers" || opt_key == "thumbnails" || opt_key == "wrapping_exclude_area")
|
||||
return true;
|
||||
const ConfigOptionDef *opt_def = def ? def->get(opt_key) : nullptr;
|
||||
return opt_def != nullptr &&
|
||||
(opt_def->gui_flags == "serialized" || opt_def->gui_type == ConfigOptionDef::GUIType::plugin_picker);
|
||||
}
|
||||
|
||||
// Use deep_diff to correct return of changed options, considering individual options for each extruder.
|
||||
inline t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other, bool strict = true)
|
||||
{
|
||||
@@ -4123,8 +4133,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi
|
||||
const ConfigOption *other_opt = config_other.option(opt_key);
|
||||
if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt)
|
||||
{
|
||||
//BBS: add bed_exclude_area
|
||||
if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "thumbnails" || opt_key == "wrapping_exclude_area" || opt_key == "slicing_pipeline_plugin") {
|
||||
if (is_edited_as_whole_list(config_other.def(), opt_key)) {
|
||||
// Scalar variable, or a vector variable, which is independent from number of extruders,
|
||||
// thus the vector is presented to the user as a single input.
|
||||
diff.emplace_back(opt_key);
|
||||
@@ -4163,7 +4172,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi
|
||||
else if (this_opt == nullptr && other_opt != nullptr)
|
||||
opt = other_opt;
|
||||
if (opt) {
|
||||
if (opt->type() & coVectorType) {
|
||||
if ((opt->type() & coVectorType) && !is_edited_as_whole_list(config_other.def(), opt_key)) {
|
||||
auto vec = dynamic_cast<ConfigOptionVectorBase const *>(opt);
|
||||
for (size_t i = 0; i < vec->size(); i++)
|
||||
diff.push_back(opt_key + "#" + std::to_string(i));
|
||||
|
||||
@@ -490,6 +490,9 @@ bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const Pre
|
||||
bool is_compatible_with_printer(const DynamicPrintConfig &preset_config, Preset::Type preset_type,
|
||||
const DynamicPrintConfig &printer_config, const std::string &printer_name);
|
||||
|
||||
// True for a list option the settings tab edits as one value, so a change to it is reported for the whole list.
|
||||
bool is_edited_as_whole_list(const ConfigDef *def, const std::string &opt_key);
|
||||
|
||||
// Where a preset is being loaded from. `Auto` lets load_presets() infer from the directory path.
|
||||
struct PresetOrigin {
|
||||
enum class Kind { Auto, User, LocalBundle, SubscribedBundle };
|
||||
|
||||
@@ -422,58 +422,81 @@ std::string PresetBundle::find_preset_vendor(const std::string &preset_name, Pre
|
||||
return "";
|
||||
}
|
||||
|
||||
// A vendor is named by its profile or, where the build ships preset caches
|
||||
// instead of the raw profile JSONs, by its cache alone.
|
||||
for (const std::string& vendor_name : vendor_names_in(system_dir)) {
|
||||
const fs::path vendor_json = system_dir / (vendor_name + ".json");
|
||||
if (! fs::exists(vendor_json)) {
|
||||
if (VendorCacheFile::carries_preset((system_dir / (vendor_name + ".opc")).string(), vendor_name, type, preset_name)) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << preset_name
|
||||
<< " in vendor cache " << vendor_name;
|
||||
return vendor_name;
|
||||
// A preset's old names are kept in its own file, not in the vendor's list, so they are only read
|
||||
// once no vendor lists the name itself.
|
||||
auto renamed_from = [&preset_name](const fs::path &preset_file) {
|
||||
boost::nowide::ifstream ifs(preset_file.string());
|
||||
const std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
if (text.find(ORCA_JSON_KEY_RENAMED_FROM) == std::string::npos)
|
||||
return false;
|
||||
const json preset = json::parse(text, nullptr, false);
|
||||
if (!preset.is_object() || !preset.contains(ORCA_JSON_KEY_RENAMED_FROM) || !preset[ORCA_JSON_KEY_RENAMED_FROM].is_string())
|
||||
return false;
|
||||
std::vector<std::string> names;
|
||||
return unescape_strings_cstyle(preset[ORCA_JSON_KEY_RENAMED_FROM].get<std::string>(), names) &&
|
||||
std::find(names.begin(), names.end(), preset_name) != names.end();
|
||||
};
|
||||
|
||||
for (const bool renamed : {false, true}) {
|
||||
// A vendor is named by its profile or, where the build ships preset caches
|
||||
// instead of the raw profile JSONs, by its cache alone.
|
||||
for (const std::string& vendor_name : vendor_names_in(system_dir)) {
|
||||
const fs::path vendor_json = system_dir / (vendor_name + ".json");
|
||||
if (! fs::exists(vendor_json)) {
|
||||
if (VendorCacheFile::carries_preset((system_dir / (vendor_name + ".opc")).string(), vendor_name, type, preset_name, renamed)) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << preset_name << (renamed ? " as an old name" : "")
|
||||
<< " in vendor cache " << vendor_name;
|
||||
return vendor_name;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const std::string vendor_file = vendor_json.string();
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Checking vendor: " << vendor_file;
|
||||
const std::string vendor_file = vendor_json.string();
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Checking vendor: " << vendor_file;
|
||||
|
||||
try {
|
||||
// Load and parse the vendor JSON file
|
||||
boost::nowide::ifstream ifs(vendor_file);
|
||||
json j;
|
||||
ifs >> j;
|
||||
try {
|
||||
// Load and parse the vendor JSON file
|
||||
boost::nowide::ifstream ifs(vendor_file);
|
||||
json j;
|
||||
ifs >> j;
|
||||
|
||||
// Check if the preset list key exists
|
||||
if (!j.contains(preset_list_key))
|
||||
continue;
|
||||
|
||||
auto& preset_list = j[preset_list_key];
|
||||
if (!preset_list.is_array())
|
||||
continue;
|
||||
|
||||
// Search for the preset in the list
|
||||
for (auto& preset_entry : preset_list) {
|
||||
if (!preset_entry.is_object())
|
||||
// Check if the preset list key exists
|
||||
if (!j.contains(preset_list_key))
|
||||
continue;
|
||||
|
||||
// Get the preset name
|
||||
std::string p_name;
|
||||
if (preset_entry.contains(BBL_JSON_KEY_NAME) && preset_entry[BBL_JSON_KEY_NAME].is_string())
|
||||
p_name = preset_entry[BBL_JSON_KEY_NAME].get<std::string>();
|
||||
|
||||
if (p_name != preset_name)
|
||||
auto& preset_list = j[preset_list_key];
|
||||
if (!preset_list.is_array())
|
||||
continue;
|
||||
|
||||
// Found the preset! Get the vendor name and install the entire bundle
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << p_name
|
||||
// Search for the preset in the list
|
||||
for (auto& preset_entry : preset_list) {
|
||||
if (!preset_entry.is_object())
|
||||
continue;
|
||||
|
||||
if (renamed) {
|
||||
if (!preset_entry.contains(BBL_JSON_KEY_SUB_PATH) || !preset_entry[BBL_JSON_KEY_SUB_PATH].is_string() ||
|
||||
!renamed_from(system_dir / vendor_name / preset_entry[BBL_JSON_KEY_SUB_PATH].get<std::string>()))
|
||||
continue;
|
||||
} else {
|
||||
// Get the preset name
|
||||
std::string p_name;
|
||||
if (preset_entry.contains(BBL_JSON_KEY_NAME) && preset_entry[BBL_JSON_KEY_NAME].is_string())
|
||||
p_name = preset_entry[BBL_JSON_KEY_NAME].get<std::string>();
|
||||
|
||||
if (p_name != preset_name)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Found the preset! Get the vendor name and install the entire bundle
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << preset_name << (renamed ? " as an old name" : "")
|
||||
<< " in vendor bundle " << vendor_name;
|
||||
|
||||
return vendor_name;
|
||||
|
||||
return vendor_name;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to find vendor name for " << preset_name << ": " << e.what();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to find vendor name for " << preset_name << ": " << e.what();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,6 +706,8 @@ const PresetBundle *PresetBundle::load_source_vendor(const boost::filesystem::pa
|
||||
error = "Vendor bundle contains invalid presets";
|
||||
return nullptr;
|
||||
}
|
||||
// Lets find_preset() resolve a name a preset was renamed from.
|
||||
bundle->update_system_maps();
|
||||
return m_source_vendor_bundles.emplace(std::move(key), std::move(bundle)).first->second.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -567,7 +567,7 @@ Semver VendorCacheFile::usable_version(const std::string& path, const std::strin
|
||||
|
||||
// static
|
||||
bool VendorCacheFile::carries_preset(const std::string& path, const std::string& vendor_name,
|
||||
Preset::Type type, const std::string& preset_name)
|
||||
Preset::Type type, const std::string& preset_name, bool renamed)
|
||||
{
|
||||
std::string blob;
|
||||
if (! read_cache_blob(path, blob))
|
||||
@@ -581,7 +581,7 @@ bool VendorCacheFile::carries_preset(const std::string& path, const std::string&
|
||||
dict.load(ar);
|
||||
VendorMap vendors;
|
||||
ar(vendors);
|
||||
// Reused: every entry overwrites it, and only its name is ever looked at.
|
||||
// Reused: every entry overwrites it, and only its names are ever looked at.
|
||||
CachedPreset entry;
|
||||
// Written in this order by save. The list that could carry the preset
|
||||
// is the last one worth reading.
|
||||
@@ -590,7 +590,8 @@ bool VendorCacheFile::carries_preset(const std::string& path, const std::string&
|
||||
ar(cnt);
|
||||
for (uint32_t i = 0; i < cnt; ++ i) {
|
||||
visit_entry(ar, entry, [&] { skip_config(ar, dict); });
|
||||
if (kind == type && entry.name == preset_name)
|
||||
if (kind == type && (renamed ? std::find(entry.renamed_from.begin(), entry.renamed_from.end(), preset_name) != entry.renamed_from.end() :
|
||||
entry.name == preset_name))
|
||||
return true;
|
||||
}
|
||||
if (kind == type)
|
||||
|
||||
@@ -193,9 +193,10 @@ public:
|
||||
// read. The three kinds are written in one stream, so reaching the machines
|
||||
// means reading past the processes and filaments — their configs are consumed
|
||||
// and dropped rather than built. This is how a build that ships caches instead
|
||||
// of preset JSONs answers "which vendor carries this preset?".
|
||||
// of preset JSONs answers "which vendor carries this preset?". With `renamed`
|
||||
// it answers whether a preset was renamed from `preset_name` instead.
|
||||
static bool carries_preset(const std::string& path, const std::string& vendor_name,
|
||||
Preset::Type type, const std::string& preset_name);
|
||||
Preset::Type type, const std::string& preset_name, bool renamed = false);
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
+10
-5
@@ -3015,10 +3015,12 @@ StringObjectException Print::validate(std::vector<StringObjectException> *warnin
|
||||
"adaptive_pressure_advance_model");
|
||||
break;
|
||||
}
|
||||
if (!AdaptivePAProcessor::validate_adaptive_pa_model(pa_model).empty()) {
|
||||
warn(L("The Adaptive Pressure Advance model for one or more extruders may contain invalid values."),
|
||||
const std::string pa_error = AdaptivePAProcessor::validate_adaptive_pa_model(pa_model);
|
||||
if (!pa_error.empty()) {
|
||||
// TRN %1% is the filament number as shown in the filament list, starting from 1; %2% names the invalid line.
|
||||
// one warning per filament, the notifications stack
|
||||
warn(Slic3r::format(L("The Adaptive Pressure Advance model of filament %1% contains invalid values.\n%2%"), filament_id + 1, pa_error),
|
||||
"adaptive_pressure_advance_model");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4951,7 +4953,8 @@ std::vector<std::set<int>> Print::get_physical_unprintable_filaments(const std::
|
||||
auto get_unprintable_extruder_id = [&](unsigned int filament_idx) -> int {
|
||||
// filament_printable may be shorter than the filament count; get_at() clamps.
|
||||
int status = m_config.filament_printable.get_at(filament_idx);
|
||||
for (int i = 0; i < extruder_num; ++i) {
|
||||
// An int has bits for the first 32 extruders only.
|
||||
for (int i = 0; i < std::min(extruder_num, 32); ++i) {
|
||||
if (!(status >> i & 1)) {
|
||||
return i;
|
||||
}
|
||||
@@ -5872,6 +5875,7 @@ DynamicConfig PrintStatistics::config() const
|
||||
config.set_key_value("initial_tool", new ConfigOptionInt(static_cast<int>(this->initial_tool)));
|
||||
config.set_key_value("initial_extruder", new ConfigOptionInt(static_cast<int>(this->initial_tool)));
|
||||
config.set_key_value("initial_no_support_extruder", new ConfigOptionInt(static_cast<int>(this->initial_no_support_tool)));
|
||||
config.set_key_value("printing_filament_types", new ConfigOptionString(this->printing_filament_types));
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -5881,7 +5885,8 @@ DynamicConfig PrintStatistics::placeholders()
|
||||
for (const std::string key : {
|
||||
"print_time", "normal_print_time", "silent_print_time",
|
||||
"used_filament", "extruded_volume", "extruded_volume_total", "total_cost", "total_weight", "extruded_weight_total",
|
||||
"initial_tool", "initial_extruder", "initial_no_support_extruder", "total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament"})
|
||||
"initial_tool", "initial_extruder", "initial_no_support_extruder", "total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament",
|
||||
"printing_filament_types"})
|
||||
config.set_key_value(key, new ConfigOptionString(std::string("{") + key + "}"));
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -965,6 +965,8 @@ struct PrintStatistics
|
||||
double total_wipe_tower_filament;
|
||||
unsigned int initial_tool;
|
||||
unsigned int initial_no_support_tool;
|
||||
// Orca: underscore-separated list of the filament types really extruded on the plate.
|
||||
std::string printing_filament_types;
|
||||
std::map<size_t, double> filament_stats;
|
||||
|
||||
// Config with the filled in print statistics.
|
||||
@@ -984,6 +986,7 @@ struct PrintStatistics
|
||||
total_wipe_tower_filament = 0.;
|
||||
initial_tool = 0;
|
||||
initial_no_support_tool = 0;
|
||||
printing_filament_types.clear();
|
||||
filament_stats.clear();
|
||||
}
|
||||
static const std::string FilamentUsedG;
|
||||
|
||||
@@ -13433,9 +13433,9 @@ PrintStatisticsConfigDef::PrintStatisticsConfigDef()
|
||||
def->label = L("Print time (normal mode)");
|
||||
def->tooltip = L("Estimated print time when printed in normal mode (i.e. not in silent mode). Same as normal_print_time.");
|
||||
|
||||
//def = this->add("printing_filament_types", coString);
|
||||
//def->label = L("Used filament types");
|
||||
//def->tooltip = L("Comma-separated list of all filament types used during the print.");
|
||||
def = this->add("printing_filament_types", coString);
|
||||
def->label = L("Used filament types");
|
||||
def->tooltip = L("Underscore-separated list of all filament types used during the print.");
|
||||
|
||||
def = this->add("silent_print_time", coString);
|
||||
def->label = L("Print time (silent mode)");
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
@@ -1116,8 +1117,14 @@ protected:
|
||||
m_keys.emplace_back(kvp.first);
|
||||
const ConfigOptionDef *def = defs->get(kvp.first);
|
||||
assert(def != nullptr);
|
||||
if (def->default_value)
|
||||
opt->set(def->default_value.get());
|
||||
if (def->default_value) {
|
||||
if (def->default_value->type() == coEnums) {
|
||||
// Enum list defaults are built without a keys map; set() adopts the one create_default_option() adds.
|
||||
std::unique_ptr<ConfigOption> default_option(def->create_default_option());
|
||||
opt->set(default_option.get());
|
||||
} else
|
||||
opt->set(def->default_value.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -864,6 +864,9 @@ std::string fix_slicing_errors(PrintObject* object, LayerPtrs &layers, const std
|
||||
|
||||
void groupingVolumesForBrim(PrintObject* object, LayerPtrs& layers, int firstLayerReplacedBy)
|
||||
{
|
||||
if (layers.empty())
|
||||
return;
|
||||
|
||||
const auto scaled_resolution = scaled<double>(object->print()->config().resolution.value);
|
||||
auto partsObjSliceByVolume = findPartVolumes(object->firstLayerObjSliceMod(), object->model_object()->volumes);
|
||||
groupingVolumes(partsObjSliceByVolume, object->firstLayerObjGroupsMod(), scaled_resolution, firstLayerReplacedBy);
|
||||
|
||||
@@ -721,6 +721,9 @@ void adjust_layer_height_profile(
|
||||
|
||||
bool adjust_layer_series_to_align_object_height(const SlicingParameters &slicing_params, std::vector<coordf_t>& layer_series)
|
||||
{
|
||||
if (layer_series.empty())
|
||||
return false;
|
||||
|
||||
coordf_t object_height = slicing_params.object_print_z_height();
|
||||
if (is_approx(layer_series.back(), object_height))
|
||||
return true;
|
||||
|
||||
@@ -903,6 +903,8 @@ if (APPLE)
|
||||
GUI/GUI_UtilsMac.mm
|
||||
GUI/MacIME.mm
|
||||
GUI/MacIME.hpp
|
||||
GUI/Accessibility/AccessibilityMac.mm
|
||||
GUI/Accessibility/AccessibilityMac.h
|
||||
)
|
||||
FIND_LIBRARY(DISKARBITRATION_LIBRARY DiskArbitration)
|
||||
endif ()
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef slic3r_GUI_AccessibilityMac_h_
|
||||
#define slic3r_GUI_AccessibilityMac_h_
|
||||
|
||||
#include <functional>
|
||||
#include <wx/string.h>
|
||||
|
||||
#ifdef __WXOSX__
|
||||
|
||||
class wxWindow;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
// macOS accessibility (VoiceOver / Voice Control) for custom-drawn and native widgets.
|
||||
//
|
||||
// OrcaSlicer draws many controls with a plain NSView (backed by wxWindow), which
|
||||
// assistive technologies neither name nor identify. This module configures the
|
||||
// NSAccessibility metadata those views need so VoiceOver can focus, name and activate
|
||||
// them and Voice Control can target them. The C++ API below is the only thing the rest
|
||||
// of the codebase touches; every Cocoa and NSAccessibility detail stays in
|
||||
// AccessibilityMac.mm.
|
||||
namespace Accessibility {
|
||||
|
||||
// The NSAccessibility role an element advertises. Add values here as more custom
|
||||
// widgets are exposed. Keep in sync with role_string() in AccessibilityMac.mm.
|
||||
enum class Role {
|
||||
Button, // NSAccessibilityButtonRole
|
||||
Checkbox, // NSAccessibilityCheckBoxRole
|
||||
};
|
||||
|
||||
// How a wxWindow should be exposed to assistive technologies.
|
||||
struct Descriptor {
|
||||
Role role{ Role::Button };
|
||||
// Accessible name. When empty, the window's tooltip is used so icon-only controls
|
||||
// still get a name.
|
||||
wxString name;
|
||||
// Default action invoked when the assistive technology activates the element. Stored
|
||||
// as a block on the window's NSView (see detach()) and may capture the widget's
|
||||
// `this`. Ignored for native controls, which have their own press action.
|
||||
std::function<void()> press;
|
||||
};
|
||||
|
||||
// Expose `win` to assistive technologies as described. Idempotent; call again whenever
|
||||
// the name or enabled state changes (for example after a button's label is updated).
|
||||
//
|
||||
// The call is a no-op for a native control (an NSControl-backed wxWindow, e.g. a
|
||||
// wxBitmapToggleButton): AppKit already exposes its role, value, enabled state and press
|
||||
// action, so apply() only fills in the name and Voice Control identifier. Custom-drawn
|
||||
// views are configured in full.
|
||||
void apply(wxWindow* win, const Descriptor& desc);
|
||||
|
||||
// Clear the press block apply() stored on the window's NSView. Call when the widget is
|
||||
// destroyed so the view cannot outlive it with a press block capturing the freed widget.
|
||||
void detach(wxWindow* win);
|
||||
|
||||
} // namespace Accessibility
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // __WXOSX__
|
||||
|
||||
#endif // !slic3r_GUI_AccessibilityMac_h_
|
||||
@@ -0,0 +1,144 @@
|
||||
#include "AccessibilityMac.h"
|
||||
|
||||
#include <objc/runtime.h>
|
||||
#include <wx/window.h>
|
||||
#include "wx/osx/core/cfstring.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// VoiceOver / Voice Control accessibility for custom-drawn controls.
|
||||
//
|
||||
// OrcaSlicer renders its dialog controls with a plain wxNSView (backed by wxWindow),
|
||||
// which assistive technologies neither name nor identify. The NSAccessibility
|
||||
// attributes of those views are configured through AppKit's instance-scoped setters
|
||||
// (setAccessibilityRole:, setAccessibilityTitle:, setAccessibilityEnabled:,
|
||||
// setAccessibilityIdentifier:, setAccessibilityElement:), which confines the change
|
||||
// to the specific views we opt in.
|
||||
//
|
||||
// The press action has no setter, so accessibilityPerformPress is swizzled onto
|
||||
// NSView once (install_press_action()). The replacement runs the press block stored
|
||||
// on the view and otherwise forwards to the original implementation, so views that
|
||||
// were never configured behave exactly as before.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static const void* kOrcaAccessibilityPressKey = &kOrcaAccessibilityPressKey;
|
||||
|
||||
// Swizzle accessibilityPerformPress on NSView, keeping the original implementation
|
||||
// reachable through the captured IMP. dispatch_once makes this safe to trigger from
|
||||
// every apply() call.
|
||||
static void install_press_action()
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
SEL sel = @selector(accessibilityPerformPress);
|
||||
Method original = class_getInstanceMethod([NSView class], sel);
|
||||
if (!original)
|
||||
return;
|
||||
|
||||
IMP original_imp = method_getImplementation(original);
|
||||
IMP replacement = imp_implementationWithBlock(^BOOL(NSView* view) {
|
||||
void (^handler)(void) = objc_getAssociatedObject(view, kOrcaAccessibilityPressKey);
|
||||
if (handler) {
|
||||
handler();
|
||||
return YES;
|
||||
}
|
||||
return ((BOOL (*)(id, SEL))original_imp)(view, sel);
|
||||
});
|
||||
|
||||
const char* types = method_getTypeEncoding(original);
|
||||
if (!class_addMethod([NSView class], sel, replacement, types)) {
|
||||
// NSView implements the method itself rather than inheriting it, so adding
|
||||
// failed; exchange the implementations instead. The captured original_imp
|
||||
// stays valid and is called directly, so there is no recursion risk.
|
||||
SEL stored = @selector(orca_accessibilityPerformPress);
|
||||
if (class_addMethod([NSView class], stored, replacement, types))
|
||||
method_exchangeImplementations(original, class_getInstanceMethod([NSView class], stored));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
namespace Accessibility {
|
||||
|
||||
namespace {
|
||||
|
||||
// Maps a Role to its NSAccessibility role string. Keep in sync with Role in
|
||||
// AccessibilityMac.h: every enumerator needs a case here, otherwise it falls through to
|
||||
// NSAccessibilityUnknownRole.
|
||||
NSString* role_string(Role role)
|
||||
{
|
||||
switch (role) {
|
||||
case Role::Button: return NSAccessibilityButtonRole;
|
||||
case Role::Checkbox: return NSAccessibilityCheckBoxRole;
|
||||
}
|
||||
return NSAccessibilityUnknownRole;
|
||||
}
|
||||
|
||||
// Voice Control identifier. wxWindow::GetId() is stable for the window's lifetime but
|
||||
// can be recycled once a window is destroyed; Voice Control's spoken-number overlay
|
||||
// only needs the mapping to stay stable while the element is on screen.
|
||||
wxString default_identifier(const wxWindow* win)
|
||||
{
|
||||
return wxString::Format("wxID_%d", (int)win->GetId());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void apply(wxWindow* win, const Descriptor& desc)
|
||||
{
|
||||
if (!win)
|
||||
return;
|
||||
|
||||
NSView* view = (NSView*)win->GetHandle();
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
// A native control (an NSControl-backed wxWindow such as a wxBitmapToggleButton)
|
||||
// already exposes its role, value, enabled state and press action through AppKit, so
|
||||
// we only fill in the two pieces AppKit cannot derive for our controls: the name and
|
||||
// the Voice Control identifier. A custom-drawn view (a plain wxNSView) exposes none
|
||||
// of this, so it is configured in full below.
|
||||
const bool native = [view isKindOfClass:[NSControl class]];
|
||||
|
||||
// The element's name. Fall back to the tooltip so icon-only controls get a name.
|
||||
wxString name = desc.name;
|
||||
if (name.empty())
|
||||
name = win->GetToolTipText();
|
||||
[view setAccessibilityTitle:name.empty() ? nil : wxCFStringRef(name).AsNSString()];
|
||||
|
||||
// A stable id Voice Control uses to map spoken commands back to the element.
|
||||
[view setAccessibilityIdentifier:wxCFStringRef(default_identifier(win)).AsNSString()];
|
||||
|
||||
if (native)
|
||||
return;
|
||||
|
||||
install_press_action();
|
||||
|
||||
[view setAccessibilityRole:role_string(desc.role)];
|
||||
|
||||
// wxWindow::IsEnabled() includes disabled ancestors; kept current by re-calling
|
||||
// apply() from the widget's DoEnable() (wx cascades DoEnable to children).
|
||||
[view setAccessibilityEnabled:win->IsEnabled()];
|
||||
|
||||
if (desc.press) {
|
||||
auto press = desc.press; // copy the std::function into the stored block
|
||||
objc_setAssociatedObject(view, kOrcaAccessibilityPressKey, ^{ press(); }, OBJC_ASSOCIATION_COPY_NONATOMIC);
|
||||
} else {
|
||||
objc_setAssociatedObject(view, kOrcaAccessibilityPressKey, nil, OBJC_ASSOCIATION_COPY_NONATOMIC);
|
||||
}
|
||||
|
||||
// Opt this view into the accessibility tree.
|
||||
[view setAccessibilityElement:YES];
|
||||
}
|
||||
|
||||
void detach(wxWindow* win)
|
||||
{
|
||||
NSView* view = win ? (NSView*)win->GetHandle() : nil;
|
||||
if (view)
|
||||
objc_setAssociatedObject(view, kOrcaAccessibilityPressKey, nil, OBJC_ASSOCIATION_COPY_NONATOMIC);
|
||||
}
|
||||
|
||||
} // namespace Accessibility
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
@@ -807,6 +807,10 @@ void BackgroundSlicingProcess::reset_export()
|
||||
if (!this->running()) {
|
||||
m_export_path.clear();
|
||||
m_export_path_on_removable_media = false;
|
||||
// A scheduled upload only leaves m_upload_job when prepare_upload() hands it to the print host
|
||||
// job queue. If the run ended before that (a post-processing script or plugin failure, or a
|
||||
// cancel), the job must not survive into the next plain slice, which would upload again.
|
||||
m_upload_job = PrintHostJob();
|
||||
// invalidate_step expects the mutex to be locked.
|
||||
std::scoped_lock<std::mutex> lock(m_print->state_mutex());
|
||||
this->invalidate_step(bspsGCodeFinalize);
|
||||
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
// Set print host upload job data to be enqueued to the PrintHostJobQueue
|
||||
// after current print slicing is complete
|
||||
void schedule_upload(Slic3r::PrintHostJob upload_job);
|
||||
// Clear m_export_path.
|
||||
// Clear m_export_path and drop a scheduled upload that was not handed to the print host job queue.
|
||||
void reset_export();
|
||||
// Once the G-code export is scheduled, the apply() methods will do nothing.
|
||||
bool is_export_scheduled() const { return ! m_export_path.empty(); }
|
||||
|
||||
@@ -182,6 +182,12 @@ wxString get_string_value(const std::string& opt_key, const DynamicPrintConfig&
|
||||
out.RemoveLast(1);
|
||||
return out;
|
||||
}
|
||||
if (orig_opt_idx < 0 && opt->gui_flags == "serialized") {
|
||||
// Joins the entries as the settings tab shows them.
|
||||
for (const std::string& value : strings->values)
|
||||
out += from_u8(value) + ";";
|
||||
return out;
|
||||
}
|
||||
if (!strings->empty() && opt_idx < strings->values.size())
|
||||
return from_u8(strings->get_at(opt_idx));
|
||||
}
|
||||
|
||||
@@ -2245,34 +2245,17 @@ void GCodeViewer::render_markers(int canvas_width, int canvas_height)
|
||||
// Cache guard. The marker plan below is resolved from preset/plate state only,
|
||||
// so it is rebuilt when that state moves and reused otherwise — the sequential
|
||||
// slider is sticky, and re-resolving the zone layout on every frame of the rest
|
||||
// of the session showed up as a measurable per-frame cost. The comparison is
|
||||
// deliberately made against the live config rather than against a freshly built
|
||||
// key, so an unchanged frame allocates nothing at all.
|
||||
static const std::vector<std::string> s_no_strings;
|
||||
auto* names_opt = printer_cfg.opt<ConfigOptionStrings>("imex_mode_names");
|
||||
auto* tools_opt = printer_cfg.opt<ConfigOptionStrings>("imex_mode_active_tools");
|
||||
const std::vector<std::string>& mode_names = names_opt ? names_opt->values : s_no_strings;
|
||||
const std::vector<std::string>& active_tools = tools_opt ? tools_opt->values : s_no_strings;
|
||||
// of the session showed up as a measurable per-frame cost.
|
||||
ImexMarkerKey::Plate plate;
|
||||
plate.plate_index = plate_list.get_curr_plate_index();
|
||||
plate.bed_min_x = bed_extents.min.x();
|
||||
plate.bed_min_y = bed_extents.min.y();
|
||||
plate.bed_max_x = bed_extents.max.x();
|
||||
plate.bed_max_y = bed_extents.max.y();
|
||||
|
||||
ImexMarkerKey::Scalars key;
|
||||
key.plate_index = plate_list.get_curr_plate_index();
|
||||
// Same accessor the plan is built from: a key holding a different fallback than
|
||||
// the value actually laid out would compare equal across a real change.
|
||||
key.gantry_count = imex_cfg_int(printer_cfg, "imex_gantry_count");
|
||||
key.tools_per_gantry = imex_cfg_int(printer_cfg, "imex_tools_per_gantry");
|
||||
key.tool_layout = (int)imex_cfg_enum<ImexToolLayout>(printer_cfg, "imex_tool_layout");
|
||||
key.clearance_x = imex_cfg_float(printer_cfg, "imex_nozzle_clearance_x");
|
||||
key.clearance_y = imex_cfg_float(printer_cfg, "imex_nozzle_clearance_y");
|
||||
key.firmware_managed = imex_cfg_bool(printer_cfg, "imex_firmware_managed_zones");
|
||||
key.bed_min_x = bed_extents.min.x();
|
||||
key.bed_min_y = bed_extents.min.y();
|
||||
key.bed_max_x = bed_extents.max.x();
|
||||
key.bed_max_y = bed_extents.max.y();
|
||||
|
||||
if (!(m_imex_marker_key.s == key) || m_imex_marker_key.mode != mode ||
|
||||
m_imex_marker_key.mode_names != mode_names ||
|
||||
m_imex_marker_key.mode_active_tools != active_tools) {
|
||||
m_imex_marker_key = ImexMarkerKey{ key, mode, mode_names, active_tools };
|
||||
const bool layout_changed = update_imex_layout_key(m_imex_marker_key.layout, &printer_cfg, mode);
|
||||
if (layout_changed || !(m_imex_marker_key.plate == plate)) {
|
||||
m_imex_marker_key.plate = plate;
|
||||
m_imex_marker_plan = resolve_imex_marker_plan(printer_cfg, mode, bed_extents);
|
||||
// The carriage roster — and with it the marker count — can change with any
|
||||
// of those inputs, so drop the markers and let the lazy init below rebuild
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
#include "libslic3r/BoundingBox.hpp"
|
||||
#include <cstddef>
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/IMEXZones.hpp"
|
||||
#include "libvgcode/include/GCodeInputData.hpp"
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include "libvgcode/include/PathVertex.hpp"
|
||||
#include <libvgcode/include/Types.hpp>
|
||||
|
||||
@@ -271,50 +273,23 @@ private:
|
||||
// Invalidation key for the plan above: every input the plan is derived from, and
|
||||
// nothing that changes between frames. A stale plan would put the preview markers
|
||||
// somewhere the plate's own zones and ghosts do not agree with, which is exactly the
|
||||
// drift the shared layout call exists to prevent -- so this deliberately mirrors
|
||||
// PartPlate::build_imex_cache_key(). The two keys are not field-for-field identical, and
|
||||
// the differences are deliberate rather than incidental:
|
||||
// - bed extents and plate_index are here and not there. Zone centres scale with the
|
||||
// extents, and one preview serves every plate, so the preview must key what the plate
|
||||
// gets for free -- it re-bakes on set_shape() and is keyed by being that plate.
|
||||
// - mode_names / mode_active_tools hold the printer's WHOLE mode table; the plate resolves
|
||||
// one active mode and keys that roster plus its primary head. Same information reached
|
||||
// two ways, so a change to the active mode moves both keys.
|
||||
// - imex_carriage_margin is there and not here: it only sizes the plate's advisory bands,
|
||||
// which the preview never draws.
|
||||
// imex_tool_layout is in both, which the plate's key gained for the reason this one has it:
|
||||
// the T0-corner flip moves every zone rectangle while nothing else keyed changes.
|
||||
// drift the shared layout call exists to prevent -- so the layout half is the plate's own
|
||||
// key. The preview adds the plate index and bed extents, which a plate gets for free: zone
|
||||
// centers scale with the bed, and one preview serves every plate, while each plate rebuilds
|
||||
// its zones in set_shape(). The layout key also holds imex_carriage_margin, which only sizes
|
||||
// the plate's advisory bands, so a margin change re-resolves the plan needlessly.
|
||||
struct ImexMarkerKey
|
||||
{
|
||||
// Scalar half. Built fresh on the stack each frame -- it allocates nothing -- and
|
||||
// compared as a tuple.
|
||||
struct Scalars
|
||||
std::optional<ImexLayoutKey> layout;
|
||||
struct Plate
|
||||
{
|
||||
int plate_index = -1;
|
||||
int gantry_count = 0;
|
||||
int tools_per_gantry = 0;
|
||||
int tool_layout = -1;
|
||||
double clearance_x = 0.0;
|
||||
double clearance_y = 0.0;
|
||||
bool firmware_managed = false;
|
||||
int plate_index = -1;
|
||||
double bed_min_x = 0.0, bed_min_y = 0.0, bed_max_x = 0.0, bed_max_y = 0.0;
|
||||
|
||||
auto tied() const {
|
||||
return std::tie(plate_index, gantry_count, tools_per_gantry, tool_layout,
|
||||
clearance_x, clearance_y, firmware_managed,
|
||||
bed_min_x, bed_min_y, bed_max_x, bed_max_y);
|
||||
}
|
||||
bool operator==(const Scalars& rhs) const { return tied() == rhs.tied(); }
|
||||
auto tied() const { return std::tie(plate_index, bed_min_x, bed_min_y, bed_max_x, bed_max_y); }
|
||||
bool operator==(const Plate& rhs) const { return tied() == rhs.tied(); }
|
||||
};
|
||||
Scalars s;
|
||||
// Resolved active mode (the plate's mode beats the process preset), plus the printer
|
||||
// preset's whole mode table. The name alone is not identity: two presets can carry
|
||||
// the same mode name over different tool rosters, and editing a roster in place
|
||||
// moves neither the name nor any scalar above. Compared by value, never copied
|
||||
// unless something actually changed.
|
||||
std::string mode;
|
||||
std::vector<std::string> mode_names;
|
||||
std::vector<std::string> mode_active_tools;
|
||||
Plate plate;
|
||||
};
|
||||
ImexMarkerKey m_imex_marker_key;
|
||||
ImexMarkerPlan m_imex_marker_plan;
|
||||
|
||||
@@ -3390,9 +3390,14 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
||||
volume->is_modifier = !mvs->model_volume->is_model_part();
|
||||
volume->set_color(color_from_model_volume(*mvs->model_volume));
|
||||
|
||||
const ModelInstance& instance = *mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id];
|
||||
// Follow the instance's printable flag on every reload; the assemble view never shows it.
|
||||
if (m_canvas_type != ECanvasType::CanvasAssembleView)
|
||||
volume->printable = instance.printable;
|
||||
|
||||
// updates volumes transformations
|
||||
if (m_canvas_type != ECanvasType::CanvasAssembleView) {
|
||||
volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_transformation());
|
||||
volume->set_instance_transformation(instance.get_transformation());
|
||||
volume->set_volume_transformation(mvs->model_volume->get_transformation());
|
||||
// updates volumes convex hull
|
||||
if (mvs->model_volume->is_model_part() && ! volume->convex_hull())
|
||||
@@ -3402,14 +3407,14 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
||||
volume->set_offset_to_assembly(Vec3d(0, 0, 0));
|
||||
}
|
||||
else {
|
||||
volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_assemble_transformation());
|
||||
volume->set_instance_transformation(instance.get_assemble_transformation());
|
||||
volume->set_volume_transformation(mvs->model_volume->get_transformation());
|
||||
// updates volumes convex hull
|
||||
if (mvs->model_volume->is_model_part() && ! volume->convex_hull())
|
||||
// Model volume was likely changed from modifier or support blocker / enforcer to a model part.
|
||||
// Only model parts require convex hulls.
|
||||
volume->set_convex_hull(mvs->model_volume->get_convex_hull_shared_ptr());
|
||||
volume->set_offset_to_assembly(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_offset_to_assembly());
|
||||
volume->set_offset_to_assembly(instance.get_offset_to_assembly());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3479,6 +3484,8 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
||||
it->volume_idx = m_volumes.volumes.size();
|
||||
m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by, m_initialized, m_canvas_type == ECanvasType::CanvasAssembleView);
|
||||
m_volumes.volumes.back()->geometry_id = key.geometry_id;
|
||||
if (m_canvas_type != ECanvasType::CanvasAssembleView)
|
||||
m_volumes.volumes.back()->printable = model_instance.printable;
|
||||
update_object_list = true;
|
||||
} else {
|
||||
// Recycling an old GLVolume.
|
||||
|
||||
@@ -45,11 +45,13 @@ bool input_pending()
|
||||
#endif
|
||||
}
|
||||
|
||||
// True inside a wxYield(), where a slice would build pages in the middle of the code that yielded.
|
||||
bool yielding()
|
||||
// True inside a wxYield() or a nested loop such as a modal dialog's, where a slice would build pages in
|
||||
// the middle of the code that is waiting. A new web view waits for WebKit in a yield loop; if the dialog
|
||||
// closes meanwhile, macOS aborts its modal session, the reply never arrives and the app hangs.
|
||||
bool in_nested_loop()
|
||||
{
|
||||
const wxEventLoopBase* loop = wxEventLoopBase::GetActive();
|
||||
return loop != nullptr && loop->IsYielding();
|
||||
return loop != nullptr && (loop->IsYielding() || !loop->IsMain());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -79,7 +81,7 @@ void IdleScheduler::tick()
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
if (m_input_idle_ms() < quiet_ms || input_pending() || yielding()) {
|
||||
if (m_input_idle_ms() < quiet_ms || input_pending() || in_nested_loop()) {
|
||||
start();
|
||||
return;
|
||||
}
|
||||
|
||||
+61
-126
@@ -472,7 +472,7 @@ std::string PartPlate::get_effective_imex_mode() const
|
||||
std::string mode = get_imex_mode();
|
||||
if (mode != kImexPrimaryMode)
|
||||
return mode;
|
||||
// wxGetApp() is not available headless -- see build_imex_cache_key, which guards on the
|
||||
// wxGetApp() is not available headless -- see refresh_imex_layout_key, which guards on the
|
||||
// same thing. Nothing calls this from the CLI today; this keeps that from being fatal.
|
||||
if (!m_plater)
|
||||
return mode;
|
||||
@@ -492,16 +492,14 @@ void PartPlate::set_imex_mode(const std::string& mode)
|
||||
m_config.set_key_value("imex_parallel_mode", new ConfigOptionString(mode));
|
||||
}
|
||||
update_slice_result_valid_state(false);
|
||||
m_imex_zones_mode_cache = "\x01"; // force zone rebuild
|
||||
m_imex_ghost_cache_key = "\x01"; // force ghost rebuild
|
||||
m_imex_layout_key.reset(); // force zone and ghost rebuild
|
||||
}
|
||||
|
||||
void PartPlate::reset_imex_mode()
|
||||
{
|
||||
m_config.erase("imex_parallel_mode");
|
||||
update_slice_result_valid_state(false);
|
||||
m_imex_zones_mode_cache = "\x01";
|
||||
m_imex_ghost_cache_key = "\x01";
|
||||
m_imex_layout_key.reset();
|
||||
}
|
||||
|
||||
std::map<int,int> PartPlate::get_imex_head_filament_map() const
|
||||
@@ -678,7 +676,6 @@ void PartPlate::calc_imex_zones()
|
||||
m_imex_margin_overlay.clear();
|
||||
m_imex_primary_zone_box = std::nullopt;
|
||||
m_imex_head_zone_centers.clear();
|
||||
m_imex_primary_head = -1;
|
||||
|
||||
if (!wxGetApp().preset_bundle)
|
||||
return;
|
||||
@@ -695,7 +692,6 @@ void PartPlate::calc_imex_zones()
|
||||
const ImexZoneLayout layout = compute_imex_zone_layout(printer_cfg, get_imex_mode(),
|
||||
process_mode, get_extents(m_shape));
|
||||
|
||||
m_imex_primary_head = layout.primary_head;
|
||||
m_imex_head_zone_centers = layout.head_zone_centers;
|
||||
m_imex_primary_zone_box = layout.primary_zone_box;
|
||||
m_imex_secondary_zone_boxes = layout.secondary_zone_boxes;
|
||||
@@ -737,62 +733,32 @@ void PartPlate::calc_imex_zones()
|
||||
push_zone_fill(m_imex_margin_overlay, b.min.x(), b.max.x(), b.min.y(), b.max.y());
|
||||
}
|
||||
|
||||
// Build a cache key from the current IDEX/IQEX config options, or "" if IDEX/IQEX is off.
|
||||
// Reads per-plate mode from m_config first, falling back to the process preset.
|
||||
//
|
||||
// Inputs that contribute to the key (any change must invalidate the IMEX zone cache):
|
||||
// - active_mode (per-plate or process-preset fallback)
|
||||
// - imex_tools_per_gantry, imex_gantry_count (grid shape)
|
||||
// - imex_tool_layout (which corner tool 0 occupies)
|
||||
// - imex_nozzle_clearance_x, imex_nozzle_clearance_y (zone widths / collision strips)
|
||||
// - imex_carriage_margin (zone shrink)
|
||||
// - the active mode's tool roster and its Primary head (same name, different roster)
|
||||
// - imex_firmware_managed_zones (suppresses ghost generation)
|
||||
//
|
||||
// IMPORTANT: if you add a printer config option that affects zone geometry, ghost transforms,
|
||||
// or collision strips, it MUST be incorporated here — otherwise ghost meshes and zone overlays
|
||||
// will go stale silently after a config change. Float values are scaled by 10 before integer
|
||||
// cast so 0.1 mm steps invalidate the cache; if you add a float option needing finer precision,
|
||||
// adjust the scale.
|
||||
std::string PartPlate::build_imex_cache_key() const
|
||||
void PartPlate::refresh_imex_layout_key()
|
||||
{
|
||||
// CLI / headless slice: no GUI_App is initialized, so `wxGetApp()` returns
|
||||
// memory that segfaults on member access. `m_plater` is set only by the GUI
|
||||
// construction path; treat its absence as "no IMEX state to compute" and
|
||||
// return an empty key. Same guard pattern used by calc_imex_ghosts.
|
||||
if (!m_plater || !wxGetApp().preset_bundle)
|
||||
return "";
|
||||
const DynamicPrintConfig& printer_cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||
auto* is_imex_opt = printer_cfg.option<ConfigOptionBool>("is_imex");
|
||||
if (!is_imex_opt || !is_imex_opt->value)
|
||||
return "";
|
||||
std::string active_mode = get_effective_imex_mode();
|
||||
// Mode NAME alone is not printer identity: two presets can define the same mode
|
||||
// name with different tool rosters/primary, and imex_firmware_managed_zones
|
||||
// suppresses ghost generation entirely. Both shape the baked zone/ghost set, so
|
||||
// key them directly (previously caught only incidentally, via the ghost key's
|
||||
// since-removed pem entry).
|
||||
std::string active_tools;
|
||||
int primary_phys = -1;
|
||||
resolve_active_mode_tools(active_tools, primary_phys); // empty on failure — keyed as such
|
||||
// imex_tool_layout decides which physical corner tool 0 occupies (flip_x / flip_y inside
|
||||
// compute_imex_zone_layout), so every zone rectangle, collision strip and ghost offset moves
|
||||
// when it changes while every other keyed field stays put. Without it the key is identical
|
||||
// across a layout change and the baked zones go stale; that this currently appears to work is
|
||||
// incidental -- some other path happens to rebuild -- not something to rely on.
|
||||
// Geometry values go through imex_cfg_* so the key is built from the same numbers
|
||||
// compute_imex_zone_layout() lays out with; a literal here could key on a value the layout
|
||||
// never used.
|
||||
return active_mode
|
||||
+ "|" + std::to_string(imex_cfg_int(printer_cfg, "imex_tools_per_gantry"))
|
||||
+ "x" + std::to_string(imex_cfg_int(printer_cfg, "imex_gantry_count"))
|
||||
+ "|ly" + std::to_string((int)imex_cfg_enum<ImexToolLayout>(printer_cfg, "imex_tool_layout"))
|
||||
+ "|cw" + std::to_string((int)(imex_cfg_float(printer_cfg, "imex_nozzle_clearance_x") * 10))
|
||||
+ "|ch" + std::to_string((int)(imex_cfg_float(printer_cfg, "imex_nozzle_clearance_y") * 10))
|
||||
+ "|mg" + std::to_string((int)(imex_cfg_float(printer_cfg, "imex_carriage_margin") * 10))
|
||||
+ "|t" + active_tools
|
||||
+ "|p" + std::to_string(primary_phys)
|
||||
+ "|fw" + (imex_cfg_bool(printer_cfg, "imex_firmware_managed_zones") ? "1" : "0");
|
||||
// construction path; treat its absence as "IMEX off". Same guard pattern used
|
||||
// by calc_imex_ghosts.
|
||||
const DynamicPrintConfig* printer_cfg = nullptr;
|
||||
if (m_plater && wxGetApp().preset_bundle) {
|
||||
const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||
const auto* is_imex = cfg.option<ConfigOptionBool>("is_imex");
|
||||
if (is_imex != nullptr && is_imex->value)
|
||||
printer_cfg = &cfg;
|
||||
}
|
||||
// With IMEX off the key ignores the mode, so don't resolve it.
|
||||
if (!update_imex_layout_key(m_imex_layout_key, printer_cfg, printer_cfg != nullptr ? get_effective_imex_mode() : std::string()))
|
||||
return;
|
||||
|
||||
++m_imex_layout_key_version;
|
||||
m_imex_zones_stale = true;
|
||||
m_imex_active_mode = {};
|
||||
if (m_imex_layout_key->s.imex && m_imex_layout_key->mode != kImexPrimaryMode) {
|
||||
// A mode missing from the table, or past the end of a short imex_mode_active_tools, gets
|
||||
// empty tools, which declare no Primary, so the mode stays unresolved.
|
||||
m_imex_active_mode.tools = find_imex_mode(*printer_cfg, m_imex_layout_key->mode).active_tools;
|
||||
m_imex_active_mode.primary = imex_primary_tool_for_mode(m_imex_active_mode.tools);
|
||||
}
|
||||
}
|
||||
|
||||
// Reposition the IMEX mode icon without requiring a full set_shape() rebuild.
|
||||
@@ -824,66 +790,36 @@ void PartPlate::refresh_imex_icon()
|
||||
}
|
||||
|
||||
// Ensure zone geometry (secondary boxes, collision strips, visual meshes) is up to date.
|
||||
// Called before any collision check AND before rendering so both paths share the same data.
|
||||
void PartPlate::ensure_imex_zones()
|
||||
{
|
||||
// CLI / headless slice: no GUI_App, no plater, no IMEX state to track. Bail out
|
||||
// before touching `wxGetApp()` (which segfaults without a GUI_App) — placement
|
||||
// checks reach this from the headless 3MF-load path through `check_outside`.
|
||||
if (!m_plater) return;
|
||||
std::string cache_key = build_imex_cache_key();
|
||||
if (cache_key != m_imex_zones_mode_cache) {
|
||||
m_imex_zones_mode_cache = cache_key;
|
||||
calc_imex_zones();
|
||||
}
|
||||
refresh_imex_layout_key();
|
||||
rebuild_stale_imex_zones();
|
||||
}
|
||||
|
||||
std::string PartPlate::build_imex_ghost_cache_key() const
|
||||
void PartPlate::rebuild_stale_imex_zones()
|
||||
{
|
||||
// Ghost shape depends on: mode topology (same inputs as zone key) + set of
|
||||
// objects on plate + each primary instance's transform. Filament routing and
|
||||
// colors are deliberately NOT keyed: ghost RGB is restamped live every frame
|
||||
// by update_imex_ghost_colors, so color-only changes never need a mesh rebuild.
|
||||
std::string k = build_imex_cache_key();
|
||||
if (k.empty()) return ""; // ghost-off when zones-off
|
||||
|
||||
k += "|obj";
|
||||
for (const auto& oi : obj_to_instance_set)
|
||||
k += std::to_string(oi.first) + "." + std::to_string(oi.second) + ",";
|
||||
return k;
|
||||
if (!m_plater || !m_imex_zones_stale) return;
|
||||
m_imex_zones_stale = false;
|
||||
calc_imex_zones();
|
||||
}
|
||||
|
||||
void PartPlate::ensure_imex_ghosts()
|
||||
{
|
||||
std::string key = build_imex_ghost_cache_key();
|
||||
if (key != m_imex_ghost_cache_key) {
|
||||
m_imex_ghost_cache_key = key;
|
||||
calc_imex_ghosts();
|
||||
}
|
||||
}
|
||||
|
||||
bool PartPlate::resolve_active_mode_tools(std::string& out_tools_str, int& out_primary_phys) const
|
||||
{
|
||||
if (!wxGetApp().preset_bundle) return false;
|
||||
const DynamicPrintConfig& printer_cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||
auto* is_imex_opt = printer_cfg.option<ConfigOptionBool>("is_imex");
|
||||
if (!is_imex_opt || !is_imex_opt->value) return false;
|
||||
|
||||
const std::string active_mode = get_effective_imex_mode();
|
||||
if (active_mode == kImexPrimaryMode) return false;
|
||||
|
||||
const ImexMode mode = find_imex_mode(printer_cfg, active_mode);
|
||||
if (!mode.found()) return false;
|
||||
|
||||
// Also the ragged case: a tools array too short to reach this row hands back an empty
|
||||
// string, which has no declared primary, which is the same "no zones here" answer the
|
||||
// explicit bounds check used to give.
|
||||
const int primary_phys = imex_primary_tool_for_mode(mode.active_tools);
|
||||
if (primary_phys < 0) return false;
|
||||
|
||||
out_tools_str = mode.active_tools;
|
||||
out_primary_phys = primary_phys;
|
||||
return true;
|
||||
// Ghost meshes depend on: mode topology (the layout key) + set of objects on
|
||||
// plate. Instance transforms are applied live by update_imex_ghost_transforms.
|
||||
// Filament routing and colors are deliberately NOT keyed: ghost RGB is restamped
|
||||
// live every frame by update_imex_ghost_colors, so color-only changes never need
|
||||
// a mesh rebuild. With IMEX off there are no ghosts, whatever the plate holds.
|
||||
if (m_imex_ghost_layout_version == m_imex_layout_key_version &&
|
||||
(!m_imex_layout_key || !m_imex_layout_key->s.imex || m_imex_ghost_objects == obj_to_instance_set))
|
||||
return;
|
||||
m_imex_ghost_layout_version = m_imex_layout_key_version;
|
||||
m_imex_ghost_objects = obj_to_instance_set;
|
||||
calc_imex_ghosts();
|
||||
}
|
||||
|
||||
// Ghost opacity, stamped together with RGB by update_imex_ghost_colors every
|
||||
@@ -896,9 +832,10 @@ void PartPlate::calc_imex_ghosts()
|
||||
if (!m_plater || !m_model) return;
|
||||
if (obj_to_instance_set.empty()) return;
|
||||
|
||||
std::string active_tools_str;
|
||||
int primary_phys = -1;
|
||||
if (!resolve_active_mode_tools(active_tools_str, primary_phys)) return;
|
||||
const ImexActiveMode& active = m_imex_active_mode;
|
||||
if (!active.resolved()) return;
|
||||
const std::string& active_tools_str = active.tools;
|
||||
const int primary_phys = active.primary;
|
||||
|
||||
// IMEX firmware-managed zones: the slicer emits a centered single-half slice and the
|
||||
// firmware fans copies/mirrors out from there — placement is not slicer-authoritative.
|
||||
@@ -911,9 +848,8 @@ void PartPlate::calc_imex_ghosts()
|
||||
return;
|
||||
|
||||
// Zone centers are the basis for ghost placement; make sure they exist before
|
||||
// we read them. render_imex_zones already ensures this, but ghost rebuild can
|
||||
// also be driven from mode/preset invalidation paths that don't touch zones.
|
||||
ensure_imex_zones();
|
||||
// we read them.
|
||||
rebuild_stale_imex_zones();
|
||||
|
||||
const auto heads = parse_imex_active_tools(active_tools_str);
|
||||
|
||||
@@ -1051,13 +987,13 @@ void PartPlate::update_imex_ghost_transforms(
|
||||
{
|
||||
if (m_imex_ghost_volumes.empty() || !m_plater || !m_model) return;
|
||||
|
||||
std::string active_tools_str;
|
||||
int primary_phys = -1;
|
||||
if (!resolve_active_mode_tools(active_tools_str, primary_phys)) return;
|
||||
|
||||
// Reuse zone-center-derived offsets (same source calc_imex_ghosts uses), so
|
||||
// update and rebuild paths always agree on where each ghost belongs.
|
||||
ensure_imex_zones();
|
||||
const ImexActiveMode& active = m_imex_active_mode;
|
||||
if (!active.resolved()) return;
|
||||
const std::string& active_tools_str = active.tools;
|
||||
const int primary_phys = active.primary;
|
||||
auto center_for = [&](int phys) -> Vec2d {
|
||||
auto it = m_imex_head_zone_centers.find(phys);
|
||||
return (it == m_imex_head_zone_centers.end()) ? Vec2d::Zero() : it->second;
|
||||
@@ -1294,11 +1230,11 @@ bool PartPlate::has_imex_multimaterial_conflict() const
|
||||
// which the raw key's single default entry does not describe.
|
||||
const ConfigOptionInts pem = effective_physical_extruder_map(*pb);
|
||||
|
||||
// Resolve the active mode's tools string from the printer config. Print::validate()
|
||||
// The active mode's roster, as refresh_imex_layout_key() resolved it. Print::validate()
|
||||
// resolves the same name the same way and keeps going on an empty result -- the mixed
|
||||
// filament rule below does not depend on the roster -- so this must too, or the badge
|
||||
// goes quiet on exactly the plates the slicer refuses.
|
||||
const std::string active_tools_str = find_imex_mode(printer_cfg, mode).active_tools;
|
||||
const std::string& active_tools_str = m_imex_active_mode.tools;
|
||||
|
||||
// Convert PartPlate's 1-based extruder list to the 0-based form the helper expects.
|
||||
//
|
||||
@@ -1330,7 +1266,7 @@ void PartPlate::render_imex_zones(bool force_default_color)
|
||||
if (force_default_color)
|
||||
return;
|
||||
|
||||
ensure_imex_zones();
|
||||
rebuild_stale_imex_zones();
|
||||
ensure_imex_ghosts();
|
||||
|
||||
// Read visualization theme from printer config.
|
||||
@@ -2673,11 +2609,8 @@ void PartPlate::render_icons(bool bottom, bool only_name, int hover_id)
|
||||
auto* is_imex_opt = pb ? pb->printers.get_edited_preset().config.option<ConfigOptionBool>("is_imex") : nullptr;
|
||||
if (is_imex_opt && is_imex_opt->value) {
|
||||
// The icon shows the mode the plate slices as, the one its ghosts follow.
|
||||
std::string active_tools;
|
||||
int primary_phys = -1;
|
||||
const size_t kind = size_t(resolve_active_mode_tools(active_tools, primary_phys) ?
|
||||
imex_mode_kind(active_tools) :
|
||||
ImexModeKind::Primary);
|
||||
const ImexActiveMode& active = m_imex_active_mode;
|
||||
const size_t kind = size_t(active.resolved() ? imex_mode_kind(active.tools) : ImexModeKind::Primary);
|
||||
// Both the mode name and the conflict warning describe the same hovered icon,
|
||||
// and set_hover_tooltip records one string per frame, so they are composed here.
|
||||
std::string hover_tip;
|
||||
@@ -5222,7 +5155,7 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, co
|
||||
|
||||
const BoundingBox& pp_bbox = poly.contour.bounding_box();
|
||||
calc_gridlines(poly, pp_bbox);
|
||||
m_imex_zones_mode_cache = "\x01"; // force rebuild on next render
|
||||
m_imex_zones_stale = true; // force rebuild on next render
|
||||
calc_imex_zones();
|
||||
|
||||
calc_vertex_for_icons(0, m_del_icon);
|
||||
@@ -5340,6 +5273,8 @@ bool PartPlate::intersects(const BoundingBoxf3& bb) const
|
||||
|
||||
void PartPlate::render(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool only_body, bool force_background_color, HeightLimitMode mode, int hover_id, bool render_cali, bool show_grid, bool hide_chrome)
|
||||
{
|
||||
refresh_imex_layout_key();
|
||||
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
|
||||
GLShaderProgram *shader = wxGetApp().get_shader("flat");
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "libslic3r/ObjectID.hpp"
|
||||
#include "libslic3r/GCode/GCodeProcessor.hpp"
|
||||
#include "libslic3r/Format/bbs_3mf.hpp"
|
||||
#include "libslic3r/IMEXZones.hpp"
|
||||
#include "libslic3r/Slicing.hpp"
|
||||
#include "libslic3r/GCode/WipeTowerEstimate.hpp"
|
||||
#include "libslic3r/Arrange.hpp"
|
||||
@@ -181,10 +182,23 @@ private:
|
||||
std::vector<GLModel> m_imex_margin_overlay; // amber advisory bands just inside collision strips
|
||||
std::optional<BoundingBoxf> m_imex_primary_zone_box; // primary zone extents in mm; empty when IDEX/IQEX is off/primary-only
|
||||
std::map<int, Vec2d> m_imex_head_zone_centers; // physical-head → zone-center (mm); populated by calc_imex_zones
|
||||
int m_imex_primary_head{ -1 }; // physical-head index of the primary tool in the active mode; -1 when no mode
|
||||
std::string m_imex_zones_mode_cache{ "\x01" }; // cached mode+topology key; sentinel = unbuilt
|
||||
// What the zones, the ghosts and m_imex_active_mode were last built from; nullopt rebuilds all three.
|
||||
std::optional<ImexLayoutKey> m_imex_layout_key;
|
||||
unsigned m_imex_layout_key_version{ 0 }; // bumped whenever m_imex_layout_key changes
|
||||
bool m_imex_zones_stale{ true }; // set when the key changes, cleared by the zone rebuild
|
||||
// Resolved only when m_imex_layout_key changes, because find_imex_mode() copies the whole
|
||||
// mode, G-code included.
|
||||
struct ImexActiveMode
|
||||
{
|
||||
std::string tools; // the mode's imex_mode_active_tools entry; empty if there's none
|
||||
int primary = -1; // physical head of the mode's Primary tool
|
||||
bool resolved() const { return primary >= 0; }
|
||||
};
|
||||
ImexActiveMode m_imex_active_mode;
|
||||
std::vector<std::unique_ptr<GLVolume>> m_imex_ghost_volumes;
|
||||
std::string m_imex_ghost_cache_key{ "\x01" }; // sentinel = unbuilt
|
||||
// The layout key version and the objects the ghosts were built from; nullopt = unbuilt.
|
||||
std::optional<unsigned> m_imex_ghost_layout_version;
|
||||
std::set<std::pair<int, int>> m_imex_ghost_objects;
|
||||
GLModel m_height_limit_common;
|
||||
GLModel m_height_limit_bottom;
|
||||
GLModel m_height_limit_top;
|
||||
@@ -233,16 +247,14 @@ private:
|
||||
void calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox);
|
||||
void calc_height_limit();
|
||||
void calc_imex_zones();
|
||||
void ensure_imex_zones();
|
||||
std::string build_imex_cache_key() const;
|
||||
void ensure_imex_zones(); // checks the layout key, then rebuild_stale_imex_zones()
|
||||
void rebuild_stale_imex_zones(); // rebuilds the zones if they're stale; doesn't refresh the key
|
||||
// Brings m_imex_layout_key up to date; when it changes, re-resolves m_imex_active_mode and
|
||||
// marks the zones stale. Reads per-plate mode first, falling back to the process preset.
|
||||
// render() calls it once a frame, and ensure_imex_zones() for callers outside render().
|
||||
void refresh_imex_layout_key();
|
||||
void calc_imex_ghosts(); // full rebuild
|
||||
void ensure_imex_ghosts(); // cached rebuild on key change
|
||||
std::string build_imex_ghost_cache_key() const;
|
||||
// Resolves the currently-active IMEX mode's tools string + primary physical head.
|
||||
// Plate override wins; else falls back to process preset `imex_parallel_mode`.
|
||||
// Returns false (and leaves outputs untouched) if IMEX is off, mode is empty/"primary",
|
||||
// mode config is missing, the mode isn't listed, or no primary is found.
|
||||
bool resolve_active_mode_tools(std::string& out_tools_str, int& out_primary_phys) const;
|
||||
void render_imex_zones(bool force_default_color);
|
||||
void refresh_imex_icon();
|
||||
float icon_scale_factor() const;
|
||||
@@ -273,6 +285,9 @@ private:
|
||||
void render_icon_texture(GLModel &buffer, GLTexture &texture);
|
||||
void set_hover_tooltip(const std::string& tooltip);
|
||||
void render_icons(bool bottom, bool only_name = false, int hover_id = -1);
|
||||
// Returns true when IMEX parallel mode is active (non-primary) AND the plate
|
||||
// has objects assigned to more than one filament — a combination that warrants caution.
|
||||
bool has_imex_multimaterial_conflict() const;
|
||||
void render_only_numbers(bool bottom);
|
||||
void render_plate_name_texture();
|
||||
void invalidate_plate_name_texture();
|
||||
@@ -419,7 +434,7 @@ public:
|
||||
void update_imex_ghost_colors();
|
||||
|
||||
// Invalidate the ghost cache so the next render_imex_zones() call rebuilds fully.
|
||||
void invalidate_imex_ghosts() { m_imex_ghost_cache_key = "\x01"; }
|
||||
void invalidate_imex_ghosts() { m_imex_ghost_layout_version.reset(); }
|
||||
|
||||
std::vector<Vec2d> get_plate_wrapping_detection_area() const;
|
||||
|
||||
@@ -635,9 +650,6 @@ public:
|
||||
// Footprint of the prime tower as the scene draws it, in scaled plate-list coords.
|
||||
// Empty when the plate has no tower.
|
||||
Polygon imex_wipe_tower_hull() const;
|
||||
// Returns true when IMEX parallel mode is active (non-primary) AND the plate
|
||||
// has objects assigned to more than one filament — a combination that warrants caution.
|
||||
bool has_imex_multimaterial_conflict() const;
|
||||
// Returns the primary-zone bounding box in mm when an IDEX/IQEX parallel mode is active.
|
||||
// Empty (nullopt) when IDEX/IQEX is off or the mode is "primary" (full-bed).
|
||||
std::optional<BoundingBoxf> imex_primary_zone() { ensure_imex_zones(); return m_imex_primary_zone_box; }
|
||||
|
||||
@@ -6317,6 +6317,14 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn)
|
||||
|
||||
auto & list = wxGetApp().preset_bundle->filament_ams_list;
|
||||
if (list.empty()) {
|
||||
// Only an unreachable printer is "not connected". One that is online and has
|
||||
// delivered at least one status push answered the request without listing any
|
||||
// filament slot, and the message then names the machine that answered.
|
||||
if (obj->is_connected() && obj->m_push_count > 0) {
|
||||
p->plater->pop_warning_and_go_to_device_page(from_u8(obj->get_dev_name()), Plater::PrinterWarningType::NO_FILAMENT_SYSTEM,
|
||||
_L("Sync printer information"));
|
||||
return;
|
||||
}
|
||||
auto printer_name = p->plater->get_selected_printer_name_in_combox();
|
||||
p->plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
|
||||
return;
|
||||
@@ -22472,6 +22480,9 @@ void Plater::pop_warning_and_go_to_device_page(wxString printer_name, PrinterWar
|
||||
content = _L("There are no filaments on the printer. Please load the filaments on the printer first.");
|
||||
} else if (type == PrinterWarningType::EMPTY_FILAMENT) {
|
||||
content = _L("The filaments on the printer are all unknown types. Please go to the printer screen or software device page to set the filament type.");
|
||||
} else if (type == PrinterWarningType::NO_FILAMENT_SYSTEM) {
|
||||
// TRN %s is the connected printer's name.
|
||||
content = wxString::Format(_L("%s is connected, but no filament system (AMS, CFS or other multi-material unit) was found on it, so there are no filaments to synchronize."), printer_name);
|
||||
}
|
||||
MessageDialog dlg(this, content, title, wxOK | wxFORWARD | wxICON_WARNING, _L("Device Page"));
|
||||
auto result = dlg.ShowModal();
|
||||
|
||||
@@ -695,7 +695,8 @@ public:
|
||||
NOT_CONNECTED,
|
||||
INCONSISTENT,
|
||||
UNINSTALL_FILAMENT,
|
||||
EMPTY_FILAMENT
|
||||
EMPTY_FILAMENT,
|
||||
NO_FILAMENT_SYSTEM
|
||||
};
|
||||
void pop_warning_and_go_to_device_page(wxString printer_name, PrinterWarningType type, const wxString &title);
|
||||
bool check_printer_initialized(MachineObject *obj, bool only_warning = false,bool popup_warning = true);
|
||||
|
||||
+1
-11
@@ -1160,10 +1160,6 @@ void add_correct_opts_to_options_list(const std::string &opt_key, std::map<std::
|
||||
|
||||
std::string Tab::options_list_storage_key(const std::string& opt_key) const
|
||||
{
|
||||
if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "compatible_prints" ||
|
||||
opt_key == "compatible_printers" || opt_key == "thumbnails" || opt_key == "wrapping_exclude_area")
|
||||
return opt_key;
|
||||
|
||||
if (m_config == nullptr || !m_config->has(opt_key))
|
||||
return opt_key;
|
||||
|
||||
@@ -1171,13 +1167,7 @@ std::string Tab::options_list_storage_key(const std::string& opt_key) const
|
||||
if (option == nullptr || !option->is_vector())
|
||||
return opt_key;
|
||||
|
||||
const ConfigOptionDef* def = m_config->def()->get(opt_key);
|
||||
if (def == nullptr)
|
||||
return opt_key;
|
||||
|
||||
const bool serialized = def->gui_flags == "serialized";
|
||||
const bool is_plugin_field = def->gui_type == ConfigOptionDef::GUIType::plugin_picker;
|
||||
return (serialized || is_plugin_field) ? opt_key : opt_key + "#0";
|
||||
return is_edited_as_whole_list(m_config->def(), opt_key) ? opt_key : opt_key + "#0";
|
||||
}
|
||||
|
||||
// Orca: deep_diff() flags every vector entry at or past the reference vector's length as changed,
|
||||
|
||||
@@ -16,11 +16,106 @@
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/tipwin.h>
|
||||
#include <wx/window.h>
|
||||
#include "slic3r/GUI/Widgets/StateColor.hpp"
|
||||
#include "slic3r/GUI/wxExtensions.hpp"
|
||||
#ifdef __APPLE__
|
||||
#include "libslic3r/MacUtils.hpp"
|
||||
#endif
|
||||
#include <wx/setup.h>
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
#include <wx/access.h>
|
||||
#endif
|
||||
#ifdef __WXOSX__
|
||||
#include "slic3r/GUI/Accessibility/AccessibilityMac.h"
|
||||
#endif
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
|
||||
namespace {
|
||||
|
||||
// Exposes the custom-drawn Button to screen readers. On Windows the base
|
||||
// wxWindowAccessible reports every window as a generic client area, so NVDA and
|
||||
// Narrator announce the label but not the button role. Overriding these
|
||||
// callbacks reports the button as a push button with its name and state, and
|
||||
// lets the screen reader activate it through DoDefaultAction.
|
||||
class ButtonAccessible : public wxWindowAccessible
|
||||
{
|
||||
public:
|
||||
explicit ButtonAccessible(Button* btn)
|
||||
: wxWindowAccessible(btn)
|
||||
, m_btn(btn)
|
||||
{
|
||||
}
|
||||
|
||||
wxAccStatus GetName(int childId, wxString* name) override
|
||||
{
|
||||
if (childId != wxACC_SELF)
|
||||
return wxACC_NOT_IMPLEMENTED;
|
||||
|
||||
*name = m_btn->GetLabel();
|
||||
if (name->empty())
|
||||
*name = m_btn->GetToolTipText();
|
||||
return name->empty() ? wxACC_NOT_IMPLEMENTED : wxACC_OK;
|
||||
}
|
||||
|
||||
wxAccStatus GetRole(int childId, wxAccRole* role) override
|
||||
{
|
||||
if (childId != wxACC_SELF)
|
||||
return wxACC_NOT_IMPLEMENTED;
|
||||
|
||||
*role = wxROLE_SYSTEM_PUSHBUTTON;
|
||||
return wxACC_OK;
|
||||
}
|
||||
|
||||
wxAccStatus GetValue(int childId, wxString* strValue) override
|
||||
{
|
||||
if (childId != wxACC_SELF)
|
||||
return wxACC_NOT_IMPLEMENTED;
|
||||
|
||||
// A push button carries no value; expose an explicit empty one.
|
||||
strValue->clear();
|
||||
return wxACC_OK;
|
||||
}
|
||||
|
||||
wxAccStatus GetState(int childId, long* state) override
|
||||
{
|
||||
if (childId != wxACC_SELF)
|
||||
return wxACC_NOT_IMPLEMENTED;
|
||||
|
||||
long st = 0;
|
||||
if (!m_btn->IsEnabled())
|
||||
st |= wxACC_STATE_SYSTEM_UNAVAILABLE;
|
||||
if (!m_btn->IsShown())
|
||||
st |= wxACC_STATE_SYSTEM_INVISIBLE;
|
||||
if (m_btn->IsFocusable())
|
||||
st |= wxACC_STATE_SYSTEM_FOCUSABLE;
|
||||
if (m_btn->HasFocus())
|
||||
st |= wxACC_STATE_SYSTEM_FOCUSED;
|
||||
if (m_btn->GetValue())
|
||||
st |= wxACC_STATE_SYSTEM_PRESSED;
|
||||
|
||||
*state = st;
|
||||
return wxACC_OK;
|
||||
}
|
||||
|
||||
wxAccStatus DoDefaultAction(int childId) override
|
||||
{
|
||||
if (childId != wxACC_SELF)
|
||||
return wxACC_NOT_IMPLEMENTED;
|
||||
|
||||
m_btn->Click();
|
||||
return wxACC_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
Button* m_btn;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
#endif // wxUSE_ACCESSIBILITY
|
||||
|
||||
BEGIN_EVENT_TABLE(Button, StaticBox)
|
||||
|
||||
EVT_LEFT_DOWN(Button::mouseDown)
|
||||
@@ -66,6 +161,10 @@ bool Button::Create(wxWindow* parent, wxString text, wxString icon, long style,
|
||||
this->active_icon = ScalableBitmap(this, icon.ToStdString(), iconSize > 0 ? iconSize : 20);
|
||||
}
|
||||
messureSize();
|
||||
#ifdef __WXOSX__
|
||||
applyAccessibility();
|
||||
Bind(wxEVT_DESTROY, [this](wxWindowDestroyEvent&) { Slic3r::GUI::Accessibility::detach(this); });
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,6 +174,10 @@ void Button::SetLabel(const wxString& label)
|
||||
wxWindow::SetLabel(label);
|
||||
messureSize();
|
||||
Refresh();
|
||||
#ifdef __WXOSX__
|
||||
// Keep the accessible name in sync with the visible label.
|
||||
applyAccessibility();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,6 +613,45 @@ void Button::sendButtonEvent()
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
void Button::Click()
|
||||
{
|
||||
if (IsEnabled())
|
||||
sendButtonEvent();
|
||||
}
|
||||
|
||||
#ifdef __WXOSX__
|
||||
void Button::DoSetToolTipText(const wxString& tip)
|
||||
{
|
||||
wxWindow::DoSetToolTipText(tip);
|
||||
// Icon-only buttons are named by their tooltip, which callers set after Create().
|
||||
applyAccessibility();
|
||||
}
|
||||
|
||||
void Button::DoEnable(bool enable)
|
||||
{
|
||||
wxWindow::DoEnable(enable);
|
||||
// Keep the accessibility enabled state in sync; wx cascades DoEnable to children
|
||||
// when an ancestor is (re)enabled, and apply() reads the ancestor-aware IsEnabled().
|
||||
applyAccessibility();
|
||||
}
|
||||
|
||||
void Button::applyAccessibility()
|
||||
{
|
||||
Slic3r::GUI::Accessibility::Descriptor desc;
|
||||
desc.role = Slic3r::GUI::Accessibility::Role::Button;
|
||||
desc.name = GetLabel();
|
||||
desc.press = [this] { Click(); };
|
||||
Slic3r::GUI::Accessibility::apply(this, desc);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
wxAccessible* Button::CreateAccessible()
|
||||
{
|
||||
return new ButtonAccessible(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
WXLRESULT Button::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <wx/dc.h>
|
||||
#include <wx/tipwin.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/setup.h>
|
||||
|
||||
class ButtonProps
|
||||
{
|
||||
@@ -113,11 +114,26 @@ public:
|
||||
|
||||
void Rescale();
|
||||
|
||||
// Programmatically activate the button, as if it had been clicked. Used by the
|
||||
// accessibility layer to trigger the button from a screen reader.
|
||||
void Click();
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
// Return the accessible object that exposes this button's accessible name, role
|
||||
// and state to screen readers. See ButtonAccessible in Button.cpp.
|
||||
wxAccessible* CreateAccessible() override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#ifdef __WIN32__
|
||||
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) override;
|
||||
#endif
|
||||
|
||||
#ifdef __WXOSX__
|
||||
void DoSetToolTipText(const wxString& tip) override;
|
||||
void DoEnable(bool enable) override;
|
||||
#endif
|
||||
|
||||
bool AcceptsFocus() const override;
|
||||
|
||||
private:
|
||||
@@ -140,6 +156,11 @@ private:
|
||||
//
|
||||
void sendButtonEvent();
|
||||
|
||||
#ifdef __WXOSX__
|
||||
// (Re)expose this button to VoiceOver using its current label as the accessible name.
|
||||
void applyAccessibility();
|
||||
#endif
|
||||
|
||||
// parent motion
|
||||
void OnParentMotion(wxMouseEvent& event);
|
||||
void OnParentLeave(wxMouseEvent& event);
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#ifdef __WXGTK__
|
||||
#include "../GUI_Utils.hpp"
|
||||
#endif
|
||||
#ifdef __WXOSX__
|
||||
#include "slic3r/GUI/Accessibility/AccessibilityMac.h"
|
||||
#endif
|
||||
|
||||
CheckBox::CheckBox(wxWindow *parent, int id)
|
||||
: wxBitmapToggleButton(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE)
|
||||
@@ -38,6 +41,9 @@ CheckBox::CheckBox(wxWindow *parent, int id)
|
||||
#endif
|
||||
|
||||
Rescale();
|
||||
#ifdef __WXOSX__
|
||||
applyAccessibility();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CheckBox::SetValue(bool value)
|
||||
@@ -135,5 +141,22 @@ void CheckBox::updateBitmap(wxEvent & evt)
|
||||
OnLeaveWindow(e);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckBox::DoSetToolTipText(const wxString& tip)
|
||||
{
|
||||
wxWindow::DoSetToolTipText(tip);
|
||||
// The accessible name comes from the tooltip, which callers set after construction.
|
||||
applyAccessibility();
|
||||
}
|
||||
|
||||
void CheckBox::applyAccessibility()
|
||||
{
|
||||
// This is an NSButton-backed control, so apply() only fills in the accessible name
|
||||
// and Voice Control identifier; the checkbox role, checked value and press action
|
||||
// are already reported natively by AppKit.
|
||||
Slic3r::GUI::Accessibility::Descriptor desc;
|
||||
desc.role = Slic3r::GUI::Accessibility::Role::Checkbox;
|
||||
Slic3r::GUI::Accessibility::apply(this, desc);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -33,7 +33,9 @@ protected:
|
||||
|
||||
#ifdef __WXOSX__
|
||||
virtual wxBitmap DoGetBitmap(State which) const wxOVERRIDE;
|
||||
|
||||
|
||||
virtual void DoSetToolTipText(const wxString& tip) wxOVERRIDE;
|
||||
|
||||
void updateBitmap(wxEvent & evt);
|
||||
|
||||
bool m_disable = false;
|
||||
@@ -44,6 +46,13 @@ protected:
|
||||
private:
|
||||
void update();
|
||||
|
||||
#ifdef __WXOSX__
|
||||
// Expose this checkbox to VoiceOver / Voice Control. Native NSButton-backed controls
|
||||
// already report their role, value and press action, so this only supplies the
|
||||
// accessible name and Voice Control identifier.
|
||||
void applyAccessibility();
|
||||
#endif
|
||||
|
||||
private:
|
||||
ScalableBitmap m_on;
|
||||
ScalableBitmap m_half;
|
||||
|
||||
@@ -12,10 +12,10 @@ struct CrealityHost
|
||||
std::string ip; // dotted-quad IPv4
|
||||
std::string service_name; // raw mDNS service type, e.g. "_Creality-543324280CDB19._udp.local."
|
||||
std::string hostname; // e.g. "K2-DB19" (derived from service-name suffix)
|
||||
std::string model_code; // "F008" / "F012" / "F021" (empty if /info probe failed)
|
||||
std::string model_name; // "K2 Plus" / "K2 Pro" / "K2" (empty if model not in our table)
|
||||
std::string model_code; // "F008" / "F012" / "F021" on K2, literal name (e.g. "K1 Max") on K1-family (empty if /info probe failed)
|
||||
std::string model_name; // display name from the CFS table, e.g. "K2 Plus" / "K1 Max" (empty if model not in our table)
|
||||
std::string mac; // from /info if probed
|
||||
bool cfs_capable = false; // true when model_code is in the K2 family
|
||||
bool cfs_capable = false; // true when model_code is in the CFS-capable table
|
||||
};
|
||||
|
||||
// Synchronous LAN discovery for Creality K-series printers via DNS-SD mDNS.
|
||||
@@ -28,10 +28,10 @@ struct CrealityHost
|
||||
// reliable way to find them.
|
||||
//
|
||||
// When probe_info is true, each discovered host is followed up with an HTTP
|
||||
// GET http://<ip>/info call to fetch the printer's model code (F008/F012/F021)
|
||||
// and MAC. The probe step adds ~2-4 seconds per host but yields enriched
|
||||
// results that let the UI display "K2" / "K2 Plus" / "K2 Pro" instead of
|
||||
// just an IP.
|
||||
// GET http://<ip>/info call to fetch the printer's model code (F008/F012/F021
|
||||
// on K2, a literal model name on K1-family) and MAC. The probe step adds
|
||||
// ~2-4 seconds per host but yields enriched results that let the UI display
|
||||
// "K2 Plus" / "K1 Max" instead of just an IP.
|
||||
//
|
||||
// Call from a background thread -- the function blocks for at least 5 seconds.
|
||||
class CrealityHostDiscovery
|
||||
|
||||
@@ -294,13 +294,18 @@ static void ws_close(net::io_context& ioc, websocket::stream<beast::tcp_stream>&
|
||||
}
|
||||
|
||||
// K1-family firmware stores gcodes under /usr/data and uses a stricter WebSocket
|
||||
// protocol (TEXT frames, heartbeat acks). Add verified K1-family model IDs here.
|
||||
// protocol (TEXT frames, heartbeat acks). The /info model is the literal name on
|
||||
// K1-family, including the *_CFS-C bundle variants. Add verified model IDs here.
|
||||
static bool is_k1_family(const std::string& model)
|
||||
{
|
||||
static const std::unordered_set<std::string> k1_models = {
|
||||
"K1",
|
||||
"K1 Max",
|
||||
"K1 Max_CFS-C",
|
||||
"K1 SE",
|
||||
"K1 SE_CFS-C",
|
||||
"K1C",
|
||||
"K1C_CFS-C",
|
||||
"K1_CFS-C",
|
||||
};
|
||||
return k1_models.count(model) > 0;
|
||||
@@ -322,11 +327,16 @@ static const std::map<std::string, std::string>& cfs_capable_models()
|
||||
static const std::map<std::string, std::string> models = {
|
||||
{"F008", "K2 Plus"},
|
||||
{"F012", "K2 Pro"},
|
||||
{"F016", "K2 SE"},
|
||||
{"F021", "K2"},
|
||||
{"F022", "SPARKX i7"},
|
||||
{"K1", "K1"},
|
||||
{"K1 Max", "K1 Max"},
|
||||
{"K1 Max_CFS-C", "K1 Max_CFS-C"},
|
||||
{"K1 SE", "K1 SE"},
|
||||
{"K1 SE_CFS-C", "K1 SE_CFS-C"},
|
||||
{"K1C", "K1C"},
|
||||
{"K1C_CFS-C", "K1C_CFS-C"},
|
||||
{"K1_CFS-C", "K1_CFS-C"},
|
||||
};
|
||||
return models;
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
#include "IPrinterAgent.hpp"
|
||||
#include "NetworkAgentFactory.hpp"
|
||||
#include "bambu_networking.hpp"
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/Format/bbs_3mf.hpp"
|
||||
#include "libslic3r/Preset.hpp"
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/miniz_extension.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/I18N.hpp"
|
||||
#include "slic3r/GUI/DeviceManager.hpp"
|
||||
@@ -49,7 +52,9 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <miniz.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/tls1.h>
|
||||
@@ -57,15 +62,18 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <ios>
|
||||
#include <functional>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
@@ -154,6 +162,117 @@ uint64_t steady_now_ms()
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
|
||||
bool extract_plate_gcode(const std::string& archive_path, int plate_index, const boost::filesystem::path& gcode_path)
|
||||
{
|
||||
static const std::regex plate_gcode(R"(Metadata/plate_\d+\.gcode)");
|
||||
|
||||
mz_zip_archive archive;
|
||||
mz_zip_zero_struct(&archive);
|
||||
if (!Slic3r::open_zip_reader(&archive, archive_path))
|
||||
return false;
|
||||
|
||||
int index = mz_zip_reader_locate_file(&archive, (boost::format(GCODE_FILE_FORMAT) % plate_index).str().c_str(), nullptr, 0);
|
||||
if (index < 0) {
|
||||
int plates = 0;
|
||||
for (mz_uint i = 0, n = mz_zip_reader_get_num_files(&archive); i < n; ++i) {
|
||||
mz_zip_archive_file_stat stat;
|
||||
if (mz_zip_reader_file_stat(&archive, i, &stat) && std::regex_match(stat.m_filename, plate_gcode)) {
|
||||
index = int(i);
|
||||
++plates;
|
||||
}
|
||||
}
|
||||
// Another plate's G-code would print the wrong part
|
||||
if (plates != 1)
|
||||
index = -1;
|
||||
}
|
||||
const bool extracted = index >= 0 && Slic3r::extract_zip_entry_to_file(&archive, mz_uint(index), gcode_path);
|
||||
Slic3r::close_zip_reader(&archive);
|
||||
return extracted;
|
||||
}
|
||||
|
||||
// Klipper reads any uploaded file as G-code, so unless the printer prints 3MF, a .gcode.3mf bundle is uploaded as the
|
||||
// plate's G-code inside it.
|
||||
class UploadFile
|
||||
{
|
||||
public:
|
||||
UploadFile(const std::string& path, const Slic3r::PrintParams& params, bool printer_accepts_3mf) : m_source(path), m_path(path)
|
||||
{
|
||||
if (!boost::iends_with(path, ".3mf"))
|
||||
return;
|
||||
if (printer_accepts_3mf) {
|
||||
m_sends_bundle = true;
|
||||
return;
|
||||
}
|
||||
m_path.clear();
|
||||
m_failed = true;
|
||||
boost::system::error_code ec;
|
||||
const boost::filesystem::path temp_dir = boost::filesystem::temp_directory_path(ec);
|
||||
const boost::filesystem::path name = ec ? boost::filesystem::path() :
|
||||
boost::filesystem::unique_path("orca-upload-%%%%-%%%%-%%%%.gcode", ec);
|
||||
if (ec) {
|
||||
BOOST_LOG_TRIVIAL(error) << "MoonrakerPrinterAgent: no temp file to extract the plate G-code to: " << ec.message();
|
||||
return;
|
||||
}
|
||||
m_extracted = temp_dir / name;
|
||||
// plate_index is read only for a bundle, because the verify uploads leave it unset
|
||||
if (!extract_plate_gcode(path, params.plate_index, m_extracted)) {
|
||||
BOOST_LOG_TRIVIAL(error) << "MoonrakerPrinterAgent: no G-code for plate " << params.plate_index << " in " << path;
|
||||
return;
|
||||
}
|
||||
m_path = m_extracted.string();
|
||||
m_failed = false;
|
||||
}
|
||||
~UploadFile()
|
||||
{
|
||||
if (!m_extracted.empty()) {
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::remove(m_extracted, ec);
|
||||
}
|
||||
}
|
||||
UploadFile(const UploadFile&) = delete;
|
||||
UploadFile& operator=(const UploadFile&) = delete;
|
||||
|
||||
// ok() is false when a bundle's plate G-code could not be extracted.
|
||||
bool ok() const { return !m_failed; }
|
||||
const std::string& path() const { return m_path; }
|
||||
|
||||
std::string upload_name(std::string name) const
|
||||
{
|
||||
if (name.empty())
|
||||
name = boost::filesystem::path(m_source).filename().string();
|
||||
for (const char* extension : {".3mf", ".gcode"})
|
||||
if (boost::iends_with(name, extension))
|
||||
name.erase(name.size() - std::strlen(extension));
|
||||
// Klipper's print start can't take # ; * or control characters, newer curl uploads " as %22, and / \ would make
|
||||
// the name a path
|
||||
std::replace_if(name.begin(), name.end(), [](char c) {
|
||||
const auto byte = static_cast<unsigned char>(c);
|
||||
return byte < 0x20 || byte == 0x7F || std::string_view("\"#;*/\\").find(c) != std::string_view::npos;
|
||||
}, '_');
|
||||
// A leading dot hides the file in Fluidd and Mainsail, and a leading space may be trimmed from the stored name
|
||||
name.erase(0, name.find_first_not_of(". "));
|
||||
// Printer file systems allow 255 bytes per name
|
||||
const std::size_t max_stem = 255 - std::strlen(".gcode.3mf");
|
||||
if (name.size() > max_stem) {
|
||||
std::size_t cut = max_stem;
|
||||
while (cut > 0 && (static_cast<unsigned char>(name[cut]) & 0xC0) == 0x80)
|
||||
--cut;
|
||||
name.resize(cut);
|
||||
}
|
||||
if (name.empty())
|
||||
name = "print";
|
||||
// A bundle is named .gcode.3mf, as the print host upload names it
|
||||
return name + (m_sends_bundle ? ".gcode.3mf" : ".gcode");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_source;
|
||||
std::string m_path;
|
||||
boost::filesystem::path m_extracted;
|
||||
bool m_sends_bundle = false;
|
||||
bool m_failed = false;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Slic3r {
|
||||
@@ -339,19 +458,13 @@ int MoonrakerPrinterAgent::start_send_gcode_to_sdcard(PrintParams params,
|
||||
if (update_fn)
|
||||
update_fn(PrintingStageCreate, 0, _u8L("Preparing..."));
|
||||
|
||||
std::string filename = params.filename;
|
||||
if (filename.empty()) {
|
||||
filename = params.task_name;
|
||||
UploadFile file(params.filename, params, accepts_3mf());
|
||||
if (!file.ok()) {
|
||||
return BAMBU_NETWORK_ERR_FILE_NOT_EXIST;
|
||||
}
|
||||
if (!boost::iends_with(filename, ".gcode")) {
|
||||
filename += ".gcode";
|
||||
}
|
||||
|
||||
// Sanitize filename to prevent path traversal attacks
|
||||
std::string safe_filename = sanitize_filename(filename);
|
||||
|
||||
// Upload only, don't start print
|
||||
if (!upload_gcode(params.filename, safe_filename, device_info.base_url, device_info.api_key, update_fn, cancel_fn)) {
|
||||
if (!upload_gcode(file.path(), file.upload_name(params.project_name), device_info.base_url, device_info.api_key, update_fn, cancel_fn)) {
|
||||
return BAMBU_NETWORK_ERR_PRINT_SG_UPLOAD_FTP_FAILED;
|
||||
}
|
||||
|
||||
@@ -376,7 +489,6 @@ int MoonrakerPrinterAgent::start_local_print(PrintParams params, OnUpdateStatusF
|
||||
gcode_path = params.dst_file;
|
||||
}
|
||||
|
||||
// Check if file exists and has .gcode extension
|
||||
namespace fs = boost::filesystem;
|
||||
fs::path source_path(gcode_path);
|
||||
if (!fs::exists(source_path)) {
|
||||
@@ -384,18 +496,17 @@ int MoonrakerPrinterAgent::start_local_print(PrintParams params, OnUpdateStatusF
|
||||
return BAMBU_NETWORK_ERR_FILE_NOT_EXIST;
|
||||
}
|
||||
|
||||
// Extract filename for upload (relative to gcodes root)
|
||||
std::string upload_filename = source_path.filename().string();
|
||||
if (!boost::iends_with(upload_filename, ".gcode")) {
|
||||
upload_filename += ".gcode";
|
||||
UploadFile file(gcode_path, params, accepts_3mf());
|
||||
if (!file.ok()) {
|
||||
return BAMBU_NETWORK_ERR_FILE_NOT_EXIST;
|
||||
}
|
||||
// Sanitize filename to prevent path traversal attacks (extra safety)
|
||||
upload_filename = sanitize_filename(upload_filename);
|
||||
|
||||
const std::string upload_filename = file.upload_name(params.project_name);
|
||||
|
||||
// Upload file
|
||||
if (update_fn)
|
||||
update_fn(PrintingStageUpload, 0, _u8L("Uploading G-code..."));
|
||||
if (!upload_gcode(gcode_path, upload_filename, device_info.base_url, device_info.api_key, update_fn, cancel_fn)) {
|
||||
if (!upload_gcode(file.path(), upload_filename, device_info.base_url, device_info.api_key, update_fn, cancel_fn)) {
|
||||
return BAMBU_NETWORK_ERR_PRINT_LP_UPLOAD_FTP_FAILED;
|
||||
}
|
||||
|
||||
@@ -417,8 +528,15 @@ int MoonrakerPrinterAgent::start_local_print(PrintParams params, OnUpdateStatusF
|
||||
|
||||
bool MoonrakerPrinterAgent::print_uploaded_file(const PrintParams& /*params*/, const std::string& filename)
|
||||
{
|
||||
// Start print via gcode script (simpler than JSON-RPC)
|
||||
return send_gcode_sync(device_info.dev_id, "SDCARD_PRINT_FILE FILENAME=" + filename);
|
||||
// Start print via gcode script (simpler than JSON-RPC); quoted so spaces and apostrophes stay part of the name
|
||||
return send_gcode_sync(device_info.dev_id, "SDCARD_PRINT_FILE FILENAME=\"" + filename + "\"");
|
||||
}
|
||||
|
||||
bool MoonrakerPrinterAgent::accepts_3mf() const
|
||||
{
|
||||
const PresetBundle* bundle = GUI::wxGetApp().preset_bundle;
|
||||
const ConfigOptionBool* use_3mf = bundle ? bundle->printers.get_edited_preset().config.option<ConfigOptionBool>("use_3mf") : nullptr;
|
||||
return use_3mf != nullptr && use_3mf->value;
|
||||
}
|
||||
|
||||
int MoonrakerPrinterAgent::start_sdcard_print(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn)
|
||||
@@ -2460,9 +2578,8 @@ std::string MoonrakerPrinterAgent::sanitize_filename(const std::string& filename
|
||||
if (filename.empty()) {
|
||||
return "print.gcode";
|
||||
}
|
||||
namespace fs = boost::filesystem;
|
||||
fs::path p(filename);
|
||||
std::string basename = p.filename().string();
|
||||
// boost's Windows path parsing would also split at ':', which printer file names may contain
|
||||
const std::string basename = filename.substr(filename.find_last_of("/\\") + 1);
|
||||
if (basename.empty() || basename == "." || basename == "..") {
|
||||
return "print.gcode";
|
||||
}
|
||||
|
||||
@@ -133,6 +133,8 @@ protected:
|
||||
const std::function<bool()>& cancelled) const;
|
||||
// Starts the print of a file already uploaded to the gcodes root
|
||||
virtual bool print_uploaded_file(const PrintParams& params, const std::string& filename);
|
||||
// Whether the printer prints a .gcode.3mf bundle as is (its use_3mf option)
|
||||
virtual bool accepts_3mf() const;
|
||||
void start_status_stream(const std::string& dev_id, const std::string& base_url, const std::string& api_key);
|
||||
void stop_status_stream();
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
@@ -129,7 +130,16 @@ bool QidiPrinterAgent::print_uploaded_file(const PrintParams& params, const std:
|
||||
|
||||
// On the X-Max 4 and Q2, Klipper only opens the copy Moonraker's print start makes, so SDCARD_PRINT_FILE can't find the upload
|
||||
std::string response;
|
||||
return send_jsonrpc_command(device_info.base_url, device_info.api_key, {{"filename", filename}}, response);
|
||||
return send_jsonrpc_command(device_info.base_url, device_info.api_key, print_start_request(params, filename), response);
|
||||
}
|
||||
|
||||
nlohmann::json QidiPrinterAgent::print_start_request(const PrintParams& params, const std::string& filename)
|
||||
{
|
||||
nlohmann::json request{{"filename", filename}};
|
||||
// Qidi's Moonraker prints Metadata/plate_<plateindex>.gcode from a 3MF, defaulting to plate 1
|
||||
if (boost::iends_with(filename, ".3mf"))
|
||||
request["plateindex"] = std::to_string(params.plate_index);
|
||||
return request;
|
||||
}
|
||||
|
||||
bool QidiPrinterAgent::fetch_slot_info(const std::string& base_url,
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class QidiPrinterAgent final : public MoonrakerPrinterAgent
|
||||
@@ -25,6 +27,8 @@ public:
|
||||
|
||||
// Builds the SAVE_VARIABLE lines that make each T<n> macro load the Box slot picked for filament n
|
||||
static std::string build_tool_slot_script(const std::string& ams_mapping);
|
||||
// Builds the body of Moonraker's print start for an uploaded file, naming the plate to print when it is a 3MF
|
||||
static nlohmann::json print_start_request(const PrintParams& params, const std::string& filename);
|
||||
|
||||
protected:
|
||||
// Saves the Box slot picked for each filament in the print dialog, then starts the print through Moonraker
|
||||
|
||||
@@ -95,18 +95,24 @@ TEST_CASE("The default adaptive pressure advance model holds no measurements", "
|
||||
CHECK(AdaptivePAProcessor::adaptive_pa_model_has_measurements("0.04,3.96,3000"));
|
||||
}
|
||||
|
||||
// The warnings Print::validate raises about the adaptive pressure advance model.
|
||||
static std::vector<std::string> adaptive_pa_model_warnings(const std::string &model)
|
||||
// The warnings Print::validate raises about the adaptive pressure advance models, one per filament,
|
||||
// when a cube is printed with the given filament.
|
||||
static std::vector<std::string> adaptive_pa_model_warnings(const std::vector<std::string> &models, int filament = 1)
|
||||
{
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "enable_pressure_advance", "1" },
|
||||
{ "adaptive_pressure_advance", "1" },
|
||||
// the default config fails validation on relative extrusion without a G92 E0 at each layer
|
||||
{ "use_relative_e_distances", "0" },
|
||||
});
|
||||
for (const char *key : { "enable_pressure_advance", "adaptive_pressure_advance" })
|
||||
config.option<ConfigOptionBools>(key)->values.assign(models.size(), true);
|
||||
// the filament count is the number of filament diameters
|
||||
config.option<ConfigOptionFloats>("filament_diameter")->values.assign(models.size(), 1.75);
|
||||
// set as a value so that an empty model stays one filament column, as a preset holds it
|
||||
config.option<ConfigOptionStrings>("adaptive_pressure_advance_model")->values = { model };
|
||||
config.option<ConfigOptionStrings>("adaptive_pressure_advance_model")->values = models;
|
||||
for (const char *key : { "outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_filament_id",
|
||||
"internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id" })
|
||||
config.option<ConfigOptionInt>(key)->value = filament;
|
||||
Print print;
|
||||
Model model_instance;
|
||||
init_print({ cube(20) }, print, model_instance, config);
|
||||
@@ -121,6 +127,11 @@ static std::vector<std::string> adaptive_pa_model_warnings(const std::string &mo
|
||||
return texts;
|
||||
}
|
||||
|
||||
static std::vector<std::string> adaptive_pa_model_warnings(const std::string &model)
|
||||
{
|
||||
return adaptive_pa_model_warnings(std::vector<std::string>{ model });
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing warns when adaptive pressure advance is enabled without a model", "[AdaptivePressureAdvance]")
|
||||
{
|
||||
const std::string default_model = DynamicPrintConfig::full_print_config().opt_string("adaptive_pressure_advance_model", 0u);
|
||||
@@ -141,3 +152,20 @@ TEST_CASE("Slicing warns about an adaptive pressure advance model whose flow is
|
||||
REQUIRE(warnings.size() == 1);
|
||||
CHECK(warnings.front().find("invalid values") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing names the filament and the line of an invalid adaptive pressure advance model", "[AdaptivePressureAdvance]")
|
||||
{
|
||||
// a period where the comma belongs leaves the second line with two values
|
||||
const std::vector<std::string> warnings = adaptive_pa_model_warnings("0.07,4.71,500\n0.04.7.53,1000\n0.035,9.41,1000");
|
||||
REQUIRE(warnings.size() == 1);
|
||||
CHECK(warnings.front().find("filament 1") != std::string::npos);
|
||||
CHECK(warnings.front().find("Line 2") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing names the second filament when its adaptive pressure advance model is invalid", "[AdaptivePressureAdvance]")
|
||||
{
|
||||
const std::vector<std::string> warnings = adaptive_pa_model_warnings({ "0.07,4.71,500\n0.035,9.41,1000", "0.07,4.71,500\n0.04.7.53,1000" }, 2);
|
||||
REQUIRE(warnings.size() == 1);
|
||||
CHECK(warnings.front().find("filament 2") != std::string::npos);
|
||||
CHECK(warnings.front().find("Line 2") != std::string::npos);
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
#include "libslic3r/libslic3r.h"
|
||||
#include "libslic3r/BeltTransform.hpp"
|
||||
#include "libslic3r/BoundingBox.hpp"
|
||||
@@ -24,10 +25,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <initializer_list>
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
@@ -658,36 +661,57 @@ TEST_CASE("Each extrusion weighs its filament's density", "[GCodeProcessor]")
|
||||
|
||||
namespace {
|
||||
|
||||
// Two nozzles over a 200 mm square bed: nozzle 1 reaches only `nozzle_1_area`, nozzle 2 the whole bed.
|
||||
// A 20 mm cube centered on `center` prints with filament 1, mapped to nozzle 1.
|
||||
void slice_cube_in_nozzle_area(const Vec2ds &nozzle_1_area, const Vec2d ¢er, GCodeProcessorResult &result)
|
||||
// A printer with `nozzles` nozzles over a 200 mm square bed: nozzle `filament_1_nozzle` reaches only
|
||||
// `nozzle_area`, the others the whole bed. A 20 mm cube centered on `center` prints with filament 1,
|
||||
// mapped to that nozzle and printable on every nozzle.
|
||||
void slice_cube_in_nozzle_area(const Vec2ds &nozzle_area, const Vec2d ¢er, GCodeProcessorResult &result, int nozzles = 2,
|
||||
int filament_1_nozzle = 1)
|
||||
{
|
||||
const auto per_nozzle = [nozzles](const std::string &value) {
|
||||
std::string values = value;
|
||||
for (int i = 1; i < nozzles; ++i)
|
||||
values += "," + value;
|
||||
return values;
|
||||
};
|
||||
std::string extruder_ids = "1";
|
||||
for (int i = 2; i <= nozzles; ++i)
|
||||
extruder_ids += "," + std::to_string(i);
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "nozzle_diameter", "0.4,0.4" },
|
||||
{ "printer_extruder_id", "1,2" },
|
||||
{ "printer_extruder_variant", "Direct Drive Standard,Direct Drive Standard" },
|
||||
{ "extruder_offset", "0x0,0x0" },
|
||||
{ "nozzle_diameter", per_nozzle("0.4") },
|
||||
{ "printer_extruder_id", extruder_ids },
|
||||
{ "printer_extruder_variant", per_nozzle("Direct Drive Standard") },
|
||||
{ "extruder_offset", per_nozzle("0x0") },
|
||||
{ "printable_area", "0x0,200x0,200x200,0x200" },
|
||||
{ "printable_height", 100 },
|
||||
{ "extruder_printable_height", "100,100" },
|
||||
{ "extruder_printable_height", per_nozzle("100") },
|
||||
// One filament, so one purge volume per nozzle, as the GUI and the CLI size it.
|
||||
{ "flush_volumes_matrix", per_nozzle("0") },
|
||||
{ "skirt_loops", 0 },
|
||||
{ "brim_type", "no_brim" },
|
||||
{ "layer_change_gcode", "G92 E0\n" }, // validate() relative-E reset
|
||||
{ "filament_map_mode", "Manual" },
|
||||
{ "filament_map", "1" },
|
||||
{ "filament_map", filament_1_nozzle },
|
||||
{ "filament_printable", -1 },
|
||||
});
|
||||
// Other per-nozzle printer options, at their defaults.
|
||||
for (const char *key : { "extruder_type", "nozzle_volume_type", "min_layer_height", "max_layer_height", "extruder_max_nozzle_count" })
|
||||
dynamic_cast<ConfigOptionVectorBase *>(config.option(key))->resize(nozzles);
|
||||
const Vec2ds bed { Vec2d(0., 0.), Vec2d(200., 0.), Vec2d(200., 200.), Vec2d(0., 200.) };
|
||||
config.set_key_value("extruder_printable_area", new ConfigOptionPointsGroups(std::vector<Vec2ds>{ nozzle_1_area, bed }));
|
||||
std::vector<Vec2ds> areas(nozzles, bed);
|
||||
areas[filament_1_nozzle - 1] = nozzle_area;
|
||||
config.set_key_value("extruder_printable_area", new ConfigOptionPointsGroups(areas));
|
||||
|
||||
TriangleMesh mesh = Test::cube(20);
|
||||
mesh.translate(float(center.x() - 10.), float(center.y() - 10.), 0.f);
|
||||
Print print;
|
||||
Model model;
|
||||
Test::init_print(std::vector<TriangleMesh>{ std::move(mesh) }, print, model, config, nullptr, false);
|
||||
REQUIRE_THAT(print.validate().string, Catch::Matchers::Equals(std::string()));
|
||||
Test::gcode(print, &result);
|
||||
}
|
||||
|
||||
// Nozzle 1's area inset from the bed on one side, on two adjacent sides (leaving an L-shaped
|
||||
// A nozzle's area inset from the bed on one side, on two adjacent sides (leaving an L-shaped
|
||||
// unprintable region), on three (a U) and on all four (a frame). Each contains the bed center and
|
||||
// has an X 150 edge; all but the first also have a Y 50 edge, meeting it in an inner corner.
|
||||
Vec2ds inset_nozzle_area(int sides)
|
||||
@@ -802,3 +826,63 @@ TEST_CASE("A filament mapped to no nozzle has no errors listed under a nozzle",
|
||||
|
||||
CHECK(result.gcode_check_result.print_area_error_infos.count(-1) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Nozzles up to the 64th are marked as unable to print a filament they can't", "[GCodeProcessor][Regression]")
|
||||
{
|
||||
// 64 nozzles over a 200 mm square bed. Filament 1 maps to one of them and prints a 20 mm square
|
||||
// at X 160-180, Y 100-120, Z 10, which that nozzle alone can't print.
|
||||
const int nozzle = GENERATE(1, 31, 32, 63); // 0-based
|
||||
CAPTURE(nozzle);
|
||||
const Vec2ds bed { Vec2d(0., 0.), Vec2d(200., 0.), Vec2d(200., 200.), Vec2d(0., 200.) };
|
||||
std::vector<Polygons> unprintable_areas(MAXIMUM_EXTRUDER_NUMBER);
|
||||
std::vector<double> printable_heights(MAXIMUM_EXTRUDER_NUMBER, 100.);
|
||||
std::vector<std::set<int>> unprintable_filament_types(MAXIMUM_EXTRUDER_NUMBER);
|
||||
int expected_error = 0;
|
||||
SECTION("it can't reach the square")
|
||||
{
|
||||
const Vec2ds nozzle_area { Vec2d(0., 0.), Vec2d(150., 0.), Vec2d(150., 200.), Vec2d(0., 200.) };
|
||||
unprintable_areas[nozzle] = diff(Polygon::new_scale(bed), Polygon::new_scale(nozzle_area));
|
||||
expected_error = 1;
|
||||
}
|
||||
SECTION("the square is above its printable height")
|
||||
{
|
||||
printable_heights[nozzle] = 5.;
|
||||
expected_error = 1 << 1;
|
||||
}
|
||||
SECTION("it can't print the filament's type") { unprintable_filament_types[nozzle] = { 0 }; }
|
||||
|
||||
GCodeProcessor processor;
|
||||
for (const Vec2d &point : { Vec2d(160., 100.), Vec2d(180., 100.), Vec2d(180., 120.), Vec2d(160., 120.) }) {
|
||||
GCodeProcessorResult::MoveVertex move;
|
||||
move.type = EMoveType::Extrude;
|
||||
move.extrusion_role = erExternalPerimeter;
|
||||
move.extruder_id = 0; // filament 1
|
||||
move.object_label_id = 1;
|
||||
move.position = Vec3f(float(point.x()), float(point.y()), 10.f);
|
||||
move.print_z = 10.f;
|
||||
processor.result().moves.emplace_back(move);
|
||||
}
|
||||
processor.check_multi_extruder_gcode_valid(int(MAXIMUM_EXTRUDER_NUMBER), bed, 100., {}, unprintable_areas, printable_heights,
|
||||
{ nozzle + 1 }, unprintable_filament_types);
|
||||
const GCodeProcessorResult &result = processor.result();
|
||||
|
||||
CHECK(result.gcode_check_result.error_code == expected_error);
|
||||
REQUIRE(result.limit_filament_maps.size() == 1);
|
||||
CHECK(result.limit_filament_maps[0] == uint64_t(1) << nozzle);
|
||||
}
|
||||
|
||||
TEST_CASE("A cube on the 64th nozzle of a 64-nozzle printer slices, and fails the area check only outside that nozzle's area", "[GCodeProcessor][Regression]")
|
||||
{
|
||||
// Filament 1 maps to nozzle 64, which reaches X 0-150. The cube sits at the bed center, or at X 165-185.
|
||||
const int nozzles = 64;
|
||||
const bool outside = GENERATE(false, true);
|
||||
INFO("cube " << (outside ? "outside" : "inside") << " nozzle 64's area");
|
||||
GCodeProcessorResult result;
|
||||
slice_cube_in_nozzle_area(inset_nozzle_area(1), outside ? Vec2d(175., 100.) : Vec2d(100., 100.), result, nozzles, nozzles);
|
||||
|
||||
const int expected = outside ? 1 : 0;
|
||||
CHECK((result.gcode_check_result.error_code & 1) == expected);
|
||||
CHECK(result.gcode_check_result.print_area_error_infos.count(nozzles - 1) == size_t(expected));
|
||||
REQUIRE(result.limit_filament_maps.size() == 1);
|
||||
CHECK(result.limit_filament_maps[0] == uint64_t(expected) << (nozzles - 1));
|
||||
}
|
||||
@@ -561,6 +561,40 @@ TEST_CASE("Print: {first_object_name} is not replaced by the saved-project file
|
||||
CHECK(resolved_output_name(model, "{first_object_name}", "SavedProject") == "WidgetPart.gcode");
|
||||
}
|
||||
|
||||
TEST_CASE("{printing_filament_types} lists the filament types really printed", "[Print]")
|
||||
{
|
||||
// Two filaments of different types. The start G-code uses the placeholder too: it has to
|
||||
// resolve there as well as in the file name.
|
||||
DynamicPrintConfig config = multifilament_config(2, {
|
||||
{ "filament_type", "ABS;PLA" },
|
||||
{ "enable_prime_tower", 0 },
|
||||
{ "filename_format", "{printing_filament_types}-{filament_type[initial_tool]}" },
|
||||
{ "machine_start_gcode", "; printing types: {printing_filament_types}" },
|
||||
});
|
||||
|
||||
SECTION("only the filament the object is printed with, not filament 1") {
|
||||
const std::vector<std::vector<ConfigBase::SetDeserializeItem>> overrides{ { { "extruder", 2 } } };
|
||||
Print print;
|
||||
Model model;
|
||||
init_print({ cube(20) }, print, model, config, &overrides);
|
||||
const std::string gcode = Slic3r::Test::gcode(print);
|
||||
|
||||
CHECK(gcode.find("; printing types: PLA\n") != std::string::npos);
|
||||
CHECK(print.output_filename() == "PLA-PLA.gcode");
|
||||
}
|
||||
|
||||
SECTION("every type printed, joined with an underscore") {
|
||||
const std::vector<std::vector<ConfigBase::SetDeserializeItem>> overrides{ { { "extruder", 1 } }, { { "extruder", 2 } } };
|
||||
Print print;
|
||||
Model model;
|
||||
init_print({ cube(20), cube(20) }, print, model, config, &overrides);
|
||||
const std::string gcode = Slic3r::Test::gcode(print);
|
||||
|
||||
CHECK(gcode.find("; printing types: ABS_PLA\n") != std::string::npos);
|
||||
CHECK(print.output_filename() == "ABS_PLA-ABS.gcode");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Print::validate stacks independent warnings", "[Print][validate]")
|
||||
{
|
||||
// Two unrelated checks (region precise-wall + machine acceleration) must each
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/catch_message.hpp>
|
||||
#include "libslic3r/libslic3r.h"
|
||||
@@ -161,6 +162,24 @@ TEST_CASE("Initial layer height is honored", "[PrintObject]")
|
||||
REQUIRE_THAT(*std::next(layer_zs.begin()), Catch::Matchers::WithinAbs(0.5, 1e-4));
|
||||
}
|
||||
|
||||
TEST_CASE("An object too thin for any layer fails with a slicing error", "[PrintObject][Regression]")
|
||||
{
|
||||
const int raft_layers = GENERATE(0, 2);
|
||||
const bool precise_z_height = GENERATE(false, true);
|
||||
DYNAMIC_SECTION("raft_layers " << raft_layers << ", precise_z_height " << precise_z_height) {
|
||||
Slic3r::Print print;
|
||||
Slic3r::Model model;
|
||||
Slic3r::Test::init_print({make_cube(20, 20, 0.002)}, print, model, {
|
||||
{ "layer_height", 0.2 },
|
||||
{ "initial_layer_print_height", 0.2 },
|
||||
{ "min_layer_height", 0.07 },
|
||||
{ "raft_layers", raft_layers },
|
||||
{ "precise_z_height", precise_z_height }
|
||||
});
|
||||
REQUIRE_THROWS_WITH(print.process(), Catch::Matchers::ContainsSubstring("No layers were detected"));
|
||||
}
|
||||
}
|
||||
|
||||
static TriangleMesh internal_bridge_step()
|
||||
{
|
||||
// Orca: The smaller tower leaves a shoulder whose solid skin needs internal bridges
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "libslic3r/BoundingBox.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
#include "libslic3r/GCode/GCodeProcessor.hpp"
|
||||
#include "libslic3r/GCodeReader.hpp"
|
||||
#include "libslic3r/GCode/WipeTower.hpp"
|
||||
#include "libslic3r/LocalesUtils.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
@@ -573,3 +575,101 @@ TEST_CASE("Only a cone wall gives the tower a stabilization cone", "[WipeTower]"
|
||||
CHECK_FALSE(print.get_conflict_result().has_value());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Without sparse layers the filament change starts at the tallest printed layer", "[WipeTower]")
|
||||
{
|
||||
// Filament 2 on top surfaces only, so the layers between the short cube's top and the tall
|
||||
// cube's top have no toolchange and the tower skips them: at the tall cube's top it is still
|
||||
// about 2 mm high. A custom change_filament_gcode may travel anywhere, and so may the firmware
|
||||
// Tn of a switch to another physical extruder, so neither may start that low.
|
||||
const std::string tower_type = GENERATE("type1", "type2");
|
||||
const bool two_nozzles = GENERATE(false, true);
|
||||
const bool custom_macro = GENERATE(true, false);
|
||||
DynamicPrintConfig config = multifilament_config(2, {
|
||||
{ "top_surface_filament_id", 2 },
|
||||
{ "enable_prime_tower", true },
|
||||
{ "wipe_tower_type", tower_type },
|
||||
{ "wipe_tower_no_sparse_layers", true },
|
||||
{ "wipe_tower_x", 30 },
|
||||
{ "wipe_tower_y", 30 },
|
||||
{ "layer_height", 0.2 },
|
||||
{ "change_filament_gcode", custom_macro ? "; TOOLCHANGE_MARK\n" : "" },
|
||||
{ "gcode_comments", true },
|
||||
{ "timelapse_type", "0" },
|
||||
{ "enable_wrapping_detection", false },
|
||||
{ "raft_layers", "0" } });
|
||||
if (two_nozzles) {
|
||||
config.set_num_extruders(2);
|
||||
config.set_deserialize_strict({
|
||||
{ "single_extruder_multi_material", false },
|
||||
{ "nozzle_diameter", "0.4,0.4" },
|
||||
{ "printer_extruder_id", "1,2" },
|
||||
{ "printer_extruder_variant", "Direct Drive Standard,Direct Drive Standard" },
|
||||
{ "extruder_printable_height", "0,0" },
|
||||
{ "filament_map_mode", "Manual" },
|
||||
{ "filament_map", "1,2" } });
|
||||
size_flush_to_nozzles(config);
|
||||
}
|
||||
|
||||
const double short_height = 2., tall_height = 10.;
|
||||
TriangleMesh tall = make_cube(10., 10., tall_height);
|
||||
tall.translate(120.f, 120.f, 0.f);
|
||||
TriangleMesh low = make_cube(10., 10., short_height);
|
||||
low.translate(150.f, 120.f, 0.f);
|
||||
|
||||
Print print;
|
||||
Model model;
|
||||
init_print({ std::move(tall), std::move(low) }, print, model, config, nullptr, false);
|
||||
print.apply(model, config);
|
||||
const std::string gcode = Slic3r::Test::gcode(print);
|
||||
|
||||
// Z where each change_filament_gcode or Tn starts, next to the highest Z of the objects
|
||||
// extruded before it; and the Z of each tower extrusion once the objects pass the short cube.
|
||||
std::vector<std::pair<double, double>> changes;
|
||||
std::vector<std::pair<double, double>> tower_extrusions;
|
||||
double object_z = 0.;
|
||||
bool in_tower = false;
|
||||
size_t lifts = 0;
|
||||
GCodeReader parser;
|
||||
parser.parse_buffer(gcode, [&](GCodeReader &self, const GCodeReader::GCodeLine &line) {
|
||||
const std::string_view raw = line.raw();
|
||||
// Objects are tagged with the processor's ;TYPE:, the tower with its own ; FEATURE:.
|
||||
if (raw.rfind(";TYPE:", 0) == 0 || raw.rfind("; FEATURE: ", 0) == 0)
|
||||
in_tower = raw.find("Prime tower") != std::string_view::npos;
|
||||
else if (line.extruding(self) && (line.has_x() || line.has_y())) { // not an unretract
|
||||
if (!in_tower)
|
||||
object_z = std::max(object_z, double(self.z()));
|
||||
// Above the tall cube is the final unload, printed over the finished parts on purpose.
|
||||
else if (object_z > short_height + EPSILON && self.z() <= tall_height + EPSILON)
|
||||
tower_extrusions.emplace_back(self.z(), object_z);
|
||||
} else if (raw.find("; TOOLCHANGE_MARK") != std::string_view::npos
|
||||
|| (raw.size() > 1 && raw[0] == 'T' && raw[1] >= '0' && raw[1] <= '9'))
|
||||
changes.emplace_back(self.z(), object_z);
|
||||
if (raw.find("Restore layer Z before toolchange") != std::string_view::npos)
|
||||
++lifts;
|
||||
});
|
||||
INFO(tower_type << (two_nozzles ? ", two nozzles" : ", one nozzle") << (custom_macro ? ", custom macro" : ", empty macro"));
|
||||
|
||||
if (!custom_macro && !two_nozzles) {
|
||||
// Nothing travels during the change, so the toolhead stays down at the tower.
|
||||
CHECK(lifts == 0);
|
||||
} else {
|
||||
size_t above_short = 0;
|
||||
for (const auto &[change_z, printed_z] : changes) {
|
||||
if (printed_z <= short_height + EPSILON)
|
||||
continue;
|
||||
++above_short;
|
||||
INFO("toolchange at Z " << change_z << ", printed up to Z " << printed_z);
|
||||
CHECK(change_z >= printed_z - EPSILON);
|
||||
}
|
||||
// The tall cube's top surface needs at least one change above the short cube.
|
||||
CHECK(above_short > 0);
|
||||
}
|
||||
|
||||
// Every lift has to come back down: the tower keeps printing at its compacted height.
|
||||
REQUIRE_FALSE(tower_extrusions.empty());
|
||||
for (const auto &[tower_z, printed_z] : tower_extrusions) {
|
||||
INFO("tower extrusion at Z " << tower_z << ", printed up to Z " << printed_z);
|
||||
CHECK(tower_z < printed_z - EPSILON);
|
||||
}
|
||||
}
|
||||
@@ -303,6 +303,15 @@ TEST_CASE("Flush-volume warning predicate respects used filament transitions", "
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Enum list options copied from the print config defaults read and write their names", "[Config]")
|
||||
{
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
// z_hop_types defaults to Slope Lift.
|
||||
CHECK(config.opt_serialize("z_hop_types") == "Slope Lift");
|
||||
config.set_deserialize_strict("z_hop_types", "Normal Lift");
|
||||
CHECK(config.opt_serialize("z_hop_types") == "Normal Lift");
|
||||
}
|
||||
|
||||
// TODO: https://github.com/SoftFever/OrcaSlicer/issues/11269 - Is this test still relevant? Delete if not.
|
||||
// It was failing so at least "nozzle_type" and "extruder_printable_area" could not be serialized
|
||||
// and an exception was thrown, but "nozzle_type" has been around for at least 3 months now.
|
||||
@@ -1886,3 +1895,30 @@ TEST_CASE("Every listed filament override is nullable", "[Config]")
|
||||
CHECK(def.nullable);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Entries of a list applied by index onto an empty list are copied", "[Config][Regression]")
|
||||
{
|
||||
const std::vector<std::string> ids = GENERATE(std::vector<std::string>{"GFA00"}, std::vector<std::string>{"GFA00", "GFA01"});
|
||||
DynamicPrintConfig edited;
|
||||
edited.set_key_value("filament_ids", new ConfigOptionStrings(ids));
|
||||
std::vector<std::string> keys;
|
||||
for (size_t i = 0; i < ids.size(); ++i)
|
||||
keys.push_back("filament_ids#" + std::to_string(i));
|
||||
|
||||
DynamicPrintConfig saved;
|
||||
saved.set_key_value("filament_ids", new ConfigOptionStrings());
|
||||
saved.apply_only(edited, keys);
|
||||
CHECK(saved.option<ConfigOptionStrings>("filament_ids")->values == ids);
|
||||
}
|
||||
|
||||
TEST_CASE("An empty list applied by index replaces the target list", "[Config][Regression]")
|
||||
{
|
||||
DynamicPrintConfig saved;
|
||||
saved.set_key_value("filament_ids", new ConfigOptionStrings());
|
||||
DynamicPrintConfig edited;
|
||||
SECTION("target has entries") { edited.set_key_value("filament_ids", new ConfigOptionStrings({"GFA00"})); }
|
||||
SECTION("target lacks the option") {}
|
||||
|
||||
edited.apply_only(saved, {"filament_ids#0"});
|
||||
CHECK(edited.option<ConfigOptionStrings>("filament_ids")->values.empty());
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <libslic3r/BoundingBox.hpp>
|
||||
#include <libslic3r/Config.hpp>
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -577,3 +579,85 @@ TEST_CASE("an aggregated gantry raises its collision strip from the zone it pain
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("a plate's IMEX layout key changes with each input of its zones and ghosts", "[IMEXZones]")
|
||||
{
|
||||
PrinterCfg p;
|
||||
p.active_tools = "0:P,1:M";
|
||||
DynamicPrintConfig cfg = make_cfg(p);
|
||||
cfg.set_key_value("imex_firmware_managed_zones", new ConfigOptionBool(false));
|
||||
std::string mode = kMode;
|
||||
const DynamicPrintConfig* cfg_ptr = &cfg;
|
||||
|
||||
std::optional<ImexLayoutKey> key;
|
||||
REQUIRE(update_imex_layout_key(key, cfg_ptr, mode));
|
||||
REQUIRE_FALSE(update_imex_layout_key(key, cfg_ptr, mode));
|
||||
|
||||
SECTION("imex_gantry_count") { cfg.set_key_value("imex_gantry_count", new ConfigOptionInt(2)); }
|
||||
SECTION("imex_tools_per_gantry") { cfg.set_key_value("imex_tools_per_gantry", new ConfigOptionInt(3)); }
|
||||
SECTION("imex_tool_layout")
|
||||
{
|
||||
cfg.set_deserialize_strict("imex_tool_layout", ConfigOptionEnum<ImexToolLayout>(ImexToolLayout::RearRight).serialize());
|
||||
}
|
||||
// Clearances and the margin are compared exactly, so even 0.05 mm counts.
|
||||
SECTION("imex_nozzle_clearance_x") { cfg.set_key_value("imex_nozzle_clearance_x", new ConfigOptionFloat(0.05)); }
|
||||
SECTION("imex_nozzle_clearance_y") { cfg.set_key_value("imex_nozzle_clearance_y", new ConfigOptionFloat(0.05)); }
|
||||
SECTION("imex_carriage_margin") { cfg.set_key_value("imex_carriage_margin", new ConfigOptionFloat(0.05)); }
|
||||
SECTION("imex_firmware_managed_zones") { cfg.set_key_value("imex_firmware_managed_zones", new ConfigOptionBool(true)); }
|
||||
SECTION("the plate's mode") { mode = kImexPrimaryMode; }
|
||||
SECTION("the printer config going away") { cfg_ptr = nullptr; }
|
||||
SECTION("the mode's roster, under the same name") { cfg.option<ConfigOptionStrings>("imex_mode_active_tools")->values[1] = "0:P,1:C"; }
|
||||
// The plate's mode no longer names a row, so it has no zones.
|
||||
SECTION("the mode's name in the table") { cfg.option<ConfigOptionStrings>("imex_mode_names")->values[1] = "renamed"; }
|
||||
SECTION("another mode in the table")
|
||||
{
|
||||
cfg.option<ConfigOptionStrings>("imex_mode_names")->values.emplace_back("other");
|
||||
cfg.option<ConfigOptionStrings>("imex_mode_active_tools")->values.emplace_back("0:P,1:C");
|
||||
}
|
||||
|
||||
CHECK(update_imex_layout_key(key, cfg_ptr, mode));
|
||||
CHECK_FALSE(update_imex_layout_key(key, cfg_ptr, mode));
|
||||
}
|
||||
|
||||
TEST_CASE("a plate's IMEX layout key ignores a mode's G-code and settles on a NaN clearance", "[IMEXZones]")
|
||||
{
|
||||
PrinterCfg p;
|
||||
p.active_tools = "0:P,1:M";
|
||||
DynamicPrintConfig cfg = make_cfg(p);
|
||||
cfg.set_key_value("imex_mode_gcodes", new ConfigOptionStrings(std::vector<std::string>{ std::string(), "M400" }));
|
||||
|
||||
std::optional<ImexLayoutKey> key;
|
||||
REQUIRE(update_imex_layout_key(key, &cfg, kMode));
|
||||
|
||||
SECTION("a mode's G-code, which moves no zone")
|
||||
{
|
||||
cfg.option<ConfigOptionStrings>("imex_mode_gcodes")->values[1] = "G28";
|
||||
CHECK_FALSE(update_imex_layout_key(key, &cfg, kMode));
|
||||
}
|
||||
// A clearance field accepts "nan". Setting it changes the key once, then the key holds still.
|
||||
SECTION("a NaN clearance")
|
||||
{
|
||||
cfg.set_key_value("imex_nozzle_clearance_x", new ConfigOptionFloat(std::nan("")));
|
||||
CHECK(update_imex_layout_key(key, &cfg, kMode));
|
||||
CHECK_FALSE(update_imex_layout_key(key, &cfg, kMode));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("a plate's IMEX layout key ignores the IMEX inputs while IMEX is off", "[IMEXZones]")
|
||||
{
|
||||
PrinterCfg p;
|
||||
p.is_imex = false;
|
||||
p.active_tools = "0:P,1:M";
|
||||
DynamicPrintConfig cfg = make_cfg(p);
|
||||
|
||||
std::optional<ImexLayoutKey> key;
|
||||
REQUIRE(update_imex_layout_key(key, &cfg, kMode));
|
||||
cfg.set_key_value("imex_nozzle_clearance_x", new ConfigOptionFloat(5.0));
|
||||
cfg.option<ConfigOptionStrings>("imex_mode_active_tools")->values[1] = "0:P,1:C";
|
||||
CHECK_FALSE(update_imex_layout_key(key, &cfg, "other"));
|
||||
// No printer config at all reads the same as IMEX off.
|
||||
CHECK_FALSE(update_imex_layout_key(key, nullptr, kMode));
|
||||
|
||||
cfg.set_key_value("is_imex", new ConfigOptionBool(true));
|
||||
CHECK(update_imex_layout_key(key, &cfg, kMode));
|
||||
}
|
||||
@@ -6959,8 +6959,9 @@ struct ScopedResourcesDir
|
||||
~ScopedResourcesDir() { set_resources_dir(previous); }
|
||||
};
|
||||
|
||||
// An "Acme" vendor under root whose "Acme Printer" inherits extruder_clearance_dist_to_rod from an
|
||||
// abstract base, with the printer in a nested sub_path so the name cannot be derived from the file.
|
||||
// An "Acme" vendor under root whose "Acme Printer", formerly "Acme Classic", inherits
|
||||
// extruder_clearance_dist_to_rod from an abstract base, with the printer in a nested sub_path so the
|
||||
// name cannot be derived from the file.
|
||||
void write_acme_printer_vendor(const fs::path &root, double dist_to_rod)
|
||||
{
|
||||
const fs::path machine_dir = root / "Acme" / "machine";
|
||||
@@ -6976,8 +6977,8 @@ void write_acme_printer_vendor(const fs::path &root, double dist_to_rod)
|
||||
<< R"({"type":"machine","name":"fdm_acme_common","from":"system","instantiation":"false",)"
|
||||
<< R"("extruder_clearance_dist_to_rod":")" << dist_to_rod << R"("})";
|
||||
std::ofstream((machine_dir / "nested" / "printer.json").string())
|
||||
<< R"({"type":"machine","name":"Acme Printer","from":"system","instantiation":"true","inherits":"fdm_acme_common",)"
|
||||
<< R"("printer_model":"Acme One","printer_variant":"0.4"})";
|
||||
<< R"({"type":"machine","name":"Acme Printer","renamed_from":"Acme Classic","from":"system","instantiation":"true",)"
|
||||
<< R"("inherits":"fdm_acme_common","printer_model":"Acme One","printer_variant":"0.4"})";
|
||||
}
|
||||
|
||||
std::string read_file(const fs::path &file)
|
||||
@@ -7960,6 +7961,35 @@ TEST_CASE("A system preset resolves from a vendor shipped as its preset cache al
|
||||
CHECK_THAT(config.opt_float("extruder_clearance_dist_to_rod"), Catch::Matchers::WithinAbs(33., 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("A system preset resolves by a name it was renamed from", "[Preset][Bundle]")
|
||||
{
|
||||
ScopedTemporaryDir temp_dir;
|
||||
ScopedDataDir data(temp_dir.path() / "data");
|
||||
ScopedResourcesDir resources(temp_dir.path() / "resources");
|
||||
const fs::path profiles = temp_dir.path() / "resources" / "profiles";
|
||||
write_acme_printer_vendor(profiles, 33.);
|
||||
|
||||
SECTION("from the profile JSONs") {}
|
||||
SECTION("from a vendor shipped as its preset cache alone") {
|
||||
PresetBundle writer;
|
||||
writer.set_generate_vendor_caches(true);
|
||||
writer.load_vendor_configs_from_json(profiles.string(), "Acme", PresetBundle::LoadSystem,
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent);
|
||||
REQUIRE(fs::exists(profiles / "Acme.opc"));
|
||||
fs::remove(profiles / "Acme.json");
|
||||
fs::remove_all(profiles / "Acme");
|
||||
}
|
||||
|
||||
CHECK(PresetBundle::find_preset_vendor("Acme Classic", Preset::TYPE_PRINTER) == "Acme");
|
||||
PresetBundle bundle;
|
||||
DynamicPrintConfig config;
|
||||
std::string error;
|
||||
REQUIRE(bundle.resolve_system_preset(config, Preset::TYPE_PRINTER, "Acme Classic",
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(config.opt_string("printer_model") == "Acme One");
|
||||
CHECK_THAT(config.opt_float("extruder_clearance_dist_to_rod"), Catch::Matchers::WithinAbs(33., 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("A system preset no vendor lists is not resolved", "[Preset][Bundle]")
|
||||
{
|
||||
ScopedTemporaryDir temp_dir;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include <catch2/catch_message.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include "libslic3r/Preset.hpp"
|
||||
@@ -10,6 +11,7 @@
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
@@ -56,3 +58,48 @@ TEST_CASE("deep_diff distinguishes absolute and percentage speeds for each varia
|
||||
transferred.apply_only(edited.config, diff);
|
||||
REQUIRE(*transferred.option("small_perimeter_speed") == *edited.config.option("small_perimeter_speed"));
|
||||
}
|
||||
|
||||
TEST_CASE("deep_diff reports a serialized list as one option that transfers and reverts whole", "[PresetDiff][Config]")
|
||||
{
|
||||
std::vector<std::string> serialized_keys;
|
||||
for (const auto &[key, def] : print_config_def.options)
|
||||
if (def.gui_flags == "serialized")
|
||||
serialized_keys.push_back(key);
|
||||
REQUIRE(std::find(serialized_keys.begin(), serialized_keys.end(), "post_process") != serialized_keys.end());
|
||||
|
||||
using Values = std::vector<std::string>;
|
||||
const auto [saved_values, edited_values] = GENERATE(std::make_pair(Values{}, Values{"a"}),
|
||||
std::make_pair(Values{"b", "c"}, Values{"a"}),
|
||||
std::make_pair(Values{"a", "b"}, Values{"a"}));
|
||||
for (const std::string &key : serialized_keys) {
|
||||
INFO(key);
|
||||
Preset reference(Preset::TYPE_PRINT, "ref");
|
||||
reference.config.set_key_value(key, new ConfigOptionStrings(saved_values));
|
||||
Preset edited = reference;
|
||||
edited.config.option<ConfigOptionStrings>(key)->values = edited_values;
|
||||
|
||||
const std::vector<std::string> expected{key};
|
||||
const auto diff = PresetCollection::dirty_options(&edited, &reference, /*deep_compare=*/true);
|
||||
CHECK(diff == expected);
|
||||
if (diff != expected)
|
||||
continue;
|
||||
|
||||
DynamicPrintConfig transferred = reference.config;
|
||||
transferred.apply_only(edited.config, diff);
|
||||
CHECK(transferred.option<ConfigOptionStrings>(key)->values == edited_values);
|
||||
|
||||
DynamicPrintConfig reverted = edited.config;
|
||||
reverted.apply_only(reference.config, diff);
|
||||
CHECK(reverted.option<ConfigOptionStrings>(key)->values == saved_values);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("deep_diff reports a serialized list that only one preset has as one option", "[PresetDiff][Config]")
|
||||
{
|
||||
Preset reference(Preset::TYPE_PRINT, "ref");
|
||||
Preset edited(Preset::TYPE_PRINT, "edited");
|
||||
edited.config.set_key_value("post_process", new ConfigOptionStrings({"a", "b"}));
|
||||
|
||||
const auto diff = PresetCollection::dirty_options(&edited, &reference, /*deep_compare=*/true);
|
||||
CHECK(diff == std::vector<std::string>{"post_process"});
|
||||
}
|
||||
@@ -38,3 +38,21 @@ TEST_CASE("An enum value outside the label list reads as undefined", "[ConfigVal
|
||||
|
||||
CHECK(get_string_value(key + "#0", config) == "Undefined");
|
||||
}
|
||||
|
||||
TEST_CASE("A serialized list read without an index reads as the settings tab shows it", "[ConfigValueFormatter]")
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value("post_process", new ConfigOptionStrings({"a.ps1", "b.ps1"}));
|
||||
config.set_key_value("small_area_infill_flow_compensation_model", new ConfigOptionStrings({"0,0", "\n0.2,0.4444"}));
|
||||
|
||||
CHECK(get_string_value("post_process", config).utf8_string() == "a.ps1;b.ps1;");
|
||||
CHECK(get_string_value("small_area_infill_flow_compensation_model", config).utf8_string() == "0,0;\n0.2,0.4444;");
|
||||
}
|
||||
|
||||
TEST_CASE("A string list that is not serialized reads its first entry without an index", "[ConfigValueFormatter]")
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value("filament_ids", new ConfigOptionStrings({"GFA00", "GFA01"}));
|
||||
|
||||
CHECK(get_string_value("filament_ids", config).utf8_string() == "GFA00");
|
||||
}
|
||||
@@ -6,10 +6,14 @@
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <ios>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
@@ -35,11 +39,21 @@
|
||||
#include <boost/beast/websocket/rfc6455.hpp>
|
||||
#include <boost/beast/websocket/ssl.hpp>
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
#include <boost/filesystem/directory.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/nowide/convert.hpp>
|
||||
#include <boost/nowide/cstdlib.hpp>
|
||||
#include <miniz.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "libslic3r/miniz_extension.hpp"
|
||||
#include "slic3r/GUI/DeviceCore/DevStorage.h"
|
||||
#include "slic3r/Utils/IPrinterAgent.hpp"
|
||||
#include "slic3r/Utils/MoonrakerPrinterAgent.hpp"
|
||||
#include "slic3r/Utils/bambu_networking.hpp"
|
||||
#include "test_utils.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
@@ -242,6 +256,20 @@ public:
|
||||
m_disk_usage = std::move(disk_usage);
|
||||
}
|
||||
|
||||
// The multipart body of the last file upload.
|
||||
std::string upload()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_upload;
|
||||
}
|
||||
|
||||
// The last G-code script sent to the printer.
|
||||
std::string script()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_script;
|
||||
}
|
||||
|
||||
// Hangs up every connection that is waiting.
|
||||
void release()
|
||||
{
|
||||
@@ -369,6 +397,17 @@ private:
|
||||
}
|
||||
response.result(http::status::ok);
|
||||
response.body() = nlohmann::json{{"result", result}}.dump();
|
||||
} else if (request.target() == "/server/files/upload") {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_upload = request.body();
|
||||
response.result(http::status::created);
|
||||
response.body() = "{}";
|
||||
} else if (request.target() == "/printer/gcode/script") {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
const nlohmann::json body = nlohmann::json::parse(request.body(), nullptr, false);
|
||||
m_script = body.is_object() ? body.value("script", "") : "";
|
||||
response.result(http::status::ok);
|
||||
response.body() = R"({"result": "ok"})";
|
||||
}
|
||||
response.prepare_payload();
|
||||
beast::error_code ec;
|
||||
@@ -454,6 +493,8 @@ private:
|
||||
int m_close_frames = 0;
|
||||
bool m_released = false;
|
||||
nlohmann::json m_disk_usage = {{"total", 8e9}, {"used", 2e9}, {"free", 6e9}};
|
||||
std::string m_upload;
|
||||
std::string m_script;
|
||||
};
|
||||
|
||||
// Records when the agent dispatches a status report.
|
||||
@@ -527,6 +568,69 @@ template<class Agent> bool destroys_within(std::unique_ptr<Agent>& agent, std::c
|
||||
return destroyed.wait_for(limit) == std::future_status::ready;
|
||||
}
|
||||
|
||||
// Uploads to a printer without connecting to it, and records the file it is told to print.
|
||||
class UploadAgent : public MoonrakerPrinterAgent
|
||||
{
|
||||
public:
|
||||
explicit UploadAgent(const FakePrinter& printer) : MoonrakerPrinterAgent("") { device_info.base_url = printer.base_url(); }
|
||||
std::string printed;
|
||||
bool takes_3mf = false;
|
||||
|
||||
protected:
|
||||
bool accepts_3mf() const override { return takes_3mf; }
|
||||
|
||||
bool print_uploaded_file(const PrintParams& params, const std::string& filename) override
|
||||
{
|
||||
printed = filename;
|
||||
return MoonrakerPrinterAgent::print_uploaded_file(params, filename);
|
||||
}
|
||||
};
|
||||
|
||||
// Writes a .gcode.3mf holding one line of G-code for each of the given plate numbers.
|
||||
void write_bundle(const std::string& path, const std::vector<std::string>& plates)
|
||||
{
|
||||
mz_zip_archive zip;
|
||||
mz_zip_zero_struct(&zip);
|
||||
REQUIRE(open_zip_writer(&zip, path));
|
||||
for (const std::string& plate : plates) {
|
||||
const std::string gcode = "; plate " + plate + "\n";
|
||||
REQUIRE(mz_zip_writer_add_mem(&zip, ("Metadata/plate_" + plate + ".gcode").c_str(), gcode.data(), gcode.size(), MZ_DEFAULT_COMPRESSION));
|
||||
}
|
||||
REQUIRE(mz_zip_writer_finalize_archive(&zip));
|
||||
REQUIRE(close_zip_writer(&zip));
|
||||
}
|
||||
|
||||
// Makes a fresh directory the system temp folder for its lifetime, so a test sees only what the agent leaves there.
|
||||
class ScopedSystemTemp : public ScopedTemporaryDir
|
||||
{
|
||||
public:
|
||||
ScopedSystemTemp() : ScopedTemporaryDir("moonraker-temp")
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const std::string dir = boost::nowide::narrow(path().wstring());
|
||||
#else
|
||||
const std::string dir = string();
|
||||
#endif
|
||||
for (const char* name : {"TMP", "TEMP", "TMPDIR"}) {
|
||||
const char* value = boost::nowide::getenv(name);
|
||||
m_saved.emplace_back(name, value ? std::optional<std::string>(value) : std::nullopt);
|
||||
boost::nowide::setenv(name, dir.c_str(), 1);
|
||||
}
|
||||
}
|
||||
~ScopedSystemTemp()
|
||||
{
|
||||
for (const auto& [name, value] : m_saved) {
|
||||
if (value)
|
||||
boost::nowide::setenv(name.c_str(), value->c_str(), 1);
|
||||
else
|
||||
boost::nowide::unsetenv(name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::string, std::optional<std::string>>> m_saved;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Moonraker discovery waits for a complete device identity", "[MoonrakerPrinterAgent][Discovery]")
|
||||
@@ -837,3 +941,144 @@ TEST_CASE("Destroying the agent does not wait out a connection retry's delay", "
|
||||
|
||||
CHECK(destroys_within(agent, 1s));
|
||||
}
|
||||
|
||||
TEST_CASE("A .gcode.3mf goes to the printer as the printed plate's G-code unless the printer takes 3MF", "[MoonrakerPrinterAgent][Upload]")
|
||||
{
|
||||
const bool takes_3mf = GENERATE(false, true);
|
||||
CAPTURE(takes_3mf);
|
||||
const std::string name = takes_3mf ? "Cube.gcode.3mf" : "Cube.gcode";
|
||||
|
||||
ScopedTemporaryDir dir("moonraker-upload");
|
||||
const std::string bundle = (dir.path() / ".1234.0.3mf").string();
|
||||
write_bundle(bundle, {"1", "2"});
|
||||
ScopedSystemTemp temp;
|
||||
REQUIRE(boost::filesystem::equivalent(boost::filesystem::temp_directory_path(), temp.path()));
|
||||
|
||||
FakePrinter printer(Behavior::AnswersPings);
|
||||
UploadAgent agent(printer);
|
||||
agent.takes_3mf = takes_3mf;
|
||||
PrintParams params{};
|
||||
params.filename = bundle;
|
||||
params.plate_index = 2;
|
||||
|
||||
SECTION("Print plate")
|
||||
{
|
||||
params.project_name = "Cube";
|
||||
REQUIRE(agent.start_local_print(params, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
|
||||
CHECK(agent.printed == name);
|
||||
}
|
||||
SECTION("Send to printer")
|
||||
{
|
||||
params.project_name = "Cube.gcode.3mf";
|
||||
REQUIRE(agent.start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
|
||||
CHECK(agent.printed.empty());
|
||||
}
|
||||
|
||||
const std::string upload = printer.upload();
|
||||
CHECK(upload.find("filename=\"" + name + "\"") != std::string::npos);
|
||||
if (takes_3mf) {
|
||||
CHECK(upload.find("PK\x03\x04") != std::string::npos);
|
||||
} else {
|
||||
CHECK(upload.find("; plate 2") != std::string::npos);
|
||||
CHECK(upload.find("; plate 1") == std::string::npos);
|
||||
}
|
||||
// Neither the source folder nor the temp folder keeps an extracted copy
|
||||
CHECK(std::distance(boost::filesystem::directory_iterator(dir.path()), boost::filesystem::directory_iterator()) == 1);
|
||||
CHECK(boost::filesystem::is_empty(temp.path()));
|
||||
}
|
||||
|
||||
TEST_CASE("A bundle without the printed plate's G-code is uploaded only when it holds a single plate", "[MoonrakerPrinterAgent][Upload]")
|
||||
{
|
||||
auto [plates, uploaded] = GENERATE(table<std::vector<std::string>, bool>({
|
||||
{{"1"}, true},
|
||||
{{"1", "3"}, false},
|
||||
}));
|
||||
CAPTURE(plates.size());
|
||||
|
||||
ScopedTemporaryDir dir("moonraker-upload");
|
||||
const std::string bundle = (dir.path() / ".1234.0.3mf").string();
|
||||
write_bundle(bundle, plates);
|
||||
|
||||
FakePrinter printer(Behavior::AnswersPings);
|
||||
UploadAgent agent(printer);
|
||||
PrintParams params{};
|
||||
params.filename = bundle;
|
||||
params.plate_index = 2;
|
||||
params.project_name = "Cube";
|
||||
|
||||
const int result = agent.start_local_print(params, nullptr, nullptr);
|
||||
CHECK((result == BAMBU_NETWORK_SUCCESS) == uploaded);
|
||||
CHECK((printer.upload().find("; plate 1") != std::string::npos) == uploaded);
|
||||
}
|
||||
|
||||
TEST_CASE("The job name reaches the print start as a file name the printer can store and list", "[MoonrakerPrinterAgent][Upload]")
|
||||
{
|
||||
// A long name is cut to fit 255 bytes with room for .gcode.3mf, at a whole 2-byte character
|
||||
std::string long_name;
|
||||
for (int i = 0; i < 150; ++i)
|
||||
long_name += "\xC3\xA9";
|
||||
const std::size_t max_stem = 255 - std::strlen(".gcode.3mf");
|
||||
const std::string cut_long_name = long_name.substr(0, max_stem - max_stem % 2);
|
||||
|
||||
auto [job_name, file_name] = GENERATE_COPY(table<std::string, std::string>({
|
||||
{"Cable clip #2; v\"3\"*", "Cable clip _2_ v_3__.gcode"},
|
||||
{"Bracket 1/2", "Bracket 1_2.gcode"},
|
||||
{"A: frame", "A: frame.gcode"},
|
||||
{"Bob's", "Bob's.gcode"},
|
||||
{"Bob's \"best\" frame (v2) [final] {\xC3\xA9} <x> |y| ?!&%$@=+,~`", "Bob's _best_ frame (v2) [final] {\xC3\xA9} <x> |y| ?!&%$@=+,~`.gcode"},
|
||||
{"x\nM104 S300", "x_M104 S300.gcode"},
|
||||
{" .Cube", "Cube.gcode"},
|
||||
{"", "1234.0.gcode"},
|
||||
{long_name, cut_long_name + ".gcode"},
|
||||
}));
|
||||
CAPTURE(job_name);
|
||||
|
||||
ScopedTemporaryDir dir("moonraker-upload");
|
||||
const std::string bundle = (dir.path() / ".1234.0.3mf").string();
|
||||
write_bundle(bundle, {"1"});
|
||||
|
||||
FakePrinter printer(Behavior::AnswersPings);
|
||||
UploadAgent agent(printer);
|
||||
PrintParams params{};
|
||||
params.filename = bundle;
|
||||
params.plate_index = 1;
|
||||
params.project_name = job_name;
|
||||
|
||||
REQUIRE(agent.start_local_print(params, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
|
||||
CHECK(printer.upload().find("filename=\"" + file_name + "\"") != std::string::npos);
|
||||
CHECK(printer.script() == "SDCARD_PRINT_FILE FILENAME=\"" + file_name + "\"");
|
||||
}
|
||||
|
||||
TEST_CASE("A file that is not a 3MF is uploaded as it is, named after the job when there is one", "[MoonrakerPrinterAgent][Upload]")
|
||||
{
|
||||
auto [job_name, file_name] = GENERATE(table<std::string, std::string>({
|
||||
{"Cube", "Cube.gcode"},
|
||||
{"", "part.gcode"},
|
||||
}));
|
||||
CAPTURE(job_name);
|
||||
|
||||
ScopedTemporaryDir dir("moonraker-upload");
|
||||
const boost::filesystem::path gcode = dir.path() / "part.gcode";
|
||||
boost::filesystem::ofstream(gcode, std::ios::binary) << "; plain G-code\n";
|
||||
|
||||
FakePrinter printer(Behavior::AnswersPings);
|
||||
UploadAgent agent(printer);
|
||||
PrintParams params{};
|
||||
params.filename = gcode.string();
|
||||
params.project_name = job_name;
|
||||
|
||||
SECTION("Print plate")
|
||||
{
|
||||
REQUIRE(agent.start_local_print(params, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
|
||||
CHECK(agent.printed == file_name);
|
||||
}
|
||||
SECTION("Send to printer")
|
||||
{
|
||||
REQUIRE(agent.start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
|
||||
}
|
||||
|
||||
const std::string upload = printer.upload();
|
||||
CHECK(upload.find("filename=\"" + file_name + "\"") != std::string::npos);
|
||||
CHECK(upload.find("; plain G-code") != std::string::npos);
|
||||
CHECK(std::distance(boost::filesystem::directory_iterator(dir.path()), boost::filesystem::directory_iterator()) == 1);
|
||||
}
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "slic3r/Utils/QidiPrinterAgent.hpp"
|
||||
#include "slic3r/Utils/bambu_networking.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
@@ -46,3 +49,13 @@ TEST_CASE("Filaments past the firmware's last tool variable are skipped", "[Qidi
|
||||
|
||||
CHECK(QidiPrinterAgent::build_tool_slot_script(mapping) == "SAVE_VARIABLE VARIABLE=value_t15 VALUE=\"'slot1'\"");
|
||||
}
|
||||
|
||||
TEST_CASE("The print start of a 3MF names the plate to print", "[QidiPrinterAgent]")
|
||||
{
|
||||
PrintParams params;
|
||||
params.plate_index = 2;
|
||||
|
||||
CHECK(QidiPrinterAgent::print_start_request(params, "Cube.gcode.3mf") ==
|
||||
nlohmann::json{{"filename", "Cube.gcode.3mf"}, {"plateindex", "2"}});
|
||||
CHECK(QidiPrinterAgent::print_start_request(params, "Cube.gcode") == nlohmann::json{{"filename", "Cube.gcode"}});
|
||||
}
|
||||
Reference in new issue
Block a user