Merge remote-tracking branch 'upstream/main' into dev/h2d

# Conflicts:
#	resources/profiles/BBL.json
#	src/slic3r/GUI/AmsMappingPopup.cpp
#	src/slic3r/GUI/MediaFilePanel.cpp
#	src/slic3r/GUI/Plater.cpp
#	src/slic3r/GUI/StatusPanel.cpp
This commit is contained in:
Noisyfox
2025-09-16 11:27:44 +08:00
6267 changed files with 210560 additions and 178856 deletions

View File

@@ -1578,4 +1578,91 @@ void load_string_file(const boost::filesystem::path& p, std::string& str)
file.read(&str[0], sz);
}
// pattern string supprt these pattern: "
// 1. 5#1, insert 1 solid layer every 5 layers. this can be simplified to 5
// 2."1,7,9", explicitly insert solid layer at layer 1, 7, 9
bool check_layer_id_pattern(const std::string& pattern, int layer_id){
if (pattern.empty() || layer_id < 0)
return false;
// layer_id is 0-based, so we need to add 1 to make it 1-based
layer_id++;
// Remove whitespace and surrounding quotes.
std::string p; p.reserve(pattern.size());
for (char c : pattern) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
continue;
p.push_back(c);
}
if (!p.empty() && (p.front() == '"' || p.front() == '\''))
p.erase(p.begin());
if (!p.empty() && (p.back() == '"' || p.back() == '\''))
p.pop_back();
if (p.empty())
return false;
// Explicit list form: "1,7,9" or with counts per entry: "5,9#2,18"
if (p.find(',') != std::string::npos) {
size_t start = 0;
while (start < p.size()) {
size_t end = p.find(',', start);
std::string token = p.substr(start, (end == std::string::npos) ? std::string::npos : end - start);
if (!token.empty()) {
try {
size_t hash_pos_token = token.find('#');
if (hash_pos_token == std::string::npos) {
int value = std::stoi(token);
if (value == layer_id)
return true;
} else {
int base_layer = std::stoi(token.substr(0, hash_pos_token));
std::string count_str = token.substr(hash_pos_token + 1);
int local_count = 1;
if (!count_str.empty())
local_count = std::stoi(count_str);
if (base_layer > 0 && local_count > 0) {
if (layer_id >= base_layer && layer_id < base_layer + local_count)
return true;
}
}
} catch (...) {
// Ignore invalid tokens
}
}
if (end == std::string::npos)
break;
start = end + 1;
}
return false;
}
// Interval form: "N#K" or simplified "N" (equals to N#1)
int interval = 0;
int count = 1;
size_t hash_pos = p.find('#');
try {
if (hash_pos == std::string::npos) {
interval = std::stoi(p);
} else {
interval = std::stoi(p.substr(0, hash_pos));
std::string count_str = p.substr(hash_pos + 1);
if (!count_str.empty())
count = std::stoi(count_str);
}
} catch (...) {
return false;
}
if (interval <= 0 || count <= 0)
return false;
// Layers are 1-based. Match layers interval, interval+1, ..., interval+count-1, then repeat every interval.
if (layer_id < interval)
return false;
int mod = layer_id % interval; // For multiples, mod == 0
return mod >= 0 && mod < count;
}
}; // namespace Slic3r