From ca6a7ac8d52cd65d96304b0daa46334a5d200b5c Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 3 Jan 2019 11:24:03 +0100 Subject: [PATCH] Further improvement in objects manipulation using sidebar (multiselection) --- src/libslic3r/Technologies.hpp | 60 +++++++++++------------ src/slic3r/GUI/GLCanvas3D.cpp | 50 ++++++++++++++++--- src/slic3r/GUI/GLCanvas3D.hpp | 4 ++ src/slic3r/GUI/GUI_ObjectManipulation.cpp | 12 +++++ src/slic3r/GUI/Plater.cpp | 4 ++ 5 files changed, 94 insertions(+), 36 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 681259996..38d0f5b6e 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -10,41 +10,41 @@ // Log debug messages to console when changing selection #define ENABLE_SELECTION_DEBUG_OUTPUT 0 -//============= -// 1.42.0 techs -//============= -#define ENABLE_1_42_0 1 - -// Uses a unique opengl context -#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0) -// Disable synchronization of unselected instances -#define DISABLE_INSTANCES_SYNCH (0 && ENABLE_1_42_0) -// Keeps objects on bed while scaling them using the scale gizmo -#define ENABLE_ENSURE_ON_BED_WHILE_SCALING (1 && ENABLE_1_42_0) -// All rotations made using the rotate gizmo are done with respect to the world reference system -#define ENABLE_WORLD_ROTATIONS (1 && ENABLE_1_42_0) -// Scene's GUI made using imgui library -#define ENABLE_IMGUI (1 && ENABLE_1_42_0) -#define DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI (1 && ENABLE_IMGUI) -// Modified Sla support gizmo -#define ENABLE_SLA_SUPPORT_GIZMO_MOD (1 && ENABLE_1_42_0) -// Removes the wxNotebook from plater -#define ENABLE_REMOVE_TABS_FROM_PLATER (1 && ENABLE_1_42_0) -// Use wxDataViewRender instead of wxDataViewCustomRenderer -#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0) -// Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active -#define ENABLE_RENDER_SELECTION_CENTER (0 && ENABLE_1_42_0) -// Show visual hints in the 3D scene when sidebar matrix fields have focus -#define ENABLE_SIDEBAR_VISUAL_HINTS (1 && ENABLE_1_42_0) -// Separate rendering for opaque and transparent volumes -#define ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING (1 && ENABLE_1_42_0) - //==================== // 1.42.0.alpha1 techs //==================== #define ENABLE_1_42_0_ALPHA1 1 -#define ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION (1 && ENABLE_1_42_0_ALPHA1) +// Uses a unique opengl context +#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0_ALPHA1) +// Disable synchronization of unselected instances +#define DISABLE_INSTANCES_SYNCH (0 && ENABLE_1_42_0_ALPHA1) +// Keeps objects on bed while scaling them using the scale gizmo +#define ENABLE_ENSURE_ON_BED_WHILE_SCALING (1 && ENABLE_1_42_0_ALPHA1) +// All rotations made using the rotate gizmo are done with respect to the world reference system +#define ENABLE_WORLD_ROTATIONS (1 && ENABLE_1_42_0_ALPHA1) +// Scene's GUI made using imgui library +#define ENABLE_IMGUI (1 && ENABLE_1_42_0_ALPHA1) +#define DISABLE_MOVE_ROTATE_SCALE_GIZMOS_IMGUI (1 && ENABLE_IMGUI) +// Modified Sla support gizmo +#define ENABLE_SLA_SUPPORT_GIZMO_MOD (1 && ENABLE_1_42_0_ALPHA1) +// Removes the wxNotebook from plater +#define ENABLE_REMOVE_TABS_FROM_PLATER (1 && ENABLE_1_42_0_ALPHA1) +// Use wxDataViewRender instead of wxDataViewCustomRenderer +#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1) +// Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active +#define ENABLE_RENDER_SELECTION_CENTER (0 && ENABLE_1_42_0_ALPHA1) +// Show visual hints in the 3D scene when sidebar matrix fields have focus +#define ENABLE_SIDEBAR_VISUAL_HINTS (1 && ENABLE_1_42_0_ALPHA1) +// Separate rendering for opaque and transparent volumes +#define ENABLE_IMPROVED_TRANSPARENT_VOLUMES_RENDERING (1 && ENABLE_1_42_0_ALPHA1) + +//==================== +// 1.42.0.alpha2 techs +//==================== +#define ENABLE_1_42_0_ALPHA2 1 + +#define ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION (1 && ENABLE_1_42_0_ALPHA2) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index df70a787e..a49a130ee 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3648,6 +3648,10 @@ wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event); wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent); +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION +wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_ROTATED, SimpleEvent); +wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_SCALED, SimpleEvent); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION wxDEFINE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent); wxDEFINE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event); wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); @@ -5023,6 +5027,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) bool already_selected = m_selection.contains_volume(m_hover_volume_id); bool shift_down = evt.ShiftDown(); +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + Selection::IndicesList curr_idxs = m_selection.get_volume_idxs(); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + if (already_selected && shift_down) m_selection.remove(m_hover_volume_id); else @@ -5031,11 +5039,21 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_selection.add(m_hover_volume_id, add_as_single); } - m_gizmos.update_on_off_state(m_selection); - _update_gizmos_data(); - wxGetApp().obj_manipul()->update_settings_value(m_selection); - post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); - m_dirty = true; +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + if (curr_idxs != m_selection.get_volume_idxs()) + { +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + + m_gizmos.update_on_off_state(m_selection); + _update_gizmos_data(); +#if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + wxGetApp().obj_manipul()->update_settings_value(m_selection); +#endif // !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); + m_dirty = true; +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + } +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } } @@ -5408,6 +5426,15 @@ void GLCanvas3D::do_move() ModelObject* model_object = m_model->objects[object_idx]; if (model_object != nullptr) { +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + if (selection_mode == Selection::Instance) + model_object->instances[instance_idx]->set_offset(v->get_instance_offset()); + else if (selection_mode == Selection::Volume) + model_object->volumes[volume_idx]->set_offset(v->get_volume_offset()); + + object_moved = true; + model_object->invalidate_bounding_box(); +#else if (selection_mode == Selection::Instance) { model_object->instances[instance_idx]->set_offset(v->get_instance_offset()); @@ -5419,7 +5446,8 @@ void GLCanvas3D::do_move() object_moved = true; } if (object_moved) - model_object->invalidate_bounding_box(); + model_object->invalidate_bounding_box(); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } } else if (object_idx == 1000) @@ -5490,7 +5518,12 @@ void GLCanvas3D::do_rotate() m->translate_instance(i.second, shift); } +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + if (!done.empty()) + post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_ROTATED)); +#else post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } void GLCanvas3D::do_scale() @@ -5541,7 +5574,12 @@ void GLCanvas3D::do_scale() m->translate_instance(i.second, shift); } +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + if (!done.empty()) + post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_ROTATED)); +#else post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } void GLCanvas3D::do_flatten() diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 3c963f8be..a46168094 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -110,6 +110,10 @@ wxDECLARE_EVENT(EVT_GLCANVAS_QUESTION_MARK, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event); // data: +1 => increase, -1 => decrease wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent); +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION +wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_ROTATED, SimpleEvent); +wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_SCALED, SimpleEvent); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event); wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); wxDECLARE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 9b730b3f2..32a38a77c 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -413,6 +413,10 @@ void ObjectManipulation::change_rotation_value(const Vec3d& rotation) canvas->get_selection().start_dragging(); canvas->get_selection().rotate(rad_rotation, selection.is_single_full_instance()); canvas->do_rotate(); + +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + m_cache_rotation = rotation; +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } void ObjectManipulation::change_scale_value(const Vec3d& scale) @@ -443,6 +447,10 @@ void ObjectManipulation::change_scale_value(const Vec3d& scale) canvas->get_selection().start_dragging(); canvas->get_selection().scale(scaling_factor, false); canvas->do_scale(); + +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + m_cache_scale = scale; +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } void ObjectManipulation::change_size_value(const Vec3d& size) @@ -457,6 +465,10 @@ void ObjectManipulation::change_size_value(const Vec3d& size) } change_scale_value(100.0 * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2))); + +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + m_cache_size = size; +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } } //namespace GUI diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 65ec044fd..bb5eec204 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1196,6 +1196,10 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) { if (evt.data == 1) this->q->increase_instances(); else if (this->can_decrease_instances()) this->q->decrease_instances(); }); view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_MOVED, [this](SimpleEvent&) { update(); }); view3D_canvas->Bind(EVT_GLCANVAS_WIPETOWER_MOVED, &priv::on_wipetower_moved, this); +#if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_ROTATED, [this](SimpleEvent&) { update(); }); + view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_SCALED, [this](SimpleEvent&) { update(); }); +#endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION view3D_canvas->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, [this](Event &evt) { this->sidebar->enable_buttons(evt.data); }); view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_GEOMETRY, &priv::on_update_geometry, this); view3D_canvas->Bind(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, &priv::on_3dcanvas_mouse_dragging_finished, this);