mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 00:01:09 -06:00
First implementation of the "compatible_printers_condition"
for the print and filament profiles. Added documentation for building the boost library for Slic3r on Linux.
This commit is contained in:
parent
bb61de8379
commit
6b81f43206
7 changed files with 63 additions and 18 deletions
|
@ -139,6 +139,13 @@ PrintConfigDef::PrintConfigDef()
|
|||
def->label = "Compatible printers";
|
||||
def->default_value = new ConfigOptionStrings();
|
||||
|
||||
def = this->add("compatible_printers_condition", coString);
|
||||
def->label = "Compatible printers condition";
|
||||
def->tooltip = "A boolean expression using the configuration values of an active printer profile. "
|
||||
"If this expression evaluates to true, this profile is considered compatible "
|
||||
"with the active printer profile.";
|
||||
def->default_value = new ConfigOptionString();
|
||||
|
||||
def = this->add("complete_objects", coBool);
|
||||
def->label = "Complete individual objects";
|
||||
def->tooltip = "When printing multiple objects or copies, this feature will complete "
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "../../libslic3r/libslic3r.h"
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
#include "../../libslic3r/PlaceholderParser.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -141,16 +142,26 @@ std::string Preset::label() const
|
|||
return this->name + (this->is_dirty ? g_suffix_modified : "");
|
||||
}
|
||||
|
||||
bool Preset::is_compatible_with_printer(const std::string &active_printer) const
|
||||
bool Preset::is_compatible_with_printer(const Preset &active_printer) const
|
||||
{
|
||||
auto *condition = dynamic_cast<const ConfigOptionString*>(this->config.option("compatible_printers_condition"));
|
||||
if (condition != nullptr && ! condition->value.empty()) {
|
||||
try {
|
||||
return PlaceholderParser::evaluate_boolean_expression(condition->value, active_printer.config);
|
||||
} catch (const std::runtime_error &err) {
|
||||
//FIXME in case of an error, return "compatible with everything".
|
||||
printf("Preset::is_compatible_with_printer - parsing error of compatible_printers_condition %s:\n%s\n", active_printer.name.c_str(), err.what());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(this->config.option("compatible_printers"));
|
||||
return this->is_default || active_printer.empty() ||
|
||||
return this->is_default || active_printer.name.empty() ||
|
||||
compatible_printers == nullptr || compatible_printers->values.empty() ||
|
||||
std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer) !=
|
||||
std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer.name) !=
|
||||
compatible_printers->values.end();
|
||||
}
|
||||
|
||||
bool Preset::update_compatible_with_printer(const std::string &active_printer)
|
||||
bool Preset::update_compatible_with_printer(const Preset &active_printer)
|
||||
{
|
||||
return this->is_compatible = is_compatible_with_printer(active_printer);
|
||||
}
|
||||
|
@ -180,7 +191,7 @@ const std::vector<std::string>& Preset::print_options()
|
|||
"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",
|
||||
"compatible_printers"
|
||||
"compatible_printers", "compatible_printers_condition"
|
||||
};
|
||||
return s_opts;
|
||||
}
|
||||
|
@ -193,7 +204,7 @@ const std::vector<std::string>& Preset::filament_options()
|
|||
"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",
|
||||
"compatible_printers"
|
||||
"compatible_printers", "compatible_printers_condition"
|
||||
};
|
||||
return s_opts;
|
||||
}
|
||||
|
@ -395,7 +406,7 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
|
|||
}
|
||||
}
|
||||
|
||||
void PresetCollection::update_compatible_with_printer(const std::string &active_printer, bool select_other_if_incompatible)
|
||||
void PresetCollection::update_compatible_with_printer(const Preset &active_printer, bool select_other_if_incompatible)
|
||||
{
|
||||
for (size_t idx_preset = 1; idx_preset < m_presets.size(); ++ idx_preset) {
|
||||
bool selected = idx_preset == m_idx_selected;
|
||||
|
@ -490,9 +501,11 @@ std::vector<std::string> PresetCollection::current_dirty_options() const
|
|||
// The "compatible_printers" option key is handled differently from the others:
|
||||
// It is not mandatory. If the key is missing, it means it is compatible with any printer.
|
||||
// If the key exists and it is empty, it means it is compatible with no printer.
|
||||
const char compatible_printers[] = "compatible_printers";
|
||||
if (this->get_selected_preset().config.has(compatible_printers) != this->get_edited_preset().config.has(compatible_printers))
|
||||
changed.emplace_back(compatible_printers);
|
||||
std::initializer_list<const char*> optional_keys { "compatible_printers", "compatible_printers_condition" };
|
||||
for (auto &opt_key : optional_keys) {
|
||||
if (this->get_selected_preset().config.has(opt_key) != this->get_edited_preset().config.has(opt_key))
|
||||
changed.emplace_back(opt_key);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,9 +79,9 @@ public:
|
|||
void set_dirty(bool dirty = true) { this->is_dirty = dirty; }
|
||||
void reset_dirty() { this->is_dirty = false; }
|
||||
|
||||
bool is_compatible_with_printer(const std::string &active_printer) const;
|
||||
bool is_compatible_with_printer(const Preset &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);
|
||||
bool update_compatible_with_printer(const Preset &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); }
|
||||
|
@ -180,7 +180,7 @@ public:
|
|||
size_t size() const { return this->m_presets.size(); }
|
||||
|
||||
// For Print / Filament presets, disable those, which are not compatible with the printer.
|
||||
void update_compatible_with_printer(const std::string &active_printer, bool select_other_if_incompatible);
|
||||
void update_compatible_with_printer(const Preset &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;}); }
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@ PresetBundle::PresetBundle() :
|
|||
this->printers.preset(0).config.opt_string("print_settings_id", true);
|
||||
// Create the "compatible printers" keys, as they are not part of the Static print config classes.
|
||||
this->filaments.preset(0).config.optptr("compatible_printers", true);
|
||||
this->filaments.preset(0).config.optptr("compatible_printers_condition", true);
|
||||
this->prints.preset(0).config.optptr("compatible_printers", true);
|
||||
this->prints.preset(0).config.optptr("compatible_printers_condition", true);
|
||||
|
||||
this->prints .load_bitmap_default("cog.png");
|
||||
this->filaments.load_bitmap_default("spool.png");
|
||||
|
@ -537,8 +539,8 @@ void PresetBundle::update_multi_material_filament_presets()
|
|||
|
||||
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);
|
||||
this->prints.update_compatible_with_printer(this->printers.get_edited_preset(), select_other_if_incompatible);
|
||||
this->filaments.update_compatible_with_printer(this->printers.get_edited_preset(), select_other_if_incompatible);
|
||||
if (select_other_if_incompatible) {
|
||||
// Verify validity of the current filament presets.
|
||||
for (std::string &filament_name : this->filament_presets) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue