mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
SLA gizmo - clicking on object does not add new points if any point is selected
Remove selected points button is greyed out unless something is selected
This commit is contained in:
parent
b0d78c3fb2
commit
5292f16f32
2 changed files with 28 additions and 18 deletions
|
@ -2064,18 +2064,21 @@ bool GLGizmoSlaSupports::mouse_event(SLAGizmoEventType action, const Vec2d& mous
|
|||
if (instance_id == -1)
|
||||
return false;
|
||||
|
||||
// Regardless of whether the user clicked the object or not, we will unselect all points:
|
||||
select_point(NoPoints);
|
||||
|
||||
// If there is some selection, don't add new point and deselect everything instead.
|
||||
if (m_selection_empty) {
|
||||
Vec3f new_pos;
|
||||
try {
|
||||
new_pos = unproject_on_mesh(mouse_position); // this can throw - we don't want to create a new point in that case
|
||||
m_editing_mode_cache.emplace_back(std::make_pair(sla::SupportPoint(new_pos, m_new_point_head_diameter/2.f, false), true));
|
||||
m_editing_mode_cache.emplace_back(std::make_pair(sla::SupportPoint(new_pos, m_new_point_head_diameter/2.f, false), false));
|
||||
m_unsaved_changes = true;
|
||||
}
|
||||
catch (...) { // not clicked on object
|
||||
return true; // prevents deselection of the gizmo by GLCanvas3D
|
||||
}
|
||||
}
|
||||
else
|
||||
select_point(NoPoints);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2106,9 +2109,8 @@ bool GLGizmoSlaSupports::mouse_event(SLAGizmoEventType action, const Vec2d& mous
|
|||
direction_to_camera = instance_matrix_no_translation.inverse().cast<float>() * direction_to_camera.eval();
|
||||
|
||||
// Iterate over all points, check if they're in the rectangle and if so, check that they are not obscured by the mesh:
|
||||
for (std::pair<sla::SupportPoint, bool>& point_and_selection : m_editing_mode_cache) {
|
||||
const sla::SupportPoint& support_point = point_and_selection.first;
|
||||
Vec3f pos = instance_matrix.cast<float>() * support_point.pos;
|
||||
for (unsigned int i=0; i<m_editing_mode_cache.size(); ++i) {
|
||||
Vec3f pos = instance_matrix.cast<float>() * m_editing_mode_cache[i].first.pos;
|
||||
pos(2) += z_offset;
|
||||
GLdouble out_x, out_y, out_z;
|
||||
::gluProject((GLdouble)pos(0), (GLdouble)pos(1), (GLdouble)pos(2), modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z);
|
||||
|
@ -2118,14 +2120,14 @@ bool GLGizmoSlaSupports::mouse_event(SLAGizmoEventType action, const Vec2d& mous
|
|||
bool is_obscured = false;
|
||||
// Cast a ray in the direction of the camera and look for intersection with the mesh:
|
||||
std::vector<igl::Hit> hits;
|
||||
if (m_AABB.intersect_ray(m_V, m_F, support_point.pos, direction_to_camera, hits))
|
||||
if (m_AABB.intersect_ray(m_V, m_F, m_editing_mode_cache[i].first.pos, direction_to_camera, hits))
|
||||
// FIXME: the intersection could in theory be behind the camera, but as of now we only have camera direction.
|
||||
// Also, the threshold is in mesh coordinates, not in actual dimensions.
|
||||
if (hits.size() > 1 || hits.front().t > 0.001f)
|
||||
is_obscured = true;
|
||||
|
||||
if (!is_obscured)
|
||||
point_and_selection.second = true;
|
||||
select_point(i);
|
||||
}
|
||||
}
|
||||
m_selection_rectangle_active = false;
|
||||
|
@ -2170,6 +2172,8 @@ void GLGizmoSlaSupports::delete_selected_points()
|
|||
// wxGetApp().plater()->reslice();
|
||||
}
|
||||
|
||||
select_point(NoPoints);
|
||||
|
||||
//m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
||||
}
|
||||
|
||||
|
@ -2269,7 +2273,9 @@ RENDER_AGAIN:
|
|||
m_imgui->checkbox(_(L("Lock supports under new islands")), m_lock_unique_islands);
|
||||
force_refresh |= changed != m_lock_unique_islands;
|
||||
|
||||
m_imgui->disabled_begin(m_selection_empty);
|
||||
remove_selected = m_imgui->button(_(L("Remove selected points")));
|
||||
m_imgui->disabled_end();
|
||||
|
||||
m_imgui->text(" "); // vertical gap
|
||||
|
||||
|
@ -2448,10 +2454,13 @@ void GLGizmoSlaSupports::select_point(int i)
|
|||
{
|
||||
if (i == AllPoints || i == NoPoints) {
|
||||
for (auto& point_and_selection : m_editing_mode_cache)
|
||||
point_and_selection.second = ( i == AllPoints ? true : false);
|
||||
point_and_selection.second = ( i == AllPoints );
|
||||
m_selection_empty = (i == NoPoints);
|
||||
}
|
||||
else
|
||||
else {
|
||||
m_editing_mode_cache[i].second = true;
|
||||
m_selection_empty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoSlaSupports::editing_mode_discard_changes()
|
||||
|
|
|
@ -502,6 +502,7 @@ private:
|
|||
bool m_ignore_up_event = false;
|
||||
bool m_combo_box_open = false;
|
||||
bool m_unsaved_changes = false;
|
||||
bool m_selection_empty = true;
|
||||
EState m_old_state = Off; // to be able to see that the gizmo has just been closed (see on_set_state)
|
||||
#if SLAGIZMO_IMGUI_MODAL
|
||||
bool m_show_modal = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue