Skip to content

Commit

Permalink
feat: add model_name and plate_number placeholders
Browse files Browse the repository at this point in the history
This uses the BBS project name from the `Project` tab which could be
susceptible to upstream changes removing this feature.

The project_name template only works when you open a 3MF file. If you
create a new project and set the project name `Model.model_info` is
always null whether you save the project or not. If you save the current
project, switch to a new project/different project, then re-load it then
the template works as expected.

The plate number is assumed to always be <100 which matches the
formatting of the plate number in the UI.

Relates-To: #3816
  • Loading branch information
Deadleg committed May 24, 2024
1 parent 1701cbc commit dad49b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
this->placeholder_parser().set("first_layer_temperature", new ConfigOptionInts(m_config.nozzle_temperature_initial_layer));
this->placeholder_parser().set("max_print_height",new ConfigOptionInt(m_config.printable_height));
this->placeholder_parser().set("z_offset", new ConfigOptionFloat(m_config.z_offset));
this->placeholder_parser().set("model_name", new ConfigOptionString(print.get_model_name()));
this->placeholder_parser().set("plate_number", new ConfigOptionString(print.get_plate_number_formatted()));
this->placeholder_parser().set("plate_name", new ConfigOptionString(print.get_plate_name()));
this->placeholder_parser().set("first_layer_height", new ConfigOptionFloat(m_config.initial_layer_print_height.value));

Expand Down
20 changes: 20 additions & 0 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,10 +2841,30 @@ std::string Print::output_filename(const std::string &filename_base) const
DynamicConfig config = this->finished() ? this->print_statistics().config() : this->print_statistics().placeholders();
config.set_key_value("num_filaments", new ConfigOptionInt((int)m_config.nozzle_diameter.size()));
config.set_key_value("plate_name", new ConfigOptionString(get_plate_name()));
config.set_key_value("plate_number", new ConfigOptionString(get_plate_number_formatted()));
config.set_key_value("model_name", new ConfigOptionString(get_model_name()));

return this->PrintBase::output_filename(m_config.filename_format.value, ".gcode", filename_base, &config);
}

std::string Print::get_model_name() const
{
if (model().model_info != nullptr)
{
return model().model_info->model_name;
} else {
return "";
}
}

std::string Print::get_plate_number_formatted() const
{
std::string plate_number = std::to_string(get_plate_index() + 1);
static const size_t n_zero = 2;

return std::string(n_zero - std::min(n_zero, plate_number.length()), '0') + plate_number;
}

//BBS: add gcode file preload logic
void Print::set_gcode_file_ready()
{
Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/Print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ class Print : public PrintBaseWithState<PrintStep, psCount>

std::string output_filename(const std::string &filename_base = std::string()) const override;

std::string get_model_name() const;
std::string get_plate_number_formatted() const;

size_t num_print_regions() const throw() { return m_print_regions.size(); }
const PrintRegion& get_print_region(size_t idx) const { return *m_print_regions[idx]; }
const ToolOrdering& get_tool_ordering() const { return m_wipe_tower_data.tool_ordering; }
Expand Down

0 comments on commit dad49b2

Please sign in to comment.