%module{Slic3r::XS}; %{ #include #include "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] = *(Surface *)SvIV((SV*)SvRV( 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++, (*it).to_SV_ref()); } 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, (*it).to_SV_ref()); } RETVAL = newRV_noinc((SV*)av); OUTPUT: RETVAL void SurfaceCollection::append(...) CODE: for (unsigned int i = 1; i < items; i++) { // Note: a COPY of the input is stored THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) ))); } 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(merge_solid = false) bool merge_solid CODE: // perform grouping std::vector groups; THIS->group(&groups, merge_solid); // build return arrayref AV* av = newAV(); av_fill(av, groups.size()-1); size_t i = 0; for (std::vector::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++, (*it_s)->to_SV_clone_ref()); } av_store(av, i++, newRV_noinc((SV*)innerav)); } RETVAL = newRV_noinc((SV*)av); OUTPUT: RETVAL %} };