Gizmo measure - Show radius of single selected circle, to allow for object scaling

This commit is contained in:
enricoturri1966 2022-11-30 12:51:37 +01:00
parent b45ae31af3
commit 93a3ee5019
2 changed files with 67 additions and 39 deletions

View File

@ -422,8 +422,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event)
m_selected_sphere_raycasters.push_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, SEL_SPHERE_1_ID, *m_sphere.mesh_raycaster));
}
if (m_selected_features != selected_features_old && m_selected_features.second.feature.has_value())
m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get());
update_measurement_result();
m_imgui->set_requires_extra_frame();
@ -469,7 +468,7 @@ void GLGizmoMeasure::data_changed()
m_last_inv_zoom = 0.0f;
m_last_plane_idx = -1;
if (m_pending_scale) {
m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get());
update_measurement_result();
m_pending_scale = false;
}
else
@ -517,8 +516,10 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po
m_parent.request_extra_frame();
}
else if (action == SLAGizmoEventType::Escape) {
if (!m_selected_features.first.feature.has_value())
if (!m_selected_features.first.feature.has_value()) {
update_measurement_result();
return false;
}
else {
if (m_selected_features.second.feature.has_value()) {
remove_selected_sphere_raycaster(SEL_SPHERE_2_ID);
@ -528,6 +529,8 @@ bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_po
remove_selected_sphere_raycaster(SEL_SPHERE_1_ID);
m_selected_features.first.feature.reset();
}
update_measurement_result();
}
}
@ -1135,7 +1138,10 @@ void GLGizmoMeasure::render_dimensioning()
{
static SelectedFeatures last_selected_features;
if (!m_selected_features.first.feature.has_value() || !m_selected_features.second.feature.has_value())
if (!m_selected_features.first.feature.has_value())
return;
if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() != Measure::SurfaceFeatureType::Circle)
return;
GLShaderProgram* shader = wxGetApp().get_shader("flat");
@ -1343,6 +1349,7 @@ void GLGizmoMeasure::render_dimensioning()
const Vec3d new_center = selection.get_bounding_box().center();
const TrafoData trafo_data(ratio, old_center, new_center);
scale_feature(*m_selected_features.first.feature, trafo_data);
if (m_selected_features.second.feature.has_value())
scale_feature(*m_selected_features.second.feature, trafo_data);
// update measure on next call to data_changed()
@ -1646,11 +1653,22 @@ void GLGizmoMeasure::render_dimensioning()
glsafe(::glDisable(GL_DEPTH_TEST));
if (m_selected_features.second.feature.has_value()) {
const bool has_distance = m_measurement_result.has_distance_data();
const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature);
const Measure::SurfaceFeature* f2 = &(*m_selected_features.second.feature);
const Measure::SurfaceFeature* f2 = nullptr;
std::unique_ptr<Measure::SurfaceFeature> temp_feature;
if (m_selected_features.second.feature.has_value())
f2 = &(*m_selected_features.second.feature);
else {
assert(m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Circle);
temp_feature = std::make_unique<Measure::SurfaceFeature>(std::get<0>(m_selected_features.first.feature->get_circle()));
f2 = temp_feature.get();
}
if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() != Measure::SurfaceFeatureType::Circle)
return;
Measure::SurfaceFeatureType ft1 = f1->get_type();
Measure::SurfaceFeatureType ft2 = f2->get_type();
@ -1679,7 +1697,6 @@ void GLGizmoMeasure::render_dimensioning()
: *m_measurement_result.distance_strict;
point_point(dap.from, dap.to, dap.dist);
}
}
glsafe(::glEnable(GL_DEPTH_TEST));
@ -2051,5 +2068,15 @@ void GLGizmoMeasure::remove_selected_sphere_raycaster(int id)
m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo, id);
}
void GLGizmoMeasure::update_measurement_result()
{
if (!m_selected_features.first.feature.has_value())
m_measurement_result = Measure::MeasurementResult();
else if (m_selected_features.second.feature.has_value())
m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, *m_selected_features.second.feature, m_measuring.get());
else if (!m_selected_features.second.feature.has_value() && m_selected_features.first.feature->get_type() == Measure::SurfaceFeatureType::Circle)
m_measurement_result = Measure::get_measurement(*m_selected_features.first.feature, Measure::SurfaceFeature(std::get<0>(m_selected_features.first.feature->get_circle())), m_measuring.get());
}
} // namespace GUI
} // namespace Slic3r

View File

@ -176,6 +176,7 @@ protected:
virtual void on_unregister_raycasters_for_picking() override;
void remove_selected_sphere_raycaster(int id);
void update_measurement_result();
};
} // namespace GUI