Ported some methods to XS

This commit is contained in:
Alessandro Ranellucci 2014-08-03 18:41:09 +02:00
parent 1813a309a7
commit 380dd8adfc
13 changed files with 176 additions and 93 deletions

View file

@ -1,4 +1,7 @@
#include "Layer.hpp"
#include "ClipperUtils.hpp"
#include "Geometry.hpp"
#include "Print.hpp"
namespace Slic3r {
@ -108,6 +111,42 @@ Layer::delete_region(int idx)
delete item;
}
// merge all regions' slices to get islands
void
Layer::make_slices()
{
ExPolygons slices;
if (this->regions.size() == 1) {
// optimization: if we only have one region, take its slices
slices = this->regions.front()->slices;
} else {
Polygons slices_p;
FOREACH_LAYERREGION(this, layerm) {
Polygons region_slices_p = (*layerm)->slices;
slices_p.insert(slices_p.end(), region_slices_p.begin(), region_slices_p.end());
}
union_(slices_p, slices);
}
this->slices.expolygons.clear();
this->slices.expolygons.reserve(slices.size());
// prepare ordering points
Points ordering_points;
ordering_points.reserve(slices.size());
for (ExPolygons::const_iterator ex = slices.begin(); ex != slices.end(); ++ex)
ordering_points.push_back(ex->contour.first_point());
// sort slices
std::vector<Points::size_type> order;
Slic3r::Geometry::chained_path(ordering_points, order);
// populate slices vector
for (std::vector<Points::size_type>::const_iterator it = order.begin(); it != order.end(); ++it) {
this->slices.expolygons.push_back(slices[*it]);
}
}
#ifdef SLIC3RXS
REGISTER_CLASS(Layer, "Layer");

View file

@ -84,6 +84,8 @@ class Layer {
size_t region_count();
LayerRegion* get_region(int idx);
LayerRegion* add_region(PrintRegion* print_region);
void make_slices();
protected:
int _id; // sequential number of layer, 0-based

View file

@ -1,5 +1,6 @@
#include "Print.hpp"
#include "BoundingBox.hpp"
#include <algorithm>
namespace Slic3r {
@ -511,7 +512,7 @@ Print::invalidate_step(PrintStep step)
if (step == psSkirt) {
this->invalidate_step(psBrim);
} else if (step == psInitExtruders) {
for (PrintObjectPtrs::iterator object = this->objects.begin(); object != this->objects.end(); ++object) {
FOREACH_OBJECT(this, object) {
(*object)->invalidate_step(posPerimeters);
(*object)->invalidate_step(posSupportMaterial);
}
@ -533,6 +534,77 @@ Print::invalidate_all_steps()
return invalidated;
}
// returns 0-based indices of used extruders
std::set<size_t>
Print::extruders() const
{
std::set<size_t> extruders;
FOREACH_REGION(this, region) {
extruders.insert((*region)->config.perimeter_extruder - 1);
extruders.insert((*region)->config.infill_extruder - 1);
}
FOREACH_OBJECT(this, object) {
extruders.insert((*object)->config.support_material_extruder - 1);
extruders.insert((*object)->config.support_material_interface_extruder - 1);
}
return extruders;
}
void
Print::_simplify_slices(double distance)
{
FOREACH_OBJECT(this, object) {
FOREACH_LAYER(*object, layer) {
(*layer)->slices.simplify(distance);
FOREACH_LAYERREGION(*layer, layerm) {
(*layerm)->slices.simplify(distance);
}
}
}
}
double
Print::max_allowed_layer_height() const
{
std::vector<double> nozzle_diameter;
std::set<size_t> extruders = this->extruders();
for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
nozzle_diameter.push_back(this->config.nozzle_diameter.get_at(*e));
}
return *std::max_element(nozzle_diameter.begin(), nozzle_diameter.end());
}
void
Print::init_extruders()
{
if (this->state.is_done(psInitExtruders)) return;
this->state.set_done(psInitExtruders);
// enforce tall skirt if using ooze_prevention
// FIXME: this is not idempotent (i.e. switching ooze_prevention off will not revert skirt settings)
if (this->config.ooze_prevention && this->extruders().size() > 1) {
this->config.skirt_height.value = -1;
if (this->config.skirts == 0) this->config.skirts.value = 1;
}
this->state.set_done(psInitExtruders);
}
bool
Print::has_support_material() const
{
FOREACH_OBJECT(this, object) {
PrintObjectConfig &config = (*object)->config;
if (config.support_material || config.raft_layers > 0 || config.support_material_enforce_layers > 0)
return true;
}
return false;
}
#ifdef SLIC3RXS
REGISTER_CLASS(Print, "Print");

View file

@ -160,12 +160,25 @@ class Print
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
bool invalidate_step(PrintStep step);
bool invalidate_all_steps();
void init_extruders();
std::set<size_t> extruders() const;
void _simplify_slices(double distance);
double max_allowed_layer_height() const;
bool has_support_material() const;
private:
void clear_regions();
void delete_region(size_t idx);
};
#define FOREACH_BASE(type, container, iterator) for (type::const_iterator iterator = (container).begin(); iterator != (container).end(); ++iterator)
#define FOREACH_REGION(print, region) FOREACH_BASE(PrintRegionPtrs, (print)->regions, region)
#define FOREACH_OBJECT(print, object) FOREACH_BASE(PrintObjectPtrs, (print)->objects, object)
#define FOREACH_LAYER(object, layer) FOREACH_BASE(LayerPtrs, (object)->layers, layer)
#define FOREACH_LAYERREGION(layer, layerm) FOREACH_BASE(LayerRegionPtrs, (layer)->regions, layerm)
}
#endif

View file

@ -3,6 +3,26 @@
namespace Slic3r {
SurfaceCollection::operator Polygons() const
{
Polygons polygons;
for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) {
Polygons surface_p = surface->expolygon;
polygons.insert(polygons.end(), surface_p.begin(), surface_p.end());
}
return polygons;
}
SurfaceCollection::operator ExPolygons() const
{
ExPolygons expp;
expp.reserve(this->surfaces.size());
for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) {
expp.push_back(surface->expolygon);
}
return expp;
}
void
SurfaceCollection::simplify(double tolerance)
{

View file

@ -10,6 +10,9 @@ class SurfaceCollection
{
public:
Surfaces surfaces;
operator Polygons() const;
operator ExPolygons() const;
void simplify(double tolerance);
void group(std::vector<SurfacesPtr> *retval);
};