115aa6885f
Type handling is mainly done using templates. Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used. Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type). Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return. Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments). It is overloaded to be able to return type, type* and type&. Typechecking in ExtrusionEntityCollection updated to check all passed types.
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#include "SurfaceCollection.hpp"
|
|
#include <map>
|
|
#ifdef SLIC3RXS
|
|
#include "perlglue.hpp"
|
|
#endif
|
|
|
|
namespace Slic3r {
|
|
|
|
void
|
|
SurfaceCollection::simplify(double tolerance)
|
|
{
|
|
Surfaces ss;
|
|
for (Surfaces::const_iterator it_s = this->surfaces.begin(); it_s != this->surfaces.end(); ++it_s) {
|
|
ExPolygons expp;
|
|
it_s->expolygon.simplify(tolerance, expp);
|
|
for (ExPolygons::const_iterator it_e = expp.begin(); it_e != expp.end(); ++it_e) {
|
|
Surface s = *it_s;
|
|
s.expolygon = *it_e;
|
|
ss.push_back(s);
|
|
}
|
|
}
|
|
this->surfaces = ss;
|
|
}
|
|
|
|
/* group surfaces by common properties */
|
|
void
|
|
SurfaceCollection::group(std::vector<SurfacesPtr> *retval)
|
|
{
|
|
for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
|
|
// find a group with the same properties
|
|
SurfacesPtr* group = NULL;
|
|
for (std::vector<SurfacesPtr>::iterator git = retval->begin(); git != retval->end(); ++git) {
|
|
Surface* gkey = git->front();
|
|
if ( gkey->surface_type == it->surface_type
|
|
&& gkey->thickness == it->thickness
|
|
&& gkey->thickness_layers == it->thickness_layers
|
|
&& gkey->bridge_angle == it->bridge_angle) {
|
|
group = &*git;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// if no group with these properties exists, add one
|
|
if (group == NULL) {
|
|
retval->resize(retval->size() + 1);
|
|
group = &retval->back();
|
|
}
|
|
|
|
// append surface to group
|
|
group->push_back(&*it);
|
|
}
|
|
}
|
|
|
|
#ifdef SLIC3RXS
|
|
REGISTER_CLASS(SurfaceCollection, "Surface::Collection");
|
|
#endif
|
|
|
|
}
|