Integrated the "compatible printers" idea by @alexrj with Vojtech's twist:
The incompatible presets are hidden in the tabs if show_incompatible_presets is false. If show_incompatible_presets is true, there is a button to show / hide the incompatible presets from the tab selector.
This commit is contained in:
parent
b23b9ea1d2
commit
bfce6dba9b
12 changed files with 482 additions and 226 deletions
|
@ -40,6 +40,8 @@ void AppConfig::set_defaults()
|
|||
// If set, the "- default -" selections of print/filament/printer are suppressed, if there is a valid preset available.
|
||||
if (get("no_defaults").empty())
|
||||
set("no_defaults", "1");
|
||||
if (get("show_incompatible_presets").empty())
|
||||
set("show_incompatible_presets", "0");
|
||||
// Version check is enabled by default in the config, but it is not implemented yet.
|
||||
if (get("version_check").empty())
|
||||
set("version_check", "1");
|
||||
|
|
|
@ -96,6 +96,8 @@ void Preset::normalize(DynamicPrintConfig &config)
|
|||
size_t n = (nozzle_diameter == nullptr) ? 1 : nozzle_diameter->values.size();
|
||||
const auto &defaults = FullPrintConfig::defaults();
|
||||
for (const std::string &key : Preset::filament_options()) {
|
||||
if (key == "compatible_printers")
|
||||
continue;
|
||||
auto *opt = config.option(key, false);
|
||||
assert(opt != nullptr);
|
||||
assert(opt->is_vector());
|
||||
|
@ -138,13 +140,18 @@ std::string Preset::label() const
|
|||
return this->name + (this->is_dirty ? g_suffix_modified : "");
|
||||
}
|
||||
|
||||
bool Preset::enable_compatible(const std::string &active_printer)
|
||||
bool Preset::is_compatible_with_printer(const std::string &active_printer) const
|
||||
{
|
||||
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(this->config.optptr("compatible_printers"));
|
||||
this->is_visible = compatible_printers && ! compatible_printers->values.empty() &&
|
||||
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(this->config.option("compatible_printers"));
|
||||
return this->is_default || active_printer.empty() ||
|
||||
compatible_printers == nullptr || compatible_printers->values.empty() ||
|
||||
std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer) !=
|
||||
compatible_printers->values.end();
|
||||
return this->is_visible;
|
||||
}
|
||||
|
||||
bool Preset::update_compatible_with_printer(const std::string &active_printer)
|
||||
{
|
||||
return this->is_compatible = is_compatible_with_printer(active_printer);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& Preset::print_options()
|
||||
|
@ -171,7 +178,8 @@ const std::vector<std::string>& Preset::print_options()
|
|||
"perimeter_extrusion_width", "external_perimeter_extrusion_width", "infill_extrusion_width", "solid_infill_extrusion_width",
|
||||
"top_infill_extrusion_width", "support_material_extrusion_width", "infill_overlap", "bridge_flow_ratio", "clip_multipart_objects",
|
||||
"elefant_foot_compensation", "xy_size_compensation", "threads", "resolution", "wipe_tower", "wipe_tower_x", "wipe_tower_y",
|
||||
"wipe_tower_width", "wipe_tower_per_color_wipe"
|
||||
"wipe_tower_width", "wipe_tower_per_color_wipe",
|
||||
"compatible_printers"
|
||||
};
|
||||
return s_opts;
|
||||
}
|
||||
|
@ -183,7 +191,8 @@ const std::vector<std::string>& Preset::filament_options()
|
|||
"extrusion_multiplier", "filament_density", "filament_cost", "temperature", "first_layer_temperature", "bed_temperature",
|
||||
"first_layer_bed_temperature", "fan_always_on", "cooling", "min_fan_speed", "max_fan_speed", "bridge_fan_speed",
|
||||
"disable_fan_first_layers", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed", "start_filament_gcode",
|
||||
"end_filament_gcode"
|
||||
"end_filament_gcode",
|
||||
"compatible_printers"
|
||||
};
|
||||
return s_opts;
|
||||
}
|
||||
|
@ -361,6 +370,18 @@ size_t PresetCollection::first_visible_idx() const
|
|||
return idx;
|
||||
}
|
||||
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
size_t PresetCollection::first_compatible_idx() const
|
||||
{
|
||||
size_t idx = m_default_suppressed ? 1 : 0;
|
||||
for (; idx < this->m_presets.size(); ++ idx)
|
||||
if (m_presets[idx].is_compatible)
|
||||
break;
|
||||
if (idx == this->m_presets.size())
|
||||
idx = 0;
|
||||
return idx;
|
||||
}
|
||||
|
||||
void PresetCollection::set_default_suppressed(bool default_suppressed)
|
||||
{
|
||||
if (m_default_suppressed != default_suppressed) {
|
||||
|
@ -369,13 +390,29 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
|
|||
}
|
||||
}
|
||||
|
||||
void PresetCollection::enable_disable_compatible_to_printer(const std::string &active_printer)
|
||||
void PresetCollection::update_compatible_with_printer(const std::string &active_printer, bool select_other_if_incompatible)
|
||||
{
|
||||
size_t num_visible = 0;
|
||||
for (size_t idx_preset = 1; idx_preset < m_presets.size(); ++ idx_preset)
|
||||
if (m_presets[idx_preset].enable_compatible(active_printer))
|
||||
for (size_t idx_preset = 1; idx_preset < m_presets.size(); ++ idx_preset) {
|
||||
bool selected = idx_preset == m_idx_selected;
|
||||
Preset &preset_selected = m_presets[idx_preset];
|
||||
Preset &preset_edited = selected ? m_edited_preset : preset_selected;
|
||||
if (preset_edited.update_compatible_with_printer(active_printer))
|
||||
// Mark compatible presets as visible.
|
||||
preset_selected.is_visible = true;
|
||||
else if (selected && select_other_if_incompatible) {
|
||||
preset_selected.is_visible = false;
|
||||
m_idx_selected = (size_t)-1;
|
||||
}
|
||||
if (selected)
|
||||
preset_selected.is_compatible = preset_edited.is_compatible;
|
||||
if (preset_selected.is_visible)
|
||||
++ num_visible;
|
||||
if (num_visible == 0)
|
||||
}
|
||||
if (m_idx_selected == (size_t)-1)
|
||||
// Find some other visible preset.
|
||||
this->select_preset(first_visible_idx());
|
||||
else if (num_visible == 0)
|
||||
// Show the "-- default --" preset.
|
||||
m_presets.front().is_visible = true;
|
||||
}
|
||||
|
@ -399,15 +436,18 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
|
|||
ui->Clear();
|
||||
for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++ i) {
|
||||
const Preset &preset = this->m_presets[i];
|
||||
const wxBitmap *bmp = (i == 0 || preset.is_visible) ? m_bitmap_compatible : m_bitmap_incompatible;
|
||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), (bmp == 0) ? wxNullBitmap : *bmp, (void*)i);
|
||||
if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected))
|
||||
continue;
|
||||
const wxBitmap *bmp = (i == 0 || preset.is_compatible) ? m_bitmap_main_frame : m_bitmap_incompatible;
|
||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
|
||||
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
|
||||
if (i == m_idx_selected)
|
||||
ui->SetSelection(ui->GetCount() - 1);
|
||||
}
|
||||
ui->Thaw();
|
||||
}
|
||||
|
||||
void PresetCollection::update_tab_ui(wxChoice *ui)
|
||||
void PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompatible)
|
||||
{
|
||||
if (ui == nullptr)
|
||||
return;
|
||||
|
@ -415,8 +455,11 @@ void PresetCollection::update_tab_ui(wxChoice *ui)
|
|||
ui->Clear();
|
||||
for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++ i) {
|
||||
const Preset &preset = this->m_presets[i];
|
||||
const wxBitmap *bmp = (i == 0 || preset.is_visible) ? m_bitmap_compatible : m_bitmap_incompatible;
|
||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), (void*)&preset);
|
||||
if (! show_incompatible && ! preset.is_compatible && i != m_idx_selected)
|
||||
continue;
|
||||
const wxBitmap *bmp = preset.is_compatible ? m_bitmap_compatible : m_bitmap_incompatible;
|
||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
|
||||
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
|
||||
if (i == m_idx_selected)
|
||||
ui->SetSelection(ui->GetCount() - 1);
|
||||
}
|
||||
|
@ -425,8 +468,9 @@ void PresetCollection::update_tab_ui(wxChoice *ui)
|
|||
|
||||
// Update a dirty floag of the current preset, update the labels of the UI component accordingly.
|
||||
// Return true if the dirty flag changed.
|
||||
bool PresetCollection::update_dirty_ui(wxItemContainer *ui)
|
||||
bool PresetCollection::update_dirty_ui(wxBitmapComboBox *ui)
|
||||
{
|
||||
wxWindowUpdateLocker noUpdates(ui);
|
||||
// 1) Update the dirty flag of the current preset.
|
||||
bool was_dirty = this->get_selected_preset().is_dirty;
|
||||
bool is_dirty = current_is_dirty();
|
||||
|
@ -445,12 +489,6 @@ bool PresetCollection::update_dirty_ui(wxItemContainer *ui)
|
|||
return was_dirty != is_dirty;
|
||||
}
|
||||
|
||||
bool PresetCollection::update_dirty_ui(wxChoice *ui)
|
||||
{
|
||||
wxWindowUpdateLocker noUpdates(ui);
|
||||
return update_dirty_ui(dynamic_cast<wxItemContainer*>(ui));
|
||||
}
|
||||
|
||||
Preset& PresetCollection::select_preset(size_t idx)
|
||||
{
|
||||
for (Preset &preset : m_presets)
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
bool is_visible = true;
|
||||
// Has this preset been modified?
|
||||
bool is_dirty = false;
|
||||
// Is this preset compatible with the currently active printer?
|
||||
bool is_compatible = true;
|
||||
|
||||
// Name of the preset, usually derived form the file name.
|
||||
std::string name;
|
||||
|
@ -77,8 +79,9 @@ public:
|
|||
void set_dirty(bool dirty = true) { this->is_dirty = dirty; }
|
||||
void reset_dirty() { this->is_dirty = false; }
|
||||
|
||||
// Mark this preset as visible if it is compatible with active_printer.
|
||||
bool enable_compatible(const std::string &active_printer);
|
||||
bool is_compatible_with_printer(const std::string &active_printer) const;
|
||||
// Mark this preset as compatible if it is compatible with active_printer.
|
||||
bool update_compatible_with_printer(const std::string &active_printer);
|
||||
|
||||
// Resize the extruder specific fields, initialize them with the content of the 1st extruder.
|
||||
void set_num_extruders(unsigned int n) { set_num_extruders(this->config, n); }
|
||||
|
@ -147,6 +150,7 @@ public:
|
|||
// Return the selected preset, without the user modifications applied.
|
||||
Preset& get_selected_preset() { return m_presets[m_idx_selected]; }
|
||||
const Preset& get_selected_preset() const { return m_presets[m_idx_selected]; }
|
||||
int get_selected_idx() const { return m_idx_selected; }
|
||||
// Return the selected preset including the user modifications.
|
||||
Preset& get_edited_preset() { return m_edited_preset; }
|
||||
const Preset& get_edited_preset() const { return m_edited_preset; }
|
||||
|
@ -155,6 +159,7 @@ public:
|
|||
// Return a preset by an index. If the preset is active, a temporary copy is returned.
|
||||
Preset& preset(size_t idx) { return (int(idx) == m_idx_selected) ? m_edited_preset : m_presets[idx]; }
|
||||
const Preset& preset(size_t idx) const { return const_cast<PresetCollection*>(this)->preset(idx); }
|
||||
void discard_current_changes() { m_edited_preset = m_presets[m_idx_selected]; }
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
|
@ -163,16 +168,19 @@ public:
|
|||
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found); }
|
||||
|
||||
size_t first_visible_idx() const;
|
||||
size_t first_compatible_idx() const;
|
||||
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
// Return the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
Preset& first_visible() { return this->preset(this->first_visible_idx()); }
|
||||
const Preset& first_visible() const { return this->preset(this->first_visible_idx()); }
|
||||
Preset& first_visible() { return this->preset(this->first_visible_idx()); }
|
||||
const Preset& first_visible() const { return this->preset(this->first_visible_idx()); }
|
||||
Preset& first_compatible() { return this->preset(this->first_compatible_idx()); }
|
||||
const Preset& first_compatible() const { return this->preset(this->first_compatible_idx()); }
|
||||
|
||||
// Return number of presets including the "- default -" preset.
|
||||
size_t size() const { return this->m_presets.size(); }
|
||||
|
||||
// For Print / Filament presets, disable those, which are not compatible with the printer.
|
||||
void enable_disable_compatible_to_printer(const std::string &active_printer);
|
||||
void update_compatible_with_printer(const std::string &active_printer, bool select_other_if_incompatible);
|
||||
|
||||
size_t num_visible() const { return std::count_if(m_presets.begin(), m_presets.end(), [](const Preset &preset){return preset.is_visible;}); }
|
||||
|
||||
|
@ -182,13 +190,17 @@ public:
|
|||
std::vector<std::string> current_dirty_options() { return this->get_selected_preset().config.diff(this->get_edited_preset().config); }
|
||||
|
||||
// Update the choice UI from the list of presets.
|
||||
void update_tab_ui(wxChoice *ui);
|
||||
// If show_incompatible, all presets are shown, otherwise only the compatible presets are shown.
|
||||
// If an incompatible preset is selected, it is shown as well.
|
||||
void update_tab_ui(wxBitmapComboBox *ui, bool show_incompatible);
|
||||
// Update the choice UI from the list of presets.
|
||||
// Only the compatible presets are shown.
|
||||
// If an incompatible preset is selected, it is shown as well.
|
||||
void update_platter_ui(wxBitmapComboBox *ui);
|
||||
|
||||
// Update a dirty floag of the current preset, update the labels of the UI component accordingly.
|
||||
// Return true if the dirty flag changed.
|
||||
bool update_dirty_ui(wxItemContainer *ui);
|
||||
bool update_dirty_ui(wxChoice *ui);
|
||||
bool update_dirty_ui(wxBitmapComboBox *ui);
|
||||
|
||||
// Select a profile by its name. Return true if the selection changed.
|
||||
// Without force, the selection is only updated if the index changes.
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
#include <wx/dcmemory.h>
|
||||
#include <wx/image.h>
|
||||
#include <wx/choice.h>
|
||||
#include <wx/bmpcbox.h>
|
||||
|
@ -46,9 +47,7 @@ PresetBundle::PresetBundle() :
|
|||
this->prints .load_bitmap_default("cog.png");
|
||||
this->filaments.load_bitmap_default("spool.png");
|
||||
this->printers .load_bitmap_default("printer_empty.png");
|
||||
|
||||
// FIXME select some icons indicating compatibility.
|
||||
this->load_compatible_bitmaps("cog.png", "cog.png");
|
||||
this->load_compatible_bitmaps();
|
||||
}
|
||||
|
||||
PresetBundle::~PresetBundle()
|
||||
|
@ -110,6 +109,9 @@ void PresetBundle::load_selections(const AppConfig &config)
|
|||
break;
|
||||
this->set_filament_preset(i, remove_ini_suffix(config.get("presets", name)));
|
||||
}
|
||||
// Update visibility of presets based on their compatibility with the active printer.
|
||||
// This will switch the print or filament presets to compatible if the active presets are incompatible.
|
||||
this->update_compatible_with_printer(false);
|
||||
}
|
||||
|
||||
// Export selections (current print, current filaments, current printer) into config.ini
|
||||
|
@ -137,8 +139,10 @@ void PresetBundle::export_selections(PlaceholderParser &pp)
|
|||
pp.set("printer_preset", printers.get_selected_preset().name);
|
||||
}
|
||||
|
||||
bool PresetBundle::load_compatible_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible)
|
||||
bool PresetBundle::load_compatible_bitmaps()
|
||||
{
|
||||
const std::string path_bitmap_compatible = "flag-green-icon.png";
|
||||
const std::string path_bitmap_incompatible = "flag-red-icon.png";
|
||||
bool loaded_compatible = m_bitmapCompatible ->LoadFile(
|
||||
wxString::FromUTF8(Slic3r::var(path_bitmap_compatible).c_str()), wxBITMAP_TYPE_PNG);
|
||||
bool loaded_incompatible = m_bitmapIncompatible->LoadFile(
|
||||
|
@ -146,12 +150,12 @@ bool PresetBundle::load_compatible_bitmaps(const std::string &path_bitmap_compat
|
|||
if (loaded_compatible) {
|
||||
prints .set_bitmap_compatible(m_bitmapCompatible);
|
||||
filaments.set_bitmap_compatible(m_bitmapCompatible);
|
||||
printers .set_bitmap_compatible(m_bitmapCompatible);
|
||||
// printers .set_bitmap_compatible(m_bitmapCompatible);
|
||||
}
|
||||
if (loaded_incompatible) {
|
||||
prints .set_bitmap_compatible(m_bitmapIncompatible);
|
||||
filaments.set_bitmap_compatible(m_bitmapIncompatible);
|
||||
printers .set_bitmap_compatible(m_bitmapIncompatible);
|
||||
prints .set_bitmap_incompatible(m_bitmapIncompatible);
|
||||
filaments.set_bitmap_incompatible(m_bitmapIncompatible);
|
||||
// printers .set_bitmap_incompatible(m_bitmapIncompatible);
|
||||
}
|
||||
return loaded_compatible && loaded_incompatible;
|
||||
}
|
||||
|
@ -180,6 +184,8 @@ DynamicPrintConfig PresetBundle::full_config() const
|
|||
std::vector<const ConfigOption*> filament_opts(num_extruders, nullptr);
|
||||
// loop through options and apply them to the resulting config.
|
||||
for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
|
||||
if (key == "compatible_printers")
|
||||
continue;
|
||||
// Get a destination option.
|
||||
ConfigOption *opt_dst = out.option(key, false);
|
||||
if (opt_dst->is_scalar()) {
|
||||
|
@ -434,6 +440,20 @@ void PresetBundle::update_multi_material_filament_presets()
|
|||
this->filament_presets.resize(num_extruders, this->filament_presets.empty() ? this->filaments.first_visible().name : this->filament_presets.back());
|
||||
}
|
||||
|
||||
void PresetBundle::update_compatible_with_printer(bool select_other_if_incompatible)
|
||||
{
|
||||
this->prints.update_compatible_with_printer(this->printers.get_selected_preset().name, select_other_if_incompatible);
|
||||
this->filaments.update_compatible_with_printer(this->printers.get_selected_preset().name, select_other_if_incompatible);
|
||||
if (select_other_if_incompatible) {
|
||||
// Verify validity of the current filament presets.
|
||||
for (std::string &filament_name : this->filament_presets) {
|
||||
Preset *preset = this->filaments.find_preset(filament_name, false);
|
||||
if (preset == nullptr || ! preset->is_compatible)
|
||||
filament_name = this->filaments.first_compatible().name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PresetBundle::export_configbundle(const std::string &path) //, const DynamicPrintConfig &settings
|
||||
{
|
||||
boost::nowide::ofstream c;
|
||||
|
@ -526,42 +546,66 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitma
|
|||
// Fill in the list from scratch.
|
||||
ui->Freeze();
|
||||
ui->Clear();
|
||||
for (size_t i = this->filaments().front().is_visible ? 0 : 1; i < this->filaments().size(); ++ i) {
|
||||
const Preset &preset = this->filaments.preset(i);
|
||||
if (! preset.is_visible)
|
||||
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,
|
||||
// and draw a red flag in front of the selected preset.
|
||||
bool wide_icons = selected_preset != nullptr && ! selected_preset->is_compatible && m_bitmapIncompatible != nullptr;
|
||||
assert(selected_preset != nullptr);
|
||||
for (int i = this->filaments().front().is_visible ? 0 : 1; i < int(this->filaments().size()); ++ i) {
|
||||
const Preset &preset = this->filaments.preset(i);
|
||||
bool selected = this->filament_presets[idx_extruder] == preset.name;
|
||||
if (! preset.is_visible || (! preset.is_compatible && ! selected))
|
||||
continue;
|
||||
bool selected = this->filament_presets[idx_extruder] == preset.name;
|
||||
// Assign an extruder color to the selected item if the extruder color is defined.
|
||||
std::string filament_rgb = preset.config.opt_string("filament_colour", 0);
|
||||
std::string extruder_rgb = (selected && !extruder_color.empty()) ? extruder_color : filament_rgb;
|
||||
wxBitmap *bitmap = nullptr;
|
||||
if (filament_rgb == extruder_rgb) {
|
||||
auto it = m_mapColorToBitmap.find(filament_rgb);
|
||||
if (it == m_mapColorToBitmap.end()) {
|
||||
// Create the bitmap.
|
||||
parse_color(filament_rgb, rgb);
|
||||
wxImage image(24, 16);
|
||||
image.SetRGB(wxRect(0, 0, 24, 16), rgb[0], rgb[1], rgb[2]);
|
||||
m_mapColorToBitmap[filament_rgb] = bitmap = new wxBitmap(image);
|
||||
} else {
|
||||
bitmap = it->second;
|
||||
}
|
||||
} else {
|
||||
std::string bitmap_key = filament_rgb + extruder_rgb;
|
||||
auto it = m_mapColorToBitmap.find(bitmap_key);
|
||||
if (it == m_mapColorToBitmap.end()) {
|
||||
// Create the bitmap.
|
||||
wxImage image(24, 16);
|
||||
parse_color(extruder_rgb, rgb);
|
||||
image.SetRGB(wxRect(0, 0, 16, 16), rgb[0], rgb[1], rgb[2]);
|
||||
parse_color(filament_rgb, rgb);
|
||||
image.SetRGB(wxRect(16, 0, 8, 16), rgb[0], rgb[1], rgb[2]);
|
||||
m_mapColorToBitmap[filament_rgb] = bitmap = new wxBitmap(image);
|
||||
} else {
|
||||
bitmap = it->second;
|
||||
}
|
||||
bool single_bar = filament_rgb == extruder_rgb;
|
||||
std::string bitmap_key = single_bar ? filament_rgb : filament_rgb + extruder_rgb;
|
||||
// If the filament preset is not compatible and there is a "red flag" icon loaded, show it left
|
||||
// to the filament color image.
|
||||
if (wide_icons)
|
||||
bitmap_key += preset.is_compatible ? "comp" : "notcomp";
|
||||
auto it = m_mapColorToBitmap.find(bitmap_key);
|
||||
wxBitmap *bitmap = (it == m_mapColorToBitmap.end()) ? nullptr : it->second;
|
||||
if (bitmap == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
bitmap = new wxBitmap((wide_icons ? 16 : 0) + 24, 16);
|
||||
bitmap->UseAlpha();
|
||||
wxMemoryDC memDC;
|
||||
memDC.SelectObject(*bitmap);
|
||||
memDC.SetBackground(*wxTRANSPARENT_BRUSH);
|
||||
memDC.Clear();
|
||||
if (wide_icons && ! preset.is_compatible)
|
||||
// Paint the red flag.
|
||||
memDC.DrawBitmap(*m_bitmapIncompatible, 0, 0, false);
|
||||
// Paint the color bars.
|
||||
parse_color(filament_rgb, rgb);
|
||||
wxImage image(24, 16);
|
||||
image.InitAlpha();
|
||||
unsigned char* imgdata = image.GetData();
|
||||
unsigned char* imgalpha = image.GetAlpha();
|
||||
for (size_t i = 0; i < image.GetWidth() * image.GetHeight(); ++ i) {
|
||||
*imgdata ++ = rgb[0];
|
||||
*imgdata ++ = rgb[1];
|
||||
*imgdata ++ = rgb[2];
|
||||
*imgalpha ++ = wxALPHA_OPAQUE;
|
||||
}
|
||||
if (! single_bar) {
|
||||
parse_color(extruder_rgb, rgb);
|
||||
imgdata = image.GetData();
|
||||
for (size_t r = 0; r < 16; ++ r) {
|
||||
imgdata = image.GetData() + r * image.GetWidth() * 3;
|
||||
for (size_t c = 0; c < 16; ++ c) {
|
||||
*imgdata ++ = rgb[0];
|
||||
*imgdata ++ = rgb[1];
|
||||
*imgdata ++ = rgb[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
memDC.DrawBitmap(wxBitmap(image), wide_icons ? 16 : 0, 0, false);
|
||||
memDC.SelectObject(wxNullBitmap);
|
||||
m_mapColorToBitmap[bitmap_key] = bitmap;
|
||||
}
|
||||
|
||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), (bitmap == 0) ? wxNullBitmap : *bitmap);
|
||||
if (selected)
|
||||
ui->SetSelection(ui->GetCount() - 1);
|
||||
|
@ -569,59 +613,6 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitma
|
|||
ui->Thaw();
|
||||
}
|
||||
|
||||
// Update the colors preview at the platter extruder combo box.
|
||||
void PresetBundle::update_platter_filament_ui_colors(unsigned int idx_extruder, wxBitmapComboBox *ui)
|
||||
{
|
||||
this->update_platter_filament_ui(idx_extruder, ui);
|
||||
return;
|
||||
|
||||
unsigned char rgb[3];
|
||||
std::string extruder_color = this->printers.get_edited_preset().config.opt_string("extruder_colour", idx_extruder);
|
||||
if (! parse_color(extruder_color, rgb))
|
||||
// Extruder color is not defined.
|
||||
extruder_color.clear();
|
||||
|
||||
ui->Freeze();
|
||||
for (unsigned int ui_id = 0; ui_id < ui->GetCount(); ++ ui_id) {
|
||||
std::string preset_name = ui->GetString(ui_id).utf8_str().data();
|
||||
size_t filament_preset_id = size_t(ui->GetClientData(ui_id));
|
||||
const Preset *filament_preset = filaments.find_preset(preset_name, false);
|
||||
assert(filament_preset != nullptr);
|
||||
// Assign an extruder color to the selected item if the extruder color is defined.
|
||||
std::string filament_rgb = filament_preset->config.opt_string("filament_colour", 0);
|
||||
std::string extruder_rgb = (int(ui_id) == ui->GetSelection() && ! extruder_color.empty()) ? extruder_color : filament_rgb;
|
||||
wxBitmap *bitmap = nullptr;
|
||||
if (filament_rgb == extruder_rgb) {
|
||||
auto it = m_mapColorToBitmap.find(filament_rgb);
|
||||
if (it == m_mapColorToBitmap.end()) {
|
||||
// Create the bitmap.
|
||||
parse_color(filament_rgb, rgb);
|
||||
wxImage image(24, 16);
|
||||
image.SetRGB(wxRect(0, 0, 24, 16), rgb[0], rgb[1], rgb[2]);
|
||||
m_mapColorToBitmap[filament_rgb] = new wxBitmap(image);
|
||||
} else {
|
||||
bitmap = it->second;
|
||||
}
|
||||
} else {
|
||||
std::string bitmap_key = filament_rgb + extruder_rgb;
|
||||
auto it = m_mapColorToBitmap.find(bitmap_key);
|
||||
if (it == m_mapColorToBitmap.end()) {
|
||||
// Create the bitmap.
|
||||
wxImage image(24, 16);
|
||||
parse_color(extruder_rgb, rgb);
|
||||
image.SetRGB(wxRect(0, 0, 16, 16), rgb[0], rgb[1], rgb[2]);
|
||||
parse_color(filament_rgb, rgb);
|
||||
image.SetRGB(wxRect(16, 0, 8, 16), rgb[0], rgb[1], rgb[2]);
|
||||
m_mapColorToBitmap[filament_rgb] = new wxBitmap(image);
|
||||
} else {
|
||||
bitmap = it->second;
|
||||
}
|
||||
}
|
||||
ui->SetItemBitmap(ui_id, *bitmap);
|
||||
}
|
||||
ui->Thaw();
|
||||
}
|
||||
|
||||
void PresetBundle::set_default_suppressed(bool default_suppressed)
|
||||
{
|
||||
prints.set_default_suppressed(default_suppressed);
|
||||
|
|
|
@ -58,8 +58,6 @@ public:
|
|||
|
||||
// Update a filament selection combo box on the platter for an idx_extruder.
|
||||
void update_platter_filament_ui(unsigned int idx_extruder, wxBitmapComboBox *ui);
|
||||
// Update the colors preview at the platter extruder combo box.
|
||||
void update_platter_filament_ui_colors(unsigned int idx_extruder, wxBitmapComboBox *ui);
|
||||
|
||||
// Enable / disable the "- default -" preset.
|
||||
void set_default_suppressed(bool default_suppressed);
|
||||
|
@ -72,10 +70,17 @@ public:
|
|||
// update size and content of filament_presets.
|
||||
void update_multi_material_filament_presets();
|
||||
|
||||
// Update the is_compatible flag of all print and filament presets depending on whether they are marked
|
||||
// as compatible with the currently selected printer.
|
||||
// Also updates the is_visible flag of each preset.
|
||||
// If select_other_if_incompatible is true, then the print or filament preset is switched to some compatible
|
||||
// preset if the current print or filament preset is not compatible.
|
||||
void update_compatible_with_printer(bool select_other_if_incompatible);
|
||||
|
||||
private:
|
||||
void load_config_file_config(const std::string &path, const DynamicPrintConfig &config);
|
||||
void load_config_file_config_bundle(const std::string &path, const boost::property_tree::ptree &tree);
|
||||
bool load_compatible_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible);
|
||||
bool load_compatible_bitmaps();
|
||||
|
||||
// Indicator, that the preset is compatible with the selected printer.
|
||||
wxBitmap *m_bitmapCompatible;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <xsinit.h>
|
||||
#include "slic3r/GUI/Preset.hpp"
|
||||
#include "slic3r/GUI/PresetBundle.hpp"
|
||||
#include "slic3r/GUI/PresetHints.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::GUI::Preset} class Preset {
|
||||
|
@ -13,6 +14,7 @@
|
|||
bool external() %code%{ RETVAL = THIS->is_external; %};
|
||||
bool visible() %code%{ RETVAL = THIS->is_visible; %};
|
||||
bool dirty() %code%{ RETVAL = THIS->is_dirty; %};
|
||||
bool is_compatible_with_printer(char *active_printer) const;
|
||||
|
||||
const char* name() %code%{ RETVAL = THIS->name.c_str(); %};
|
||||
const char* file() %code%{ RETVAL = THIS->file.c_str(); %};
|
||||
|
@ -30,6 +32,7 @@
|
|||
Ref<Preset> default_preset() %code%{ RETVAL = &THIS->default_preset(); %};
|
||||
size_t size() const;
|
||||
size_t num_visible() const;
|
||||
std::string name() const;
|
||||
|
||||
Ref<Preset> get_selected_preset() %code%{ RETVAL = &THIS->get_selected_preset(); %};
|
||||
Ref<Preset> get_current_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
|
||||
|
@ -41,19 +44,20 @@
|
|||
bool current_is_dirty();
|
||||
std::vector<std::string> current_dirty_options();
|
||||
|
||||
void update_tab_ui(SV *ui)
|
||||
%code%{ auto cb = (wxChoice*)wxPli_sv_2_object( aTHX_ ui, "Wx::Choice" );
|
||||
THIS->update_tab_ui(cb); %};
|
||||
void update_tab_ui(SV *ui, bool show_incompatible)
|
||||
%code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object( aTHX_ ui, "Wx::BitmapComboBox" );
|
||||
THIS->update_tab_ui(cb, show_incompatible); %};
|
||||
|
||||
void update_platter_ui(SV *ui)
|
||||
%code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object( aTHX_ ui, "Wx::BitmapComboBox" );
|
||||
THIS->update_platter_ui(cb); %};
|
||||
|
||||
bool update_dirty_ui(SV *ui)
|
||||
%code%{ RETVAL = THIS->update_dirty_ui((wxChoice*)wxPli_sv_2_object(aTHX_ ui, "Wx::Choice")); %};
|
||||
%code%{ RETVAL = THIS->update_dirty_ui((wxBitmapComboBox*)wxPli_sv_2_object(aTHX_ ui, "Wx::BitmapComboBox")); %};
|
||||
|
||||
void select_preset(int idx);
|
||||
bool select_preset_by_name(char *name) %code%{ RETVAL = THIS->select_preset_by_name(name, true); %};
|
||||
void discard_current_changes();
|
||||
|
||||
void save_current_preset(char *new_name)
|
||||
%code%{
|
||||
|
@ -150,14 +154,21 @@ PresetCollection::arrayref()
|
|||
void set_filament_preset(int idx, const char *name);
|
||||
void update_multi_material_filament_presets();
|
||||
|
||||
void update_compatible_with_printer(bool select_other_if_incompatible);
|
||||
|
||||
Clone<DynamicPrintConfig> full_config() %code%{ RETVAL = THIS->full_config(); %};
|
||||
|
||||
void update_platter_filament_ui(int extruder_idx, SV *ui)
|
||||
%code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object(aTHX_ ui, "Wx::BitmapComboBox");
|
||||
THIS->update_platter_filament_ui(extruder_idx, cb); %};
|
||||
|
||||
void update_platter_filament_ui_colors(int extruder_idx, SV *ui)
|
||||
%code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object(aTHX_ ui, "Wx::BitmapComboBox");
|
||||
THIS->update_platter_filament_ui_colors(extruder_idx, cb); %};
|
||||
|
||||
};
|
||||
|
||||
%name{Slic3r::GUI::PresetHints} class PresetHints {
|
||||
PresetHints();
|
||||
~PresetHints();
|
||||
|
||||
static std::string cooling_description(Preset *preset)
|
||||
%code%{ RETVAL = PresetHints::cooling_description(*preset); %};
|
||||
static std::string maximum_volumetric_flow_description(PresetBundle *preset)
|
||||
%code%{ RETVAL = PresetHints::maximum_volumetric_flow_description(*preset); %};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue