FIX: crash of filament group in cli mode
1. Add protection for building machine filaments.Sometimes we don't know the info about maahcine filament jira:NONE Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I3198d3a1a8825aa50aa49734f60a32620fc4f890
This commit is contained in:
parent
481ebc4a4b
commit
0c60cefe5e
|
@ -5666,6 +5666,10 @@ int CLI::run(int argc, char **argv)
|
||||||
std::vector<std::string> extruder_ams_count(new_extruder_count, "");
|
std::vector<std::string> extruder_ams_count(new_extruder_count, "");
|
||||||
std::vector<std::vector<DynamicPrintConfig>> extruder_filament_info(new_extruder_count, std::vector<DynamicPrintConfig>());
|
std::vector<std::vector<DynamicPrintConfig>> extruder_filament_info(new_extruder_count, std::vector<DynamicPrintConfig>());
|
||||||
int color_count = 0;
|
int color_count = 0;
|
||||||
|
|
||||||
|
const ConfigOptionStrings* filament_type = dynamic_cast<const ConfigOptionStrings *>(m_print_config.option("filament_type"));
|
||||||
|
std::vector<std::string> types = filament_type ? filament_type->vserialize() : std::vector<std::string>{"PLA"};
|
||||||
|
|
||||||
for (int e_index = 0; e_index < new_extruder_count; e_index++)
|
for (int e_index = 0; e_index < new_extruder_count; e_index++)
|
||||||
{
|
{
|
||||||
extruder_ams_count[e_index] = "1#0|4#1";
|
extruder_ams_count[e_index] = "1#0|4#1";
|
||||||
|
@ -5673,10 +5677,15 @@ int CLI::run(int argc, char **argv)
|
||||||
{
|
{
|
||||||
DynamicPrintConfig temp_config;
|
DynamicPrintConfig temp_config;
|
||||||
std::vector<std::string> temp_colors(1, "#FFFFFFFF");
|
std::vector<std::string> temp_colors(1, "#FFFFFFFF");
|
||||||
|
std::vector<std::string> temp_types(1, "PLA");
|
||||||
if (filament_color) {
|
if (filament_color) {
|
||||||
temp_colors[0] = colors[color_count % colors.size()];
|
temp_colors[0] = colors[color_count % colors.size()];
|
||||||
}
|
}
|
||||||
|
if (filament_type)
|
||||||
|
temp_types[0] = types[color_count % types.size()];
|
||||||
|
|
||||||
temp_config.option<ConfigOptionStrings>("filament_colour", true)->values = temp_colors;
|
temp_config.option<ConfigOptionStrings>("filament_colour", true)->values = temp_colors;
|
||||||
|
temp_config.option<ConfigOptionStrings>("filament_type", true)->values = temp_types;
|
||||||
extruder_filament_info[e_index].push_back(std::move(temp_config));
|
extruder_filament_info[e_index].push_back(std::move(temp_config));
|
||||||
color_count++;
|
color_count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,14 +79,21 @@ namespace FilamentGroupUtils
|
||||||
auto& arr = filament_configs[idx];
|
auto& arr = filament_configs[idx];
|
||||||
for (auto& item : arr) {
|
for (auto& item : arr) {
|
||||||
FilamentInfo temp;
|
FilamentInfo temp;
|
||||||
std::string color_str = item.option<ConfigOptionStrings>("filament_colour")->get_at(0);
|
std::string type = "PLA";
|
||||||
if (color_str.empty())
|
std::string color = "#FFFFFF";
|
||||||
temp.color = Color();
|
std::string tray_name;
|
||||||
else
|
|
||||||
temp.color = Color(color_str);
|
if (auto color_ptr = item.option<ConfigOptionStrings>("filament_colour"); color_ptr)
|
||||||
temp.type = item.option<ConfigOptionStrings>("filament_type")->get_at(0);
|
color = color_ptr->get_at(0);
|
||||||
|
if (auto type_ptr = item.option<ConfigOptionStrings>("filament_type"); type_ptr)
|
||||||
|
type = type_ptr->get_at(0);
|
||||||
|
if (auto tray_ptr = item.option<ConfigOptionStrings>("tray_name"); tray_ptr)
|
||||||
|
tray_name = tray_ptr->get_at(0);
|
||||||
|
|
||||||
|
temp.color = color.empty() ? Color() : Color(color);
|
||||||
|
temp.type =type;
|
||||||
temp.extruder_id = idx;
|
temp.extruder_id = idx;
|
||||||
temp.is_extended = item.option<ConfigOptionStrings>("tray_name")->get_at(0) == "Ext"; // hard-coded ext flag
|
temp.is_extended = tray_name == "Ext"; // hard-coded ext flag
|
||||||
machine_filaments[idx].emplace_back(std::move(temp));
|
machine_filaments[idx].emplace_back(std::move(temp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue