mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 00:01:09 -06:00
Ported Slic3r::GCode::AvoidCrossingPerimeters to XS
This commit is contained in:
parent
580d28d071
commit
bf9cd1b8e6
10 changed files with 148 additions and 79 deletions
|
@ -1670,6 +1670,7 @@ src/libslic3r/ExtrusionEntityCollection.cpp
|
|||
src/libslic3r/ExtrusionEntityCollection.hpp
|
||||
src/libslic3r/Flow.cpp
|
||||
src/libslic3r/Flow.hpp
|
||||
src/libslic3r/GCode.cpp
|
||||
src/libslic3r/GCode.hpp
|
||||
src/libslic3r/GCodeWriter.cpp
|
||||
src/libslic3r/GCodeWriter.hpp
|
||||
|
@ -1762,6 +1763,7 @@ xsp/ExtrusionEntityCollection.xsp
|
|||
xsp/ExtrusionLoop.xsp
|
||||
xsp/ExtrusionPath.xsp
|
||||
xsp/Flow.xsp
|
||||
xsp/GCode.xsp
|
||||
xsp/GCodeWriter.xsp
|
||||
xsp/Geometry.xsp
|
||||
xsp/GUI_3DScene.xsp
|
||||
|
|
|
@ -215,6 +215,7 @@ for my $class (qw(
|
|||
Slic3r::ExtrusionPath
|
||||
Slic3r::ExtrusionPath::Collection
|
||||
Slic3r::Flow
|
||||
Slic3r::GCode::AvoidCrossingPerimeters
|
||||
Slic3r::GCode::PlaceholderParser
|
||||
Slic3r::Geometry::BoundingBox
|
||||
Slic3r::Geometry::BoundingBoxf
|
||||
|
|
70
xs/src/libslic3r/GCode.cpp
Normal file
70
xs/src/libslic3r/GCode.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "GCode.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
AvoidCrossingPerimeters::AvoidCrossingPerimeters()
|
||||
: use_external_mp(false), use_external_mp_once(false), disable_once(true),
|
||||
_external_mp(NULL), _layer_mp(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AvoidCrossingPerimeters::~AvoidCrossingPerimeters()
|
||||
{
|
||||
if (this->_external_mp != NULL)
|
||||
delete this->_external_mp;
|
||||
|
||||
if (this->_layer_mp != NULL)
|
||||
delete this->_layer_mp;
|
||||
}
|
||||
|
||||
void
|
||||
AvoidCrossingPerimeters::init_external_mp(const ExPolygons &islands)
|
||||
{
|
||||
if (this->_external_mp != NULL)
|
||||
delete this->_external_mp;
|
||||
|
||||
this->_external_mp = new MotionPlanner(islands);
|
||||
}
|
||||
|
||||
void
|
||||
AvoidCrossingPerimeters::init_layer_mp(const ExPolygons &islands)
|
||||
{
|
||||
if (this->_layer_mp != NULL)
|
||||
delete this->_layer_mp;
|
||||
|
||||
this->_layer_mp = new MotionPlanner(islands);
|
||||
}
|
||||
|
||||
Polyline
|
||||
AvoidCrossingPerimeters::travel_to(Point point, const Pointf &gcodegen_origin,
|
||||
const Point &gcodegen_last_pos)
|
||||
{
|
||||
if (this->use_external_mp || this->use_external_mp_once) {
|
||||
// get current origin set in gcodegen
|
||||
// (the one that will be used to translate the G-code coordinates by)
|
||||
Point scaled_origin = Point::new_scale(gcodegen_origin.x, gcodegen_origin.y);
|
||||
|
||||
// represent last_pos in absolute G-code coordinates
|
||||
Point last_pos = gcodegen_last_pos;
|
||||
last_pos.translate(scaled_origin);
|
||||
|
||||
// represent point in absolute G-code coordinates
|
||||
point.translate(scaled_origin);
|
||||
|
||||
// calculate path
|
||||
Polyline travel = this->_external_mp->shortest_path(last_pos, point);
|
||||
|
||||
// translate the path back into the shifted coordinate system that gcodegen
|
||||
// is currently using for writing coordinates
|
||||
travel.translate(scaled_origin.negative());
|
||||
return travel;
|
||||
} else {
|
||||
return this->_layer_mp->shortest_path(gcodegen_last_pos, point);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(AvoidCrossingPerimeters, "GCode::AvoidCrossingPerimeters");
|
||||
#endif
|
||||
|
||||
}
|
|
@ -2,32 +2,37 @@
|
|||
#define slic3r_GCode_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "ExPolygon.hpp"
|
||||
#include "MotionPlanner.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// draft for a binary representation of a G-code line
|
||||
|
||||
enum GCodeCmdType {
|
||||
gcctSyncMotion,
|
||||
gcctExtrude,
|
||||
gcctResetE,
|
||||
gcctSetTemp,
|
||||
gcctSetTempWait,
|
||||
gcctToolchange,
|
||||
gcctCustom
|
||||
};
|
||||
|
||||
class GCodeCmd {
|
||||
class AvoidCrossingPerimeters {
|
||||
public:
|
||||
GCodeCmdType type;
|
||||
float X, Y, Z, E, F;
|
||||
unsigned short T, S;
|
||||
std::string custom, comment;
|
||||
float xy_dist; // cache
|
||||
|
||||
GCodeCmd(GCodeCmdType type)
|
||||
: type(type), X(0), Y(0), Z(0), E(0), F(0), T(-1), S(0), xy_dist(-1) {};
|
||||
// this flag triggers the use of the external configuration space
|
||||
bool use_external_mp;
|
||||
bool use_external_mp_once; // just for the next travel move
|
||||
|
||||
// this flag disables avoid_crossing_perimeters just for the next travel move
|
||||
// we enable it by default for the first travel move in print
|
||||
bool disable_once;
|
||||
|
||||
AvoidCrossingPerimeters();
|
||||
~AvoidCrossingPerimeters();
|
||||
void init_external_mp(const ExPolygons &islands);
|
||||
void init_layer_mp(const ExPolygons &islands);
|
||||
|
||||
//Polyline travel_to(GCode &gcodegen, const Point &point);
|
||||
Polyline travel_to(Point point, const Pointf &gcodegen_origin,
|
||||
const Point &gcodegen_last_pos);
|
||||
|
||||
private:
|
||||
MotionPlanner* _external_mp;
|
||||
MotionPlanner* _layer_mp;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
31
xs/xsp/GCode.xsp
Normal file
31
xs/xsp/GCode.xsp
Normal file
|
@ -0,0 +1,31 @@
|
|||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "libslic3r/GCode.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::GCode::AvoidCrossingPerimeters} class AvoidCrossingPerimeters {
|
||||
AvoidCrossingPerimeters();
|
||||
~AvoidCrossingPerimeters();
|
||||
|
||||
void init_external_mp(ExPolygons islands);
|
||||
void init_layer_mp(ExPolygons islands);
|
||||
Clone<Polyline> travel_to(Point* point, Pointf* gcodegen_origin, Point* gcodegen_last_pos)
|
||||
%code{% RETVAL = THIS->travel_to(*point, *gcodegen_origin, *gcodegen_last_pos); %};
|
||||
|
||||
bool use_external_mp()
|
||||
%code{% RETVAL = THIS->use_external_mp; %};
|
||||
void set_use_external_mp(bool value)
|
||||
%code{% THIS->use_external_mp = value; %};
|
||||
|
||||
bool use_external_mp_once()
|
||||
%code{% RETVAL = THIS->use_external_mp_once; %};
|
||||
void set_use_external_mp_once(bool value)
|
||||
%code{% THIS->use_external_mp_once = value; %};
|
||||
|
||||
bool disable_once()
|
||||
%code{% RETVAL = THIS->disable_once; %};
|
||||
void set_disable_once(bool value)
|
||||
%code{% THIS->disable_once = value; %};
|
||||
};
|
|
@ -170,6 +170,10 @@ PlaceholderParser* O_OBJECT_SLIC3R
|
|||
Ref<PlaceholderParser> O_OBJECT_SLIC3R_T
|
||||
Clone<PlaceholderParser> O_OBJECT_SLIC3R_T
|
||||
|
||||
AvoidCrossingPerimeters* O_OBJECT_SLIC3R
|
||||
Ref<AvoidCrossingPerimeters> O_OBJECT_SLIC3R_T
|
||||
Clone<AvoidCrossingPerimeters> O_OBJECT_SLIC3R_T
|
||||
|
||||
MotionPlanner* O_OBJECT_SLIC3R
|
||||
Ref<MotionPlanner> O_OBJECT_SLIC3R_T
|
||||
Clone<MotionPlanner> O_OBJECT_SLIC3R_T
|
||||
|
|
|
@ -125,6 +125,10 @@
|
|||
%typemap{Ref<PlaceholderParser>}{simple};
|
||||
%typemap{Clone<PlaceholderParser>}{simple};
|
||||
|
||||
%typemap{AvoidCrossingPerimeters*};
|
||||
%typemap{Ref<AvoidCrossingPerimeters>}{simple};
|
||||
%typemap{Clone<AvoidCrossingPerimeters>}{simple};
|
||||
|
||||
|
||||
%typemap{Points};
|
||||
%typemap{Pointfs};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue