support custom bed texture and model

#83
#685
#695
This commit is contained in:
SoftFever 2023-04-15 01:37:34 +08:00
parent 9671cdfc68
commit 7f12c18a4a
7 changed files with 36 additions and 20 deletions

View file

@ -1308,7 +1308,7 @@ void ConfigBase::save_to_json(const std::string &file, const std::string &name,
{ {
const ConfigOption* opt = this->option(opt_key); const ConfigOption* opt = this->option(opt_key);
if ( opt->is_scalar() ) { 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 //keep \n, \r, \t
j[opt_key] = (dynamic_cast<const ConfigOptionString *>(opt))->value; j[opt_key] = (dynamic_cast<const ConfigOptionString *>(opt))->value;
else else

View file

@ -169,12 +169,12 @@ void BedShapeDialog::on_dpi_changed(const wxRect &suggested_rect)
const std::string BedShapePanel::NONE = "None"; const std::string BedShapePanel::NONE = "None";
const std::string BedShapePanel::EMPTY_STRING = ""; 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); wxGetApp().UpdateDarkUI(this);
m_shape = default_pt.values; m_shape = default_pt.values;
m_custom_texture = custom_texture.value.empty() ? NONE : custom_texture.value; m_custom_texture = custom_texture.empty() ? NONE : custom_texture;
m_custom_model = custom_model.value.empty() ? NONE : custom_model.value; m_custom_model = custom_model.empty() ? NONE : custom_model;
auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Shape")); auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Shape"));
sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font()); sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font());

View file

@ -63,7 +63,7 @@ class BedShapePanel : public wxPanel
public: public:
BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY), m_custom_texture(NONE), m_custom_model(NONE) {} 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. // Returns the resulting bed shape polygon. This value will be stored to the ini file.
const std::vector<Vec2d>& get_shape() const { return m_shape; } const std::vector<Vec2d>& get_shape() const { return m_shape; }

View file

@ -652,7 +652,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config,
if (opt_key == "extruders_count") { if (opt_key == "extruders_count") {
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("nozzle_diameter")); auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("nozzle_diameter"));
value = int(nozzle_diameter->values.size()); value = int(nozzle_diameter->values.size());
} }
#if 0 #if 0
// BBS // BBS
else if (opt_key == "bed_temperature" || opt_key == "bed_temperature_initial_layer") { 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 #endif
else if (m_opt_map.find(opt_key) == m_opt_map.end() || else if (m_opt_map.find(opt_key) == m_opt_map.end() ||
// This option don't have corresponded field // This option don't have corresponded field
opt_key == "printable_area" || opt_key == "printable_area" || opt_key == "compatible_printers" || opt_key == "compatible_prints" ||
opt_key == "compatible_printers" || opt_key == "compatible_prints" || opt_key == "thumbnails" ) { opt_key == "thumbnails" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") {
value = get_config_value(config, opt_key); value = get_config_value(config, opt_key);
this->change_opt_value(opt_key, value); this->change_opt_value(opt_key, value);
return; return;
} } else {
else auto opt_id = m_opt_map.find(opt_key)->first;
{ std::string opt_short_key = m_opt_map.at(opt_id).first;
auto opt_id = m_opt_map.find(opt_key)->first; int opt_index = m_opt_map.at(opt_id).second;
std::string opt_short_key = m_opt_map.at(opt_id).first; value = get_config_value(config, opt_short_key, opt_index);
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 // BBS: restore all pages in preset
if (set_value(opt_key, value)) if (set_value(opt_key, value))

View file

@ -638,6 +638,11 @@ public:
m_height_limit_mode = mode; 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; } int get_curr_plate_index() const { return m_current_plate; }
PartPlate* get_curr_plate() { return m_plate_list[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]; } const PartPlate* get_curr_plate() const { return m_plate_list[m_current_plate]; }

View file

@ -6981,11 +6981,13 @@ void Plater::priv::set_bed_shape(const Pointfs& shape, const Pointfs& exclude_ar
float prev_height_lid, prev_height_rod; float prev_height_lid, prev_height_rod;
partplate_list.get_height_limits(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_lid = config->opt_float("extruder_clearance_height_to_lid");
double height_to_rod = config->opt_float("extruder_clearance_height_to_rod"); 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(); 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 (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();
@ -10581,6 +10583,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
} }
//BBS: add bed_exclude_area //BBS: add bed_exclude_area
else if (opt_key == "printable_area" || opt_key == "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_lid"
|| opt_key == "extruder_clearance_height_to_rod") { || opt_key == "extruder_clearance_height_to_rod") {
bed_shape_changed = true; bed_shape_changed = true;

View file

@ -4860,20 +4860,30 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)
btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e)
{ {
BedShapeDialog dlg(this); BedShapeDialog dlg(this);
dlg.build_dialog(*m_config->option<ConfigOptionPoints>("printable_area"), {}, {}); dlg.build_dialog(*m_config->option<ConfigOptionPoints>("printable_area"),
*m_config->option<ConfigOptionString>("bed_custom_texture"),
*m_config->option<ConfigOptionString>("bed_custom_model"));
if (dlg.ShowModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
const std::vector<Vec2d>& shape = dlg.get_shape(); const std::vector<Vec2d>& 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()) if (!shape.empty())
{ {
load_key_value("printable_area", shape); 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(); update_changed_ui();
} }
on_presets_changed();
} }
})); }));
{ {
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher(); Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
const Search::GroupAndCategory& gc = searcher.get_group_and_category("printable_area"); 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; return sizer;