From 3ed01dad9cce4035cbd71c3d03363955867a12e4 Mon Sep 17 00:00:00 2001 From: remi durand Date: Fri, 28 May 2021 01:56:31 +0200 Subject: [PATCH] fix thumbnails gui * drawing when no state button * now has state (unsaved, reset...) * unsaved dialog --- src/libslic3r/Preset.cpp | 3 ++- src/libslic3r/PrintConfig.cpp | 2 ++ src/slic3r/GUI/Field.cpp | 28 ++++++++++++------------- src/slic3r/GUI/Field.hpp | 2 +- src/slic3r/GUI/OG_CustomCtrl.cpp | 21 +++++++++++++------ src/slic3r/GUI/Search.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 8 +++---- src/slic3r/GUI/Tab.hpp | 2 +- src/slic3r/GUI/UnsavedChangesDialog.cpp | 2 -- 9 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 738af3c95..c31835869 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1398,9 +1398,10 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi if (this_opt != nullptr && other_opt != nullptr && !(this_opt->is_phony() && other_opt->is_phony()) && ((*this_opt != *other_opt) || (this_opt->is_phony() != other_opt->is_phony()))) { - if (opt_key == "bed_shape" || opt_key == "thumbnails" || opt_key == "compatible_prints" || opt_key == "compatible_printers") { + if (opt_key == "bed_shape" || opt_key == "compatible_prints" || opt_key == "compatible_printers") { // Scalar variable, or a vector variable, which is independent from number of extruders, // thus the vector is presented to the user as a single input. + // note that thumbnails are not here becasue it has individual # entries diff.emplace_back(opt_key); } else if (opt_key == "default_filament_profile") { // Ignore this field, it is not presented to the user, therefore showing a "modified" flag for this parameter does not help. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 27e60143f..d76234d95 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -76,6 +76,8 @@ void PrintConfigDef::init_common_params() def->label = L("Thumbnails size"); def->tooltip = L("Picture sizes to be stored into a .gcode and .sl1 files, in the following format: \"XxY, XxY, ...\""); def->mode = comExpert; + def->min = 0; + def->max = 2048; //def->gui_type = "one_string"; //supermerill: test/see what this does. def->set_default_value(new ConfigOptionPoints{ Vec2d(0,0), Vec2d(0,0) }); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 5a5f356e0..be0a4f575 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -56,7 +56,7 @@ wxString double_to_string(double const value, const int max_precision /*= 8*/) return s; } -wxString get_thumbnails_string(const std::vector& values) +wxString get_points_string(const std::vector& values) { wxString ret_str; for (size_t i = 0; i < values.size(); ++ i) { @@ -361,17 +361,17 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true if (!str.IsEmpty()) { bool invalid_val = false; bool out_of_range_val = false; - wxStringTokenizer thumbnails(str, ","); - while (thumbnails.HasMoreTokens()) { - wxString token = thumbnails.GetNextToken(); + wxStringTokenizer points(str, ","); + while (points.HasMoreTokens()) { + wxString token = points.GetNextToken(); double x, y; - wxStringTokenizer thumbnail(token, "x"); - if (thumbnail.HasMoreTokens()) { - wxString x_str = thumbnail.GetNextToken(); - if (x_str.ToDouble(&x) && thumbnail.HasMoreTokens()) { - wxString y_str = thumbnail.GetNextToken(); - if (y_str.ToDouble(&y) && !thumbnail.HasMoreTokens()) { - if (0 < x && x < 1000 && 0 < y && y < 1000) { + wxStringTokenizer point(token, "x"); + if (point.HasMoreTokens()) { + wxString x_str = point.GetNextToken(); + if (x_str.ToDouble(&x) && point.HasMoreTokens()) { + wxString y_str = point.GetNextToken(); + if (y_str.ToDouble(&y) && !point.HasMoreTokens()) { + if (m_opt.min <= x && x <= m_opt.max && m_opt.min <= y && y <= m_opt.max) { out_values.push_back(Vec2d(x, y)); continue; } @@ -387,7 +387,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true if (out_of_range_val) { wxString text_value; if (!m_value.empty()) - text_value = get_thumbnails_string(boost::any_cast>(m_value)); + text_value = get_points_string(boost::any_cast>(m_value)); set_value(text_value, true); show_error(m_parent, _L("Input value is out of range") ); @@ -395,7 +395,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true else if (invalid_val) { wxString text_value; if (!m_value.empty()) - text_value = get_thumbnails_string(boost::any_cast>(m_value)); + text_value = get_points_string(boost::any_cast>(m_value)); set_value(text_value, true); show_error(m_parent, format_wxstr(_L("Invalid input format. Expected vector of dimensions in the following format: \"%1%\""),"XxY, XxY, ..." )); } @@ -472,7 +472,7 @@ void TextCtrl::BUILD() { break; } case coPoints: - text_value = get_thumbnails_string(m_opt.get_default_value()->values); + text_value = get_points_string(m_opt.get_default_value()->values); break; default: break; diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index af54e8f38..42aaa5372 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -37,7 +37,7 @@ using t_change = std::function; wxString double_to_string(double const value, const int max_precision = 8); -wxString get_thumbnails_string(const std::vector& values); +wxString get_points_string(const std::vector& values); class Field { protected: diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index 134e27b79..ccc9413ef 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -236,7 +236,8 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/) break; if (opt.opt.gui_type == "legend") - h_pos += 2 * blinking_button_width; if (field->getSizer()) { + h_pos += 2 * blinking_button_width; + if (field->getSizer()) { for (auto child : field->getSizer()->GetChildren()) { if (child->IsWindow() && child->IsShown()) { wxSize sz = child->GetWindow()->GetSize(); @@ -537,10 +538,11 @@ void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode) void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) { Field* field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id); + int blinking_button_width = ctrl->m_bmp_blinking_sz.GetWidth() + ctrl->m_h_gap; bool suppress_hyperlinks = get_app_config()->get("suppress_hyperlinks") == "1"; if (draw_just_act_buttons) { - if (field) + if (field && field->undo_to_sys_bitmap()) draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink()); return; } @@ -578,8 +580,12 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) option_set.front().opt.label.empty() && option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0) { - if (field && field->undo_to_sys_bitmap()) - h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink()) + ctrl->m_h_gap; + if (field) { + if (field->undo_to_sys_bitmap()) + h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink()) + ctrl->m_h_gap; + else + h_pos += 2 * blinking_button_width; + } // update width for full_width fields if (option_set.front().opt.full_width && field->getWindow()) field->getWindow()->SetSize(ctrl->GetSize().x - h_pos, -1); @@ -625,8 +631,11 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) //round it to next m_em_unit h_pos += (h_pos % ctrl->m_em_unit == 0 ) ? 0 : ctrl->m_em_unit - (h_pos % ctrl->m_em_unit); - if (field && field->undo_to_sys_bitmap()) { - h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink(), bmp_rect_id++); + if (field) { + if(field->undo_to_sys_bitmap()) + h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink(), bmp_rect_id++); + else + h_pos += 2 * blinking_button_width; if (field->getSizer()) { auto children = field->getSizer()->GetChildren(); diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index d61fc05e0..1542067b3 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -94,7 +94,7 @@ void OptionsSearcher::append_options(DynamicPrintConfig* config, Preset::Type ty int cnt = 0; - if ( (type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER) && opt_key != "bed_shape" && opt_key != "thumbnails") + if ( (type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER) && opt_key != "bed_shape") switch (config->option(opt_key)->type()) { case coInts: change_opt_key(opt_key, config, cnt); break; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index ea374a580..ba528684a 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -572,7 +572,7 @@ void Tab::decorate() if (!colored_label_clr) { field = get_field(opt.first); if (!field) - continue; + continue; } bool is_nonsys_value = false; @@ -711,7 +711,7 @@ void TabPrinter::init_options_list() for (const auto opt_key : m_config->keys()) { - if (opt_key == "bed_shape" || opt_key == "thumbnails") { + if (opt_key == "bed_shape") { m_options_list.emplace(opt_key, m_opt_status_value); continue; } @@ -1084,13 +1084,13 @@ std::pair Tab::get_custom_ctrl_with_blinking_ptr(const t_ return ret; } -Field* Tab::get_field(const t_config_option_key& opt_key, Page** selected_page, int opt_index/* = -1*/) +Field* Tab::get_field(Page*& selected_page, const t_config_option_key& opt_key, int opt_index/* = -1*/) { Field* field = nullptr; for (auto page : m_pages) { field = page->get_field(opt_key, opt_index); if (field != nullptr) { - *selected_page = page.get(); + selected_page = page.get(); return field; } } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index bb10b10db..29d4699c3 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -335,7 +335,7 @@ public: Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; std::pair get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index = -1); - Field* get_field(const t_config_option_key &opt_key, Page** selected_page, int opt_index = -1); + Field* get_field(Page*& selected_page, const t_config_option_key &opt_key, int opt_index = -1); void toggle_option(const std::string& opt_key, bool toggle, int opt_index = -1); wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText, wxString text = wxEmptyString); bool current_preset_is_dirty(); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 5d4322ffb..4636f6a4b 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -997,8 +997,6 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig& BedShape shape(*config.option(opt_key)); return shape.get_full_name_with_params(); } - if (opt_key == "thumbnails") - return get_thumbnails_string(config.option(opt_key)->values); Vec2d val = config.opt(opt_key)->get_at(opt_idx); return from_u8((boost::format("[%1%]") % ConfigOptionPoint(val).serialize()).str());