SLA support point gizmo - ImGui experimental overlay plus a small bugfix related to point deletion

This commit is contained in:
Lukas Matena 2018-11-26 15:54:12 +01:00
parent 52c9dd3252
commit 878c7ee3d7
6 changed files with 49 additions and 5 deletions

View file

@ -3711,6 +3711,7 @@ void GLCanvas3D::update_volumes_colors_by_extruder()
// Returns a Rect object denoting size and position of the Reset button used by a gizmo. // Returns a Rect object denoting size and position of the Reset button used by a gizmo.
// Returns in either screen or viewport coords. // Returns in either screen or viewport coords.
#ifndef ENABLE_IMGUI
Rect GLCanvas3D::get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const Rect GLCanvas3D::get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const
{ {
const Size& cnv_size = canvas.get_canvas_size(); const Size& cnv_size = canvas.get_canvas_size();
@ -3728,6 +3729,7 @@ bool GLCanvas3D::gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, fl
const Rect& rect = get_gizmo_reset_rect(canvas, false); const Rect& rect = get_gizmo_reset_rect(canvas, false);
return (rect.get_left() <= x) && (x <= rect.get_right()) && (rect.get_top() <= y) && (y <= rect.get_bottom()); return (rect.get_left() <= x) && (x <= rect.get_right()) && (rect.get_top() <= y) && (y <= rect.get_bottom());
} }
#endif // not ENABLE_IMGUI
void GLCanvas3D::render() void GLCanvas3D::render()
{ {
@ -4570,6 +4572,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_dirty = true; m_dirty = true;
} }
} }
#ifndef ENABLE_IMGUI
else if ((m_gizmos.get_current_type() == Gizmos::SlaSupports) && gizmo_reset_rect_contains(*this, pos(0), pos(1))) else if ((m_gizmos.get_current_type() == Gizmos::SlaSupports) && gizmo_reset_rect_contains(*this, pos(0), pos(1)))
{ {
if (evt.LeftDown()) if (evt.LeftDown())
@ -4581,6 +4584,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_dirty = true; m_dirty = true;
} }
} }
#endif // not ENABLE_IMGUI
else if (!m_selection.is_empty() && gizmos_overlay_contains_mouse) else if (!m_selection.is_empty() && gizmos_overlay_contains_mouse)
{ {
m_gizmos.update_on_off_state(*this, m_mouse.position, m_selection); m_gizmos.update_on_off_state(*this, m_mouse.position, m_selection);
@ -4824,7 +4828,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// of the scene with the background processing data should be performed. // of the scene with the background processing data should be performed.
post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED)); post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED));
} }
else if (m_gizmos.get_current_type() == Gizmos::SlaSupports && m_hover_volume_id != -1) else if (evt.LeftUp() && m_gizmos.get_current_type() == Gizmos::SlaSupports && m_hover_volume_id != -1)
{ {
int id = m_selection.get_object_idx(); int id = m_selection.get_object_idx();

View file

@ -814,8 +814,11 @@ public:
void update_volumes_colors_by_extruder(); void update_volumes_colors_by_extruder();
#ifndef ENABLE_IMGUI
Rect get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const; Rect get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const;
bool gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, float y) const; bool gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, float y) const;
#endif // not ENABLE_IMGUI
bool is_dragging() const { return m_gizmos.is_dragging() || m_moving; } bool is_dragging() const { return m_gizmos.is_dragging() || m_moving; }
void render(); void render();

View file

@ -1660,7 +1660,9 @@ void GLGizmoSlaSupports::on_render(const GLCanvas3D::Selection& selection) const
render_grabbers(); render_grabbers();
::glPopMatrix(); ::glPopMatrix();
#ifndef ENABLE_IMGUI
render_tooltip_texture(); render_tooltip_texture();
#endif // not ENABLE_IMGUI
::glDisable(GL_BLEND); ::glDisable(GL_BLEND);
} }
@ -1756,7 +1758,6 @@ void GLGizmoSlaSupports::update_mesh()
m_grabbers.push_back(Grabber()); m_grabbers.push_back(Grabber());
m_grabbers.back().center = point.cast<double>(); m_grabbers.back().center = point.cast<double>();
} }
m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
} }
Vec3f GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos) Vec3f GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos)
@ -1812,6 +1813,7 @@ void GLGizmoSlaSupports::delete_current_grabber(bool delete_all)
if (delete_all) { if (delete_all) {
m_grabbers.clear(); m_grabbers.clear();
m_model_object->sla_support_points.clear(); m_model_object->sla_support_points.clear();
m_parent.reload_scene(true); // in case this was called from ImGui overlay dialog, the refresh would be delayed
// This should trigger the support generation // This should trigger the support generation
// wxGetApp().plater()->reslice(); // wxGetApp().plater()->reslice();
@ -1825,7 +1827,6 @@ void GLGizmoSlaSupports::delete_current_grabber(bool delete_all)
// This should trigger the support generation // This should trigger the support generation
// wxGetApp().plater()->reslice(); // wxGetApp().plater()->reslice();
} }
m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
} }
@ -1843,7 +1844,7 @@ void GLGizmoSlaSupports::on_update(const UpdateData& data)
} }
} }
#ifndef ENABLE_IMGUI
void GLGizmoSlaSupports::render_tooltip_texture() const { void GLGizmoSlaSupports::render_tooltip_texture() const {
if (m_tooltip_texture.get_id() == 0) if (m_tooltip_texture.get_id() == 0)
if (!m_tooltip_texture.load_from_file(resources_dir() + "/icons/sla_support_points_tooltip.png", false)) if (!m_tooltip_texture.load_from_file(resources_dir() + "/icons/sla_support_points_tooltip.png", false))
@ -1872,6 +1873,29 @@ void GLGizmoSlaSupports::render_tooltip_texture() const {
::glPopMatrix(); ::glPopMatrix();
::glEnable(GL_DEPTH_TEST); ::glEnable(GL_DEPTH_TEST);
} }
#endif // not ENABLE_IMGUI
#if ENABLE_IMGUI
void GLGizmoSlaSupports::on_render_input_window(float x, float y, const GLCanvas3D::Selection& selection)
{
m_imgui->set_next_window_pos(x, y, ImGuiCond_Always);
m_imgui->set_next_window_bg_alpha(0.5f);
m_imgui->begin(on_get_name(), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
ImGui::PushItemWidth(100.0f);
m_imgui->text(_(L("Left mouse click - add point")));
m_imgui->text(_(L("Right mouse click - remove point")));
m_imgui->text(" ");
bool remove_all_clicked = m_imgui->button(_(L("Remove all points")));
m_imgui->end();
if (remove_all_clicked)
delete_current_grabber(true);
}
#endif // ENABLE_IMGUI
bool GLGizmoSlaSupports::on_is_activable(const GLCanvas3D::Selection& selection) const bool GLGizmoSlaSupports::on_is_activable(const GLCanvas3D::Selection& selection) const
{ {

View file

@ -482,12 +482,14 @@ private:
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const; virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
void render_grabbers(bool picking = false) const; void render_grabbers(bool picking = false) const;
void render_tooltip_texture() const;
bool is_mesh_update_necessary() const; bool is_mesh_update_necessary() const;
void update_mesh(); void update_mesh();
#ifndef ENABLE_IMGUI
void render_tooltip_texture() const;
mutable GLTexture m_tooltip_texture; mutable GLTexture m_tooltip_texture;
mutable GLTexture m_reset_texture; mutable GLTexture m_reset_texture;
#endif // not ENABLE_IMGUI
protected: protected:
void on_set_state() override { void on_set_state() override {
@ -496,6 +498,10 @@ protected:
} }
} }
#if ENABLE_IMGUI
virtual void on_render_input_window(float x, float y, const GLCanvas3D::Selection& selection) override;
#endif // ENABLE_IMGUI
virtual std::string on_get_name() const; virtual std::string on_get_name() const;
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const; virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const;
virtual bool on_is_selectable() const; virtual bool on_is_selectable() const;

View file

@ -169,6 +169,12 @@ bool ImGuiWrapper::checkbox(const wxString &label, bool &value)
return ImGui::Checkbox(label_utf8.c_str(), &value); return ImGui::Checkbox(label_utf8.c_str(), &value);
} }
void ImGuiWrapper::text(const wxString &label)
{
auto label_utf8 = into_u8(label);
ImGui::Text(label_utf8.c_str(), NULL);
}
bool ImGuiWrapper::want_mouse() const bool ImGuiWrapper::want_mouse() const
{ {
return ImGui::GetIO().WantCaptureMouse; return ImGui::GetIO().WantCaptureMouse;

View file

@ -59,6 +59,7 @@ public:
bool input_double(const std::string &label, const double &value, const std::string &format = "%.3f"); bool input_double(const std::string &label, const double &value, const std::string &format = "%.3f");
bool input_vec3(const std::string &label, const Vec3d &value, float width, const std::string &format = "%.3f"); bool input_vec3(const std::string &label, const Vec3d &value, float width, const std::string &format = "%.3f");
bool checkbox(const wxString &label, bool &value); bool checkbox(const wxString &label, bool &value);
void text(const wxString &label);
bool want_mouse() const; bool want_mouse() const;
bool want_keyboard() const; bool want_keyboard() const;