Reworked management of bed shape changes (may fix #1671)

This commit is contained in:
Enrico Turri 2019-01-17 13:21:33 +01:00
parent e8d63f3eb1
commit aa7ff0700b
5 changed files with 54 additions and 3 deletions

View file

@ -60,3 +60,5 @@
#define ENABLE_MOVE_MIN_THRESHOLD (1 && ENABLE_1_42_0_ALPHA4) #define ENABLE_MOVE_MIN_THRESHOLD (1 && ENABLE_1_42_0_ALPHA4)
// Modified initial default placement of generic subparts // Modified initial default placement of generic subparts
#define ENABLE_GENERIC_SUBPARTS_PLACEMENT (1 && ENABLE_1_42_0_ALPHA4) #define ENABLE_GENERIC_SUBPARTS_PLACEMENT (1 && ENABLE_1_42_0_ALPHA4)
// Reworked management of bed shape changes
#define ENABLE_REWORKED_BED_SHAPE_CHANGE (1 && ENABLE_1_42_0_ALPHA4)

View file

@ -3718,7 +3718,11 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
, m_dirty(true) , m_dirty(true)
, m_initialized(false) , m_initialized(false)
, m_use_VBOs(false) , m_use_VBOs(false)
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
, m_requires_zoom_to_bed(false)
#else
, m_force_zoom_to_bed_enabled(false) , m_force_zoom_to_bed_enabled(false)
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
, m_apply_zoom_to_volumes_filter(false) , m_apply_zoom_to_volumes_filter(false)
, m_hover_volume_id(-1) , m_hover_volume_id(-1)
, m_toolbar_action_running(false) , m_toolbar_action_running(false)
@ -3937,7 +3941,11 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape)
set_bed_axes_length(0.1 * m_bed.get_bounding_box().max_size()); set_bed_axes_length(0.1 * m_bed.get_bounding_box().max_size());
if (new_shape) if (new_shape)
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
m_requires_zoom_to_bed = true;
#else
zoom_to_bed(); zoom_to_bed();
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
m_dirty = true; m_dirty = true;
} }
@ -4032,10 +4040,12 @@ void GLCanvas3D::enable_toolbar(bool enable)
m_toolbar.set_enabled(enable); m_toolbar.set_enabled(enable);
} }
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
void GLCanvas3D::enable_force_zoom_to_bed(bool enable) void GLCanvas3D::enable_force_zoom_to_bed(bool enable)
{ {
m_force_zoom_to_bed_enabled = enable; m_force_zoom_to_bed_enabled = enable;
} }
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
void GLCanvas3D::enable_dynamic_background(bool enable) void GLCanvas3D::enable_dynamic_background(bool enable)
{ {
@ -4116,6 +4126,9 @@ void GLCanvas3D::set_viewport_from_scene(const GLCanvas3D& other)
m_camera.set_scene_box(other.m_camera.get_scene_box(), *this); m_camera.set_scene_box(other.m_camera.get_scene_box(), *this);
m_camera.set_target(other.m_camera.get_target(), *this); m_camera.set_target(other.m_camera.get_target(), *this);
m_camera.zoom = other.m_camera.zoom; m_camera.zoom = other.m_camera.zoom;
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
m_requires_zoom_to_bed = false;
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
m_dirty = true; m_dirty = true;
} }
@ -4168,8 +4181,18 @@ void GLCanvas3D::render()
#endif // ENABLE_USE_UNIQUE_GLCONTEXT #endif // ENABLE_USE_UNIQUE_GLCONTEXT
return; return;
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
if (m_requires_zoom_to_bed)
{
zoom_to_bed();
const Size& cnv_size = get_canvas_size();
_resize((unsigned int)cnv_size.get_width(), (unsigned int)cnv_size.get_height());
m_requires_zoom_to_bed = false;
}
#else
if (m_force_zoom_to_bed_enabled) if (m_force_zoom_to_bed_enabled)
_force_zoom_to_bed(); _force_zoom_to_bed();
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
_camera_tranform(); _camera_tranform();
@ -5738,11 +5761,13 @@ bool GLCanvas3D::_is_shown_on_screen() const
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false; return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
} }
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
void GLCanvas3D::_force_zoom_to_bed() void GLCanvas3D::_force_zoom_to_bed()
{ {
zoom_to_bed(); zoom_to_bed();
m_force_zoom_to_bed_enabled = false; m_force_zoom_to_bed_enabled = false;
} }
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
bool GLCanvas3D::_init_toolbar() bool GLCanvas3D::_init_toolbar()
{ {
@ -5974,7 +5999,11 @@ void GLCanvas3D::_zoom_to_bounding_box(const BoundingBoxf3& bbox)
viewport_changed(); viewport_changed();
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
m_dirty = true;
#else
_refresh_if_shown_on_screen(); _refresh_if_shown_on_screen();
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
} }
} }
@ -6076,11 +6105,15 @@ void GLCanvas3D::_refresh_if_shown_on_screen()
// Because of performance problems on macOS, where PaintEvents are not delivered // Because of performance problems on macOS, where PaintEvents are not delivered
// frequently enough, we call render() here directly when we can. // frequently enough, we call render() here directly when we can.
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
render();
#else
// We can't do that when m_force_zoom_to_bed_enabled == true, because then render() // We can't do that when m_force_zoom_to_bed_enabled == true, because then render()
// ends up calling back here via _force_zoom_to_bed(), causing a stack overflow. // ends up calling back here via _force_zoom_to_bed(), causing a stack overflow.
if (m_canvas != nullptr) { if (m_canvas != nullptr) {
m_force_zoom_to_bed_enabled ? m_canvas->Refresh() : render(); m_force_zoom_to_bed_enabled ? m_canvas->Refresh() : render();
} }
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
} }
} }

View file

@ -829,7 +829,11 @@ private:
bool m_dirty; bool m_dirty;
bool m_initialized; bool m_initialized;
bool m_use_VBOs; bool m_use_VBOs;
#if ENABLE_REWORKED_BED_SHAPE_CHANGE
bool m_requires_zoom_to_bed;
#else
bool m_force_zoom_to_bed_enabled; bool m_force_zoom_to_bed_enabled;
#endif // ENABLE_REWORKED_BED_SHAPE_CHANGE
bool m_apply_zoom_to_volumes_filter; bool m_apply_zoom_to_volumes_filter;
mutable int m_hover_volume_id; mutable int m_hover_volume_id;
bool m_toolbar_action_running; bool m_toolbar_action_running;
@ -920,7 +924,9 @@ public:
void enable_moving(bool enable); void enable_moving(bool enable);
void enable_gizmos(bool enable); void enable_gizmos(bool enable);
void enable_toolbar(bool enable); void enable_toolbar(bool enable);
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
void enable_force_zoom_to_bed(bool enable); void enable_force_zoom_to_bed(bool enable);
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
void enable_dynamic_background(bool enable); void enable_dynamic_background(bool enable);
void allow_multisample(bool allow); void allow_multisample(bool allow);
@ -1001,7 +1007,9 @@ public:
private: private:
bool _is_shown_on_screen() const; bool _is_shown_on_screen() const;
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
void _force_zoom_to_bed(); void _force_zoom_to_bed();
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
bool _init_toolbar(); bool _init_toolbar();

View file

@ -69,7 +69,9 @@ bool View3D::init(wxWindow* parent, Model* model, DynamicPrintConfig* config, Ba
m_canvas->set_config(config); m_canvas->set_config(config);
m_canvas->enable_gizmos(true); m_canvas->enable_gizmos(true);
m_canvas->enable_toolbar(true); m_canvas->enable_toolbar(true);
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
m_canvas->enable_force_zoom_to_bed(true); m_canvas->enable_force_zoom_to_bed(true);
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
#if !ENABLE_IMGUI #if !ENABLE_IMGUI
m_gizmo_widget = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_gizmo_widget = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
@ -107,7 +109,9 @@ void View3D::set_bed_shape(const Pointfs& shape)
if (m_canvas != nullptr) if (m_canvas != nullptr)
{ {
m_canvas->set_bed_shape(shape); m_canvas->set_bed_shape(shape);
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
m_canvas->zoom_to_bed(); m_canvas->zoom_to_bed();
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
} }
} }

View file

@ -1125,9 +1125,11 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->background_process_timer.SetOwner(this->q, 0); this->background_process_timer.SetOwner(this->q, 0);
this->q->Bind(wxEVT_TIMER, [this](wxTimerEvent &evt) { this->update_restart_background_process(false, false); }); this->q->Bind(wxEVT_TIMER, [this](wxTimerEvent &evt) { this->update_restart_background_process(false, false); });
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
auto *bed_shape = config->opt<ConfigOptionPoints>("bed_shape"); auto *bed_shape = config->opt<ConfigOptionPoints>("bed_shape");
view3D->set_bed_shape(bed_shape->values); view3D->set_bed_shape(bed_shape->values);
preview->set_bed_shape(bed_shape->values); preview->set_bed_shape(bed_shape->values);
#endif // !ENABLE_REWORKED_BED_SHAPE_CHANGE
update(); update();
@ -2990,12 +2992,14 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
p->preview->set_number_extruders(p->config->option<ConfigOptionStrings>(opt_key)->values.size()); p->preview->set_number_extruders(p->config->option<ConfigOptionStrings>(opt_key)->values.size());
} else if(opt_key == "max_print_height") { } else if(opt_key == "max_print_height") {
update_scheduled = true; update_scheduled = true;
} else if(opt_key == "printer_model") { }
else if (opt_key == "printer_model") {
// update to force bed selection(for texturing) // update to force bed selection(for texturing)
if (p->view3D) p->view3D->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values); if (p->view3D) p->view3D->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values);
if (p->preview) p->preview->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values); if (p->preview) p->preview->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values);
update_scheduled = true; update_scheduled = true;
} else if (opt_key == "host_type" && this->p->printer_technology == ptSLA) { }
else if (opt_key == "host_type" && this->p->printer_technology == ptSLA) {
p->config->option<ConfigOptionEnum<PrintHostType>>(opt_key)->value = htSL1; p->config->option<ConfigOptionEnum<PrintHostType>>(opt_key)->value = htSL1;
} }
} }