2015-12-07 23:39:54 +00:00
|
|
|
#ifndef _xsinit_h_
|
|
|
|
#define _xsinit_h_
|
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Disable some obnoxious warnings given by Visual Studio with the default warning level 4.
|
|
|
|
#pragma warning(disable: 4100 4127 4189 4244 4267 4700 4702 4800)
|
|
|
|
#endif
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
// undef some macros set by Perl which cause compilation errors on Win32
|
|
|
|
#undef read
|
|
|
|
#undef seekdir
|
|
|
|
#undef bind
|
|
|
|
#undef send
|
|
|
|
#undef connect
|
|
|
|
#undef wait
|
|
|
|
#undef accept
|
|
|
|
#undef close
|
|
|
|
#undef open
|
|
|
|
#undef write
|
|
|
|
#undef socket
|
|
|
|
#undef listen
|
|
|
|
#undef shutdown
|
|
|
|
#undef ioctl
|
|
|
|
#undef getpeername
|
|
|
|
#undef rect
|
|
|
|
#undef setsockopt
|
|
|
|
#undef getsockopt
|
|
|
|
#undef getsockname
|
|
|
|
#undef gethostname
|
|
|
|
#undef select
|
|
|
|
#undef socketpair
|
|
|
|
#undef recvfrom
|
|
|
|
#undef sendto
|
2017-09-01 15:30:18 +00:00
|
|
|
#undef pause
|
2015-12-07 23:39:54 +00:00
|
|
|
|
|
|
|
// these need to be included early for Win32 (listing it in Build.PL is not enough)
|
|
|
|
#include <ostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2016-11-30 02:46:44 +00:00
|
|
|
#include <libslic3r.h>
|
2015-12-07 23:39:54 +00:00
|
|
|
|
|
|
|
#ifdef SLIC3RXS
|
|
|
|
extern "C" {
|
|
|
|
#include "EXTERN.h"
|
|
|
|
#include "perl.h"
|
|
|
|
#include "XSUB.h"
|
|
|
|
#include "ppport.h"
|
|
|
|
#undef do_open
|
|
|
|
#undef do_close
|
2016-11-16 12:06:51 +00:00
|
|
|
#undef bind
|
2016-11-16 12:19:48 +00:00
|
|
|
#undef seed
|
2016-12-12 17:55:04 +00:00
|
|
|
#undef push
|
|
|
|
#undef pop
|
2016-08-21 19:46:17 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Undef some of the macros set by Perl <xsinit.h>, which cause compilation errors on Win32
|
|
|
|
#undef connect
|
2017-11-01 18:30:05 +00:00
|
|
|
#undef link
|
|
|
|
#undef unlink
|
2016-12-12 17:55:04 +00:00
|
|
|
#undef seek
|
|
|
|
#undef send
|
|
|
|
#undef write
|
2018-02-23 15:48:11 +00:00
|
|
|
#undef open
|
|
|
|
#undef close
|
|
|
|
#undef seekdir
|
|
|
|
#undef setbuf
|
|
|
|
#undef fread
|
|
|
|
#undef fseek
|
|
|
|
#undef fputc
|
|
|
|
#undef fwrite
|
|
|
|
#undef fclose
|
2016-08-21 19:46:17 +00:00
|
|
|
#endif /* _MSC_VER */
|
2015-12-07 23:39:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ClipperUtils.hpp>
|
|
|
|
#include <Config.hpp>
|
|
|
|
#include <ExPolygon.hpp>
|
|
|
|
#include <MultiPoint.hpp>
|
|
|
|
#include <Point.hpp>
|
|
|
|
#include <Polygon.hpp>
|
|
|
|
#include <Polyline.hpp>
|
|
|
|
#include <TriangleMesh.hpp>
|
2018-06-19 15:43:59 +00:00
|
|
|
#include <slic3r/AppController.hpp>
|
2015-12-07 23:39:54 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct ClassTraits {
|
2018-04-18 16:06:07 +00:00
|
|
|
// Name of a Perl alias of a C++ class type, owned by Perl, reference counted.
|
2015-12-07 23:39:54 +00:00
|
|
|
static const char* name;
|
2018-04-18 16:06:07 +00:00
|
|
|
// Name of a Perl alias of a C++ class type, owned by the C++ code.
|
|
|
|
// The references shall be enumerated at the end of XS.pm, where the desctructor is undefined with sub DESTROY {},
|
|
|
|
// so Perl will never delete the object instance.
|
|
|
|
static const char* name_ref;
|
2015-12-07 23:39:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// use this for typedefs for which the forward prototype
|
|
|
|
// in REGISTER_CLASS won't work
|
|
|
|
#define __REGISTER_CLASS(cname, perlname) \
|
|
|
|
template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \
|
|
|
|
template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref";
|
|
|
|
|
|
|
|
#define REGISTER_CLASS(cname,perlname) \
|
|
|
|
class cname; \
|
|
|
|
__REGISTER_CLASS(cname, perlname);
|
|
|
|
|
2018-04-18 16:06:07 +00:00
|
|
|
// Return Perl alias to a C++ class name.
|
2015-12-07 23:39:54 +00:00
|
|
|
template<class T>
|
|
|
|
const char* perl_class_name(const T*) { return ClassTraits<T>::name; }
|
2018-04-18 16:06:07 +00:00
|
|
|
// Return Perl alias to a C++ class name, suffixed with ::Ref.
|
|
|
|
// Such a C++ class instance will not be destroyed by Perl, the instance destruction is left to the C++ code.
|
2015-12-07 23:39:54 +00:00
|
|
|
template<class T>
|
|
|
|
const char* perl_class_name_ref(const T*) { return ClassTraits<T>::name_ref; }
|
|
|
|
|
2018-04-18 16:06:07 +00:00
|
|
|
// Mark the Perl SV (Scalar Value) as owning a "blessed" pointer to an object reference.
|
|
|
|
// Perl will never release the C++ instance.
|
2015-12-07 23:39:54 +00:00
|
|
|
template<class T>
|
|
|
|
SV* perl_to_SV_ref(T &t) {
|
|
|
|
SV* sv = newSV(0);
|
|
|
|
sv_setref_pv( sv, perl_class_name_ref(&t), &t );
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:06:07 +00:00
|
|
|
// Mark the Perl SV (Scalar Value) as owning a "blessed" pointer to an object instance.
|
|
|
|
// Perl will own the C++ instance, therefore it will also release it.
|
2015-12-07 23:39:54 +00:00
|
|
|
template<class T>
|
|
|
|
SV* perl_to_SV_clone_ref(const T &t) {
|
|
|
|
SV* sv = newSV(0);
|
|
|
|
sv_setref_pv( sv, perl_class_name(&t), new T(t) );
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:06:07 +00:00
|
|
|
// Reference wrapper to provide a C++ instance to Perl while keeping Perl from destroying the instance.
|
|
|
|
// The instance is created temporarily by XS.cpp just to provide Perl with a CLASS name and a object instance pointer.
|
2015-12-07 23:39:54 +00:00
|
|
|
template <class T>
|
|
|
|
class Ref {
|
|
|
|
T* val;
|
|
|
|
public:
|
|
|
|
Ref() : val(NULL) {}
|
|
|
|
Ref(T* t) : val(t) {}
|
|
|
|
Ref(const T* t) : val(const_cast<T*>(t)) {}
|
2018-04-18 16:06:07 +00:00
|
|
|
// Called by XS.cpp to convert the referenced object instance to a Perl SV, before it is blessed with the name
|
|
|
|
// returned by CLASS()
|
2015-12-07 23:39:54 +00:00
|
|
|
operator T*() const { return val; }
|
2018-04-18 16:06:07 +00:00
|
|
|
// Name to bless the Perl SV with. The name ends with a "::Ref" suffix to keep Perl from destroying the object instance.
|
2015-12-07 23:39:54 +00:00
|
|
|
static const char* CLASS() { return ClassTraits<T>::name_ref; }
|
|
|
|
};
|
2018-04-18 16:06:07 +00:00
|
|
|
|
|
|
|
// Wrapper to clone a C++ object instance before passing it to Perl for ownership.
|
|
|
|
// This wrapper instance is created temporarily by XS.cpp to provide Perl with a CLASS name and a object instance pointer.
|
2015-12-07 23:39:54 +00:00
|
|
|
template <class T>
|
|
|
|
class Clone {
|
|
|
|
T* val;
|
|
|
|
public:
|
|
|
|
Clone() : val(NULL) {}
|
|
|
|
Clone(T* t) : val(new T(*t)) {}
|
|
|
|
Clone(const T& t) : val(new T(t)) {}
|
2018-04-18 16:06:07 +00:00
|
|
|
// Called by XS.cpp to convert the cloned object instance to a Perl SV, before it is blessed with the name
|
|
|
|
// returned by CLASS()
|
2015-12-07 23:39:54 +00:00
|
|
|
operator T*() const { return val; }
|
2018-04-18 16:06:07 +00:00
|
|
|
// Name to bless the Perl SV with. If there is a destructor registered in the XSP file for this class, then Perl will
|
|
|
|
// call this destructor when the reference counter of this SV drops to zero.
|
2015-12-07 23:39:54 +00:00
|
|
|
static const char* CLASS() { return ClassTraits<T>::name; }
|
|
|
|
};
|
|
|
|
|
|
|
|
SV* ConfigBase__as_hash(ConfigBase* THIS);
|
2015-12-16 11:58:06 +00:00
|
|
|
SV* ConfigOption_to_SV(const ConfigOption &opt, const ConfigOptionDef &def);
|
2015-12-07 23:39:54 +00:00
|
|
|
SV* ConfigBase__get(ConfigBase* THIS, const t_config_option_key &opt_key);
|
|
|
|
SV* ConfigBase__get_at(ConfigBase* THIS, const t_config_option_key &opt_key, size_t i);
|
|
|
|
bool ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value);
|
|
|
|
bool ConfigBase__set_deserialize(ConfigBase* THIS, const t_config_option_key &opt_key, SV* str);
|
|
|
|
void ConfigBase__set_ifndef(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value, bool deserialize = false);
|
|
|
|
bool StaticConfig__set(StaticConfig* THIS, const t_config_option_key &opt_key, SV* value);
|
|
|
|
SV* to_AV(ExPolygon* expolygon);
|
|
|
|
SV* to_SV_pureperl(const ExPolygon* expolygon);
|
|
|
|
void from_SV(SV* expoly_sv, ExPolygon* expolygon);
|
|
|
|
void from_SV_check(SV* expoly_sv, ExPolygon* expolygon);
|
|
|
|
void from_SV(SV* line_sv, Line* THIS);
|
|
|
|
void from_SV_check(SV* line_sv, Line* THIS);
|
|
|
|
SV* to_AV(Line* THIS);
|
|
|
|
SV* to_SV_pureperl(const Line* THIS);
|
|
|
|
void from_SV(SV* poly_sv, MultiPoint* THIS);
|
|
|
|
void from_SV_check(SV* poly_sv, MultiPoint* THIS);
|
|
|
|
SV* to_AV(MultiPoint* THIS);
|
|
|
|
SV* to_SV_pureperl(const MultiPoint* THIS);
|
|
|
|
void from_SV_check(SV* poly_sv, Polygon* THIS);
|
|
|
|
void from_SV_check(SV* poly_sv, Polyline* THIS);
|
|
|
|
SV* to_SV_pureperl(const Point* THIS);
|
|
|
|
void from_SV(SV* point_sv, Point* point);
|
|
|
|
void from_SV_check(SV* point_sv, Point* point);
|
|
|
|
SV* to_SV_pureperl(const Pointf* point);
|
|
|
|
bool from_SV(SV* point_sv, Pointf* point);
|
|
|
|
bool from_SV_check(SV* point_sv, Pointf* point);
|
|
|
|
void from_SV_check(SV* surface_sv, Surface* THIS);
|
|
|
|
SV* to_SV(TriangleMesh* THIS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-17 18:00:15 +00:00
|
|
|
// Defined in wxPerlIface.cpp
|
|
|
|
// Return a pointer to the associated wxWidgets object instance given by classname.
|
|
|
|
extern void* wxPli_sv_2_object( pTHX_ SV* scalar, const char* classname );
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
using namespace Slic3r;
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#endif
|