From 70478f226f739f08dba2fac59e44b0ddd9e009e5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 8 Jun 2020 12:27:32 +0200 Subject: [PATCH] ENABLE_GCODE_VIEWER_AS_STATE -> Use default printbed in gcode viewer --- src/slic3r/GUI/GCodeViewer.cpp | 17 +++++++++++++++- src/slic3r/GUI/GLCanvas3D.cpp | 37 +++++++++++++++++++++++++--------- src/slic3r/GUI/GLCanvas3D.hpp | 3 +++ src/slic3r/GUI/MainFrame.cpp | 11 +++++++++- src/slic3r/GUI/Plater.cpp | 37 ++++++++++++++++++---------------- src/slic3r/GUI/Plater.hpp | 3 +++ 6 files changed, 79 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 31065d230..281ccfa67 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -251,6 +251,19 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& load_toolpaths(gcode_result); load_shells(print, initialized); + +#if ENABLE_GCODE_VIEWER_AS_STATE + // adjust printbed size + const double margin = 10.0; + Vec2d min(m_bounding_box.min(0) - margin, m_bounding_box.min(1) - margin); + Vec2d max(m_bounding_box.max(0) + margin, m_bounding_box.max(1) + margin); + Pointfs bed_shape = { + { min(0), min(1) }, + { max(0), min(1) }, + { max(0), max(1) }, + { min(0), max(1) } }; + wxGetApp().plater()->set_bed_shape(bed_shape, "", ""); +#endif // ENABLE_GCODE_VIEWER_AS_STATE } void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std::vector& str_tool_colors) @@ -450,7 +463,9 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) for (size_t i = 0; i < m_vertices.vertices_count; ++i) { const GCodeProcessor::MoveVertex& move = gcode_result.moves[i]; #if ENABLE_GCODE_VIEWER_AS_STATE - if (wxGetApp().mainframe->get_mode() != MainFrame::EMode::GCodeViewer) { + if (wxGetApp().mainframe->get_mode() == MainFrame::EMode::GCodeViewer) + m_bounding_box.merge(move.position.cast()); + else { #endif // ENABLE_GCODE_VIEWER_AS_STATE if (move.type == GCodeProcessor::EMoveType::Extrude && move.width != 0.0f && move.height != 0.0f) m_bounding_box.merge(move.position.cast()); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 304bc9fe7..29d3b9aa5 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1930,6 +1930,13 @@ void GLCanvas3D::zoom_to_selection() _zoom_to_box(m_selection.get_bounding_box()); } +#if ENABLE_GCODE_VIEWER_AS_STATE +void GLCanvas3D::zoom_to_gcode() +{ + _zoom_to_box(m_gcode_viewer.get_bounding_box(), 1.05); +} +#endif // ENABLE_GCODE_VIEWER_AS_STATE + void GLCanvas3D::select_view(const std::string& direction) { wxGetApp().plater()->get_camera().select_view(direction); @@ -2706,7 +2713,10 @@ static void load_gcode_retractions(const GCodePreviewData::Retraction& retractio void GLCanvas3D::load_gcode_preview(const GCodeProcessor::Result& gcode_result) { m_gcode_viewer.load(gcode_result, *this->fff_print(), m_initialized); - _show_warning_texture_if_needed(WarningTexture::ToolpathOutside); +#if ENABLE_GCODE_VIEWER_AS_STATE + if (wxGetApp().mainframe->get_mode() != MainFrame::EMode::GCodeViewer) +#endif // ENABLE_GCODE_VIEWER_AS_STATE + _show_warning_texture_if_needed(WarningTexture::ToolpathOutside); } void GLCanvas3D::refresh_gcode_preview(const GCodeProcessor::Result& gcode_result, const std::vector& str_tool_colors) @@ -5351,8 +5361,7 @@ static BoundingBoxf3 print_volume(const DynamicPrintConfig& config) BoundingBoxf3 ret; const ConfigOptionPoints* opt = dynamic_cast(config.option("bed_shape")); - if (opt != nullptr) - { + if (opt != nullptr) { BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); ret = BoundingBoxf3(Vec3d(unscale(bed_box_2D.min(0)) - tolerance_x, unscale(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale(bed_box_2D.max(0)) + tolerance_x, unscale(bed_box_2D.max(1)) + tolerance_y, config.opt_float("max_print_height"))); // Allow the objects to protrude below the print bed @@ -5365,14 +5374,22 @@ static BoundingBoxf3 print_volume(const DynamicPrintConfig& config) void GLCanvas3D::_render_background() const { #if ENABLE_GCODE_VIEWER - bool use_error_color = m_dynamic_background_enabled; - if (!m_volumes.empty()) - use_error_color &= _is_any_volume_outside(); - else - { - BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); - use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_bounding_box()) : false; +#if ENABLE_GCODE_VIEWER_AS_STATE + bool use_error_color = false; + if (wxGetApp().mainframe->get_mode() != MainFrame::EMode::GCodeViewer) { + use_error_color = m_dynamic_background_enabled; +#else + bool use_error_color = m_dynamic_background_enabled; +#endif // ENABLE_GCODE_VIEWER_AS_STATE + if (!m_volumes.empty()) + use_error_color &= _is_any_volume_outside(); + else { + BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); + use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_bounding_box()) : false; + } +#if ENABLE_GCODE_VIEWER_AS_STATE } +#endif // ENABLE_GCODE_VIEWER_AS_STATE #endif // ENABLE_GCODE_VIEWER glsafe(::glPushMatrix()); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index c8b7d3231..782a9425d 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -624,6 +624,9 @@ public: void zoom_to_bed(); void zoom_to_volumes(); void zoom_to_selection(); +#if ENABLE_GCODE_VIEWER_AS_STATE + void zoom_to_gcode(); +#endif // ENABLE_GCODE_VIEWER_AS_STATE void select_view(const std::string& direction); void update_volumes_colors_by_extruder(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index f09f611e6..f9e757251 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1162,10 +1162,14 @@ void MainFrame::set_mode(EMode mode) case EMode::Editor: { m_plater->reset(); -// m_plater->reset_last_loaded_gcode(); // switch view m_plater->select_view_3D("3D"); + m_plater->select_view("iso"); + + // switch printbed + m_plater->set_bed_shape(); + // switch menubar SetMenuBar(m_editor_menubar); @@ -1196,6 +1200,11 @@ void MainFrame::set_mode(EMode mode) // switch view m_plater->select_view_3D("Preview"); + m_plater->select_view("iso"); + + // switch printbed + m_plater->set_bed_shape({ { 0.0, 0.0 }, { 200.0, 0.0 }, { 200.0, 200.0 }, { 0.0, 200.0 } }, "", ""); + // switch menubar SetMenuBar(m_gcodeviewer_menubar); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7e9779f17..e5bbf73c6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2014,21 +2014,11 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) view3D_canvas->Bind(EVT_GLTOOLBAR_SPLIT_OBJECTS, &priv::on_action_split_objects, this); view3D_canvas->Bind(EVT_GLTOOLBAR_SPLIT_VOLUMES, &priv::on_action_split_volumes, this); view3D_canvas->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this); - view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) - { - set_bed_shape(config->option("bed_shape")->values, - config->option("bed_custom_texture")->value, - config->option("bed_custom_model")->value); - }); + view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [q](SimpleEvent&) { q->set_bed_shape(); }); // Preview events: preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_QUESTION_MARK, [this](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); }); - preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) - { - set_bed_shape(config->option("bed_shape")->values, - config->option("bed_custom_texture")->value, - config->option("bed_custom_model")->value); - }); + preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [q](SimpleEvent&) { q->set_bed_shape(); }); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); }); #if ENABLE_GCODE_VIEWER preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_MOVE_LAYERS_SLIDER, [this](wxKeyEvent& evt) { preview->move_layers_slider(evt); }); @@ -4567,14 +4557,16 @@ void Plater::load_gcode(const wxString& filename) p->get_current_canvas3D()->render(); wxBusyCursor wait; -// wxBusyInfo info(_L("Processing GCode") + "...", get_current_canvas3D()->get_wxglcanvas()); + // process gcode GCodeProcessor processor; // processor.apply_config(config); processor.process_file(filename.ToUTF8().data()); p->gcode_result = std::move(processor.extract_result()); + // show results p->preview->reload_print(false); + p->preview->get_canvas3d()->zoom_to_gcode(); } #endif // ENABLE_GCODE_VIEWER_AS_STATE @@ -5318,9 +5310,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config) } if (bed_shape_changed) - p->set_bed_shape(p->config->option("bed_shape")->values, - p->config->option("bed_custom_texture")->value, - p->config->option("bed_custom_model")->value); + set_bed_shape(); if (update_scheduled) update(); @@ -5331,11 +5321,24 @@ void Plater::on_config_change(const DynamicPrintConfig &config) void Plater::set_bed_shape() const { - p->set_bed_shape(p->config->option("bed_shape")->values, +#if ENABLE_GCODE_VIEWER_AS_STATE + set_bed_shape(p->config->option("bed_shape")->values, + p->config->option("bed_custom_texture")->value, + p->config->option("bed_custom_model")->value); +#else + p->set_bed_shape(p->config->option("bed_shape")->values, p->config->option("bed_custom_texture")->value, p->config->option("bed_custom_model")->value); +#endif // ENABLE_GCODE_VIEWER_AS_STATE } +#if ENABLE_GCODE_VIEWER_AS_STATE +void Plater::set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model) const +{ + p->set_bed_shape(shape, custom_texture, custom_model); +} +#endif // ENABLE_GCODE_VIEWER_AS_STATE + void Plater::force_filament_colors_update() { bool update_scheduled = false; diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index fdead2a1c..9759a7ffc 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -360,6 +360,9 @@ public: Mouse3DController& get_mouse3d_controller(); void set_bed_shape() const; +#if ENABLE_GCODE_VIEWER_AS_STATE + void set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model) const; +#endif // ENABLE_GCODE_VIEWER_AS_STATE // ROII wrapper for suppressing the Undo / Redo snapshot to be taken. class SuppressSnapshots