mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Implemented aliases for filaments
This commit is contained in:
parent
15251397b8
commit
cb395460c4
5 changed files with 81 additions and 6 deletions
|
@ -2268,6 +2268,7 @@ temperature = 265
|
||||||
|
|
||||||
[filament:ColorFabb nGen MINI]
|
[filament:ColorFabb nGen MINI]
|
||||||
inherits = ColorFabb nGen; *PETMINI*
|
inherits = ColorFabb nGen; *PETMINI*
|
||||||
|
filament_type = NGEN
|
||||||
alias = ColorFabb nGen
|
alias = ColorFabb nGen
|
||||||
|
|
||||||
[filament:ColorFabb nGen flex MINI]
|
[filament:ColorFabb nGen flex MINI]
|
||||||
|
|
|
@ -642,11 +642,17 @@ void PageMaterials::select_material(int i)
|
||||||
{
|
{
|
||||||
const bool checked = list_l3->IsChecked(i);
|
const bool checked = list_l3->IsChecked(i);
|
||||||
const Preset &preset = list_l3->get_data(i);
|
const Preset &preset = list_l3->get_data(i);
|
||||||
|
// #ys_FIXME_aliases
|
||||||
|
// if (checked) {
|
||||||
|
// wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
|
||||||
|
// } else {
|
||||||
|
// wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
|
||||||
|
// }
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
|
wizard_p()->add_presets(materials->appconfig_section(), preset.name);
|
||||||
} else {
|
} else {
|
||||||
wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
|
wizard_p()->del_presets(materials->appconfig_section(), preset.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1444,6 +1450,7 @@ void ConfigWizard::priv::update_materials(Technology technology)
|
||||||
{
|
{
|
||||||
if (any_fff_selected && (technology & T_FFF)) {
|
if (any_fff_selected && (technology & T_FFF)) {
|
||||||
filaments.clear();
|
filaments.clear();
|
||||||
|
aliases.clear();
|
||||||
|
|
||||||
// Iterate filaments in all bundles
|
// Iterate filaments in all bundles
|
||||||
for (const auto &pair : bundles) {
|
for (const auto &pair : bundles) {
|
||||||
|
@ -1461,6 +1468,8 @@ void ConfigWizard::priv::update_materials(Technology technology)
|
||||||
|
|
||||||
if (filament.is_compatible_with_printer(printer)) {
|
if (filament.is_compatible_with_printer(printer)) {
|
||||||
filaments.push(&filament);
|
filaments.push(&filament);
|
||||||
|
if (!filament.alias.empty())
|
||||||
|
aliases[filament.alias].insert(filament.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1669,6 +1678,30 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
||||||
preset_bundle->export_selections(*app_config);
|
preset_bundle->export_selections(*app_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigWizard::priv::add_presets(const std::string& section, const std::string& alias_key)
|
||||||
|
{
|
||||||
|
// add preset to config
|
||||||
|
appconfig_new.set(section, alias_key, "1");
|
||||||
|
|
||||||
|
// add presets had a same alias
|
||||||
|
auto it = aliases.find(alias_key);
|
||||||
|
if (it != aliases.end())
|
||||||
|
for (const std::string& name : it->second)
|
||||||
|
appconfig_new.set(section, name, "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigWizard::priv::del_presets(const std::string& section, const std::string& alias_key)
|
||||||
|
{
|
||||||
|
// delete preset from config
|
||||||
|
appconfig_new.erase(section, alias_key);
|
||||||
|
|
||||||
|
// delete presets had a same alias
|
||||||
|
auto it = aliases.find(alias_key);
|
||||||
|
if (it != aliases.end())
|
||||||
|
for (const std::string& name : it->second)
|
||||||
|
appconfig_new.erase(section, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,8 @@ struct Materials
|
||||||
|
|
||||||
template<class F> void filter_presets(const std::string &type, const std::string &vendor, F cb) {
|
template<class F> void filter_presets(const std::string &type, const std::string &vendor, F cb) {
|
||||||
for (const Preset *preset : presets) {
|
for (const Preset *preset : presets) {
|
||||||
if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)) {
|
if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)//) {
|
||||||
|
&& preset->alias.empty()) {
|
||||||
cb(preset);
|
cb(preset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,6 +405,8 @@ wxDEFINE_EVENT(EVT_INDEX_PAGE, wxCommandEvent);
|
||||||
|
|
||||||
// ConfigWizard private data
|
// ConfigWizard private data
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::set<std::string>> PresetAliases;
|
||||||
|
|
||||||
struct ConfigWizard::priv
|
struct ConfigWizard::priv
|
||||||
{
|
{
|
||||||
ConfigWizard *q;
|
ConfigWizard *q;
|
||||||
|
@ -415,6 +418,7 @@ struct ConfigWizard::priv
|
||||||
// PrinterPickers state.
|
// PrinterPickers state.
|
||||||
Materials filaments; // Holds available filament presets and their types & vendors
|
Materials filaments; // Holds available filament presets and their types & vendors
|
||||||
Materials sla_materials; // Ditto for SLA materials
|
Materials sla_materials; // Ditto for SLA materials
|
||||||
|
PresetAliases aliases; // Map of aliase to preset names
|
||||||
std::unique_ptr<DynamicPrintConfig> custom_config; // Backing for custom printer definition
|
std::unique_ptr<DynamicPrintConfig> custom_config; // Backing for custom printer definition
|
||||||
bool any_fff_selected; // Used to decide whether to display Filaments page
|
bool any_fff_selected; // Used to decide whether to display Filaments page
|
||||||
bool any_sla_selected; // Used to decide whether to display SLA Materials page
|
bool any_sla_selected; // Used to decide whether to display SLA Materials page
|
||||||
|
@ -473,6 +477,9 @@ struct ConfigWizard::priv
|
||||||
void on_3rdparty_install(const VendorProfile *vendor, bool install);
|
void on_3rdparty_install(const VendorProfile *vendor, bool install);
|
||||||
|
|
||||||
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
|
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
|
||||||
|
// #ys_FIXME_alise
|
||||||
|
void add_presets(const std::string& section, const std::string& alias_key);
|
||||||
|
void del_presets(const std::string& section, const std::string& alias_key);
|
||||||
|
|
||||||
int em() const { return index->em(); }
|
int em() const { return index->em(); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -148,6 +148,9 @@ public:
|
||||||
// Configuration data, loaded from a file, or set from the defaults.
|
// Configuration data, loaded from a file, or set from the defaults.
|
||||||
DynamicPrintConfig config;
|
DynamicPrintConfig config;
|
||||||
|
|
||||||
|
// Alias of the preset
|
||||||
|
std::string alias = "";
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
|
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
|
||||||
|
|
|
@ -1122,6 +1122,7 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
|
||||||
PresetCollection *presets = nullptr;
|
PresetCollection *presets = nullptr;
|
||||||
std::vector<std::string> *loaded = nullptr;
|
std::vector<std::string> *loaded = nullptr;
|
||||||
std::string preset_name;
|
std::string preset_name;
|
||||||
|
std::string alias_name;
|
||||||
if (boost::starts_with(section.first, "print:")) {
|
if (boost::starts_with(section.first, "print:")) {
|
||||||
presets = &this->prints;
|
presets = &this->prints;
|
||||||
loaded = &loaded_prints;
|
loaded = &loaded_prints;
|
||||||
|
@ -1130,6 +1131,14 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
|
||||||
presets = &this->filaments;
|
presets = &this->filaments;
|
||||||
loaded = &loaded_filaments;
|
loaded = &loaded_filaments;
|
||||||
preset_name = section.first.substr(9);
|
preset_name = section.first.substr(9);
|
||||||
|
|
||||||
|
for (const auto& item : section.second)
|
||||||
|
{
|
||||||
|
if (boost::starts_with(item.first, "alias")) {
|
||||||
|
alias_name = item.second.data();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (boost::starts_with(section.first, "sla_print:")) {
|
} else if (boost::starts_with(section.first, "sla_print:")) {
|
||||||
presets = &this->sla_prints;
|
presets = &this->sla_prints;
|
||||||
loaded = &loaded_sla_prints;
|
loaded = &loaded_sla_prints;
|
||||||
|
@ -1138,6 +1147,14 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
|
||||||
presets = &this->sla_materials;
|
presets = &this->sla_materials;
|
||||||
loaded = &loaded_sla_materials;
|
loaded = &loaded_sla_materials;
|
||||||
preset_name = section.first.substr(13);
|
preset_name = section.first.substr(13);
|
||||||
|
|
||||||
|
for (const auto& item : section.second)
|
||||||
|
{
|
||||||
|
if (boost::starts_with(item.first, "alias")) {
|
||||||
|
alias_name = item.second.data();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (boost::starts_with(section.first, "printer:")) {
|
} else if (boost::starts_with(section.first, "printer:")) {
|
||||||
presets = &this->printers;
|
presets = &this->printers;
|
||||||
loaded = &loaded_printers;
|
loaded = &loaded_printers;
|
||||||
|
@ -1283,6 +1300,8 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
|
||||||
loaded.is_system = true;
|
loaded.is_system = true;
|
||||||
loaded.vendor = vendor_profile;
|
loaded.vendor = vendor_profile;
|
||||||
}
|
}
|
||||||
|
if (!alias_name.empty())
|
||||||
|
loaded.alias = alias_name;
|
||||||
++ presets_loaded;
|
++ presets_loaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1538,7 +1557,8 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
|
||||||
// Fill in the list from scratch.
|
// Fill in the list from scratch.
|
||||||
ui->Freeze();
|
ui->Freeze();
|
||||||
ui->Clear();
|
ui->Clear();
|
||||||
size_t selected_preset_item = 0;
|
size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected
|
||||||
|
|
||||||
const Preset *selected_preset = this->filaments.find_preset(this->filament_presets[idx_extruder]);
|
const Preset *selected_preset = this->filaments.find_preset(this->filament_presets[idx_extruder]);
|
||||||
// Show wide icons if the currently selected preset is not compatible with the current printer,
|
// Show wide icons if the currently selected preset is not compatible with the current printer,
|
||||||
// and draw a red flag in front of the selected preset.
|
// and draw a red flag in front of the selected preset.
|
||||||
|
@ -1611,7 +1631,9 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
|
||||||
if (preset.is_default || preset.is_system) {
|
if (preset.is_default || preset.is_system) {
|
||||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()),
|
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()),
|
||||||
(bitmap == 0) ? wxNullBitmap : *bitmap);
|
(bitmap == 0) ? wxNullBitmap : *bitmap);
|
||||||
if (selected)
|
if (selected ||
|
||||||
|
// just in case: mark selected_preset_item as a first added element
|
||||||
|
selected_preset_item == INT_MAX )
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1630,13 +1652,22 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
|
||||||
ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap));
|
ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap));
|
||||||
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
||||||
ui->Append(it->first, *it->second);
|
ui->Append(it->first, *it->second);
|
||||||
if (it->first == selected_str)
|
if (it->first == selected_str ||
|
||||||
|
// just in case: mark selected_preset_item as a first added element
|
||||||
|
selected_preset_item == INT_MAX) {
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove filaments")), wxNullBitmap), GUI::PresetComboBox::LABEL_ITEM_WIZARD_FILAMENTS);
|
ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove filaments")), wxNullBitmap), GUI::PresetComboBox::LABEL_ITEM_WIZARD_FILAMENTS);
|
||||||
|
|
||||||
|
/* But, if selected_preset_item is still equal to INT_MAX, it means that
|
||||||
|
* there is no presets added to the list.
|
||||||
|
* */ So, select last combobox item ("Add/Remove filaments")
|
||||||
|
if (selected_preset_item == INT_MAX)
|
||||||
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
|
|
||||||
ui->SetSelection(selected_preset_item);
|
ui->SetSelection(selected_preset_item);
|
||||||
ui->SetToolTip(ui->GetString(selected_preset_item));
|
ui->SetToolTip(ui->GetString(selected_preset_item));
|
||||||
ui->check_selection();
|
ui->check_selection();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue