Merge remote-tracking branch 'origin/ys_preset_edit_buttons' into ys_comboboxes

This commit is contained in:
YuSanka 2019-03-20 10:33:50 +01:00
commit b36e4fa512
7 changed files with 78 additions and 20 deletions

View File

@ -746,6 +746,13 @@ wxNotebook* GUI_App::tab_panel() const
return mainframe->m_tabpanel; return mainframe->m_tabpanel;
} }
int GUI_App::extruders_cnt() const
{
const Preset& preset = preset_bundle->printers.get_selected_preset();
return preset.printer_technology() == ptSLA ? 1 :
preset.config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
}
void GUI_App::window_pos_save(wxTopLevelWindow* window, const std::string &name) void GUI_App::window_pos_save(wxTopLevelWindow* window, const std::string &name)
{ {
if (name.empty()) { return; } if (name.empty()) { return; }

View File

@ -160,6 +160,7 @@ public:
Plater* plater_{ nullptr }; Plater* plater_{ nullptr };
wxNotebook* tab_panel() const ; wxNotebook* tab_panel() const ;
int extruders_cnt() const;
std::vector<Tab *> tabs_list; std::vector<Tab *> tabs_list;

View File

@ -51,8 +51,7 @@ static DynamicPrintConfig& printer_config()
static int extruders_count() static int extruders_count()
{ {
return printer_technology() == ptSLA ? 1 : return wxGetApp().extruders_cnt();
printer_config().option<ConfigOptionFloats>("nozzle_diameter")->values.size();
} }
ObjectList::ObjectList(wxWindow* parent) : ObjectList::ObjectList(wxWindow* parent) :

View File

@ -275,9 +275,45 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 *
dialog->Destroy(); dialog->Destroy();
}); });
} }
edit_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
#ifdef __WINDOWS__
edit_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif
edit_btn->SetBitmap(create_scaled_bitmap("cog.png"));
edit_btn->SetToolTip(_(L("Click to edit preset")));
edit_btn->Bind(wxEVT_BUTTON, ([preset_type, this](wxCommandEvent)
{
Tab* tab = wxGetApp().get_tab(preset_type);
if (!tab)
return;
int page_id = wxGetApp().tab_panel()->FindPage(tab);
if (page_id == wxNOT_FOUND)
return;
wxGetApp().tab_panel()->ChangeSelection(page_id);
/* In a case of a multi-material printing, for editing another Filament Preset
* it's needed to select this preset for the "Filament settings" Tab
*/
if (preset_type == Preset::TYPE_FILAMENT && wxGetApp().extruders_cnt() > 1)
{
const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data();
// Call select_preset() only if there is new preset and not just modified
if ( !boost::algorithm::ends_with(selected_preset, Preset::suffix_modified()) )
tab->select_preset(selected_preset);
}
}));
} }
PresetComboBox::~PresetComboBox() {} PresetComboBox::~PresetComboBox()
{
if (edit_btn)
edit_btn->Destroy();
}
void PresetComboBox::set_label_marker(int item) void PresetComboBox::set_label_marker(int item)
@ -611,13 +647,18 @@ Sidebar::Sidebar(Plater *parent)
text->SetFont(wxGetApp().small_font()); text->SetFont(wxGetApp().small_font());
*combo = new PresetComboBox(p->presets_panel, preset_type); *combo = new PresetComboBox(p->presets_panel, preset_type);
auto combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL);
combo_and_btn_sizer->Add(*combo, 1, wxEXPAND);
if ((*combo)->edit_btn)
combo_and_btn_sizer->Add((*combo)->edit_btn, 0, wxLEFT|wxRIGHT, int(0.3*wxGetApp().em_unit()));
auto *sizer_presets = this->p->sizer_presets; auto *sizer_presets = this->p->sizer_presets;
auto *sizer_filaments = this->p->sizer_filaments; auto *sizer_filaments = this->p->sizer_filaments;
sizer_presets->Add(text, 0, wxALIGN_LEFT | wxEXPAND | wxRIGHT, 4); sizer_presets->Add(text, 0, wxALIGN_LEFT | wxEXPAND | wxRIGHT, 4);
if (! filament) { if (! filament) {
sizer_presets->Add(*combo, 0, wxEXPAND | wxBOTTOM, 1); sizer_presets->Add(combo_and_btn_sizer, 0, wxEXPAND | wxBOTTOM, 1);
} else { } else {
sizer_filaments->Add(*combo, 0, wxEXPAND | wxBOTTOM, 1); sizer_filaments->Add(combo_and_btn_sizer, 0, wxEXPAND | wxBOTTOM, 1);
(*combo)->set_extruder_idx(0); (*combo)->set_extruder_idx(0);
sizer_presets->Add(sizer_filaments, 1, wxEXPAND); sizer_presets->Add(sizer_filaments, 1, wxEXPAND);
} }
@ -714,8 +755,12 @@ void Sidebar::init_filament_combo(PresetComboBox **combo, const int extr_idx) {
(*combo)->set_extruder_idx(extr_idx); (*combo)->set_extruder_idx(extr_idx);
auto combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL);
combo_and_btn_sizer->Add(*combo, 1, wxEXPAND);
combo_and_btn_sizer->Add((*combo)->edit_btn, 0, wxLEFT | wxRIGHT, int(0.3*wxGetApp().em_unit()));
auto /***/sizer_filaments = this->p->sizer_filaments; auto /***/sizer_filaments = this->p->sizer_filaments;
sizer_filaments->Add(*combo, 1, wxEXPAND | wxBOTTOM, 1); sizer_filaments->Add(combo_and_btn_sizer, 1, wxEXPAND | wxBOTTOM, 1);
} }
void Sidebar::remove_unused_filament_combos(const int current_extruder_count) void Sidebar::remove_unused_filament_combos(const int current_extruder_count)

View File

@ -46,6 +46,8 @@ public:
PresetComboBox(wxWindow *parent, Preset::Type preset_type); PresetComboBox(wxWindow *parent, Preset::Type preset_type);
~PresetComboBox(); ~PresetComboBox();
wxButton* edit_btn { nullptr };
void set_label_marker(int item); void set_label_marker(int item);
void set_extruder_idx(const int extr_idx) { extruder_idx = extr_idx; } void set_extruder_idx(const int extr_idx) { extruder_idx = extr_idx; }
int get_extruder_idx() const { return extruder_idx; } int get_extruder_idx() const { return extruder_idx; }

View File

@ -201,6 +201,7 @@ public:
static const std::vector<std::string>& sla_print_options(); static const std::vector<std::string>& sla_print_options();
static void update_suffix_modified(); static void update_suffix_modified();
static const std::string& suffix_modified();
static void normalize(DynamicPrintConfig &config); static void normalize(DynamicPrintConfig &config);
// Report configuration fields, which are misplaced into a wrong group, remove them from the config. // Report configuration fields, which are misplaced into a wrong group, remove them from the config.
static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config); static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config);
@ -210,7 +211,6 @@ protected:
friend class PresetBundle; friend class PresetBundle;
// Resize the extruder specific vectors () // Resize the extruder specific vectors ()
static void set_num_extruders(DynamicPrintConfig &config, unsigned int n); static void set_num_extruders(DynamicPrintConfig &config, unsigned int n);
static const std::string& suffix_modified();
static std::string remove_suffix_modified(const std::string &name); static std::string remove_suffix_modified(const std::string &name);
}; };

View File

@ -1308,11 +1308,14 @@ void PresetBundle::update_compatible(bool select_other_if_incompatible)
{ return std::find(prefered_filament_profiles.begin(), prefered_filament_profiles.end(), profile_name) != prefered_filament_profiles.end(); }); { return std::find(prefered_filament_profiles.begin(), prefered_filament_profiles.end(), profile_name) != prefered_filament_profiles.end(); });
if (select_other_if_incompatible) { if (select_other_if_incompatible) {
// Verify validity of the current filament presets. // Verify validity of the current filament presets.
if (this->filament_presets.size() == 1)
this->filament_presets.front() = this->filaments.get_edited_preset().name; this->filament_presets.front() = this->filaments.get_edited_preset().name;
for (size_t idx = 1; idx < this->filament_presets.size(); ++ idx) { else
{
for (size_t idx = 0; idx < this->filament_presets.size(); ++idx) {
std::string &filament_name = this->filament_presets[idx]; std::string &filament_name = this->filament_presets[idx];
Preset *preset = this->filaments.find_preset(filament_name, false); Preset *preset = this->filaments.find_preset(filament_name, false);
if (preset == nullptr || ! preset->is_compatible) { if (preset == nullptr || !preset->is_compatible) {
// Pick a compatible profile. If there are prefered_filament_profiles, use them. // Pick a compatible profile. If there are prefered_filament_profiles, use them.
if (prefered_filament_profiles.empty()) if (prefered_filament_profiles.empty())
filament_name = this->filaments.first_compatible().name; filament_name = this->filaments.first_compatible().name;
@ -1324,6 +1327,7 @@ void PresetBundle::update_compatible(bool select_other_if_incompatible)
} }
} }
} }
}
} }
break; break;
} }