Follow-up of 9d4344a78ce56ecf722e946f2c1796a9e1df96e8 -> ensure printbed always rendered as custom in gcode preview mode

This commit is contained in:
enricoturri1966 2020-07-29 14:20:01 +02:00
parent 54a4340631
commit 0348986bda
7 changed files with 33 additions and 30 deletions

View File

@ -694,7 +694,6 @@ bool GCodeProcessor::process_producers_tags(const std::string& comment)
bool GCodeProcessor::process_prusaslicer_tags(const std::string& comment) bool GCodeProcessor::process_prusaslicer_tags(const std::string& comment)
{ {
std::cout << comment << "\n";
return false; return false;
} }

View File

@ -255,7 +255,7 @@ Bed3D::Bed3D()
{ {
} }
bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model) bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom)
{ {
auto check_texture = [](const std::string& texture) { auto check_texture = [](const std::string& texture) {
return !texture.empty() && (boost::algorithm::iends_with(texture, ".png") || boost::algorithm::iends_with(texture, ".svg")) && boost::filesystem::exists(texture); return !texture.empty() && (boost::algorithm::iends_with(texture, ".png") || boost::algorithm::iends_with(texture, ".svg")) && boost::filesystem::exists(texture);
@ -265,30 +265,39 @@ bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, c
return !model.empty() && boost::algorithm::iends_with(model, ".stl") && boost::filesystem::exists(model); return !model.empty() && boost::algorithm::iends_with(model, ".stl") && boost::filesystem::exists(model);
}; };
auto [new_type, system_model, system_texture] = detect_type(shape); EType type;
std::string model;
std::string texture;
if (force_as_custom)
type = Custom;
else {
auto [new_type, system_model, system_texture] = detect_type(shape);
type = new_type;
model = system_model;
texture = system_texture;
}
std::string texture_filename = custom_texture.empty() ? system_texture : custom_texture; std::string texture_filename = custom_texture.empty() ? texture : custom_texture;
if (!check_texture(texture_filename)) if (!check_texture(texture_filename))
texture_filename.clear(); texture_filename.clear();
std::string model_filename = custom_model.empty() ? system_model : custom_model; std::string model_filename = custom_model.empty() ? model : custom_model;
if (!check_model(model_filename)) if (!check_model(model_filename))
model_filename.clear(); model_filename.clear();
if ((m_shape == shape) && (m_type == new_type) && (m_texture_filename == texture_filename) && (m_model_filename == model_filename)) if (m_shape == shape && m_type == type && m_texture_filename == texture_filename && m_model_filename == model_filename)
// No change, no need to update the UI. // No change, no need to update the UI.
return false; return false;
m_shape = shape; m_shape = shape;
m_texture_filename = texture_filename; m_texture_filename = texture_filename;
m_model_filename = model_filename; m_model_filename = model_filename;
m_type = new_type; m_type = type;
calc_bounding_boxes(); calc_bounding_boxes();
ExPolygon poly; ExPolygon poly;
for (const Vec2d& p : m_shape) for (const Vec2d& p : m_shape) {
{
poly.contour.append(Point(scale_(p(0)), scale_(p(1)))); poly.contour.append(Point(scale_(p(0)), scale_(p(1))));
} }
@ -435,19 +444,15 @@ static std::string system_print_bed_texture(const Preset &preset)
std::tuple<Bed3D::EType, std::string, std::string> Bed3D::detect_type(const Pointfs& shape) const std::tuple<Bed3D::EType, std::string, std::string> Bed3D::detect_type(const Pointfs& shape) const
{ {
auto bundle = wxGetApp().preset_bundle; auto bundle = wxGetApp().preset_bundle;
if (bundle != nullptr) if (bundle != nullptr) {
{
const Preset* curr = &bundle->printers.get_selected_preset(); const Preset* curr = &bundle->printers.get_selected_preset();
while (curr != nullptr) while (curr != nullptr) {
{ if (curr->config.has("bed_shape")) {
if (curr->config.has("bed_shape")) if (shape == dynamic_cast<const ConfigOptionPoints*>(curr->config.option("bed_shape"))->values) {
{
if (shape == dynamic_cast<const ConfigOptionPoints*>(curr->config.option("bed_shape"))->values)
{
std::string model_filename = system_print_bed_model(*curr); std::string model_filename = system_print_bed_model(*curr);
std::string texture_filename = system_print_bed_texture(*curr); std::string texture_filename = system_print_bed_texture(*curr);
if (!model_filename.empty() && !texture_filename.empty()) if (!model_filename.empty() && !texture_filename.empty())
return std::make_tuple(System, model_filename, texture_filename); return { System, model_filename, texture_filename };
} }
} }
@ -455,7 +460,7 @@ std::tuple<Bed3D::EType, std::string, std::string> Bed3D::detect_type(const Poin
} }
} }
return std::make_tuple(Custom, "", ""); return { Custom, "", "" };
} }
void Bed3D::render_axes() const void Bed3D::render_axes() const

View File

@ -144,7 +144,7 @@ public:
const Pointfs& get_shape() const { return m_shape; } const Pointfs& get_shape() const { return m_shape; }
// Return true if the bed shape changed, so the calee will update the UI. // Return true if the bed shape changed, so the calee will update the UI.
bool set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model); bool set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false);
const BoundingBoxf3& get_bounding_box(bool extended) const { const BoundingBoxf3& get_bounding_box(bool extended) const {
return extended ? m_extended_bounding_box : m_bounding_box; return extended ? m_extended_bounding_box : m_bounding_box;

View File

@ -337,7 +337,7 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print&
{ max(0), max(1) }, { max(0), max(1) },
{ min(0), max(1) } }; { min(0), max(1) } };
} }
wxGetApp().plater()->set_bed_shape(bed_shape, "", ""); wxGetApp().plater()->set_bed_shape(bed_shape, "", "", true);
} }
#endif // ENABLE_GCODE_VIEWER_AS_STATE #endif // ENABLE_GCODE_VIEWER_AS_STATE
} }

View File

@ -1490,7 +1490,7 @@ void MainFrame::set_mode(EMode mode)
m_plater->select_view("iso"); m_plater->select_view("iso");
// switch printbed // switch printbed
m_plater->set_bed_shape({ { 0.0, 0.0 }, { 200.0, 0.0 }, { 200.0, 200.0 }, { 0.0, 200.0 } }, "", ""); m_plater->set_bed_shape({ { 0.0, 0.0 }, { 200.0, 0.0 }, { 200.0, 200.0 }, { 0.0, 200.0 } }, "", "", true);
// switch menubar // switch menubar
SetMenuBar(m_gcodeviewer_menubar); SetMenuBar(m_gcodeviewer_menubar);

View File

@ -1867,7 +1867,7 @@ struct Plater::priv
// triangulate the bed and store the triangles into m_bed.m_triangles, // triangulate the bed and store the triangles into m_bed.m_triangles,
// fills the m_bed.m_grid_lines and sets m_bed.m_origin. // fills the m_bed.m_grid_lines and sets m_bed.m_origin.
// Sets m_bed.m_polygon to limit the object placement. // Sets m_bed.m_polygon to limit the object placement.
void set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model); void set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false);
bool can_delete() const; bool can_delete() const;
bool can_delete_all() const; bool can_delete_all() const;
@ -4182,11 +4182,10 @@ bool Plater::priv::can_reload_from_disk() const
return !paths.empty(); return !paths.empty();
} }
void Plater::priv::set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model) void Plater::priv::set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom)
{ {
bool new_shape = bed.set_shape(shape, custom_texture, custom_model); bool new_shape = bed.set_shape(shape, custom_texture, custom_model, force_as_custom);
if (new_shape) if (new_shape) {
{
if (view3D) view3D->bed_shape_changed(); if (view3D) view3D->bed_shape_changed();
if (preview) preview->bed_shape_changed(); if (preview) preview->bed_shape_changed();
} }
@ -5456,9 +5455,9 @@ void Plater::set_bed_shape() const
} }
#if 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 void Plater::set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom) const
{ {
p->set_bed_shape(shape, custom_texture, custom_model); p->set_bed_shape(shape, custom_texture, custom_model, force_as_custom);
} }
#endif // ENABLE_GCODE_VIEWER_AS_STATE #endif // ENABLE_GCODE_VIEWER_AS_STATE

View File

@ -363,7 +363,7 @@ public:
void set_bed_shape() const; void set_bed_shape() const;
#if ENABLE_GCODE_VIEWER_AS_STATE #if ENABLE_GCODE_VIEWER_AS_STATE
void set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model) const; void set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false) const;
#endif // ENABLE_GCODE_VIEWER_AS_STATE #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.