From 7f12c18a4aafdeceb65c5d4e5e0b8a4bdcf6726e Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sat, 15 Apr 2023 01:37:34 +0800 Subject: [PATCH] support custom bed texture and model #83 #685 #695 --- src/libslic3r/Config.cpp | 2 +- src/slic3r/GUI/BedShapeDialog.cpp | 6 +++--- src/slic3r/GUI/BedShapeDialog.hpp | 2 +- src/slic3r/GUI/OptionsGroup.cpp | 24 +++++++++++------------- src/slic3r/GUI/PartPlate.hpp | 5 +++++ src/slic3r/GUI/Plater.cpp | 5 ++++- src/slic3r/GUI/Tab.cpp | 12 +++++++++++- 7 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 57a60fda06..08f679b5c8 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -1308,7 +1308,7 @@ void ConfigBase::save_to_json(const std::string &file, const std::string &name, { const ConfigOption* opt = this->option(opt_key); if ( opt->is_scalar() ) { - if (opt->type() == coString) + if (opt->type() == coString && (opt_key != "bed_custom_texture" && opt_key != "bed_custom_model")) //keep \n, \r, \t j[opt_key] = (dynamic_cast(opt))->value; else diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index b6863cac34..b784781412 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -169,12 +169,12 @@ void BedShapeDialog::on_dpi_changed(const wxRect &suggested_rect) const std::string BedShapePanel::NONE = "None"; const std::string BedShapePanel::EMPTY_STRING = ""; -void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model) +void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const std::string& custom_texture, const std::string& custom_model) { wxGetApp().UpdateDarkUI(this); m_shape = default_pt.values; - m_custom_texture = custom_texture.value.empty() ? NONE : custom_texture.value; - m_custom_model = custom_model.value.empty() ? NONE : custom_model.value; + m_custom_texture = custom_texture.empty() ? NONE : custom_texture; + m_custom_model = custom_model.empty() ? NONE : custom_model; auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Shape")); sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font()); diff --git a/src/slic3r/GUI/BedShapeDialog.hpp b/src/slic3r/GUI/BedShapeDialog.hpp index 638edd30b6..f41ecf6fdd 100644 --- a/src/slic3r/GUI/BedShapeDialog.hpp +++ b/src/slic3r/GUI/BedShapeDialog.hpp @@ -63,7 +63,7 @@ class BedShapePanel : public wxPanel public: BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY), m_custom_texture(NONE), m_custom_model(NONE) {} - void build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model); + void build_panel(const ConfigOptionPoints& default_pt, const std::string& custom_texture, const std::string& custom_model); // Returns the resulting bed shape polygon. This value will be stored to the ini file. const std::vector& get_shape() const { return m_shape; } diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index d8b8cdb048..b90c7b20df 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -652,7 +652,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, if (opt_key == "extruders_count") { auto *nozzle_diameter = dynamic_cast(config.option("nozzle_diameter")); value = int(nozzle_diameter->values.size()); - } + } #if 0 // BBS else if (opt_key == "bed_temperature" || opt_key == "bed_temperature_initial_layer") { @@ -669,21 +669,19 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, } } #endif - else if (m_opt_map.find(opt_key) == m_opt_map.end() || - // This option don't have corresponded field - opt_key == "printable_area" || - opt_key == "compatible_printers" || opt_key == "compatible_prints" || opt_key == "thumbnails" ) { + else if (m_opt_map.find(opt_key) == m_opt_map.end() || + // This option don't have corresponded field + opt_key == "printable_area" || opt_key == "compatible_printers" || opt_key == "compatible_prints" || + opt_key == "thumbnails" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") { value = get_config_value(config, opt_key); this->change_opt_value(opt_key, value); return; - } - else - { - auto opt_id = m_opt_map.find(opt_key)->first; - std::string opt_short_key = m_opt_map.at(opt_id).first; - int opt_index = m_opt_map.at(opt_id).second; - value = get_config_value(config, opt_short_key, opt_index); - } + } else { + auto opt_id = m_opt_map.find(opt_key)->first; + std::string opt_short_key = m_opt_map.at(opt_id).first; + int opt_index = m_opt_map.at(opt_id).second; + value = get_config_value(config, opt_short_key, opt_index); + } // BBS: restore all pages in preset if (set_value(opt_key, value)) diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index c3d7b7cc13..01c6f6583a 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -638,6 +638,11 @@ public: m_height_limit_mode = mode; } + // SoftFever + const std::string& get_logo_texture_filename() const { + return m_logo_texture_filename; + } + int get_curr_plate_index() const { return m_current_plate; } PartPlate* get_curr_plate() { return m_plate_list[m_current_plate]; } const PartPlate* get_curr_plate() const { return m_plate_list[m_current_plate]; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index cd41b3e714..62f5008c75 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6981,11 +6981,13 @@ void Plater::priv::set_bed_shape(const Pointfs& shape, const Pointfs& exclude_ar float prev_height_lid, prev_height_rod; partplate_list.get_height_limits(prev_height_lid, prev_height_rod); + auto prev_logo = partplate_list.get_logo_texture_filename(); double height_to_lid = config->opt_float("extruder_clearance_height_to_lid"); double height_to_rod = config->opt_float("extruder_clearance_height_to_rod"); + auto custom_bed_texture = config->opt_string("bed_custom_texture"); Pointfs prev_exclude_areas = partplate_list.get_exclude_area(); - new_shape |= (height_to_lid != prev_height_lid) || (height_to_rod != prev_height_rod) || (prev_exclude_areas != exclude_areas); + new_shape |= (height_to_lid != prev_height_lid) || (height_to_rod != prev_height_rod) || (prev_exclude_areas != exclude_areas) || (prev_logo != custom_bed_texture); if (new_shape) { if (view3D) view3D->bed_shape_changed(); if (preview) preview->bed_shape_changed(); @@ -10581,6 +10583,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config) } //BBS: add bed_exclude_area else if (opt_key == "printable_area" || opt_key == "bed_exclude_area" + || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model" || opt_key == "extruder_clearance_height_to_lid" || opt_key == "extruder_clearance_height_to_rod") { bed_shape_changed = true; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index afea7de50a..b0b6924ec3 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -4860,20 +4860,30 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent) btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { BedShapeDialog dlg(this); - dlg.build_dialog(*m_config->option("printable_area"), {}, {}); + dlg.build_dialog(*m_config->option("printable_area"), + *m_config->option("bed_custom_texture"), + *m_config->option("bed_custom_model")); if (dlg.ShowModal() == wxID_OK) { const std::vector& shape = dlg.get_shape(); + const std::string& custom_texture = dlg.get_custom_texture(); + const std::string& custom_model = dlg.get_custom_model(); if (!shape.empty()) { load_key_value("printable_area", shape); + load_key_value("bed_custom_texture", custom_texture); + load_key_value("bed_custom_model", custom_model); update_changed_ui(); } + on_presets_changed(); + } })); { Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher(); const Search::GroupAndCategory& gc = searcher.get_group_and_category("printable_area"); + searcher.add_key("bed_custom_texture", m_type, gc.group, gc.category); + searcher.add_key("bed_custom_model", m_type, gc.group, gc.category); } return sizer;