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
@ -408,12 +408,10 @@ Measuring::Measuring(const indexed_triangle_set& its)
|
||||
Measuring::~Measuring() {}
|
||||
|
||||
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
std::vector<SurfaceFeature> Measuring::get_all_features() const
|
||||
{
|
||||
return priv->get_all_features();
|
||||
}
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
|
||||
std::optional<SurfaceFeature> Measuring::get_feature(size_t face_idx, const Vec3d& point) const
|
||||
|
@ -59,6 +59,10 @@ public:
|
||||
return this->m_value == other.m_value;
|
||||
}
|
||||
|
||||
bool operator != (const SurfaceFeature& other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
private:
|
||||
SurfaceFeatureType m_type = SurfaceFeatureType::Undef;
|
||||
Vec3d m_pt1;
|
||||
@ -79,11 +83,9 @@ public:
|
||||
explicit Measuring(const indexed_triangle_set& its);
|
||||
~Measuring();
|
||||
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
// Return a reference to a list of all features identified on the its.
|
||||
// Use only for debugging. Expensive, do not call often.
|
||||
std::vector<SurfaceFeature> get_all_features() const;
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
// Given a face_idx where the mouse cursor points, return a feature that
|
||||
// should be highlighted (if any).
|
||||
|
@ -68,8 +68,6 @@
|
||||
#define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING)
|
||||
// Enable Measure Gizmo
|
||||
#define ENABLE_MEASURE_GIZMO (1 && ENABLE_RAYCAST_PICKING)
|
||||
// Enable debug code for Measure Gizmo
|
||||
#define ENABLE_MEASURE_GIZMO_DEBUG (0 && ENABLE_MEASURE_GIZMO)
|
||||
|
||||
|
||||
#endif // _prusaslicer_technologies_h_
|
||||
|
@ -19,6 +19,9 @@
|
||||
#if ENABLE_RAYCAST_PICKING
|
||||
#include "SceneRaycaster.hpp"
|
||||
#endif // ENABLE_RAYCAST_PICKING
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
#include "GUI_Utils.hpp"
|
||||
#endif // ENABLE_MEASURE_GIZMO
|
||||
|
||||
#include "libslic3r/Slicing.hpp"
|
||||
|
||||
@ -135,6 +138,7 @@ private:
|
||||
wxTimer* m_timer;
|
||||
};
|
||||
|
||||
#if !ENABLE_MEASURE_GIZMO
|
||||
class KeyAutoRepeatFilter
|
||||
{
|
||||
size_t m_count{ 0 };
|
||||
@ -144,6 +148,7 @@ public:
|
||||
void reset_count() { m_count = 0; }
|
||||
bool is_first() const { return m_count == 0; }
|
||||
};
|
||||
#endif // !ENABLE_MEASURE_GIZMO
|
||||
|
||||
wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent);
|
||||
|
||||
|
@ -416,6 +416,18 @@ public:
|
||||
~TaskTimer();
|
||||
};
|
||||
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
class KeyAutoRepeatFilter
|
||||
{
|
||||
size_t m_count{ 0 };
|
||||
|
||||
public:
|
||||
void increase_count() { ++m_count; }
|
||||
void reset_count() { m_count = 0; }
|
||||
bool is_first() const { return m_count == 0; }
|
||||
};
|
||||
#endif // ENABLE_MEASURE_GIZMO
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
@ -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,37 +58,36 @@ 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;
|
||||
|
||||
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();
|
||||
@ -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,51 +173,20 @@ 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());
|
||||
}
|
||||
else {
|
||||
if (!m_parent.is_mouse_dragging()) {
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
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);
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
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:
|
||||
@ -246,7 +242,7 @@ void GLGizmoMeasure::on_render()
|
||||
}
|
||||
}
|
||||
}
|
||||
#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
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "GLGizmoBase.hpp"
|
||||
#include "slic3r/GUI/GLModel.hpp"
|
||||
#include "slic3r/GUI/GUI_Utils.hpp"
|
||||
#include "libslic3r/Measure.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
@ -18,12 +19,19 @@ namespace Measure { class Measuring; }
|
||||
|
||||
namespace GUI {
|
||||
|
||||
enum class SLAGizmoEventType : unsigned char;
|
||||
|
||||
class GLGizmoMeasure : public GLGizmoBase
|
||||
{
|
||||
// This gizmo does not use grabbers. The m_hover_id relates to polygon managed by the class itself.
|
||||
|
||||
private:
|
||||
enum class EMode : unsigned char
|
||||
{
|
||||
BasicSelection,
|
||||
ExtendedSelection
|
||||
};
|
||||
|
||||
EMode m_mode{ EMode::BasicSelection };
|
||||
std::unique_ptr<Measure::Measuring> m_measuring;
|
||||
|
||||
PickingModel m_sphere;
|
||||
@ -49,10 +57,8 @@ private:
|
||||
|
||||
int m_mouse_pos_x;
|
||||
int m_mouse_pos_y;
|
||||
#if ENABLE_MEASURE_GIZMO_DEBUG
|
||||
bool m_show_all = false;
|
||||
bool m_show_planes = false;
|
||||
#endif // ENABLE_MEASURE_GIZMO_DEBUG
|
||||
|
||||
KeyAutoRepeatFilter m_ctrl_kar_filter;
|
||||
|
||||
void update_if_needed();
|
||||
|
||||
@ -68,6 +74,8 @@ public:
|
||||
|
||||
void data_changed() override;
|
||||
|
||||
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
|
||||
|
||||
protected:
|
||||
bool on_init() override;
|
||||
std::string on_get_name() const override;
|
||||
@ -77,6 +85,7 @@ protected:
|
||||
void on_set_state() override;
|
||||
CommonGizmosDataID on_get_requirements() const override;
|
||||
|
||||
virtual void on_render_input_window(float x, float y, float bottom_limit) override;
|
||||
virtual void on_register_raycasters_for_picking() override;
|
||||
virtual void on_unregister_raycasters_for_picking() override;
|
||||
};
|
||||
|
@ -24,6 +24,10 @@ enum class SLAGizmoEventType : unsigned char {
|
||||
Dragging,
|
||||
Delete,
|
||||
SelectAll,
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
CtrlDown,
|
||||
CtrlUp,
|
||||
#endif // ENABLE_MEASURE_GIZMO
|
||||
ShiftUp,
|
||||
AltUp,
|
||||
ApplyChanges,
|
||||
|
@ -294,6 +294,10 @@ bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_p
|
||||
return dynamic_cast<GLGizmoSeam*>(m_gizmos[Seam].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
|
||||
else if (m_current == MmuSegmentation)
|
||||
return dynamic_cast<GLGizmoMmuSegmentation*>(m_gizmos[MmuSegmentation].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
else if (m_current == Measure)
|
||||
return dynamic_cast<GLGizmoMeasure*>(m_gizmos[Measure].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
|
||||
#endif // ENABLE_MEASURE_GIZMO
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@ -499,8 +503,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt)
|
||||
|
||||
bool processed = false;
|
||||
|
||||
if ((evt.GetModifiers() & ctrlMask) != 0)
|
||||
{
|
||||
if ((evt.GetModifiers() & ctrlMask) != 0) {
|
||||
switch (keyCode)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
@ -518,15 +521,13 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!evt.HasModifiers())
|
||||
{
|
||||
else if (!evt.HasModifiers()) {
|
||||
switch (keyCode)
|
||||
{
|
||||
// key ESC
|
||||
case WXK_ESCAPE:
|
||||
{
|
||||
if (m_current != Undefined)
|
||||
{
|
||||
if (m_current != Undefined) {
|
||||
if ((m_current != SlaSupports) || !gizmo_event(SLAGizmoEventType::DiscardChanges))
|
||||
reset_all_states();
|
||||
|
||||
@ -563,8 +564,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt)
|
||||
case 'A':
|
||||
case 'a':
|
||||
{
|
||||
if (m_current == SlaSupports)
|
||||
{
|
||||
if (m_current == SlaSupports) {
|
||||
gizmo_event(SLAGizmoEventType::AutomaticGeneration);
|
||||
// set as processed no matter what's returned by gizmo_event() to avoid the calling canvas to process 'A' as arrange
|
||||
processed = true;
|
||||
@ -582,8 +582,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt)
|
||||
case 'F':
|
||||
case 'f':
|
||||
{
|
||||
if (m_current == Scale)
|
||||
{
|
||||
if (m_current == Scale) {
|
||||
if (!is_dragging())
|
||||
wxGetApp().plater()->scale_selection_to_fit_print_volume();
|
||||
|
||||
@ -595,8 +594,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt)
|
||||
}
|
||||
}
|
||||
|
||||
if (!processed && !evt.HasModifiers())
|
||||
{
|
||||
if (!processed && !evt.HasModifiers()) {
|
||||
if (handle_shortcut(keyCode))
|
||||
processed = true;
|
||||
}
|
||||
@ -612,10 +610,8 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt)
|
||||
const int keyCode = evt.GetKeyCode();
|
||||
bool processed = false;
|
||||
|
||||
if (evt.GetEventType() == wxEVT_KEY_UP)
|
||||
{
|
||||
if (m_current == SlaSupports || m_current == Hollow)
|
||||
{
|
||||
if (evt.GetEventType() == wxEVT_KEY_UP) {
|
||||
if (m_current == SlaSupports || m_current == Hollow) {
|
||||
bool is_editing = true;
|
||||
bool is_rectangle_dragging = false;
|
||||
|
||||
@ -629,33 +625,33 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt)
|
||||
is_rectangle_dragging = gizmo->is_selection_rectangle_dragging();
|
||||
}
|
||||
|
||||
if (keyCode == WXK_SHIFT)
|
||||
{
|
||||
if (keyCode == WXK_SHIFT) {
|
||||
// shift has been just released - SLA gizmo might want to close rectangular selection.
|
||||
if (gizmo_event(SLAGizmoEventType::ShiftUp) || (is_editing && is_rectangle_dragging))
|
||||
processed = true;
|
||||
}
|
||||
else if (keyCode == WXK_ALT)
|
||||
{
|
||||
else if (keyCode == WXK_ALT) {
|
||||
// alt has been just released - SLA gizmo might want to close rectangular selection.
|
||||
if (gizmo_event(SLAGizmoEventType::AltUp) || (is_editing && is_rectangle_dragging))
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
else if (m_current == Measure && keyCode == WXK_CONTROL) {
|
||||
gizmo_event(SLAGizmoEventType::CtrlUp, Vec2d::Zero(), false);
|
||||
}
|
||||
#endif // ENABLE_MEASURE_GIZMO
|
||||
|
||||
// if (processed)
|
||||
// m_parent.set_cursor(GLCanvas3D::Standard);
|
||||
}
|
||||
else if (evt.GetEventType() == wxEVT_KEY_DOWN)
|
||||
{
|
||||
if ((m_current == SlaSupports) && ((keyCode == WXK_SHIFT) || (keyCode == WXK_ALT))
|
||||
&& dynamic_cast<GLGizmoSlaSupports*>(get_current())->is_in_editing_mode())
|
||||
{
|
||||
else if (evt.GetEventType() == wxEVT_KEY_DOWN) {
|
||||
if (m_current == SlaSupports && (keyCode == WXK_SHIFT || keyCode == WXK_ALT)
|
||||
&& dynamic_cast<GLGizmoSlaSupports*>(get_current())->is_in_editing_mode()) {
|
||||
// m_parent.set_cursor(GLCanvas3D::Cross);
|
||||
processed = true;
|
||||
}
|
||||
else if (m_current == Cut)
|
||||
{
|
||||
else if (m_current == Cut) {
|
||||
auto do_move = [this, &processed](double delta_z) {
|
||||
GLGizmoCut* cut = dynamic_cast<GLGizmoCut*>(get_current());
|
||||
cut->set_cut_z(delta_z + cut->get_cut_z());
|
||||
@ -668,11 +664,17 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt)
|
||||
case WXK_NUMPAD_DOWN: case WXK_DOWN: { do_move(-1.0); break; }
|
||||
default: { break; }
|
||||
}
|
||||
} else if (m_current == Simplify && keyCode == WXK_ESCAPE) {
|
||||
}
|
||||
else if (m_current == Simplify && keyCode == WXK_ESCAPE) {
|
||||
GLGizmoSimplify *simplify = dynamic_cast<GLGizmoSimplify *>(get_current());
|
||||
if (simplify != nullptr)
|
||||
processed = simplify->on_esc_key_down();
|
||||
}
|
||||
#if ENABLE_MEASURE_GIZMO
|
||||
else if (m_current == Measure && keyCode == WXK_CONTROL) {
|
||||
gizmo_event(SLAGizmoEventType::CtrlDown, Vec2d::Zero(), true);
|
||||
}
|
||||
#endif // ENABLE_MEASURE_GIZMO
|
||||
}
|
||||
|
||||
if (processed)
|
||||
|
Loading…
Reference in New Issue
Block a user