Refactoring of GLGizmosXX classes to cleanup their interface

This commit is contained in:
Enrico Turri 2019-07-17 12:06:23 +02:00
parent 0a530ab7bc
commit da1fa0b6e3
16 changed files with 165 additions and 141 deletions

View file

@ -180,7 +180,7 @@ void GLGizmoBase::disable_grabber(unsigned int id)
on_disable_grabber(id); on_disable_grabber(id);
} }
void GLGizmoBase::start_dragging(const Selection& selection) void GLGizmoBase::start_dragging()
{ {
m_dragging = true; m_dragging = true;
@ -189,7 +189,7 @@ void GLGizmoBase::start_dragging(const Selection& selection)
m_grabbers[i].dragging = (m_hover_id == i); m_grabbers[i].dragging = (m_hover_id == i);
} }
on_start_dragging(selection); on_start_dragging();
} }
void GLGizmoBase::stop_dragging() void GLGizmoBase::stop_dragging()
@ -204,10 +204,10 @@ void GLGizmoBase::stop_dragging()
on_stop_dragging(); on_stop_dragging();
} }
void GLGizmoBase::update(const UpdateData& data, const Selection& selection) void GLGizmoBase::update(const UpdateData& data)
{ {
if (m_hover_id != -1) if (m_hover_id != -1)
on_update(data, selection); on_update(data);
} }
std::array<float, 3> GLGizmoBase::picking_color_component(unsigned int id) const std::array<float, 3> GLGizmoBase::picking_color_component(unsigned int id) const

View file

@ -76,10 +76,10 @@ public:
struct UpdateData struct UpdateData
{ {
const Linef3 mouse_ray; const Linef3& mouse_ray;
const Point* mouse_pos; const Point& mouse_pos;
UpdateData(const Linef3& mouse_ray, const Point* mouse_pos = nullptr) UpdateData(const Linef3& mouse_ray, const Point& mouse_pos)
: mouse_ray(mouse_ray), mouse_pos(mouse_pos) : mouse_ray(mouse_ray), mouse_pos(mouse_pos)
{} {}
}; };
@ -122,7 +122,7 @@ public:
const std::string& get_icon_filename() const { return m_icon_filename; } const std::string& get_icon_filename() const { return m_icon_filename; }
bool is_activable(const Selection& selection) const { return on_is_activable(selection); } bool is_activable() const { return on_is_activable(); }
bool is_selectable() const { return on_is_selectable(); } bool is_selectable() const { return on_is_selectable(); }
unsigned int get_sprite_id() const { return m_sprite_id; } unsigned int get_sprite_id() const { return m_sprite_id; }
@ -135,16 +135,16 @@ public:
void enable_grabber(unsigned int id); void enable_grabber(unsigned int id);
void disable_grabber(unsigned int id); void disable_grabber(unsigned int id);
void start_dragging(const Selection& selection); void start_dragging();
void stop_dragging(); void stop_dragging();
bool is_dragging() const { return m_dragging; } bool is_dragging() const { return m_dragging; }
void update(const UpdateData& data, const Selection& selection); void update(const UpdateData& data);
void render(const Selection& selection) const { on_render(selection); } void render() const { on_render(); }
void render_for_picking(const Selection& selection) const { on_render_for_picking(selection); } void render_for_picking() const { on_render_for_picking(); }
void render_input_window(float x, float y, float bottom_limit, const Selection& selection) { on_render_input_window(x, y, bottom_limit, selection); } void render_input_window(float x, float y, float bottom_limit) { on_render_input_window(x, y, bottom_limit); }
protected: protected:
virtual bool on_init() = 0; virtual bool on_init() = 0;
@ -153,16 +153,16 @@ protected:
virtual std::string on_get_name() const = 0; virtual std::string on_get_name() const = 0;
virtual void on_set_state() {} virtual void on_set_state() {}
virtual void on_set_hover_id() {} virtual void on_set_hover_id() {}
virtual bool on_is_activable(const Selection& selection) const { return true; } virtual bool on_is_activable() const { return true; }
virtual bool on_is_selectable() const { return true; } virtual bool on_is_selectable() const { return true; }
virtual void on_enable_grabber(unsigned int id) {} virtual void on_enable_grabber(unsigned int id) {}
virtual void on_disable_grabber(unsigned int id) {} virtual void on_disable_grabber(unsigned int id) {}
virtual void on_start_dragging(const Selection& selection) {} virtual void on_start_dragging() {}
virtual void on_stop_dragging() {} virtual void on_stop_dragging() {}
virtual void on_update(const UpdateData& data, const Selection& selection) = 0; virtual void on_update(const UpdateData& data) {}
virtual void on_render(const Selection& selection) const = 0; virtual void on_render() const = 0;
virtual void on_render_for_picking(const Selection& selection) const = 0; virtual void on_render_for_picking() const = 0;
virtual void on_render_input_window(float x, float y, float bottom_limit, const Selection& selection) {} virtual void on_render_input_window(float x, float y, float bottom_limit) {}
// Returns the picking color for the given id, based on the BASE_ID constant // Returns the picking color for the given id, based on the BASE_ID constant
// No check is made for clashing with other picking color (i.e. GLVolumes) // No check is made for clashing with other picking color (i.e. GLVolumes)

View file

@ -48,15 +48,18 @@ void GLGizmoCut::on_set_state()
} }
} }
bool GLGizmoCut::on_is_activable(const Selection& selection) const bool GLGizmoCut::on_is_activable() const
{ {
const Selection& selection = m_parent.get_selection();
return selection.is_single_full_instance() && !selection.is_wipe_tower(); return selection.is_single_full_instance() && !selection.is_wipe_tower();
} }
void GLGizmoCut::on_start_dragging(const Selection& selection) void GLGizmoCut::on_start_dragging()
{ {
if (m_hover_id == -1) { return; } if (m_hover_id == -1)
return;
const Selection& selection = m_parent.get_selection();
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = selection.get_bounding_box();
m_start_z = m_cut_z; m_start_z = m_cut_z;
update_max_z(selection); update_max_z(selection);
@ -65,19 +68,21 @@ void GLGizmoCut::on_start_dragging(const Selection& selection)
m_drag_center(2) = m_cut_z; m_drag_center(2) = m_cut_z;
} }
void GLGizmoCut::on_update(const UpdateData& data, const Selection& selection) void GLGizmoCut::on_update(const UpdateData& data)
{ {
if (m_hover_id != -1) { if (m_hover_id != -1) {
set_cut_z(m_start_z + calc_projection(data.mouse_ray)); set_cut_z(m_start_z + calc_projection(data.mouse_ray));
} }
} }
void GLGizmoCut::on_render(const Selection& selection) const void GLGizmoCut::on_render() const
{ {
if (m_grabbers[0].dragging) { if (m_grabbers[0].dragging) {
set_tooltip("Z: " + format(m_cut_z, 2)); set_tooltip("Z: " + format(m_cut_z, 2));
} }
const Selection& selection = m_parent.get_selection();
update_max_z(selection); update_max_z(selection);
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = selection.get_bounding_box();
@ -123,14 +128,13 @@ void GLGizmoCut::on_render(const Selection& selection) const
m_grabbers[0].render(m_hover_id == 0, (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0)); m_grabbers[0].render(m_hover_id == 0, (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0));
} }
void GLGizmoCut::on_render_for_picking(const Selection& selection) const void GLGizmoCut::on_render_for_picking() const
{ {
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
render_grabbers_for_picking(m_parent.get_selection().get_bounding_box());
render_grabbers_for_picking(selection.get_bounding_box());
} }
void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection) void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit)
{ {
const float approx_height = m_imgui->scaled(11.0f); const float approx_height = m_imgui->scaled(11.0f);
y = std::min(y, bottom_limit - approx_height); y = std::min(y, bottom_limit - approx_height);
@ -153,7 +157,7 @@ void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit, co
m_imgui->end(); m_imgui->end();
if (cut_clicked && (m_keep_upper || m_keep_lower)) { if (cut_clicked && (m_keep_upper || m_keep_lower)) {
perform_cut(selection); perform_cut(m_parent.get_selection());
} }
} }

View file

@ -31,12 +31,12 @@ protected:
virtual void on_save(cereal::BinaryOutputArchive& ar) const { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); } virtual void on_save(cereal::BinaryOutputArchive& ar) const { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); }
virtual std::string on_get_name() const; virtual std::string on_get_name() const;
virtual void on_set_state(); virtual void on_set_state();
virtual bool on_is_activable(const Selection& selection) const; virtual bool on_is_activable() const;
virtual void on_start_dragging(const Selection& selection); virtual void on_start_dragging();
virtual void on_update(const UpdateData& data, const Selection& selection); virtual void on_update(const UpdateData& data);
virtual void on_render(const Selection& selection) const; virtual void on_render() const;
virtual void on_render_for_picking(const Selection& selection) const; virtual void on_render_for_picking() const;
virtual void on_render_input_window(float x, float y, float bottom_limit, const Selection& selection); virtual void on_render_input_window(float x, float y, float bottom_limit);
private: private:
void update_max_z(const Selection& selection) const; void update_max_z(const Selection& selection) const;

View file

@ -1,5 +1,6 @@
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoFlatten.hpp" #include "GLGizmoFlatten.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include <numeric> #include <numeric>
@ -27,23 +28,25 @@ std::string GLGizmoFlatten::on_get_name() const
return (_(L("Place on face")) + " [F]").ToUTF8().data(); return (_(L("Place on face")) + " [F]").ToUTF8().data();
} }
bool GLGizmoFlatten::on_is_activable(const Selection& selection) const bool GLGizmoFlatten::on_is_activable() const
{ {
return selection.is_single_full_instance(); return m_parent.get_selection().is_single_full_instance();
} }
void GLGizmoFlatten::on_start_dragging(const Selection& selection) void GLGizmoFlatten::on_start_dragging()
{ {
if (m_hover_id != -1) if (m_hover_id != -1)
{ {
assert(m_planes_valid); assert(m_planes_valid);
m_normal = m_planes[m_hover_id].normal; m_normal = m_planes[m_hover_id].normal;
m_starting_center = selection.get_bounding_box().center(); m_starting_center = m_parent.get_selection().get_bounding_box().center();
} }
} }
void GLGizmoFlatten::on_render(const Selection& selection) const void GLGizmoFlatten::on_render() const
{ {
const Selection& selection = m_parent.get_selection();
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
@ -78,8 +81,10 @@ void GLGizmoFlatten::on_render(const Selection& selection) const
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
} }
void GLGizmoFlatten::on_render_for_picking(const Selection& selection) const void GLGizmoFlatten::on_render_for_picking() const
{ {
const Selection& selection = m_parent.get_selection();
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));

View file

@ -45,11 +45,10 @@ public:
protected: protected:
virtual bool on_init(); virtual bool on_init();
virtual std::string on_get_name() const; virtual std::string on_get_name() const;
virtual bool on_is_activable(const Selection& selection) const; virtual bool on_is_activable() const;
virtual void on_start_dragging(const Selection& selection); virtual void on_start_dragging();
virtual void on_update(const UpdateData& data, const Selection& selection) {} virtual void on_render() const;
virtual void on_render(const Selection& selection) const; virtual void on_render_for_picking() const;
virtual void on_render_for_picking(const Selection& selection) const;
virtual void on_set_state() virtual void on_set_state()
{ {
if (m_state == On && is_plane_update_necessary()) if (m_state == On && is_plane_update_necessary())

View file

@ -1,5 +1,6 @@
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoMove.hpp" #include "GLGizmoMove.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include <GL/glew.h> #include <GL/glew.h>
@ -47,12 +48,12 @@ std::string GLGizmoMove3D::on_get_name() const
return (_(L("Move")) + " [M]").ToUTF8().data(); return (_(L("Move")) + " [M]").ToUTF8().data();
} }
void GLGizmoMove3D::on_start_dragging(const Selection& selection) void GLGizmoMove3D::on_start_dragging()
{ {
if (m_hover_id != -1) if (m_hover_id != -1)
{ {
m_displacement = Vec3d::Zero(); m_displacement = Vec3d::Zero();
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = m_parent.get_selection().get_bounding_box();
m_starting_drag_position = m_grabbers[m_hover_id].center; m_starting_drag_position = m_grabbers[m_hover_id].center;
m_starting_box_center = box.center(); m_starting_box_center = box.center();
m_starting_box_bottom_center = box.center(); m_starting_box_bottom_center = box.center();
@ -65,7 +66,7 @@ void GLGizmoMove3D::on_stop_dragging()
m_displacement = Vec3d::Zero(); m_displacement = Vec3d::Zero();
} }
void GLGizmoMove3D::on_update(const UpdateData& data, const Selection& selection) void GLGizmoMove3D::on_update(const UpdateData& data)
{ {
if (m_hover_id == 0) if (m_hover_id == 0)
m_displacement(0) = calc_projection(data); m_displacement(0) = calc_projection(data);
@ -75,8 +76,10 @@ void GLGizmoMove3D::on_update(const UpdateData& data, const Selection& selection
m_displacement(2) = calc_projection(data); m_displacement(2) = calc_projection(data);
} }
void GLGizmoMove3D::on_render(const Selection& selection) const void GLGizmoMove3D::on_render() const
{ {
const Selection& selection = m_parent.get_selection();
bool show_position = selection.is_single_full_instance(); bool show_position = selection.is_single_full_instance();
const Vec3d& position = selection.get_bounding_box().center(); const Vec3d& position = selection.get_bounding_box().center();
@ -152,20 +155,21 @@ void GLGizmoMove3D::on_render(const Selection& selection) const
} }
} }
void GLGizmoMove3D::on_render_for_picking(const Selection& selection) const void GLGizmoMove3D::on_render_for_picking() const
{ {
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = m_parent.get_selection().get_bounding_box();
render_grabbers_for_picking(box); render_grabbers_for_picking(box);
render_grabber_extension(X, box, true); render_grabber_extension(X, box, true);
render_grabber_extension(Y, box, true); render_grabber_extension(Y, box, true);
render_grabber_extension(Z, box, true); render_grabber_extension(Z, box, true);
} }
void GLGizmoMove3D::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection)
{
#if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI #if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
void GLGizmoMove3D::on_render_input_window(float x, float y, float bottom_limit)
{
const Selection& selection = m_parent.get_selection();
bool show_position = selection.is_single_full_instance(); bool show_position = selection.is_single_full_instance();
const Vec3d& position = selection.get_bounding_box().center(); const Vec3d& position = selection.get_bounding_box().center();
@ -178,8 +182,8 @@ void GLGizmoMove3D::on_render_input_window(float x, float y, float bottom_limit,
m_imgui->input_vec3("", displacement, 100.0f, "%.2f"); m_imgui->input_vec3("", displacement, 100.0f, "%.2f");
m_imgui->end(); m_imgui->end();
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
} }
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
double GLGizmoMove3D::calc_projection(const UpdateData& data) const double GLGizmoMove3D::calc_projection(const UpdateData& data) const
{ {

View file

@ -33,12 +33,14 @@ public:
protected: protected:
virtual bool on_init(); virtual bool on_init();
virtual std::string on_get_name() const; virtual std::string on_get_name() const;
virtual void on_start_dragging(const Selection& selection); virtual void on_start_dragging();
virtual void on_stop_dragging(); virtual void on_stop_dragging();
virtual void on_update(const UpdateData& data, const Selection& selection); virtual void on_update(const UpdateData& data);
virtual void on_render(const Selection& selection) const; virtual void on_render() const;
virtual void on_render_for_picking(const Selection& selection) const; virtual void on_render_for_picking() const;
virtual void on_render_input_window(float x, float y, float bottom_limit, const Selection& selection); #if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
virtual void on_render_input_window(float x, float y, float bottom_limit);
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
private: private:
double calc_projection(const UpdateData& data) const; double calc_projection(const UpdateData& data) const;

View file

@ -1,5 +1,6 @@
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoRotate.hpp" #include "GLGizmoRotate.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include <GL/glew.h> #include <GL/glew.h>
@ -72,9 +73,9 @@ bool GLGizmoRotate::on_init()
return true; return true;
} }
void GLGizmoRotate::on_start_dragging(const Selection& selection) void GLGizmoRotate::on_start_dragging()
{ {
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = m_parent.get_selection().get_bounding_box();
m_center = box.center(); m_center = box.center();
m_radius = Offset + box.radius(); m_radius = Offset + box.radius();
m_snap_coarse_in_radius = m_radius / 3.0f; m_snap_coarse_in_radius = m_radius / 3.0f;
@ -83,9 +84,9 @@ void GLGizmoRotate::on_start_dragging(const Selection& selection)
m_snap_fine_out_radius = m_snap_fine_in_radius + m_radius * ScaleLongTooth; m_snap_fine_out_radius = m_snap_fine_in_radius + m_radius * ScaleLongTooth;
} }
void GLGizmoRotate::on_update(const UpdateData& data, const Selection& selection) void GLGizmoRotate::on_update(const UpdateData& data)
{ {
Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(data.mouse_ray, selection)); Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(data.mouse_ray, m_parent.get_selection()));
Vec2d orig_dir = Vec2d::UnitX(); Vec2d orig_dir = Vec2d::UnitX();
Vec2d new_dir = mouse_pos.normalized(); Vec2d new_dir = mouse_pos.normalized();
@ -118,11 +119,12 @@ void GLGizmoRotate::on_update(const UpdateData& data, const Selection& selection
m_angle = theta; m_angle = theta;
} }
void GLGizmoRotate::on_render(const Selection& selection) const void GLGizmoRotate::on_render() const
{ {
if (!m_grabbers[0].enabled) if (!m_grabbers[0].enabled)
return; return;
const Selection& selection = m_parent.get_selection();
const BoundingBoxf3& box = selection.get_bounding_box(); const BoundingBoxf3& box = selection.get_bounding_box();
std::string axis; std::string axis;
@ -175,8 +177,10 @@ void GLGizmoRotate::on_render(const Selection& selection) const
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
} }
void GLGizmoRotate::on_render_for_picking(const Selection& selection) const void GLGizmoRotate::on_render_for_picking() const
{ {
const Selection& selection = m_parent.get_selection();
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
@ -445,10 +449,10 @@ std::string GLGizmoRotate3D::on_get_name() const
return (_(L("Rotate")) + " [R]").ToUTF8().data(); return (_(L("Rotate")) + " [R]").ToUTF8().data();
} }
void GLGizmoRotate3D::on_start_dragging(const Selection& selection) void GLGizmoRotate3D::on_start_dragging()
{ {
if ((0 <= m_hover_id) && (m_hover_id < 3)) if ((0 <= m_hover_id) && (m_hover_id < 3))
m_gizmos[m_hover_id].start_dragging(selection); m_gizmos[m_hover_id].start_dragging();
} }
void GLGizmoRotate3D::on_stop_dragging() void GLGizmoRotate3D::on_stop_dragging()
@ -457,23 +461,23 @@ void GLGizmoRotate3D::on_stop_dragging()
m_gizmos[m_hover_id].stop_dragging(); m_gizmos[m_hover_id].stop_dragging();
} }
void GLGizmoRotate3D::on_render(const Selection& selection) const void GLGizmoRotate3D::on_render() const
{ {
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
if ((m_hover_id == -1) || (m_hover_id == 0)) if ((m_hover_id == -1) || (m_hover_id == 0))
m_gizmos[X].render(selection); m_gizmos[X].render();
if ((m_hover_id == -1) || (m_hover_id == 1)) if ((m_hover_id == -1) || (m_hover_id == 1))
m_gizmos[Y].render(selection); m_gizmos[Y].render();
if ((m_hover_id == -1) || (m_hover_id == 2)) if ((m_hover_id == -1) || (m_hover_id == 2))
m_gizmos[Z].render(selection); m_gizmos[Z].render();
} }
void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection)
{
#if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI #if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limit)
{
Vec3d rotation(Geometry::rad2deg(m_gizmos[0].get_angle()), Geometry::rad2deg(m_gizmos[1].get_angle()), Geometry::rad2deg(m_gizmos[2].get_angle())); Vec3d rotation(Geometry::rad2deg(m_gizmos[0].get_angle()), Geometry::rad2deg(m_gizmos[1].get_angle()), Geometry::rad2deg(m_gizmos[2].get_angle()));
wxString label = _(L("Rotation (deg)")); wxString label = _(L("Rotation (deg)"));
@ -482,8 +486,8 @@ void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limi
m_imgui->begin(label, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); m_imgui->begin(label, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
m_imgui->input_vec3("", rotation, 100.0f, "%.2f"); m_imgui->input_vec3("", rotation, 100.0f, "%.2f");
m_imgui->end(); m_imgui->end();
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
} }
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI

View file

@ -52,10 +52,10 @@ public:
protected: protected:
virtual bool on_init(); virtual bool on_init();
virtual std::string on_get_name() const { return ""; } virtual std::string on_get_name() const { return ""; }
virtual void on_start_dragging(const Selection& selection); virtual void on_start_dragging();
virtual void on_update(const UpdateData& data, const Selection& selection); virtual void on_update(const UpdateData& data);
virtual void on_render(const Selection& selection) const; virtual void on_render() const;
virtual void on_render_for_picking(const Selection& selection) const; virtual void on_render_for_picking() const;
private: private:
void render_circle() const; void render_circle() const;
@ -98,7 +98,6 @@ protected:
m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1); m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1);
} }
} }
virtual bool on_is_activable(const Selection& selection) const { return true; }
virtual void on_enable_grabber(unsigned int id) virtual void on_enable_grabber(unsigned int id)
{ {
if ((0 <= id) && (id < 3)) if ((0 <= id) && (id < 3))
@ -109,25 +108,26 @@ protected:
if ((0 <= id) && (id < 3)) if ((0 <= id) && (id < 3))
m_gizmos[id].disable_grabber(0); m_gizmos[id].disable_grabber(0);
} }
virtual void on_start_dragging(const Selection& selection); virtual void on_start_dragging();
virtual void on_stop_dragging(); virtual void on_stop_dragging();
virtual void on_update(const UpdateData& data, const Selection& selection) virtual void on_update(const UpdateData& data)
{ {
for (GLGizmoRotate& g : m_gizmos) for (GLGizmoRotate& g : m_gizmos)
{ {
g.update(data, selection); g.update(data);
} }
} }
virtual void on_render(const Selection& selection) const; virtual void on_render() const;
virtual void on_render_for_picking(const Selection& selection) const virtual void on_render_for_picking() const
{ {
for (const GLGizmoRotate& g : m_gizmos) for (const GLGizmoRotate& g : m_gizmos)
{ {
g.render_for_picking(selection); g.render_for_picking();
} }
} }
#if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
virtual void on_render_input_window(float x, float y, float bottom_limit, const Selection& selection); virtual void on_render_input_window(float x, float y, float bottom_limit);
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
}; };

View file

@ -1,7 +1,6 @@
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoScale.hpp" #include "GLGizmoScale.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include <GL/glew.h> #include <GL/glew.h>
@ -48,13 +47,18 @@ std::string GLGizmoScale3D::on_get_name() const
return (_(L("Scale")) + " [S]").ToUTF8().data(); return (_(L("Scale")) + " [S]").ToUTF8().data();
} }
void GLGizmoScale3D::on_start_dragging(const Selection& selection) bool GLGizmoScale3D::on_is_activable() const
{
return !m_parent.get_selection().is_wipe_tower();
}
void GLGizmoScale3D::on_start_dragging()
{ {
if (m_hover_id != -1) if (m_hover_id != -1)
{ {
m_starting.drag_position = m_grabbers[m_hover_id].center; m_starting.drag_position = m_grabbers[m_hover_id].center;
m_starting.ctrl_down = wxGetKeyState(WXK_CONTROL); m_starting.ctrl_down = wxGetKeyState(WXK_CONTROL);
m_starting.box = (m_starting.ctrl_down && (m_hover_id < 6)) ? m_box : selection.get_bounding_box(); m_starting.box = (m_starting.ctrl_down && (m_hover_id < 6)) ? m_box : m_parent.get_selection().get_bounding_box();
const Vec3d& center = m_starting.box.center(); const Vec3d& center = m_starting.box.center();
m_starting.pivots[0] = m_transform * Vec3d(m_starting.box.max(0), center(1), center(2)); m_starting.pivots[0] = m_transform * Vec3d(m_starting.box.max(0), center(1), center(2));
@ -66,7 +70,7 @@ void GLGizmoScale3D::on_start_dragging(const Selection& selection)
} }
} }
void GLGizmoScale3D::on_update(const UpdateData& data, const Selection& selection) void GLGizmoScale3D::on_update(const UpdateData& data)
{ {
if ((m_hover_id == 0) || (m_hover_id == 1)) if ((m_hover_id == 0) || (m_hover_id == 1))
do_scale_along_axis(X, data); do_scale_along_axis(X, data);
@ -78,8 +82,10 @@ void GLGizmoScale3D::on_update(const UpdateData& data, const Selection& selectio
do_scale_uniform(data); do_scale_uniform(data);
} }
void GLGizmoScale3D::on_render(const Selection& selection) const void GLGizmoScale3D::on_render() const
{ {
const Selection& selection = m_parent.get_selection();
bool single_instance = selection.is_single_full_instance(); bool single_instance = selection.is_single_full_instance();
bool single_volume = selection.is_single_modifier() || selection.is_single_volume(); bool single_volume = selection.is_single_modifier() || selection.is_single_volume();
bool single_selection = single_instance || single_volume; bool single_selection = single_instance || single_volume;
@ -272,16 +278,16 @@ void GLGizmoScale3D::on_render(const Selection& selection) const
} }
} }
void GLGizmoScale3D::on_render_for_picking(const Selection& selection) const void GLGizmoScale3D::on_render_for_picking() const
{ {
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
render_grabbers_for_picking(m_parent.get_selection().get_bounding_box());
render_grabbers_for_picking(selection.get_bounding_box());
} }
void GLGizmoScale3D::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection)
{
#if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI #if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
void GLGizmoScale3D::on_render_input_window(float x, float y, float bottom_limit)
{
const Selection& selection = m_parent.get_selection();
bool single_instance = selection.is_single_full_instance(); bool single_instance = selection.is_single_full_instance();
wxString label = _(L("Scale (%)")); wxString label = _(L("Scale (%)"));
@ -290,8 +296,8 @@ void GLGizmoScale3D::on_render_input_window(float x, float y, float bottom_limit
m_imgui->begin(label, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); m_imgui->begin(label, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
m_imgui->input_vec3("", m_scale * 100.f, 100.0f, "%.2f"); m_imgui->input_vec3("", m_scale * 100.f, 100.0f, "%.2f");
m_imgui->end(); m_imgui->end();
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
} }
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const
{ {

View file

@ -45,12 +45,14 @@ public:
protected: protected:
virtual bool on_init(); virtual bool on_init();
virtual std::string on_get_name() const; virtual std::string on_get_name() const;
virtual bool on_is_activable(const Selection& selection) const { return !selection.is_wipe_tower(); } virtual bool on_is_activable() const;
virtual void on_start_dragging(const Selection& selection); virtual void on_start_dragging();
virtual void on_update(const UpdateData& data, const Selection& selection); virtual void on_update(const UpdateData& data);
virtual void on_render(const Selection& selection) const; virtual void on_render() const;
virtual void on_render_for_picking(const Selection& selection) const; virtual void on_render_for_picking() const;
virtual void on_render_input_window(float x, float y, float bottom_limit, const Selection& selection); #if !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
virtual void on_render_input_window(float x, float y, float bottom_limit);
#endif // !DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI
private: private:
void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const;

View file

@ -94,8 +94,10 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S
} }
} }
void GLGizmoSlaSupports::on_render(const Selection& selection) const void GLGizmoSlaSupports::on_render() const
{ {
const Selection& selection = m_parent.get_selection();
// If current m_model_object does not match selection, ask GLCanvas3D to turn us off // If current m_model_object does not match selection, ask GLCanvas3D to turn us off
if (m_state == On if (m_state == On
&& (m_model_object != selection.get_model()->objects[selection.get_object_idx()] && (m_model_object != selection.get_model()->objects[selection.get_object_idx()]
@ -252,8 +254,9 @@ void GLGizmoSlaSupports::render_clipping_plane(const Selection& selection) const
} }
void GLGizmoSlaSupports::on_render_for_picking(const Selection& selection) const void GLGizmoSlaSupports::on_render_for_picking() const
{ {
const Selection& selection = m_parent.get_selection();
#if ENABLE_RENDER_PICKING_PASS #if ENABLE_RENDER_PICKING_PASS
m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z();
#endif #endif
@ -702,12 +705,12 @@ void GLGizmoSlaSupports::delete_selected_points(bool force)
//m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); //m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
} }
void GLGizmoSlaSupports::on_update(const UpdateData& data, const Selection& selection) void GLGizmoSlaSupports::on_update(const UpdateData& data)
{ {
if (m_editing_mode && m_hover_id != -1 && data.mouse_pos && (!m_editing_mode_cache[m_hover_id].support_point.is_new_island || !m_lock_unique_islands)) { if (m_editing_mode && m_hover_id != -1 && (!m_editing_mode_cache[m_hover_id].support_point.is_new_island || !m_lock_unique_islands)) {
std::pair<Vec3f, Vec3f> pos_and_normal; std::pair<Vec3f, Vec3f> pos_and_normal;
try { try {
pos_and_normal = unproject_on_mesh(Vec2d((*data.mouse_pos)(0), (*data.mouse_pos)(1))); pos_and_normal = unproject_on_mesh(data.mouse_pos.cast<double>());
} }
catch (...) { return; } catch (...) { return; }
m_editing_mode_cache[m_hover_id].support_point.pos = pos_and_normal.first; m_editing_mode_cache[m_hover_id].support_point.pos = pos_and_normal.first;
@ -822,7 +825,7 @@ void GLGizmoSlaSupports::make_line_segments() const
*/ */
void GLGizmoSlaSupports::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection) void GLGizmoSlaSupports::on_render_input_window(float x, float y, float bottom_limit)
{ {
if (!m_model_object) if (!m_model_object)
return; return;
@ -1002,8 +1005,10 @@ RENDER_AGAIN:
m_parent.set_as_dirty(); m_parent.set_as_dirty();
} }
bool GLGizmoSlaSupports::on_is_activable(const Selection& selection) const bool GLGizmoSlaSupports::on_is_activable() const
{ {
const Selection& selection = m_parent.get_selection();
if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA
|| !selection.is_from_single_instance()) || !selection.is_from_single_instance())
return false; return false;
@ -1075,7 +1080,7 @@ void GLGizmoSlaSupports::on_set_state()
void GLGizmoSlaSupports::on_start_dragging(const Selection& selection) void GLGizmoSlaSupports::on_start_dragging()
{ {
if (m_hover_id != -1) { if (m_hover_id != -1) {
select_point(NoPoints); select_point(NoPoints);

View file

@ -70,9 +70,9 @@ public:
private: private:
bool on_init(); bool on_init();
void on_update(const UpdateData& data, const Selection& selection); void on_update(const UpdateData& data);
virtual void on_render(const Selection& selection) const; virtual void on_render() const;
virtual void on_render_for_picking(const Selection& selection) const; virtual void on_render_for_picking() const;
//void render_selection_rectangle() const; //void render_selection_rectangle() const;
void render_points(const Selection& selection, bool picking = false) const; void render_points(const Selection& selection, bool picking = false) const;
@ -133,11 +133,11 @@ protected:
if ((int)m_editing_mode_cache.size() <= m_hover_id) if ((int)m_editing_mode_cache.size() <= m_hover_id)
m_hover_id = -1; m_hover_id = -1;
} }
void on_start_dragging(const Selection& selection) override; void on_start_dragging() override;
virtual void on_render_input_window(float x, float y, float bottom_limit, const Selection& selection) override; virtual void on_render_input_window(float x, float y, float bottom_limit) override;
virtual std::string on_get_name() const; virtual std::string on_get_name() const;
virtual bool on_is_activable(const Selection& selection) const; virtual bool on_is_activable() const;
virtual bool on_is_selectable() const; virtual bool on_is_selectable() const;
}; };

View file

@ -150,7 +150,7 @@ void GLGizmosManager::refresh_on_off_state()
GizmosMap::iterator it = m_gizmos.find(m_current); GizmosMap::iterator it = m_gizmos.find(m_current);
if ((it != m_gizmos.end()) && (it->second != nullptr)) if ((it != m_gizmos.end()) && (it->second != nullptr))
{ {
if (!it->second->is_activable(m_parent->get_selection())) if (!it->second->is_activable())
{ {
it->second->set_state(GLGizmoBase::Off); it->second->set_state(GLGizmoBase::Off);
m_current = Undefined; m_current = Undefined;
@ -205,14 +205,14 @@ void GLGizmosManager::enable_grabber(EType type, unsigned int id, bool enable)
} }
} }
void GLGizmosManager::update(const Linef3& mouse_ray, const Point* mouse_pos) void GLGizmosManager::update(const Linef3& mouse_ray, const Point& mouse_pos)
{ {
if (!m_enabled || (m_parent == nullptr)) if (!m_enabled || (m_parent == nullptr))
return; return;
GLGizmoBase* curr = get_current(); GLGizmoBase* curr = get_current();
if (curr != nullptr) if (curr != nullptr)
curr->update(GLGizmoBase::UpdateData(mouse_ray, mouse_pos), m_parent->get_selection()); curr->update(GLGizmoBase::UpdateData(mouse_ray, mouse_pos));
} }
void GLGizmosManager::update_data() void GLGizmosManager::update_data()
@ -282,8 +282,7 @@ bool GLGizmosManager::handle_shortcut(int key)
if (!m_enabled || (m_parent == nullptr)) if (!m_enabled || (m_parent == nullptr))
return false; return false;
const Selection& selection = m_parent->get_selection(); if (m_parent->get_selection().is_empty())
if (selection.is_empty())
return false; return false;
EType old_current = m_current; EType old_current = m_current;
@ -295,7 +294,7 @@ bool GLGizmosManager::handle_shortcut(int key)
int it_key = it->second->get_shortcut_key(); int it_key = it->second->get_shortcut_key();
if (it->second->is_activable(selection) && ((it_key == key - 64) || (it_key == key - 96))) if (it->second->is_activable() && ((it_key == key - 64) || (it_key == key - 96)))
{ {
if ((it->second->get_state() == GLGizmoBase::On)) if ((it->second->get_state() == GLGizmoBase::On))
{ {
@ -338,7 +337,7 @@ void GLGizmosManager::start_dragging()
GLGizmoBase* curr = get_current(); GLGizmoBase* curr = get_current();
if (curr != nullptr) if (curr != nullptr)
curr->start_dragging(m_parent->get_selection()); curr->start_dragging();
} }
void GLGizmosManager::stop_dragging() void GLGizmosManager::stop_dragging()
@ -469,7 +468,7 @@ void GLGizmosManager::render_current_gizmo() const
GLGizmoBase* curr = get_current(); GLGizmoBase* curr = get_current();
if (curr != nullptr) if (curr != nullptr)
curr->render(m_parent->get_selection()); curr->render();
} }
void GLGizmosManager::render_current_gizmo_for_picking_pass() const void GLGizmosManager::render_current_gizmo_for_picking_pass() const
@ -479,7 +478,7 @@ void GLGizmosManager::render_current_gizmo_for_picking_pass() const
GLGizmoBase* curr = get_current(); GLGizmoBase* curr = get_current();
if (curr != nullptr) if (curr != nullptr)
curr->render_for_picking(m_parent->get_selection()); curr->render_for_picking();
} }
void GLGizmosManager::render_overlay() const void GLGizmosManager::render_overlay() const
@ -589,7 +588,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
m_parent->get_wxglcanvas()->CaptureMouse(); m_parent->get_wxglcanvas()->CaptureMouse();
m_parent->set_mouse_as_dragging(); m_parent->set_mouse_as_dragging();
update(m_parent->mouse_ray(pos), &pos); update(m_parent->mouse_ray(pos), pos);
switch (m_current) switch (m_current)
{ {
@ -902,8 +901,6 @@ void GLGizmosManager::do_render_overlay() const
if ((m_parent == nullptr) || m_gizmos.empty()) if ((m_parent == nullptr) || m_gizmos.empty())
return; return;
const Selection& selection = m_parent->get_selection();
float cnv_w = (float)m_parent->get_canvas_size().get_width(); float cnv_w = (float)m_parent->get_canvas_size().get_width();
float cnv_h = (float)m_parent->get_canvas_size().get_height(); float cnv_h = (float)m_parent->get_canvas_size().get_height();
float zoom = (float)m_parent->get_camera().get_zoom(); float zoom = (float)m_parent->get_camera().get_zoom();
@ -1020,7 +1017,7 @@ void GLGizmosManager::do_render_overlay() const
GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } });
if (it->second->get_state() == GLGizmoBase::On) { if (it->second->get_state() == GLGizmoBase::On) {
float toolbar_top = (float)cnv_h - m_parent->get_view_toolbar_height(); float toolbar_top = (float)cnv_h - m_parent->get_view_toolbar_height();
it->second->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top, selection); it->second->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top);
} }
top_y -= scaled_stride_y; top_y -= scaled_stride_y;
} }
@ -1087,8 +1084,6 @@ void GLGizmosManager::update_on_off_state(const Vec2d& mouse_pos)
if (!m_enabled || (m_parent == nullptr)) if (!m_enabled || (m_parent == nullptr))
return; return;
const Selection& selection = m_parent->get_selection();
float cnv_h = (float)m_parent->get_canvas_size().get_height(); float cnv_h = (float)m_parent->get_canvas_size().get_height();
float height = get_total_overlay_height(); float height = get_total_overlay_height();
@ -1104,7 +1099,7 @@ void GLGizmosManager::update_on_off_state(const Vec2d& mouse_pos)
continue; continue;
bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size); bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size);
if (it->second->is_activable(selection) && inside) if (it->second->is_activable() && inside)
{ {
if ((it->second->get_state() == GLGizmoBase::On)) if ((it->second->get_state() == GLGizmoBase::On))
{ {
@ -1135,8 +1130,6 @@ std::string GLGizmosManager::update_hover_state(const Vec2d& mouse_pos)
if (!m_enabled || (m_parent == nullptr)) if (!m_enabled || (m_parent == nullptr))
return name; return name;
const Selection& selection = m_parent->get_selection();
float cnv_h = (float)m_parent->get_canvas_size().get_height(); float cnv_h = (float)m_parent->get_canvas_size().get_height();
float height = get_total_overlay_height(); float height = get_total_overlay_height();
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale; float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
@ -1154,7 +1147,7 @@ std::string GLGizmosManager::update_hover_state(const Vec2d& mouse_pos)
if (inside) if (inside)
name = it->second->get_name(); name = it->second->get_name();
if (it->second->is_activable(selection) && (it->second->get_state() != GLGizmoBase::On)) if (it->second->is_activable() && (it->second->get_state() != GLGizmoBase::On))
it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off); it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
top_y += scaled_stride_y; top_y += scaled_stride_y;

View file

@ -140,7 +140,7 @@ public:
void set_hover_id(int id); void set_hover_id(int id);
void enable_grabber(EType type, unsigned int id, bool enable); void enable_grabber(EType type, unsigned int id, bool enable);
void update(const Linef3& mouse_ray, const Point* mouse_pos = nullptr); void update(const Linef3& mouse_ray, const Point& mouse_pos);
void update_data(); void update_data();
EType get_current_type() const { return m_current; } EType get_current_type() const { return m_current; }