Skip to content

Commit

Permalink
#1047 "colour" settings can now be used as XXX_colour_int to output t…
Browse files Browse the repository at this point in the history
…he color value as a int in a custom_gcode output
  • Loading branch information
remi durand committed Apr 3, 2021
1 parent 099c209 commit fd743c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,24 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
print.throw_if_canceled();
}

std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override)
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, DynamicConfig *config_override)
{
DynamicConfig default_config;
if (config_override == nullptr)
config_override = &default_config;
try {
//add some config conversion for colors
auto func_add_colour = [config_override](std::string key, std::string colour) {
if (colour.length() == 7) {
config_override->set_key_value(key, new ConfigOptionInt((int)strtol(colour.substr(1, 6).c_str(), NULL, 16)));
}
};
if (current_extruder_id >= 0 && current_extruder_id < config().filament_colour.size()) {
func_add_colour("filament_colour_int", config().filament_colour.values[current_extruder_id]);
func_add_colour("extruder_colour_int", config().extruder_colour.values[current_extruder_id]);
}
func_add_colour("thumbnails_color_int", config().thumbnails_color);

std::string gcode = m_placeholder_parser.process(templ, current_extruder_id, config_override, &m_placeholder_parser_context);
if (!gcode.empty() && m_config.gcode_comments) {
gcode = "; custom gcode: " + name + "\n" + gcode;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class GCode : ExtrusionVisitorConst {
const PlaceholderParser& placeholder_parser() const { return m_placeholder_parser; }
// Process a template through the placeholder parser, collect error messages to be reported
// inside the generated string and after the G-code export finishes.
std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override = nullptr);
std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, DynamicConfig *config_override = nullptr);
bool enable_cooling_markers() const { return m_enable_cooling_markers; }
std::string extrusion_role_to_string_for_parser(const ExtrusionRole &);

Expand Down

0 comments on commit fd743c6

Please sign in to comment.