ENH:enhance the entry of coloring tools

Jira: STUDIO-6026
Change-Id: I3b9b5781379902026b669f1d763d4dcad9342d76
This commit is contained in:
zhou.xu 2024-01-22 17:14:59 +08:00 committed by Lane.Wei
parent 5ed07b0588
commit 3b4e2a0afd
7 changed files with 112 additions and 41 deletions

View File

@ -0,0 +1,4 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7H12" stroke="white" stroke-linecap="round"/>
<path d="M7 2V12" stroke="white" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 219 B

View File

@ -0,0 +1,3 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7H12" stroke="white" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 161 B

View File

@ -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);
}

View File

@ -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<int> 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<float, 4> 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));

View File

@ -76,6 +76,11 @@ static const std::map<const wchar_t, std::string> 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" },

View File

@ -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);

View File

@ -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);