mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-22 08:22:58 +00:00
Resync the DeviceCore state models
This commit is contained in:
@@ -1,16 +1,41 @@
|
||||
#include "DevConfigUtil.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#include <wx/dir.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include "../I18N.hpp"
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
|
||||
// Translation markers for xgettext extraction.
|
||||
// These strings are configured in printers/*.json (tool_head_display_names)
|
||||
// and passed to _L() at runtime. xgettext cannot scan dynamic strings,
|
||||
// so we mark them here with L() for extraction into .pot file.
|
||||
// This block is never executed at runtime.
|
||||
static void _toolhead_translation_markers()
|
||||
{
|
||||
// Dynamic toolhead display names from JSON config — xgettext cannot scan these
|
||||
L("Main Extruder"); L("Main extruder"); L("main extruder");
|
||||
L("Auxiliary Extruder"); L("Auxiliary extruder"); L("auxiliary extruder");
|
||||
L("Left Extruder"); L("Left extruder"); L("left extruder");
|
||||
L("Right Extruder"); L("Right extruder"); L("right extruder");
|
||||
L("Main Nozzle"); L("Main nozzle"); L("main nozzle");
|
||||
L("Auxiliary Nozzle"); L("Auxiliary nozzle"); L("auxiliary nozzle");
|
||||
L("Left Nozzle"); L("Left nozzle"); L("left nozzle");
|
||||
L("Right Nozzle"); L("Right nozzle"); L("right nozzle");
|
||||
L("Main Hotend"); L("Main hotend"); L("main hotend");
|
||||
L("Auxiliary Hotend"); L("Auxiliary hotend"); L("auxiliary hotend");
|
||||
L("Left Hotend"); L("Left hotend"); L("left hotend");
|
||||
L("Right Hotend"); L("Right hotend"); L("right hotend");
|
||||
// standalone position words (short_name=true runtime results)
|
||||
L("main"); L("auxiliary");
|
||||
L("Main"); L("Auxiliary");
|
||||
L("left"); L("right");
|
||||
L("Left"); L("Right");
|
||||
}
|
||||
|
||||
std::string DevPrinterConfigUtil::m_resource_file_path = "";
|
||||
|
||||
|
||||
@@ -36,8 +61,6 @@ std::map<std::string, std::string> DevPrinterConfigUtil::get_all_model_id_with_n
|
||||
|
||||
for (wxString file : m_files)
|
||||
{
|
||||
if (!file.Lower().ends_with(".json")) continue;
|
||||
|
||||
std::string config_file = m_resource_file_path + "/printers/" + file.ToStdString();
|
||||
boost::nowide::ifstream json_file(config_file.c_str());
|
||||
|
||||
@@ -91,7 +114,7 @@ std::string DevPrinterConfigUtil::get_filament_load_img(const std::string &type_
|
||||
{
|
||||
if (has_nozzle_rack)
|
||||
{
|
||||
const auto &rack_vec = get_value_from_config<std::vector<std::string>>(type_str, "filament_load_image_nozzle_rack");
|
||||
const auto &rack_vec = get_value_from_config<std::vector<std::string>>(type_str, "filament_load_image_nozzle_rack") ;
|
||||
if (!rack_vec.empty())
|
||||
{
|
||||
if (ext_id >= 0 && static_cast<size_t>(ext_id) < rack_vec.size())
|
||||
@@ -111,7 +134,6 @@ std::string DevPrinterConfigUtil::get_filament_load_img(const std::string &type_
|
||||
|
||||
std::string DevPrinterConfigUtil::get_fan_text(const std::string& type_str, const std::string& key)
|
||||
{
|
||||
std::vector<std::string> filaments;
|
||||
std::string config_file = m_resource_file_path + "/printers/" + type_str + ".json";
|
||||
boost::nowide::ifstream json_file(config_file.c_str());
|
||||
try
|
||||
@@ -134,6 +156,25 @@ std::string DevPrinterConfigUtil::get_fan_text(const std::string& type_str, cons
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<std::string> DevPrinterConfigUtil::get_fan_text_params(const std::string& type_str, const std::string& key)
|
||||
{
|
||||
std::string config_file = m_resource_file_path + "/printers/" + type_str + ".json";
|
||||
boost::nowide::ifstream json_file(config_file.c_str());
|
||||
try {
|
||||
json jj;
|
||||
if (json_file.is_open()) {
|
||||
json_file >> jj;
|
||||
if (jj.contains("00.00.00.00")) {
|
||||
json const& printer = jj["00.00.00.00"];
|
||||
if (printer.contains("fan") && printer["fan"].contains(key)) {
|
||||
return printer["fan"][key].get<std::vector<std::string>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (...) {}
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::string DevPrinterConfigUtil::get_fan_text(const std::string& type_str, int airduct_mode, int airduct_func, int submode)
|
||||
{
|
||||
std::vector<std::string> filaments;
|
||||
@@ -181,6 +222,36 @@ std::string DevPrinterConfigUtil::get_fan_text(const std::string& type_str, int
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string DevPrinterConfigUtil::get_fan_mode_text(const std::string& type_str, int airduct_mode, const std::string& key)
|
||||
{
|
||||
std::vector<std::string> filaments;
|
||||
std::string config_file = m_resource_file_path + "/printers/" + type_str + ".json";
|
||||
boost::nowide::ifstream json_file(config_file.c_str());
|
||||
try {
|
||||
json jj;
|
||||
if (json_file.is_open()) {
|
||||
json_file >> jj;
|
||||
if (jj.contains("00.00.00.00")) {
|
||||
json const& printer = jj["00.00.00.00"];
|
||||
if (!printer.contains("fan")) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
json const& fan_item = printer["fan"];
|
||||
const auto& airduct_mode_str = std::to_string(airduct_mode);
|
||||
if (!fan_item.contains(airduct_mode_str)) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (fan_item[airduct_mode_str].contains(key)) {
|
||||
return fan_item[airduct_mode_str][key].get<std::string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (...) {}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<std::string>> DevPrinterConfigUtil::get_all_subseries(std::string type_str)
|
||||
{
|
||||
std::map<std::string, std::vector<std::string>> subseries;
|
||||
@@ -284,36 +355,45 @@ std::string DevPrinterConfigUtil::get_toolhead_display_name(
|
||||
{ ToolHeadComponent::Hotend, "hotend" }
|
||||
};
|
||||
|
||||
const int case_index = static_cast<int>(name_case);
|
||||
const std::string role_key = std::to_string(ext_id);
|
||||
int case_index = static_cast<int>(name_case); // 0, 1, 2
|
||||
|
||||
// Try to read from printer config json
|
||||
auto names_json = get_value_from_config<json>(type_str, "tool_head_display_names");
|
||||
std::string role_key = std::to_string(ext_id); // "0" or "1"
|
||||
const std::string& comp_key = comp_keys.at(component);
|
||||
|
||||
std::string result;
|
||||
auto names_json = get_value_from_config<json>(type_str, "tool_head_display_names");
|
||||
if (!names_json.is_null() && names_json.contains(role_key) && names_json[role_key].contains(comp_key)) {
|
||||
|
||||
if (!names_json.is_null()
|
||||
&& names_json.contains(role_key)
|
||||
&& names_json[role_key].contains(comp_key))
|
||||
{
|
||||
auto& arr = names_json[role_key][comp_key];
|
||||
if (arr.is_array() && case_index < static_cast<int>(arr.size()))
|
||||
if (arr.is_array() && case_index < static_cast<int>(arr.size())) {
|
||||
result = arr[case_index].get<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: all dual-extruder printers should have tool_head_display_names configured.
|
||||
// This is a safety net only — return a generic name.
|
||||
if (result.empty()) {
|
||||
const std::string side = ext_id == DEPUTY_EXTRUDER_ID ? "Left" : "Right";
|
||||
const std::string component_name = component == ToolHeadComponent::Extruder ? "Extruder" :
|
||||
component == ToolHeadComponent::Hotend ? "Hotend" : "Nozzle";
|
||||
result = side + " " + component_name;
|
||||
if (name_case == ToolHeadNameCase::SentenceCase && result.size() > side.size() + 1)
|
||||
result[side.size() + 1] = static_cast<char>(std::tolower(static_cast<unsigned char>(result[side.size() + 1])));
|
||||
else if (name_case == ToolHeadNameCase::LowerCase)
|
||||
std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||
static const std::map<ToolHeadComponent, std::string> fallback_names = {
|
||||
{ ToolHeadComponent::Extruder, "Extruder" },
|
||||
{ ToolHeadComponent::Nozzle, "Nozzle" },
|
||||
{ ToolHeadComponent::Hotend, "Hotend" }
|
||||
};
|
||||
result = fallback_names.at(component);
|
||||
}
|
||||
|
||||
// short_name: return only the role prefix (e.g. "Main" from "Main Nozzle")
|
||||
if (short_name) {
|
||||
auto sp = result.find(' ');
|
||||
if (sp != std::string::npos)
|
||||
if (sp != std::string::npos) {
|
||||
result = result.substr(0, sp);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user