From 2910014887b47d144431a966d37179a22eb3385e Mon Sep 17 00:00:00 2001 From: Stone Li Date: Wed, 14 Jun 2023 15:38:38 +0800 Subject: [PATCH] NEW: render cali lines for X1 series printer Change-Id: I0edbe9cac3be837702e0b03d66766291b012b4b8 Signed-off-by: Stone Li --- resources/images/bbl_cali_lines.svg | 24 +++++++++ src/libslic3r/Preset.cpp | 9 ++++ src/libslic3r/Preset.hpp | 1 + src/slic3r/GUI/GLCanvas3D.cpp | 6 +-- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- src/slic3r/GUI/PartPlate.cpp | 75 ++++++++++++++++++++++++++--- src/slic3r/GUI/PartPlate.hpp | 14 ++++-- src/slic3r/GUI/Tab.cpp | 11 ++++- 8 files changed, 125 insertions(+), 17 deletions(-) create mode 100644 resources/images/bbl_cali_lines.svg diff --git a/resources/images/bbl_cali_lines.svg b/resources/images/bbl_cali_lines.svg new file mode 100644 index 000000000..fe8248a73 --- /dev/null +++ b/resources/images/bbl_cali_lines.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 6eddf4ad2..1621c42a6 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -704,6 +704,15 @@ bool Preset::is_bbl_vendor_preset(PresetBundle *preset_bundle) return is_bbl_vendor_preset; } +bool Preset::has_cali_lines(PresetBundle* preset_bundle) +{ + std::string model_id = this->get_printer_type(preset_bundle); + if (model_id == "BL-P001" || model_id == "BL-P002") { + return true; + } + return false; +} + static std::vector s_Preset_print_options { "layer_height", "initial_layer_print_height", "wall_loops", "slice_closing_radius", "spiral_mode", "slicing_mode", "top_shell_layers", "top_shell_thickness", "bottom_shell_layers", "bottom_shell_thickness", diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index c509dd8da..26f4d2f65 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -303,6 +303,7 @@ public: bool is_custom_defined(); bool is_bbl_vendor_preset(PresetBundle *preset_bundle); + bool has_cali_lines(PresetBundle* preset_bundle); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b356bffba..86bce64de 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1891,7 +1891,7 @@ void GLCanvas3D::render(bool only_init) if (!no_partplate) _render_bed(!camera.is_looking_downward(), show_axes); if (!no_partplate) //BBS: add outline logic - _render_platelist(!camera.is_looking_downward(), only_current, only_body, hover_id); + _render_platelist(!camera.is_looking_downward(), only_current, only_body, hover_id, true); _render_objects(GLVolumeCollection::ERenderType::Transparent, !m_gizmos.is_running()); } /* preview render */ @@ -6677,9 +6677,9 @@ void GLCanvas3D::_render_bed_for_picking(bool bottom) //m_bed.render_for_picking(*this, bottom, scale_factor); } -void GLCanvas3D::_render_platelist(bool bottom, bool only_current, bool only_body, int hover_id) const +void GLCanvas3D::_render_platelist(bool bottom, bool only_current, bool only_body, int hover_id, bool render_cali) const { - wxGetApp().plater()->get_partplate_list().render(bottom, only_current, only_body, hover_id); + wxGetApp().plater()->get_partplate_list().render(bottom, only_current, only_body, hover_id, render_cali); } void GLCanvas3D::_render_plates_for_picking() const diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index d6304eae2..856c24ed4 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -1106,7 +1106,7 @@ private: void _render_bed(bool bottom, bool show_axes); void _render_bed_for_picking(bool bottom); //BBS: add part plate related logic - void _render_platelist(bool bottom, bool only_current, bool only_body = false, int hover_id = -1) const; + void _render_platelist(bool bottom, bool only_current, bool only_body = false, int hover_id = -1, bool render_cali = false) const; void _render_plates_for_picking() const; //BBS: add outline drawing logic void _render_objects(GLVolumeCollection::ERenderType type, bool with_outline = true); diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 69c0c7f74..691b23402 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -557,7 +557,7 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffe } } -void PartPlate::render_logo(bool bottom) const +void PartPlate::render_logo(bool bottom, bool render_cali) const { if (!m_partplate_list->render_bedtype_logo) { // render third-party printer texture logo @@ -636,6 +636,7 @@ void PartPlate::render_logo(bool bottom) const } m_partplate_list->load_bedtype_textures(); + m_partplate_list->load_cali_textures(); // btDefault should be skipped auto curr_bed_type = get_bed_type(); @@ -645,6 +646,7 @@ void PartPlate::render_logo(bool bottom) const curr_bed_type = proj_cfg.opt_enum(std::string("curr_bed_type")); } int bed_type_idx = (int)curr_bed_type; + // render bed textures for (auto &part : m_partplate_list->bed_texture_info[bed_type_idx].parts) { if (part.texture) { if (part.buffer && part.buffer->get_vertices_count() > 0 @@ -661,6 +663,24 @@ void PartPlate::render_logo(bool bottom) const } } } + + // render cali texture + if (render_cali) { + for (auto& part : m_partplate_list->cali_texture_info.parts) { + if (part.texture) { + if (part.buffer && part.buffer->get_vertices_count() > 0) { + if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) { + part.offset = Vec2d(m_origin.x(), m_origin.y()); + part.update_buffer(); + } + render_logo_texture(*(part.texture), + *(part.buffer), + bottom, + part.vbo_id); + } + } + } + } } void PartPlate::render_exclude_area(bool force_default_color) const { @@ -2301,7 +2321,7 @@ bool PartPlate::intersects(const BoundingBoxf3& bb) const return print_volume.intersects(bb); } -void PartPlate::render(bool bottom, bool only_body, bool force_background_color, HeightLimitMode mode, int hover_id) +void PartPlate::render(bool bottom, bool only_body, bool force_background_color, HeightLimitMode mode, int hover_id, bool render_cali) { glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_BLEND)); @@ -2318,7 +2338,10 @@ void PartPlate::render(bool bottom, bool only_body, bool force_background_color, render_grid(bottom); if (!bottom && m_selected && !force_background_color) { - render_logo(bottom); + if (m_partplate_list) + render_logo(bottom, m_partplate_list->render_cali_logo && render_cali); + else + render_logo(bottom); } render_height_limit(mode); @@ -2860,6 +2883,7 @@ void PartPlateList::release_icon_textures() } //reset PartPlateList::is_load_bedtype_textures = false; + PartPlateList::is_load_cali_texture = false; for (int i = 0; i < btCount; i++) { for (auto& part: bed_texture_info[i].parts) { if (part.texture) { @@ -4124,7 +4148,7 @@ void PartPlateList::postprocess_arrange_polygon(arrangement::ArrangePolygon& arr /*rendering related functions*/ //render -void PartPlateList::render(bool bottom, bool only_current, bool only_body, int hover_id) +void PartPlateList::render(bool bottom, bool only_current, bool only_body, int hover_id, bool render_cali) { const std::lock_guard local_lock(m_plates_mutex); std::vector::iterator it = m_plate_list.begin(); @@ -4149,15 +4173,15 @@ void PartPlateList::render(bool bottom, bool only_current, bool only_body, int h if (current_index == m_current_plate) { PartPlate::HeightLimitMode height_mode = (only_current)?PartPlate::HEIGHT_LIMIT_NONE:m_height_limit_mode; if (plate_hover_index == current_index) - (*it)->render(bottom, only_body, false, height_mode, plate_hover_action); + (*it)->render(bottom, only_body, false, height_mode, plate_hover_action, render_cali); else - (*it)->render(bottom, only_body, false, height_mode, -1); + (*it)->render(bottom, only_body, false, height_mode, -1, render_cali); } else { if (plate_hover_index == current_index) - (*it)->render(bottom, only_body, false, PartPlate::HEIGHT_LIMIT_NONE, plate_hover_action); + (*it)->render(bottom, only_body, false, PartPlate::HEIGHT_LIMIT_NONE, plate_hover_action, render_cali); else - (*it)->render(bottom, only_body, false, PartPlate::HEIGHT_LIMIT_NONE, -1); + (*it)->render(bottom, only_body, false, PartPlate::HEIGHT_LIMIT_NONE, -1, render_cali); } } } @@ -4747,6 +4771,7 @@ void PartPlateList::print() const } bool PartPlateList::is_load_bedtype_textures = false; +bool PartPlateList::is_load_cali_texture = false; void PartPlateList::BedTextureInfo::TexturePart::update_buffer() { @@ -4837,5 +4862,39 @@ void PartPlateList::load_bedtype_textures() PartPlateList::is_load_bedtype_textures = true; } +void PartPlateList::init_cali_texture_info() +{ + BedTextureInfo::TexturePart cali_line(1, -3, 256, 70, "bbl_cali_lines.svg"); + cali_texture_info.parts.push_back(cali_line); + + for (int j = 0; j < cali_texture_info.parts.size(); j++) { + cali_texture_info.parts[j].update_buffer(); + } +} + +void PartPlateList::load_cali_textures() +{ + if (PartPlateList::is_load_cali_texture) return; + + init_cali_texture_info(); + GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size(); + GLint logo_tex_size = (max_tex_size < 2048) ? max_tex_size : 2048; + for (int i = 0; i < (unsigned int)btCount; ++i) { + for (int j = 0; j < cali_texture_info.parts.size(); j++) { + std::string filename = resources_dir() + "/images/" + cali_texture_info.parts[j].filename; + if (boost::filesystem::exists(filename)) { + PartPlateList::cali_texture_info.parts[j].texture = new GLTexture(); + if (!PartPlateList::cali_texture_info.parts[j].texture->load_from_svg_file(filename, true, true, true, logo_tex_size)) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": load cali texture from %1% failed!") % filename; + } + } + else { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": load cali texture from %1% failed!") % filename; + } + } + } + PartPlateList::is_load_cali_texture = true; +} + }//end namespace GUI }//end namespace slic3r diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index db8cbfaf0..a131eff70 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -170,7 +170,7 @@ private: void calc_vertex_for_icons(int index, GeometryBuffer &buffer); void calc_vertex_for_icons_background(int icon_count, GeometryBuffer &buffer); void render_background(bool force_default_color = false) const; - void render_logo(bool bottom) const; + void render_logo(bool bottom, bool render_cali = true) const; void render_logo_texture(GLTexture& logo_texture, const GeometryBuffer& logo_buffer, bool bottom, unsigned int vbo_id) const; void render_exclude_area(bool force_default_color) const; //void render_background_for_picking(const float* render_color) const; @@ -338,7 +338,7 @@ public: bool contains(const BoundingBoxf3& bb) const; bool intersects(const BoundingBoxf3& bb) const; - void render(bool bottom, bool only_body = false, bool force_background_color = false, HeightLimitMode mode = HEIGHT_LIMIT_NONE, int hover_id = -1); + void render(bool bottom, bool only_body = false, bool force_background_color = false, HeightLimitMode mode = HEIGHT_LIMIT_NONE, int hover_id = -1, bool render_cali = false); void render_for_picking() const { on_render_for_picking(); } void set_selected(); void set_unselected(); @@ -522,6 +522,7 @@ class PartPlateList : public ObjectBase // set render option bool render_bedtype_logo = true; bool render_plate_settings = true; + bool render_cali_logo = true; bool m_is_dark = false; @@ -585,6 +586,7 @@ public: static const unsigned int MAX_PLATES_COUNT = MAX_PLATE_COUNT; static GLTexture bed_textures[(unsigned int)btCount]; static bool is_load_bedtype_textures; + static bool is_load_cali_texture; PartPlateList(int width, int depth, int height, Plater* platerObj, Model* modelObj, PrinterTechnology tech = ptFFF); PartPlateList(Plater* platerObj, Model* modelObj, PrinterTechnology tech = ptFFF); @@ -725,9 +727,10 @@ public: /*rendering related functions*/ void on_change_color_mode(bool is_dark) { m_is_dark = is_dark; } - void render(bool bottom, bool only_current = false, bool only_body = false, int hover_id = -1); + void render(bool bottom, bool only_current = false, bool only_body = false, int hover_id = -1, bool render_cali = false); void render_for_picking_pass(); void set_render_option(bool bedtype_texture, bool plate_settings); + void set_render_cali(bool value = true) { render_cali_logo = value; } BoundingBoxf3& get_bounding_box() { return m_bounding_box; } //int select_plate_by_hover_id(int hover_id); int select_plate_by_obj(int obj_index, int instance_index); @@ -785,7 +788,12 @@ public: void init_bed_type_info(); void load_bedtype_textures(); + void show_cali_texture(bool show = true); + void init_cali_texture_info(); + void load_cali_textures(); + BedTextureInfo bed_texture_info[btCount]; + BedTextureInfo cali_texture_info; }; } // namespace GUI diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 3d480d42d..43a41ad75 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1643,10 +1643,17 @@ void Tab::on_presets_changed() wxGetApp().plater()->sidebar().update_presets(m_type); bool is_bbl_vendor_preset = wxGetApp().preset_bundle->printers.get_edited_preset().is_bbl_vendor_preset(wxGetApp().preset_bundle); - if (is_bbl_vendor_preset) + if (is_bbl_vendor_preset) { wxGetApp().plater()->get_partplate_list().set_render_option(true, true); - else + if (wxGetApp().preset_bundle->printers.get_edited_preset().has_cali_lines(wxGetApp().preset_bundle)) { + wxGetApp().plater()->get_partplate_list().set_render_cali(true); + } else { + wxGetApp().plater()->get_partplate_list().set_render_cali(false); + } + } else { wxGetApp().plater()->get_partplate_list().set_render_option(false, false); + wxGetApp().plater()->get_partplate_list().set_render_cali(false); + } // Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors. for (auto t: m_dependent_tabs)