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
|
%module{Slic3r::XS};
%{
#include <myinit.h>
#include "libslic3r/SurfaceCollection.hpp"
%}
%name{Slic3r::Surface::Collection} class SurfaceCollection {
~SurfaceCollection();
void clear()
%code{% THIS->surfaces.clear(); %};
int count()
%code{% RETVAL = THIS->surfaces.size(); %};
void simplify(double tolerance);
%{
SurfaceCollection*
SurfaceCollection::new(...)
CODE:
RETVAL = new SurfaceCollection;
// ST(0) is class name, others are surfaces
RETVAL->surfaces.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
// Note: a COPY of the input is stored
RETVAL->surfaces[i-1].from_SV_check(ST(i));
}
OUTPUT:
RETVAL
SV*
SurfaceCollection::arrayref()
CODE:
AV* av = newAV();
av_fill(av, THIS->surfaces.size()-1);
int i = 0;
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
av_store(av, i++, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
RETVAL
SV*
SurfaceCollection::filter_by_type(surface_type)
SurfaceType surface_type;
CODE:
AV* av = newAV();
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
if ((*it).surface_type == surface_type) av_push(av, perl_to_SV_ref(*it));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
RETVAL
void
SurfaceCollection::append(...)
CODE:
for (unsigned int i = 1; i < items; i++) {
Surface surface;
surface.from_SV_check( ST(i) );
THIS->surfaces.push_back(surface);
}
void
SurfaceCollection::replace(index, surface)
int index
Surface* surface
CODE:
THIS->surfaces[index] = *surface;
void
SurfaceCollection::set_surface_type(index, surface_type)
int index
SurfaceType surface_type;
CODE:
THIS->surfaces[index].surface_type = surface_type;
SV*
SurfaceCollection::group()
CODE:
// perform grouping
std::vector<SurfacesPtr> groups;
THIS->group(&groups);
// build return arrayref
AV* av = newAV();
av_fill(av, groups.size()-1);
size_t i = 0;
for (std::vector<SurfacesPtr>::iterator it = groups.begin(); it != groups.end(); ++it) {
AV* innerav = newAV();
av_fill(innerav, it->size()-1);
size_t j = 0;
for (SurfacesPtr::iterator it_s = it->begin(); it_s != it->end(); ++it_s) {
av_store(innerav, j++, perl_to_SV_clone_ref(**it_s));
}
av_store(av, i++, newRV_noinc((SV*)innerav));
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
RETVAL
%}
};
|