Skip to content

Commit 7e1b2d9

Browse files
loss-and-quickigiannakasclaude
authored
Add Pressure Advance visualization support (OrcaSlicer#11673)
* Add Pressure Advance visualization support Signed-off-by: minicx <minicx@disroot.org> * Port Pressure Advance visualization to libvgcode architecture Adapt PA visualization (originally in commit e3a7725) to work with the new libvgcode library introduced by upstream PR OrcaSlicer#10735. Changes across the libvgcode stack: - PathVertex: add pressure_advance field - Types.hpp: add PressureAdvance to EViewType enum - ViewerImpl: add ColorRange, color mapping, range updates for PA - LibVGCodeWrapper: pass pressure_advance from MoveVertex to PathVertex GCodeViewer UI integration: - Add "Pressure Advance" to view type dropdown - Add PA color range in legend (3 decimal places) - Add PA value display in sequential view marker tooltip - Add PA row in position properties table The GCodeProcessor PA parsing (M900, M572, SET_PRESSURE_ADVANCE) is preserved from the original implementation. * Tag Pressure Advance visualization changes with ORCA comments Signed-off-by: minicx <minicx@disroot.org> --------- Signed-off-by: minicx <minicx@disroot.org> Co-authored-by: Ioannis Giannakas <59056762+igiannakas@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 528e7c6 commit 7e1b2d9

File tree

9 files changed

+111
-4
lines changed

9 files changed

+111
-4
lines changed

src/libslic3r/GCode/GCodeProcessor.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,10 @@ void GCodeProcessor::register_commands()
19671967
{"M702", [this](const GCodeReader::GCodeLine& line) { process_M702(line); }}, // Unload the current filament into the MK3 MMU2 unit at the end of print.
19681968
{"M1020", [this](const GCodeReader::GCodeLine& line) { process_M1020(line); }}, // Select Tool
19691969

1970+
// ORCA: Add Pressure Advance visualization support
1971+
{"M900", [this](const GCodeReader::GCodeLine& line) { process_M900(line); }}, // Marlin: Set pressure advance
1972+
{"M572", [this](const GCodeReader::GCodeLine& line) { process_M572(line); }}, // RepRapFirmware/Duet: Set pressure advance
1973+
19701974
{"T", [this](const GCodeReader::GCodeLine& line) { process_T(line); }}, // Select Tool
19711975
{"SYNC", [this](const GCodeReader::GCodeLine& line) { process_SYNC(line); }}, // SYNC TIME
19721976

@@ -3028,6 +3032,12 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool
30283032
process_SET_VELOCITY_LIMIT(line);
30293033
return;
30303034
}
3035+
// ORCA: Add Pressure Advance visualization support
3036+
if (boost::iequals(cmd, "SET_PRESSURE_ADVANCE"))
3037+
{
3038+
process_SET_PRESSURE_ADVANCE(line);
3039+
return;
3040+
}
30313041
}
30323042

30333043
if (cmd.length() > 1) {
@@ -5150,6 +5160,37 @@ void GCodeProcessor::process_M106(const GCodeReader::GCodeLine& line)
51505160
}
51515161
}
51525162

5163+
// ORCA: Add Pressure Advance visualization support
5164+
void GCodeProcessor::process_M900(const GCodeReader::GCodeLine &line)
5165+
{
5166+
float pa_value = m_pressure_advance;
5167+
line.has_value('K', pa_value);
5168+
m_pressure_advance = std::max(0.0f, pa_value);
5169+
// BOOST_LOG_TRIVIAL(debug) << "M900 command: PA set to " << m_pressure_advance;
5170+
}
5171+
5172+
void GCodeProcessor::process_M572(const GCodeReader::GCodeLine &line)
5173+
{
5174+
float pa_value = m_pressure_advance;
5175+
line.has_value('S', pa_value);
5176+
m_pressure_advance = std::max(0.0f, pa_value);
5177+
// BOOST_LOG_TRIVIAL(debug) << "M572 command: PA set to " << m_pressure_advance;
5178+
}
5179+
5180+
void GCodeProcessor::process_SET_PRESSURE_ADVANCE(const GCodeReader::GCodeLine& line)
5181+
{
5182+
std::regex regex(R"(SET_PRESSURE_ADVANCE\s+(?:.*\s+)?ADVANCE\s*=\s*([\d.]+))");
5183+
std::smatch matches;
5184+
5185+
if (std::regex_search(line.raw(), matches, regex) && matches.size() > 1) {
5186+
float pa_value = 0;
5187+
try {
5188+
pa_value = std::stof(matches[1].str());
5189+
} catch (...) {}
5190+
m_pressure_advance = std::max(0.0f, pa_value);
5191+
}
5192+
}
5193+
51535194
void GCodeProcessor::process_M107(const GCodeReader::GCodeLine& line)
51545195
{
51555196
m_fan_speed = 0.0f;
@@ -5689,6 +5730,8 @@ void GCodeProcessor::store_move_vertex(EMoveType type, EMovePathType path_type,
56895730
m_travel_dist,
56905731
m_fan_speed,
56915732
m_extruder_temps[filament_id],
5733+
// ORCA: Add Pressure Advance visualization support
5734+
m_pressure_advance,
56925735
{ 0.0f, 0.0f }, // time
56935736
static_cast<float>(m_layer_id), //layer_duration: set later
56945737
std::max<unsigned int>(1, m_layer_id) - 1,

src/libslic3r/GCode/GCodeProcessor.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ class Print;
184184
float travel_dist{ 0.0f }; // mm
185185
float fan_speed{ 0.0f }; // percentage
186186
float temperature{ 0.0f }; // Celsius degrees
187+
// ORCA: Add Pressure Advance visualization support
188+
float pressure_advance{ 0.0f };
187189
std::array<float, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> time{ 0.0f, 0.0f }; // s
188190
float layer_duration{ 0.0f }; // s
189191
unsigned int layer_id{ 0 };
@@ -777,6 +779,8 @@ class Print;
777779
float m_travel_dist; // mm
778780
float m_fan_speed; // percentage
779781
float m_z_offset; // mm
782+
// ORCA: Add Pressure Advance visualization support
783+
float m_pressure_advance;
780784
ExtrusionRole m_extrusion_role;
781785
std::vector<int> m_filament_maps;
782786
std::vector<unsigned char> m_last_filament_id;
@@ -981,6 +985,12 @@ class Print;
981985
// Disable fan
982986
void process_M107(const GCodeReader::GCodeLine& line);
983987

988+
// ORCA: Add Pressure Advance visualization support
989+
// Set pressure advance
990+
void process_M900(const GCodeReader::GCodeLine& line);
991+
void process_M572(const GCodeReader::GCodeLine &line);
992+
void process_SET_PRESSURE_ADVANCE(const GCodeReader::GCodeLine& line);
993+
984994
// Set tool (Sailfish)
985995
void process_M108(const GCodeReader::GCodeLine& line);
986996

src/libvgcode/include/PathVertex.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ struct PathVertex
8686
// Layer duration in seconds
8787
//
8888
float layer_duration{ 0.0f };
89+
//
90+
// ORCA: Add Pressure Advance visualization support
91+
// Pressure advance value
92+
//
93+
float pressure_advance{ 0.0f };
8994

9095
//
9196
// Return true if the segment is an extrusion move

src/libvgcode/include/Types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ enum class EViewType : uint8_t
9292
LayerTimeLogarithmic,
9393
FanSpeed,
9494
Temperature,
95+
// ORCA: Add Pressure Advance visualization support
96+
PressureAdvance,
9597
Tool,
9698
COUNT
9799
};

src/libvgcode/include/Viewer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class Viewer
169169
// EViewType::ActualSpeed
170170
// EViewType::FanSpeed
171171
// EViewType::Temperature
172+
// ORCA: Add Pressure Advance visualization support
173+
// EViewType::PressureAdvance
172174
// EViewType::VolumetricFlowRate
173175
// EViewType::ActualVolumetricFlowRate
174176
// EViewType::LayerTimeLinear
@@ -185,6 +187,8 @@ class Viewer
185187
// EViewType::ActualSpeed
186188
// EViewType::FanSpeed
187189
// EViewType::Temperature
190+
// ORCA: Add Pressure Advance visualization support
191+
// EViewType::PressureAdvance
188192
// EViewType::VolumetricFlowRate
189193
// EViewType::ActualVolumetricFlowRate
190194
// EViewType::LayerTimeLinear

src/libvgcode/src/ViewerImpl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,11 @@ Color ViewerImpl::get_vertex_color(const PathVertex& v) const
14931493
{
14941494
return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_temperature_range.get_color_at(v.temperature);
14951495
}
1496+
// ORCA: Add Pressure Advance visualization support
1497+
case EViewType::PressureAdvance:
1498+
{
1499+
return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_pressure_advance_range.get_color_at(v.pressure_advance);
1500+
}
14961501
case EViewType::VolumetricFlowRate:
14971502
{
14981503
return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_volumetric_rate_range.get_color_at(v.volumetric_rate());
@@ -1582,6 +1587,8 @@ const ColorRange& ViewerImpl::get_color_range(EViewType type) const
15821587
case EViewType::ActualSpeed: { return m_actual_speed_range; }
15831588
case EViewType::FanSpeed: { return m_fan_speed_range; }
15841589
case EViewType::Temperature: { return m_temperature_range; }
1590+
// ORCA: Add Pressure Advance visualization support
1591+
case EViewType::PressureAdvance: { return m_pressure_advance_range; }
15851592
case EViewType::VolumetricFlowRate: { return m_volumetric_rate_range; }
15861593
case EViewType::ActualVolumetricFlowRate: { return m_actual_volumetric_rate_range; }
15871594
case EViewType::LayerTimeLinear: { return m_layer_time_range[0]; }
@@ -1600,6 +1607,8 @@ void ViewerImpl::set_color_range_palette(EViewType type, const Palette& palette)
16001607
case EViewType::ActualSpeed: { m_actual_speed_range.set_palette(palette); break; }
16011608
case EViewType::FanSpeed: { m_fan_speed_range.set_palette(palette); break; }
16021609
case EViewType::Temperature: { m_temperature_range.set_palette(palette); break; }
1610+
// ORCA: Add Pressure Advance visualization support
1611+
case EViewType::PressureAdvance: { m_pressure_advance_range.set_palette(palette); break; }
16031612
case EViewType::VolumetricFlowRate: { m_volumetric_rate_range.set_palette(palette); break; }
16041613
case EViewType::ActualVolumetricFlowRate: { m_actual_volumetric_rate_range.set_palette(palette); break; }
16051614
case EViewType::LayerTimeLinear: { m_layer_time_range[0].set_palette(palette); break; }
@@ -1637,6 +1646,8 @@ size_t ViewerImpl::get_used_cpu_memory() const
16371646
ret += m_actual_speed_range.size_in_bytes_cpu();
16381647
ret += m_fan_speed_range.size_in_bytes_cpu();
16391648
ret += m_temperature_range.size_in_bytes_cpu();
1649+
// ORCA: Add Pressure Advance visualization support
1650+
ret += m_pressure_advance_range.size_in_bytes_cpu();
16401651
ret += m_volumetric_rate_range.size_in_bytes_cpu();
16411652
ret += m_actual_volumetric_rate_range.size_in_bytes_cpu();
16421653
for (size_t i = 0; i < COLOR_RANGE_TYPES_COUNT; ++i) {
@@ -1787,6 +1798,8 @@ void ViewerImpl::update_color_ranges()
17871798
m_actual_speed_range.reset();
17881799
m_fan_speed_range.reset();
17891800
m_temperature_range.reset();
1801+
// ORCA: Add Pressure Advance visualization support
1802+
m_pressure_advance_range.reset();
17901803
m_volumetric_rate_range.reset();
17911804
m_actual_volumetric_rate_range.reset();
17921805
m_layer_time_range[0].reset(); // ColorRange::EType::Linear
@@ -1803,6 +1816,9 @@ void ViewerImpl::update_color_ranges()
18031816
}
18041817
m_fan_speed_range.update(round_to_bin(v.fan_speed));
18051818
m_temperature_range.update(round_to_bin(v.temperature));
1819+
// ORCA: Add Pressure Advance visualization support
1820+
if (v.pressure_advance >= 0.0f)
1821+
m_pressure_advance_range.update(v.pressure_advance);
18061822
}
18071823
if ((v.is_travel() && m_settings.options_visibility[size_t(EOptionType::Travels)]) ||
18081824
(v.is_wipe() && m_settings.options_visibility[size_t(EOptionType::Wipes)]) ||

src/libvgcode/src/ViewerImpl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ class ViewerImpl
289289
ColorRange m_actual_speed_range;
290290
ColorRange m_fan_speed_range;
291291
ColorRange m_temperature_range;
292+
// ORCA: Add Pressure Advance visualization support
293+
ColorRange m_pressure_advance_range;
292294
ColorRange m_volumetric_rate_range;
293295
ColorRange m_actual_volumetric_rate_range;
294296
std::array<ColorRange, COLOR_RANGE_TYPES_COUNT> m_layer_time_range{

src/slic3r/GUI/GCodeViewer.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ static std::string get_view_type_string(libvgcode::EViewType view_type)
9191
return _u8L("Layer Time");
9292
else if (view_type == libvgcode::EViewType::LayerTimeLogarithmic)
9393
return _u8L("Layer Time (log)");
94+
// ORCA: Add Pressure Advance visualization support
95+
else if (view_type == libvgcode::EViewType::PressureAdvance)
96+
return _u8L("Pressure Advance");
9497
return "";
9598
}
9699

@@ -397,6 +400,11 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode
397400
sprintf(buff, ("%.0f " + _u8L("°C")).c_str(), vertex.temperature);
398401
ImGuiWrapper::text(std::string(buff));
399402
});
403+
// ORCA: Add Pressure Advance visualization support
404+
append_table_row(_u8L("Pressure Advance"), [&vertex, &buff]() {
405+
sprintf(buff, "%.4f", vertex.pressure_advance);
406+
ImGuiWrapper::text(std::string(buff));
407+
});
400408
append_table_row(_u8L("Time"), [viewer, &vertex, &buff, vertex_id]() {
401409
const float estimated_time = viewer->get_estimated_time_at(vertex_id);
402410
sprintf(buff, "%s (%.3fs)", get_time_dhms(estimated_time).c_str(), vertex.times[static_cast<size_t>(viewer->get_time_mode())]);
@@ -607,6 +615,11 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode
607615
sprintf(buf, "%s %s%.1f", buf, _u8L("Actual Speed: ").c_str(), vertex.actual_feedrate);
608616
break;
609617
}
618+
// ORCA: Add Pressure Advance visualization support
619+
case libvgcode::EViewType::PressureAdvance: {
620+
sprintf(buf, "%s %s%.4f", buf, _u8L("PA: ").c_str(), vertex.pressure_advance);
621+
break;
622+
}
610623

611624
default:
612625
break;
@@ -1024,6 +1037,8 @@ void GCodeViewer::update_by_mode(ConfigOptionMode mode)
10241037
view_type_items.push_back(libvgcode::EViewType::LayerTimeLogarithmic);
10251038
view_type_items.push_back(libvgcode::EViewType::FanSpeed);
10261039
view_type_items.push_back(libvgcode::EViewType::Temperature);
1040+
// ORCA: Add Pressure Advance visualization support
1041+
view_type_items.push_back(libvgcode::EViewType::PressureAdvance);
10271042
//if (mode == ConfigOptionMode::comDevelop) {
10281043
// view_type_items.push_back(EViewType::Tool);
10291044
//}
@@ -2250,6 +2265,8 @@ void GCodeViewer::render_toolpaths()
22502265
add_range_property_row("speed range", m_viewer.get_color_range(libvgcode::EViewType::Speed).get_range());
22512266
add_range_property_row("fan speed range", m_viewer.get_color_range(libvgcode::EViewType::FanSpeed).get_range());
22522267
add_range_property_row("temperature range", m_viewer.get_color_range(libvgcode::EViewType::Temperature).get_range());
2268+
// ORCA: Add Pressure Advance visualization support
2269+
add_range_property_row("pressure advance range", m_viewer.get_color_range(libvgcode::EViewType::PressureAdvance).get_range());
22532270
add_range_property_row("volumetric rate range", m_viewer.get_color_range(libvgcode::EViewType::VolumetricFlowRate).get_range());
22542271
add_range_property_row("layer time linear range", m_viewer.get_color_range(libvgcode::EViewType::LayerTimeLinear).get_range());
22552272
add_range_property_row("layer time logarithmic range", m_viewer.get_color_range(libvgcode::EViewType::LayerTimeLogarithmic).get_range());
@@ -3498,6 +3515,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
34983515
}
34993516
case libvgcode::EViewType::FanSpeed: { imgui.title(_u8L("Fan Speed (%)")); break; }
35003517
case libvgcode::EViewType::Temperature: { imgui.title(_u8L("Temperature (°C)")); break; }
3518+
// ORCA: Add Pressure Advance visualization support
3519+
case libvgcode::EViewType::PressureAdvance:{ imgui.title(_u8L("Pressure Advance")); break; }
35013520
case libvgcode::EViewType::VolumetricFlowRate:
35023521
{ imgui.title(_u8L("Volumetric flow rate (mm³/s)")); break; }
35033522
case libvgcode::EViewType::ActualVolumetricFlowRate:
@@ -3674,6 +3693,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
36743693
}
36753694
case libvgcode::EViewType::FanSpeed: { append_range(m_viewer.get_color_range(libvgcode::EViewType::FanSpeed), 0); break; }
36763695
case libvgcode::EViewType::Temperature: { append_range(m_viewer.get_color_range(libvgcode::EViewType::Temperature), 0); break; }
3696+
// ORCA: Add Pressure Advance visualization support
3697+
case libvgcode::EViewType::PressureAdvance: { append_range(m_viewer.get_color_range(libvgcode::EViewType::PressureAdvance), 3); break; }
36773698
case libvgcode::EViewType::LayerTimeLinear: { append_range(m_viewer.get_color_range(libvgcode::EViewType::LayerTimeLinear), true); break; }
36783699
case libvgcode::EViewType::LayerTimeLogarithmic: { append_range(m_viewer.get_color_range(libvgcode::EViewType::LayerTimeLogarithmic), true); break; }
36793700
case libvgcode::EViewType::VolumetricFlowRate: { append_range(m_viewer.get_color_range(libvgcode::EViewType::VolumetricFlowRate), 2); break; }

src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,14 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, const std::ve
224224
const libvgcode::PathVertex vertex = { convert(prev.position), curr.height, curr.width, curr.feedrate, prev.actual_feedrate,
225225
curr.mm3_per_mm, curr.fan_speed, curr.temperature, 0.0f, convert(curr.extrusion_role), curr_type,
226226
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
227-
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
227+
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f },
228+
/* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance };
228229
#else
229230
const libvgcode::PathVertex vertex = { convert(prev.position), curr.height, curr.width, curr.feedrate, prev.actual_feedrate,
230231
curr.mm3_per_mm, curr.fan_speed, curr.temperature, convert(curr.extrusion_role), curr_type,
231232
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
232-
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
233+
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f },
234+
/* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance };
233235
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
234236
ret.vertices.emplace_back(vertex);
235237
}
@@ -240,12 +242,14 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, const std::ve
240242
curr.mm3_per_mm, curr.fan_speed, curr.temperature,
241243
result.filament_densities[curr.extruder_id] * curr.mm3_per_mm * (curr.position - prev.position).norm(),
242244
convert(curr.extrusion_role), curr_type, static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
243-
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time };
245+
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time,
246+
/* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance };
244247
#else
245248
const libvgcode::PathVertex vertex = { convert(curr.position), curr.height, curr.width, curr.feedrate, curr.actual_feedrate,
246249
curr.mm3_per_mm, curr.fan_speed, curr.temperature, convert(curr.extrusion_role), curr_type,
247250
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
248-
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time };
251+
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time,
252+
/* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance };
249253
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
250254
ret.vertices.emplace_back(vertex);
251255
}

0 commit comments

Comments
 (0)