Implement Preparation for Edit Custom Gcode

Original Commit: prusa3d/PrusaSlicer@7db83d5

Co-authored-by: YuSanka <yusanka@gmail.com>
This commit is contained in:
Ocraftyone 2023-12-23 06:04:43 -05:00
parent 4f0a47b7f4
commit accdbb9661
No known key found for this signature in database
GPG key ID: 85836ED21AD4D125
8 changed files with 117 additions and 25 deletions

View file

@ -196,6 +196,11 @@ void Field::on_back_to_sys_value()
m_back_to_sys_value(m_opt_id);
}
void Field::on_edit_value()
{
if (m_fn_edit_value)
m_fn_edit_value(m_opt_id);
}
/// Fires the enable or disable function, based on the input.

View file

@ -183,6 +183,8 @@ public:
void on_back_to_initial_value();
/// Call the attached m_back_to_sys_value method.
void on_back_to_sys_value();
/// Call the attached m_fn_edit_value method.
void on_edit_value();
public:
/// parent wx item, opportunity to refactor (probably not necessary - data duplication)
@ -198,6 +200,9 @@ public:
t_back_to_init m_back_to_initial_value{ nullptr };
t_back_to_init m_back_to_sys_value{ nullptr };
/// Callback function to edit field value
t_back_to_init m_fn_edit_value{ nullptr };
// This is used to avoid recursive invocation of the field change/update by wxWidgets.
bool m_disable_change_event {false};
bool m_is_modified_value {false};

View file

@ -373,22 +373,31 @@ void OG_CustomCtrl::OnMotion(wxMouseEvent& event)
break;
}
for (size_t opt_idx = 0; opt_idx < line.rects_undo_icon.size(); opt_idx++)
size_t undo_icons_cnt = line.rects_undo_icon.size();
assert(line.rects_undo_icon.size() == line.rects_undo_to_sys_icon.size());
const std::vector<Option>& option_set = line.og_line.get_options();
for (size_t opt_idx = 0; opt_idx < undo_icons_cnt; opt_idx++) {
const std::string& opt_key = option_set[opt_idx].opt_id;
if (is_point_in_rect(pos, line.rects_undo_icon[opt_idx])) {
const std::vector<Option>& option_set = line.og_line.get_options();
Field* field = opt_group->get_field(option_set[opt_idx].opt_id);
if (field)
if (line.og_line.has_undo_ui())
tooltip = *line.og_line.undo_tooltip();
else if (Field* field = opt_group->get_field(opt_key))
tooltip = *field->undo_tooltip();
break;
}
for (size_t opt_idx = 0; opt_idx < line.rects_undo_to_sys_icon.size(); opt_idx++)
if (is_point_in_rect(pos, line.rects_undo_to_sys_icon[opt_idx])) {
const std::vector<Option>& option_set = line.og_line.get_options();
Field* field = opt_group->get_field(option_set[opt_idx].opt_id);
if (field)
if (line.og_line.has_undo_ui())
tooltip = *line.og_line.undo_to_sys_tooltip();
else if (Field* field = opt_group->get_field(opt_key))
tooltip = *field->undo_to_sys_tooltip();
break;
}
if (opt_idx < line.rects_edit_icon.size() && is_point_in_rect(pos, line.rects_edit_icon[opt_idx])) {
if (Field* field = opt_group->get_field(opt_key); field && field->has_edit_ui())
tooltip = *field->edit_tooltip();
break;
}
}
if (!tooltip.IsEmpty())
break;
}
@ -424,24 +433,40 @@ void OG_CustomCtrl::OnLeftDown(wxMouseEvent& event)
if (!line.is_visible) continue;
if (line.launch_browser())
return;
for (size_t opt_idx = 0; opt_idx < line.rects_undo_icon.size(); opt_idx++)
size_t undo_icons_cnt = line.rects_undo_icon.size();
assert(line.rects_undo_icon.size() == line.rects_undo_to_sys_icon.size());
const std::vector<Option>& option_set = line.og_line.get_options();
for (size_t opt_idx = 0; opt_idx < undo_icons_cnt; opt_idx++) {
const std::string& opt_key = option_set[opt_idx].opt_id;
if (is_point_in_rect(pos, line.rects_undo_icon[opt_idx])) {
const std::vector<Option>& option_set = line.og_line.get_options();
Field* field = opt_group->get_field(option_set[opt_idx].opt_id);
if (field)
if (line.og_line.has_undo_ui()) {
if (ConfigOptionsGroup* conf_OG = dynamic_cast<ConfigOptionsGroup*>(line.ctrl->opt_group))
conf_OG->back_to_initial_value(opt_key);
}
else if (Field* field = opt_group->get_field(opt_key))
field->on_back_to_initial_value();
event.Skip();
return;
}
for (size_t opt_idx = 0; opt_idx < line.rects_undo_to_sys_icon.size(); opt_idx++)
if (is_point_in_rect(pos, line.rects_undo_to_sys_icon[opt_idx])) {
const std::vector<Option>& option_set = line.og_line.get_options();
Field* field = opt_group->get_field(option_set[opt_idx].opt_id);
if (field)
if (line.og_line.has_undo_ui()) {
if (ConfigOptionsGroup* conf_OG = dynamic_cast<ConfigOptionsGroup*>(line.ctrl->opt_group))
conf_OG->back_to_sys_value(opt_key);
}
else if (Field* field = opt_group->get_field(opt_key))
field->on_back_to_sys_value();
event.Skip();
return;
}
if (opt_idx < line.rects_edit_icon.size() && is_point_in_rect(pos, line.rects_edit_icon[opt_idx])) {
if (Field* field = opt_group->get_field(opt_key))
field->on_edit_value();
event.Skip();
return;
}
}
}
SetFocusIgnoringChildren();
@ -745,10 +770,14 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord h_pos, wxCoord v_pos)
bool suppress_hyperlinks = false;
if (draw_just_act_buttons) {
//BBS: GUI refactor
if (field && field->undo_bitmap())
//if (field)
// BBS: new layout
draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->get_bitmap(), field->undo_bitmap()->get_bitmap(), field->blink());
if (field && field->undo_bitmap()) {
// if (field)
// BBS: new layout
const wxPoint pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->get_bitmap(),
field->undo_bitmap()->get_bitmap(), field->blink());
if (field->has_edit_ui())
draw_edit_bmp(dc, pos, field->edit_bitmap());
}
return;
}
@ -802,7 +831,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord h_pos, wxCoord v_pos)
auto draw_buttons = [&h_pos, &dc, &v_pos, this](Field* field, size_t bmp_rect_id = 0) {
if (field && field->undo_to_sys_bitmap()) {
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->get_bitmap(), field->undo_bitmap()->get_bitmap(), field->blink(), bmp_rect_id);
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->get_bitmap(), field->undo_bitmap()->get_bitmap(), field->blink(), bmp_rect_id).x;
}
#ifndef DISABLE_BLINKING
else if (field && !field->undo_to_sys_bitmap() && field->blink())
@ -945,7 +974,7 @@ wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, bool i
return wxPoint(h_pos, v_pos);
}
wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmapBundle& bmp_undo_to_sys, const wxBitmapBundle& bmp_undo, bool is_blinking, size_t rect_id)
wxPoint OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmapBundle& bmp_undo_to_sys, const wxBitmapBundle& bmp_undo, bool is_blinking, size_t rect_id)
{
#ifndef DISABLE_BLINKING
pos = draw_blinking_bmp(dc, pos, is_blinking);
@ -979,7 +1008,19 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBi
h_pos += bmp_dim2 + ctrl->m_h_gap;
return h_pos;
return wxPoint(h_pos, v_pos);
}
wxCoord OG_CustomCtrl::CtrlLine::draw_edit_bmp(wxDC &dc, wxPoint pos, const wxBitmapBundle *bmp_edit)
{
const wxCoord h_pos = pos.x + ctrl->m_h_gap;
const wxCoord v_pos = pos.y;
const int bmp_w = get_bitmap_size(bmp_edit, ctrl).GetWidth();
rects_edit_icon.emplace_back(wxRect(h_pos, v_pos, bmp_w, bmp_w));
dc.DrawBitmap(bmp_edit->GetBitmapFor(ctrl), h_pos, v_pos);
return h_pos + bmp_w + ctrl->m_h_gap;
}
bool OG_CustomCtrl::CtrlLine::launch_browser() const

View file

@ -64,12 +64,14 @@ class OG_CustomCtrl :public wxPanel
void render(wxDC& dc, wxCoord h_pos, wxCoord v_pos);
wxCoord draw_text (wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width, bool is_url = false, bool is_main = false);
wxPoint draw_blinking_bmp(wxDC& dc, wxPoint pos, bool is_blinking);
wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmapBundle& bmp_undo_to_sys, const wxBitmapBundle& bmp_undo, bool is_blinking, size_t rect_id = 0);
wxPoint draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmapBundle& bmp_undo_to_sys, const wxBitmapBundle& bmp_undo, bool is_blinking, size_t rect_id = 0);
wxCoord draw_edit_bmp(wxDC& dc, wxPoint pos, const wxBitmapBundle* bmp_edit);
bool launch_browser() const;
bool is_separator() const { return og_line.is_separator(); }
std::vector<wxRect> rects_undo_icon;
std::vector<wxRect> rects_undo_to_sys_icon;
std::vector<wxRect> rects_edit_icon;
wxRect rect_label;
};

View file

@ -102,6 +102,14 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co
};
field->m_parent = parent();
if (edit_custom_gcode && opt.is_code) {
field->m_fn_edit_value = [this](std::string opt_id) {
if (!m_disabled)
this->edit_custom_gcode(opt_id);
};
field->set_edit_tooltip(_L("Edit CustomG-code"));
}
field->m_back_to_initial_value = [this](std::string opt_id) {
if (!m_disabled)
this->back_to_initial_value(opt_id);

View file

@ -121,6 +121,8 @@ public:
std::function<void(wxWindow* win)> rescale_extra_column_item { nullptr };
std::function<void(wxWindow* win)> rescale_near_label_widget { nullptr };
std::function<void(const t_config_option_key& opt_key)> edit_custom_gcode { nullptr };
wxFont sidetext_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };

View file

@ -252,6 +252,8 @@ void Tab::create_preset_tab()
// Bitmaps to be shown on the "Undo user changes" button next to each input field.
add_scaled_bitmap(this, m_bmp_value_revert, "undo");
add_scaled_bitmap(this, m_bmp_white_bullet, "dot");
// Bitmap to be shown on the "edit" button before to each editable input field.
add_scaled_bitmap(this, m_bmp_edit_value, "edit");
set_tooltips_text();
@ -817,6 +819,10 @@ void Tab::decorate()
field->set_undo_tooltip(tt);
field->set_undo_to_sys_tooltip(sys_tt);
field->set_label_colour(color);
if (field->has_edit_ui())
field->set_edit_bitmap(&m_bmp_edit_value);
}
if (m_active_page)
@ -2860,6 +2866,11 @@ static void validate_custom_gcode_cb(Tab* tab, ConfigOptionsGroupShp opt_group,
tab->on_value_change(opt_key, value);
}
void Tab::edit_custom_gcode(const t_config_option_key& opt_key)
{
MessageDialog(this, format_wxstr("Edit gcode for %1%", opt_key), this->title()).ShowModal();
}
void TabFilament::add_filament_overrides_page()
{
//BBS
@ -3134,11 +3145,14 @@ void TabFilament::build()
const int gcode_field_height = 15; // 150
const int notes_field_height = 25; // 250
auto edit_custom_gcode_fn = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
page = add_options_page(L("Advanced"), "advanced");
optgroup = page->new_optgroup(L("Filament start G-code"), L"param_gcode", 0);
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("filament_start_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3149,6 +3163,7 @@ void TabFilament::build()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("filament_end_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3450,6 +3465,8 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line("support_chamber_temp_control", "chamber-temperature");
optgroup->append_single_option_line("support_air_filtration", "air-filtration");
auto edit_custom_gcode_fn = [this](const t_config_option_key& opt_key) { edit_custom_gcode(opt_key); };
const int gcode_field_height = 15; // 150
const int notes_field_height = 25; // 250
page = add_options_page(L("Machine gcode"), "cog");
@ -3457,6 +3474,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("machine_start_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3467,6 +3485,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("machine_end_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3477,6 +3496,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, optgroup](const t_config_option_key &opt_key, const boost::any &value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("printing_by_object_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3488,6 +3508,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("before_layer_change_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3498,6 +3519,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("layer_change_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3508,6 +3530,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("time_lapse_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3518,6 +3541,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("change_filament_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3528,7 +3552,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key &opt_key, const boost::any &value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("change_extrusion_role_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -3539,6 +3563,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("machine_pause_gcode");
option.opt.is_code = true;
option.opt.height = gcode_field_height;//150;
@ -3548,6 +3573,7 @@ void TabPrinter::build_fff()
optgroup->m_on_change = [this, &optgroup_title = optgroup->title](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup_title, opt_key, value);
};
optgroup->edit_custom_gcode = edit_custom_gcode_fn;
option = optgroup->get_option("template_custom_gcode");
option.opt.is_code = true;
option.opt.height = gcode_field_height;//150;

View file

@ -196,6 +196,8 @@ protected:
ScalableBitmap *m_bmp_non_system;
// Bitmaps to be shown on the "Undo user changes" button next to each input field.
ScalableBitmap m_bmp_value_revert;
// Bitmaps to be shown on the "Undo user changes" button next to each input field.
ScalableBitmap m_bmp_edit_value;
std::vector<ScalableButton*> m_scaled_buttons = {};
std::vector<ScalableBitmap*> m_scaled_bitmaps = {};
@ -402,6 +404,7 @@ public:
void restore_last_select_item();
static bool validate_custom_gcode(const wxString& title, const std::string& gcode);
void edit_custom_gcode(const t_config_option_key &opt_key);
bool validate_custom_gcodes();
bool validate_custom_gcodes_was_shown{ false };
void set_just_edit(bool just_edit);