Merge branch 'master' into fs_svg_SPE-1517

This commit is contained in:
Filip Sykala - NTB T15p 2023-09-18 17:25:41 +02:00
commit db64aacaf8
3 changed files with 25 additions and 22 deletions

View File

@ -346,7 +346,7 @@ std::string GLCanvas3D::LayersEditing::get_tooltip(const GLCanvas3D& canvas) con
} }
} }
if (h > 0.0f) if (h > 0.0f)
ret = std::to_string(h); ret = format("%.3f", h);
} }
} }
return ret; return ret;

View File

@ -1799,7 +1799,7 @@ void TabPrint::update_description_lines()
_L("Post processing scripts shall modify G-code file in place.")); _L("Post processing scripts shall modify G-code file in place."));
m_post_process_explanation->SetPathEnd("post-processing-scripts_283913"); m_post_process_explanation->SetPathEnd("post-processing-scripts_283913");
} }
// upadte G-code substitutions from the current configuration // update G-code substitutions from the current configuration
{ {
m_subst_manager.update_from_config(); m_subst_manager.update_from_config();
if (m_del_all_substitutions_btn) if (m_del_all_substitutions_btn)
@ -4548,7 +4548,7 @@ void SubstitutionManager::init(DynamicPrintConfig* config, wxWindow* parent, wxF
m_substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values; m_substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
} }
void SubstitutionManager::validate_lenth() void SubstitutionManager::validate_length()
{ {
if ((m_substitutions.size() % 4) != 0) { if ((m_substitutions.size() % 4) != 0) {
WarningDialog(m_parent, "Value of gcode_substitutions parameter will be cut to valid length", WarningDialog(m_parent, "Value of gcode_substitutions parameter will be cut to valid length",
@ -4559,7 +4559,7 @@ void SubstitutionManager::validate_lenth()
} }
} }
bool SubstitutionManager::is_compatibile_with_ui() bool SubstitutionManager::is_compatible_with_ui()
{ {
if (int(m_substitutions.size() / 4) != m_grid_sizer->GetEffectiveRowsCount() - 1) { if (int(m_substitutions.size() / 4) != m_grid_sizer->GetEffectiveRowsCount() - 1) {
ErrorDialog(m_parent, "Invalid compatibility between UI and BE", false).ShowModal(); ErrorDialog(m_parent, "Invalid compatibility between UI and BE", false).ShowModal();
@ -4596,15 +4596,13 @@ void SubstitutionManager::create_legend()
// delete substitution_id from substitutions // delete substitution_id from substitutions
void SubstitutionManager::delete_substitution(int substitution_id) void SubstitutionManager::delete_substitution(int substitution_id)
{ {
validate_lenth(); validate_length();
if (!is_valid_id(substitution_id, "Invalid substitution_id to delete")) if (!is_valid_id(substitution_id, "Invalid substitution_id to delete"))
return; return;
// delete substitution // delete substitution
m_substitutions.erase(std::next(m_substitutions.begin(), substitution_id * 4), std::next(m_substitutions.begin(), substitution_id * 4 + 4)); std::vector<std::string>& substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
substitutions.erase(std::next(substitutions.begin(), substitution_id * 4), std::next(substitutions.begin(), substitution_id * 4 + 4));
// save changes from m_substitutions to config
m_config->option<ConfigOptionStrings>("gcode_substitutions")->values = m_substitutions;
call_ui_update(); call_ui_update();
@ -4695,13 +4693,7 @@ void SubstitutionManager::add_substitution( int substitution_id,
auto chb_match_single_line = new wxCheckBox(m_parent, wxID_ANY, _L("Match single line")); auto chb_match_single_line = new wxCheckBox(m_parent, wxID_ANY, _L("Match single line"));
chb_match_single_line->SetValue(match_single_line); chb_match_single_line->SetValue(match_single_line);
chb_match_single_line->Show(regexp); chb_match_single_line->Show(regexp);
m_chb_match_single_lines.emplace_back(chb_match_single_line);
chb_match_single_line->Bind(wxEVT_SHOW, [chb_match_single_line, chb_regexp](wxShowEvent& evt) {
if (evt.IsShown() && !chb_regexp->GetValue()) {
// To avoid a case, when ShowAll() is called for m_grid_sizer but chb_match_single_line have to be hidden
chb_match_single_line->Hide();
}
});
params_sizer->Add(chb_match_single_line, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, m_em); params_sizer->Add(chb_match_single_line, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, m_em);
@ -4740,21 +4732,31 @@ void SubstitutionManager::update_from_config()
{ {
std::vector<std::string>& subst = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values; std::vector<std::string>& subst = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
if (m_substitutions == subst && m_grid_sizer->IsShown(1)) { if (m_substitutions == subst && m_grid_sizer->IsShown(1)) {
// just update visibility for chb_match_single_lines
int subst_id = 0;
for (size_t i = 0; i < subst.size(); i += 4) {
const std::string& params = subst[i + 2];
const bool regexp = strchr(params.c_str(), 'r') != nullptr || strchr(params.c_str(), 'R') != nullptr;
m_chb_match_single_lines[subst_id++]->Show(regexp);
}
// "gcode_substitutions" values didn't changed in config. There is no need to update/recreate controls // "gcode_substitutions" values didn't changed in config. There is no need to update/recreate controls
return; return;
} }
m_substitutions = subst; m_substitutions = subst;
if (!m_grid_sizer->IsEmpty()) if (!m_grid_sizer->IsEmpty()) {
m_grid_sizer->Clear(true); m_grid_sizer->Clear(true);
m_chb_match_single_lines.clear();
}
if (subst.empty()) if (subst.empty())
hide_delete_all_btn(); hide_delete_all_btn();
else else
create_legend(); create_legend();
validate_lenth(); validate_length();
int subst_id = 0; int subst_id = 0;
for (size_t i = 0; i < subst.size(); i += 4) for (size_t i = 0; i < subst.size(); i += 4)
@ -4777,8 +4779,8 @@ void SubstitutionManager::delete_all()
void SubstitutionManager::edit_substitution(int substitution_id, int opt_pos, const std::string& value) void SubstitutionManager::edit_substitution(int substitution_id, int opt_pos, const std::string& value)
{ {
validate_lenth(); validate_length();
if(!is_compatibile_with_ui() || !is_valid_id(substitution_id, "Invalid substitution_id to edit")) if(!is_compatible_with_ui() || !is_valid_id(substitution_id, "Invalid substitution_id to edit"))
return; return;
m_substitutions[substitution_id * 4 + opt_pos] = value; m_substitutions[substitution_id * 4 + opt_pos] = value;

View File

@ -71,9 +71,10 @@ class SubstitutionManager
std::function<void()> m_cb_hide_delete_all_btn{ nullptr }; std::function<void()> m_cb_hide_delete_all_btn{ nullptr };
std::vector<std::string> m_substitutions; std::vector<std::string> m_substitutions;
std::vector<wxCheckBox*> m_chb_match_single_lines;
void validate_lenth(); void validate_length();
bool is_compatibile_with_ui(); bool is_compatible_with_ui();
bool is_valid_id(int substitution_id, const wxString& message); bool is_valid_id(int substitution_id, const wxString& message);
public: public: