fix thumbnails gui

* drawing when no state button
 * now has state (unsaved, reset...)
 * unsaved dialog
This commit is contained in:
remi durand 2021-05-28 01:56:31 +02:00
parent bf520b8bdb
commit 3ed01dad9c
9 changed files with 40 additions and 30 deletions

View File

@ -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.

View File

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

View File

@ -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<Vec2d>& values)
wxString get_points_string(const std::vector<Vec2d>& 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<std::vector<Vec2d>>(m_value));
text_value = get_points_string(boost::any_cast<std::vector<Vec2d>>(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<std::vector<Vec2d>>(m_value));
text_value = get_points_string(boost::any_cast<std::vector<Vec2d>>(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<ConfigOptionPoints>()->values);
text_value = get_points_string(m_opt.get_default_value<ConfigOptionPoints>()->values);
break;
default:
break;

View File

@ -37,7 +37,7 @@ using t_change = std::function<void(const t_config_option_key&, const boost::any
using t_back_to_init = std::function<void(const std::string&)>;
wxString double_to_string(double const value, const int max_precision = 8);
wxString get_thumbnails_string(const std::vector<Vec2d>& values);
wxString get_points_string(const std::vector<Vec2d>& values);
class Field {
protected:

View File

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

View File

@ -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<ConfigOptionInts >(opt_key, config, cnt); break;

View File

@ -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<OG_CustomCtrl*, bool*> 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;
}
}

View File

@ -335,7 +335,7 @@ public:
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
std::pair<OG_CustomCtrl*, bool*> 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();

View File

@ -997,8 +997,6 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig&
BedShape shape(*config.option<ConfigOptionPoints>(opt_key));
return shape.get_full_name_with_params();
}
if (opt_key == "thumbnails")
return get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values);
Vec2d val = config.opt<ConfigOptionPoints>(opt_key)->get_at(opt_idx);
return from_u8((boost::format("[%1%]") % ConfigOptionPoint(val).serialize()).str());