WIP GCode substitutions: Changed the format of gcode_substitutions by

adding an empty comment as a fourth parameter to each substitution.
In the future, we will provide a UI to show / edit the comment.
This commit is contained in:
Vojtech Bubnik 2022-01-27 17:02:07 +01:00
parent 12cebddce6
commit 7da4bebe7a
3 changed files with 13 additions and 13 deletions

View file

@ -24,11 +24,11 @@ const void unescape_extended_search_mode(std::string &s)
GCodeFindReplace::GCodeFindReplace(const std::vector<std::string> &gcode_substitutions)
{
if ((gcode_substitutions.size() % 3) != 0)
if ((gcode_substitutions.size() % 4) != 0)
throw RuntimeError("Invalid length of gcode_substitutions parameter");
m_substitutions.reserve(gcode_substitutions.size() / 3);
for (size_t i = 0; i < gcode_substitutions.size(); i += 3) {
m_substitutions.reserve(gcode_substitutions.size() / 4);
for (size_t i = 0; i < gcode_substitutions.size(); i += 4) {
Substitution out;
try {
out.plain_pattern = gcode_substitutions[i];

View file

@ -3899,17 +3899,17 @@ void SubstitutionManager::init(DynamicPrintConfig* config, wxWindow* parent, wxF
void SubstitutionManager::validate_lenth()
{
std::vector<std::string>& substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
if ((substitutions.size() % 3) != 0) {
if ((substitutions.size() % 4) != 0) {
WarningDialog(m_parent, "Value of gcode_substitutions parameter will be cut to valid length",
"Invalid length of gcode_substitutions parameter").ShowModal();
substitutions.resize(substitutions.size() - (substitutions.size() % 3));
substitutions.resize(substitutions.size() - (substitutions.size() % 4));
}
}
bool SubstitutionManager::is_compatibile_with_ui()
{
const std::vector<std::string>& substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
if (int(substitutions.size() / 3) != m_grid_sizer->GetEffectiveRowsCount() - 1) {
if (int(substitutions.size() / 4) != m_grid_sizer->GetEffectiveRowsCount() - 1) {
ErrorDialog(m_parent, "Invalid compatibility between UI and BE", false).ShowModal();
return false;
}
@ -3919,7 +3919,7 @@ bool SubstitutionManager::is_compatibile_with_ui()
bool SubstitutionManager::is_valid_id(int substitution_id, const wxString& message)
{
const std::vector<std::string>& substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
if (int(substitutions.size() / 3) < substitution_id) {
if (int(substitutions.size() / 4) < substitution_id) {
ErrorDialog(m_parent, message, false).ShowModal();
return false;
}
@ -3948,7 +3948,7 @@ void SubstitutionManager::delete_substitution(int substitution_id)
// delete substitution
std::vector<std::string>& substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
substitutions.erase(std::next(substitutions.begin(), substitution_id * 3), std::next(substitutions.begin(), substitution_id * 3 + 3));
substitutions.erase(std::next(substitutions.begin(), substitution_id * 4), std::next(substitutions.begin(), substitution_id * 4 + 4));
call_ui_update();
// update grid_sizer
@ -3970,7 +3970,7 @@ void SubstitutionManager::add_substitution(int substitution_id, const std::strin
// create new substitution
// it have to be added to config too
std::vector<std::string>& substitutions = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
for (size_t i = 0; i < 3; i ++)
for (size_t i = 0; i < 4; i ++)
substitutions.push_back(std::string());
call_after_layout = true;
@ -4073,7 +4073,7 @@ void SubstitutionManager::update_from_config()
validate_lenth();
int subst_id = 0;
for (size_t i = 0; i < subst.size(); i += 3)
for (size_t i = 0; i < subst.size(); i += 4)
add_substitution(subst_id++, subst[i], subst[i + 1], subst[i + 2]);
m_parent->GetParent()->Layout();
@ -4098,7 +4098,7 @@ void SubstitutionManager::edit_substitution(int substitution_id, int opt_pos, co
if(!is_compatibile_with_ui() || !is_valid_id(substitution_id, "Invalid substitution_id to edit"))
return;
substitutions[substitution_id * 3 + opt_pos] = value;
substitutions[substitution_id * 4 + opt_pos] = value;
call_ui_update();
}

View file

@ -60,8 +60,8 @@ class SubstitutionManager
bool is_valid_id(int substitution_id, const wxString& message);
public:
SubstitutionManager() {};
~SubstitutionManager() {};
SubstitutionManager() = default;
~SubstitutionManager() = default;
void init(DynamicPrintConfig* config, wxWindow* parent, wxFlexGridSizer* grid_sizer);
void create_legend();