Measuring: Added Measure gizmo imgui dialog + removed tech ENABLE_MEASURE_GIZMO_DEBUG + locking of features by pressing CTRL key
This commit is contained in:
parent
6c0aff0d23
commit
ed287215db
9 changed files with 311 additions and 162 deletions
|
@ -15,10 +15,26 @@
|
|||
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
|
||||
std::string surface_feature_type_as_string(Slic3r::Measure::SurfaceFeatureType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case Slic3r::Measure::SurfaceFeatureType::Undef: { return L("Undefined"); }
|
||||
case Slic3r::Measure::SurfaceFeatureType::Point: { return L("Point"); }
|
||||
case Slic3r::Measure::SurfaceFeatureType::Edge: { return L("Edge"); }
|
||||
case Slic3r::Measure::SurfaceFeatureType::Circle: { return L("Circle"); }
|
||||
case Slic3r::Measure::SurfaceFeatureType::Plane: { return L("Plane"); }
|
||||
}
|
||||
}
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
static const Slic3r::ColorRGBA HOVER_COLOR = { 0.8f, 0.2f, 0.2f, 1.0f };
|
||||
static const Slic3r::ColorRGBA BASIC_HOVER_COLOR = { 0.8f, 0.2f, 0.2f, 1.0f };
|
||||
static const Slic3r::ColorRGBA EXTENDED_HOVER_COLOR = { 0.2f, 0.8f, 0.2f, 1.0f };
|
||||
static const Slic3r::ColorRGBA LOCK_COLOR = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
|
||||
static const int POINT_ID = 100;
|
||||
static const int EDGE_ID = 200;
|
||||
static const int CIRCLE_ID = 300;
|
||||
|
@ -42,40 +58,39 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event)
|
|||
m_mouse_pos_x = mouse_event.GetX();
|
||||
m_mouse_pos_y = mouse_event.GetY();
|
||||
|
||||
|
||||
if (mouse_event.Moving()) {
|
||||
// only for sure
|
||||
m_mouse_left_down = false;
|
||||
return false;
|
||||
}
|
||||
if (mouse_event.LeftDown()) {
|
||||
else if (mouse_event.LeftDown()) {
|
||||
if (m_hover_id != -1) {
|
||||
m_mouse_left_down = true;
|
||||
|
||||
m_mouse_left_down = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// fix: prevent restart gizmo when reselect object
|
||||
// take responsibility for left up
|
||||
if (m_parent.get_first_hover_volume_idx() >= 0) m_mouse_left_down = true;
|
||||
if (m_parent.get_first_hover_volume_idx() >= 0)
|
||||
m_mouse_left_down = true;
|
||||
|
||||
} else if (mouse_event.LeftUp()) {
|
||||
}
|
||||
else if (mouse_event.LeftUp()) {
|
||||
if (m_mouse_left_down) {
|
||||
// responsible for mouse left up after selecting plane
|
||||
m_mouse_left_down = false;
|
||||
return true;
|
||||
}
|
||||
} else if (mouse_event.Leaving()) {
|
||||
m_mouse_left_down = false;
|
||||
}
|
||||
else if (mouse_event.Leaving())
|
||||
m_mouse_left_down = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GLGizmoMeasure::data_changed()
|
||||
{
|
||||
const Selection & selection = m_parent.get_selection();
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
const ModelObject* model_object = nullptr;
|
||||
const ModelVolume* model_volume = nullptr;
|
||||
if (selection.is_single_full_instance() ||
|
||||
|
@ -87,29 +102,43 @@ void GLGizmoMeasure::data_changed()
|
|||
update_if_needed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GLGizmoMeasure::on_init()
|
||||
bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down)
|
||||
{
|
||||
// FIXME m_shortcut_key = WXK_CONTROL_F;
|
||||
if (action == SLAGizmoEventType::CtrlDown) {
|
||||
if (m_ctrl_kar_filter.is_first()) {
|
||||
if (!m_features.empty())
|
||||
m_mode = EMode::ExtendedSelection;
|
||||
}
|
||||
|
||||
m_ctrl_kar_filter.increase_count();
|
||||
}
|
||||
else if (action == SLAGizmoEventType::CtrlUp) {
|
||||
m_ctrl_kar_filter.reset_count();
|
||||
m_mode = EMode::BasicSelection;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool GLGizmoMeasure::on_init()
|
||||
{
|
||||
m_shortcut_key = WXK_CONTROL_U;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoMeasure::on_set_state()
|
||||
{
|
||||
if (m_state == Off)
|
||||
m_ctrl_kar_filter.reset_count();
|
||||
else
|
||||
m_mode = EMode::BasicSelection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CommonGizmosDataID GLGizmoMeasure::on_get_requirements() const
|
||||
{
|
||||
return CommonGizmosDataID(int(CommonGizmosDataID::SelectionInfo) | int(CommonGizmosDataID::Raycaster));
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string GLGizmoMeasure::on_get_name() const
|
||||
{
|
||||
return _u8L("Measure");
|
||||
|
@ -125,11 +154,9 @@ bool GLGizmoMeasure::on_is_activable() const
|
|||
|
||||
void GLGizmoMeasure::on_render()
|
||||
{
|
||||
#if !ENABLE_MEASURE_GIZMO_DEBUG
|
||||
// do not render if the user is panning/rotating the 3d scene
|
||||
if (m_parent.is_mouse_dragging())
|
||||
return;
|
||||
#endif // !ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
|
||||
|
@ -146,107 +173,76 @@ void GLGizmoMeasure::on_render()
|
|||
size_t facet_idx;
|
||||
m_c->raycaster()->raycasters().front()->unproject_on_mesh(Vec2d(m_mouse_pos_x, m_mouse_pos_y), model_matrix, camera, pos, normal, nullptr, &facet_idx);
|
||||
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
m_imgui->begin(std::string("DEBUG"));
|
||||
m_imgui->checkbox(wxString("Show all features"), m_show_all);
|
||||
m_imgui->checkbox(wxString("Show all planes"), m_show_planes);
|
||||
ImGui::Separator();
|
||||
m_imgui->text(std::string("face_idx: ") + std::to_string(facet_idx));
|
||||
m_imgui->text(std::string("pos_x: ") + std::to_string(pos.x()));
|
||||
m_imgui->text(std::string("pos_y: ") + std::to_string(pos.y()));
|
||||
m_imgui->text(std::string("pos_z: ") + std::to_string(pos.z()));
|
||||
m_imgui->end();
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
std::vector<Measure::SurfaceFeature> features;
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
if (m_show_all || m_show_planes) {
|
||||
features = m_measuring->get_all_features();
|
||||
if (!m_show_planes)
|
||||
features.erase(std::remove_if(features.begin(), features.end(),
|
||||
[](const Measure::SurfaceFeature& f) {
|
||||
return f.get_type() == Measure::SurfaceFeatureType::Plane;
|
||||
}), features.end());
|
||||
if (!m_show_all)
|
||||
features.erase(std::remove_if(features.begin(), features.end(),
|
||||
[](const Measure::SurfaceFeature& f) {
|
||||
return f.get_type() != Measure::SurfaceFeatureType::Plane;
|
||||
}), features.end());
|
||||
if (m_mode == EMode::BasicSelection) {
|
||||
std::optional<Measure::SurfaceFeature> feat = m_measuring->get_feature(facet_idx, pos.cast<double>());
|
||||
if (feat.has_value())
|
||||
features.emplace_back(*feat);
|
||||
}
|
||||
else {
|
||||
if (!m_parent.is_mouse_dragging()) {
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
std::optional<Measure::SurfaceFeature> feat = m_measuring->get_feature(facet_idx, pos.cast<double>());
|
||||
if (feat.has_value())
|
||||
features.emplace_back(*feat);
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
if (m_features != features) {
|
||||
GLGizmoMeasure::on_unregister_raycasters_for_picking();
|
||||
m_features = features;
|
||||
if (m_features.empty())
|
||||
return;
|
||||
if (m_mode == EMode::BasicSelection) {
|
||||
if (m_features != features) {
|
||||
GLGizmoMeasure::on_unregister_raycasters_for_picking();
|
||||
m_features = features;
|
||||
if (m_features.empty())
|
||||
return;
|
||||
|
||||
#if !ENABLE_MEASURE_GIZMO_DEBUG
|
||||
for (const Measure::SurfaceFeature& feature : m_features) {
|
||||
switch (feature.get_type()) {
|
||||
case Measure::SurfaceFeatureType::Point:
|
||||
{
|
||||
m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Edge:
|
||||
{
|
||||
m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Circle:
|
||||
{
|
||||
const auto& [center, radius, n] = feature.get_circle();
|
||||
m_circle.reset();
|
||||
GLModel::Geometry circle_geometry = smooth_torus(64, 16, float(radius), 5.0f * inv_zoom);
|
||||
m_circle.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(circle_geometry.get_as_indexed_triangle_set())));
|
||||
m_circle.model.init_from(std::move(circle_geometry));
|
||||
|
||||
m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) });
|
||||
m_raycasters.insert({ CIRCLE_CENTER_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_CENTER_ID, *m_sphere.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Plane:
|
||||
{
|
||||
const auto& [idx, normal, pt] = feature.get_plane();
|
||||
const std::vector<std::vector<int>> planes_triangles = m_measuring->get_planes_triangle_indices();
|
||||
const std::vector<int>& triangle_indices = planes_triangles[idx];
|
||||
|
||||
const indexed_triangle_set its = (m_old_model_volume != nullptr) ? m_old_model_volume->mesh().its : m_old_model_object->volumes.front()->mesh().its;
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
|
||||
unsigned int i = 0;
|
||||
for (int idx : triangle_indices) {
|
||||
const Vec3f& v0 = its.vertices[its.indices[idx][0]];
|
||||
const Vec3f& v1 = its.vertices[its.indices[idx][1]];
|
||||
const Vec3f& v2 = its.vertices[its.indices[idx][2]];
|
||||
|
||||
const Vec3f n = (v1 - v0).cross(v2 - v0).normalized();
|
||||
init_data.add_vertex(v0, n);
|
||||
init_data.add_vertex(v1, n);
|
||||
init_data.add_vertex(v2, n);
|
||||
init_data.add_triangle(i, i + 1, i + 2);
|
||||
i += 3;
|
||||
for (const Measure::SurfaceFeature& feature : m_features) {
|
||||
switch (feature.get_type()) {
|
||||
case Measure::SurfaceFeatureType::Point:
|
||||
{
|
||||
m_raycasters.insert({ POINT_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, POINT_ID, *m_sphere.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Edge:
|
||||
{
|
||||
m_raycasters.insert({ EDGE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, EDGE_ID, *m_cylinder.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Circle:
|
||||
{
|
||||
const auto& [center, radius, n] = feature.get_circle();
|
||||
m_circle.reset();
|
||||
GLModel::Geometry circle_geometry = smooth_torus(64, 16, float(radius), 5.0f * inv_zoom);
|
||||
m_circle.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(circle_geometry.get_as_indexed_triangle_set())));
|
||||
m_circle.model.init_from(std::move(circle_geometry));
|
||||
|
||||
m_plane.reset();
|
||||
m_plane.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(init_data.get_as_indexed_triangle_set())));
|
||||
m_plane.model.init_from(std::move(init_data));
|
||||
m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
m_raycasters.insert({ CIRCLE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_ID, *m_circle.mesh_raycaster) });
|
||||
m_raycasters.insert({ CIRCLE_CENTER_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, CIRCLE_CENTER_ID, *m_sphere.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Plane:
|
||||
{
|
||||
const auto& [idx, normal, pt] = feature.get_plane();
|
||||
const std::vector<std::vector<int>> planes_triangles = m_measuring->get_planes_triangle_indices();
|
||||
const std::vector<int>& triangle_indices = planes_triangles[idx];
|
||||
|
||||
const indexed_triangle_set its = (m_old_model_volume != nullptr) ? m_old_model_volume->mesh().its : m_old_model_object->volumes.front()->mesh().its;
|
||||
GLModel::Geometry init_data;
|
||||
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
|
||||
unsigned int i = 0;
|
||||
for (int idx : triangle_indices) {
|
||||
const Vec3f& v0 = its.vertices[its.indices[idx][0]];
|
||||
const Vec3f& v1 = its.vertices[its.indices[idx][1]];
|
||||
const Vec3f& v2 = its.vertices[its.indices[idx][2]];
|
||||
|
||||
const Vec3f n = (v1 - v0).cross(v2 - v0).normalized();
|
||||
init_data.add_vertex(v0, n);
|
||||
init_data.add_vertex(v1, n);
|
||||
init_data.add_vertex(v2, n);
|
||||
init_data.add_triangle(i, i + 1, i + 2);
|
||||
i += 3;
|
||||
}
|
||||
|
||||
m_plane.reset();
|
||||
m_plane.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(init_data.get_as_indexed_triangle_set())));
|
||||
m_plane.model.init_from(std::move(init_data));
|
||||
m_raycasters.insert({ PLANE_ID, m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, PLANE_ID, *m_plane.mesh_raycaster) });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ENABLE_MEASURE_GIZMO_DEBUG
|
||||
}
|
||||
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
|
||||
|
@ -262,6 +258,13 @@ void GLGizmoMeasure::on_render()
|
|||
|
||||
const Transform3d& view_matrix = camera.get_view_matrix();
|
||||
|
||||
ColorRGBA color;
|
||||
switch (m_mode)
|
||||
{
|
||||
case EMode::BasicSelection: { color = BASIC_HOVER_COLOR; break; }
|
||||
case EMode::ExtendedSelection: { color = LOCK_COLOR; break; }
|
||||
}
|
||||
|
||||
for (const Measure::SurfaceFeature& feature : m_features) {
|
||||
switch (feature.get_type()) {
|
||||
case Measure::SurfaceFeatureType::Point:
|
||||
|
@ -272,7 +275,7 @@ void GLGizmoMeasure::on_render()
|
|||
shader->set_uniform("view_model_matrix", view_model_matrix);
|
||||
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * feature_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
shader->set_uniform("view_normal_matrix", view_normal_matrix);
|
||||
m_sphere.model.set_color(HOVER_COLOR);
|
||||
m_sphere.model.set_color(color);
|
||||
m_sphere.model.render();
|
||||
auto it = m_raycasters.find(POINT_ID);
|
||||
if (it != m_raycasters.end() && it->second != nullptr)
|
||||
|
@ -288,7 +291,7 @@ void GLGizmoMeasure::on_render()
|
|||
shader->set_uniform("view_model_matrix", center_view_model_matrix);
|
||||
const Matrix3d center_view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * center_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
shader->set_uniform("view_normal_matrix", center_view_normal_matrix);
|
||||
m_sphere.model.set_color(HOVER_COLOR);
|
||||
m_sphere.model.set_color(color);
|
||||
m_sphere.model.render();
|
||||
auto it = m_raycasters.find(CIRCLE_CENTER_ID);
|
||||
if (it != m_raycasters.end() && it->second != nullptr)
|
||||
|
@ -299,7 +302,7 @@ void GLGizmoMeasure::on_render()
|
|||
shader->set_uniform("view_model_matrix", circle_view_model_matrix);
|
||||
const Matrix3d circle_view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * circle_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
shader->set_uniform("view_normal_matrix", circle_view_normal_matrix);
|
||||
m_circle.model.set_color(HOVER_COLOR);
|
||||
m_circle.model.set_color(color);
|
||||
m_circle.model.render();
|
||||
it = m_raycasters.find(CIRCLE_ID);
|
||||
if (it != m_raycasters.end() && it->second != nullptr)
|
||||
|
@ -316,7 +319,7 @@ void GLGizmoMeasure::on_render()
|
|||
shader->set_uniform("view_model_matrix", view_model_matrix);
|
||||
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * feature_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
shader->set_uniform("view_normal_matrix", view_normal_matrix);
|
||||
m_cylinder.model.set_color(HOVER_COLOR);
|
||||
m_cylinder.model.set_color(color);
|
||||
m_cylinder.model.render();
|
||||
auto it = m_raycasters.find(EDGE_ID);
|
||||
if (it != m_raycasters.end() && it->second != nullptr)
|
||||
|
@ -331,7 +334,7 @@ void GLGizmoMeasure::on_render()
|
|||
shader->set_uniform("view_model_matrix", view_model_matrix);
|
||||
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
shader->set_uniform("view_normal_matrix", view_normal_matrix);
|
||||
m_plane_models_cache[idx].set_color(HOVER_COLOR);
|
||||
m_plane_models_cache[idx].set_color(color);
|
||||
m_plane_models_cache[idx].render();
|
||||
auto it = m_raycasters.find(PLANE_ID);
|
||||
if (it != m_raycasters.end() && it->second != nullptr)
|
||||
|
@ -344,8 +347,6 @@ void GLGizmoMeasure::on_render()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GLGizmoMeasure::update_if_needed()
|
||||
{
|
||||
auto update_plane_models_cache = [this](const indexed_triangle_set& its) {
|
||||
|
@ -423,6 +424,124 @@ void GLGizmoMeasure::update_if_needed()
|
|||
}
|
||||
}
|
||||
|
||||
void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit)
|
||||
{
|
||||
static Measure::SurfaceFeature last_feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Undef, Vec3d::Zero(), Vec3d::Zero(), std::nullopt, 0.0);
|
||||
|
||||
static float last_y = 0.0f;
|
||||
static float last_h = 0.0f;
|
||||
|
||||
m_imgui->begin(_L("Measure tool"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
|
||||
|
||||
// adjust window position to avoid overlap the view toolbar
|
||||
const float win_h = ImGui::GetWindowHeight();
|
||||
y = std::min(y, bottom_limit - win_h);
|
||||
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always);
|
||||
if (last_h != win_h || last_y != y) {
|
||||
// ask canvas for another frame to render the window in the correct position
|
||||
m_imgui->set_requires_extra_frame();
|
||||
if (last_h != win_h)
|
||||
last_h = win_h;
|
||||
if (last_y != y)
|
||||
last_y = y;
|
||||
}
|
||||
|
||||
if (m_features.empty())
|
||||
m_imgui->text(_u8L("Select features to measure"));
|
||||
|
||||
auto add_row_to_table = [this](const wxString& label, const std::string& value) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
m_imgui->text(value);
|
||||
};
|
||||
|
||||
const Transform3d volume_matrix = m_parent.get_selection().get_first_volume()->world_matrix();
|
||||
Measure::SurfaceFeature curr_feature = Measure::SurfaceFeature(Measure::SurfaceFeatureType::Undef, Vec3d::Zero(), Vec3d::Zero(), std::nullopt, 0.0);
|
||||
for (size_t i = 0; i < m_features.size(); ++i) {
|
||||
curr_feature = m_features[i];
|
||||
const Measure::SurfaceFeatureType type = curr_feature.get_type();
|
||||
if (type != Measure::SurfaceFeatureType::Undef) {
|
||||
const std::string header = surface_feature_type_as_string(type) + std::string("##") + std::to_string(i);
|
||||
if (ImGui::CollapsingHeader(header.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
if (ImGui::BeginTable("Data", 2)) {
|
||||
switch (type)
|
||||
{
|
||||
case Measure::SurfaceFeatureType::Point:
|
||||
{
|
||||
const Vec3d position = volume_matrix * curr_feature.get_point();
|
||||
char buf[1024];
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", position.x(), position.y(), position.z());
|
||||
add_row_to_table(_u8L("Position") + ":", std::string(buf));
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Edge:
|
||||
{
|
||||
auto [from, to] = curr_feature.get_edge();
|
||||
from = volume_matrix * from;
|
||||
to = volume_matrix * to;
|
||||
char buf[1024];
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", from.x(), from.y(), from.z());
|
||||
add_row_to_table(_u8L("From") + ":", std::string(buf));
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", to.x(), to.y(), to.z());
|
||||
add_row_to_table(_u8L("To") + ":", std::string(buf));
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Circle:
|
||||
{
|
||||
auto [center, radius, normal] = curr_feature.get_circle();
|
||||
center = volume_matrix * center;
|
||||
normal = volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal;
|
||||
char buf[1024];
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", center.x(), center.y(), center.z());
|
||||
add_row_to_table(_u8L("Center") + ":", std::string(buf));
|
||||
sprintf(buf, "%.3f", radius);
|
||||
add_row_to_table(_u8L("Radius") + ":", std::string(buf));
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", normal.x(), normal.y(), normal.z());
|
||||
add_row_to_table(_u8L("Normal") + ":", std::string(buf));
|
||||
break;
|
||||
}
|
||||
case Measure::SurfaceFeatureType::Plane:
|
||||
{
|
||||
auto [idx, normal, origin] = curr_feature.get_plane();
|
||||
origin = volume_matrix * origin;
|
||||
normal = volume_matrix.matrix().block(0, 0, 3, 3).inverse().transpose() * normal;
|
||||
char buf[1024];
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", origin.x(), origin.y(), origin.z());
|
||||
add_row_to_table(_u8L("Origin") + ":", std::string(buf));
|
||||
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", normal.x(), normal.y(), normal.z());
|
||||
add_row_to_table(_u8L("Normal") + ":", std::string(buf));
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (last_feature != curr_feature) {
|
||||
// the dialog may have changed its size, ask for an extra frame to render it properly
|
||||
last_feature = curr_feature;
|
||||
m_imgui->set_requires_extra_frame();
|
||||
}
|
||||
|
||||
if (!m_features.empty()) {
|
||||
static const std::string ctrl =
|
||||
#ifdef __APPLE__
|
||||
"⌘"
|
||||
#else
|
||||
"Ctrl"
|
||||
#endif //__APPLE__
|
||||
;
|
||||
|
||||
ImGui::Separator();
|
||||
m_imgui->text(_u8L("Press") + " " + ctrl + " " + _u8L("to enable extended selection"));
|
||||
}
|
||||
m_imgui->end();
|
||||
}
|
||||
|
||||
void GLGizmoMeasure::on_register_raycasters_for_picking()
|
||||
{
|
||||
// the features are rendered on top of the scene, so the raytraced picker should take it into account
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue