ENABLE_GCODE_VIEWER_AS_STATE -> Use default printbed in gcode viewer

This commit is contained in:
enricoturri1966 2020-06-08 12:27:32 +02:00
parent ca17948f87
commit 70478f226f
6 changed files with 79 additions and 29 deletions

View file

@ -251,6 +251,19 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print&
load_toolpaths(gcode_result); load_toolpaths(gcode_result);
load_shells(print, initialized); 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<std::string>& str_tool_colors) void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std::vector<std::string>& 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) { for (size_t i = 0; i < m_vertices.vertices_count; ++i) {
const GCodeProcessor::MoveVertex& move = gcode_result.moves[i]; const GCodeProcessor::MoveVertex& move = gcode_result.moves[i];
#if ENABLE_GCODE_VIEWER_AS_STATE #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<double>());
else {
#endif // ENABLE_GCODE_VIEWER_AS_STATE #endif // ENABLE_GCODE_VIEWER_AS_STATE
if (move.type == GCodeProcessor::EMoveType::Extrude && move.width != 0.0f && move.height != 0.0f) if (move.type == GCodeProcessor::EMoveType::Extrude && move.width != 0.0f && move.height != 0.0f)
m_bounding_box.merge(move.position.cast<double>()); m_bounding_box.merge(move.position.cast<double>());

View file

@ -1930,6 +1930,13 @@ void GLCanvas3D::zoom_to_selection()
_zoom_to_box(m_selection.get_bounding_box()); _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) void GLCanvas3D::select_view(const std::string& direction)
{ {
wxGetApp().plater()->get_camera().select_view(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) void GLCanvas3D::load_gcode_preview(const GCodeProcessor::Result& gcode_result)
{ {
m_gcode_viewer.load(gcode_result, *this->fff_print(), m_initialized); 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<std::string>& str_tool_colors) void GLCanvas3D::refresh_gcode_preview(const GCodeProcessor::Result& gcode_result, const std::vector<std::string>& str_tool_colors)
@ -5351,8 +5361,7 @@ static BoundingBoxf3 print_volume(const DynamicPrintConfig& config)
BoundingBoxf3 ret; BoundingBoxf3 ret;
const ConfigOptionPoints* opt = dynamic_cast<const ConfigOptionPoints*>(config.option("bed_shape")); const ConfigOptionPoints* opt = dynamic_cast<const ConfigOptionPoints*>(config.option("bed_shape"));
if (opt != nullptr) if (opt != nullptr) {
{
BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values));
ret = BoundingBoxf3(Vec3d(unscale<double>(bed_box_2D.min(0)) - tolerance_x, unscale<double>(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale<double>(bed_box_2D.max(0)) + tolerance_x, unscale<double>(bed_box_2D.max(1)) + tolerance_y, config.opt_float("max_print_height"))); ret = BoundingBoxf3(Vec3d(unscale<double>(bed_box_2D.min(0)) - tolerance_x, unscale<double>(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale<double>(bed_box_2D.max(0)) + tolerance_x, unscale<double>(bed_box_2D.max(1)) + tolerance_y, config.opt_float("max_print_height")));
// Allow the objects to protrude below the print bed // 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 void GLCanvas3D::_render_background() const
{ {
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
bool use_error_color = m_dynamic_background_enabled; #if ENABLE_GCODE_VIEWER_AS_STATE
if (!m_volumes.empty()) bool use_error_color = false;
use_error_color &= _is_any_volume_outside(); if (wxGetApp().mainframe->get_mode() != MainFrame::EMode::GCodeViewer) {
else use_error_color = m_dynamic_background_enabled;
{ #else
BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); bool use_error_color = m_dynamic_background_enabled;
use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_bounding_box()) : false; #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 #endif // ENABLE_GCODE_VIEWER
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());

View file

@ -624,6 +624,9 @@ public:
void zoom_to_bed(); void zoom_to_bed();
void zoom_to_volumes(); void zoom_to_volumes();
void zoom_to_selection(); 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 select_view(const std::string& direction);
void update_volumes_colors_by_extruder(); void update_volumes_colors_by_extruder();

View file

@ -1162,10 +1162,14 @@ void MainFrame::set_mode(EMode mode)
case EMode::Editor: case EMode::Editor:
{ {
m_plater->reset(); m_plater->reset();
// m_plater->reset_last_loaded_gcode();
// switch view // switch view
m_plater->select_view_3D("3D"); m_plater->select_view_3D("3D");
m_plater->select_view("iso");
// switch printbed
m_plater->set_bed_shape();
// switch menubar // switch menubar
SetMenuBar(m_editor_menubar); SetMenuBar(m_editor_menubar);
@ -1196,6 +1200,11 @@ void MainFrame::set_mode(EMode mode)
// switch view // switch view
m_plater->select_view_3D("Preview"); 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 // switch menubar
SetMenuBar(m_gcodeviewer_menubar); SetMenuBar(m_gcodeviewer_menubar);

View file

@ -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_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_SPLIT_VOLUMES, &priv::on_action_split_volumes, this);
view3D_canvas->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this); view3D_canvas->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this);
view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [q](SimpleEvent&) { q->set_bed_shape(); });
{
set_bed_shape(config->option<ConfigOptionPoints>("bed_shape")->values,
config->option<ConfigOptionString>("bed_custom_texture")->value,
config->option<ConfigOptionString>("bed_custom_model")->value);
});
// Preview events: // Preview events:
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_QUESTION_MARK, [this](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); }); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_QUESTION_MARK, [this](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); });
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [q](SimpleEvent&) { q->set_bed_shape(); });
{
set_bed_shape(config->option<ConfigOptionPoints>("bed_shape")->values,
config->option<ConfigOptionString>("bed_custom_texture")->value,
config->option<ConfigOptionString>("bed_custom_model")->value);
});
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); }); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); });
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_MOVE_LAYERS_SLIDER, [this](wxKeyEvent& evt) { preview->move_layers_slider(evt); }); 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(); p->get_current_canvas3D()->render();
wxBusyCursor wait; wxBusyCursor wait;
// wxBusyInfo info(_L("Processing GCode") + "...", get_current_canvas3D()->get_wxglcanvas());
// process gcode
GCodeProcessor processor; GCodeProcessor processor;
// processor.apply_config(config); // processor.apply_config(config);
processor.process_file(filename.ToUTF8().data()); processor.process_file(filename.ToUTF8().data());
p->gcode_result = std::move(processor.extract_result()); p->gcode_result = std::move(processor.extract_result());
// show results
p->preview->reload_print(false); p->preview->reload_print(false);
p->preview->get_canvas3d()->zoom_to_gcode();
} }
#endif // ENABLE_GCODE_VIEWER_AS_STATE #endif // ENABLE_GCODE_VIEWER_AS_STATE
@ -5318,9 +5310,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
} }
if (bed_shape_changed) if (bed_shape_changed)
p->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values, set_bed_shape();
p->config->option<ConfigOptionString>("bed_custom_texture")->value,
p->config->option<ConfigOptionString>("bed_custom_model")->value);
if (update_scheduled) if (update_scheduled)
update(); update();
@ -5331,11 +5321,24 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
void Plater::set_bed_shape() const void Plater::set_bed_shape() const
{ {
p->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values, #if ENABLE_GCODE_VIEWER_AS_STATE
set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values,
p->config->option<ConfigOptionString>("bed_custom_texture")->value,
p->config->option<ConfigOptionString>("bed_custom_model")->value);
#else
p->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values,
p->config->option<ConfigOptionString>("bed_custom_texture")->value, p->config->option<ConfigOptionString>("bed_custom_texture")->value,
p->config->option<ConfigOptionString>("bed_custom_model")->value); p->config->option<ConfigOptionString>("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() void Plater::force_filament_colors_update()
{ {
bool update_scheduled = false; bool update_scheduled = false;

View file

@ -360,6 +360,9 @@ public:
Mouse3DController& get_mouse3d_controller(); Mouse3DController& get_mouse3d_controller();
void set_bed_shape() const; 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. // ROII wrapper for suppressing the Undo / Redo snapshot to be taken.
class SuppressSnapshots class SuppressSnapshots