Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Model.xsp « xsp « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f9b5cd1599738d063e5e70ecadcd8ab5968f991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
%module{Slic3r::XS};

%{
#include <xsinit.h>
#include "libslic3r/Model.hpp"
#include "libslic3r/Print.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/Slicing.hpp"
#include "libslic3r/Format/AMF.hpp"
#include "libslic3r/Format/3mf.hpp"
#include "libslic3r/Format/OBJ.hpp"
#include "libslic3r/Format/PRUS.hpp"
#include "libslic3r/Format/STL.hpp"
#include "slic3r/GUI/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 {
                RETVAL = new Model(Model::read_from_file(input_file, add_default_instances));
            } catch (std::exception& e) {
                croak("Error while opening %s: %s\n", input_file.c_str(), e.what());
            }
        %};

    %name{read_from_archive} Model(std::string input_file, PresetBundle* bundle, bool add_default_instances = true)
        %code%{
            try {
                RETVAL = new Model(Model::read_from_archive(input_file, bundle, add_default_instances));
            } 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();
    Ref<ModelObject> _add_object_clone(ModelObject* other, bool copy_volumes = true)
        %code%{ RETVAL = THIS->add_object(*other, copy_volumes); %};
    void delete_object(size_t idx);
    void clear_objects();
    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(); %};

    bool add_default_instances();
    Clone<BoundingBoxf3> bounding_box();
    void center_instances_around_point(Pointf* point)
        %code%{ THIS->center_instances_around_point(*point); %};
    void translate(double x, double y, double z);
    Clone<TriangleMesh> mesh();

    ModelObjectPtrs* objects()
        %code%{ RETVAL = &THIS->objects; %};
    
    bool arrange_objects(double dist, BoundingBoxf* bb = NULL);
    void duplicate(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL);
    void duplicate_objects(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL);
    void duplicate_objects_grid(unsigned int x, unsigned int y, double dist);

    bool looks_like_multipart_object() const;
    void convert_multipart_object(unsigned int max_extruders);

    void print_info() const;

    bool store_stl(char *path, bool binary)
        %code%{ TriangleMesh mesh = THIS->mesh(); RETVAL = Slic3r::store_stl(path, &mesh, binary); %};
    bool store_amf(char *path, Print* print, bool export_print_config)
        %code%{ RETVAL = Slic3r::store_amf(path, THIS, print, export_print_config); %};
    bool store_3mf(char *path, Print* print, bool export_print_config)
        %code%{ RETVAL = Slic3r::store_3mf(path, THIS, print, export_print_config); %};

%{

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

Model*
load_obj(CLASS, path, object_name)
    char*           CLASS;
    char*           path;
    char*           object_name;
    CODE:
        RETVAL = new Model();
        if (! load_obj(path, RETVAL, object_name)) {
            delete RETVAL;
            RETVAL = NULL;
        }
    OUTPUT:
        RETVAL

Model*
load_amf(CLASS, bundle, path)
    char*           CLASS;
    PresetBundle*   bundle;
    char*           path;
    CODE:
        RETVAL = new Model();
        if (! load_amf(path, bundle, RETVAL)) {
            delete RETVAL;
            RETVAL = NULL;
        }
    OUTPUT:
        RETVAL

Model*
load_3mf(CLASS, bundle, path)
    char*           CLASS;
    PresetBundle*   bundle;
    char*           path;
    CODE:
        RETVAL = new Model();
        if (! load_3mf(path, bundle, RETVAL)) {
            delete RETVAL;
            RETVAL = NULL;
        }
    OUTPUT:
        RETVAL
        
Model*
load_prus(CLASS, path)
    char*           CLASS;
    char*           path;
    CODE:
#ifdef SLIC3R_PRUS
        RETVAL = new Model();
        if (! load_prus(path, RETVAL)) {
            delete RETVAL;
            RETVAL = NULL;
        }
#else
        RETVAL = nullptr;
#endif
    OUTPUT:
        RETVAL

%}

};

%name{Slic3r::Model::Material} class ModelMaterial {
    Ref<Model> model()
        %code%{ RETVAL = THIS->get_model(); %};

    Ref<DynamicPrintConfig> config()
        %code%{ RETVAL = &THIS->config; %};
    
    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();
    Clone<BoundingBoxf3> instance_bounding_box(int idx)
        %code%{ RETVAL = THIS->instance_bounding_box(idx, true); %};
    Clone<BoundingBoxf3> bounding_box();

    %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();
    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()
        %code%{ RETVAL = &THIS->config; %};

    Ref<Model> model()
        %code%{ RETVAL = THIS->get_model(); %};

    t_layer_height_ranges layer_height_ranges()
        %code%{ RETVAL = THIS->layer_height_ranges; %};
    void set_layer_height_ranges(t_layer_height_ranges ranges)
        %code%{ THIS->layer_height_ranges = ranges; %};

    std::vector<double> layer_height_profile() 
        %code%{ RETVAL = THIS->layer_height_profile_valid ? THIS->layer_height_profile : std::vector<double>(); %};
    void set_layer_height_profile(std::vector<double> profile)
        %code%{ THIS->layer_height_profile = profile; THIS->layer_height_profile_valid = true; %};

    Ref<Pointf3> origin_translation()
        %code%{ RETVAL = &THIS->origin_translation; %};
    void set_origin_translation(Pointf3* point)
        %code%{ THIS->origin_translation = *point; %};
    
    bool needed_repair() const;
    int materials_count() const;
    int facets_count();
    void center_around_origin();
    void translate(double x, double y, double z);
    void scale_xyz(Pointf3* versor)
        %code{% THIS->scale(*versor); %};
    void rotate(float angle, Pointf3* axis)
        %code{% THIS->rotate(angle, *axis); %};
    void mirror(Axis axis);
    
    Model* cut(double z)
        %code%{
            RETVAL = new Model();
            THIS->cut(z, RETVAL);
        %};

    ModelObjectPtrs* split_object()
        %code%{
            RETVAL = new ModelObjectPtrs();  // leak?
            THIS->split(RETVAL);
        %};

    void print_info() const;
};


%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->material_id(material_id); %};
    Ref<ModelMaterial> material();
    
    Ref<DynamicPrintConfig> config()
        %code%{ RETVAL = &THIS->config; %};
    Ref<TriangleMesh> mesh()
        %code%{ RETVAL = &THIS->mesh; %};
    
    bool modifier()
        %code%{ RETVAL = THIS->is_modifier(); %};
    void set_modifier(bool modifier)
        %code%{ THIS->set_type(modifier ? ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART); %};
    bool model_part()
        %code%{ RETVAL = THIS->is_model_part(); %};
    bool support_enforcer()
        %code%{ RETVAL = THIS->is_support_enforcer(); %};
    void set_support_enforcer()
        %code%{ THIS->set_type(ModelVolume::SUPPORT_ENFORCER); %};
    bool support_blocker()
        %code%{ RETVAL = THIS->is_support_blocker(); %};
    void set_support_blocker()
        %code%{ THIS->set_type(ModelVolume::SUPPORT_BLOCKER); %};

    size_t split(unsigned int max_extruders);
    
    ModelMaterial* assign_unique_material();
};


%name{Slic3r::Model::Instance} class ModelInstance {
    Ref<ModelObject> object()
        %code%{ RETVAL = THIS->get_object(); %};

    double rotation()
        %code%{ RETVAL = THIS->rotation; %};
    double scaling_factor()
        %code%{ RETVAL = THIS->scaling_factor; %};
    Ref<Pointf> offset()
        %code%{ RETVAL = &THIS->offset; %};

    void set_rotation(double val)
        %code%{ THIS->rotation = val; THIS->get_object()->invalidate_bounding_box(); %};
    void set_scaling_factor(double val)
        %code%{ THIS->scaling_factor = val; THIS->get_object()->invalidate_bounding_box(); %};
    void set_offset(Pointf *offset)
        %code%{ THIS->offset = *offset; %};
    
    void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
    void transform_polygon(Polygon* polygon) const;
};