mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Set options value from edited preset instead of default preset, when call "Add Settings"
+ added code for custom editing of the frequently used settings bundle (it's commented for this moment) + some code refactoring
This commit is contained in:
parent
4dfcd49869
commit
c5152d04f8
2 changed files with 132 additions and 27 deletions
|
@ -21,8 +21,6 @@ namespace GUI
|
||||||
|
|
||||||
wxDEFINE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
|
wxDEFINE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
|
||||||
|
|
||||||
typedef std::map<std::string, std::vector<std::string>> FreqSettingsBundle;
|
|
||||||
|
|
||||||
// pt_FFF
|
// pt_FFF
|
||||||
FreqSettingsBundle FREQ_SETTINGS_BUNDLE_FFF =
|
FreqSettingsBundle FREQ_SETTINGS_BUNDLE_FFF =
|
||||||
{
|
{
|
||||||
|
@ -587,9 +585,9 @@ void ObjectList::OnDrop(wxDataViewEvent &event)
|
||||||
|
|
||||||
// Context Menu
|
// Context Menu
|
||||||
|
|
||||||
std::vector<std::string> get_options(const bool is_part, const bool is_sla)
|
std::vector<std::string> ObjectList::get_options(const bool is_part)
|
||||||
{
|
{
|
||||||
if (is_sla) {
|
if (wxGetApp().plater()->printer_technology() == ptSLA) {
|
||||||
SLAPrintObjectConfig full_sla_config;
|
SLAPrintObjectConfig full_sla_config;
|
||||||
auto options = full_sla_config.keys();
|
auto options = full_sla_config.keys();
|
||||||
options.erase(find(options.begin(), options.end(), "layer_height"));
|
options.erase(find(options.begin(), options.end(), "layer_height"));
|
||||||
|
@ -605,13 +603,8 @@ std::vector<std::string> get_options(const bool is_part, const bool is_sla)
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_options(const bool is_part)
|
|
||||||
{
|
|
||||||
return get_options(is_part, wxGetApp().plater()->printer_technology() == ptSLA);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::string>& get_options_for_bundle(const wxString& bundle_name)
|
const std::vector<std::string>& ObjectList::get_options_for_bundle(const wxString& bundle_name)
|
||||||
{
|
{
|
||||||
const FreqSettingsBundle& bundle = wxGetApp().plater()->printer_technology() == ptSLA ?
|
const FreqSettingsBundle& bundle = wxGetApp().plater()->printer_technology() == ptSLA ?
|
||||||
FREQ_SETTINGS_BUNDLE_SLA : FREQ_SETTINGS_BUNDLE_FFF;
|
FREQ_SETTINGS_BUNDLE_SLA : FREQ_SETTINGS_BUNDLE_FFF;
|
||||||
|
@ -621,14 +614,24 @@ const std::vector<std::string>& get_options_for_bundle(const wxString& bundle_na
|
||||||
if (bundle_name == _(it.first))
|
if (bundle_name == _(it.first))
|
||||||
return it.second;
|
return it.second;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
// if "Quick menu" is selected
|
||||||
|
FreqSettingsBundle& bundle_quick = wxGetApp().plater()->printer_technology() == ptSLA ?
|
||||||
|
m_freq_settings_sla: m_freq_settings_fff;
|
||||||
|
|
||||||
|
for (auto& it : bundle_quick)
|
||||||
|
{
|
||||||
|
if ( bundle_name == wxString::Format(_(L("Quick Add Settings (%s)")), _(it.first)) )
|
||||||
|
return it.second;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return std::vector<std::string> {};
|
return std::vector<std::string> {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// category -> vector ( option ; label )
|
void ObjectList::get_options_menu(settings_menu_hierarchy& settings_menu, const bool is_part)
|
||||||
typedef std::map< std::string, std::vector< std::pair<std::string, std::string> > > settings_menu_hierarchy;
|
|
||||||
void get_options_menu(settings_menu_hierarchy& settings_menu, const bool is_part, const bool is_sla)
|
|
||||||
{
|
{
|
||||||
auto options = get_options(is_part, is_sla);
|
auto options = get_options(is_part);
|
||||||
|
|
||||||
auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 :
|
auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 :
|
||||||
wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
|
wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
|
||||||
|
@ -653,11 +656,6 @@ void get_options_menu(settings_menu_hierarchy& settings_menu, const bool is_part
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_options_menu(settings_menu_hierarchy& settings_menu, const bool is_part)
|
|
||||||
{
|
|
||||||
get_options_menu(settings_menu, is_part, wxGetApp().plater()->printer_technology() == ptSLA);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectList::get_settings_choice(const wxString& category_name)
|
void ObjectList::get_settings_choice(const wxString& category_name)
|
||||||
{
|
{
|
||||||
wxArrayString names;
|
wxArrayString names;
|
||||||
|
@ -691,10 +689,59 @@ void ObjectList::get_settings_choice(const wxString& category_name)
|
||||||
if (wxGetSelectedChoices(selections, _(L("Select showing settings")), category_name, names) == -1)
|
if (wxGetSelectedChoices(selections, _(L("Select showing settings")), category_name, names) == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const int selection_cnt = selections.size();
|
||||||
|
#if 0
|
||||||
|
if (selection_cnt > 0)
|
||||||
|
{
|
||||||
|
// Add selected items to the "Quick menu"
|
||||||
|
FreqSettingsBundle& freq_settings = wxGetApp().plater()->printer_technology() == ptSLA ?
|
||||||
|
m_freq_settings_sla : m_freq_settings_fff;
|
||||||
|
bool changed_existing = false;
|
||||||
|
|
||||||
|
std::vector<std::string> tmp_freq_cat = {};
|
||||||
|
|
||||||
|
for (auto& cat : freq_settings)
|
||||||
|
{
|
||||||
|
if (_(cat.first) == category_name)
|
||||||
|
{
|
||||||
|
std::vector<std::string>& freq_settings_category = cat.second;
|
||||||
|
freq_settings_category.clear();
|
||||||
|
freq_settings_category.reserve(selection_cnt);
|
||||||
|
for (auto sel : selections)
|
||||||
|
freq_settings_category.push_back((*settings_list)[sel].first);
|
||||||
|
|
||||||
|
changed_existing = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!changed_existing)
|
||||||
|
{
|
||||||
|
// Create new "Quick menu" item
|
||||||
|
for (auto& cat : settings_menu)
|
||||||
|
{
|
||||||
|
if (_(cat.first) == category_name)
|
||||||
|
{
|
||||||
|
freq_settings[cat.first] = std::vector<std::string> {};
|
||||||
|
|
||||||
|
std::vector<std::string>& freq_settings_category = freq_settings.find(cat.first)->second;
|
||||||
|
freq_settings_category.reserve(selection_cnt);
|
||||||
|
for (auto sel : selections)
|
||||||
|
freq_settings_category.push_back((*settings_list)[sel].first);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector <std::string> selected_options;
|
std::vector <std::string> selected_options;
|
||||||
|
selected_options.reserve(selection_cnt);
|
||||||
for (auto sel : selections)
|
for (auto sel : selections)
|
||||||
selected_options.push_back((*settings_list)[sel].first);
|
selected_options.push_back((*settings_list)[sel].first);
|
||||||
|
|
||||||
|
const DynamicPrintConfig& from_config = wxGetApp().preset_bundle->prints.get_edited_preset().config;
|
||||||
|
|
||||||
for (auto& setting : (*settings_list))
|
for (auto& setting : (*settings_list))
|
||||||
{
|
{
|
||||||
auto& opt_key = setting.first;
|
auto& opt_key = setting.first;
|
||||||
|
@ -703,8 +750,17 @@ void ObjectList::get_settings_choice(const wxString& category_name)
|
||||||
m_config->erase(opt_key);
|
m_config->erase(opt_key);
|
||||||
|
|
||||||
if (find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end() &&
|
if (find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end() &&
|
||||||
find(selected_options.begin(), selected_options.end(), opt_key) != selected_options.end())
|
find(selected_options.begin(), selected_options.end(), opt_key) != selected_options.end()) {
|
||||||
m_config->set_key_value(opt_key, m_default_config->option(opt_key)->clone());
|
const ConfigOption* option = from_config.option(opt_key);
|
||||||
|
if (!option) {
|
||||||
|
// if current option doesn't exist in prints.get_edited_preset(),
|
||||||
|
// get it from m_default_config
|
||||||
|
if (m_default_config) delete m_default_config;
|
||||||
|
m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(false));
|
||||||
|
option = m_default_config->option(opt_key);
|
||||||
|
}
|
||||||
|
m_config->set_key_value(opt_key, option->clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -718,10 +774,20 @@ void ObjectList::get_freq_settings_choice(const wxString& bundle_name)
|
||||||
|
|
||||||
auto opt_keys = m_config->keys();
|
auto opt_keys = m_config->keys();
|
||||||
|
|
||||||
|
const DynamicPrintConfig& from_config = wxGetApp().preset_bundle->prints.get_edited_preset().config;
|
||||||
for (auto& opt_key : options)
|
for (auto& opt_key : options)
|
||||||
{
|
{
|
||||||
if ( find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end() )
|
if (find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end()) {
|
||||||
m_config->set_key_value(opt_key, m_default_config->option(opt_key)->clone());
|
const ConfigOption* option = from_config.option(opt_key);
|
||||||
|
if (!option) {
|
||||||
|
// if current option doesn't exist in prints.get_edited_preset(),
|
||||||
|
// get it from m_default_config
|
||||||
|
if (m_default_config) delete m_default_config;
|
||||||
|
m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(false));
|
||||||
|
option = m_default_config->option(opt_key);
|
||||||
|
}
|
||||||
|
m_config->set_key_value(opt_key, option->clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add settings item for object
|
// Add settings item for object
|
||||||
|
@ -835,7 +901,20 @@ wxMenuItem* ObjectList::append_menu_item_settings(wxMenu* menu_)
|
||||||
if (settings_id != wxNOT_FOUND)
|
if (settings_id != wxNOT_FOUND)
|
||||||
menu->Destroy(settings_id);
|
menu->Destroy(settings_id);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
for (auto& it : m_freq_settings_fff)
|
||||||
|
{
|
||||||
|
settings_id = menu->FindItem(wxString::Format(_(L("Quick Add Settings (%s)")), _(it.first)));
|
||||||
|
if (settings_id != wxNOT_FOUND)
|
||||||
|
menu->Destroy(settings_id);
|
||||||
|
}
|
||||||
|
for (auto& it : m_freq_settings_sla)
|
||||||
|
{
|
||||||
|
settings_id = menu->FindItem(wxString::Format(_(L("Quick Add Settings (%s)")), _(it.first)));
|
||||||
|
if (settings_id != wxNOT_FOUND)
|
||||||
|
menu->Destroy(settings_id);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
menu->DestroySeparators(); // delete old separators
|
menu->DestroySeparators(); // delete old separators
|
||||||
|
|
||||||
const auto sel_vol = get_selected_model_volume();
|
const auto sel_vol = get_selected_model_volume();
|
||||||
|
@ -937,6 +1016,7 @@ wxMenu* ObjectList::create_settings_popupmenu(wxMenu *parent_menu)
|
||||||
|
|
||||||
void ObjectList::create_freq_settings_popupmenu(wxMenu *menu)
|
void ObjectList::create_freq_settings_popupmenu(wxMenu *menu)
|
||||||
{
|
{
|
||||||
|
// Add default settings bundles
|
||||||
const FreqSettingsBundle& bundle = wxGetApp().plater()->printer_technology() == ptFFF ?
|
const FreqSettingsBundle& bundle = wxGetApp().plater()->printer_technology() == ptFFF ?
|
||||||
FREQ_SETTINGS_BUNDLE_FFF : FREQ_SETTINGS_BUNDLE_SLA;
|
FREQ_SETTINGS_BUNDLE_FFF : FREQ_SETTINGS_BUNDLE_SLA;
|
||||||
|
|
||||||
|
@ -951,6 +1031,20 @@ void ObjectList::create_freq_settings_popupmenu(wxMenu *menu)
|
||||||
[menu, this](wxCommandEvent& event) { get_freq_settings_choice(menu->GetLabel(event.GetId())); },
|
[menu, this](wxCommandEvent& event) { get_freq_settings_choice(menu->GetLabel(event.GetId())); },
|
||||||
CATEGORY_ICON.find(it.first) == CATEGORY_ICON.end() ? wxNullBitmap : CATEGORY_ICON.at(it.first), menu);
|
CATEGORY_ICON.find(it.first) == CATEGORY_ICON.end() ? wxNullBitmap : CATEGORY_ICON.at(it.first), menu);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
// Add "Quick" settings bundles
|
||||||
|
const FreqSettingsBundle& bundle_quick = wxGetApp().plater()->printer_technology() == ptFFF ?
|
||||||
|
m_freq_settings_fff : m_freq_settings_sla;
|
||||||
|
|
||||||
|
for (auto& it : bundle_quick) {
|
||||||
|
if (it.first.empty() || it.first == "Extruders" && extruders_cnt == 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
append_menu_item(menu, wxID_ANY, wxString::Format(_(L("Quick Add Settings (%s)")), _(it.first)), "",
|
||||||
|
[menu, this](wxCommandEvent& event) { get_freq_settings_choice(menu->GetLabel(event.GetId())); },
|
||||||
|
CATEGORY_ICON.find(it.first) == CATEGORY_ICON.end() ? wxNullBitmap : CATEGORY_ICON.at(it.first), menu);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectList::update_opt_keys(t_config_option_keys& opt_keys)
|
void ObjectList::update_opt_keys(t_config_option_keys& opt_keys)
|
||||||
|
@ -1381,9 +1475,6 @@ void ObjectList::part_selection_changed()
|
||||||
m_config = &(*m_objects)[obj_idx_]->config;
|
m_config = &(*m_objects)[obj_idx_]->config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_default_config) delete m_default_config;
|
|
||||||
m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(is_part));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,11 @@ class ModelVolume;
|
||||||
// FIXME: broken build on mac os because of this is missing:
|
// FIXME: broken build on mac os because of this is missing:
|
||||||
typedef std::vector<std::string> t_config_option_keys;
|
typedef std::vector<std::string> t_config_option_keys;
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::vector<std::string>> FreqSettingsBundle;
|
||||||
|
|
||||||
|
// category -> vector ( option ; label )
|
||||||
|
typedef std::map< std::string, std::vector< std::pair<std::string, std::string> > > settings_menu_hierarchy;
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
wxDECLARE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
|
wxDECLARE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
|
||||||
|
@ -129,6 +134,11 @@ class ObjectList : public wxDataViewCtrl
|
||||||
|
|
||||||
int m_selected_row = 0;
|
int m_selected_row = 0;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
FreqSettingsBundle m_freq_settings_fff;
|
||||||
|
FreqSettingsBundle m_freq_settings_sla;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectList(wxWindow* parent);
|
ObjectList(wxWindow* parent);
|
||||||
~ObjectList();
|
~ObjectList();
|
||||||
|
@ -264,6 +274,10 @@ private:
|
||||||
|
|
||||||
void ItemValueChanged(wxDataViewEvent &event);
|
void ItemValueChanged(wxDataViewEvent &event);
|
||||||
void OnEditingDone(wxDataViewEvent &event);
|
void OnEditingDone(wxDataViewEvent &event);
|
||||||
|
|
||||||
|
std::vector<std::string> get_options(const bool is_part);
|
||||||
|
const std::vector<std::string>& get_options_for_bundle(const wxString& bundle_name);
|
||||||
|
void get_options_menu(settings_menu_hierarchy& settings_menu, const bool is_part);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue