Skip to content

Commit

Permalink
ENH: refine gizmo paint tools
Browse files Browse the repository at this point in the history
1. support to adjust cursor size and section view by key + mouse wheel
2. display shortcut tips according to the selected tool type
3. change the left mouse behavior to object movement for color painting tool

Signed-off-by: yifan.wu <[email protected]>
Change-Id: I13d2a83d562d6ccd8d915158e263a90ad3c02db0
  • Loading branch information
YifanWuBambu authored and lanewei120 committed Oct 20, 2022
1 parent d38c5b0 commit f3c65f8
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void GLGizmoAdvancedCut::on_render_input_window(float x, float y, float bottom_l

// Rotation input box
ImGui::PushItemWidth(caption_size);
m_imgui->text(_L("Rotation:"));
m_imgui->text(_L("Rotation") + " ");
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::BBLInputDouble("##cut_rotation_x", &rotation[0], 0.0f, 0.0f, "%.2f");
Expand Down Expand Up @@ -471,7 +471,7 @@ void GLGizmoAdvancedCut::on_render_input_window(float x, float y, float bottom_l
double movement = m_movement;
ImGui::PushItemWidth(caption_size);
ImGui::AlignTextToFramePadding();
m_imgui->text(_L("Movement:"));
m_imgui->text(_L("Movement") + " ");
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(3 * unit_size + 2 * space_size);
ImGui::BBLInputDouble("##cut_movement", &movement, 0.0f, 0.0f, "%.2f");
Expand All @@ -497,7 +497,7 @@ void GLGizmoAdvancedCut::on_render_input_window(float x, float y, float bottom_l
double height = m_height;
ImGui::PushItemWidth(caption_size);
ImGui::AlignTextToFramePadding();
m_imgui->text(_L("Height:"));
m_imgui->text(_L("Height") + " ");
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(3 * unit_size + 2 * space_size);
ImGui::BBLInputDouble("##cut_height", &height, 0.0f, 0.0f, "%.2f");
Expand Down
45 changes: 33 additions & 12 deletions src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,25 @@ bool GLGizmoFdmSupports::on_init()
// BBS
m_shortcut_key = WXK_CONTROL_L;

m_desc["clipping_of_view"] = _L("Section view") + ": ";
m_desc["cursor_size"] = _L("Pen size") + ": ";
m_desc["enforce_caption"] = _L("Left mouse button") + ": ";
m_desc["clipping_of_view_caption"] = _L("Alt + Mouse wheel");
m_desc["clipping_of_view"] = _L("Section view");
m_desc["cursor_size_caption"] = _L("Ctrl + Mouse wheel");
m_desc["cursor_size"] = _L("Pen size");
m_desc["enforce_caption"] = _L("Left mouse button");
m_desc["enforce"] = _L("Enforce supports");
m_desc["block_caption"] = _L("Right mouse button") + ": ";
m_desc["block_caption"] = _L("Right mouse button");
m_desc["block"] = _L("Block supports");
m_desc["remove_caption"] = _L("Shift + Left mouse button") + ": ";
m_desc["remove"] = _L("Erase painting");
m_desc["remove_caption"] = _L("Shift + Left mouse button");
m_desc["remove"] = _L("Erase");
m_desc["remove_all"] = _L("Erase all painting");
m_desc["highlight_by_angle"] = _L("Highlight overhang areas") + ": ";
m_desc["highlight_by_angle"] = _L("Highlight overhang areas");
m_desc["gap_fill"] = _L("Gap fill");
m_desc["perform"] = _L("Perform");
m_desc["gap_area_caption"] = _L("Ctrl + Mouse wheel");
m_desc["gap_area"] = _L("Gap area");
m_desc["brush_size"] = _L("Set pen size");
m_desc["brush_size_caption"] = _L("Ctrl + Mouse wheel") + ": ";
m_desc["tool_type"] = _L("Tool type");
m_desc["smart_fill_angle"] = _L("Smart fill angle") + ": ";
m_desc["smart_fill_angle_caption"] = _L("Ctrl + Mouse wheel");
m_desc["smart_fill_angle"] = _L("Smart fill angle");

memset(&m_print_instance, sizeof(m_print_instance), 0);
return true;
Expand Down Expand Up @@ -224,7 +226,7 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l

float caption_max = 0.f;
float total_text_max = 0.f;
for (const auto &t : std::array<std::string, 4>{"enforce", "block", "remove", "brush_size"}) {
for (const auto &t : std::array<std::string, 5>{"enforce", "block", "remove", "cursor_size", "clipping_of_view"}) {
caption_max = std::max(caption_max, m_imgui->calc_text_size(m_desc[t + "_caption"]).x);
total_text_max = std::max(total_text_max, m_imgui->calc_text_size(m_desc[t]).x);
}
Expand Down Expand Up @@ -461,6 +463,8 @@ void GLGizmoFdmSupports::show_tooltip_information(float caption_max, float x, fl
ImTextureID normal_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP);
ImTextureID hover_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER);

caption_max += m_imgui->calc_text_size(": ").x + 15.f;

float font_size = ImGui::GetFontSize();
ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
Expand All @@ -475,7 +479,24 @@ void GLGizmoFdmSupports::show_tooltip_information(float caption_max, float x, fl
m_imgui->text_colored(ImGuiWrapper::COL_WINDOW_BG, text);
};

for (const auto &t : std::array<std::string, 4>{"enforce", "block", "remove", "brush_size"}) draw_text_with_caption(m_desc.at(t + "_caption"), m_desc.at(t));
std::vector<std::string> tip_items;
switch (m_tool_type) {
case ToolType::BRUSH:
tip_items = {"enforce", "block", "remove", "cursor_size", "clipping_of_view"};
break;
case ToolType::BUCKET_FILL:
break;
case ToolType::SMART_FILL:
tip_items = {"enforce", "block", "remove", "smart_fill_angle", "clipping_of_view"};
break;
case ToolType::GAP_FILL:
tip_items = {"gap_area"};
break;
default:
break;
}
for (const auto &t : tip_items) draw_text_with_caption(m_desc.at(t + "_caption") + ": ", m_desc.at(t));

ImGui::EndTooltip();
}
ImGui::PopStyleVar(1);
Expand Down
45 changes: 32 additions & 13 deletions src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,20 @@ bool GLGizmoMmuSegmentation::on_init()
// BBS
m_shortcut_key = WXK_CONTROL_N;

m_desc["clipping_of_view"] = _L("Section view") + ": ";
m_desc["cursor_size"] = _L("Pen size") + ": ";
m_desc["clipping_of_view_caption"] = _L("Alt + Mouse wheel");
m_desc["clipping_of_view"] = _L("Section view");
m_desc["cursor_size_caption"] = _L("Ctrl + Mouse wheel");
m_desc["cursor_size"] = _L("Pen size");
m_desc["cursor_type"] = _L("Pen shape");

// BBS
m_desc["paint_caption"] = _L("Left mouse button") + ": ";
m_desc["paint_caption"] = _L("Left mouse button");
m_desc["paint"] = _L("Paint");
m_desc["erase_caption"] = _L("Right mouse button") + ": ";
m_desc["erase_caption"] = _L("Shift + Left mouse button");
m_desc["erase"] = _L("Erase");
m_desc["shortcut_key_caption"] = _L("Key 1~9") + ": ";
m_desc["shortcut_key_caption"] = _L("Key 1~9");
m_desc["shortcut_key"] = _L("Choose filament");
m_desc["edge_detection"] = _L("Edge detection");
m_desc["gap_area_caption"] = _L("Ctrl + Mouse wheel");
m_desc["gap_area"] = _L("Gap area");
m_desc["perform"] = _L("Perform");

Expand All @@ -123,12 +125,10 @@ bool GLGizmoMmuSegmentation::on_init()
m_desc["tool_smart_fill"] = _L("Smart fill");
m_desc["tool_bucket_fill"] = _L("Bucket fill");

m_desc["smart_fill_angle_caption"] = _L("Ctrl + Mouse wheel");
m_desc["smart_fill_angle"] = _L("Smart fill angle");

m_desc["brush_size"] = _L("Set pen size");
m_desc["brush_size_caption"] = _L("Ctrl + Mouse wheel") + ": ";

// BBS
m_desc["height_range_caption"] = _L("Ctrl + Mouse wheel");
m_desc["height_range"] = _L("Height range");

init_extruders_data();
Expand Down Expand Up @@ -297,6 +297,8 @@ void GLGizmoMmuSegmentation::show_tooltip_information(float caption_max, float x
ImTextureID normal_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP);
ImTextureID hover_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER);

caption_max += m_imgui->calc_text_size(": ").x + 15.f;

float font_size = ImGui::GetFontSize();
ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
Expand All @@ -310,7 +312,24 @@ void GLGizmoMmuSegmentation::show_tooltip_information(float caption_max, float x
m_imgui->text_colored(ImGuiWrapper::COL_WINDOW_BG, text);
};

for (const auto &t : std::array<std::string, 3>{"paint", "erase", "brush_size"}) draw_text_with_caption(m_desc.at(t + "_caption"), m_desc.at(t));
std::vector<std::string> tip_items;
switch (m_tool_type) {
case ToolType::BRUSH:
tip_items = {"paint", "erase", "cursor_size", "clipping_of_view"};
break;
case ToolType::BUCKET_FILL:
tip_items = {"paint", "erase", "smart_fill_angle", "clipping_of_view"};
break;
case ToolType::SMART_FILL:
// TODO:
break;
case ToolType::GAP_FILL:
tip_items = {"gap_area"};
break;
default:
break;
}
for (const auto &t : tip_items) draw_text_with_caption(m_desc.at(t + "_caption") + ": ", m_desc.at(t));
ImGui::EndTooltip();
}
ImGui::PopStyleVar(1);
Expand Down Expand Up @@ -347,7 +366,7 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott

float caption_max = 0.f;
float total_text_max = 0.f;
for (const auto &t : std::array<std::string, 3>{"paint", "erase", "brush_size"}) {
for (const auto &t : std::array<std::string, 6>{"paint", "erase", "cursor_size", "smart_fill_angle", "height_range", "clipping_of_view"}) {
caption_max = std::max(caption_max, m_imgui->calc_text_size(m_desc[t + "_caption"]).x);
total_text_max = std::max(total_text_max, m_imgui->calc_text_size(m_desc[t]).x);
}
Expand Down Expand Up @@ -537,7 +556,7 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott

if (m_detect_geometry_edge) {
ImGui::AlignTextToFramePadding();
m_imgui->text(m_desc["smart_fill_angle"] + ":");
m_imgui->text(m_desc["smart_fill_angle"]);
std::string format_str = std::string("%.f") + I18N::translate_utf8("°", "Face angle threshold,"
"placed after the number with no whitespace in between.");
ImGui::SameLine(sliders_left_width);
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class GLGizmoMmuSegmentation : public GLGizmoPainterBase
void on_set_state() override;

EnforcerBlockerType get_left_button_state_type() const override { return EnforcerBlockerType(m_selected_extruder_idx + 1); }
EnforcerBlockerType get_right_button_state_type() const override { return EnforcerBlockerType::NONE; }
EnforcerBlockerType get_right_button_state_type() const override { return EnforcerBlockerType(-1); }

void on_render_input_window(float x, float y, float bottom_limit) override;
std::string on_get_name() const override;
Expand Down
46 changes: 36 additions & 10 deletions src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,21 +495,22 @@ bool GLGizmoPainterBase::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
if (action == SLAGizmoEventType::MouseWheelUp
|| action == SLAGizmoEventType::MouseWheelDown) {
if (control_down) {
//BBS
if (m_tool_type == ToolType::BRUSH && m_cursor_type == TriangleSelector::CursorType::HEIGHT_RANGE) {
m_cursor_height = action == SLAGizmoEventType::MouseWheelDown ? std::max(m_cursor_height - this->get_cursor_height_step(), this->get_cursor_height_min()) :
std::min(m_cursor_height + this->get_cursor_height_step(), this->get_cursor_height_max());
m_parent.set_as_dirty();
return true;
}

if (m_tool_type == ToolType::BRUSH && (m_cursor_type == TriangleSelector::CursorType::SPHERE || m_cursor_type == TriangleSelector::CursorType::CIRCLE)) {
m_cursor_radius = action == SLAGizmoEventType::MouseWheelDown ? std::max(m_cursor_radius - this->get_cursor_radius_step(), this->get_cursor_radius_min()) :
std::min(m_cursor_radius + this->get_cursor_radius_step(), this->get_cursor_radius_max());
m_parent.set_as_dirty();
return true;
}
double pos = m_c->object_clipper()->get_position();
pos = action == SLAGizmoEventType::MouseWheelDown
? std::max(0., pos - 0.01)
: std::min(1., pos + 0.01);
m_c->object_clipper()->set_position(pos, true);
return true;
}
else if (alt_down) {
if (m_tool_type == ToolType::SMART_FILL) {

if (m_tool_type == ToolType::BUCKET_FILL || m_tool_type == ToolType::SMART_FILL) {
m_smart_fill_angle = action == SLAGizmoEventType::MouseWheelDown ? std::max(m_smart_fill_angle - SmartFillAngleStep, SmartFillAngleMin)
: std::min(m_smart_fill_angle + SmartFillAngleStep, SmartFillAngleMax);
m_parent.set_as_dirty();
Expand All @@ -527,7 +528,22 @@ bool GLGizmoPainterBase::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
return true;
}

return false;
if (m_tool_type == ToolType::GAP_FILL) {
TriangleSelectorPatch::gap_area = action == SLAGizmoEventType::MouseWheelDown ?
std::max(TriangleSelectorPatch::gap_area - TriangleSelectorPatch::GapAreaStep, TriangleSelectorPatch::GapAreaMin) :
std::min(TriangleSelectorPatch::gap_area + TriangleSelectorPatch::GapAreaStep, TriangleSelectorPatch::GapAreaMax);
m_parent.set_as_dirty();
return true;
}
}
else if (alt_down) {
// BBS
double pos = m_c->object_clipper()->get_position();
pos = action == SLAGizmoEventType::MouseWheelDown
? std::max(0., pos - 0.01)
: std::min(1., pos + 0.01);
m_c->object_clipper()->set_position(pos, true);
return true;
}
}

Expand All @@ -544,6 +560,16 @@ bool GLGizmoPainterBase::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
return false;

EnforcerBlockerType new_state = EnforcerBlockerType::NONE;
// BBS
if (action == SLAGizmoEventType::Dragging) {
if (m_button_down == Button::Right && this->get_right_button_state_type() == EnforcerBlockerType(-1))
return false;
}
else {
if (action == SLAGizmoEventType::RightDown && this->get_right_button_state_type() == EnforcerBlockerType(-1))
return false;
}

if (! shift_down) {
if (action == SLAGizmoEventType::Dragging)
new_state = m_button_down == Button::Left ? this->get_left_button_state_type() : this->get_right_button_state_type();
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class TriangleSelectorPatch : public TriangleSelectorGUI {

constexpr static float GapAreaMin = 0.f;
constexpr static float GapAreaMax = 5.f;
constexpr static float GapAreaStep = 0.2f;

// BBS: fix me
static float gap_area;
Expand Down
22 changes: 13 additions & 9 deletions src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ bool GLGizmoSeam::on_init()
{
m_shortcut_key = WXK_CONTROL_P;

m_desc["clipping_of_view"] = _L("Section view") + ": ";
m_desc["clipping_of_view_caption"] = _L("Alt + Mouse wheel");
m_desc["clipping_of_view"] = _L("Section view");
m_desc["reset_direction"] = _L("Reset direction");
m_desc["cursor_size"] = _L("Brush size") + ": ";
m_desc["cursor_type"] = _L("Brush shape") + ": ";
m_desc["enforce_caption"] = _L("Left mouse button") + ": ";
m_desc["cursor_size_caption"] = _L("Ctrl + Mouse wheel");
m_desc["cursor_size"] = _L("Brush size");
m_desc["cursor_type"] = _L("Brush shape");
m_desc["enforce_caption"] = _L("Left mouse button");
m_desc["enforce"] = _L("Enforce seam");
m_desc["block_caption"] = _L("Right mouse button") + ": ";
m_desc["block_caption"] = _L("Right mouse button");
m_desc["block"] = _L("Block seam");
m_desc["remove_caption"] = _L("Shift + Left mouse button") + ": ";
m_desc["remove"] = _L("Remove selection");
m_desc["remove_caption"] = _L("Shift + Left mouse button");
m_desc["remove"] = _L("Erase");
m_desc["remove_all"] = _L("Erase all painting");
m_desc["circle"] = _L("Circle");
m_desc["sphere"] = _L("Sphere");
Expand Down Expand Up @@ -125,6 +127,8 @@ void GLGizmoSeam::show_tooltip_information(float caption_max, float x, float y)
ImTextureID normal_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP);
ImTextureID hover_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER);

caption_max += m_imgui->calc_text_size(": ").x + 35.f;

float font_size = ImGui::GetFontSize();
ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
Expand All @@ -138,7 +142,7 @@ void GLGizmoSeam::show_tooltip_information(float caption_max, float x, float y)
m_imgui->text_colored(ImGuiWrapper::COL_WINDOW_BG, text);
};

for (const auto &t : std::array<std::string, 3>{"enforce", "block", "remove"}) draw_text_with_caption(m_desc.at(t + "_caption"), m_desc.at(t));
for (const auto &t : std::array<std::string, 5>{"enforce", "block", "remove", "cursor_size", "clipping_of_view"}) draw_text_with_caption(m_desc.at(t + "_caption") + ": ", m_desc.at(t));
ImGui::EndTooltip();
}
ImGui::PopStyleVar(1);
Expand Down Expand Up @@ -187,7 +191,7 @@ void GLGizmoSeam::on_render_input_window(float x, float y, float bottom_limit)

float caption_max = 0.f;
float total_text_max = 0.f;
for (const auto &t : std::array<std::string, 3>{"enforce", "block", "remove"}) {
for (const auto &t : std::array<std::string, 6>{"enforce", "block", "remove", "cursor_size", "clipping_of_view"}) {
caption_max = std::max(caption_max, m_imgui->calc_text_size(m_desc[t + "_caption"]).x);
total_text_max = std::max(total_text_max, m_imgui->calc_text_size(m_desc[t]).x);
}
Expand Down
12 changes: 10 additions & 2 deletions src/slic3r/GUI/Gizmos/GLGizmosManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,14 @@ bool GLGizmosManager::on_mouse_wheel(wxMouseEvent& evt)

if (m_current == SlaSupports || m_current == Hollow || m_current == FdmSupports || m_current == Seam || m_current == MmuSegmentation) {
float rot = (float)evt.GetWheelRotation() / (float)evt.GetWheelDelta();
if (gizmo_event((rot > 0.f ? SLAGizmoEventType::MouseWheelUp : SLAGizmoEventType::MouseWheelDown), Vec2d::Zero(), evt.ShiftDown(), evt.AltDown(), evt.ControlDown()))
if (gizmo_event((rot > 0.f ? SLAGizmoEventType::MouseWheelUp : SLAGizmoEventType::MouseWheelDown), Vec2d::Zero(), evt.ShiftDown(), evt.AltDown()
// BBS
#ifdef __WXOSX_MAC__
, evt.RawControlDown()
#else
, evt.ControlDown()
#endif
))
processed = true;
}

Expand All @@ -705,7 +712,8 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
if (evt.Moving()) {
m_tooltip = update_hover_state(mouse_pos);
if (m_current == MmuSegmentation || m_current == FdmSupports)
gizmo_event(SLAGizmoEventType::Moving, mouse_pos, evt.ShiftDown(), evt.AltDown());
// BBS
gizmo_event(SLAGizmoEventType::Moving, mouse_pos, evt.ShiftDown(), evt.AltDown(), evt.ControlDown());
} else if (evt.LeftUp()) {
if (m_mouse_capture.left) {
processed = true;
Expand Down

0 comments on commit f3c65f8

Please sign in to comment.