2014-04-29 23:04:49 +00:00
|
|
|
%module{Slic3r::XS};
|
|
|
|
|
|
|
|
%{
|
2015-12-07 23:39:54 +00:00
|
|
|
#include <xsinit.h>
|
2014-08-03 17:42:29 +00:00
|
|
|
#include "libslic3r/Model.hpp"
|
2020-04-23 16:19:03 +00:00
|
|
|
#include "libslic3r/ModelArrange.hpp"
|
2018-02-13 14:19:55 +00:00
|
|
|
#include "libslic3r/Print.hpp"
|
2014-08-03 17:42:29 +00:00
|
|
|
#include "libslic3r/PrintConfig.hpp"
|
2017-02-07 17:17:12 +00:00
|
|
|
#include "libslic3r/Slicing.hpp"
|
2017-02-26 20:46:33 +00:00
|
|
|
#include "libslic3r/Format/AMF.hpp"
|
2018-02-08 12:26:50 +00:00
|
|
|
#include "libslic3r/Format/3mf.hpp"
|
2017-02-26 20:46:33 +00:00
|
|
|
#include "libslic3r/Format/OBJ.hpp"
|
|
|
|
#include "libslic3r/Format/STL.hpp"
|
2020-06-24 07:20:04 +00:00
|
|
|
#include "libslic3r/PresetBundle.hpp"
|
2014-04-29 23:04:49 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%name{Slic3r::Model} class Model {
|
|
|
|
Model();
|
|
|
|
~Model();
|
|
|
|
|
2017-08-02 14:05:18 +00:00
|
|
|
%name{read_from_file} Model(std::string input_file, bool add_default_instances = true)
|
|
|
|
%code%{
|
|
|
|
try {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
RETVAL = new Model(Model::read_from_file(input_file, nullptr, nullptr, only_if(add_default_instances, Model::LoadAttribute::AddDefaultInstances)));
|
2017-08-02 14:05:18 +00:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
croak("Error while opening %s: %s\n", input_file.c_str(), e.what());
|
|
|
|
}
|
|
|
|
%};
|
|
|
|
|
2014-04-29 23:04:49 +00:00
|
|
|
Clone<Model> clone()
|
|
|
|
%code%{ RETVAL = THIS; %};
|
|
|
|
|
2014-05-09 12:24:35 +00:00
|
|
|
%name{_add_object} Ref<ModelObject> add_object();
|
2014-11-12 22:50:09 +00:00
|
|
|
Ref<ModelObject> _add_object_clone(ModelObject* other, bool copy_volumes = true)
|
2018-11-02 18:49:40 +00:00
|
|
|
%code%{ auto ptr = THIS->add_object(*other); if (! copy_volumes) ptr->clear_volumes(); RETVAL = ptr; %};
|
2014-04-29 23:04:49 +00:00
|
|
|
void delete_object(size_t idx);
|
2014-05-06 22:58:29 +00:00
|
|
|
void clear_objects();
|
2014-07-13 10:10:34 +00:00
|
|
|
size_t objects_count()
|
|
|
|
%code%{ RETVAL = THIS->objects.size(); %};
|
2014-12-13 19:41:03 +00:00
|
|
|
Ref<ModelObject> get_object(int idx)
|
|
|
|
%code%{ RETVAL = THIS->objects.at(idx); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
Ref<ModelMaterial> get_material(t_model_material_id material_id)
|
|
|
|
%code%{
|
2014-05-09 12:24:35 +00:00
|
|
|
RETVAL = THIS->get_material(material_id);
|
|
|
|
if (RETVAL == NULL) {
|
2014-04-29 23:04:49 +00:00
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
%};
|
|
|
|
|
2014-05-09 12:24:35 +00:00
|
|
|
%name{add_material} Ref<ModelMaterial> add_material(t_model_material_id material_id);
|
|
|
|
Ref<ModelMaterial> add_material_clone(t_model_material_id material_id, ModelMaterial* other)
|
|
|
|
%code%{ RETVAL = THIS->add_material(material_id, *other); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
bool has_material(t_model_material_id material_id) const
|
|
|
|
%code%{
|
2014-05-09 12:24:35 +00:00
|
|
|
RETVAL = (THIS->get_material(material_id) != NULL);
|
2014-04-29 23:04:49 +00:00
|
|
|
%};
|
2014-05-09 12:24:35 +00:00
|
|
|
void delete_material(t_model_material_id material_id);
|
|
|
|
void clear_materials();
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
std::vector<std::string> material_names() const
|
|
|
|
%code%{
|
|
|
|
for (ModelMaterialMap::iterator i = THIS->materials.begin();
|
|
|
|
i != THIS->materials.end(); ++i)
|
|
|
|
{
|
|
|
|
RETVAL.push_back(i->first);
|
|
|
|
}
|
|
|
|
%};
|
|
|
|
|
|
|
|
size_t material_count() const
|
|
|
|
%code%{ RETVAL = THIS->materials.size(); %};
|
|
|
|
|
2014-08-08 19:48:59 +00:00
|
|
|
bool add_default_instances();
|
2018-08-21 19:05:24 +00:00
|
|
|
void center_instances_around_point(Vec2d* point)
|
2014-09-21 08:51:36 +00:00
|
|
|
%code%{ THIS->center_instances_around_point(*point); %};
|
|
|
|
void translate(double x, double y, double z);
|
2015-01-19 17:53:04 +00:00
|
|
|
Clone<TriangleMesh> mesh();
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-05-09 12:24:35 +00:00
|
|
|
ModelObjectPtrs* objects()
|
|
|
|
%code%{ RETVAL = &THIS->objects; %};
|
2015-12-01 20:51:16 +00:00
|
|
|
|
2022-05-04 17:10:34 +00:00
|
|
|
bool arrange_objects(double dist) %code%{ ArrangeParams ap{scaled(dist)}; arrange_objects(*THIS, InfiniteBed{}, ap); %};
|
|
|
|
void duplicate(unsigned int copies_num, double dist) %code%{ ArrangeParams ap{scaled(dist)}; duplicate(*THIS, copies_num, InfiniteBed{}, ap); %};
|
2017-08-02 14:05:18 +00:00
|
|
|
bool looks_like_multipart_object() const;
|
2018-05-07 14:13:58 +00:00
|
|
|
void convert_multipart_object(unsigned int max_extruders);
|
2017-08-02 14:05:18 +00:00
|
|
|
|
2017-02-27 00:03:00 +00:00
|
|
|
bool store_stl(char *path, bool binary)
|
|
|
|
%code%{ TriangleMesh mesh = THIS->mesh(); RETVAL = Slic3r::store_stl(path, &mesh, binary); %};
|
|
|
|
|
2017-02-26 20:46:33 +00:00
|
|
|
%{
|
|
|
|
|
|
|
|
Model*
|
|
|
|
load_stl(CLASS, path, object_name)
|
|
|
|
char* CLASS;
|
|
|
|
char* path;
|
|
|
|
char* object_name;
|
|
|
|
CODE:
|
|
|
|
RETVAL = new Model();
|
|
|
|
if (! load_stl(path, RETVAL, object_name)) {
|
|
|
|
delete RETVAL;
|
|
|
|
RETVAL = NULL;
|
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
|
|
|
|
%}
|
|
|
|
};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
%name{Slic3r::Model::Material} class ModelMaterial {
|
|
|
|
Ref<Model> model()
|
2014-05-09 12:24:35 +00:00
|
|
|
%code%{ RETVAL = THIS->get_model(); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
Ref<DynamicPrintConfig> config()
|
2020-09-24 14:18:56 +00:00
|
|
|
%code%{ RETVAL = &const_cast<DynamicPrintConfig&>(THIS->config.get()); %};
|
2014-05-06 22:22:56 +00:00
|
|
|
|
|
|
|
std::string get_attribute(std::string name)
|
|
|
|
%code%{ if (THIS->attributes.find(name) != THIS->attributes.end()) RETVAL = THIS->attributes[name]; %};
|
|
|
|
|
|
|
|
void set_attribute(std::string name, std::string value)
|
|
|
|
%code%{ THIS->attributes[name] = value; %};
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
SV*
|
|
|
|
ModelMaterial::attributes()
|
|
|
|
CODE:
|
|
|
|
HV* hv = newHV();
|
|
|
|
for (t_model_material_attributes::const_iterator attr = THIS->attributes.begin(); attr != THIS->attributes.end(); ++attr) {
|
|
|
|
(void)hv_store( hv, attr->first.c_str(), attr->first.length(), newSVpv(attr->second.c_str(), attr->second.length()), 0 );
|
|
|
|
}
|
|
|
|
RETVAL = (SV*)newRV_noinc((SV*)hv);
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
|
|
|
%}
|
|
|
|
|
2014-04-29 23:04:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
%name{Slic3r::Model::Object} class ModelObject {
|
2014-05-09 12:24:35 +00:00
|
|
|
ModelVolumePtrs* volumes()
|
|
|
|
%code%{ RETVAL = &THIS->volumes; %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-05-09 12:24:35 +00:00
|
|
|
ModelInstancePtrs* instances()
|
|
|
|
%code%{ RETVAL = &THIS->instances; %};
|
|
|
|
|
2014-04-29 23:04:49 +00:00
|
|
|
void invalidate_bounding_box();
|
2015-01-19 17:53:04 +00:00
|
|
|
Clone<TriangleMesh> mesh();
|
|
|
|
Clone<TriangleMesh> raw_mesh();
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-05-09 12:24:35 +00:00
|
|
|
%name{_add_volume} Ref<ModelVolume> add_volume(TriangleMesh* mesh)
|
|
|
|
%code%{ RETVAL = THIS->add_volume(*mesh); %};
|
|
|
|
Ref<ModelVolume> _add_volume_clone(ModelVolume* other)
|
|
|
|
%code%{ RETVAL = THIS->add_volume(*other); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
void delete_volume(size_t idx);
|
|
|
|
void clear_volumes();
|
2014-09-21 08:51:36 +00:00
|
|
|
int volumes_count()
|
|
|
|
%code%{ RETVAL = THIS->volumes.size(); %};
|
2017-02-22 15:05:14 +00:00
|
|
|
Ref<ModelVolume> get_volume(int idx)
|
|
|
|
%code%{ RETVAL = THIS->volumes.at(idx); %};
|
2017-05-20 20:02:04 +00:00
|
|
|
bool move_volume_up(int idx)
|
|
|
|
%code%{
|
|
|
|
if (idx > 0 && idx < int(THIS->volumes.size())) {
|
|
|
|
std::swap(THIS->volumes[idx-1], THIS->volumes[idx]);
|
|
|
|
RETVAL = true;
|
|
|
|
} else
|
|
|
|
RETVAL = false;
|
|
|
|
%};
|
|
|
|
bool move_volume_down(int idx)
|
|
|
|
%code%{
|
|
|
|
if (idx >= 0 && idx + 1 < int(THIS->volumes.size())) {
|
|
|
|
std::swap(THIS->volumes[idx+1], THIS->volumes[idx]);
|
|
|
|
RETVAL = true;
|
|
|
|
} else
|
|
|
|
RETVAL = false;
|
|
|
|
%};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-05-09 12:24:35 +00:00
|
|
|
%name{_add_instance} Ref<ModelInstance> add_instance();
|
|
|
|
Ref<ModelInstance> _add_instance_clone(ModelInstance* other)
|
|
|
|
%code%{ RETVAL = THIS->add_instance(*other); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
void delete_last_instance();
|
|
|
|
void clear_instances();
|
2014-05-09 12:24:35 +00:00
|
|
|
int instances_count()
|
|
|
|
%code%{ RETVAL = THIS->instances.size(); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-07-12 09:20:57 +00:00
|
|
|
std::string name()
|
|
|
|
%code%{ RETVAL = THIS->name; %};
|
|
|
|
void set_name(std::string value)
|
|
|
|
%code%{ THIS->name = value; %};
|
2014-04-29 23:04:49 +00:00
|
|
|
std::string input_file()
|
|
|
|
%code%{ RETVAL = THIS->input_file; %};
|
|
|
|
void set_input_file(std::string value)
|
|
|
|
%code%{ THIS->input_file = value; %};
|
|
|
|
Ref<DynamicPrintConfig> config()
|
2020-09-24 14:18:56 +00:00
|
|
|
%code%{ RETVAL = &const_cast<DynamicPrintConfig&>(THIS->config.get()); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
Ref<Model> model()
|
2014-05-09 12:24:35 +00:00
|
|
|
%code%{ RETVAL = THIS->get_model(); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2018-08-21 15:43:05 +00:00
|
|
|
Ref<Vec3d> origin_translation()
|
2014-05-15 14:37:18 +00:00
|
|
|
%code%{ RETVAL = &THIS->origin_translation; %};
|
2018-08-21 15:43:05 +00:00
|
|
|
void set_origin_translation(Vec3d* point)
|
2014-05-09 12:24:35 +00:00
|
|
|
%code%{ THIS->origin_translation = *point; %};
|
2014-08-08 19:48:59 +00:00
|
|
|
|
2019-06-20 18:23:05 +00:00
|
|
|
void ensure_on_bed();
|
2014-09-21 08:51:36 +00:00
|
|
|
int materials_count() const;
|
2014-08-08 19:48:59 +00:00
|
|
|
int facets_count();
|
2014-09-21 08:51:36 +00:00
|
|
|
void center_around_origin();
|
|
|
|
void translate(double x, double y, double z);
|
2018-08-21 15:43:05 +00:00
|
|
|
void scale_xyz(Vec3d* versor)
|
2014-09-21 08:51:36 +00:00
|
|
|
%code{% THIS->scale(*versor); %};
|
2018-08-27 12:00:53 +00:00
|
|
|
void rotate(float angle, Vec3d* axis)
|
2018-08-21 13:40:11 +00:00
|
|
|
%code{% THIS->rotate(angle, *axis); %};
|
2015-11-04 22:11:30 +00:00
|
|
|
void mirror(Axis axis);
|
2014-11-12 22:50:09 +00:00
|
|
|
|
2014-04-29 23:04:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
%name{Slic3r::Model::Volume} class ModelVolume {
|
|
|
|
Ref<ModelObject> object()
|
2014-05-09 12:24:35 +00:00
|
|
|
%code%{ RETVAL = THIS->get_object(); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-07-12 09:20:57 +00:00
|
|
|
std::string name()
|
|
|
|
%code%{ RETVAL = THIS->name; %};
|
|
|
|
void set_name(std::string value)
|
|
|
|
%code%{ THIS->name = value; %};
|
2014-05-10 14:59:17 +00:00
|
|
|
t_model_material_id material_id();
|
2014-05-09 12:24:35 +00:00
|
|
|
void set_material_id(t_model_material_id material_id)
|
2018-10-17 09:12:38 +00:00
|
|
|
%code%{ THIS->set_material_id(material_id); %};
|
2014-05-10 14:59:17 +00:00
|
|
|
Ref<ModelMaterial> material();
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2014-07-11 18:09:01 +00:00
|
|
|
Ref<DynamicPrintConfig> config()
|
2020-09-24 14:18:56 +00:00
|
|
|
%code%{ RETVAL = &const_cast<DynamicPrintConfig&>(THIS->config.get()); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
Ref<TriangleMesh> mesh()
|
2019-06-11 15:08:47 +00:00
|
|
|
%code%{ RETVAL = &THIS->mesh(); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
|
|
|
bool modifier()
|
2018-09-17 13:12:13 +00:00
|
|
|
%code%{ RETVAL = THIS->is_modifier(); %};
|
2014-05-09 12:24:35 +00:00
|
|
|
void set_modifier(bool modifier)
|
2019-02-25 07:55:25 +00:00
|
|
|
%code%{ THIS->set_type(modifier ? ModelVolumeType::PARAMETER_MODIFIER : ModelVolumeType::MODEL_PART); %};
|
2018-09-17 13:12:13 +00:00
|
|
|
bool model_part()
|
|
|
|
%code%{ RETVAL = THIS->is_model_part(); %};
|
|
|
|
bool support_enforcer()
|
|
|
|
%code%{ RETVAL = THIS->is_support_enforcer(); %};
|
|
|
|
void set_support_enforcer()
|
2019-02-25 07:55:25 +00:00
|
|
|
%code%{ THIS->set_type(ModelVolumeType::SUPPORT_ENFORCER); %};
|
2018-09-17 13:12:13 +00:00
|
|
|
bool support_blocker()
|
|
|
|
%code%{ RETVAL = THIS->is_support_blocker(); %};
|
|
|
|
void set_support_blocker()
|
2019-02-25 07:55:25 +00:00
|
|
|
%code%{ THIS->set_type(ModelVolumeType::SUPPORT_BLOCKER); %};
|
2017-06-15 13:38:15 +00:00
|
|
|
|
2018-05-07 14:13:58 +00:00
|
|
|
size_t split(unsigned int max_extruders);
|
2014-04-29 23:04:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
%name{Slic3r::Model::Instance} class ModelInstance {
|
|
|
|
Ref<ModelObject> object()
|
2014-05-09 12:24:35 +00:00
|
|
|
%code%{ RETVAL = THIS->get_object(); %};
|
2014-04-29 23:04:49 +00:00
|
|
|
|
2018-09-24 13:21:18 +00:00
|
|
|
Vec3d* rotation()
|
|
|
|
%code%{ RETVAL = new Vec3d(THIS->get_rotation(X), THIS->get_rotation(Y), THIS->get_rotation(Z)); %};
|
2018-09-25 08:42:11 +00:00
|
|
|
|
2018-09-24 13:54:09 +00:00
|
|
|
Vec3d* scaling_factor()
|
|
|
|
%code%{ RETVAL = new Vec3d(THIS->get_scaling_factor(X), THIS->get_scaling_factor(Y), THIS->get_scaling_factor(Z)); %};
|
2018-09-25 08:42:11 +00:00
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
Vec2d* offset()
|
|
|
|
%code%{ RETVAL = new Vec2d(THIS->get_offset(X), THIS->get_offset(Y)); %};
|
2018-09-25 08:42:11 +00:00
|
|
|
|
2018-09-20 13:00:40 +00:00
|
|
|
void set_rotation(double val)
|
|
|
|
%code%{ THIS->set_rotation(Z, val); THIS->get_object()->invalidate_bounding_box(); %};
|
|
|
|
|
|
|
|
void set_rotations(Vec3d *rotation)
|
|
|
|
%code%{ THIS->set_rotation(*rotation); THIS->get_object()->invalidate_bounding_box(); %};
|
|
|
|
|
2014-04-29 23:04:49 +00:00
|
|
|
void set_scaling_factor(double val)
|
2018-09-24 13:54:09 +00:00
|
|
|
%code%{ THIS->set_scaling_factor(X, val); THIS->set_scaling_factor(Y, val); THIS->set_scaling_factor(Z, val); THIS->get_object()->invalidate_bounding_box(); %};
|
|
|
|
|
|
|
|
void set_scaling_factors(Vec3d *scale)
|
|
|
|
%code%{ THIS->set_scaling_factor(*scale); THIS->get_object()->invalidate_bounding_box(); %};
|
2018-09-25 08:42:11 +00:00
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void set_offset(Vec2d *offset)
|
|
|
|
%code%{
|
|
|
|
THIS->set_offset(X, (*offset)(0));
|
|
|
|
THIS->set_offset(Y, (*offset)(1));
|
|
|
|
%};
|
2014-04-29 23:04:49 +00:00
|
|
|
};
|