diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 47729cffb6..440ca5fc6f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1346,7 +1346,7 @@ bool GLCanvas3D::Selection::is_single_full_instance() const int object_idx = m_valid ? get_object_idx() : -1; if (object_idx != -1) { - if (get_instance_idx() != -1) + if ((object_idx != -1) && (object_idx < 1000)) return m_model->objects[object_idx]->volumes.size() == m_list.size(); } @@ -1653,7 +1653,7 @@ void GLCanvas3D::Selection::_calc_bounding_box() const { for (unsigned int i : m_list) { - m_bounding_box.merge((*m_volumes)[i]->transformed_bounding_box()); + m_bounding_box.merge((*m_volumes)[i]->transformed_convex_hull_bounding_box()); } } m_bounding_box_dirty = false; @@ -1702,7 +1702,7 @@ void GLCanvas3D::Selection::_render_unselected_instances() const if (it == boxes.end()) it = boxes.insert(InstanceToBoxMap::value_type(box_id, BoundingBoxf3())).first; - it->second.merge(v->transformed_bounding_box()); + it->second.merge(v->transformed_convex_hull_bounding_box()); done.insert(j); } @@ -2081,6 +2081,9 @@ bool GLCanvas3D::Gizmos::is_running() const bool GLCanvas3D::Gizmos::is_dragging() const { + if (!m_enabled) + return false; + GLGizmoBase* curr = _get_current(); return (curr != nullptr) ? curr->is_dragging() : false; } @@ -2088,6 +2091,9 @@ bool GLCanvas3D::Gizmos::is_dragging() const #if ENABLE_EXTENDED_SELECTION void GLCanvas3D::Gizmos::start_dragging(const GLCanvas3D::Selection& selection) { + if (!m_enabled) + return; + GLGizmoBase* curr = _get_current(); if (curr != nullptr) curr->start_dragging(selection); @@ -2095,6 +2101,9 @@ void GLCanvas3D::Gizmos::start_dragging(const GLCanvas3D::Selection& selection) #else void GLCanvas3D::Gizmos::start_dragging(const BoundingBoxf3& box) { + if (!m_enabled) + return; + GLGizmoBase* curr = _get_current(); if (curr != nullptr) curr->start_dragging(box); @@ -2103,6 +2112,9 @@ void GLCanvas3D::Gizmos::start_dragging(const BoundingBoxf3& box) void GLCanvas3D::Gizmos::stop_dragging() { + if (!m_enabled) + return; + GLGizmoBase* curr = _get_current(); if (curr != nullptr) curr->stop_dragging(); @@ -2650,8 +2662,8 @@ wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); #if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); -#endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); +#endif // !ENABLE_EXTENDED_SELECTION GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) : m_canvas(canvas) @@ -3784,7 +3796,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_selection.scale(m_gizmos.get_scale()); _on_scale(); #else - m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); + post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale())); #endif // ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION wxGetApp().obj_manipul()->update_settings_value(m_selection); @@ -3879,7 +3891,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (m_gizmos.get_current_type() == Gizmos::Flatten) { // Rotate the object so the normal points downward: +#if ENABLE_EXTENDED_SELECTION + m_regenerate_volumes = false; + m_selection.rotate(m_gizmos.get_flattening_rotation()); + _on_flatten(); + wxGetApp().obj_manipul()->update_settings_value(m_selection); +#else post_event(Vec3dEvent(EVT_GIZMO_FLATTEN, m_gizmos.get_flattening_rotation())); +#endif // ENABLE_EXTENDED_SELECTION } m_dirty = true; @@ -5002,7 +5021,7 @@ void GLCanvas3D::_render_objects() const void GLCanvas3D::_render_selection() const { Gizmos::EType type = m_gizmos.get_current_type(); - bool show_indirect_selection = m_gizmos.is_running() && ((type == Gizmos::Rotate) || (type == Gizmos::Scale)); + bool show_indirect_selection = m_gizmos.is_running() && ((type == Gizmos::Rotate) || (type == Gizmos::Scale) || (type == Gizmos::Flatten)); m_selection.render(show_indirect_selection); } #endif // ENABLE_EXTENDED_SELECTION @@ -6354,11 +6373,9 @@ void GLCanvas3D::_on_move() std::set> done; // prevent moving instances twice bool object_moved = false; Vec3d wipe_tower_origin = Vec3d::Zero(); - const Selection::IndicesList& selection = m_selection.get_volume_idxs(); - for (unsigned int i : selection) + for (const GLVolume* v : m_volumes.volumes) { - const GLVolume* v = m_volumes.volumes[i]; int object_idx = v->object_idx(); int instance_idx = v->instance_idx(); @@ -6398,11 +6415,9 @@ void GLCanvas3D::_on_rotate() return; std::set> done; // prevent rotating instances twice - const Selection::IndicesList& selection = m_selection.get_volume_idxs(); - for (unsigned int i : selection) + for (const GLVolume* v : m_volumes.volumes) { - const GLVolume* v = m_volumes.volumes[i]; int object_idx = v->object_idx(); if (object_idx >= 1000) continue; @@ -6434,18 +6449,16 @@ void GLCanvas3D::_on_scale() return; std::set> done; // prevent scaling instances twice - const Selection::IndicesList& selection = m_selection.get_volume_idxs(); - for (unsigned int i : selection) + for (const GLVolume* v : m_volumes.volumes) { - const GLVolume* v = m_volumes.volumes[i]; int object_idx = v->object_idx(); if (object_idx >= 1000) continue; int instance_idx = v->instance_idx(); - // prevent rotating instances twice + // prevent scaling instances twice std::pair done_id(object_idx, instance_idx); if (done.find(done_id) != done.end()) continue; @@ -6463,6 +6476,12 @@ void GLCanvas3D::_on_scale() // schedule_background_process } + +void GLCanvas3D::_on_flatten() +{ + _on_rotate(); +} + #else void GLCanvas3D::_on_move(const std::vector& volume_idxs) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 8029ed4c44..e4019e2a1d 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -118,8 +118,8 @@ wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); #if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDECLARE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); -#endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); +#endif // !ENABLE_EXTENDED_SELECTION class GLCanvas3D @@ -946,6 +946,7 @@ private: void _on_move(); void _on_rotate(); void _on_scale(); + void _on_flatten(); #else void _on_move(const std::vector& volume_idxs); #endif // ENABLE_EXTENDED_SELECTION diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 88672f5061..e01f57ff90 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -1482,6 +1482,23 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const else ::glColor4f(0.9f, 0.9f, 0.9f, 0.5f); +#if ENABLE_EXTENDED_SELECTION + int instance_idx = selection.get_instance_idx(); + if ((instance_idx != -1) && (m_model_object != nullptr)) + { + Transform3d m = m_model_object->instances[instance_idx]->world_matrix(); + m.pretranslate(dragged_offset); + ::glPushMatrix(); + ::glMultMatrixd(m.data()); + ::glBegin(GL_POLYGON); + for (const Vec3d& vertex : m_planes[i].vertices) + { + ::glVertex3dv(vertex.data()); + } + ::glEnd(); + ::glPopMatrix(); + } +#else for (const InstanceData& inst : m_instances) { Transform3d m = inst.matrix; m.pretranslate(dragged_offset); @@ -1493,6 +1510,7 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const ::glEnd(); ::glPopMatrix(); } +#endif // ENABLE_EXTENDED_SELECTION } ::glDisable(GL_BLEND); @@ -1509,6 +1527,21 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const for (unsigned int i = 0; i < m_planes.size(); ++i) { ::glColor3f(1.0f, 1.0f, picking_color_component(i)); +#if ENABLE_EXTENDED_SELECTION + int instance_idx = selection.get_instance_idx(); + if ((instance_idx != -1) && (m_model_object != nullptr)) + { + ::glPushMatrix(); + ::glMultMatrixd(m_model_object->instances[instance_idx]->world_matrix().data()); + ::glBegin(GL_POLYGON); + for (const Vec3d& vertex : m_planes[i].vertices) + { + ::glVertex3dv(vertex.data()); + } + ::glEnd(); + ::glPopMatrix(); + } +#else for (const InstanceData& inst : m_instances) { ::glPushMatrix(); ::glMultMatrixd(inst.matrix.data()); @@ -1518,6 +1551,7 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const ::glEnd(); ::glPopMatrix(); } +#endif // ENABLE_EXTENDED_SELECTION } } @@ -1525,12 +1559,14 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) { m_model_object = model_object; +#if !ENABLE_EXTENDED_SELECTION // ...and save the updated positions of the object instances: if (m_model_object && !m_model_object->instances.empty()) { m_instances.clear(); for (const auto* instance : m_model_object->instances) m_instances.emplace_back(instance->world_matrix()); } +#endif // !ENABLE_EXTENDED_SELECTION if (is_plane_update_necessary()) update_planes(); diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 7c0196a83c..cb0ef4f50c 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -427,12 +427,14 @@ private: SourceDataSummary m_source_data; std::vector m_planes; +#if !ENABLE_EXTENDED_SELECTION struct InstanceData { Transform3d matrix; InstanceData(const Transform3d& matrix) : matrix(matrix) {} }; std::vector m_instances; +#endif // !ENABLE_EXTENDED_SELECTION Vec3d m_starting_center; const ModelObject* m_model_object = nullptr;