Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/slic3r/GUI/AMSMaterialsSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ExtrusionCalibration.hpp"
#include "MsgDialog.hpp"
#include "GUI_App.hpp"
#include "FilamentPresetUtils.hpp"
#include "libslic3r/Preset.hpp"
#include "I18N.hpp"
#include <boost/log/trivial.hpp>
Expand Down Expand Up @@ -1418,6 +1419,7 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt)

m_filament_type = "";
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
const Preset* selected_filament_preset = nullptr;
if (preset_bundle) {
std::ostringstream stream;
if (obj)
Expand All @@ -1439,6 +1441,7 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt)
}
}
if (!it->is_system && !has_compatible_printer) continue;
selected_filament_preset = &(*it);
// ) if nozzle_temperature_range is found
ConfigOption* opt_min = it->config.option("nozzle_temperature_range_low");
if (opt_min) {
Expand Down Expand Up @@ -1527,11 +1530,25 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt)
if (it->alias.compare(into_u8(m_comboBox_filament->GetValue())) == 0) {
ams_filament_id = it->filament_id;
ams_setting_id = it->setting_id;
if (!selected_filament_preset) {
selected_filament_preset = &(*it);
}
break;
}
}
}

if (!selected_filament_preset && preset_bundle && !ams_filament_id.empty()) {
selected_filament_preset = find_filament_preset_by_id(preset_bundle, ams_filament_id);
}

std::string default_color = filament_default_colour(selected_filament_preset);
if (!default_color.empty()) {
wxColour color = DevAmsTray::decode_color(default_color);
set_color(color);
set_colors({ color });
}

auto get_cali_index = [this](const std::string& str) -> int{
for (int i = 0; i < int(m_pa_profile_items.size()); ++i) {
if (m_pa_profile_items[i].name == str)
Expand Down
46 changes: 46 additions & 0 deletions src/slic3r/GUI/FilamentPresetUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef slic3r_GUI_FilamentPresetUtils_hpp_
#define slic3r_GUI_FilamentPresetUtils_hpp_

#include <string>

#include "libslic3r/Preset.hpp"
#include "libslic3r/PresetBundle.hpp"

namespace Slic3r { namespace GUI {

inline std::string filament_default_colour(const Preset* preset)
{
return preset ? preset->config.opt_string("default_filament_colour", 0u) : std::string();
}

inline const Preset* find_preset_by_name_or_alias(
const PresetBundle* preset_bundle,
Preset::Type preset_type,
const PresetCollection* collection,
const std::string& name_or_alias)
{
if (!collection || name_or_alias.empty())
return nullptr;

std::string preset_name = Preset::remove_suffix_modified(name_or_alias);
if (preset_bundle)
preset_name = preset_bundle->get_preset_name_by_alias(preset_type, preset_name);

return collection->find_preset(preset_name);
}

inline const Preset* find_filament_preset_by_id(const PresetBundle* preset_bundle, const std::string& filament_id)
{
if (!preset_bundle || filament_id.empty())
return nullptr;

for (auto it = preset_bundle->filaments.begin(); it != preset_bundle->filaments.end(); ++it)
if (it->filament_id == filament_id)
return &(*it);

return nullptr;
}

}} // namespace Slic3r::GUI

#endif // slic3r_GUI_FilamentPresetUtils_hpp_
14 changes: 14 additions & 0 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

#include "GUI.hpp"
#include "GUI_App.hpp"
#include "FilamentPresetUtils.hpp"
#include "GuiColor.hpp"
#include "GUI_ObjectList.hpp"
#include "GUI_Utils.hpp"
Expand Down Expand Up @@ -11211,6 +11212,19 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
if (!q->on_filament_change(idx))
wxGetApp().preset_bundle->set_filament_preset(idx, old_name);
else if (idx >= 0) {
auto* preset = find_preset_by_name_or_alias(wxGetApp().preset_bundle, Preset::TYPE_FILAMENT, &wxGetApp().preset_bundle->filaments, preset_name);
std::string color = filament_default_colour(preset);
if (!color.empty()) {
auto& project_config = wxGetApp().preset_bundle->project_config;
if (auto* color_opt = project_config.option<ConfigOptionStrings>("filament_colour");
color_opt && static_cast<size_t>(idx) < color_opt->values.size())
color_opt->values[idx] = color;
if (auto* multi_color_opt = project_config.option<ConfigOptionStrings>("filament_multi_colour");
multi_color_opt && static_cast<size_t>(idx) < multi_color_opt->values.size())
multi_color_opt->values[idx] = color;
}
}
wxGetApp().plater()->update_project_dirty_from_presets();
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
dynamic_filament_list.update();
Expand Down
14 changes: 8 additions & 6 deletions src/slic3r/GUI/PresetComboBoxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "MsgDialog.hpp"
#include "ParamsDialog.hpp"
#include "FilamentPickerDialog.hpp"
#include "FilamentPresetUtils.hpp"
#include "wxExtensions.hpp"

#include "DeviceCore/DevManager.h"
Expand Down Expand Up @@ -233,11 +234,10 @@ int PresetComboBox::update_ams_color()
std::string color;
std::string ctype;
std::vector<std::string> colors;
auto* preset = find_preset_by_name_or_alias(wxGetApp().preset_bundle, m_type, m_collection, GetValue().ToUTF8().data());
color = filament_default_colour(preset);
bool use_preset_default_color = !color.empty();
if (idx < 0) {
auto name = Preset::remove_suffix_modified(GetValue().ToUTF8().data());
auto *preset = m_collection->find_preset(name);
if (preset)
color = preset->config.opt_string("default_filament_colour", 0u);
if (color.empty()) return -1;
} else {
auto &ams_list = wxGetApp().preset_bundle->filament_ams_list;
Expand All @@ -246,9 +246,11 @@ int PresetComboBox::update_ams_color()
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": ams %1% out of range %2%") % idx % ams_list.size();
return -1;
}
color = iter->second.opt_string("filament_colour", 0u);
if (color.empty())
color = iter->second.opt_string("filament_colour", 0u);
ctype = iter->second.opt_string("filament_colour_type", 0u);
colors = iter->second.opt<ConfigOptionStrings>("filament_multi_colour")->values;
if (!use_preset_default_color)
colors = iter->second.opt<ConfigOptionStrings>("filament_multi_colour")->values;
}
DynamicPrintConfig *cfg = &wxGetApp().preset_bundle->project_config;
auto color_head = static_cast<ConfigOptionStrings*>(cfg->option("filament_colour")->clone()); // single color (the first color if multi-color filament)
Expand Down