mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 12:41:20 -06:00 
			
		
		
		
	Some code refactoring follow-up 33aa6be7b7 and 92b1302a08
				
					
				
			This commit is contained in:
		
							parent
							
								
									18ac892ed6
								
							
						
					
					
						commit
						88bd189047
					
				
					 4 changed files with 39 additions and 94 deletions
				
			
		|  | @ -10,6 +10,7 @@ | |||
| #include "libslic3r/AppConfig.hpp" | ||||
| #include "GUI_Utils.hpp" | ||||
| #include "MsgDialog.hpp" | ||||
| #include "Tab.hpp" | ||||
| 
 | ||||
| #include <wx/button.h> | ||||
| #include <wx/dialog.h> | ||||
|  | @ -2033,27 +2034,6 @@ static void upgrade_text_entry_dialog(wxTextEntryDialog* dlg, double min = -1.0, | |||
|     }, btn_OK->GetId()); | ||||
| } | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| static bool validate_custom_gcode(const std::string& gcode, const wxString& title) | ||||
| { | ||||
|     std::vector<std::string> tags; | ||||
|     bool invalid = GCodeProcessor::contains_reserved_tags(gcode, 5, tags); | ||||
|     if (invalid) { | ||||
|         wxString reports = _L_PLURAL("The following line", "The following lines", tags.size()); | ||||
|         reports += ":\n"; | ||||
|         for (const std::string& keyword : tags) { | ||||
|             reports += ";" + keyword + "\n"; | ||||
|         } | ||||
|         reports += _L("contain reserved keywords.") + "\n"; | ||||
|         reports += _L("Please remove them, as they may cause problems in g-code visualization and printing time estimation."); | ||||
| 
 | ||||
|         wxMessageDialog dialog(nullptr, reports, _L("Found reserved keywords in") + " " + title, wxICON_WARNING | wxOK); | ||||
|         dialog.ShowModal(); | ||||
|     } | ||||
|     return !invalid; | ||||
| } | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
| 
 | ||||
| static std::string get_custom_code(const std::string& code_in, double height) | ||||
| { | ||||
|     wxString msg_text = _L("Enter custom G-code used on current layer") + ":"; | ||||
|  | @ -2072,7 +2052,7 @@ static std::string get_custom_code(const std::string& code_in, double height) | |||
|             return ""; | ||||
| 
 | ||||
|         value = dlg.GetValue().ToStdString(); | ||||
|         valid = validate_custom_gcode(value, _L("Custom G-code")); | ||||
|         valid = GUI::Tab::validate_custom_gcode("Custom G-code", value); | ||||
|     } while (!valid); | ||||
|     return value; | ||||
| #else | ||||
|  |  | |||
|  | @ -548,18 +548,10 @@ void MainFrame::init_tabpanel() | |||
|     m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, [this](wxBookCtrlEvent& evt) { | ||||
|         wxWindow* panel = m_tabpanel->GetCurrentPage(); | ||||
|         if (panel != nullptr) { | ||||
|             TabPrinter* printer_tab = dynamic_cast<TabPrinter*>(panel); | ||||
|             if (printer_tab != nullptr) { | ||||
|                 if (!printer_tab->validate_custom_gcodes()) | ||||
|             Tab* tab = dynamic_cast<Tab*>(panel); | ||||
|             if (tab && (tab->type() == Preset::TYPE_FILAMENT || tab->type() == Preset::TYPE_PRINTER)) | ||||
|                 if (!tab->validate_custom_gcodes()) | ||||
|                     evt.Veto(); | ||||
|                 return; | ||||
|             } | ||||
|             TabFilament* filament_tab = dynamic_cast<TabFilament*>(panel); | ||||
|             if (filament_tab != nullptr) { | ||||
|                 if (!filament_tab->validate_custom_gcodes()) | ||||
|                     evt.Veto(); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|         }); | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|  |  | |||
|  | @ -1712,11 +1712,11 @@ void TabPrint::clear_pages() | |||
| } | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| static bool validate_custom_gcode(wxWindow* parent, const wxString& title, const std::string& gcode) | ||||
| bool Tab::validate_custom_gcode(const wxString& title, const std::string& gcode) | ||||
| { | ||||
|     std::vector<std::string> tags; | ||||
|     bool invalid = GCodeProcessor::contains_reserved_tags(gcode, 5, tags); | ||||
|     if (parent != nullptr && invalid) { | ||||
|     if (invalid) { | ||||
|         wxString reports = _L_PLURAL("The following line", "The following lines", tags.size()); | ||||
|         reports += ":\n"; | ||||
|         for (const std::string& keyword : tags) { | ||||
|  | @ -1725,11 +1725,17 @@ static bool validate_custom_gcode(wxWindow* parent, const wxString& title, const | |||
|         reports += _L("contain reserved keywords.") + "\n"; | ||||
|         reports += _L("Please remove them, as they may cause problems in g-code visualization and printing time estimation."); | ||||
| 
 | ||||
|         wxMessageDialog dialog(parent, reports, _L("Found reserved keywords in") + " " + title, wxICON_WARNING | wxOK); | ||||
|         wxMessageDialog dialog(wxGetApp().mainframe, reports, _L("Found reserved keywords in") + " " + _(title), wxICON_WARNING | wxOK); | ||||
|         dialog.ShowModal(); | ||||
|     } | ||||
|     return !invalid; | ||||
| } | ||||
| 
 | ||||
| static void validate_custom_gcode_cb(Tab* tab, ConfigOptionsGroupShp opt_group, const boost::any& value) { | ||||
|     Tab::validate_custom_gcode(opt_group->title, boost::any_cast<std::string>(value)); | ||||
|     tab->update_dirty(); | ||||
|     tab->update(); | ||||
| } | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
| 
 | ||||
| void TabFilament::add_filament_overrides_page() | ||||
|  | @ -1957,7 +1963,7 @@ void TabFilament::build() | |||
|         optgroup = page->new_optgroup(L("Start G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Start G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, value); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("start_filament_gcode"); | ||||
|  | @ -1969,7 +1975,7 @@ void TabFilament::build() | |||
|         optgroup = page->new_optgroup(L("End G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("End G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, value); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("end_filament_gcode"); | ||||
|  | @ -2086,25 +2092,6 @@ void TabFilament::clear_pages() | |||
| 	m_cooling_description_line = nullptr; | ||||
| } | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| bool TabFilament::validate_custom_gcodes() const | ||||
| { | ||||
|     auto check_optgroup = [this](const wxString& title, const Slic3r::t_config_option_key& key) { | ||||
|         const ConfigOptionsGroupShp opt_group = m_active_page->get_optgroup(title); | ||||
|         return (opt_group != nullptr) ? | ||||
|             validate_custom_gcode((wxWindow*)this, title, boost::any_cast<std::string>(opt_group->get_value(key))) : | ||||
|             true; | ||||
|     }; | ||||
| 
 | ||||
|     bool valid = true; | ||||
|     if (m_active_page->title() == L("Custom G-code")) { | ||||
|         valid &= check_optgroup(L("Start G-code"), "start_filament_gcode"); | ||||
|         valid &= check_optgroup(L("End G-code"), "end_filament_gcode"); | ||||
|     } | ||||
|     return valid; | ||||
| } | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
| 
 | ||||
| wxSizer* Tab::description_line_widget(wxWindow* parent, ogStaticText* *StaticText, wxString text /*= wxEmptyString*/) | ||||
| { | ||||
|     *StaticText = new ogStaticText(parent, text); | ||||
|  | @ -2295,7 +2282,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Start G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Start G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("start_gcode"); | ||||
|  | @ -2307,7 +2294,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("End G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("End G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("end_gcode"); | ||||
|  | @ -2319,7 +2306,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Before layer change G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Before layer change G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("before_layer_gcode"); | ||||
|  | @ -2331,7 +2318,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("After layer change G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("After layer change G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("layer_gcode"); | ||||
|  | @ -2343,7 +2330,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Tool change G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Tool change G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("toolchange_gcode"); | ||||
|  | @ -2355,7 +2342,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Between objects G-code (for sequential printing)"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Between objects G-code (for sequential printing)"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("between_objects_gcode"); | ||||
|  | @ -2367,7 +2354,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Color Change G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Color Change G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("color_change_gcode"); | ||||
|  | @ -2378,7 +2365,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Pause Print G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Pause Print G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("pause_print_gcode"); | ||||
|  | @ -2389,7 +2376,7 @@ void TabPrinter::build_fff() | |||
|         optgroup = page->new_optgroup(L("Template Custom G-code"), 0); | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
|         optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { | ||||
|             validate_custom_gcode(this, L("Template Custom G-code"), boost::any_cast<std::string>(value)); | ||||
|             validate_custom_gcode_cb(this, optgroup, boost::any_cast<std::string>(value)); | ||||
|         }; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
|         option = optgroup->get_option("template_custom_gcode"); | ||||
|  | @ -3842,28 +3829,17 @@ void TabPrinter::apply_extruder_cnt_from_cache() | |||
| } | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| bool TabPrinter::validate_custom_gcodes() const | ||||
| bool Tab::validate_custom_gcodes() | ||||
| { | ||||
|     auto check_optgroup = [this](const wxString& title, const Slic3r::t_config_option_key& key) { | ||||
|         const ConfigOptionsGroupShp opt_group = m_active_page->get_optgroup(title); | ||||
|         return (opt_group != nullptr) ?  | ||||
|             validate_custom_gcode((wxWindow*)this, title, boost::any_cast<std::string>(opt_group->get_value(key))) : | ||||
|             true; | ||||
|     }; | ||||
| 
 | ||||
|     bool valid = true; | ||||
|     if (m_printer_technology == ptFFF) { | ||||
|         if (m_active_page->title() == L("Custom G-code")) { | ||||
|             valid &= check_optgroup(L("Start G-code"), "start_gcode"); | ||||
|             valid &= check_optgroup(L("End G-code"), "end_gcode"); | ||||
|             valid &= check_optgroup(L("Before layer change G-code"), "before_layer_gcode"); | ||||
|             valid &= check_optgroup(L("After layer change G-code"), "layer_gcode"); | ||||
|             valid &= check_optgroup(L("Tool change G-code"), "toolchange_gcode"); | ||||
|             valid &= check_optgroup(L("Between objects G-code (for sequential printing)"), "between_objects_gcode"); | ||||
|             valid &= check_optgroup(L("Color Change G-code"), "color_change_gcode"); | ||||
|             valid &= check_optgroup(L("Pause Print G-code"), "pause_print_gcode"); | ||||
|             valid &= check_optgroup(L("Template Custom G-code"), "template_custom_gcode"); | ||||
|         } | ||||
|     if ((m_type == Preset::TYPE_FILAMENT ||  | ||||
|         m_type == Preset::TYPE_PRINTER && static_cast<TabPrinter*>(this)->m_printer_technology == ptFFF) && | ||||
|         m_active_page->title() == "Custom G-code") { | ||||
|             for (auto opt_group : m_active_page->m_optgroups) { | ||||
|                 assert(opt_group->opt_map().size() == 1); | ||||
|                 std::string key = opt_group->opt_map().begin()->first; | ||||
|                 valid &= validate_custom_gcode(opt_group->title, boost::any_cast<std::string>(opt_group->get_value(key))); | ||||
|             } | ||||
|     } | ||||
|     return valid; | ||||
| } | ||||
|  |  | |||
|  | @ -348,6 +348,11 @@ public: | |||
| 
 | ||||
| 	const std::map<wxString, std::string>& get_category_icon_map() { return m_category_icon; } | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| 	static bool validate_custom_gcode(const wxString& title, const std::string& gcode); | ||||
| 	bool        validate_custom_gcodes(); | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
| 
 | ||||
| protected: | ||||
| 	void			create_line_with_widget(ConfigOptionsGroup* optgroup, const std::string& opt_key, const wxString& path, widget_t widget); | ||||
| 	wxSizer*		compatible_widget_create(wxWindow* parent, PresetDependencies &deps); | ||||
|  | @ -412,10 +417,6 @@ public: | |||
| 	void		update() override; | ||||
| 	void		clear_pages() override; | ||||
|     bool 		supports_printer_technology(const PrinterTechnology tech) override { return tech == ptFFF; } | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| 	bool        validate_custom_gcodes() const; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
| }; | ||||
| 
 | ||||
| class TabPrinter : public Tab | ||||
|  | @ -474,10 +475,6 @@ public: | |||
| 	wxSizer*	create_bed_shape_widget(wxWindow* parent); | ||||
| 	void		cache_extruder_cnt(); | ||||
| 	void		apply_extruder_cnt_from_cache(); | ||||
| 
 | ||||
| #if ENABLE_VALIDATE_CUSTOM_GCODE | ||||
| 	bool        validate_custom_gcodes() const; | ||||
| #endif // ENABLE_VALIDATE_CUSTOM_GCODE
 | ||||
| }; | ||||
| 
 | ||||
| class TabSLAMaterial : public Tab | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 YuSanka
						YuSanka