QoL: show transparent shell in gcode preview and truncate long gcode line caused by native Klipper commands

This commit is contained in:
SoftFever 2023-08-29 21:25:47 +08:00
parent 40b08bb0e1
commit 95d12c24f6
23 changed files with 157 additions and 133 deletions

View file

@ -2561,7 +2561,7 @@ msgstr ""
msgid "Layer Time: " msgid "Layer Time: "
msgstr "" msgstr ""
msgid "Fan Speed: " msgid "Fan: "
msgstr "" msgstr ""
msgid "Temperature: " msgid "Temperature: "

View file

@ -2759,7 +2759,7 @@ msgstr "Průtok: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Čas vrstvy: " msgstr "Čas vrstvy: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Rychlost ventilátoru: " msgstr "Rychlost ventilátoru: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2822,7 +2822,7 @@ msgstr "Durchfluss: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Schichtdauer:" msgstr "Schichtdauer:"
msgid "Fan Speed: " msgid "Fan: "
msgstr "Lüftergeschwindigkeit: " msgstr "Lüftergeschwindigkeit: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2725,8 +2725,8 @@ msgstr "Flow: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Layer Time: " msgstr "Layer Time: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Fan Speed: " msgstr "Fan: "
msgid "Temperature: " msgid "Temperature: "
msgstr "Temperature: " msgstr "Temperature: "

View file

@ -2799,7 +2799,7 @@ msgstr "Flujo: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Tiempo de Capa: " msgstr "Tiempo de Capa: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Velocidad del Ventilador: " msgstr "Velocidad del Ventilador: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2806,7 +2806,7 @@ msgstr "Débit: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Durée de couche:" msgstr "Durée de couche:"
msgid "Fan Speed: " msgid "Fan: "
msgstr "Vitesse du ventilateur: " msgstr "Vitesse du ventilateur: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2749,7 +2749,7 @@ msgstr "Anyagáramlás:"
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Rétegidő: " msgstr "Rétegidő: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Ventilátor-fordulatszám:" msgstr "Ventilátor-fordulatszám:"
msgid "Temperature: " msgid "Temperature: "

View file

@ -2744,7 +2744,7 @@ msgstr "Flusso: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Tempo layer:" msgstr "Tempo layer:"
msgid "Fan Speed: " msgid "Fan: "
msgstr "Velocità ventola:" msgstr "Velocità ventola:"
msgid "Temperature: " msgid "Temperature: "

View file

@ -2665,7 +2665,7 @@ msgstr "フロー"
msgid "Layer Time: " msgid "Layer Time: "
msgstr "積層時間" msgstr "積層時間"
msgid "Fan Speed: " msgid "Fan: "
msgstr "ファン回転速度" msgstr "ファン回転速度"
msgid "Temperature: " msgid "Temperature: "

View file

@ -2708,7 +2708,7 @@ msgstr "유량: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "레이어 시간: " msgstr "레이어 시간: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "팬 속도: " msgstr "팬 속도: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2769,7 +2769,7 @@ msgstr "Flow: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Laagtijd:" msgstr "Laagtijd:"
msgid "Fan Speed: " msgid "Fan: "
msgstr "Ventilatorsnelheid:" msgstr "Ventilatorsnelheid:"
msgid "Temperature: " msgid "Temperature: "

View file

@ -2783,7 +2783,7 @@ msgstr "Поток: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Время печати слоя: " msgstr "Время печати слоя: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Скорость вентилятора: " msgstr "Скорость вентилятора: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2738,7 +2738,7 @@ msgstr "Flöde: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Lager Tid: " msgstr "Lager Tid: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Fläkthastighet: " msgstr "Fläkthastighet: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2768,7 +2768,7 @@ msgstr "Потік: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "Час шару: " msgstr "Час шару: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "Швидкість вентилятора: " msgstr "Швидкість вентилятора: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2641,7 +2641,7 @@ msgstr "擠出流量: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "層時間: " msgstr "層時間: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "風扇速度: " msgstr "風扇速度: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -2641,7 +2641,7 @@ msgstr "挤出流量: "
msgid "Layer Time: " msgid "Layer Time: "
msgstr "层时间: " msgstr "层时间: "
msgid "Fan Speed: " msgid "Fan: "
msgstr "风扇速度: " msgstr "风扇速度: "
msgid "Temperature: " msgid "Temperature: "

View file

@ -1,3 +1,4 @@
#include "slic3r/GUI/3DScene.hpp"
#include <GL/glew.h> #include <GL/glew.h>
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
@ -1615,6 +1616,16 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig *con
} }
} }
void GLVolumeCollection::set_transparency(float alpha)
{
for (GLVolume *volume : volumes) {
if (volume == nullptr || volume->is_modifier || volume->is_wipe_tower || (volume->volume_idx() < 0))
continue;
volume->color[3] = alpha;
}
}
std::vector<double> GLVolumeCollection::get_current_print_zs(bool active_only) const std::vector<double> GLVolumeCollection::get_current_print_zs(bool active_only) const
{ {
// Collect layer top positions of all volumes. // Collect layer top positions of all volumes.

View file

@ -715,6 +715,8 @@ public:
// Return CPU, GPU and total memory log line. // Return CPU, GPU and total memory log line.
std::string log_memory_info() const; std::string log_memory_info() const;
void set_transparency(float alpha);
private: private:
GLVolumeCollection(const GLVolumeCollection &other); GLVolumeCollection(const GLVolumeCollection &other);
GLVolumeCollection& operator=(const GLVolumeCollection &); GLVolumeCollection& operator=(const GLVolumeCollection &);

View file

@ -327,7 +327,7 @@ void GCodeViewer::SequentialRangeCap::reset() {
void GCodeViewer::SequentialView::Marker::init(std::string filename) void GCodeViewer::SequentialView::Marker::init(std::string filename)
{ {
if (filename.empty()) { if (filename.empty()) {
//m_model.init_from(stilized_arrow(16, 1.5f, 3.0f, 0.8f, 3.0f)); m_model.init_from(stilized_arrow(16, 1.5f, 3.0f, 0.8f, 3.0f));
} else { } else {
m_model.init_from_file(filename); m_model.init_from_file(filename);
} }
@ -399,73 +399,73 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he
std::string speed = ImGui::ColorMarkerStart + _u8L("Speed: ") + ImGui::ColorMarkerEnd; std::string speed = ImGui::ColorMarkerStart + _u8L("Speed: ") + ImGui::ColorMarkerEnd;
std::string flow = ImGui::ColorMarkerStart + _u8L("Flow: ") + ImGui::ColorMarkerEnd; std::string flow = ImGui::ColorMarkerStart + _u8L("Flow: ") + ImGui::ColorMarkerEnd;
std::string layer_time = ImGui::ColorMarkerStart + _u8L("Layer Time: ") + ImGui::ColorMarkerEnd; std::string layer_time = ImGui::ColorMarkerStart + _u8L("Layer Time: ") + ImGui::ColorMarkerEnd;
std::string fanspeed = ImGui::ColorMarkerStart + _u8L("Fan Speed: ") + ImGui::ColorMarkerEnd; std::string fanspeed = ImGui::ColorMarkerStart + _u8L("Fan: ") + ImGui::ColorMarkerEnd;
std::string temperature = ImGui::ColorMarkerStart + _u8L("Temperature: ") + ImGui::ColorMarkerEnd; std::string temperature = ImGui::ColorMarkerStart + _u8L("Temperature: ") + ImGui::ColorMarkerEnd;
const float item_size = imgui.calc_text_size("X: 000.000 ").x; const float item_size = imgui.calc_text_size("X: 000.000 ").x;
const float item_spacing = imgui.get_item_spacing().x; const float item_spacing = imgui.get_item_spacing().x;
const float window_padding = ImGui::GetStyle().WindowPadding.x; const float window_padding = ImGui::GetStyle().WindowPadding.x;
char buf[1024]; char buf[1024];
if (view_type == EViewType::Height || if (true)
view_type == EViewType::Width ||
view_type == EViewType::Feedrate ||
view_type == EViewType::VolumetricRate ||
view_type == EViewType::LayerTime ||
view_type == EViewType::LayerTimeLog ||
view_type == EViewType::FanSpeed ||
view_type == EViewType::Temperature)
{ {
float startx2 = window_padding + item_size + item_spacing;
float startx3 = window_padding + 2*(item_size + item_spacing);
sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x()); sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x());
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y()); sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y());
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
ImGui::SameLine(startx3);
sprintf(buf, "%s%.3f", z.c_str(), position.z()); sprintf(buf, "%s%.3f", z.c_str(), position.z());
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate);
ImGui::PushItemWidth(item_size);
imgui.text(buf);
switch (view_type) { switch (view_type) {
case EViewType::Height: { case EViewType::Height: {
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.2f", height.c_str(), m_curr_move.height); sprintf(buf, "%s%.2f", height.c_str(), m_curr_move.height);
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
break; break;
} }
case EViewType::Width: { case EViewType::Width: {
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.2f", width.c_str(), m_curr_move.width); sprintf(buf, "%s%.2f", width.c_str(), m_curr_move.width);
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
break; break;
} }
case EViewType::Feedrate: { // case EViewType::Feedrate: {
ImGui::SameLine(window_padding + item_size + item_spacing); // ImGui::SameLine(startx2);
sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate); // sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate);
ImGui::PushItemWidth(item_size); // ImGui::PushItemWidth(item_size);
imgui.text(buf); // imgui.text(buf);
break; // break;
} // }
case EViewType::VolumetricRate: { case EViewType::VolumetricRate: {
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.2f", flow.c_str(), m_curr_move.volumetric_rate()); sprintf(buf, "%s%.2f", flow.c_str(), m_curr_move.volumetric_rate());
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
break; break;
} }
case EViewType::FanSpeed: { case EViewType::FanSpeed: {
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.0f", fanspeed.c_str(), m_curr_move.fan_speed); sprintf(buf, "%s%.0f", fanspeed.c_str(), m_curr_move.fan_speed);
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
break; break;
} }
case EViewType::Temperature: { case EViewType::Temperature: {
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.0f", temperature.c_str(), m_curr_move.temperature); sprintf(buf, "%s%.0f", temperature.c_str(), m_curr_move.temperature);
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
@ -473,7 +473,7 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he
} }
case EViewType::LayerTime: case EViewType::LayerTime:
case EViewType::LayerTimeLog: { case EViewType::LayerTimeLog: {
ImGui::SameLine(window_padding + item_size + item_spacing); ImGui::SameLine(startx2);
sprintf(buf, "%s%.1f", layer_time.c_str(), m_curr_move.layer_duration); sprintf(buf, "%s%.1f", layer_time.c_str(), m_curr_move.layer_duration);
ImGui::PushItemWidth(item_size); ImGui::PushItemWidth(item_size);
imgui.text(buf); imgui.text(buf);
@ -484,27 +484,20 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he
} }
text_line = 2; text_line = 2;
} }
else { // else {
sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x()); // sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x());
ImGui::PushItemWidth(item_size); // imgui.text(buf);
imgui.text(buf);
ImGui::SameLine(window_padding + item_size + item_spacing); // ImGui::SameLine();
sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y()); // sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y());
ImGui::PushItemWidth(item_size); // imgui.text(buf);
imgui.text(buf);
sprintf(buf, "%s%.3f", z.c_str(), position.z()); // ImGui::SameLine();
ImGui::PushItemWidth(item_size); // sprintf(buf, "%s%.3f", z.c_str(), position.z());
imgui.text(buf); // imgui.text(buf);
ImGui::SameLine(window_padding + item_size + item_spacing); // text_line = 1;
sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate); // }
ImGui::PushItemWidth(item_size);
imgui.text(buf);
text_line = 1;
}
// force extra frame to automatically update window size // force extra frame to automatically update window size
float window_width = ImGui::GetWindowWidth(); float window_width = ImGui::GetWindowWidth();
@ -553,19 +546,22 @@ void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& fil
void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, float right, uint64_t curr_line_id) const void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, float right, uint64_t curr_line_id) const
//void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, uint64_t curr_line_id) const //void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, uint64_t curr_line_id) const
{ {
// Orca: truncate long lines(>55 characters), add "..." at the end
auto update_lines = [this](uint64_t start_id, uint64_t end_id) { auto update_lines = [this](uint64_t start_id, uint64_t end_id) {
std::vector<Line> ret; std::vector<Line> ret;
ret.reserve(end_id - start_id + 1); ret.reserve(end_id - start_id + 1);
for (uint64_t id = start_id; id <= end_id; ++id) { for (uint64_t id = start_id; id <= end_id; ++id) {
// read line from file // read line from file
const size_t start = id == 1 ? 0 : m_lines_ends[id - 2]; const size_t start = id == 1 ? 0 : m_lines_ends[id - 2];
const size_t len = m_lines_ends[id - 1] - start; const size_t original_len = m_lines_ends[id - 1] - start;
const size_t len = std::min(original_len, (size_t) 55);
std::string gline(m_file.data() + start, len); std::string gline(m_file.data() + start, len);
std::string command; // If original line is longer than 55 characters, truncate and append "..."
std::string parameters; if (original_len > 55)
std::string comment; gline = gline.substr(0, 52) + "...";
std::string command, parameters, comment;
// extract comment // extract comment
std::vector<std::string> tokens; std::vector<std::string> tokens;
boost::split(tokens, gline, boost::is_any_of(";"), boost::token_compress_on); boost::split(tokens, gline, boost::is_any_of(";"), boost::token_compress_on);
@ -717,11 +713,11 @@ void GCodeViewer::SequentialView::GCodeWindow::stop_mapping_file()
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished mapping file " << m_filename; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished mapping file " << m_filename;
} }
} }
//BBS: GUI refactor: move to the right void GCodeViewer::SequentialView::render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, int right_margin, const EViewType& view_type) const
void GCodeViewer::SequentialView::render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const
{ {
if (has_render_path) if (has_render_path)
marker.render(canvas_width, canvas_height, view_type); marker.render(canvas_width, canvas_height, view_type);
//float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height(); //float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height();
// BBS // BBS
#if 0 #if 0
@ -729,8 +725,7 @@ void GCodeViewer::SequentialView::render(const bool has_render_path, float legen
bottom -= wxGetApp().plater()->get_view_toolbar().get_height(); bottom -= wxGetApp().plater()->get_view_toolbar().get_height();
#endif #endif
if (has_render_path) if (has_render_path)
gcode_window.render(legend_height + 2, std::max(10.f, (float)canvas_height - 40), (float)canvas_width, gcode_window.render(legend_height + 2, std::max(10.f, (float)canvas_height - 40), (float)canvas_width - (float)right_margin, static_cast<uint64_t>(gcode_ids[current.last]));
static_cast<uint64_t>(gcode_ids[current.last]));
} }
const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors {{ const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors {{
@ -1000,10 +995,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
m_gcode_result = &gcode_result; m_gcode_result = &gcode_result;
m_only_gcode_in_preview = only_gcode; m_only_gcode_in_preview = only_gcode;
m_sequential_view.gcode_window.load_gcode(gcode_result.filename, m_sequential_view.gcode_window.load_gcode(gcode_result.filename, gcode_result.lines_ends);
// Stealing out lines_ends should be safe because this gcode_result is
// processed only once (see the 1st if in this function).
std::move(const_cast<std::vector<size_t> &>(gcode_result.lines_ends)));
//BBS: add only gcode mode //BBS: add only gcode mode
//if (wxGetApp().is_gcode_viewer()) //if (wxGetApp().is_gcode_viewer())
@ -1161,6 +1153,9 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v
for (auto item : m_tools.m_tool_visibles) item = true; for (auto item : m_tools.m_tool_visibles) item = true;
} }
for (int i = 0; i < m_tools.m_tool_colors.size(); i++) {
m_tools.m_tool_colors[i] = adjust_color_for_rendering(m_tools.m_tool_colors[i]);
}
// ensure there are enough colors defined // ensure there are enough colors defined
while (m_tools.m_tool_colors.size() < std::max(size_t(1), gcode_result.extruders_count)) { while (m_tools.m_tool_colors.size() < std::max(size_t(1), gcode_result.extruders_count)) {
m_tools.m_tool_colors.push_back(decode_color("#FF8000")); m_tools.m_tool_colors.push_back(decode_color("#FF8000"));
@ -1224,9 +1219,11 @@ void GCodeViewer::refresh_render_paths()
void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig *config) void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig *config)
{ {
if (config != nullptr) if (config != nullptr)
m_shells.volumes.update_colors_by_extruder(config); m_shells.volumes.update_colors_by_extruder(config, false);
} }
void GCodeViewer::set_shell_transparency(float alpha) { m_shells.volumes.set_transparency(alpha); }
//BBS: always load shell at preview //BBS: always load shell at preview
void GCodeViewer::reset_shell() void GCodeViewer::reset_shell()
{ {
@ -1281,15 +1278,15 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin)
m_statistics.total_instances_gpu_size = 0; m_statistics.total_instances_gpu_size = 0;
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
//BBS: always render shells in preview window
render_shells(); render_shells();
// Orca: add shell overlay effect
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
if (m_roles.empty()) if (m_roles.empty())
return; return;
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
render_toolpaths(); render_toolpaths();
//render_shells();
float legend_height = 0.0f; float legend_height = 0.0f;
render_legend(legend_height, canvas_width, canvas_height, right_margin); render_legend(legend_height, canvas_width, canvas_height, right_margin);
@ -1299,7 +1296,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin)
} }
//BBS fixed bottom_margin for space to render horiz slider //BBS fixed bottom_margin for space to render horiz slider
int bottom_margin = 64; int bottom_margin = 39;
m_sequential_view.m_show_gcode_window = m_sequential_view.m_show_gcode_window =
m_sequential_view.m_show_gcode_window || m_sequential_view.m_show_gcode_window ||
(m_sequential_view.current.last != m_sequential_view.endpoints.last && !m_no_render_path); (m_sequential_view.current.last != m_sequential_view.endpoints.last && !m_no_render_path);
@ -1307,7 +1304,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin)
m_sequential_view.marker.set_world_position(m_sequential_view.current_position); m_sequential_view.marker.set_world_position(m_sequential_view.current_position);
m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset);
//BBS fixed buttom margin. m_moves_slider.pos_y //BBS fixed buttom margin. m_moves_slider.pos_y
m_sequential_view.render(!m_no_render_path, legend_height, canvas_width - right_margin * m_scale, canvas_height - bottom_margin * m_scale, m_view_type); m_sequential_view.render(!m_no_render_path, legend_height, canvas_width, canvas_height - bottom_margin * m_scale, right_margin * m_scale, m_view_type);
} }
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
render_statistics(); render_statistics();
@ -3840,7 +3837,7 @@ void GCodeViewer::render_toolpaths()
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
this this
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
](std::vector<RenderPath>::iterator it_path, std::vector<RenderPath>::iterator it_end, GLShaderProgram& shader, int uniform_color) { ](std::vector<RenderPath>::reverse_iterator it_path, std::vector<RenderPath>::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) {
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
glsafe(::glEnable(GL_POINT_SPRITE)); glsafe(::glEnable(GL_POINT_SPRITE));
@ -3867,7 +3864,7 @@ void GCodeViewer::render_toolpaths()
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
this this
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
](std::vector<RenderPath>::iterator it_path, std::vector<RenderPath>::iterator it_end, GLShaderProgram& shader, int uniform_color) { ](std::vector<RenderPath>::reverse_iterator it_path, std::vector<RenderPath>::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) {
for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) {
const RenderPath& path = *it; const RenderPath& path = *it;
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
@ -3885,7 +3882,7 @@ void GCodeViewer::render_toolpaths()
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
this this
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
](std::vector<RenderPath>::iterator it_path, std::vector<RenderPath>::iterator it_end, GLShaderProgram& shader, int uniform_color) { ](std::vector<RenderPath>::reverse_iterator it_path, std::vector<RenderPath>::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) {
for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) {
const RenderPath& path = *it; const RenderPath& path = *it;
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
@ -4015,13 +4012,15 @@ void GCodeViewer::render_toolpaths()
default: break; default: break;
} }
int uniform_color = shader->get_uniform_location("uniform_color"); int uniform_color = shader->get_uniform_location("uniform_color");
auto it_path = buffer.render_paths.begin(); auto it_path = buffer.render_paths.rbegin();
//BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":buffer indices size %1%, render_path size %2% ")%buffer.indices.size() %buffer.render_paths.size(); //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":buffer indices size %1%, render_path size %2% ")%buffer.indices.size() %buffer.render_paths.size();
for (unsigned int ibuffer_id = 0; ibuffer_id < static_cast<unsigned int>(buffer.indices.size()); ++ibuffer_id) { unsigned int indices_count = static_cast<unsigned int>(buffer.indices.size());
for (unsigned int index = 0; index < indices_count; ++index) {
unsigned int ibuffer_id = indices_count - index - 1;
const IBuffer& i_buffer = buffer.indices[ibuffer_id]; const IBuffer& i_buffer = buffer.indices[ibuffer_id];
// Skip all paths with ibuffer_id < ibuffer_id. // Skip all paths with ibuffer_id < ibuffer_id.
for (; it_path != buffer.render_paths.end() && it_path->ibuffer_id < ibuffer_id; ++ it_path) ; for (; it_path != buffer.render_paths.rend() && it_path->ibuffer_id > ibuffer_id; ++ it_path) ;
if (it_path == buffer.render_paths.end() || it_path->ibuffer_id > ibuffer_id) if (it_path == buffer.render_paths.rend() || it_path->ibuffer_id < ibuffer_id)
// Not found. This shall not happen. // Not found. This shall not happen.
continue; continue;
@ -4040,16 +4039,16 @@ void GCodeViewer::render_toolpaths()
switch (buffer.render_primitive_type) switch (buffer.render_primitive_type)
{ {
case TBuffer::ERenderPrimitiveType::Point: { case TBuffer::ERenderPrimitiveType::Point: {
render_as_points(it_path, buffer.render_paths.end(), *shader, uniform_color); render_as_points(it_path, buffer.render_paths.rend(), *shader, uniform_color);
break; break;
} }
case TBuffer::ERenderPrimitiveType::Line: { case TBuffer::ERenderPrimitiveType::Line: {
glsafe(::glLineWidth(static_cast<GLfloat>(line_width(zoom)))); glsafe(::glLineWidth(static_cast<GLfloat>(line_width(zoom))));
render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color); render_as_lines(it_path, buffer.render_paths.rend(), *shader, uniform_color);
break; break;
} }
case TBuffer::ERenderPrimitiveType::Triangle: { case TBuffer::ERenderPrimitiveType::Triangle: {
render_as_triangles(it_path, buffer.render_paths.end(), *shader, uniform_color); render_as_triangles(it_path, buffer.render_paths.rend(), *shader, uniform_color);
break; break;
} }
default: { break; } default: { break; }
@ -4172,6 +4171,10 @@ void GCodeViewer::render_all_plates_stats(const std::vector<const GCodeProcessor
std::vector<float> filament_densities = gcode_result_list.front()->filament_densities; std::vector<float> filament_densities = gcode_result_list.front()->filament_densities;
std::vector<Color> filament_colors = decode_colors(wxGetApp().plater()->get_extruder_colors_from_plater_config(gcode_result_list.back())); std::vector<Color> filament_colors = decode_colors(wxGetApp().plater()->get_extruder_colors_from_plater_config(gcode_result_list.back()));
for (int i = 0; i < filament_colors.size(); i++) {
filament_colors[i] = adjust_color_for_rendering(filament_colors[i]);
}
bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; bool imperial_units = wxGetApp().app_config->get("use_inches") == "1";
float window_padding = 4.0f * m_scale; float window_padding = 4.0f * m_scale;
const float icon_size = ImGui::GetTextLineHeight() * 0.7; const float icon_size = ImGui::GetTextLineHeight() * 0.7;
@ -4315,18 +4318,20 @@ void GCodeViewer::render_all_plates_stats(const std::vector<const GCodeProcessor
columns_offsets.push_back({ std::to_string(it->first + 1), offsets[0] }); columns_offsets.push_back({ std::to_string(it->first + 1), offsets[0] });
char buf[64]; char buf[64];
double unit_conver = imperial_units ? GizmoObjectManipulation::oz_to_g : 1.0;
if (show_detailed_statistics_page) { if (show_detailed_statistics_page) {
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i]); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i] / unit_conver);
columns_offsets.push_back({ buf, offsets[1] }); columns_offsets.push_back({ buf, offsets[1] });
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m_all_plates[i], flushed_filaments_g_all_plates[i]); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m_all_plates[i], flushed_filaments_g_all_plates[i] / unit_conver);
columns_offsets.push_back({ buf, offsets[2] }); columns_offsets.push_back({ buf, offsets[2] });
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m_all_plates[i] + flushed_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i] + flushed_filaments_g_all_plates[i]); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", (model_used_filaments_m_all_plates[i] + flushed_filaments_m_all_plates[i]),
(model_used_filaments_g_all_plates[i] + flushed_filaments_g_all_plates[i]) / unit_conver);
columns_offsets.push_back({ buf, offsets[3] }); columns_offsets.push_back({ buf, offsets[3] });
} }
else { else {
::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i]); ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i] / unit_conver);
columns_offsets.push_back({ buf, offsets[2] }); columns_offsets.push_back({ buf, offsets[2] });
} }
@ -4949,7 +4954,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
columns_offsets.push_back({ std::to_string(extruder_idx + 1), offsets[0] }); columns_offsets.push_back({ std::to_string(extruder_idx + 1), offsets[0] });
char buf[64]; char buf[64];
::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[0] , model_used_filaments_g[0]); ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[0], model_used_filaments_g[0] / unit_conver);
columns_offsets.push_back({ buf, offsets[2] }); columns_offsets.push_back({ buf, offsets[2] });
append_item(EItemType::Rect, m_tools.m_tool_colors[extruder_idx], columns_offsets, false); append_item(EItemType::Rect, m_tools.m_tool_colors[extruder_idx], columns_offsets, false);
@ -4983,18 +4988,19 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
char buf[64]; char buf[64];
if (show_flushed_filaments) { if (show_flushed_filaments) {
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m[i], model_used_filaments_g[i]); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m[i], model_used_filaments_g[i] / unit_conver);
columns_offsets.push_back({ buf, offsets[1] }); columns_offsets.push_back({ buf, offsets[1] });
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m[i], flushed_filaments_g[i]); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m[i], flushed_filaments_g[i] / unit_conver);
columns_offsets.push_back({ buf, offsets[2] }); columns_offsets.push_back({ buf, offsets[2] });
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m[i] + flushed_filaments_m[i], model_used_filaments_g[i] + flushed_filaments_g[i]); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", (model_used_filaments_m[i] + flushed_filaments_m[i]),
(model_used_filaments_g[i] + flushed_filaments_g[i]) / unit_conver);
columns_offsets.push_back({ buf, offsets[3] }); columns_offsets.push_back({ buf, offsets[3] });
} }
else { else {
char buf[64]; char buf[64];
::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[i], model_used_filaments_g[i]); ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[i], model_used_filaments_g[i] / unit_conver);
columns_offsets.push_back({buf, offsets[2]}); columns_offsets.push_back({buf, offsets[2]});
} }
@ -5044,20 +5050,20 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
std::vector<std::pair<std::string, float>> columns_offsets; std::vector<std::pair<std::string, float>> columns_offsets;
columns_offsets.push_back({ _u8L("Total"), offsets[0] }); columns_offsets.push_back({ _u8L("Total"), offsets[0] });
if (!show_flushed_filaments) { if (!show_flushed_filaments) {
::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", total_model_used_filament_m, total_model_used_filament_g); ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", total_model_used_filament_m, total_model_used_filament_g / unit_conver);
columns_offsets.push_back({ buf, offsets[2] }); columns_offsets.push_back({ buf, offsets[2] });
append_item(EItemType::None, m_tools.m_tool_colors[0], columns_offsets); append_item(EItemType::None, m_tools.m_tool_colors[0], columns_offsets);
} }
else { else {
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_model_used_filament_m, total_model_used_filament_g); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_model_used_filament_m, total_model_used_filament_g / unit_conver);
columns_offsets.push_back({ buf, offsets[1] }); columns_offsets.push_back({ buf, offsets[1] });
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_flushed_filament_m, total_flushed_filament_g); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_flushed_filament_m, total_flushed_filament_g / unit_conver);
columns_offsets.push_back({ buf, offsets[2] }); columns_offsets.push_back({ buf, offsets[2] });
bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; bool imperial_units = wxGetApp().app_config->get("use_inches") == "1";
::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", (total_model_used_filament_m + total_flushed_filament_m) * 1000 / /*1000*/koef, (total_model_used_filament_g + total_flushed_filament_g) / unit_conver); ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_model_used_filament_m + total_flushed_filament_m, (total_model_used_filament_g + total_flushed_filament_g) / unit_conver);
columns_offsets.push_back({ buf, offsets[3] }); columns_offsets.push_back({ buf, offsets[3] });
append_item(EItemType::None, m_tools.m_tool_colors[0], columns_offsets); append_item(EItemType::None, m_tools.m_tool_colors[0], columns_offsets);
@ -5712,3 +5718,4 @@ GCodeViewer::Color GCodeViewer::option_color(EMoveType move_type) const
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r

View file

@ -408,7 +408,7 @@ class GCodeViewer
min = std::min(min, value); min = std::min(min, value);
max = std::max(max, value); max = std::max(max, value);
} }
void reset(bool log = false) { min = FLT_MAX; max = -FLT_MAX; count = 0; log_scale = false; log_scale = log; } void reset(bool log = false) { min = FLT_MAX; max = -FLT_MAX; count = 0; log_scale = log; }
float step_size() const; float step_size() const;
Color get_color_at(float value) const; Color get_color_at(float value) const;
@ -492,7 +492,7 @@ class GCodeViewer
std::vector<Endpoints>& get_endpoints() { return m_endpoints; } std::vector<Endpoints>& get_endpoints() { return m_endpoints; }
double get_z_at(unsigned int id) const { return (id < m_zs.size()) ? m_zs[id] : 0.0; } double get_z_at(unsigned int id) const { return (id < m_zs.size()) ? m_zs[id] : 0.0; }
Endpoints get_endpoints_at(unsigned int id) const { return (id < m_endpoints.size()) ? m_endpoints[id] : Endpoints(); } Endpoints get_endpoints_at(unsigned int id) const { return (id < m_endpoints.size()) ? m_endpoints[id] : Endpoints(); }
int get_l_at(double z) const int get_l_at(float z) const
{ {
auto iter = std::upper_bound(m_zs.begin(), m_zs.end(), z); auto iter = std::upper_bound(m_zs.begin(), m_zs.end(), z);
return std::distance(m_zs.begin(), iter); return std::distance(m_zs.begin(), iter);
@ -640,7 +640,6 @@ public:
bool is_visible() const { return m_visible; } bool is_visible() const { return m_visible; }
void set_visible(bool visible) { m_visible = visible; } void set_visible(bool visible) { m_visible = visible; }
//BBS: GUI refactor: add canvas size
void render(int canvas_width, int canvas_height, const EViewType& view_type) const; void render(int canvas_width, int canvas_height, const EViewType& view_type) const;
void on_change_color_mode(bool is_dark) { m_is_dark = is_dark; } void on_change_color_mode(bool is_dark) { m_is_dark = is_dark; }
@ -708,8 +707,7 @@ public:
std::vector<unsigned int> gcode_ids; std::vector<unsigned int> gcode_ids;
float m_scale = 1.0; float m_scale = 1.0;
bool m_show_gcode_window = false; bool m_show_gcode_window = false;
//BBS: GUI refactor: add canvas size void render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, int right_margin, const EViewType& view_type) const;
void render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const;
}; };
struct ETools struct ETools
@ -737,7 +735,6 @@ public:
//BBS //BBS
ConflictResultOpt m_conflict_result; ConflictResultOpt m_conflict_result;
private: private:
std::vector<int> m_plater_extruder; std::vector<int> m_plater_extruder;
bool m_gl_data_initialized{ false }; bool m_gl_data_initialized{ false };
@ -816,6 +813,7 @@ public:
void refresh(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors); void refresh(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors);
void refresh_render_paths(); void refresh_render_paths();
void update_shells_color_by_extruder(const DynamicPrintConfig* config); void update_shells_color_by_extruder(const DynamicPrintConfig* config);
void set_shell_transparency(float alpha = 0.15f);
void reset(); void reset();
//BBS: always load shell at preview //BBS: always load shell at preview

View file

@ -17,6 +17,7 @@
#include "slic3r/GUI/3DBed.hpp" #include "slic3r/GUI/3DBed.hpp"
#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/3DScene.hpp"
#include "slic3r/GUI/BackgroundSlicingProcess.hpp" #include "slic3r/GUI/BackgroundSlicingProcess.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/GLShader.hpp" #include "slic3r/GUI/GLShader.hpp"
#include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/Tab.hpp" #include "slic3r/GUI/Tab.hpp"
@ -2753,7 +2754,6 @@ static void reserve_new_volume_finalize_old_volume(GLVolume& vol_new, GLVolume&
vol_old.finalize_geometry(gl_initialized); vol_old.finalize_geometry(gl_initialized);
} }
//BBS: always load shell at preview
void GLCanvas3D::load_shells(const Print& print, bool force_previewing) void GLCanvas3D::load_shells(const Print& print, bool force_previewing)
{ {
if (m_initialized) if (m_initialized)
@ -2763,6 +2763,10 @@ void GLCanvas3D::load_shells(const Print& print, bool force_previewing)
} }
} }
void GLCanvas3D::set_shell_transparence(float alpha){
m_gcode_viewer.set_shell_transparency(alpha);
}
//BBS: add only gcode mode //BBS: add only gcode mode
void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors, bool only_gcode) void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors, bool only_gcode)
{ {

View file

@ -900,7 +900,8 @@ public:
void mirror_selection(Axis axis); void mirror_selection(Axis axis);
void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false); void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false);
//BBS: always load shell at preview //Orca: shell preview improvement
void set_shell_transparence(float alpha = 0.2f);
void load_shells(const Print& print, bool force_previewing = false); void load_shells(const Print& print, bool force_previewing = false);
void reset_shells() { m_gcode_viewer.reset_shell(); } void reset_shells() { m_gcode_viewer.reset_shell(); }
void set_shells_on_previewing(bool is_preview) { m_gcode_viewer.set_shells_on_preview(is_preview); } void set_shells_on_previewing(bool is_preview) { m_gcode_viewer.set_shells_on_preview(is_preview); }

View file

@ -717,8 +717,9 @@ void Preview::load_print_as_fff(bool keep_z_range, bool only_gcode)
//BBS show sliders //BBS show sliders
show_moves_sliders(); show_moves_sliders();
//BBS: turn off shells for preview //Orca: keep shell preview on but make it more transparent
m_canvas->set_shells_on_previewing(false); m_canvas->set_shells_on_previewing(true);
m_canvas->set_shell_transparence();
Refresh(); Refresh();
zs = m_canvas->get_gcode_layers_zs(); zs = m_canvas->get_gcode_layers_zs();
//BBS: add m_loaded_print logic //BBS: add m_loaded_print logic