From b6995d8fb3967771656a086b5e19d5445a74808d Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Mon, 21 Aug 2023 20:29:28 +0800 Subject: [PATCH] NEW: add spiral vase mode in plate config Jira: STUDIO-4127 Change-Id: I3bbcc1a165123ff81129e159ada1e00f23e38c68 --- src/libslic3r/Format/bbs_3mf.cpp | 10 ++++++++ src/slic3r/GUI/PartPlate.cpp | 34 ++++++++++++++++++++++++-- src/slic3r/GUI/PartPlate.hpp | 3 +++ src/slic3r/GUI/PlateSettingsDialog.cpp | 28 ++++++++++++++++++++- src/slic3r/GUI/PlateSettingsDialog.hpp | 19 +++++++++++--- src/slic3r/GUI/Plater.cpp | 12 +++++++++ 6 files changed, 100 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index b329a94d2..d7aeb7da6 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -271,6 +271,7 @@ static constexpr const char* LOCK_ATTR = "locked"; static constexpr const char* BED_TYPE_ATTR = "bed_type"; static constexpr const char* PRINT_SEQUENCE_ATTR = "print_sequence"; static constexpr const char* FIRST_LAYER_PRINT_SEQUENCE_ATTR = "first_layer_print_sequence"; +static constexpr const char* SPIRAL_VASE_MODE = "spiral_mode"; static constexpr const char* GCODE_FILE_ATTR = "gcode_file"; static constexpr const char* THUMBNAIL_FILE_ATTR = "thumbnail_file"; static constexpr const char* TOP_FILE_ATTR = "top_file"; @@ -3876,6 +3877,11 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) }; m_curr_plater->config.set_key_value("first_layer_print_sequence", new ConfigOptionInts(get_vector_from_string(value))); } + else if (key == SPIRAL_VASE_MODE) { + bool spiral_mode = false; + std::istringstream(value) >> std::boolalpha >> spiral_mode; + m_curr_plater->config.set_key_value("spiral_mode", new ConfigOptionBool(spiral_mode)); + } else if (key == GCODE_FILE_ATTR) { m_curr_plater->gcode_file = value; @@ -7089,6 +7095,10 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) stream << "\"/>\n"; } + ConfigOption* spiral_mode_opt = plate_data->config.option("spiral_mode"); + if (spiral_mode_opt) + stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << SPIRAL_VASE_MODE << "\" " << VALUE_ATTR << "=\"" << spiral_mode_opt->getBool() << "\"/>\n"; + if (save_gcode) stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << GCODE_FILE_ATTR << "\" " << VALUE_ATTR << "=\"" << std::boolalpha << xml_escape(plate_data->gcode_file) << "\"/>\n"; if (!plate_data->gcode_file.empty()) { diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index ec73881f8..8feb63216 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -252,6 +252,35 @@ PrintSequence PartPlate::get_real_print_seq() const return curr_plate_seq; } +bool PartPlate::has_spiral_mode_config() const +{ + std::string key = "spiral_mode"; + return m_config.has(key); +} + +bool PartPlate::get_spiral_vase_mode() const +{ + std::string key = "spiral_mode"; + if (m_config.has(key)) { + return m_config.opt_bool(key); + } + else { + DynamicPrintConfig* global_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + if (global_config->has(key)) + return global_config->opt_bool(key); + } + return false; +} + +void PartPlate::set_spiral_vase_mode(bool spiral_mode, bool as_global) +{ + std::string key = "spiral_mode"; + if (as_global) + m_config.erase(key); + else + m_config.set_key_value(key, new ConfigOptionBool(spiral_mode)); +} + bool PartPlate::valid_instance(int obj_id, int instance_id) { if ((obj_id >= 0) && (obj_id < m_model->objects.size())) @@ -937,14 +966,15 @@ void PartPlate::render_icons(bool bottom, bool only_body, int hover_id) render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_texture, m_plate_name_edit_vbo_id); if (m_partplate_list->render_plate_settings) { + bool has_plate_settings = get_bed_type() != BedType::btDefault || get_print_seq() != PrintSequence::ByDefault || !get_first_layer_print_sequence().empty() || has_spiral_mode_config(); if (hover_id == 5) { - if (get_bed_type() == BedType::btDefault && get_print_seq() == PrintSequence::ByDefault && get_first_layer_print_sequence().empty()) + if (!has_plate_settings) render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_hovered_texture, m_plate_settings_vbo_id); else render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_hovered_texture, m_plate_settings_vbo_id); } else { - if (get_bed_type() == BedType::btDefault && get_print_seq() == PrintSequence::ByDefault && get_first_layer_print_sequence().empty()) + if (!has_plate_settings) render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_texture, m_plate_settings_vbo_id); else render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_texture, m_plate_settings_vbo_id); diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index ab5013c64..16b7c0a03 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -237,6 +237,9 @@ public: // @return PrintSequence::{ByLayer,ByObject} PrintSequence get_real_print_seq() const; + bool has_spiral_mode_config() const; + bool get_spiral_vase_mode() const; + void set_spiral_vase_mode(bool spiral_mode, bool as_global); //static const int plate_x_offset = 20; //mm //static const double plate_x_gap = 0.2; diff --git a/src/slic3r/GUI/PlateSettingsDialog.cpp b/src/slic3r/GUI/PlateSettingsDialog.cpp index d0a3d4429..4c2edca14 100644 --- a/src/slic3r/GUI/PlateSettingsDialog.cpp +++ b/src/slic3r/GUI/PlateSettingsDialog.cpp @@ -71,9 +71,20 @@ PlateSettingsDialog::PlateSettingsDialog(wxWindow* parent, wxWindowID id, const } m_drag_canvas = new DragCanvas(this, extruder_colours, order); m_drag_canvas->Hide(); - top_sizer->Add(0, 0, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5)); + top_sizer->Add(0, 0, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(0)); top_sizer->Add(m_drag_canvas, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5)); + m_spiral_mode_choice = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(240), -1), 0, NULL, wxCB_READONLY); + m_spiral_mode_choice->Append(_L("Same as Global")); + m_spiral_mode_choice->Append(_L("Enable")); + m_spiral_mode_choice->Append(_L("Disable")); + m_spiral_mode_choice->SetSelection(0); + wxStaticText* spiral_mode_txt = new wxStaticText(this, wxID_ANY, _L("Spiral Vase")); + spiral_mode_txt->SetFont(Label::Body_14); + top_sizer->Add(spiral_mode_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5)); + top_sizer->Add(m_spiral_mode_choice, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, FromDIP(5)); + + m_sizer_main->Add(top_sizer, 0, wxEXPAND | wxALL, FromDIP(30)); auto sizer_button = new wxBoxSizer(wxHORIZONTAL); @@ -166,6 +177,21 @@ void PlateSettingsDialog::sync_first_layer_print_seq(int selection, const std::v } } +void PlateSettingsDialog::sync_spiral_mode(bool spiral_mode, bool as_global) +{ + if (m_spiral_mode_choice) { + if (as_global) { + m_spiral_mode_choice->SetSelection(0); + } + else { + if (spiral_mode) + m_spiral_mode_choice->SetSelection(1); + else + m_spiral_mode_choice->SetSelection(2); + } + } +} + wxString PlateSettingsDialog::to_bed_type_name(BedType bed_type) { switch (bed_type) { case btDefault: diff --git a/src/slic3r/GUI/PlateSettingsDialog.hpp b/src/slic3r/GUI/PlateSettingsDialog.hpp index 724d54bbf..6ce34f48c 100644 --- a/src/slic3r/GUI/PlateSettingsDialog.hpp +++ b/src/slic3r/GUI/PlateSettingsDialog.hpp @@ -33,6 +33,7 @@ public: void sync_bed_type(BedType type); void sync_print_seq(int print_seq = 0); void sync_first_layer_print_seq(int selection, const std::vector& seq = std::vector()); + void sync_spiral_mode(bool spiral_mode, bool as_global); wxString to_bed_type_name(BedType bed_type); wxString to_print_sequence_name(PrintSequence print_seq); void on_dpi_changed(const wxRect& suggested_rect) override; @@ -60,11 +61,23 @@ public: std::vector get_first_layer_print_seq(); + int get_spiral_mode_choice() { + int choice = 0; + if (m_spiral_mode_choice != nullptr) + choice = m_spiral_mode_choice->GetSelection(); + return choice; + }; + + bool get_spiral_mode(){ + return false; + } + protected: - DragCanvas* m_drag_canvas; - ComboBox* m_first_layer_print_seq_choice { nullptr }; - ComboBox* m_print_seq_choice { nullptr }; ComboBox* m_bed_type_choice { nullptr }; + ComboBox* m_print_seq_choice { nullptr }; + ComboBox* m_first_layer_print_seq_choice { nullptr }; + ComboBox* m_spiral_mode_choice { nullptr }; + DragCanvas* m_drag_canvas; Button* m_button_ok; Button* m_button_cancel; }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 21b0caf46..be58cd7d2 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -12327,6 +12327,8 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi else dlg.sync_first_layer_print_seq(1, curr_plate->get_first_layer_print_sequence()); + dlg.sync_spiral_mode(curr_plate->get_spiral_vase_mode(), !curr_plate->has_spiral_mode_config()); + dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index, &dlg](wxCommandEvent& e) { PartPlate *curr_plate = p->partplate_list.get_curr_plate(); BedType old_bed_type = curr_plate->get_bed_type(); @@ -12348,6 +12350,16 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi curr_plate->set_print_seq(PrintSequence(ps_sel - 1)); else curr_plate->set_print_seq(PrintSequence::ByDefault); + + int spiral_sel = dlg.get_spiral_mode_choice(); + if (spiral_sel == 1) { + curr_plate->set_spiral_vase_mode(true, false); + }else if (spiral_sel == 2) { + curr_plate->set_spiral_vase_mode(false, false); + }else { + curr_plate->set_spiral_vase_mode(false, true); + } + update_project_dirty_from_presets(); set_plater_dirty(true); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select print sequence %1% for plate %2% at plate side")%ps_sel %plate_index;