From b8d9a2fdf368853dc513795ee5d915da5ae43f9e Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Mon, 26 Sep 2022 09:38:11 +0800 Subject: [PATCH] ENH: add custom gcode back Add custom gcode back, which can be inserted in gcode viewer layer slider. Signed-off-by: salt.wei Change-Id: I270cc438bedf11b30f07f8f9bad6ae5436d5a2dd --- src/libslic3r/Format/3mf.cpp | 2 +- src/libslic3r/Format/AMF.cpp | 2 +- src/libslic3r/Format/bbs_3mf.cpp | 2 +- src/libslic3r/GCode.cpp | 29 +++--- src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 9 ++ src/libslic3r/PrintConfig.hpp | 1 + src/slic3r/GUI/GCodeViewer.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp | 33 +----- src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp | 2 - src/slic3r/GUI/IMSlider.cpp | 117 ++++++++++++++++++++-- src/slic3r/GUI/IMSlider.hpp | 6 ++ src/slic3r/GUI/ImGuiWrapper.cpp | 27 +++++ src/slic3r/GUI/ImGuiWrapper.hpp | 2 + src/slic3r/GUI/OptionsGroup.hpp | 3 +- src/slic3r/GUI/Plater.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 9 ++ 17 files changed, 185 insertions(+), 65 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index f74545e98..4fd309654 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -3189,7 +3189,7 @@ bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archiv //BBS std::string gcode = //code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") : code.type == CustomGCode::PausePrint ? config->opt_string("machine_pause_gcode") : - //code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : + code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : code.type == CustomGCode::ToolChange ? "tool_change" : code.extra; code_tree.put(".gcode" , gcode ); } diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index ca50d3ffb..1e0b6687d 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -1336,7 +1336,7 @@ bool load_amf(const char *path, DynamicPrintConfig *config, ConfigSubstitutionCo //BBS std::string gcode = //code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") : code.type == CustomGCode::PausePrint ? config->opt_string("machine_pause_gcode") : - //code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : + code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : code.type == CustomGCode::ToolChange ? "tool_change" : code.extra; code_tree.put(".gcode" , gcode ); } diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index 68882c53b..f996f8524 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -5739,7 +5739,7 @@ bool _BBS_3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_ar //BBS std::string gcode = //code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") : code.type == CustomGCode::PausePrint ? config->opt_string("machine_pause_gcode") : - //code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : + code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : code.type == CustomGCode::ToolChange ? "tool_change" : code.extra; code_tree.put(".gcode" , gcode ); } diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 4dc125d05..7c397f205 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -866,7 +866,7 @@ namespace DoExport { //if (ret.size() < MAX_TAGS_COUNT) check(_(L("Printing by object G-code")), config.printing_by_object_gcode.value); //if (ret.size() < MAX_TAGS_COUNT) check(_(L("Color Change G-code")), config.color_change_gcode.value); if (ret.size() < MAX_TAGS_COUNT) check(_(L("Pause G-code")), config.machine_pause_gcode.value); - //if (ret.size() < MAX_TAGS_COUNT) check(_(L("Template Custom G-code")), config.template_custom_gcode.value); + if (ret.size() < MAX_TAGS_COUNT) check(_(L("Template Custom G-code")), config.template_custom_gcode.value); if (ret.size() < MAX_TAGS_COUNT) { for (const std::string& value : config.filament_start_gcode.values) { check(_(L("Filament start G-code")), value); @@ -2218,11 +2218,11 @@ namespace ProcessLayer // Extruder switches are processed by LayerTools, they should be filtered out. assert(custom_gcode->type != CustomGCode::ToolChange); - CustomGCode::Type gcode_type = custom_gcode->type; + CustomGCode::Type gcode_type = custom_gcode->type; bool color_change = gcode_type == CustomGCode::ColorChange; - bool tool_change = gcode_type == CustomGCode::ToolChange; + bool tool_change = gcode_type == CustomGCode::ToolChange; // Tool Change is applied as Color Change for a single extruder printer only. - assert(! tool_change || single_filament_print); + assert(!tool_change || single_filament_print); std::string pause_print_msg; int m600_extruder_before_layer = -1; @@ -2230,13 +2230,13 @@ namespace ProcessLayer m600_extruder_before_layer = custom_gcode->extruder - 1; else if (gcode_type == CustomGCode::PausePrint) pause_print_msg = custom_gcode->extra; - //BBS: inserting color gcode and template_custom_gcode is removed + //BBS: inserting color gcode is removed #if 0 // we should add or not colorprint_change in respect to nozzle_diameter count instead of really used extruders count if (color_change || tool_change) { assert(m600_extruder_before_layer >= 0); - // Color Change or Tool Change as Color Change. + // Color Change or Tool Change as Color Change. // add tag for processor gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Color_Change) + ",T" + std::to_string(m600_extruder_before_layer) + "," + custom_gcode->color + "\n"; @@ -2258,20 +2258,19 @@ namespace ProcessLayer // see GH issue #6362 gcodegen.writer().unretract(); } - } - else { + } + else { #endif - if (gcode_type == CustomGCode::PausePrint) // Pause print - { + if (gcode_type == CustomGCode::PausePrint) // Pause print + { // add tag for processor gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Pause_Print) + "\n"; //! FIXME_in_fw show message during print pause - //if (!pause_print_msg.empty()) - // gcode += "M117 " + pause_print_msg + "\n"; + //if (!pause_print_msg.empty()) + // gcode += "M117 " + pause_print_msg + "\n"; gcode += gcodegen.placeholder_parser_process("machine_pause_gcode", config.machine_pause_gcode, current_extruder_id) + "\n"; } -#if 0 - else { + else { // add tag for processor gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Custom_Code) + "\n"; if (gcode_type == CustomGCode::Template) // Template Custom Gcode @@ -2281,9 +2280,9 @@ namespace ProcessLayer } gcode += "\n"; +#if 0 } #endif - } return gcode; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 365a85655..210680943 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -745,7 +745,7 @@ static std::vector s_Preset_printer_options { "default_print_profile", "inherits", "silent_mode", // BBS - "scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", + "scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", "template_custom_gcode", "nozzle_type", "auxiliary_fan", "nozzle_volume", //SoftFever "host_type", "print_host", "printhost_apikey", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 4ee4f466b..ec13dc83f 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1565,6 +1565,15 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionString("")); + def = this->add("template_custom_gcode", coString); + def->label = L("Custom G-code"); + def->tooltip = L("This G-code will be used as a custom code"); + def->multiline = true; + def->full_width = true; + def->height = 12; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionString("")); + { struct AxisDefault { std::string name; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index ad42c9f30..bf66396eb 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -782,6 +782,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloat, travel_speed_z)) ((ConfigOptionBool, silent_mode)) ((ConfigOptionString, machine_pause_gcode)) + ((ConfigOptionString, template_custom_gcode)) //BBS ((ConfigOptionEnum, nozzle_type)) ((ConfigOptionBool, auxiliary_fan)) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index b8adcc991..0bd358177 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -4703,7 +4703,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv append_option_item(item,offsets); //BBS display filament change times - if (m_print_statistics.total_filamentchanges > 0) { + if (m_print_statistics.total_filamentchanges > 0 && ( total_flushed_filament_m > 0 || total_flushed_filament_g > 0)) { std::string flushed_filament_title_str = _u8L("Flushed filament"); std::string flushed_filament_str = _u8L("Filament"); std::string total_flushed_filament_str = _u8L("Total"); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index def666e5b..83a832ca8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -141,35 +141,6 @@ std::string GLGizmoSimplify::on_get_name() const return _u8L("Simplify"); } -void GLGizmoSimplify::push_simplify_style() -{ - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20.0f, 10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowTitleAlign, ImVec2(0.05f, 0.50f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 3.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(50 / 255.0f, 58 / 255.0f, 61 / 255.0f, 1.00f)); // 1 - ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGuiWrapper::COL_WINDOW_BG); // 2 - ImGui::PushStyleColor(ImGuiCol_TitleBg, ImGuiWrapper::COL_TITLE_BG); // 3 - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImGuiWrapper::COL_TITLE_BG); // 4 - ImGui::PushStyleColor(ImGuiCol_Separator, ImGuiWrapper::COL_SEPARATOR); // 5 - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 6 - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 7 - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 8 - ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.00f)); // 9 - ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.00f)); // 10 - ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 0.00f)); // 11 - ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 12 - ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, ImGuiWrapper::COL_GREEN_LIGHT); - ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); - -} -void GLGizmoSimplify::pop_simplify_style() -{ - ImGui::PopStyleColor(14); - ImGui::PopStyleVar(5); -} - void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limit) { create_gui_cfg(); @@ -260,7 +231,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi float slider_width = m_imgui->scaled(5.0f); - push_simplify_style(); + m_imgui->push_common_window_style(m_parent.get_scale()); int flag = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse; m_imgui->begin(on_get_name(), flag); @@ -412,7 +383,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi ImGui::PopStyleColor(1); m_imgui->end(); - pop_simplify_style(); + m_imgui->pop_common_window_style(); if (start_process) process(); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp index 2a53fd8e7..39093e14d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp @@ -48,8 +48,6 @@ private: void process(); void stop_worker_thread_request(); void worker_finished(); - void push_simplify_style(); - void pop_simplify_style(); void create_gui_cfg(); void request_rerender(bool force = false); diff --git a/src/slic3r/GUI/IMSlider.cpp b/src/slic3r/GUI/IMSlider.cpp index 3345e7df7..d83c08297 100644 --- a/src/slic3r/GUI/IMSlider.cpp +++ b/src/slic3r/GUI/IMSlider.cpp @@ -88,14 +88,21 @@ bool check_color_change(PrintObject *object, size_t frst_layer_id, size_t layers static std::string gcode(Type type) { - const PrintConfig& config = GUI::wxGetApp().plater()->fff_print().config(); + Slic3r::DynamicPrintConfig config = wxGetApp().preset_bundle->full_config(); switch (type) { //BBS - //case ColorChange: return config.color_change_gcode; - case PausePrint: return config.machine_pause_gcode; - //case Template: return config.template_custom_gcode; + case Template: return config.opt_string("template_custom_gcode"); default: return ""; } + + //const PrintConfig& config = GUI::wxGetApp().plater()->fff_print().config(); + //switch (type) { + ////BBS + ////case ColorChange: return config.color_change_gcode; + //case PausePrint: return config.machine_pause_gcode; + //case Template: return config.template_custom_gcode; + //default: return ""; + //} } static std::string short_and_splitted_time(const std::string &time) @@ -222,9 +229,9 @@ bool TickCodeInfo::add_tick(const int tick, Type type, const int extruder, doubl std::string extra; if (type == Custom) // custom Gcode { - /*extra = get_custom_code(custom_gcode, print_z); - if (extra.empty()) return false; - custom_gcode = extra;*/ + //extra = get_custom_code(custom_gcode, print_z); + //if (extra.empty()) return false; + //custom_gcode = extra; } else if (type == PausePrint) { //BBS do not set pause extra message //extra = get_pause_print_msg(pause_print_msg, print_z); @@ -262,9 +269,10 @@ bool TickCodeInfo::edit_tick(std::set::iterator it, double print_z) if (it->color == edited_value) return false; changed_tick.color = edited_value; } else if (it->type == Template) { - if (gcode(Template) == edited_value) return false; - changed_tick.extra = edited_value; - changed_tick.type = Custom; + //if (gcode(Template) == edited_value) return false; + //changed_tick.extra = edited_value; + //changed_tick.type = Custom; + ; } else if (it->type == Custom || it->type == PausePrint) { if (it->extra == edited_value) return false; changed_tick.extra = edited_value; @@ -625,6 +633,21 @@ void IMSlider::post_ticks_changed_event(Type type) m_is_need_post_tick_changed_event = true; } +void IMSlider::add_custom_gcode(std::string custom_gcode) +{ + if (m_selection == ssUndef) return; + const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; + + const auto it = m_ticks.ticks.find(TickCode{ tick }); + + if (it != m_ticks.ticks.end()) { + m_ticks.ticks.erase(it); + } + m_ticks.ticks.emplace(TickCode{ tick, Custom, std::max(1, m_only_extruder), "", custom_gcode }); + + post_ticks_changed_event(Custom); +} + void IMSlider::add_code_as_tick(Type type, int selected_extruder) { if (m_selection == ssUndef) return; @@ -1194,6 +1217,8 @@ bool IMSlider::render(int canvas_width, int canvas_height) float scale = (float) wxGetApp().em_unit() / 10.0f; + render_input_custom_gcode(); + if (is_horizontal()) { float pos_x = std::max(LEFT_MARGIN, 0.2f * canvas_width); float pos_y = (canvas_height - HORIZONTAL_SLIDER_SIZE.y * m_scale); @@ -1247,6 +1272,70 @@ bool IMSlider::render(int canvas_width, int canvas_height) return result; } +void IMSlider::render_input_custom_gcode() +{ + if (!m_show_custom_gcode_window) + return; + ImGuiWrapper& imgui = *wxGetApp().imgui(); + static bool move_to_center = true; + if (move_to_center) { + move_to_center = false; + auto pos_x = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width() / 2; + auto pos_y = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height() / 2; + imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always, 0.5f, 0.5f); + } + + imgui.push_common_window_style(m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.f * m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 3) * m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 7) * m_scale); + int windows_flag = + ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_AlwaysAutoResize + | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoScrollbar + | ImGuiWindowFlags_NoScrollWithMouse; + imgui.begin(_u8L("Custom G-code"), windows_flag); + imgui.text(_u8L("Enter Custom G-code used on current layer:")); + int text_height = 6; + ImGui::InputTextMultiline("##text", m_custom_gcode, sizeof(m_custom_gcode), ImVec2(-1, ImGui::GetTextLineHeight() * text_height)); + //text_height = 5; + //for (int i = 0; m_custom_gcode[i] != '\0'; ++i){ + // if ('\n' == m_custom_gcode[i] && text_height < 12) + // ++text_height; + //} + + ImGui::NewLine(); + ImGui::SameLine(ImGui::GetStyle().WindowPadding.x * 14); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f / 255.f, 174.f / 255.f, 66.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(61.f / 255.f, 203.f / 255.f, 115.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(27.f / 255.f, 136.f / 255.f, 68.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.f, 1.f, 1.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); + if (imgui.bbl_button(_L("OK"))) { + m_show_custom_gcode_window = false; + add_custom_gcode(m_custom_gcode); + move_to_center = true; + } + ImGui::PopStyleColor(5); + + ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(255.f / 255.f, 255.f / 255.f, 255.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(238.f / 255.f, 238.f / 255.f, 238.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(206.f / 255.f, 206.f / 255.f, 206.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(0.f, 0.f, 0.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(38.f / 255.0f, 46.f / 255.0f, 48.f / 255.0f, 1.00f)); + if (imgui.bbl_button(_L("Cancel"))) { + m_show_custom_gcode_window = false; + move_to_center = true; + } + ImGui::PopStyleColor(5); + + imgui.end(); + ImGui::PopStyleVar(3); + imgui.pop_common_window_style(); +} + void IMSlider::render_menu() { ImGuiWrapper::push_menu_style(m_scale); @@ -1267,6 +1356,14 @@ void IMSlider::render_menu() if (menu_item_with_icon(_u8L("Add Pause").c_str(), "")) { add_code_as_tick(PausePrint); } + if (menu_item_with_icon(_u8L("Add Custom G-code").c_str(), "")) { + m_show_custom_gcode_window = true; + } + if (!gcode(Template).empty()) { + if (menu_item_with_icon(_u8L("Add Custom Template").c_str(), "")) { + add_code_as_tick(Template); + } + } } //BBS render this menu item only when extruder_num > 1 diff --git a/src/slic3r/GUI/IMSlider.hpp b/src/slic3r/GUI/IMSlider.hpp index 0fffbb2a6..59d2e2e45 100644 --- a/src/slic3r/GUI/IMSlider.hpp +++ b/src/slic3r/GUI/IMSlider.hpp @@ -261,6 +261,7 @@ public: void UseDefaultColors(bool def_colors_on) { m_ticks.set_default_colors(def_colors_on); } + void add_custom_gcode(std::string custom_gcode); void add_code_as_tick(Type type, int selected_extruder = -1); void post_ticks_changed_event(Type type = Custom); bool check_ticks_changed_event(Type type); @@ -270,6 +271,8 @@ public: void render_menu(); + void render_input_custom_gcode(); + //BBS update scroll value changed bool is_dirty() { return m_dirty; } void set_as_dirty(bool dirty = true) { m_dirty = dirty; } @@ -327,6 +330,7 @@ private: bool m_is_one_layer = false; bool m_is_focused = false; bool m_show_menu = false; + bool m_show_custom_gcode_window = false; bool m_force_mode_apply = true; bool m_enable_action_icon = true; bool m_enable_cog_icon = false; @@ -367,6 +371,8 @@ private: Type m_tick_change_event_type; std::vector m_alternate_values; + + char m_custom_gcode[1024] = { 0 }; }; } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index e78dfcbab..77503e14e 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1687,6 +1687,33 @@ void ImGuiWrapper::pop_menu_style() ImGuiWrapper::pop_toolbar_style(); } +void ImGuiWrapper::push_common_window_style(const float scale) { + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f * scale); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20.0f, 10.0f) * scale); + ImGui::PushStyleVar(ImGuiStyleVar_WindowTitleAlign, ImVec2(0.05f, 0.50f) * scale); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 3.0f * scale); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(38 / 255.0f, 46 / 255.0f, 48 / 255.0f, 1.00f)); // 1 + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGuiWrapper::COL_WINDOW_BG); // 2 + ImGui::PushStyleColor(ImGuiCol_TitleBg, ImGuiWrapper::COL_TITLE_BG); // 3 + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImGuiWrapper::COL_TITLE_BG); // 4 + ImGui::PushStyleColor(ImGuiCol_Separator, ImGuiWrapper::COL_SEPARATOR); // 5 + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 6 + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 7 + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 8 + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.00f)); // 9 + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.00f)); // 10 + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 0.00f)); // 11 + ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 12 + ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, ImGuiWrapper::COL_GREEN_LIGHT); // 13 + ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 14 +} + +void ImGuiWrapper::pop_common_window_style() { + ImGui::PopStyleColor(14); + ImGui::PopStyleVar(5); +} + void ImGuiWrapper::init_font(bool compress) { destroy_font(); diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index dee1553eb..e0efa6b06 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -192,6 +192,8 @@ public: static void pop_toolbar_style(); static void push_menu_style(const float scale); static void pop_menu_style(); + static void push_common_window_style(const float scale); + static void pop_common_window_style(); //BBS static int TOOLBAR_WINDOW_FLAGS; diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 6fe9b9953..a758f1652 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -257,7 +257,8 @@ public: const t_opt_map& opt_map() const throw() { return m_opt_map; } void set_config_category_and_type(const wxString &category, int type) { m_config_category = category; m_config_type = type; } - void set_config(DynamicPrintConfig* config) { m_config = config; m_modelconfig = nullptr; } + void set_config(DynamicPrintConfig* config) { + m_config = config; m_modelconfig = nullptr; } Option get_option(const std::string& opt_key, int opt_index = -1); Line create_single_option_line(const std::string& title, const std::string& path = std::string(), int idx = -1) /*const*/{ Option option = get_option(title, idx); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b31c5cc13..6bb2c65e4 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2220,7 +2220,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) preview->on_tick_changed(tick_event_type); // BBS set to invalid state only - if (tick_event_type == Type::ToolChange) { + if (tick_event_type == Type::ToolChange || tick_event_type == Type::Custom || tick_event_type == Type::Template) { PartPlate *plate = this->q->get_partplate_list().get_curr_plate(); if (plate) { plate->update_slice_result_valid_state(false); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 5e817c347..6c7e56575 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2914,6 +2914,15 @@ void TabPrinter::build_fff() option.opt.height = gcode_field_height;//150; optgroup->append_single_option_line(option); + optgroup = page->new_optgroup(L("Template Custom G-code"), L"param_gcode", 0); + 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); + }; + option = optgroup->get_option("template_custom_gcode"); + option.opt.is_code = true; + option.opt.height = gcode_field_height;//150; + optgroup->append_single_option_line(option); + #if 0 //page = add_options_page(L("Dependencies"), "advanced"); // optgroup = page->new_optgroup(L("Profile dependencies"));