mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 03:06:08 +08:00
fix tool & filament color
This commit is contained in:
parent
837c3e9891
commit
cd3ea9c7c2
@ -575,17 +575,20 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
|
||||
// ensure at least one (default) color is defined
|
||||
std::string default_color = "#FF8000";
|
||||
m_result.extruder_colors = std::vector<std::string>(1, default_color);
|
||||
m_result.filament_colors = std::vector<std::string>(1, default_color);
|
||||
const ConfigOptionStrings* extruder_colour = config.option<ConfigOptionStrings>("extruder_colour");
|
||||
if (extruder_colour != nullptr) {
|
||||
// takes colors from config
|
||||
const ConfigOptionStrings* filament_colour = config.option<ConfigOptionStrings>("filament_colour");
|
||||
// takes colors from config
|
||||
if (extruder_colour != nullptr)
|
||||
m_result.extruder_colors = extruder_colour->values;
|
||||
// try to replace missing values with filament colors
|
||||
const ConfigOptionStrings* filament_colour = config.option<ConfigOptionStrings>("filament_colour");
|
||||
if (filament_colour != nullptr && filament_colour->values.size() == m_result.extruder_colors.size()) {
|
||||
for (size_t i = 0; i < m_result.extruder_colors.size(); ++i) {
|
||||
if (m_result.extruder_colors[i].empty())
|
||||
m_result.extruder_colors[i] = filament_colour->values[i];
|
||||
}
|
||||
if (filament_colour != nullptr)
|
||||
m_result.filament_colors = filament_colour->values;
|
||||
|
||||
// try to replace missing values with filament colors
|
||||
if (filament_colour != nullptr && filament_colour != nullptr && m_result.extruder_colors.size() == m_result.filament_colors.size()) {
|
||||
for (size_t i = 0; i < m_result.extruder_colors.size(); ++i) {
|
||||
if (m_result.extruder_colors[i].empty())
|
||||
m_result.extruder_colors[i] = m_result.filament_colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -594,6 +597,10 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
|
||||
if (m_result.extruder_colors[i].empty())
|
||||
m_result.extruder_colors[i] = default_color;
|
||||
}
|
||||
for (size_t i = 0; i < m_result.filament_colors.size(); ++i) {
|
||||
if (m_result.filament_colors[i].empty())
|
||||
m_result.filament_colors[i] = default_color;
|
||||
}
|
||||
|
||||
m_extruder_colors.resize(m_result.extruder_colors.size());
|
||||
for (size_t i = 0; i < m_result.extruder_colors.size(); ++i) {
|
||||
|
@ -265,6 +265,7 @@ namespace Slic3r {
|
||||
Pointfs bed_shape;
|
||||
std::string printer_settings_id;
|
||||
std::vector<std::string> extruder_colors;
|
||||
std::vector<std::string> filament_colors;
|
||||
PrintEstimatedTimeStatistics time_statistics;
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
@ -368,6 +368,13 @@ void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std:
|
||||
// update tool colors
|
||||
m_tool_colors = decode_colors(str_tool_colors);
|
||||
|
||||
if (m_view_type == EViewType::Filament && !gcode_result.filament_colors.empty())
|
||||
// update tool colors from config stored in the gcode
|
||||
m_filament_colors = decode_colors(gcode_result.filament_colors);
|
||||
else
|
||||
// update tool colors
|
||||
m_filament_colors = decode_colors(str_tool_colors);
|
||||
|
||||
// update ranges for coloring / legend
|
||||
m_extrusions.reset_ranges();
|
||||
for (size_t i = 0; i < m_moves_count; ++i) {
|
||||
@ -421,6 +428,7 @@ void GCodeViewer::reset()
|
||||
m_paths_bounding_box = BoundingBoxf3();
|
||||
m_max_bounding_box = BoundingBoxf3();
|
||||
m_tool_colors = std::vector<Color>();
|
||||
m_filament_colors = std::vector<Color>();
|
||||
m_extruder_ids = std::vector<unsigned char>();
|
||||
m_extrusions.reset_role_visibility_flags();
|
||||
m_extrusions.reset_ranges();
|
||||
@ -1677,7 +1685,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
||||
case EViewType::Chronology: { color = m_extrusions.ranges.elapsed_time.get_color_at(path.elapsed_time); break; }
|
||||
case EViewType::VolumetricRate: { color = m_extrusions.ranges.volumetric_rate.get_color_at(path.volumetric_rate); break; }
|
||||
case EViewType::Tool: { color = m_tool_colors[path.extruder_id]; break; }
|
||||
case EViewType::Filament: { color = m_tool_colors[path.extruder_id]; break; }
|
||||
case EViewType::Filament: { color = m_filament_colors[path.extruder_id]; break; }
|
||||
case EViewType::ColorPrint: { color = m_tool_colors[path.cp_color_id]; break; }
|
||||
case EViewType::ExtruderTemp: { color = m_extrusions.ranges.extruder_temp.get_color_at(path.extruder_temp); break; }
|
||||
default: { color = { 1.0f, 1.0f, 1.0f }; break; }
|
||||
@ -2345,7 +2353,6 @@ void GCodeViewer::render_legend() const
|
||||
case EViewType::Chronology: { append_range(m_extrusions.ranges.elapsed_time, 0); break; }
|
||||
case EViewType::VolumetricRate: { append_range(m_extrusions.ranges.volumetric_rate, 3); break; }
|
||||
case EViewType::Tool:
|
||||
case EViewType::Filament:
|
||||
{
|
||||
// shows only extruders actually used
|
||||
for (unsigned char i : m_extruder_ids) {
|
||||
@ -2353,6 +2360,14 @@ void GCodeViewer::render_legend() const
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EViewType::Filament:
|
||||
{
|
||||
// shows only filament actually used
|
||||
for (unsigned char i : m_extruder_ids) {
|
||||
append_item(EItemType::Rect, m_filament_colors[i], _u8L("Filament") + " " + std::to_string(i + 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EViewType::ColorPrint:
|
||||
{
|
||||
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
|
||||
|
@ -415,6 +415,7 @@ private:
|
||||
// bounding box of toolpaths + marker tools
|
||||
BoundingBoxf3 m_max_bounding_box;
|
||||
std::vector<Color> m_tool_colors;
|
||||
std::vector<Color> m_filament_colors;
|
||||
std::vector<double> m_layers_zs;
|
||||
std::array<double, 2> m_layers_z_range;
|
||||
std::vector<ExtrusionRole> m_roles;
|
||||
|
@ -1368,7 +1368,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
|
||||
}
|
||||
}
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
else if (gcode_preview_data_valid || gcode_view_type == GCodeViewer::EViewType::Filament)
|
||||
else if (gcode_view_type == GCodeViewer::EViewType::Filament)
|
||||
#else
|
||||
else if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Filament)
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
Loading…
x
Reference in New Issue
Block a user