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:
Joseph Lenox 2017-06-03 19:26:58 -05:00
parent fccdd12fba
commit e064fdf170
11 changed files with 89 additions and 17 deletions

View File

@ -72,9 +72,8 @@ sub export {
my @lt = localtime;
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];
# Write notes (content of the Print Settings tab -> Notes)
print $fh "; $_\n" foreach split /\R/, $self->config->notes;
print $fh "\n" if $self->config->notes;
# Write notes (content of all Settings tabs -> Notes)
print $fh $gcodegen->notes;
# Write some terse information on the slicing parameters.
my $first_object = $self->objects->[0];
my $layer_height = $first_object->config->layer_height;

View File

@ -262,6 +262,12 @@ GCode::set_origin(const Pointf &pointf)
this->origin = pointf;
}
std::string
GCode::notes()
{
return this->writer.notes();
}
std::string
GCode::preamble()
{

View File

@ -100,6 +100,7 @@ class GCode {
void set_extruders(const std::vector<unsigned int> &extruder_ids);
void set_origin(const Pointf &pointf);
std::string preamble();
std::string notes();
std::string change_layer(const Layer &layer);
std::string extrude(const ExtrusionEntity &entity, std::string description = "", double speed = -1);
std::string extrude(ExtrusionLoop loop, std::string description = "", double speed = -1);

View File

@ -1,4 +1,5 @@
#include "GCodeWriter.hpp"
#include "utils.hpp"
#include <algorithm>
#include <iomanip>
#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;
}
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
GCodeWriter::preamble()
{
std::ostringstream gcode;
if (FLAVOR_IS_NOT(gcfMakerWare)) {
gcode << "G21 ; set units to millimeters\n";
gcode << "G90 ; use absolute coordinates\n";
@ -49,7 +90,8 @@ GCodeWriter::preamble()
}
gcode << this->reset_e(true);
}
return gcode.str();
}

View File

@ -23,6 +23,7 @@ public:
std::string extrusion_axis() const { return this->_extrusion_axis; }
void apply_print_config(const PrintConfig &print_config);
void set_extruders(const std::vector<unsigned int> &extruder_ids);
std::string notes();
std::string preamble();
std::string postamble() const;
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const;

View File

@ -924,18 +924,14 @@ PrintConfigDef::PrintConfigDef()
def->height = 60;
def->default_value = new ConfigOptionStrings();
def = this->add("printer_notes", coStrings);
def = this->add("printer_notes", coString);
def->label = "Printer notes";
def->tooltip = "You can put your notes regarding the printer here.";
def->cli = "printer-notes=s@";
def->multiline = true;
def->full_width = true;
def->height = 130;
{
ConfigOptionStrings* opt = new ConfigOptionStrings();
opt->values.push_back("");
def->default_value = opt;
}
def->default_value = new ConfigOptionString("");
def = this->add("print_settings_id", coString);
def->default_value = new ConfigOptionString("");

View File

@ -301,12 +301,15 @@ class GCodeConfig : public virtual StaticPrintConfig
ConfigOptionFloats filament_density;
ConfigOptionFloats filament_cost;
ConfigOptionFloats filament_max_volumetric_speed;
ConfigOptionStrings filament_notes;
ConfigOptionBool gcode_comments;
ConfigOptionEnum<GCodeFlavor> gcode_flavor;
ConfigOptionString layer_gcode;
ConfigOptionFloat max_print_speed;
ConfigOptionFloat max_volumetric_speed;
ConfigOptionString notes;
ConfigOptionFloat pressure_advance;
ConfigOptionString printer_notes;
ConfigOptionFloats retract_length;
ConfigOptionFloats retract_length_toolchange;
ConfigOptionFloats retract_lift;
@ -339,12 +342,15 @@ class GCodeConfig : public virtual StaticPrintConfig
OPT_PTR(filament_density);
OPT_PTR(filament_cost);
OPT_PTR(filament_max_volumetric_speed);
OPT_PTR(filament_notes);
OPT_PTR(gcode_comments);
OPT_PTR(gcode_flavor);
OPT_PTR(layer_gcode);
OPT_PTR(max_print_speed);
OPT_PTR(max_volumetric_speed);
OPT_PTR(notes);
OPT_PTR(pressure_advance);
OPT_PTR(printer_notes);
OPT_PTR(retract_length);
OPT_PTR(retract_length_toolchange);
OPT_PTR(retract_lift);
@ -399,7 +405,6 @@ class PrintConfig : public GCodeConfig
ConfigOptionBool fan_always_on;
ConfigOptionInt fan_below_layer_time;
ConfigOptionStrings filament_colour;
ConfigOptionStrings filament_notes;
ConfigOptionFloat first_layer_acceleration;
ConfigOptionInt first_layer_bed_temperature;
ConfigOptionFloatOrPercent first_layer_extrusion_width;
@ -413,14 +418,12 @@ class PrintConfig : public GCodeConfig
ConfigOptionInt min_fan_speed;
ConfigOptionFloat min_print_speed;
ConfigOptionFloat min_skirt_length;
ConfigOptionString notes;
ConfigOptionFloats nozzle_diameter;
ConfigOptionBool only_retract_when_crossing_perimeters;
ConfigOptionBool ooze_prevention;
ConfigOptionString output_filename_format;
ConfigOptionFloat perimeter_acceleration;
ConfigOptionStrings post_process;
ConfigOptionStrings printer_notes;
ConfigOptionFloat resolution;
ConfigOptionFloats retract_before_travel;
ConfigOptionBools retract_layer_change;
@ -462,7 +465,6 @@ class PrintConfig : public GCodeConfig
OPT_PTR(fan_always_on);
OPT_PTR(fan_below_layer_time);
OPT_PTR(filament_colour);
OPT_PTR(filament_notes);
OPT_PTR(first_layer_acceleration);
OPT_PTR(first_layer_bed_temperature);
OPT_PTR(first_layer_extrusion_width);
@ -476,14 +478,12 @@ class PrintConfig : public GCodeConfig
OPT_PTR(min_fan_speed);
OPT_PTR(min_print_speed);
OPT_PTR(min_skirt_length);
OPT_PTR(notes);
OPT_PTR(nozzle_diameter);
OPT_PTR(only_retract_when_crossing_perimeters);
OPT_PTR(ooze_prevention);
OPT_PTR(output_filename_format);
OPT_PTR(perimeter_acceleration);
OPT_PTR(post_process);
OPT_PTR(printer_notes);
OPT_PTR(resolution);
OPT_PTR(retract_before_travel);
OPT_PTR(retract_layer_change);

View File

@ -1,4 +1,6 @@
#include <xsinit.h>
#include "utils.hpp"
#include <regex>
void
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;
#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};
}

View 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

View File

@ -181,6 +181,7 @@
void set_origin(Pointf* pointf)
%code{% THIS->set_origin(*pointf); %};
std::string preamble();
std::string notes();
std::string change_layer(Layer* layer)
%code{% RETVAL = THIS->change_layer(*layer); %};
%name{extrude_loop} std::string extrude(ExtrusionLoop* loop, std::string description = "", double speed = -1)

View File

@ -18,6 +18,7 @@
void apply_print_config(PrintConfig* print_config)
%code{% THIS->apply_print_config(*print_config); %};
void set_extruders(std::vector<unsigned int> extruder_ids);
std::string notes();
std::string preamble();
std::string postamble();
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1);