mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	ENH: enable gcode window and support viewing added custom gcode
Change-Id: I2def8c32c17b6f2edfd2e6d0776123127560f167
This commit is contained in:
		
							parent
							
								
									e2f96590cf
								
							
						
					
					
						commit
						d776c7595e
					
				
					 12 changed files with 195 additions and 107 deletions
				
			
		|  | @ -498,14 +498,14 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he | |||
|     imgui.pop_toolbar_style(); | ||||
| } | ||||
| 
 | ||||
| void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& filename, std::vector<size_t> &&lines_ends) | ||||
| void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& filename, const std::vector<size_t> &lines_ends) | ||||
| { | ||||
|     assert(! m_file.is_open()); | ||||
|     if (m_file.is_open()) | ||||
|         return; | ||||
| 
 | ||||
|     m_filename   = filename; | ||||
|     m_lines_ends = std::move(lines_ends); | ||||
|     m_lines_ends = lines_ends; | ||||
| 
 | ||||
|     m_selected_line_id = 0; | ||||
|     m_last_lines_size = 0; | ||||
|  | @ -561,11 +561,11 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, f | |||
|         return ret; | ||||
|     }; | ||||
| 
 | ||||
|     static const ImVec4 LINE_NUMBER_COLOR = ImGuiWrapper::COL_ORANGE_LIGHT; | ||||
|     static const ImVec4 SELECTION_RECT_COLOR = ImGuiWrapper::COL_ORANGE_DARK; | ||||
|     static const ImVec4 COMMAND_COLOR = { 0.8f, 0.8f, 0.0f, 1.0f }; | ||||
|     static const ImVec4 PARAMETERS_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f }; | ||||
|     static const ImVec4 COMMENT_COLOR = { 0.7f, 0.7f, 0.7f, 1.0f }; | ||||
|     static const ImVec4 LINE_NUMBER_COLOR = { 0, 174.0f / 255.0f, 66.0f / 255.0f, 1.0f }; | ||||
|     static const ImVec4 SELECTION_RECT_COLOR = { 0, 174.0f / 255.0f, 66.0f / 255.0f, 1.0f }; | ||||
|     static const ImVec4 COMMAND_COLOR = m_is_dark ? ImVec4( 240.0f / 255.0f, 240.0f / 255.0f, 240.0f / 255.0f, 1.0f ) : ImVec4( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
|     static const ImVec4 PARAMETERS_COLOR = m_is_dark ? ImVec4( 179.0f / 255.0f, 179.0f / 255.0f, 179.0f / 255.0f, 1.0f ) : ImVec4( 206.0f / 255.0f, 206.0f / 255.0f, 206.0f / 255.0f, 1.0f ); | ||||
|     static const ImVec4 COMMENT_COLOR = m_is_dark ? ImVec4(129.0f / 255.0f, 129.0f / 255.0f, 129.0f / 255.0f, 1.0f) : ImVec4( 172.0f / 255.0f, 172.0f / 255.0f, 172.0f / 255.0f, 1.0f ); | ||||
| 
 | ||||
|     if (!m_visible || m_filename.empty() || m_lines_ends.empty() || curr_line_id == 0) | ||||
|         return; | ||||
|  | @ -615,7 +615,7 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, f | |||
|     imgui.set_next_window_pos(right, top, ImGuiCond_Always, 1.0f, 0.0f); | ||||
|     imgui.set_next_window_size(0.0f, wnd_height, ImGuiCond_Always); | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); | ||||
|     ImGui::SetNextWindowBgAlpha(0.6f); | ||||
|     ImGui::SetNextWindowBgAlpha(0.8f); | ||||
|     imgui.begin(std::string("G-code"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove); | ||||
| 
 | ||||
|     // center the text in the window by pushing down the first line
 | ||||
|  | @ -691,7 +691,7 @@ void GCodeViewer::SequentialView::GCodeWindow::stop_mapping_file() | |||
|     } | ||||
| } | ||||
| //BBS: GUI refactor: move to the right
 | ||||
| void GCodeViewer::SequentialView::render(float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const | ||||
| void GCodeViewer::SequentialView::render(float legend_height, int canvas_width, int canvas_height, int right_margin, const EViewType& view_type) const | ||||
| { | ||||
|     marker.render(canvas_width, canvas_height, view_type); | ||||
| 
 | ||||
|  | @ -702,9 +702,7 @@ void GCodeViewer::SequentialView::render(float legend_height, int canvas_width, | |||
|         bottom -= wxGetApp().plater()->get_view_toolbar().get_height(); | ||||
| #endif | ||||
|     //gcode_window.render(legend_height, bottom, static_cast<uint64_t>(gcode_ids[current.last]));
 | ||||
|     if (wxGetApp().get_mode() == ConfigOptionMode::comDevelop) { | ||||
|         gcode_window.render(legend_height, (float)canvas_height, (float)canvas_width, static_cast<uint64_t>(gcode_ids[current.last])); | ||||
|     } | ||||
|     gcode_window.render(legend_height, (float)canvas_height, (float)canvas_width - (float)right_margin, static_cast<uint64_t>(gcode_ids[current.last])); | ||||
| } | ||||
| 
 | ||||
| const std::vector<GCodeViewer::Color> GCodeViewer::Extrusion_Role_Colors {{ | ||||
|  | @ -898,6 +896,7 @@ void GCodeViewer::init(ConfigOptionMode mode, PresetBundle* preset_bundle) | |||
| void GCodeViewer::on_change_color_mode(bool is_dark) { | ||||
|     m_is_dark = is_dark; | ||||
|     m_sequential_view.marker.on_change_color_mode(m_is_dark); | ||||
|     m_sequential_view.gcode_window.on_change_color_mode(m_is_dark); | ||||
| } | ||||
| 
 | ||||
| void GCodeViewer::set_scale(float scale) | ||||
|  | @ -984,11 +983,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr | |||
|     m_gcode_result = &gcode_result; | ||||
|     m_only_gcode_in_preview = only_gcode; | ||||
| 
 | ||||
|     if (mode == ConfigOptionMode::comDevelop) { | ||||
|         m_sequential_view.gcode_window.load_gcode(gcode_result.filename, | ||||
|             // Stealing out lines_ends should be safe because this gcode_result is processed only once (see the 1st if in this function).
 | ||||
|             std::move(const_cast<std::vector<size_t>&>(gcode_result.lines_ends))); | ||||
|     } | ||||
|     m_sequential_view.gcode_window.load_gcode(gcode_result.filename, gcode_result.lines_ends); | ||||
| 
 | ||||
|     //BBS: add only gcode mode
 | ||||
|     //if (wxGetApp().is_gcode_viewer())
 | ||||
|  | @ -1092,7 +1087,6 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr | |||
|     bool current_has_print_instances = current_plate->has_printable_instances(); | ||||
|     if (current_plate->is_slice_result_valid() && wxGetApp().model().objects.empty() && !current_has_print_instances) | ||||
|         only_gcode_3mf = true; | ||||
| 
 | ||||
|     m_layers_slider->set_menu_enable(!(only_gcode || only_gcode_3mf)); | ||||
|     m_layers_slider->set_as_dirty(); | ||||
|     m_moves_slider->set_as_dirty(); | ||||
|  | @ -1287,7 +1281,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) | |||
|         m_sequential_view.marker.set_world_position(m_sequential_view.current_position); | ||||
|         m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); | ||||
|         //BBS fixed buttom margin. m_moves_slider.pos_y
 | ||||
|         m_sequential_view.render(legend_height, canvas_width, canvas_height - bottom_margin * m_scale, m_view_type); | ||||
|         m_sequential_view.render(legend_height, canvas_width, canvas_height - bottom_margin * m_scale, right_margin * m_scale, m_view_type); | ||||
|     } | ||||
| #if ENABLE_GCODE_VIEWER_STATISTICS | ||||
|     render_statistics(); | ||||
|  | @ -4345,7 +4339,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv | |||
|     ImGui::PushStyleColor(ImGuiCol_ScrollbarGrab, ImVec4(0.42f, 0.42f, 0.42f, 1.00f)); | ||||
|     ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabHovered, ImVec4(0.93f, 0.93f, 0.93f, 1.00f)); | ||||
|     ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabActive, ImVec4(0.93f, 0.93f, 0.93f, 1.00f)); | ||||
|     ImGui::SetNextWindowBgAlpha(0.6f); | ||||
|     ImGui::SetNextWindowBgAlpha(0.8f); | ||||
|     const float max_height = 0.75f * static_cast<float>(cnv_size.get_height()); | ||||
|     const float child_height = 0.3333f * max_height; | ||||
|     ImGui::SetNextWindowSizeConstraints({ 0.0f, 0.0f }, { -1.0f, max_height }); | ||||
|  |  | |||
|  | @ -648,6 +648,7 @@ public: | |||
|                 std::string parameters; | ||||
|                 std::string comment; | ||||
|             }; | ||||
|             bool m_is_dark = false; | ||||
|             bool m_visible{ true }; | ||||
|             uint64_t m_selected_line_id{ 0 }; | ||||
|             size_t m_last_lines_size{ 0 }; | ||||
|  | @ -661,7 +662,7 @@ public: | |||
|         public: | ||||
|             GCodeWindow() = default; | ||||
|             ~GCodeWindow() { stop_mapping_file(); } | ||||
|             void load_gcode(const std::string& filename, std::vector<size_t> &&lines_ends); | ||||
|             void load_gcode(const std::string& filename, const std::vector<size_t> &lines_ends); | ||||
|             void reset() { | ||||
|                 stop_mapping_file(); | ||||
|                 m_lines_ends.clear(); | ||||
|  | @ -674,6 +675,7 @@ public: | |||
|             //BBS: GUI refactor: add canvas size
 | ||||
|             //void render(float top, float bottom, uint64_t curr_line_id) const;
 | ||||
|             void render(float top, float bottom, float right, uint64_t curr_line_id) const; | ||||
|             void on_change_color_mode(bool is_dark) { m_is_dark = is_dark; } | ||||
| 
 | ||||
|             void stop_mapping_file(); | ||||
|         }; | ||||
|  | @ -697,7 +699,7 @@ public: | |||
|         float m_scale = 1.0; | ||||
| 
 | ||||
|         //BBS: GUI refactor: add canvas size
 | ||||
|         void render(float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const; | ||||
|         void render(float legend_height, int canvas_width, int canvas_height, int right_margin, const EViewType& view_type) const; | ||||
|     }; | ||||
| 
 | ||||
|     struct ETools | ||||
|  |  | |||
|  | @ -67,6 +67,8 @@ static std::string gcode(Type type) | |||
|     switch (type) { | ||||
|     //BBS
 | ||||
|     case Template:    return config.opt_string("template_custom_gcode"); | ||||
|     case PausePrint:  return config.opt_string("machine_pause_gcode"); | ||||
| 
 | ||||
|     default:          return ""; | ||||
|     } | ||||
| 
 | ||||
|  | @ -150,6 +152,7 @@ bool IMSlider::init_texture() | |||
|         result &= IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/one_layer_off_dark.svg", 28, 28, m_one_layer_off_dark_id); | ||||
|         result &= IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/one_layer_off_hover_dark.svg", 28, 28, m_one_layer_off_hover_dark_id); | ||||
|         result &= IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/im_gcode_pause.svg", 14, 14, m_pause_icon_id); | ||||
|         result &= IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/im_gcode_custom.svg", 14, 14, m_custom_icon_id); | ||||
|         result &= IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/im_slider_delete.svg", 14, 14, m_delete_icon_id); | ||||
|     } | ||||
| 
 | ||||
|  | @ -292,18 +295,12 @@ void IMSlider::SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, | |||
| 
 | ||||
|     UseDefaultColors(m_mode == SingleExtruder); | ||||
| 
 | ||||
|     auto curr_plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); | ||||
|     auto curr_print_seq = curr_plate->get_real_print_seq(); | ||||
| 
 | ||||
|     if (curr_print_seq == PrintSequence::ByObject) | ||||
|         m_is_wipe_tower = false; | ||||
|     else  | ||||
|         m_is_wipe_tower = m_mode != SingleExtruder; | ||||
|     m_is_wipe_tower = m_mode != SingleExtruder; | ||||
| 
 | ||||
|     auto config = wxGetApp().preset_bundle->full_config(); | ||||
|     m_is_spiral_vase = config.option<ConfigOptionBool>("spiral_mode")->value; | ||||
| 
 | ||||
|     m_can_change_color = can_change_color; | ||||
|     m_can_change_color = can_change_color && !m_is_spiral_vase; | ||||
| 
 | ||||
|     // close opened menu window after reslice
 | ||||
|     m_show_menu = false; | ||||
|  | @ -376,6 +373,11 @@ void IMSlider::add_code_as_tick(Type type, int selected_extruder) | |||
|     post_ticks_changed_event(type); | ||||
| } | ||||
| 
 | ||||
| void IMSlider::delete_tick(const TickCode& tick) { | ||||
|     m_ticks.ticks.erase(tick); | ||||
|     post_ticks_changed_event(tick.type); | ||||
| } | ||||
| 
 | ||||
| bool IMSlider::check_ticks_changed_event(Type type) | ||||
| { | ||||
|     //BBL only support MultiExtruder
 | ||||
|  | @ -623,12 +625,16 @@ void IMSlider::draw_ticks(const ImRect& slideable_region) { | |||
|         if (ImGui::IsMouseHoveringRect(tick_hover_box.Min, tick_hover_box.Max)) | ||||
|         { | ||||
|             // render left tick box
 | ||||
|             ImGui::RenderFrame(tick_hover_box.Min, { slideable_region.Min.x, tick_hover_box.Max.y }, tick_hover_box_clr, false); | ||||
|             ImRect left_hover_box = ImRect(tick_hover_box.Min, { slideable_region.Min.x, tick_hover_box.Max.y }); | ||||
|             ImGui::RenderFrame(left_hover_box.Min, left_hover_box.Max, tick_hover_box_clr, false); | ||||
|             // render right tick box
 | ||||
|             ImGui::RenderFrame({ slideable_region.Max.x, tick_hover_box.Min.y }, tick_hover_box.Max, tick_hover_box_clr, false); | ||||
|             ImRect right_hover_box = ImRect({ slideable_region.Max.x, tick_hover_box.Min.y }, tick_hover_box.Max); | ||||
|             ImGui::RenderFrame(right_hover_box.Min, right_hover_box.Max, tick_hover_box_clr, false); | ||||
| 
 | ||||
|             show_tooltip(*tick_it); | ||||
|             if (context.IO.MouseClicked[0]) { | ||||
|                 m_tick_value   = tick_it->tick; | ||||
|                 m_tick_rect    = ImVec4(tick_hover_box.Min.x, tick_hover_box.Min.y, tick_hover_box.Max.x, tick_hover_box.Max.y); | ||||
|                 m_tick_value = tick_it->tick; | ||||
|                 m_tick_rect = ImVec4(tick_hover_box.Min.x, tick_hover_box.Min.y, tick_hover_box.Max.x, tick_hover_box.Max.y); | ||||
|             } | ||||
|         } | ||||
|         ++tick_it; | ||||
|  | @ -651,6 +657,11 @@ void IMSlider::draw_ticks(const ImRect& slideable_region) { | |||
|             ImVec2      icon_pos     = ImVec2(slideable_region.GetCenter().x + icon_offset.x, tick_pos - icon_offset.y); | ||||
|             button_with_pos(pause_icon_id, icon_size, icon_pos); | ||||
|         } | ||||
|         if (tick_it->type == Custom || tick_it->type == Template) { | ||||
|             ImTextureID custom_icon_id = m_custom_icon_id; | ||||
|             ImVec2      icon_pos = ImVec2(slideable_region.GetCenter().x + icon_offset.x, tick_pos - icon_offset.y); | ||||
|             button_with_pos(custom_icon_id, icon_size, icon_pos); | ||||
|         } | ||||
|         ++tick_it; | ||||
|     } | ||||
| 
 | ||||
|  | @ -664,13 +675,41 @@ void IMSlider::draw_ticks(const ImRect& slideable_region) { | |||
|         if (ImGui::IsMouseHoveringRect(icon_pos, icon_pos + icon_size)) { | ||||
|             if (context.IO.MouseClicked[0]) { | ||||
|                 // delete tick
 | ||||
|                 Type type = tick_it->type; | ||||
|                 m_ticks.ticks.erase(tick_it); | ||||
|                 post_ticks_changed_event(type); | ||||
|                 delete_tick(*tick_it); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void IMSlider::show_tooltip(const TickCode& tick){ | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 6 * m_scale, 3 * m_scale }); | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, { 3 * m_scale }); | ||||
|     ImGui::PushStyleColor(ImGuiCol_PopupBg, ImGuiWrapper::COL_WINDOW_BACKGROUND); | ||||
|     ImGui::PushStyleColor(ImGuiCol_Border, { 0,0,0,0 }); | ||||
|     ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); | ||||
|     ImGui::BeginTooltip(); | ||||
|     switch (tick.type) | ||||
|     { | ||||
|     case CustomGCode::ColorChange: | ||||
|         break; | ||||
|     case CustomGCode::PausePrint: | ||||
|         ImGui::TextUnformatted((_u8L("Pause:") + " \"" + gcode(PausePrint) + "\"").c_str()); | ||||
|         break; | ||||
|     case CustomGCode::ToolChange: | ||||
|         ImGui::TextUnformatted(_u8L("Change Filament").c_str()); | ||||
|         break; | ||||
|     case CustomGCode::Template: | ||||
|         ImGui::TextUnformatted((_u8L("Custom Template:") + " \"" + gcode(Template) + "\"").c_str()); | ||||
|         break; | ||||
|     case CustomGCode::Custom: | ||||
|         ImGui::TextUnformatted((_u8L("Custom G-code:") + " \"" + tick.extra + "\"").c_str()); | ||||
|         break; | ||||
|     default: | ||||
|         break; | ||||
|     } | ||||
|     ImGui::EndTooltip(); | ||||
|     ImGui::PopStyleColor(3); | ||||
|     ImGui::PopStyleVar(2); | ||||
| } | ||||
| 
 | ||||
| bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower_value, std::string& higher_label, std::string& lower_label,int v_min, int v_max, const ImVec2& size, SelectedSlider& selection, bool one_layer_flag, float scale) | ||||
|  | @ -790,12 +829,10 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|             context.IO.MouseClicked[0]) | ||||
|             m_show_menu = false; | ||||
| 
 | ||||
|         if (!m_ticks.empty()) { | ||||
|             // draw ticks
 | ||||
|             draw_ticks(h_selected ? higher_slideable_region : lower_slideable_region); | ||||
|             // draw colored band
 | ||||
|             draw_colored_band(groove, h_selected ? higher_slideable_region : lower_slideable_region); | ||||
|         } | ||||
|         // draw ticks
 | ||||
|         draw_ticks(h_selected ? higher_slideable_region : lower_slideable_region); | ||||
|         // draw colored band
 | ||||
|         draw_colored_band(groove, h_selected ? higher_slideable_region : lower_slideable_region); | ||||
| 
 | ||||
|         if (!m_ticks.has_tick_with_code(ToolChange)) { | ||||
|             // draw scroll line
 | ||||
|  | @ -862,12 +899,10 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|          | ||||
|         ImVec2 bar_center = higher_handle.GetCenter(); | ||||
| 
 | ||||
|         if (!m_ticks.empty()) { | ||||
|             // draw ticks
 | ||||
|             draw_ticks(one_slideable_region); | ||||
|             // draw colored band
 | ||||
|             draw_colored_band(groove, one_slideable_region); | ||||
|         } | ||||
|         // draw ticks
 | ||||
|         draw_ticks(one_slideable_region); | ||||
|         // draw colored band
 | ||||
|         draw_colored_band(groove, one_slideable_region); | ||||
| 
 | ||||
|         // draw handle
 | ||||
|         window->DrawList->AddLine(ImVec2(mid_x - 0.5 * bar_width, handle_center.y), ImVec2(mid_x + 0.5 * bar_width, handle_center.y), handle_clr, 2 * line_width); | ||||
|  | @ -963,7 +998,7 @@ bool IMSlider::render(int canvas_width, int canvas_height) | |||
|     return result; | ||||
| } | ||||
| 
 | ||||
| void IMSlider::render_input_custom_gcode() | ||||
| void IMSlider::render_input_custom_gcode(std::string custom_gcode) | ||||
| { | ||||
|     if (m_show_custom_gcode_window) | ||||
|         ImGui::OpenPopup((_u8L("Custom G-code")).c_str()); | ||||
|  | @ -995,9 +1030,13 @@ void IMSlider::render_input_custom_gcode() | |||
|         if (set_focus && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)) { | ||||
|             wxGetApp().plater()->get_current_canvas3D()->force_set_focus(); | ||||
|             ImGui::SetKeyboardFocusHere(0); | ||||
|             strcpy(m_custom_gcode, custom_gcode.c_str()); | ||||
|         } | ||||
|         const int text_height = 6; | ||||
|         ImGui::InputTextMultiline("##text", m_custom_gcode, sizeof(m_custom_gcode), ImVec2(-1, ImGui::GetTextLineHeight() * text_height)); | ||||
| 
 | ||||
|         ImGui::InputTextMultiline("##text", m_custom_gcode, sizeof(m_custom_gcode), ImVec2(-1, ImGui::GetTextLineHeight() * text_height), ImGuiInputTextFlags_CallbackAlways, [](ImGuiInputTextCallbackData* data) {  | ||||
|             return data->CursorPos = data->BufTextLen; | ||||
|             }); | ||||
| 
 | ||||
|         ImGui::NewLine(); | ||||
|         ImGui::SameLine(ImGui::GetStyle().WindowPadding.x * 14); | ||||
|  | @ -1046,7 +1085,7 @@ void IMSlider::do_go_to_layer(size_t layer_number) { | |||
| void IMSlider::render_go_to_layer_dialog() | ||||
| { | ||||
|     if (m_show_go_to_layer_dialog) | ||||
|         ImGui::OpenPopup((_u8L("Jump to layer")).c_str()); | ||||
|         ImGui::OpenPopup((_u8L("Jump to Layer")).c_str()); | ||||
| 
 | ||||
|     ImGuiWrapper& imgui = *wxGetApp().imgui(); | ||||
|     ImVec2 center = ImGui::GetMainViewport()->GetCenter(); | ||||
|  | @ -1123,28 +1162,41 @@ void IMSlider::render_go_to_layer_dialog() | |||
|     imgui.pop_menu_style(); | ||||
| } | ||||
| 
 | ||||
| void IMSlider::render_menu() | ||||
| { | ||||
| void IMSlider::render_menu() { | ||||
|     if (!m_menu_enable) | ||||
|         return; | ||||
| 
 | ||||
|     ImGuiWrapper::push_menu_style(m_scale); | ||||
|     int extruder_num = m_extruder_colors.size(); | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_ChildRounding, 4.0f * m_scale); | ||||
| 
 | ||||
|     if (m_show_menu) { | ||||
|         ImGui::OpenPopup("slider_menu_popup"); | ||||
|     auto tick_it = GetSelection() == ssHigher ? m_ticks.ticks.find(TickCode{ GetHigherValue() }) : | ||||
|         GetSelection() == ssLower ? m_ticks.ticks.find(TickCode{ GetLowerValue() }) : | ||||
|         m_ticks.ticks.end(); | ||||
|     std::string custom_code; | ||||
|     if (tick_it != m_ticks.ticks.end()) { | ||||
|         render_edit_menu(*tick_it); | ||||
|         if (tick_it->type == CustomGCode::Custom) | ||||
|             custom_code = tick_it->extra; | ||||
|     } | ||||
|     else { | ||||
|         render_add_menu(); | ||||
|     } | ||||
| 
 | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_::ImGuiStyleVar_ChildRounding, 4.0f * m_scale); | ||||
|     if (ImGui::BeginPopup("slider_menu_popup")) { | ||||
|     ImGui::PopStyleVar(1); | ||||
|     ImGuiWrapper::pop_menu_style(); | ||||
| 
 | ||||
|     render_input_custom_gcode(custom_code); | ||||
|     render_go_to_layer_dialog(); | ||||
| } | ||||
| 
 | ||||
| void IMSlider::render_add_menu() | ||||
| { | ||||
|     int extruder_num = m_extruder_colors.size(); | ||||
| 
 | ||||
|     if (m_show_menu) | ||||
|         ImGui::OpenPopup("slider_add_menu_popup"); | ||||
|     if (ImGui::BeginPopup("slider_add_menu_popup")) { | ||||
|         bool menu_item_enable = m_draw_mode != dmSequentialFffPrint; | ||||
|         //if ((m_selection == ssLower && GetLowerValueD() == m_zero_layer_height) || (m_selection == ssHigher && GetHigherValueD() == m_zero_layer_height))
 | ||||
|         //{
 | ||||
|         //    if (menu_item_with_icon(_u8L("Jump to Layer").c_str(), "")) {
 | ||||
|         //        m_show_go_to_layer_dialog = true;
 | ||||
|         //    }
 | ||||
|         //}
 | ||||
|         //else
 | ||||
|         { | ||||
|             if (menu_item_with_icon(_u8L("Add Pause").c_str(), "", ImVec2(0, 0), 0, false, menu_item_enable)) { | ||||
|                 add_code_as_tick(PausePrint); | ||||
|  | @ -1164,7 +1216,7 @@ void IMSlider::render_menu() | |||
| 
 | ||||
|         //BBS render this menu item only when extruder_num > 1
 | ||||
|         if (extruder_num > 1) { | ||||
|             if (!m_can_change_color || m_draw_mode == dmSequentialFffPrint || m_is_spiral_vase) { | ||||
|             if (!m_can_change_color || m_draw_mode == dmSequentialFffPrint) { | ||||
|                 begin_menu(_u8L("Change Filament").c_str(), false); | ||||
|             } | ||||
|             else if (begin_menu(_u8L("Change Filament").c_str())) { | ||||
|  | @ -1178,12 +1230,62 @@ void IMSlider::render_menu() | |||
|         } | ||||
|         ImGui::EndPopup(); | ||||
|     } | ||||
|     ImGui::PopStyleVar(1); | ||||
| } | ||||
| 
 | ||||
|     ImGuiWrapper::pop_menu_style(); | ||||
| 
 | ||||
|     render_input_custom_gcode(); | ||||
|     render_go_to_layer_dialog(); | ||||
| void IMSlider::render_edit_menu(const TickCode& tick) | ||||
| { | ||||
|     if (m_show_menu) | ||||
|         ImGui::OpenPopup("slider_edit_menu_popup"); | ||||
|     if (ImGui::BeginPopup("slider_edit_menu_popup")) { | ||||
|         switch (tick.type) | ||||
|         { | ||||
|         case CustomGCode::PausePrint: | ||||
|             if (menu_item_with_icon(_u8L("Delete Pause").c_str(), "")) { | ||||
|                 delete_tick(tick); | ||||
|             } | ||||
|             break; | ||||
|         case CustomGCode::Template: | ||||
|             if (!gcode(Template).empty()) { | ||||
|                 if (menu_item_with_icon(_u8L("Delete Custom Template").c_str(), "")) { | ||||
|                     delete_tick(tick); | ||||
|                 } | ||||
|             } | ||||
|             break; | ||||
|         case CustomGCode::Custom: | ||||
|             if (menu_item_with_icon(_u8L("Edit Custom G-code").c_str(), "")) { | ||||
|                 m_show_custom_gcode_window = true; | ||||
|             } | ||||
|             if (menu_item_with_icon(_u8L("Delete Custom G-code").c_str(), "")) { | ||||
|                 delete_tick(tick); | ||||
|             } | ||||
|             break; | ||||
|         case CustomGCode::ToolChange: { | ||||
|             int extruder_num = m_extruder_colors.size(); | ||||
|             if (extruder_num > 1) { | ||||
|                 if (!m_can_change_color || m_draw_mode == dmSequentialFffPrint) { | ||||
|                     begin_menu(_u8L("Change Filament").c_str(), false); | ||||
|                 } | ||||
|                 else if (begin_menu(_u8L("Change Filament").c_str())) { | ||||
|                     for (int i = 0; i < extruder_num; i++) { | ||||
|                         std::array<float, 4> rgba = decode_color_to_float_array(m_extruder_colors[i]); | ||||
|                         ImU32                icon_clr = IM_COL32(rgba[0] * 255.0f, rgba[1] * 255.0f, rgba[2] * 255.0f, rgba[3] * 255.0f); | ||||
|                         if (menu_item_with_icon((_u8L("Filament ") + std::to_string(i + 1)).c_str(), "", ImVec2(14, 14) * m_scale, icon_clr)) add_code_as_tick(ToolChange, i + 1); | ||||
|                     } | ||||
|                     end_menu(); | ||||
|                 } | ||||
|                 if (menu_item_with_icon(_u8L("Delete Filament Change").c_str(), "")) { | ||||
|                     delete_tick(tick); | ||||
|                 } | ||||
|             } | ||||
|             break; | ||||
|         } | ||||
|         case CustomGCode::ColorChange: | ||||
|         case CustomGCode::Unknown: | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|         ImGui::EndPopup(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void IMSlider::on_change_color_mode(bool is_dark) { | ||||
|  | @ -1317,16 +1419,8 @@ std::string IMSlider::get_label(int tick, LabelType label_type) | |||
|         if (label_type == ltHeightWithLayer) { | ||||
|             char   buffer[64]; | ||||
|             size_t layer_number; | ||||
|             if (m_values[GetMinValueD()] == m_zero_layer_height) { | ||||
|                 layer_number = m_is_wipe_tower ? get_layer_number(value, label_type): (m_values.empty() ? value : value); | ||||
|                 m_values[value] == m_zero_layer_height ? | ||||
|                     ::sprintf(buffer, "%5s\n%5s", _u8L("Start").c_str(), _u8L("G-code").c_str()) : | ||||
|                     ::sprintf(buffer, "%5s\n%5s", std::to_string(layer_number).c_str(), layer_height); | ||||
|             } | ||||
|             else { | ||||
|                 layer_number = m_is_wipe_tower ? get_layer_number(value, label_type) + 1 : (m_values.empty() ? value : value + 1); | ||||
|                 ::sprintf(buffer, "%5s\n%5s", std::to_string(layer_number).c_str(), layer_height); | ||||
|             } | ||||
|             layer_number = m_draw_mode == dmSequentialFffPrint ? (m_values.empty() ? value : value + 1) : m_is_wipe_tower ? get_layer_number(value, label_type) + 1 : (m_values.empty() ? value : value + 1); | ||||
|             ::sprintf(buffer, "%5s\n%5s", std::to_string(layer_number).c_str(), layer_height); | ||||
|             return std::string(buffer); | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -51,7 +51,6 @@ enum LabelType | |||
|     ltEstimatedTime, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class IMSlider | ||||
| { | ||||
| public: | ||||
|  | @ -134,16 +133,20 @@ public: | |||
| protected: | ||||
|     void add_custom_gcode(std::string custom_gcode); | ||||
|     void add_code_as_tick(Type type, int selected_extruder = -1); | ||||
|     void do_go_to_layer(size_t layer_number); | ||||
|     void delete_tick(const TickCode& tick); | ||||
|     void do_go_to_layer(size_t layer_number); //menu
 | ||||
|     void correct_lower_value(); | ||||
|     void correct_higher_value(); | ||||
|     bool horizontal_slider(const char* str_id, int* v, int v_min, int v_max, const ImVec2& size, float scale = 1.0); | ||||
|     void render_go_to_layer_dialog(); | ||||
|     void render_input_custom_gcode(); | ||||
|     void render_go_to_layer_dialog(); //menu
 | ||||
|     void render_input_custom_gcode(std::string custom_gcode = ""); //menu
 | ||||
|     void render_menu(); | ||||
|     void render_add_menu(); //menu
 | ||||
|     void render_edit_menu(const TickCode& tick); //menu
 | ||||
|     void draw_background_and_groove(const ImRect& bg_rect, const ImRect& groove); | ||||
|     void draw_colored_band(const ImRect& groove, const ImRect& slideable_region); | ||||
|     void draw_ticks(const ImRect& slideable_region); | ||||
|     void show_tooltip(const TickCode& tick); //menu
 | ||||
|     bool vertical_slider(const char* str_id, int* higher_value, int* lower_value, | ||||
|         std::string& higher_label, std::string& lower_label, | ||||
|         int v_min, int v_max, const ImVec2& size, | ||||
|  | @ -176,22 +179,14 @@ private: | |||
|     bool m_render_as_disabled{ false }; | ||||
| 
 | ||||
|     SelectedSlider m_selection; | ||||
|     bool m_is_left_down       = false; | ||||
|     bool m_is_right_down      = false; | ||||
|     bool m_is_one_layer       = false; | ||||
|     bool m_is_focused         = false; | ||||
|     bool m_show_menu          = false; | ||||
|     bool m_menu_enable        = true; | ||||
|     bool m_show_custom_gcode_window = false; | ||||
|     bool m_show_go_to_layer_dialog = false; | ||||
|     bool m_menu_enable        = true; //menu
 | ||||
|     bool m_show_menu          = false; //menu
 | ||||
|     bool m_show_custom_gcode_window = false; //menu
 | ||||
|     bool m_show_go_to_layer_dialog = false; //menu
 | ||||
|     bool m_force_mode_apply   = true; | ||||
|     bool m_enable_action_icon = true; | ||||
|     bool m_enable_cog_icon    = false; | ||||
|     bool m_is_wipe_tower      = false; // This flag indicates that there is multiple extruder print with wipe tower
 | ||||
|     bool m_is_spiral_vase     = false; | ||||
|     bool m_display_lower      = true; | ||||
|     bool m_display_higher     = true; | ||||
|     int  m_selected_tick_value = -1; | ||||
| 
 | ||||
|     /* BBS slider images */ | ||||
|     void *m_one_layer_on_id; | ||||
|  | @ -207,6 +202,7 @@ private: | |||
|     void* m_one_layer_off_dark_id; | ||||
|     void* m_one_layer_off_hover_dark_id; | ||||
|     void *m_pause_icon_id; | ||||
|     void *m_custom_icon_id; | ||||
|     void *m_delete_icon_id; | ||||
| 
 | ||||
|     DrawMode            m_draw_mode = dmRegular; | ||||
|  | @ -230,8 +226,8 @@ private: | |||
| 
 | ||||
|     std::vector<double> m_alternate_values; | ||||
| 
 | ||||
|     char m_custom_gcode[1024] = { 0 }; | ||||
|     char m_layer_number[64] = { 0 }; | ||||
|     char m_custom_gcode[1024] = { 0 }; //menu
 | ||||
|     char m_layer_number[64] = { 0 }; //menu
 | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -124,7 +124,7 @@ const ImVec4 ImGuiWrapper::COL_GREY_DARK         = { 0.333f, 0.333f, 0.333f, 1.0 | |||
| const ImVec4 ImGuiWrapper::COL_GREY_LIGHT        = { 0.4f, 0.4f, 0.4f, 1.0f }; | ||||
| const ImVec4 ImGuiWrapper::COL_ORANGE_DARK       = { 0.757f, 0.404f, 0.216f, 1.0f }; | ||||
| const ImVec4 ImGuiWrapper::COL_ORANGE_LIGHT      = { 1.0f, 0.49f, 0.216f, 1.0f }; | ||||
| const ImVec4 ImGuiWrapper::COL_WINDOW_BACKGROUND = { 0.133f, 0.133f, 0.133f, 0.8f }; | ||||
| const ImVec4 ImGuiWrapper::COL_WINDOW_BACKGROUND = { 0.1f, 0.1f, 0.1f, 0.8f }; | ||||
| const ImVec4 ImGuiWrapper::COL_BUTTON_BACKGROUND = COL_ORANGE_DARK; | ||||
| const ImVec4 ImGuiWrapper::COL_BUTTON_HOVERED    = COL_ORANGE_LIGHT; | ||||
| const ImVec4 ImGuiWrapper::COL_BUTTON_ACTIVE     = ImGuiWrapper::COL_BUTTON_HOVERED; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 liz.li
						liz.li