mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-29 15:42:03 +08:00
New gcode visualization integration - Customizable travel moves colors
This commit is contained in:
parent
7a95ce8919
commit
2ac46adde5
@ -24,8 +24,6 @@
|
||||
#define DISABLE_INSTANCES_SYNCH 0
|
||||
// Use wxDataViewRender instead of wxDataViewCustomRenderer
|
||||
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING 0
|
||||
// Enable G-Code viewer statistics imgui dialog
|
||||
#define ENABLE_GCODE_VIEWER_STATISTICS 0
|
||||
// Enable G-Code viewer comparison between toolpaths height and width detected from gcode and calculated at gcode generation
|
||||
#define ENABLE_GCODE_VIEWER_DATA_CHECKING 0
|
||||
// Enable project dirty state manager debug window
|
||||
@ -62,7 +60,9 @@
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#define ENABLE_NEW_GCODE_VIEWER 1
|
||||
#define ENABLE_NEW_GCODE_VIEWER_DEBUG (0 && ENABLE_NEW_GCODE_VIEWER)
|
||||
#define ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS (1 && ENABLE_NEW_GCODE_VIEWER)
|
||||
#define ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS (1 && ENABLE_NEW_GCODE_VIEWER)
|
||||
// Enable G-Code viewer statistics imgui dialog
|
||||
#define ENABLE_GCODE_VIEWER_STATISTICS (1 && !ENABLE_NEW_GCODE_VIEWER)
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
#endif // _prusaslicer_technologies_h_
|
||||
|
@ -4885,8 +4885,8 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#if ENABLE_NEW_GCODE_VIEWER
|
||||
if (m_new_viewer.is_option_visible(libvgcode::EOptionType::Travels))
|
||||
append_item(EItemType::Line, libvgcode::convert(libvgcode::Travels_Colors[0]), _u8L("Travel"), true, short_time_ui(get_time_dhms(travels_time)),
|
||||
travels_time / time_mode.time, max_time_percent, offsets, 0.0f, 0.0f);
|
||||
append_item(EItemType::Line, libvgcode::convert(m_new_viewer.get_travel_move_color(libvgcode::ETravelMoveType::Move)), _u8L("Travel"), true, short_time_ui(get_time_dhms(travels_time)),
|
||||
travels_time / time_mode.time, max_time_percent, offsets, 0.0f, 0.0f);
|
||||
#else
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
if (m_buffers[buffer_id(EMoveType::Travel)].visible)
|
||||
|
@ -164,11 +164,11 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels
|
||||
// for travel moves set the extrusion role
|
||||
// which will be used later to select the proper color
|
||||
if (curr.delta_extruder == 0.0f)
|
||||
extrusion_role = static_cast<EGCodeExtrusionRole>(0); // Move
|
||||
extrusion_role = static_cast<EGCodeExtrusionRole>(ETravelMoveType::Move);
|
||||
else if (curr.delta_extruder > 0.0f)
|
||||
extrusion_role = static_cast<EGCodeExtrusionRole>(1); // Extrude
|
||||
extrusion_role = static_cast<EGCodeExtrusionRole>(ETravelMoveType::Extrude);
|
||||
else
|
||||
extrusion_role = static_cast<EGCodeExtrusionRole>(2); // Retract
|
||||
extrusion_role = static_cast<EGCodeExtrusionRole>(ETravelMoveType::Retract);
|
||||
}
|
||||
else
|
||||
extrusion_role = convert(curr.extrusion_role);
|
||||
@ -251,9 +251,15 @@ static void convert_lines_to_vertices(const Slic3r::Lines& lines, const std::vec
|
||||
if (ii == 0) {
|
||||
// add a dummy vertex at the start, to separate the current line from the others
|
||||
const Slic3r::Vec2f a = unscale(line.a).cast<float>();
|
||||
#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
|
||||
0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast<uint32_t>(layer_id),
|
||||
static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
|
||||
#else
|
||||
libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast<uint32_t>(layer_id),
|
||||
static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
|
||||
#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
vertices.emplace_back(vertex);
|
||||
// add the starting vertex of the segment
|
||||
vertex.type = EMoveType::Extrude;
|
||||
@ -261,9 +267,15 @@ static void convert_lines_to_vertices(const Slic3r::Lines& lines, const std::vec
|
||||
}
|
||||
// add the ending vertex of the segment
|
||||
const Slic3r::Vec2f b = unscale(line.b).cast<float>();
|
||||
#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
|
||||
0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast<uint32_t>(layer_id),
|
||||
static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
|
||||
#else
|
||||
const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast<uint32_t>(layer_id),
|
||||
static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
|
||||
#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
vertices.emplace_back(vertex);
|
||||
}
|
||||
}
|
||||
@ -534,6 +546,7 @@ private:
|
||||
case Slic3r::CustomGCode::ColorChange: { return color_change_color_id(it, extruder_id); }
|
||||
// change tool (extruder)
|
||||
case Slic3r::CustomGCode::ToolChange: { return tool_change_color_id(it, extruder_id); }
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -546,6 +559,7 @@ private:
|
||||
case Slic3r::CustomGCode::ColorChange: { return color_change_color_id(it, extruder_id); }
|
||||
// change tool (extruder)
|
||||
case Slic3r::CustomGCode::ToolChange: { return tool_change_color_id(it, extruder_id); }
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,12 +577,12 @@ private:
|
||||
--it_n;
|
||||
if (it_n->type == Slic3r::CustomGCode::ToolChange) {
|
||||
is_tool_change = true;
|
||||
if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder_id))
|
||||
if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == static_cast<int>(extruder_id)))
|
||||
return m600_color_id(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!is_tool_change && it->extruder == extruder_id)
|
||||
if (!is_tool_change && it->extruder == static_cast<int>(extruder_id))
|
||||
return m600_color_id(it);
|
||||
|
||||
assert(false);
|
||||
|
@ -73,6 +73,8 @@ enum class EViewType : uint8_t
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t View_Types_Count = static_cast<size_t>(EViewType::COUNT);
|
||||
|
||||
//
|
||||
// Move types
|
||||
//
|
||||
@ -92,6 +94,21 @@ enum class EMoveType : uint8_t
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t Move_Types_Count = static_cast<size_t>(EMoveType::COUNT);
|
||||
|
||||
//
|
||||
// Travel move types
|
||||
//
|
||||
enum class ETravelMoveType : uint8_t
|
||||
{
|
||||
Move,
|
||||
Extrude,
|
||||
Retract,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t Travel_Move_Types_Count = static_cast<size_t>(ETravelMoveType::COUNT);
|
||||
|
||||
//
|
||||
// Extrusion roles
|
||||
//
|
||||
@ -138,6 +155,8 @@ enum class EOptionType : uint8_t
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t Option_Types_Count = static_cast<size_t>(EOptionType::COUNT);
|
||||
|
||||
//
|
||||
// Time modes
|
||||
//
|
||||
@ -173,6 +192,8 @@ enum class EBBoxType : uint8_t
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t BBox_Types_Count = static_cast<size_t>(EBBoxType::COUNT);
|
||||
|
||||
//
|
||||
// Predefined colors
|
||||
//
|
||||
@ -198,17 +219,6 @@ static const std::vector<Color> Ranges_Colors{ {
|
||||
{ 148, 38, 22 } // reddish
|
||||
} };
|
||||
|
||||
//
|
||||
// Palette used to render travel moves
|
||||
// EViewType: FeatureType, Height, Width, FanSpeed, Temperature, VolumetricFlowRate,
|
||||
// LayerTimeLinear, LayerTimeLogarithmic
|
||||
//
|
||||
static const std::vector<Color> Travels_Colors{ {
|
||||
{ 56, 72, 155 }, // Move
|
||||
{ 29, 108, 26 }, // Extrude
|
||||
{ 129, 16, 7 } // Retract
|
||||
} };
|
||||
|
||||
//
|
||||
// Mapping from EMoveType to EOptionType
|
||||
//
|
||||
|
@ -155,6 +155,10 @@ public:
|
||||
void set_option_color(EOptionType type, const Color& color);
|
||||
void reset_default_options_colors();
|
||||
|
||||
const Color& get_travel_move_color(ETravelMoveType type) const;
|
||||
void set_travel_move_color(ETravelMoveType type, const Color& color);
|
||||
void reset_default_travel_moves_colors();
|
||||
|
||||
const ColorRange& get_height_range() const;
|
||||
const ColorRange& get_width_range() const;
|
||||
const ColorRange& get_speed_range() const;
|
||||
|
@ -287,6 +287,21 @@ void Viewer::reset_default_options_colors()
|
||||
m_impl->reset_default_options_colors();
|
||||
}
|
||||
|
||||
const Color& Viewer::get_travel_move_color(ETravelMoveType type) const
|
||||
{
|
||||
return m_impl->get_travel_move_color(type);
|
||||
}
|
||||
|
||||
void Viewer::set_travel_move_color(ETravelMoveType type, const Color& color)
|
||||
{
|
||||
m_impl->set_travel_move_color(type, color);
|
||||
}
|
||||
|
||||
void Viewer::reset_default_travel_moves_colors()
|
||||
{
|
||||
m_impl->reset_default_travel_moves_colors();
|
||||
}
|
||||
|
||||
const ColorRange& Viewer::get_height_range() const
|
||||
{
|
||||
return m_impl->get_height_range();
|
||||
|
@ -998,6 +998,24 @@ void ViewerImpl::reset_default_options_colors()
|
||||
m_options_colors = Default_Options_Colors;
|
||||
}
|
||||
|
||||
const Color& ViewerImpl::get_travel_move_color(ETravelMoveType type) const
|
||||
{
|
||||
auto it = m_travel_moves_colors.find(type);
|
||||
return (it != m_travel_moves_colors.end()) ? m_travel_moves_colors.at(type) : Dummy_Color;
|
||||
}
|
||||
|
||||
void ViewerImpl::set_travel_move_color(ETravelMoveType type, const Color& color)
|
||||
{
|
||||
auto it = m_travel_moves_colors.find(type);
|
||||
if (it != m_travel_moves_colors.end())
|
||||
m_travel_moves_colors[type] = color;
|
||||
}
|
||||
|
||||
void ViewerImpl::reset_default_travel_moves_colors()
|
||||
{
|
||||
m_travel_moves_colors = Default_Travel_Moves_Colors;
|
||||
}
|
||||
|
||||
const ColorRange& ViewerImpl::get_height_range() const
|
||||
{
|
||||
return m_height_range;
|
||||
@ -1315,23 +1333,19 @@ Color ViewerImpl::select_color(const PathVertex& v) const
|
||||
if (v.is_option())
|
||||
return get_option_color(type_to_option(v.type));
|
||||
|
||||
const size_t role = static_cast<size_t>(v.role);
|
||||
switch (m_settings.view_type)
|
||||
{
|
||||
case EViewType::FeatureType:
|
||||
{
|
||||
assert((v.is_travel() && role < Travels_Colors.size()) || v.is_extrusion());
|
||||
return v.is_travel() ? Travels_Colors[role] : get_extrusion_role_color(v.role);
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) : get_extrusion_role_color(v.role);
|
||||
}
|
||||
case EViewType::Height:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_height_range.get_color_at(v.height);
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) : m_height_range.get_color_at(v.height);
|
||||
}
|
||||
case EViewType::Width:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_width_range.get_color_at(v.width);
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) : m_width_range.get_color_at(v.width);
|
||||
}
|
||||
case EViewType::Speed:
|
||||
{
|
||||
@ -1339,29 +1353,24 @@ Color ViewerImpl::select_color(const PathVertex& v) const
|
||||
}
|
||||
case EViewType::FanSpeed:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_fan_speed_range.get_color_at(v.fan_speed);
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) : m_fan_speed_range.get_color_at(v.fan_speed);
|
||||
}
|
||||
case EViewType::Temperature:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_temperature_range.get_color_at(v.temperature);
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) : m_temperature_range.get_color_at(v.temperature);
|
||||
}
|
||||
case EViewType::VolumetricFlowRate:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_volumetric_rate_range.get_color_at(v.volumetric_rate);
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) : m_volumetric_rate_range.get_color_at(v.volumetric_rate);
|
||||
}
|
||||
case EViewType::LayerTimeLinear:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] :
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) :
|
||||
m_layer_time_range[0].get_color_at(m_layers.get_layer_time(m_settings.time_mode, static_cast<size_t>(v.layer_id)));
|
||||
}
|
||||
case EViewType::LayerTimeLogarithmic:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] :
|
||||
return v.is_travel() ? get_travel_move_color(static_cast<ETravelMoveType>(v.role)) :
|
||||
m_layer_time_range[1].get_color_at(m_layers.get_layer_time(m_settings.time_mode, static_cast<size_t>(v.layer_id)));
|
||||
}
|
||||
case EViewType::Tool:
|
||||
|
@ -52,6 +52,7 @@ static const std::map<EGCodeExtrusionRole, Color> Default_Extrusion_Roles_Colors
|
||||
|
||||
//
|
||||
// Palette used to render options
|
||||
// EViewType: FeatureType
|
||||
//
|
||||
static const std::map<EOptionType, Color> Default_Options_Colors{ {
|
||||
{ EOptionType::Retractions, { 205, 34, 214 } },
|
||||
@ -63,6 +64,17 @@ static const std::map<EOptionType, Color> Default_Options_Colors{ {
|
||||
{ EOptionType::CustomGCodes, { 226, 210, 67 } }
|
||||
} };
|
||||
|
||||
//
|
||||
// Palette used to render travel moves
|
||||
// EViewType: FeatureType, Height, Width, FanSpeed, Temperature, VolumetricFlowRate,
|
||||
// LayerTimeLinear, LayerTimeLogarithmic
|
||||
//
|
||||
static const std::map<ETravelMoveType, Color> Default_Travel_Moves_Colors{ {
|
||||
{ ETravelMoveType::Move, { 56, 72, 155 } },
|
||||
{ ETravelMoveType::Extrude, { 29, 108, 26 } },
|
||||
{ ETravelMoveType::Retract, { 129, 16, 7 } }
|
||||
} };
|
||||
|
||||
class ViewerImpl
|
||||
{
|
||||
public:
|
||||
@ -173,6 +185,10 @@ public:
|
||||
void set_option_color(EOptionType type, const Color& color);
|
||||
void reset_default_options_colors();
|
||||
|
||||
const Color& get_travel_move_color(ETravelMoveType type) const;
|
||||
void set_travel_move_color(ETravelMoveType type, const Color& color);
|
||||
void reset_default_travel_moves_colors();
|
||||
|
||||
const ColorRange& get_height_range() const;
|
||||
const ColorRange& get_width_range() const;
|
||||
const ColorRange& get_speed_range() const;
|
||||
@ -226,6 +242,7 @@ private:
|
||||
|
||||
std::map<EGCodeExtrusionRole, Color> m_extrusion_roles_colors{ Default_Extrusion_Roles_Colors };
|
||||
std::map<EOptionType, Color> m_options_colors{ Default_Options_Colors };
|
||||
std::map<ETravelMoveType, Color> m_travel_moves_colors{ Default_Travel_Moves_Colors };
|
||||
|
||||
//
|
||||
// The OpenGL element used to represent all toolpath segments
|
||||
|
Loading…
x
Reference in New Issue
Block a user