Skip to content

Commit

Permalink
more fixes, fix changing extruder at start on a not-mmu
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed May 23, 2024
2 parents c02a986 + f488430 commit 57a9bdb
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 63 deletions.
8 changes: 4 additions & 4 deletions BuildLinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ then
apt install g++ m4
if [[ -z "$FOUND_GTK3" ]]
then
echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext
echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse\n"
apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse
else
echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext
echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse\n"
apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse
fi
# for ubuntu 22.04:
ubu_version="$(cat /etc/issue)"
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.13)
project(Slic3r-native)

add_subdirectory(build-utils)
add_subdirectory(test-utils)
if (NOT APPLE)
add_subdirectory(test-utils)
endif ()
add_subdirectory(admesh)
add_subdirectory(avrdude)
# boost/nowide
Expand Down
186 changes: 156 additions & 30 deletions src/libslic3r/GCode.cpp

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ class Wipe {
public:
bool enable;
Polyline path;


void append(const Point &p);
void append(const Polyline &p);
void set(const Polyline &p);
void reverse() { path.reverse(); }
void clip_start(coord_t dist) { path.clip_start(dist); }
void translate(const Point &trsl) { path.translate(trsl); }

Wipe() : enable(false) {}
bool has_path() const { return !this->path.points.empty(); }
void reset_path() { this->path = Polyline(); }
Expand Down
13 changes: 12 additions & 1 deletion src/libslic3r/GCode/CoolingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct CoolingLine
TYPE_G2 = 1 << 20,
TYPE_G3 = 1 << 21,
// Would be TYPE_ADJUSTABLE, but the block of G-code lines has zero extrusion length, thus the block
// cannot have its speed adjusted. This should not happen (sic!).
// cannot have its speed adjusted. This should not happen (sic!). (delete the block if no g1)
TYPE_ADJUSTABLE_EMPTY = 1 << 22,
};
static inline ExtrusionRole to_extrusion_role(uint32_t type) {
Expand Down Expand Up @@ -412,6 +412,12 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
// There should be at least some extrusion move inside the adjustment block.
// However if the block has no extrusion (which is wrong), fix it for the cooling buffer to work.
//FIXME: Pressure equalizer add EXTRUDE_SET_SPEED_TAG withotu removing the previous one at the line before.
if (!ignore_empty && sm.length <= 0) {
// the mouvment has been deleted because it'ts too short for the precision.
// so soft-delete the CoolingLine (will be deleted in the apply layer cooldown func)
sm.type = CoolingLine::TYPE_ADJUSTABLE_EMPTY;
return;
}
assert(ignore_empty || sm.length > 0);
assert(ignore_empty || sm.time > 0);
if (sm.time <= 0) {
Expand Down Expand Up @@ -1134,6 +1140,11 @@ std::string CoolingBuffer::apply_layer_cooldown(
new_gcode.append(end, line_end - end);
}
}
} else if(line->type == CoolingLine::TYPE_ADJUSTABLE_EMPTY) {
// nothing useful, don't write it (an extrusion that don't move because it wasn't printed as it's too small).
std::string deleted(line_start, line_end - line_start);
boost::replace_all(deleted, "\n", "");
new_gcode.append(std::string("; deleted stuff: ") + deleted);
} else {
new_gcode.append(line_start, line_end - line_start);
}
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/GCode/GCodeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ void GCodeProcessor::reset()
// 1st move must be a dummy move
assert(m_result.moves.empty());
m_result.moves.emplace_back();
m_has_reset = true;

m_use_volumetric_e = false;
m_last_default_color_id = 0;
Expand Down
6 changes: 5 additions & 1 deletion src/libslic3r/GCode/GCodeProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ namespace Slic3r {
UsedFilaments m_used_filaments;

GCodeProcessorResult m_result;
bool m_has_reset = false;
static unsigned int s_result_id;

#if ENABLE_GCODE_VIEWER_DATA_CHECKING
Expand All @@ -621,7 +622,10 @@ namespace Slic3r {
void reset();

const GCodeProcessorResult& get_result() const { return m_result; }
GCodeProcessorResult&& extract_result() { return std::move(m_result); }
GCodeProcessorResult&& extract_result() {
m_has_reset = false;
return std::move(m_result);
}

// Load a G-code into a stand-alone G-code viewer.
// throws CanceledException through print->throw_if_canceled() (sent by the caller as callback).
Expand Down
76 changes: 61 additions & 15 deletions src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ std::string GCodeWriter::get_default_color_change_gcode(const GCodeConfig &confi

void GCodeWriter::apply_print_config(const PrintConfig &print_config)
{
this->multiple_extruders = false;
this->config.apply(print_config, true);
m_extrusion_axis = get_extrusion_axis(this->config);
m_single_extruder_multi_material = print_config.single_extruder_multi_material.value;
Expand Down Expand Up @@ -343,6 +344,8 @@ std::string GCodeWriter::write_acceleration(){

std::string GCodeWriter::reset_e(bool force)
{
this->m_de_left = 0;

if (FLAVOR_IS(gcfMach3)
|| FLAVOR_IS(gcfMakerWare)
|| FLAVOR_IS(gcfSailfish))
Expand Down Expand Up @@ -472,16 +475,25 @@ std::string GCodeWriter::travel_to_xy(const Vec2d &point, const double speed, co
if ((speed > 0) & (speed < travel_speed))
travel_speed = speed;

std::string str_x = XYZ_NUM(point.x());
std::string str_y = XYZ_NUM(point.y());
if (!m_pos_str_x.empty() && m_pos_str_x == str_x && m_pos_str_y == str_y) {
//if point too close to the other, then do not write it, it's useless.
return "";
}

m_pos.x() = point.x();
m_pos.y() = point.y();

m_pos_str_x = std::move(str_x);
m_pos_str_y = std::move(str_y);

// GCodeG1Formatter w;
// w.emit_xy(point);
// w.emit_f(this->config.travel_speed.value * 60.0);
// w.emit_comment(this->config.gcode_comments, comment);
// return w.string();
gcode << "G1 X" << XYZ_NUM(point.x())
<< " Y" << XYZ_NUM(point.y())
gcode << "G1 X" << m_pos_str_x
<< " Y" << m_pos_str_y
<< " F" << F_NUM(travel_speed * 60);
COMMENT(comment);
gcode << "\n";
Expand Down Expand Up @@ -513,15 +525,17 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const double speed, c
the lift. */
m_lifted = 0;
m_pos = point;
m_pos_str_x = XYZ_NUM(point.x());
m_pos_str_y = XYZ_NUM(point.y());

double travel_speed = this->config.travel_speed.value;
if ((speed > 0) & (speed < travel_speed))
travel_speed = speed;

std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 X" << XYZ_NUM(point.x())
<< " Y" << XYZ_NUM(point.y());
gcode << "G1 X" << m_pos_str_x
<< " Y" << m_pos_str_y;
if (config.z_step > SCALING_FACTOR)
gcode << " Z" << PRECISION(point.z(), 6);
else
Expand Down Expand Up @@ -590,19 +604,47 @@ bool GCodeWriter::will_move_z(double z) const
return true;
}

std::pair<std::string, bool> GCodeWriter::_compute_de(double dE)
{
bool is_extrude = this->m_tool->extrude(dE) != 0;
std::string e_str;
if (is_extrude) {
// add missing de from rounding, compute the new rounding.
e_str = E_NUM(m_tool->E() + this->m_de_left);
double written_e = atof(e_str.c_str());
is_extrude = written_e != 0;
if (is_extrude) {
this->m_de_left = (m_tool->E() + this->m_de_left) - written_e;
} else {
this->m_de_left += dE;
}
}
return {e_str, is_extrude};
}

std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std::string &comment)
{
assert(dE == dE);
assert(m_pos.x() != point.x() || m_pos.y() != point.y());
std::string str_x = XYZ_NUM(point.x());
std::string str_y = XYZ_NUM(point.y());
if (!m_pos_str_x.empty() && m_pos_str_x == str_x && m_pos_str_y == str_y) {
//if point too close to the other, then do not write it, it's useless.
this->m_de_left += dE;
return "";
}
m_pos.x() = point.x();
m_pos.y() = point.y();
bool is_extrude = m_tool->extrude(dE) != 0;
m_pos_str_x = std::move(str_x);
m_pos_str_y = std::move(str_y);
auto [e_str, is_extrude] = this->_compute_de(dE);

std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 X" << XYZ_NUM(point.x())
<< " Y" << XYZ_NUM(point.y());
gcode << "G1 X" << m_pos_str_x
<< " Y" << m_pos_str_y;
if(is_extrude)
gcode << " " << m_extrusion_axis << E_NUM(m_tool->E());
gcode << " " << m_extrusion_axis << e_str;
COMMENT(comment);
gcode << "\n";
return gcode.str();
Expand All @@ -615,13 +657,15 @@ std::string GCodeWriter::extrude_arc_to_xy(const Vec2d& point, const Vec2d& cent
{
m_pos.x() = point.x();
m_pos.y() = point.y();
bool is_extrude = m_tool->extrude(dE) != 0;
m_pos_str_x = XYZ_NUM(point.x());
m_pos_str_y = XYZ_NUM(point.y());
auto [e_str, is_extrude] = this->_compute_de(dE);

GCodeG2G3Formatter w(this->config.gcode_precision_xyz.value, this->config.gcode_precision_e.value, is_ccw);
w.emit_xy(point);
w.emit_ij(center_offset);
if (is_extrude)
w.emit_e(m_extrusion_axis, m_tool->E());
w.emit(m_extrusion_axis, e_str);
//BBS
w.emit_comment(this->config.gcode_comments, comment);
return w.string();
Expand All @@ -632,8 +676,10 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
assert(dE == dE);
m_pos.x() = point.x();
m_pos.y() = point.y();
m_pos_str_x = XYZ_NUM(point.x());
m_pos_str_y = XYZ_NUM(point.y());
m_lifted = 0;
bool is_extrude = m_tool->extrude(dE) != 0;
auto [e_str, is_extrude] = this->_compute_de(dE);

// GCodeG1Formatter w;
// w.emit_xyz(point);
Expand All @@ -642,11 +688,11 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
// return w.string();
std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 X" << XYZ_NUM(point.x())
<< " Y" << XYZ_NUM(point.y())
gcode << "G1 X" << m_pos_str_x
<< " Y" << m_pos_str_y
<< " Z" << XYZ_NUM(point.z() + m_pos.z());
if (is_extrude)
gcode << " " << m_extrusion_axis << E_NUM(m_tool->E());
gcode << " " << m_extrusion_axis << e_str;
COMMENT(comment);
gcode << "\n";
// replace 'Z-0' by ' Z0'
Expand Down
20 changes: 19 additions & 1 deletion src/libslic3r/GCodeWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Slic3r {
class GCodeWriter {
public:
GCodeConfig config;
bool multiple_extruders;
bool multiple_extruders = false;
// override from region
const PrintRegionConfig* config_region = nullptr;

Expand Down Expand Up @@ -108,6 +108,13 @@ class GCodeWriter {
// current lift, to remove from m_pos to have the current height.
double m_lifted = 0;
Vec3d m_pos = Vec3d::Zero();
// cached string representation of x & y m_pos
std::string m_pos_str_x;
std::string m_pos_str_y;
// stored de that wasn't written, because of the rounding
double m_de_left = 0;
std::pair<std::string, bool> _compute_de(double dE);


std::string _travel_to_z(double z, const std::string &comment);
std::string _retract(double length, std::optional<double> restart_extra, std::optional<double> restart_extra_toolchange, const std::string &comment);
Expand Down Expand Up @@ -179,6 +186,17 @@ class GCodeFormatter {
}
}

void emit(const std::string &axis, std::string str) {
if (! axis.empty()) {
* ptr_err_ptr++ = ' ';
assert(axis.size() == 1);
*ptr_err_ptr++ = axis.front();
for (char c : str) {
* ptr_err_ptr++ = c;
}
}
}

void emit_f(double speed) {
this->emit_axis('F', speed, m_gcode_precision_xyz);
}
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/ObjectID.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define slic3r_ObjectID_hpp_

#include <cereal/access.hpp>
#include <cereal/types/base_class.hpp>

namespace Slic3r {

Expand Down
19 changes: 19 additions & 0 deletions src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,13 @@ ExtrusionPaths PerimeterGenerator::create_overhangs(const ClipperLib_Z::Path& ar
is_external ? this->ext_perimeter_flow : this->perimeter_flow,
std::max(this->ext_perimeter_flow.scaled_width() / 4, scale_t(this->print_config->resolution)),
(is_external ? this->ext_perimeter_flow : this->perimeter_flow).scaled_width() / 10);
if (thickpaths.empty()) {
// Note: can create problem with chain_and_reorder_extrusion_paths
assert(extrusion_path.size() < 2 ||
Point(extrusion_path.front().x(), extrusion_path.front().y())
.coincides_with_epsilon(Point(extrusion_path.back().x(), extrusion_path.back().y())));
continue;
}
#ifdef _DEBUG
for (int i = 1; i < thickpaths.size(); i++) {
assert(thickpaths[i - 1].last_point() == thickpaths[i].first_point());
Expand Down Expand Up @@ -3429,6 +3436,10 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_extrusions(std::vector<P
}

chain_and_reorder_extrusion_paths(paths, &start_point);
for(size_t i = 1; i< paths.size(); ++i)
assert(paths[i-1].last_point().coincides_with_epsilon(paths[i].first_point()));
if(extrusion->is_closed)
assert(paths.back().last_point().coincides_with_epsilon(paths.front().first_point()));
}
} else {
append(paths, Geometry::unsafe_variable_width(Arachne::to_thick_polyline(*extrusion),
Expand Down Expand Up @@ -3467,7 +3478,15 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_extrusions(std::vector<P

// Append paths to collection.
if (!paths.empty()) {
for (size_t idx_path = 0; idx_path < paths.size(); ++idx_path) {
if (idx_path > 0)
assert(paths[idx_path - 1].last_point().coincides_with_epsilon(paths[idx_path].first_point()));
for (size_t idx_pt = 1; idx_pt < paths[idx_path].size(); ++idx_pt) {
assert(!paths[idx_path].polyline.get_points()[idx_pt - 1].coincides_with_epsilon(paths[idx_path].polyline.get_points()[idx_pt]));
}
}
if (extrusion->is_closed) {
assert(paths.back().last_point().coincides_with_epsilon(paths.front().first_point()));
ExtrusionLoop extrusion_loop(std::move(paths), loop_role);
// Restore the orientation of the extrusion loop.
//TODO: use if (loop.is_steep_overhang && this->layer->id() % 2 == 1) to make_clockwise => need to detect is_steep_overhang on the arachne path
Expand Down
Loading

0 comments on commit 57a9bdb

Please sign in to comment.