refactor(imex): route three inline tool-state parsers through parse_imex_active_tools

PartPlate::calc_imex_zones, GCodeViewer::render, and Plater::collect_imex_warnings
each hand-rolled their own "phys:P/C/M" tokenizer with subtly different error
handling. Replace the three inline loops with parse_imex_active_tools +
imex_primary_tool_for_mode so the Primary/Copy/Mirror classification agrees
across zones, the G-code viewer legend, and slice warnings.

No behavior change: the shared helpers preserve the 1=Primary / 2=Copy /
3=Mirror encoding already consumed downstream and continue to accept the
legacy bare-index form as Primary.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Clifford Garwood
2026-04-21 22:49:08 -04:00
co-authored by Claude Opus 4.7
parent 77c32a2e15
commit b2128cc330
3 changed files with 32 additions and 57 deletions
+4 -11
View File
@@ -9964,17 +9964,10 @@ static std::vector<wxString> collect_imex_warnings(PartPlate* plate)
if (i >= tools_opt->values.size() || mode_names_opt->values[i] != mode) continue;
const std::string& entry = tools_opt->values[i];
primary_tool = imex_primary_tool_for_mode(entry);
std::istringstream ss(entry);
std::string token;
while (std::getline(ss, token, ',')) {
token.erase(std::remove_if(token.begin(), token.end(), ::isspace), token.end());
if (token.empty()) continue;
// std::stoi parses the leading integer and ignores any ":P/:C/:M" suffix.
try {
int idx = std::stoi(token);
if (idx >= 0 && (max_tool == 0 || (size_t)idx < max_tool))
active_tools.push_back(idx);
} catch (...) {}
for (const auto& [phys_idx, role] : parse_imex_active_tools(entry)) {
(void)role;
if (phys_idx >= 0 && (max_tool == 0 || (size_t)phys_idx < max_tool))
active_tools.push_back(phys_idx);
}
break;
}