mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Conditional compilation to exclude all Perl/XS stuff from C++ code
This commit is contained in:
		
							parent
							
								
									e2cb40766b
								
							
						
					
					
						commit
						6e22a82e7d
					
				
					 20 changed files with 133 additions and 87 deletions
				
			
		|  | @ -24,7 +24,7 @@ my $build = Module::Build::WithXSpp->new( | |||
|     # _GLIBCXX_USE_C99 : to get the long long type for g++ | ||||
|     # HAS_BOOL         : stops Perl/lib/CORE/handy.h from doing "#  define bool char" for MSVC | ||||
|     # NOGDI            : prevents inclusion of wingdi.h which defines functions Polygon() and Polyline() in global namespace | ||||
|     extra_compiler_flags => [qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI), ($ENV{SLIC3R_DEBUG} ? ' -DSLIC3R_DEBUG -g' : '')], | ||||
|     extra_compiler_flags => [qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DSLIC3RXS), ($ENV{SLIC3R_DEBUG} ? ' -DSLIC3R_DEBUG -g' : '')], | ||||
|      | ||||
|     # Provides extra C typemaps that are auto-merged | ||||
|     extra_typemap_modules => { | ||||
|  |  | |||
|  | @ -320,6 +320,7 @@ void safety_offset(ClipperLib::Polygons* &subject) | |||
| 
 | ||||
| ///////////////////////
 | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| polynode_children_2_perl(const ClipperLib::PolyNode& node) | ||||
| { | ||||
|  | @ -346,5 +347,6 @@ polynode2perl(const ClipperLib::PolyNode& node) | |||
|     (void)hv_stores( hv, "children", polynode_children_2_perl(node) ); | ||||
|     return (SV*)newRV_noinc((SV*)hv); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -77,9 +77,10 @@ void safety_offset(ClipperLib::Polygons* &subject); | |||
| 
 | ||||
| /////////////////
 | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* polynode_children_2_perl(const ClipperLib::PolyNode& node); | ||||
| SV* polynode2perl(const ClipperLib::PolyNode& node); | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -50,6 +50,7 @@ ExPolygon::is_valid() const | |||
|     return true; | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| ExPolygon::to_AV() { | ||||
|     const unsigned int num_holes = this->holes.size(); | ||||
|  | @ -118,5 +119,6 @@ ExPolygon::from_SV_check(SV* expoly_sv) | |||
|         this->from_SV(expoly_sv); | ||||
|     } | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -11,17 +11,20 @@ class ExPolygon | |||
|     public: | ||||
|     Polygon contour; | ||||
|     Polygons holes; | ||||
|     void scale(double factor); | ||||
|     void translate(double x, double y); | ||||
|     void rotate(double angle, Point* center); | ||||
|     double area() const; | ||||
|     bool is_valid() const; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     void from_SV(SV* poly_sv); | ||||
|     void from_SV_check(SV* poly_sv); | ||||
|     SV* to_AV(); | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     SV* to_SV_pureperl() const; | ||||
|     void scale(double factor); | ||||
|     void translate(double x, double y); | ||||
|     void rotate(double angle, Point* center); | ||||
|     double area() const; | ||||
|     bool is_valid() const; | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| typedef std::vector<ExPolygon> ExPolygons; | ||||
|  |  | |||
|  | @ -42,6 +42,7 @@ Line::midpoint() const | |||
|     return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0); | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| void | ||||
| Line::from_SV(SV* line_sv) | ||||
| { | ||||
|  | @ -98,5 +99,6 @@ Line::to_SV_pureperl() const { | |||
|     av_store(av, 1, this->b.to_SV_pureperl()); | ||||
|     return newRV_noinc((SV*)av); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -13,18 +13,21 @@ class Line | |||
|     Point b; | ||||
|     Line() {}; | ||||
|     explicit Line(Point _a, Point _b): a(_a), b(_b) {}; | ||||
|     void from_SV(SV* line_sv); | ||||
|     void from_SV_check(SV* line_sv); | ||||
|     SV* to_AV(); | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     SV* to_SV_pureperl() const; | ||||
|     void scale(double factor); | ||||
|     void translate(double x, double y); | ||||
|     void rotate(double angle, Point* center); | ||||
|     void reverse(); | ||||
|     double length() const; | ||||
|     Point* midpoint() const; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     void from_SV(SV* line_sv); | ||||
|     void from_SV_check(SV* line_sv); | ||||
|     SV* to_AV(); | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     SV* to_SV_pureperl() const; | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| typedef std::vector<Line> Lines; | ||||
|  |  | |||
|  | @ -11,16 +11,19 @@ class MultiPoint | |||
| { | ||||
|     public: | ||||
|     Points points; | ||||
|     void from_SV(SV* poly_sv); | ||||
|     void from_SV_check(SV* poly_sv); | ||||
|     SV* to_AV(); | ||||
|     SV* to_SV_pureperl() const; | ||||
|     void scale(double factor); | ||||
|     void translate(double x, double y); | ||||
|     void rotate(double angle, Point* center); | ||||
|     void reverse(); | ||||
|     Point* first_point() const; | ||||
|     virtual Point* last_point() const = 0; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     void from_SV(SV* poly_sv); | ||||
|     void from_SV_check(SV* poly_sv); | ||||
|     SV* to_AV(); | ||||
|     SV* to_SV_pureperl() const; | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -72,6 +72,7 @@ Point::distance_to(const Point* point) const | |||
|     return sqrt(dx*dx + dy*dy); | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| Point::to_SV_ref() { | ||||
|     SV* sv = newSV(0); | ||||
|  | @ -112,5 +113,6 @@ Point::from_SV_check(SV* point_sv) | |||
|         this->from_SV(point_sv); | ||||
|     } | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -16,11 +16,6 @@ class Point | |||
|     long x; | ||||
|     long y; | ||||
|     explicit Point(long _x = 0, long _y = 0): x(_x), y(_y) {}; | ||||
|     void from_SV(SV* point_sv); | ||||
|     void from_SV_check(SV* point_sv); | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     SV* to_SV_pureperl() const; | ||||
|     void scale(double factor); | ||||
|     void translate(double x, double y); | ||||
|     void rotate(double angle, Point* center); | ||||
|  | @ -28,6 +23,14 @@ class Point | |||
|     int nearest_point_index(const Points points) const; | ||||
|     Point* nearest_point(Points points) const; | ||||
|     double distance_to(const Point* point) const; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     void from_SV(SV* point_sv); | ||||
|     void from_SV_check(SV* point_sv); | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     SV* to_SV_pureperl() const; | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -11,20 +11,6 @@ Polygon::last_point() const | |||
|     return new Point(this->points.front());  // last point == first point for polygons
 | ||||
| } | ||||
| 
 | ||||
| SV* | ||||
| Polygon::to_SV_ref() { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::Polygon::Ref", (void*)this ); | ||||
|     return sv; | ||||
| } | ||||
| 
 | ||||
| SV* | ||||
| Polygon::to_SV_clone_ref() const { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::Polygon", new Polygon(*this) ); | ||||
|     return sv; | ||||
| } | ||||
| 
 | ||||
| Lines | ||||
| Polygon::lines() const | ||||
| { | ||||
|  | @ -117,4 +103,20 @@ Polygon::is_valid() const | |||
|     return this->points.size() >= 3; | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| Polygon::to_SV_ref() { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::Polygon::Ref", (void*)this ); | ||||
|     return sv; | ||||
| } | ||||
| 
 | ||||
| SV* | ||||
| Polygon::to_SV_clone_ref() const { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::Polygon", new Polygon(*this) ); | ||||
|     return sv; | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -12,8 +12,6 @@ namespace Slic3r { | |||
| class Polygon : public MultiPoint { | ||||
|     public: | ||||
|     Point* last_point() const; | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     Lines lines() const; | ||||
|     Polyline* split_at(const Point* point); | ||||
|     Polyline* split_at_index(int index); | ||||
|  | @ -24,6 +22,11 @@ class Polygon : public MultiPoint { | |||
|     bool make_counter_clockwise(); | ||||
|     bool make_clockwise(); | ||||
|     bool is_valid() const; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| typedef std::vector<Polygon> Polygons; | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ Polyline::lines(Lines &lines) const | |||
|     } | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| Polyline::to_SV_ref() | ||||
| { | ||||
|  | @ -32,5 +33,6 @@ Polyline::to_SV_clone_ref() const | |||
|     sv_setref_pv( sv, "Slic3r::Polyline", new Polyline(*this) ); | ||||
|     return sv; | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -10,8 +10,11 @@ class Polyline : public MultiPoint { | |||
|     public: | ||||
|     Point* last_point() const; | ||||
|     void lines(Lines &lines) const; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     SV* to_SV_ref(); | ||||
|     SV* to_SV_clone_ref() const; | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| typedef std::vector<Polyline> Polylines; | ||||
|  |  | |||
|  | @ -2,17 +2,19 @@ | |||
| 
 | ||||
| namespace Slic3r { | ||||
| 
 | ||||
| SV* | ||||
| Surface::to_SV_ref() { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::Surface::Ref", (void*)this ); | ||||
|     return sv; | ||||
| } | ||||
| 
 | ||||
| double | ||||
| Surface::area() const | ||||
| { | ||||
|     return this->expolygon.area(); | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| Surface::to_SV_ref() { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::Surface::Ref", (void*)this ); | ||||
|     return sv; | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -16,8 +16,11 @@ class Surface | |||
|     unsigned short  thickness_layers;   // in layers
 | ||||
|     double          bridge_angle; | ||||
|     unsigned short  extra_perimeters; | ||||
|     SV* to_SV_ref(); | ||||
|     double area() const; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     SV* to_SV_ref(); | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| typedef std::vector<Surface> Surfaces; | ||||
|  |  | |||
|  | @ -44,13 +44,6 @@ TriangleMesh::~TriangleMesh() { | |||
|     stl_close(&this->stl); | ||||
| } | ||||
| 
 | ||||
| SV* | ||||
| TriangleMesh::to_SV() { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::TriangleMesh", (void*)this ); | ||||
|     return sv; | ||||
| } | ||||
| 
 | ||||
| void | ||||
| TriangleMesh::ReadSTLFile(char* input_file) { | ||||
|     stl_open(&stl, input_file); | ||||
|  | @ -68,38 +61,6 @@ TriangleMesh::write_binary(char* output_file) | |||
|     stl_write_binary(&this->stl, output_file, ""); | ||||
| } | ||||
| 
 | ||||
| void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets) | ||||
| { | ||||
|     stl.stats.type = inmemory; | ||||
|      | ||||
|     // count facets and allocate memory
 | ||||
|     AV* facets_av = (AV*)SvRV(facets); | ||||
|     stl.stats.number_of_facets = av_len(facets_av)+1; | ||||
|     stl.stats.original_num_facets = stl.stats.number_of_facets; | ||||
|     stl_allocate(&stl); | ||||
|      | ||||
|     // read geometry
 | ||||
|     AV* vertices_av = (AV*)SvRV(vertices); | ||||
|     for (unsigned int i = 0; i < stl.stats.number_of_facets; i++) { | ||||
|         AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0)); | ||||
|         stl_facet facet; | ||||
|         facet.normal.x = 0; | ||||
|         facet.normal.y = 0; | ||||
|         facet.normal.z = 0; | ||||
|         for (unsigned int v = 0; v <= 2; v++) { | ||||
|             AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, SvIV(*av_fetch(facet_av, v, 0)), 0)); | ||||
|             facet.vertex[v].x = SvNV(*av_fetch(vertex_av, 0, 0)); | ||||
|             facet.vertex[v].y = SvNV(*av_fetch(vertex_av, 1, 0)); | ||||
|             facet.vertex[v].z = SvNV(*av_fetch(vertex_av, 2, 0)); | ||||
|         } | ||||
|         facet.extra[0] = 0; | ||||
|         facet.extra[1] = 0; | ||||
|          | ||||
|         stl.facet_start[i] = facet; | ||||
|     } | ||||
|      | ||||
|     stl_get_size(&(this->stl)); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| TriangleMesh::repair() { | ||||
|  | @ -599,4 +560,46 @@ TriangleMesh::merge(const TriangleMesh* mesh) | |||
|     stl_get_size(&this->stl); | ||||
| } | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| SV* | ||||
| TriangleMesh::to_SV() { | ||||
|     SV* sv = newSV(0); | ||||
|     sv_setref_pv( sv, "Slic3r::TriangleMesh", (void*)this ); | ||||
|     return sv; | ||||
| } | ||||
| 
 | ||||
| void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets) | ||||
| { | ||||
|     stl.stats.type = inmemory; | ||||
|      | ||||
|     // count facets and allocate memory
 | ||||
|     AV* facets_av = (AV*)SvRV(facets); | ||||
|     stl.stats.number_of_facets = av_len(facets_av)+1; | ||||
|     stl.stats.original_num_facets = stl.stats.number_of_facets; | ||||
|     stl_allocate(&stl); | ||||
|      | ||||
|     // read geometry
 | ||||
|     AV* vertices_av = (AV*)SvRV(vertices); | ||||
|     for (unsigned int i = 0; i < stl.stats.number_of_facets; i++) { | ||||
|         AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0)); | ||||
|         stl_facet facet; | ||||
|         facet.normal.x = 0; | ||||
|         facet.normal.y = 0; | ||||
|         facet.normal.z = 0; | ||||
|         for (unsigned int v = 0; v <= 2; v++) { | ||||
|             AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, SvIV(*av_fetch(facet_av, v, 0)), 0)); | ||||
|             facet.vertex[v].x = SvNV(*av_fetch(vertex_av, 0, 0)); | ||||
|             facet.vertex[v].y = SvNV(*av_fetch(vertex_av, 1, 0)); | ||||
|             facet.vertex[v].z = SvNV(*av_fetch(vertex_av, 2, 0)); | ||||
|         } | ||||
|         facet.extra[0] = 0; | ||||
|         facet.extra[1] = 0; | ||||
|          | ||||
|         stl.facet_start[i] = facet; | ||||
|     } | ||||
|      | ||||
|     stl_get_size(&(this->stl)); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -18,11 +18,9 @@ class TriangleMesh | |||
|     TriangleMesh(); | ||||
|     TriangleMesh(const TriangleMesh &other); | ||||
|     ~TriangleMesh(); | ||||
|     SV* to_SV(); | ||||
|     void ReadSTLFile(char* input_file); | ||||
|     void write_ascii(char* output_file); | ||||
|     void write_binary(char* output_file); | ||||
|     void ReadFromPerl(SV* vertices, SV* facets); | ||||
|     void repair(); | ||||
|     void WriteOBJFile(char* output_file); | ||||
|     void scale(float factor); | ||||
|  | @ -35,6 +33,11 @@ class TriangleMesh | |||
|     void merge(const TriangleMesh* mesh); | ||||
|     stl_file stl; | ||||
|     bool repaired; | ||||
|      | ||||
|     #ifdef SLIC3RXS | ||||
|     SV* to_SV(); | ||||
|     void ReadFromPerl(SV* vertices, SV* facets); | ||||
|     #endif | ||||
| }; | ||||
| 
 | ||||
| enum FacetEdgeType { feNone, feTop, feBottom }; | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
| #include <ostream> | ||||
| #include <iostream> | ||||
| 
 | ||||
| #ifdef SLIC3RXS | ||||
| extern "C" { | ||||
| #include "EXTERN.h" | ||||
| #include "perl.h" | ||||
|  | @ -13,6 +14,7 @@ extern "C" { | |||
| #undef do_open | ||||
| #undef do_close | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #define EPSILON 1e-4 | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ void | |||
| confess_at(const char *file, int line, const char *func, | ||||
|             const char *pat, ...) | ||||
| { | ||||
|     #ifdef SLIC3RXS | ||||
|      va_list args; | ||||
|      SV *error_sv = newSVpvf("Error in function %s at %s:%d: ", func, | ||||
|          file, line); | ||||
|  | @ -23,4 +24,5 @@ confess_at(const char *file, int line, const char *func, | |||
|      call_pv("Carp::confess", G_DISCARD); | ||||
|      FREETMPS; | ||||
|      LEAVE; | ||||
|     #endif | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci