PrusaSlicer-NonPlainar/xs/xsp/Model.xsp

287 lines
9.9 KiB
Plaintext
Raw Permalink Normal View History

%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "libslic3r/Model.hpp"
#include "libslic3r/ModelArrange.hpp"
2018-02-13 14:19:55 +00:00
#include "libslic3r/Print.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/Slicing.hpp"
#include "libslic3r/Format/AMF.hpp"
2018-02-08 12:26:50 +00:00
#include "libslic3r/Format/3mf.hpp"
#include "libslic3r/Format/OBJ.hpp"
#include "libslic3r/Format/STL.hpp"
2020-06-24 07:20:04 +00:00
#include "libslic3r/PresetBundle.hpp"
%}
%name{Slic3r::Model} class Model {
Model();
~Model();
%name{read_from_file} Model(std::string input_file, bool add_default_instances = true)
%code%{
try {
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)));
} catch (std::exception& e) {
croak("Error while opening %s: %s\n", input_file.c_str(), e.what());
}
%};
Clone<Model> clone()
%code%{ RETVAL = THIS; %};
%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)
%code%{ auto ptr = THIS->add_object(*other); if (! copy_volumes) ptr->clear_volumes(); RETVAL = ptr; %};
void delete_object(size_t idx);
void clear_objects();
2014-07-13 10:10:34 +00:00
size_t objects_count()
%code%{ RETVAL = THIS->objects.size(); %};
Ref<ModelObject> get_object(int idx)
%code%{ RETVAL = THIS->objects.at(idx); %};
Ref<ModelMaterial> get_material(t_model_material_id material_id)
%code%{
RETVAL = THIS->get_material(material_id);
if (RETVAL == NULL) {
XSRETURN_UNDEF;
}
%};
%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); %};
bool has_material(t_model_material_id material_id) const
%code%{
RETVAL = (THIS->get_material(material_id) != NULL);
%};
void delete_material(t_model_material_id material_id);
void clear_materials();
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();
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);
Clone<TriangleMesh> mesh();
ModelObjectPtrs* objects()
%code%{ RETVAL = &THIS->objects; %};
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); %};
bool looks_like_multipart_object() const;
void convert_multipart_object(unsigned int max_extruders);
bool store_stl(char *path, bool binary)
%code%{ TriangleMesh mesh = THIS->mesh(); RETVAL = Slic3r::store_stl(path, &mesh, binary); %};
%{
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
%}
};
%name{Slic3r::Model::Material} class ModelMaterial {
Ref<Model> model()
%code%{ RETVAL = THIS->get_model(); %};
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
%}
};
%name{Slic3r::Model::Object} class ModelObject {
ModelVolumePtrs* volumes()
%code%{ RETVAL = &THIS->volumes; %};
ModelInstancePtrs* instances()
%code%{ RETVAL = &THIS->instances; %};
void invalidate_bounding_box();
Clone<TriangleMesh> mesh();
Clone<TriangleMesh> raw_mesh();
%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); %};
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(); %};
Ref<ModelVolume> get_volume(int idx)
%code%{ RETVAL = THIS->volumes.at(idx); %};
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;
%};
%name{_add_instance} Ref<ModelInstance> add_instance();
Ref<ModelInstance> _add_instance_clone(ModelInstance* other)
%code%{ RETVAL = THIS->add_instance(*other); %};
void delete_last_instance();
void clear_instances();
int instances_count()
%code%{ RETVAL = THIS->instances.size(); %};
std::string name()
%code%{ RETVAL = THIS->name; %};
void set_name(std::string value)
%code%{ THIS->name = value; %};
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()); %};
Ref<Model> model()
%code%{ RETVAL = THIS->get_model(); %};
Ref<Vec3d> origin_translation()
%code%{ RETVAL = &THIS->origin_translation; %};
void set_origin_translation(Vec3d* point)
%code%{ THIS->origin_translation = *point; %};
2014-08-08 19:48:59 +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);
void scale_xyz(Vec3d* versor)
2014-09-21 08:51:36 +00:00
%code{% THIS->scale(*versor); %};
void rotate(float angle, Vec3d* axis)
%code{% THIS->rotate(angle, *axis); %};
void mirror(Axis axis);
2014-11-12 22:50:09 +00:00
};
%name{Slic3r::Model::Volume} class ModelVolume {
Ref<ModelObject> object()
%code%{ RETVAL = THIS->get_object(); %};
std::string name()
%code%{ RETVAL = THIS->name; %};
void set_name(std::string value)
%code%{ THIS->name = value; %};
t_model_material_id material_id();
void set_material_id(t_model_material_id material_id)
%code%{ THIS->set_material_id(material_id); %};
Ref<ModelMaterial> material();
Ref<DynamicPrintConfig> config()
2020-09-24 14:18:56 +00:00
%code%{ RETVAL = &const_cast<DynamicPrintConfig&>(THIS->config.get()); %};
Ref<TriangleMesh> mesh()
%code%{ RETVAL = &THIS->mesh(); %};
bool modifier()
2018-09-17 13:12:13 +00:00
%code%{ RETVAL = THIS->is_modifier(); %};
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); %};
size_t split(unsigned int max_extruders);
};
%name{Slic3r::Model::Instance} class ModelInstance {
Ref<ModelObject> object()
%code%{ RETVAL = THIS->get_object(); %};
Vec3d* rotation()
%code%{ RETVAL = new Vec3d(THIS->get_rotation(X), THIS->get_rotation(Y), THIS->get_rotation(Z)); %};
Vec3d* scaling_factor()
%code%{ RETVAL = new Vec3d(THIS->get_scaling_factor(X), THIS->get_scaling_factor(Y), THIS->get_scaling_factor(Z)); %};
2018-09-17 13:12:13 +00:00
Vec2d* offset()
%code%{ RETVAL = new Vec2d(THIS->get_offset(X), THIS->get_offset(Y)); %};
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(); %};
void set_scaling_factor(double val)
%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-17 13:12:13 +00:00
void set_offset(Vec2d *offset)
%code%{
THIS->set_offset(X, (*offset)(0));
THIS->set_offset(Y, (*offset)(1));
%};
};