Skip to content

Commit

Permalink
Fixed #126
Browse files Browse the repository at this point in the history
by re-shuffling the simplification of a path to be extruded.
A non-simplified path was being used for a wipe move before,
causing an extremely detailed path to be exported into a G-code.
  • Loading branch information
bubnikv committed Feb 15, 2017
1 parent 2ddabe5 commit 3bfa641
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
20 changes: 10 additions & 10 deletions xs/src/libslic3r/ExtrusionEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ double ExtrusionMultiPath::min_mm3_per_mm() const

Polyline ExtrusionMultiPath::as_polyline() const
{
size_t len = 0;
for (size_t i_path = 0; i_path < paths.size(); ++ i_path) {
assert(! paths[i_path].polyline.points.empty());
assert(i_path == 0 || paths[i_path - 1].polyline.points.back() == paths[i_path].polyline.points.front());
len += paths[i_path].polyline.points.size();
}
// The connecting points between the segments are equal.
len -= paths.size() - 1;

Polyline out;
if (len > 0) {
if (! paths.empty()) {
size_t len = 0;
for (size_t i_path = 0; i_path < paths.size(); ++ i_path) {
assert(! paths[i_path].polyline.points.empty());
assert(i_path == 0 || paths[i_path - 1].polyline.points.back() == paths[i_path].polyline.points.front());
len += paths[i_path].polyline.points.size();
}
// The connecting points between the segments are equal.
len -= paths.size() - 1;
assert(len > 0);
out.points.reserve(len);
out.points.push_back(paths.front().polyline.points.front());
for (size_t i_path = 0; i_path < paths.size(); ++ i_path)
Expand Down
37 changes: 19 additions & 18 deletions xs/src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ Wipe::wipe(GCode &gcodegen, bool toolchange)
/* Reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one
due to rounding (TODO: test and/or better math for this) */
double dE = length * (segment_length / wipe_dist) * 0.95;
//FIXME one shall not generate the unnecessary G1 Fxxx commands, here wipe_speed is a constant inside this cycle.
// Is it here for the cooling markers? Or should it be outside of the cycle?
gcode += gcodegen.writer.set_speed(wipe_speed*60, "", gcodegen.enable_cooling_markers ? ";_WIPE" : "");
gcode += gcodegen.writer.extrude_to_xy(
gcodegen.point_to_gcode(line->b),
Expand Down Expand Up @@ -730,10 +732,12 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed)

// extrude along the path
std::string gcode;
for (ExtrusionPaths::const_iterator path = paths.begin(); path != paths.end(); ++path)
for (ExtrusionPaths::iterator path = paths.begin(); path != paths.end(); ++path) {
// description += ExtrusionLoopRole2String(loop.role);
// description += ExtrusionRole2String(path->role);
path->simplify(SCALED_RESOLUTION);
gcode += this->_extrude(*path, description, speed);
}

// reset acceleration
gcode += this->writer.set_acceleration(this->config.default_acceleration.value);
Expand Down Expand Up @@ -783,18 +787,18 @@ GCode::extrude(ExtrusionMultiPath multipath, std::string description, double spe
{
// extrude along the path
std::string gcode;
for (ExtrusionPaths::const_iterator path = multipath.paths.begin(); path != multipath.paths.end(); ++path)
for (ExtrusionPaths::iterator path = multipath.paths.begin(); path != multipath.paths.end(); ++path) {
// description += ExtrusionLoopRole2String(loop.role);
// description += ExtrusionRole2String(path->role);
path->simplify(SCALED_RESOLUTION);
gcode += this->_extrude(*path, description, speed);

}
if (this->wipe.enable) {
this->wipe.path = std::move(multipath.paths.back().polyline); // TODO: don't limit wipe to last path
this->wipe.path.reverse();
}
// reset acceleration
gcode += this->writer.set_acceleration(this->config.default_acceleration.value);

//FIXME perform wipe on multi paths?
// if (this->wipe.enable)
// this->wipe.path = paths.front().polyline; // TODO: don't limit wipe to last path

return gcode;
}

Expand All @@ -814,22 +818,23 @@ GCode::extrude(const ExtrusionEntity &entity, std::string description, double sp
}

std::string
GCode::extrude(const ExtrusionPath &path, std::string description, double speed)
GCode::extrude(ExtrusionPath path, std::string description, double speed)
{
// description += ExtrusionRole2String(path.role);
path.simplify(SCALED_RESOLUTION);
std::string gcode = this->_extrude(path, description, speed);

if (this->wipe.enable) {
this->wipe.path = std::move(path.polyline);
this->wipe.path.reverse();
}
// reset acceleration
gcode += this->writer.set_acceleration(this->config.default_acceleration.value);

return gcode;
}

std::string
GCode::_extrude(ExtrusionPath path, std::string description, double speed)
GCode::_extrude(const ExtrusionPath &path, std::string description, double speed)
{
path.simplify(SCALED_RESOLUTION);

std::string gcode;

// go to first point of extrusion path
Expand Down Expand Up @@ -934,10 +939,6 @@ GCode::_extrude(ExtrusionPath path, std::string description, double speed)
);
}
}
if (this->wipe.enable) {
this->wipe.path = path.polyline;
this->wipe.path.reverse();
}
if (path.is_bridge() && this->enable_cooling_markers)
gcode += ";_BRIDGE_FAN_END\n";

Expand Down
4 changes: 2 additions & 2 deletions xs/src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GCode {
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(ExtrusionMultiPath multipath, std::string description = "", double speed = -1);
std::string extrude(const ExtrusionPath &path, std::string description = "", double speed = -1);
std::string extrude(ExtrusionPath path, std::string description = "", double speed = -1);
std::string travel_to(const Point &point, ExtrusionRole role, std::string comment);
bool needs_retraction(const Polyline &travel, ExtrusionRole role = erNone);
std::string retract(bool toolchange = false);
Expand All @@ -133,7 +133,7 @@ class GCode {
private:
Point _last_pos;
bool _last_pos_defined;
std::string _extrude(ExtrusionPath path, std::string description = "", double speed = -1);
std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1);
};

}
Expand Down

0 comments on commit 3bfa641

Please sign in to comment.