From 3b4e2a0afdb8288c60028b18aafa9183b8b1cca6 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Mon, 22 Jan 2024 17:14:59 +0800 Subject: [PATCH] ENH:enhance the entry of coloring tools Jira: STUDIO-6026 Change-Id: I3b9b5781379902026b669f1d763d4dcad9342d76 --- resources/images/add_filament_dark.svg | 4 + resources/images/delete_filament_dark.svg | 3 + src/imgui/imconfig.h | 10 ++- .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 48 ++++++++++-- src/slic3r/GUI/ImGuiWrapper.cpp | 5 ++ src/slic3r/GUI/Plater.cpp | 78 ++++++++++++------- src/slic3r/GUI/Plater.hpp | 5 +- 7 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 resources/images/add_filament_dark.svg create mode 100644 resources/images/delete_filament_dark.svg diff --git a/resources/images/add_filament_dark.svg b/resources/images/add_filament_dark.svg new file mode 100644 index 000000000..78ca85594 --- /dev/null +++ b/resources/images/add_filament_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/delete_filament_dark.svg b/resources/images/delete_filament_dark.svg new file mode 100644 index 000000000..8f5ca037d --- /dev/null +++ b/resources/images/delete_filament_dark.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/imgui/imconfig.h b/src/imgui/imconfig.h index ac0226042..abfdd77cf 100644 --- a/src/imgui/imconfig.h +++ b/src/imgui/imconfig.h @@ -199,8 +199,8 @@ namespace ImGui const wchar_t CloseBlockNotifHoverButton = 0x0834; const wchar_t BlockNotifErrorIcon = 0x0835; - const wchar_t PrevArrowBtnIcon = 0x0836; - const wchar_t PrevArrowHoverBtnIcon = 0x0837; + const wchar_t PrevArrowBtnIcon = 0x0836; + const wchar_t PrevArrowHoverBtnIcon = 0x0837; const wchar_t NextArrowBtnIcon = 0x0838; const wchar_t NextArrowHoverBtnIcon = 0x0839; const wchar_t OpenArrowIcon = 0x0840; @@ -208,6 +208,10 @@ namespace ImGui const wchar_t ExpandArrowIcon = 0x0842; const wchar_t CompleteIcon = 0x0843; -// void MyFunction(const char* name, const MyMatrix44& v); + const wchar_t AddFilamentIcon = 0x0844; + const wchar_t AddFilamentDarkIcon = 0x0845; + const wchar_t DeleteFilamentIcon = 0x0845; + const wchar_t DeleteFilamentDarkIcon = 0x0846; + // void MyFunction(const char* name, const MyMatrix44& v); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 50cb1a5c1..841b8b04f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -49,13 +49,13 @@ std::string GLGizmoMmuSegmentation::on_get_name() const bool GLGizmoMmuSegmentation::on_is_selectable() const { return (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptFFF - && /*wxGetApp().get_mode() != comSimple && */wxGetApp().filaments_cnt() > 1); + /*wxGetApp().get_mode() != comSimple && */); } bool GLGizmoMmuSegmentation::on_is_activable() const { const Selection& selection = m_parent.get_selection(); - return !selection.is_empty() && (selection.is_single_full_instance() || selection.is_any_volume()) && wxGetApp().filaments_cnt() > 1; + return !selection.is_empty() && (selection.is_single_full_instance() || selection.is_any_volume()); } //BBS: use the global one in 3DScene.cpp @@ -90,7 +90,10 @@ static std::vector get_extruder_id_for_volumes(const ModelObject &model_obj void GLGizmoMmuSegmentation::init_extruders_data() { m_extruders_colors = get_extruders_colors(); - m_selected_extruder_idx = 0; + size_t n_extruder_colors = std::min((size_t) EnforcerBlockerType::ExtruderMax, m_extruders_colors.size()); + if (n_extruder_colors == 2 || m_selected_extruder_idx >= n_extruder_colors) { + m_selected_extruder_idx = n_extruder_colors - 1; + } } bool GLGizmoMmuSegmentation::on_init() @@ -167,7 +170,7 @@ void GLGizmoMmuSegmentation::set_painter_gizmo_data(const Selection &selection) { GLGizmoPainterBase::set_painter_gizmo_data(selection); - if (m_state != On || wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptFFF || wxGetApp().filaments_cnt() <= 1) + if (m_state != On || wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptFFF) return; ModelObject* model_object = m_c->selection_info()->model_object(); @@ -448,7 +451,33 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott float textbox_width = 1.5 * slider_icon_width; SliderInputLayout slider_input_layout = {clipping_slider_left, sliders_width, drag_left_width + circle_max_width, textbox_width}; - m_imgui->text(m_desc.at("filaments")); + { + m_imgui->text(m_desc.at("filaments")); + float text_offset = m_imgui->calc_text_size(m_desc.at("filaments")).x + m_imgui->scaled(1.5f); + ImGui::SameLine(text_offset); + float but1_offset = m_imgui->calc_button_size("+++").x; + ImGui::PushItemWidth(but1_offset); + std::wstring add_btn_name = (m_is_dark_mode ? ImGui::AddFilamentDarkIcon : ImGui::AddFilamentIcon) + boost::nowide::widen(""); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0); + ImGui::PushStyleColor(ImGuiCol_Button, m_is_dark_mode ? ImVec4(43 / 255.0f, 64 / 255.0f, 54 / 255.0f, 0.00f) : ImVec4(0.86f, 0.99f, 0.91f, 0.00f)); // r, g, b, a + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, m_is_dark_mode ? ImVec4(150 / 255.0f, 150 / 255.0f, 150 / 255.0f, 1.00f) : ImVec4(0.86f, 0.99f, 0.91f, 1.00f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, m_is_dark_mode ? ImVec4(43 / 255.0f, 64 / 255.0f, 54 / 255.0f, 1.00f) : ImVec4(0.86f, 0.99f, 0.91f, 1.00f)); + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); + + if (ImGui::Button(into_u8(add_btn_name).c_str())) { + wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_ADD_FILAMENT)); + } + ImGui::SameLine(text_offset + but1_offset); + ImGui::PushItemWidth(but1_offset); + std::wstring del_btn_name = (m_is_dark_mode ? ImGui::DeleteFilamentDarkIcon : ImGui::DeleteFilamentIcon) + boost::nowide::widen(""); + if (ImGui::Button(into_u8(del_btn_name).c_str())) { + wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_DEL_FILAMENT)); + } + + ImGui::PopStyleColor(4); + ImGui::PopStyleVar(1); + } float start_pos_x = ImGui::GetCursorPos().x; const ImVec2 max_label_size = ImGui::CalcTextSize("99", NULL, true); @@ -921,8 +950,13 @@ std::array GLGizmoMmuSegmentation::get_cursor_hover_color() const void GLGizmoMmuSegmentation::on_set_state() { GLGizmoPainterBase::on_set_state(); - - if (get_state() == Off) { + if (get_state() == On) { + size_t n_extruder_colors = std::min((size_t) EnforcerBlockerType::ExtruderMax, m_extruders_colors.size()); + if (n_extruder_colors>=2) { + m_selected_extruder_idx = 1; + } + } + else if (get_state() == Off) { ModelObject* mo = m_c->selection_info()->model_object(); if (mo) Slic3r::save_object_mesh(*mo); m_parent.post_event(SimpleEvent(EVT_GLCANVAS_FORCE_UPDATE)); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index aafc93f1b..f05c335b2 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -76,6 +76,11 @@ static const std::map font_icons = { //{ImGui::PreferencesDarkButton , "notification_preferences_dark" }, //{ImGui::PreferencesHoverDarkButton , "notification_preferences_hover_dark"}, + {ImGui::AddFilamentIcon , "add_filament"}, + {ImGui::AddFilamentDarkIcon , "add_filament_dark"}, + {ImGui::DeleteFilamentIcon , "delete_filament"}, + {ImGui::DeleteFilamentDarkIcon , "delete_filament_dark"}, + {ImGui::CircleButtonDarkIcon , "circle_paint_dark" }, {ImGui::TriangleButtonDarkIcon , "triangle_paint_dark" }, {ImGui::FillButtonDarkIcon , "fill_paint_dark" }, diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index face4e59c..ec6d27cc6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -179,7 +179,8 @@ wxDEFINE_EVENT(EVT_PRINT_FROM_SDCARD_VIEW, SimpleEvent); wxDEFINE_EVENT(EVT_CREATE_FILAMENT, SimpleEvent); wxDEFINE_EVENT(EVT_MODIFY_FILAMENT, SimpleEvent); - +wxDEFINE_EVENT(EVT_ADD_FILAMENT, SimpleEvent); +wxDEFINE_EVENT(EVT_DEL_FILAMENT, SimpleEvent); bool Plater::has_illegal_filename_characters(const wxString& wxs_name) { std::string name = into_u8(wxs_name); @@ -810,18 +811,7 @@ Sidebar::Sidebar(Plater *parent) ScalableButton* add_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "add_filament"); add_btn->SetToolTip(_L("Add one filament")); add_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e){ - // BBS: limit filament choices to 16 - if (p->combos_filament.size() >= 16) - return; - - int filament_count = p->combos_filament.size() + 1; - wxColour new_col = Plater::get_next_color_for_filament(); - std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); - wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color); - wxGetApp().plater()->on_filaments_change(filament_count); - wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); - wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); - auto_calc_flushing_volumes(filament_count - 1); + add_filament(); }); p->m_bpButton_add_filament = add_btn; @@ -831,22 +821,7 @@ Sidebar::Sidebar(Plater *parent) ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "delete_filament"); del_btn->SetToolTip(_L("Remove last filament")); del_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent &e) { - if (p->combos_filament.size() <= 1) - return; - - size_t filament_count = p->combos_filament.size() - 1; - if (wxGetApp().preset_bundle->is_the_only_edited_filament(filament_count) || (filament_count == 1)) { - wxGetApp().get_tab(Preset::TYPE_FILAMENT)->select_preset(wxGetApp().preset_bundle->filament_presets[0], false, "", true); - } - - if (p->editing_filament >= filament_count) { - p->editing_filament = -1; - } - - wxGetApp().preset_bundle->set_num_filaments(filament_count); - wxGetApp().plater()->on_filaments_change(filament_count); - wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); - wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); + delete_filament(); }); p->m_bpButton_del_filament = del_btn; @@ -1568,6 +1543,38 @@ void Sidebar::on_filaments_change(size_t num_filaments) dynamic_filament_list.update(); } +void Sidebar::add_filament() { + // BBS: limit filament choices to 16 + if (p->combos_filament.size() >= 16) return; + + int filament_count = p->combos_filament.size() + 1; + wxColour new_col = Plater::get_next_color_for_filament(); + std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); + wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color); + wxGetApp().plater()->on_filaments_change(filament_count); + wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); + wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); + auto_calc_flushing_volumes(filament_count - 1); +} + +void Sidebar::delete_filament() { + if (p->combos_filament.size() <= 1) return; + + size_t filament_count = p->combos_filament.size() - 1; + if (wxGetApp().preset_bundle->is_the_only_edited_filament(filament_count) || (filament_count == 1)) { + wxGetApp().get_tab(Preset::TYPE_FILAMENT)->select_preset(wxGetApp().preset_bundle->filament_presets[0], false, "", true); + } + + if (p->editing_filament >= filament_count) { + p->editing_filament = -1; + } + + wxGetApp().preset_bundle->set_num_filaments(filament_count); + wxGetApp().plater()->on_filaments_change(filament_count); + wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); + wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); +} + void Sidebar::on_bed_type_change(BedType bed_type) { // btDefault option is not included in global bed type setting @@ -2479,6 +2486,8 @@ struct Plater::priv void on_action_layersediting(SimpleEvent&); void on_create_filament(SimpleEvent &); void on_modify_filament(SimpleEvent &); + void on_add_filament(SimpleEvent &); + void on_delete_filament(SimpleEvent &); void on_object_select(SimpleEvent&); void on_plate_name_change(SimpleEvent &); @@ -2710,7 +2719,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) this->q->Bind(wxEVT_SYS_COLOUR_CHANGED, &priv::on_apple_change_color_mode, this); this->q->Bind(EVT_CREATE_FILAMENT, &priv::on_create_filament, this); this->q->Bind(EVT_MODIFY_FILAMENT, &priv::on_modify_filament, this); - + this->q->Bind(EVT_ADD_FILAMENT, &priv::on_add_filament, this); + this->q->Bind(EVT_DEL_FILAMENT, &priv::on_delete_filament, this); view3D = new View3D(q, bed, &model, config, &background_process); //BBS: use partplater's gcode preview = new Preview(q, bed, &model, config, &background_process, partplate_list.get_current_slice_result(), [this]() { schedule_background_process(); }); @@ -7860,6 +7870,14 @@ void Plater::priv::on_modify_filament(SimpleEvent &evt) } +void Plater::priv::on_add_filament(SimpleEvent &evt) { + sidebar->add_filament(); +} + +void Plater::priv::on_delete_filament(SimpleEvent &evt) { + sidebar->delete_filament(); +} + void Plater::priv::enter_gizmos_stack() { assert(m_undo_redo_stack_active == &m_undo_redo_stack_main); diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index d9b3ff6e6..82fb1f5cd 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -98,7 +98,8 @@ wxDECLARE_EVENT(EVT_GLCANVAS_COLOR_MODE_CHANGED, SimpleEvent); wxDECLARE_EVENT(EVT_PRINT_FROM_SDCARD_VIEW, SimpleEvent); wxDECLARE_EVENT(EVT_CREATE_FILAMENT, SimpleEvent); wxDECLARE_EVENT(EVT_MODIFY_FILAMENT, SimpleEvent); - +wxDECLARE_EVENT(EVT_ADD_FILAMENT, SimpleEvent); +wxDECLARE_EVENT(EVT_DEL_FILAMENT, SimpleEvent); const wxString DEFAULT_PROJECT_NAME = "Untitled"; class Sidebar : public wxPanel @@ -132,6 +133,8 @@ public: void jump_to_option(const std::string& opt_key, Preset::Type type, const std::wstring& category); // BBS. Add on_filaments_change() method. void on_filaments_change(size_t num_filaments); + void add_filament(); + void delete_filament(); // BBS void on_bed_type_change(BedType bed_type); void load_ams_list(std::string const & device, MachineObject* obj);