mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-17 09:25:53 +08:00
Added notes to beginning of output gcode.
Order is Print -> Filament -> Printer. Empty fields should not produce any output. Also a bugfix - Printer notes were implemented as Strings when should have been String.
This commit is contained in:
parent
fccdd12fba
commit
e064fdf170
@ -72,9 +72,8 @@ sub export {
|
|||||||
my @lt = localtime;
|
my @lt = localtime;
|
||||||
printf $fh "; generated by Slic3r $Slic3r::VERSION on %04d-%02d-%02d at %02d:%02d:%02d\n\n",
|
printf $fh "; generated by Slic3r $Slic3r::VERSION on %04d-%02d-%02d at %02d:%02d:%02d\n\n",
|
||||||
$lt[5] + 1900, $lt[4]+1, $lt[3], $lt[2], $lt[1], $lt[0];
|
$lt[5] + 1900, $lt[4]+1, $lt[3], $lt[2], $lt[1], $lt[0];
|
||||||
# Write notes (content of the Print Settings tab -> Notes)
|
# Write notes (content of all Settings tabs -> Notes)
|
||||||
print $fh "; $_\n" foreach split /\R/, $self->config->notes;
|
print $fh $gcodegen->notes;
|
||||||
print $fh "\n" if $self->config->notes;
|
|
||||||
# Write some terse information on the slicing parameters.
|
# Write some terse information on the slicing parameters.
|
||||||
my $first_object = $self->objects->[0];
|
my $first_object = $self->objects->[0];
|
||||||
my $layer_height = $first_object->config->layer_height;
|
my $layer_height = $first_object->config->layer_height;
|
||||||
|
@ -262,6 +262,12 @@ GCode::set_origin(const Pointf &pointf)
|
|||||||
this->origin = pointf;
|
this->origin = pointf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
GCode::notes()
|
||||||
|
{
|
||||||
|
return this->writer.notes();
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
GCode::preamble()
|
GCode::preamble()
|
||||||
{
|
{
|
||||||
|
@ -100,6 +100,7 @@ class GCode {
|
|||||||
void set_extruders(const std::vector<unsigned int> &extruder_ids);
|
void set_extruders(const std::vector<unsigned int> &extruder_ids);
|
||||||
void set_origin(const Pointf &pointf);
|
void set_origin(const Pointf &pointf);
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
|
std::string notes();
|
||||||
std::string change_layer(const Layer &layer);
|
std::string change_layer(const Layer &layer);
|
||||||
std::string extrude(const ExtrusionEntity &entity, std::string description = "", double speed = -1);
|
std::string extrude(const ExtrusionEntity &entity, std::string description = "", double speed = -1);
|
||||||
std::string extrude(ExtrusionLoop loop, std::string description = "", double speed = -1);
|
std::string extrude(ExtrusionLoop loop, std::string description = "", double speed = -1);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "GCodeWriter.hpp"
|
#include "GCodeWriter.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -32,11 +33,51 @@ GCodeWriter::set_extruders(const std::vector<unsigned int> &extruder_ids)
|
|||||||
this->multiple_extruders = (*std::max_element(extruder_ids.begin(), extruder_ids.end())) > 0;
|
this->multiple_extruders = (*std::max_element(extruder_ids.begin(), extruder_ids.end())) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
GCodeWriter::notes()
|
||||||
|
{
|
||||||
|
std::ostringstream gcode;
|
||||||
|
|
||||||
|
// Write the contents of the three notes sections
|
||||||
|
// a semicolon at the beginning of each line.
|
||||||
|
if (this->config.notes.getString().size() > 0) {
|
||||||
|
gcode << "; Print Config Notes: \n";
|
||||||
|
std::vector<std::string> temp_line = split_at_regex(this->config.notes.getString(),"\n");
|
||||||
|
for (auto j = temp_line.cbegin(); j != temp_line.cend(); j++) {
|
||||||
|
gcode << "; " << *j << "\n";
|
||||||
|
}
|
||||||
|
gcode << "; \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i = this->config.filament_notes.values.cbegin(); i != this->config.filament_notes.values.cend(); i++) {
|
||||||
|
if (i->size() > 0) {
|
||||||
|
gcode << "; Filament notes: \n";
|
||||||
|
std::vector<std::string> temp_line = split_at_regex(*i,"\n");
|
||||||
|
for (auto j = temp_line.cbegin(); j != temp_line.cend(); j++) {
|
||||||
|
gcode << "; " << *j << "\n";
|
||||||
|
}
|
||||||
|
gcode << "; \n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->config.printer_notes.getString().size() > 0) {
|
||||||
|
gcode << "; Printer Config Notes: \n";
|
||||||
|
std::vector<std::string> temp_line = split_at_regex(this->config.printer_notes.getString(),"\n");
|
||||||
|
for (auto j = temp_line.cbegin(); j != temp_line.cend(); j++) {
|
||||||
|
gcode << "; " << *j << "\n";
|
||||||
|
}
|
||||||
|
gcode << "; \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return gcode.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
GCodeWriter::preamble()
|
GCodeWriter::preamble()
|
||||||
{
|
{
|
||||||
std::ostringstream gcode;
|
std::ostringstream gcode;
|
||||||
|
|
||||||
if (FLAVOR_IS_NOT(gcfMakerWare)) {
|
if (FLAVOR_IS_NOT(gcfMakerWare)) {
|
||||||
gcode << "G21 ; set units to millimeters\n";
|
gcode << "G21 ; set units to millimeters\n";
|
||||||
gcode << "G90 ; use absolute coordinates\n";
|
gcode << "G90 ; use absolute coordinates\n";
|
||||||
@ -49,7 +90,8 @@ GCodeWriter::preamble()
|
|||||||
}
|
}
|
||||||
gcode << this->reset_e(true);
|
gcode << this->reset_e(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return gcode.str();
|
return gcode.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
std::string extrusion_axis() const { return this->_extrusion_axis; }
|
std::string extrusion_axis() const { return this->_extrusion_axis; }
|
||||||
void apply_print_config(const PrintConfig &print_config);
|
void apply_print_config(const PrintConfig &print_config);
|
||||||
void set_extruders(const std::vector<unsigned int> &extruder_ids);
|
void set_extruders(const std::vector<unsigned int> &extruder_ids);
|
||||||
|
std::string notes();
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
std::string postamble() const;
|
std::string postamble() const;
|
||||||
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const;
|
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const;
|
||||||
|
@ -924,18 +924,14 @@ PrintConfigDef::PrintConfigDef()
|
|||||||
def->height = 60;
|
def->height = 60;
|
||||||
def->default_value = new ConfigOptionStrings();
|
def->default_value = new ConfigOptionStrings();
|
||||||
|
|
||||||
def = this->add("printer_notes", coStrings);
|
def = this->add("printer_notes", coString);
|
||||||
def->label = "Printer notes";
|
def->label = "Printer notes";
|
||||||
def->tooltip = "You can put your notes regarding the printer here.";
|
def->tooltip = "You can put your notes regarding the printer here.";
|
||||||
def->cli = "printer-notes=s@";
|
def->cli = "printer-notes=s@";
|
||||||
def->multiline = true;
|
def->multiline = true;
|
||||||
def->full_width = true;
|
def->full_width = true;
|
||||||
def->height = 130;
|
def->height = 130;
|
||||||
{
|
def->default_value = new ConfigOptionString("");
|
||||||
ConfigOptionStrings* opt = new ConfigOptionStrings();
|
|
||||||
opt->values.push_back("");
|
|
||||||
def->default_value = opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
def = this->add("print_settings_id", coString);
|
def = this->add("print_settings_id", coString);
|
||||||
def->default_value = new ConfigOptionString("");
|
def->default_value = new ConfigOptionString("");
|
||||||
|
@ -301,12 +301,15 @@ class GCodeConfig : public virtual StaticPrintConfig
|
|||||||
ConfigOptionFloats filament_density;
|
ConfigOptionFloats filament_density;
|
||||||
ConfigOptionFloats filament_cost;
|
ConfigOptionFloats filament_cost;
|
||||||
ConfigOptionFloats filament_max_volumetric_speed;
|
ConfigOptionFloats filament_max_volumetric_speed;
|
||||||
|
ConfigOptionStrings filament_notes;
|
||||||
ConfigOptionBool gcode_comments;
|
ConfigOptionBool gcode_comments;
|
||||||
ConfigOptionEnum<GCodeFlavor> gcode_flavor;
|
ConfigOptionEnum<GCodeFlavor> gcode_flavor;
|
||||||
ConfigOptionString layer_gcode;
|
ConfigOptionString layer_gcode;
|
||||||
ConfigOptionFloat max_print_speed;
|
ConfigOptionFloat max_print_speed;
|
||||||
ConfigOptionFloat max_volumetric_speed;
|
ConfigOptionFloat max_volumetric_speed;
|
||||||
|
ConfigOptionString notes;
|
||||||
ConfigOptionFloat pressure_advance;
|
ConfigOptionFloat pressure_advance;
|
||||||
|
ConfigOptionString printer_notes;
|
||||||
ConfigOptionFloats retract_length;
|
ConfigOptionFloats retract_length;
|
||||||
ConfigOptionFloats retract_length_toolchange;
|
ConfigOptionFloats retract_length_toolchange;
|
||||||
ConfigOptionFloats retract_lift;
|
ConfigOptionFloats retract_lift;
|
||||||
@ -339,12 +342,15 @@ class GCodeConfig : public virtual StaticPrintConfig
|
|||||||
OPT_PTR(filament_density);
|
OPT_PTR(filament_density);
|
||||||
OPT_PTR(filament_cost);
|
OPT_PTR(filament_cost);
|
||||||
OPT_PTR(filament_max_volumetric_speed);
|
OPT_PTR(filament_max_volumetric_speed);
|
||||||
|
OPT_PTR(filament_notes);
|
||||||
OPT_PTR(gcode_comments);
|
OPT_PTR(gcode_comments);
|
||||||
OPT_PTR(gcode_flavor);
|
OPT_PTR(gcode_flavor);
|
||||||
OPT_PTR(layer_gcode);
|
OPT_PTR(layer_gcode);
|
||||||
OPT_PTR(max_print_speed);
|
OPT_PTR(max_print_speed);
|
||||||
OPT_PTR(max_volumetric_speed);
|
OPT_PTR(max_volumetric_speed);
|
||||||
|
OPT_PTR(notes);
|
||||||
OPT_PTR(pressure_advance);
|
OPT_PTR(pressure_advance);
|
||||||
|
OPT_PTR(printer_notes);
|
||||||
OPT_PTR(retract_length);
|
OPT_PTR(retract_length);
|
||||||
OPT_PTR(retract_length_toolchange);
|
OPT_PTR(retract_length_toolchange);
|
||||||
OPT_PTR(retract_lift);
|
OPT_PTR(retract_lift);
|
||||||
@ -399,7 +405,6 @@ class PrintConfig : public GCodeConfig
|
|||||||
ConfigOptionBool fan_always_on;
|
ConfigOptionBool fan_always_on;
|
||||||
ConfigOptionInt fan_below_layer_time;
|
ConfigOptionInt fan_below_layer_time;
|
||||||
ConfigOptionStrings filament_colour;
|
ConfigOptionStrings filament_colour;
|
||||||
ConfigOptionStrings filament_notes;
|
|
||||||
ConfigOptionFloat first_layer_acceleration;
|
ConfigOptionFloat first_layer_acceleration;
|
||||||
ConfigOptionInt first_layer_bed_temperature;
|
ConfigOptionInt first_layer_bed_temperature;
|
||||||
ConfigOptionFloatOrPercent first_layer_extrusion_width;
|
ConfigOptionFloatOrPercent first_layer_extrusion_width;
|
||||||
@ -413,14 +418,12 @@ class PrintConfig : public GCodeConfig
|
|||||||
ConfigOptionInt min_fan_speed;
|
ConfigOptionInt min_fan_speed;
|
||||||
ConfigOptionFloat min_print_speed;
|
ConfigOptionFloat min_print_speed;
|
||||||
ConfigOptionFloat min_skirt_length;
|
ConfigOptionFloat min_skirt_length;
|
||||||
ConfigOptionString notes;
|
|
||||||
ConfigOptionFloats nozzle_diameter;
|
ConfigOptionFloats nozzle_diameter;
|
||||||
ConfigOptionBool only_retract_when_crossing_perimeters;
|
ConfigOptionBool only_retract_when_crossing_perimeters;
|
||||||
ConfigOptionBool ooze_prevention;
|
ConfigOptionBool ooze_prevention;
|
||||||
ConfigOptionString output_filename_format;
|
ConfigOptionString output_filename_format;
|
||||||
ConfigOptionFloat perimeter_acceleration;
|
ConfigOptionFloat perimeter_acceleration;
|
||||||
ConfigOptionStrings post_process;
|
ConfigOptionStrings post_process;
|
||||||
ConfigOptionStrings printer_notes;
|
|
||||||
ConfigOptionFloat resolution;
|
ConfigOptionFloat resolution;
|
||||||
ConfigOptionFloats retract_before_travel;
|
ConfigOptionFloats retract_before_travel;
|
||||||
ConfigOptionBools retract_layer_change;
|
ConfigOptionBools retract_layer_change;
|
||||||
@ -462,7 +465,6 @@ class PrintConfig : public GCodeConfig
|
|||||||
OPT_PTR(fan_always_on);
|
OPT_PTR(fan_always_on);
|
||||||
OPT_PTR(fan_below_layer_time);
|
OPT_PTR(fan_below_layer_time);
|
||||||
OPT_PTR(filament_colour);
|
OPT_PTR(filament_colour);
|
||||||
OPT_PTR(filament_notes);
|
|
||||||
OPT_PTR(first_layer_acceleration);
|
OPT_PTR(first_layer_acceleration);
|
||||||
OPT_PTR(first_layer_bed_temperature);
|
OPT_PTR(first_layer_bed_temperature);
|
||||||
OPT_PTR(first_layer_extrusion_width);
|
OPT_PTR(first_layer_extrusion_width);
|
||||||
@ -476,14 +478,12 @@ class PrintConfig : public GCodeConfig
|
|||||||
OPT_PTR(min_fan_speed);
|
OPT_PTR(min_fan_speed);
|
||||||
OPT_PTR(min_print_speed);
|
OPT_PTR(min_print_speed);
|
||||||
OPT_PTR(min_skirt_length);
|
OPT_PTR(min_skirt_length);
|
||||||
OPT_PTR(notes);
|
|
||||||
OPT_PTR(nozzle_diameter);
|
OPT_PTR(nozzle_diameter);
|
||||||
OPT_PTR(only_retract_when_crossing_perimeters);
|
OPT_PTR(only_retract_when_crossing_perimeters);
|
||||||
OPT_PTR(ooze_prevention);
|
OPT_PTR(ooze_prevention);
|
||||||
OPT_PTR(output_filename_format);
|
OPT_PTR(output_filename_format);
|
||||||
OPT_PTR(perimeter_acceleration);
|
OPT_PTR(perimeter_acceleration);
|
||||||
OPT_PTR(post_process);
|
OPT_PTR(post_process);
|
||||||
OPT_PTR(printer_notes);
|
|
||||||
OPT_PTR(resolution);
|
OPT_PTR(resolution);
|
||||||
OPT_PTR(retract_before_travel);
|
OPT_PTR(retract_before_travel);
|
||||||
OPT_PTR(retract_layer_change);
|
OPT_PTR(retract_layer_change);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include <xsinit.h>
|
#include <xsinit.h>
|
||||||
|
#include "utils.hpp"
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
void
|
void
|
||||||
confess_at(const char *file, int line, const char *func,
|
confess_at(const char *file, int line, const char *func,
|
||||||
@ -26,3 +28,13 @@ confess_at(const char *file, int line, const char *func,
|
|||||||
LEAVE;
|
LEAVE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>
|
||||||
|
split_at_regex(const std::string& input, const std::string& regex) {
|
||||||
|
// passing -1 as the submatch index parameter performs splitting
|
||||||
|
std::regex re(regex);
|
||||||
|
std::sregex_token_iterator
|
||||||
|
first{input.begin(), input.end(), re, -1},
|
||||||
|
last;
|
||||||
|
return {first, last};
|
||||||
|
}
|
||||||
|
13
xs/src/libslic3r/utils.hpp
Normal file
13
xs/src/libslic3r/utils.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef UTILS_HPP
|
||||||
|
#define UTILS_HPP
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/// Utility functions that aren't necessarily part of libslic3r but are used by it.
|
||||||
|
|
||||||
|
/// Separate a string based on some regular expression string.
|
||||||
|
std::vector<std::string>
|
||||||
|
split_at_regex(const std::string& input, const std::string& regex);
|
||||||
|
|
||||||
|
#endif // UTILS_HPP
|
@ -181,6 +181,7 @@
|
|||||||
void set_origin(Pointf* pointf)
|
void set_origin(Pointf* pointf)
|
||||||
%code{% THIS->set_origin(*pointf); %};
|
%code{% THIS->set_origin(*pointf); %};
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
|
std::string notes();
|
||||||
std::string change_layer(Layer* layer)
|
std::string change_layer(Layer* layer)
|
||||||
%code{% RETVAL = THIS->change_layer(*layer); %};
|
%code{% RETVAL = THIS->change_layer(*layer); %};
|
||||||
%name{extrude_loop} std::string extrude(ExtrusionLoop* loop, std::string description = "", double speed = -1)
|
%name{extrude_loop} std::string extrude(ExtrusionLoop* loop, std::string description = "", double speed = -1)
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
void apply_print_config(PrintConfig* print_config)
|
void apply_print_config(PrintConfig* print_config)
|
||||||
%code{% THIS->apply_print_config(*print_config); %};
|
%code{% THIS->apply_print_config(*print_config); %};
|
||||||
void set_extruders(std::vector<unsigned int> extruder_ids);
|
void set_extruders(std::vector<unsigned int> extruder_ids);
|
||||||
|
std::string notes();
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
std::string postamble();
|
std::string postamble();
|
||||||
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1);
|
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user