Bugfixes (#2)

* Bugfixes

* Reduce size of diff

to avoid merge conflicts when we cherry-pick from upstream :)

* remove extraneous space

---------

Co-authored-by: Andrew Sun <as-com@users.noreply.github.com>
This commit is contained in:
Kiss Lorand 2025-11-19 02:50:48 +02:00 committed by GitHub
parent 2440d669f0
commit a87df7f0b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 42 additions and 84 deletions

View file

@ -35,26 +35,15 @@
// Enable rework of Reload from disk command
#define ENABLE_RELOAD_FROM_DISK_REWORK 1
//====================
// 2.4.0.beta1 techs
//====================
#define ENABLE_2_4_0_BETA1 1
// Enable rendering modifiers and similar objects always as transparent
#define ENABLE_MODIFIERS_ALWAYS_TRANSPARENT (1 && ENABLE_2_4_0_BETA1)
//====================
// 2.4.0.beta2 techs
//====================
#define ENABLE_2_4_0_BETA2 1
#define ENABLE_MODIFIERS_ALWAYS_TRANSPARENT 1
// Enable modified ImGuiWrapper::slider_float() to create a compound widget where
// an additional button can be used to set the keyboard focus into the slider
// to allow the user to type in the desired value
#define ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT (1 && ENABLE_2_4_0_BETA2)
#define ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT 1
// Enable fit print volume command for circular printbeds
#define ENABLE_ENHANCED_PRINT_VOLUME_FIT (1 && ENABLE_2_4_0_BETA2)
#define ENABLE_ENHANCED_PRINT_VOLUME_FIT 1
// Enable picking using raytracing
#define ENABLE_RAYCAST_PICKING_DEBUG 0

View file

@ -81,18 +81,18 @@ enum class EViewType : uint8_t
{
Summary, // ORCA
FeatureType,
Height,
Width,
ColorPrint,
Speed,
ActualSpeed,
FanSpeed,
Temperature,
Height,
Width,
VolumetricFlowRate,
ActualVolumetricFlowRate,
LayerTimeLinear,
LayerTimeLogarithmic,
FanSpeed,
Temperature,
Tool,
ColorPrint,
COUNT
};

View file

@ -526,7 +526,6 @@ void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& fil
//BBS: GUI refactor: move to right
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
{
// Orca: truncate long lines(>55 characters), add "..." at the end
auto update_lines = [this](uint64_t start_id, uint64_t end_id) {
@ -684,6 +683,14 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, f
}
imgui.end();
#if ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
imgui.set_requires_extra_frame();
#else
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
#endif
ImGui::PopStyleVar();
}
@ -770,6 +777,17 @@ void GCodeViewer::init(ConfigOptionMode mode, PresetBundle* preset_bundle)
m_gl_data_initialized = true;
try
{
m_viewer.init(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
glcheck();
}
catch (const std::exception& e)
{
MessageDialog msg_dlg(wxGetApp().plater(), e.what(), _L("Error"), wxICON_ERROR | wxOK);
msg_dlg.ShowModal();
}
if (preset_bundle)
m_nozzle_nums = preset_bundle->get_printer_extruder_count();
@ -782,16 +800,6 @@ void GCodeViewer::init(ConfigOptionMode mode, PresetBundle* preset_bundle)
set_view_type(libvgcode::EViewType::ColorPrint);
}
try
{
m_viewer.init(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
glcheck();
}
catch (const std::exception& e)
{
MessageDialog msg_dlg(wxGetApp().plater(), e.what(), _L("Error"), wxICON_ERROR | wxOK);
msg_dlg.ShowModal();
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": finished");
}
@ -1169,9 +1177,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const
}
}
enable_view_type_cache_load(false);
set_view_type(libvgcode::EViewType::ColorPrint);
enable_view_type_cache_load(true);
}
bool only_gcode_3mf = false;
@ -3093,12 +3099,15 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
if (ImGui::BBLSelectable(view_type_items_str[i].c_str(), is_selected)) {
m_fold = false;
m_view_type_sel = i;
enable_view_type_cache_load(false);
set_view_type(view_type_items[m_view_type_sel]);
enable_view_type_cache_load(true);
reset_visible(view_type_items[m_view_type_sel]);
update_moves_slider();
#if ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
imgui.set_requires_extra_frame();
#else
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
#endif
}
if (is_selected) {
ImGui::SetItemDefaultFocus();
@ -3362,7 +3371,6 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
append_item(EItemType::Rect, color, {{ label , offsets[0] }}, true, offsets.back()/*ORCA checkbox_pos*/, visible, [this, type, visible]() {
m_viewer.toggle_option_visibility(type);
update_moves_slider();
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
});
};
const bool visible = m_viewer.is_option_visible(type);
@ -3405,7 +3413,6 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
true, offsets.back(), visible, [this, role, visible]() {
m_viewer.toggle_extrusion_role_visibility(role);
update_moves_slider();
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
});
}
@ -3423,7 +3430,6 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_option_color(libvgcode::EOptionType::Travels)), columns_offsets, true, offsets.back()/*ORCA checkbox_pos*/, visible, [this, item, visible]() {
m_viewer.toggle_option_visibility(item);
update_moves_slider();
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
});
}
}
@ -3444,7 +3450,6 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
m_viewer.toggle_option_visibility(libvgcode::EOptionType::Travels);
// refresh(*m_gcode_result, wxGetApp().plater()->get_extruder_colors_from_plater_config(m_gcode_result));
update_moves_slider();
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
});
ImGui::PopStyleVar(1);
break;
@ -3462,7 +3467,6 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
m_viewer.toggle_option_visibility(libvgcode::EOptionType::Travels);
// refresh(*m_gcode_result, wxGetApp().plater()->get_extruder_colors_from_plater_config(m_gcode_result));
update_moves_slider();
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
});
ImGui::PopStyleVar(1);
break;
@ -4047,7 +4051,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
std::string prepare_str = _u8L("Prepare time");
std::string print_str = _u8L("Model printing time");
std::string total_str = _u8L("Total time");
float max_len = window_padding + 2 * ImGui::GetStyle().ItemSpacing.x;
float max_len = window_padding + 2 * ImGui::GetStyle().ItemSpacing.x;
if (m_viewer.get_layers_estimated_times().empty())
max_len += ImGui::CalcTextSize(total_str.c_str()).x;
else {
@ -4120,7 +4124,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
imgui.set_requires_extra_frame();
#else
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
#endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
}
}

View file

@ -225,13 +225,6 @@ private:
bool m_legend_visible{ true };
bool m_legend_enabled{ true };
struct ViewTypeCache
{
bool write{ false };
bool load{ false };
libvgcode::EViewType value{ libvgcode::EViewType::FeatureType };
};
ViewTypeCache m_view_type_cache;
float m_legend_height;
PrintEstimatedStatistics m_print_statistics;
@ -318,10 +311,7 @@ public:
bool is_only_gcode_in_preview() const { return m_only_gcode_in_preview; }
void set_view_type(libvgcode::EViewType type) {
m_viewer.set_view_type((m_view_type_cache.load && m_view_type_cache.value != type) ? m_view_type_cache.value : type);
const libvgcode::EViewType view_type = get_view_type();
if (m_view_type_cache.write && m_view_type_cache.value != view_type)
m_view_type_cache.value = view_type;
m_viewer.set_view_type(type);
}
void reset_visible(libvgcode::EViewType type) {
if (type == libvgcode::EViewType::FeatureType) {
@ -336,10 +326,7 @@ public:
}
libvgcode::EViewType get_view_type() const { return m_viewer.get_view_type(); }
void enable_view_type_cache_load(bool enable) { m_view_type_cache.load = enable; }
void enable_view_type_cache_write(bool enable) { m_view_type_cache.write = enable; }
bool is_view_type_cache_load_enabled() const { return m_view_type_cache.load; }
bool is_view_type_cache_write_enabled() const { return m_view_type_cache.write; }
void set_layers_z_range(const std::array<unsigned int, 2>& layers_z_range);
bool is_legend_shown() const { return m_legend_visible && m_legend_enabled; }

View file

@ -3041,9 +3041,8 @@ void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, co
//when load gcode directly, it is too late
m_gcode_viewer.init(wxGetApp().get_mode(), wxGetApp().preset_bundle);
m_gcode_viewer.enable_legend(true);
m_gcode_viewer.enable_view_type_cache_write(true);
m_gcode_viewer.enable_view_type_cache_load(true);
m_gcode_viewer.set_view_type(m_gcode_viewer.get_view_type());
m_gcode_viewer.load_as_gcode(gcode_result, *this->fff_print(), str_tool_colors, str_color_print_colors, wxGetApp().plater()->build_volume(), exclude_bounding_box,
wxGetApp().get_mode(), only_gcode);
m_gcode_layers_times_cache = m_gcode_viewer.get_layers_times();
@ -3072,27 +3071,6 @@ void GLCanvas3D::load_sla_preview()
}
}
/*void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<std::string>& str_color_print_colors,
const std::vector<CustomGCode::Item>& color_print_values)
{
const Print *print = this->fff_print();
if (print == nullptr)
return;
_set_current();
libvgcode::GCodeInputData data = libvgcode::convert(*print, str_tool_colors, str_color_print_colors, color_print_values,
static_cast<size_t>(wxGetApp().extruders_edited_cnt()));
// send data to the viewer
m_gcode_viewer.enable_legend(false);
m_gcode_viewer.enable_view_type_cache_write(false);
m_gcode_viewer.enable_view_type_cache_load(false);
m_gcode_viewer.set_view_type(libvgcode::EViewType::FeatureType);
m_gcode_viewer.load_as_preview(std::move(data));
_set_warning_notification_if_needed(EWarning::ToolpathOutside);
}*/
void GLCanvas3D::bind_event_handlers()
{
if (m_canvas != nullptr) {

View file

@ -1014,10 +1014,6 @@ public:
const std::vector<std::string>& str_color_print_colors, bool only_gcode);
void set_gcode_view_type(libvgcode::EViewType type) { return m_gcode_viewer.set_view_type(type); }
libvgcode::EViewType get_gcode_view_type() const { return m_gcode_viewer.get_view_type(); }
void enable_gcode_view_type_cache_load(bool enable) { m_gcode_viewer.enable_view_type_cache_load(enable); }
void enable_gcode_view_type_cache_write(bool enable) { m_gcode_viewer.enable_view_type_cache_write(enable); }
bool is_gcode_view_type_cache_load_enabled() const { return m_gcode_viewer.is_view_type_cache_load_enabled(); }
bool is_gcode_view_type_cache_write_enabled() const { return m_gcode_viewer.is_view_type_cache_write_enabled(); }
void load_sla_preview();
void bind_event_handlers();

View file

@ -1468,6 +1468,8 @@ void IMSlider::on_mouse_wheel(wxMouseEvent& evt) {
return;
}
ImGuiWrapper& imgui = *wxGetApp().imgui();
float wheel = 0.0f;
wheel = evt.GetWheelRotation() > 0 ? 1.0f : -1.0f;
if (wheel == 0.0f)
@ -1492,6 +1494,7 @@ void IMSlider::on_mouse_wheel(wxMouseEvent& evt) {
const int new_pos = GetHigherValue() + wheel;
SetHigherValue(new_pos);
set_as_dirty();
imgui.set_requires_extra_frame();
}
}
else {
@ -1509,6 +1512,7 @@ void IMSlider::on_mouse_wheel(wxMouseEvent& evt) {
m_selection == ssLower ? SetLowerValue(new_pos) : SetHigherValue(new_pos);
}
set_as_dirty();
imgui.set_requires_extra_frame();
}
}
}