2013-07-18 17:09:07 +00:00
|
|
|
#ifndef slic3r_ExtrusionEntityCollection_hpp_
|
|
|
|
#define slic3r_ExtrusionEntityCollection_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-18 17:09:07 +00:00
|
|
|
#include "ExtrusionEntity.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-07-18 20:29:12 +00:00
|
|
|
class ExtrusionEntityCollection : public ExtrusionEntity
|
2013-07-18 17:09:07 +00:00
|
|
|
{
|
2016-11-03 23:10:35 +00:00
|
|
|
public:
|
2013-08-29 09:47:59 +00:00
|
|
|
ExtrusionEntityCollection* clone() const;
|
2015-07-23 13:53:02 +00:00
|
|
|
ExtrusionEntitiesPtr entities; // we own these entities
|
2014-03-15 01:16:04 +00:00
|
|
|
std::vector<size_t> orig_indices; // handy for XS
|
2013-07-18 17:09:07 +00:00
|
|
|
bool no_sort;
|
2013-08-25 18:29:45 +00:00
|
|
|
ExtrusionEntityCollection(): no_sort(false) {};
|
2017-01-19 12:37:15 +00:00
|
|
|
ExtrusionEntityCollection(const ExtrusionEntityCollection &other) : orig_indices(other.orig_indices), no_sort(other.no_sort) { this->append(other.entities); }
|
|
|
|
ExtrusionEntityCollection(ExtrusionEntityCollection &&other) : entities(std::move(other.entities)), orig_indices(std::move(other.orig_indices)), no_sort(other.no_sort) {}
|
2017-01-20 13:39:44 +00:00
|
|
|
explicit ExtrusionEntityCollection(const ExtrusionPaths &paths);
|
2017-01-19 12:37:15 +00:00
|
|
|
ExtrusionEntityCollection& operator=(const ExtrusionEntityCollection &other);
|
|
|
|
ExtrusionEntityCollection& operator=(ExtrusionEntityCollection &&other)
|
|
|
|
{ this->entities = std::move(other.entities); this->orig_indices = std::move(other.orig_indices); this->no_sort = other.no_sort; return *this; }
|
2016-11-02 09:47:00 +00:00
|
|
|
~ExtrusionEntityCollection() { clear(); }
|
2017-01-20 13:39:44 +00:00
|
|
|
explicit operator ExtrusionPaths() const;
|
2015-07-06 23:17:31 +00:00
|
|
|
|
2016-11-03 23:10:35 +00:00
|
|
|
bool is_collection() const { return true; };
|
2018-09-17 13:12:13 +00:00
|
|
|
ExtrusionRole role() const override {
|
2017-04-07 15:37:30 +00:00
|
|
|
ExtrusionRole out = erNone;
|
|
|
|
for (const ExtrusionEntity *ee : entities) {
|
|
|
|
ExtrusionRole er = ee->role();
|
|
|
|
out = (out == erNone || out == er) ? er : erMixed;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2016-11-03 23:10:35 +00:00
|
|
|
bool can_reverse() const { return !this->no_sort; };
|
|
|
|
bool empty() const { return this->entities.empty(); };
|
2016-11-02 09:47:00 +00:00
|
|
|
void clear();
|
2014-04-24 14:40:10 +00:00
|
|
|
void swap (ExtrusionEntityCollection &c);
|
2016-11-03 23:10:35 +00:00
|
|
|
void append(const ExtrusionEntity &entity) { this->entities.push_back(entity.clone()); }
|
2017-01-20 13:39:44 +00:00
|
|
|
void append(const ExtrusionEntitiesPtr &entities) {
|
|
|
|
this->entities.reserve(this->entities.size() + entities.size());
|
|
|
|
for (ExtrusionEntitiesPtr::const_iterator ptr = entities.begin(); ptr != entities.end(); ++ptr)
|
|
|
|
this->entities.push_back((*ptr)->clone());
|
|
|
|
}
|
|
|
|
void append(ExtrusionEntitiesPtr &&src) {
|
|
|
|
if (entities.empty())
|
|
|
|
entities = std::move(src);
|
|
|
|
else {
|
|
|
|
std::move(std::begin(src), std::end(src), std::back_inserter(entities));
|
|
|
|
src.clear();
|
|
|
|
}
|
|
|
|
}
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
void append(const ExtrusionPaths &paths) {
|
2017-01-20 13:39:44 +00:00
|
|
|
this->entities.reserve(this->entities.size() + paths.size());
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
for (const ExtrusionPath &path : paths)
|
|
|
|
this->entities.emplace_back(path.clone());
|
|
|
|
}
|
|
|
|
void append(ExtrusionPaths &&paths) {
|
|
|
|
this->entities.reserve(this->entities.size() + paths.size());
|
|
|
|
for (ExtrusionPath &path : paths)
|
|
|
|
this->entities.emplace_back(new ExtrusionPath(std::move(path)));
|
2017-01-20 13:39:44 +00:00
|
|
|
}
|
2016-03-19 14:33:58 +00:00
|
|
|
void replace(size_t i, const ExtrusionEntity &entity);
|
|
|
|
void remove(size_t i);
|
2017-04-07 15:37:30 +00:00
|
|
|
ExtrusionEntityCollection chained_path(bool no_reverse = false, ExtrusionRole role = erMixed) const;
|
|
|
|
void chained_path(ExtrusionEntityCollection* retval, bool no_reverse = false, ExtrusionRole role = erMixed, std::vector<size_t>* orig_indices = nullptr) const;
|
2017-05-03 16:28:22 +00:00
|
|
|
ExtrusionEntityCollection chained_path_from(Point start_near, bool no_reverse = false, ExtrusionRole role = erMixed) const;
|
2017-04-07 15:37:30 +00:00
|
|
|
void chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse = false, ExtrusionRole role = erMixed, std::vector<size_t>* orig_indices = nullptr) const;
|
2013-08-29 09:47:59 +00:00
|
|
|
void reverse();
|
2016-11-03 23:10:35 +00:00
|
|
|
Point first_point() const { return this->entities.front()->first_point(); }
|
|
|
|
Point last_point() const { return this->entities.back()->last_point(); }
|
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
2018-09-17 13:12:13 +00:00
|
|
|
void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const override;
|
2016-11-03 23:10:35 +00:00
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion spacing.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
// Useful to calculate area of an infill, which has been really filled in by a 100% rectilinear infill.
|
2018-09-17 13:12:13 +00:00
|
|
|
void polygons_covered_by_spacing(Polygons &out, const float scaled_epsilon) const override;
|
2016-11-03 23:10:35 +00:00
|
|
|
Polygons polygons_covered_by_width(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_width(out, scaled_epsilon); return out; }
|
|
|
|
Polygons polygons_covered_by_spacing(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_spacing(out, scaled_epsilon); return out; }
|
2015-04-12 18:16:27 +00:00
|
|
|
size_t items_count() const;
|
2015-05-31 20:04:32 +00:00
|
|
|
void flatten(ExtrusionEntityCollection* retval) const;
|
2015-07-06 23:17:31 +00:00
|
|
|
ExtrusionEntityCollection flatten() const;
|
2015-05-31 20:04:32 +00:00
|
|
|
double min_mm3_per_mm() const;
|
2018-09-17 13:12:13 +00:00
|
|
|
double total_volume() const override { double volume=0.; for (const auto& ent : entities) volume+=ent->total_volume(); return volume; }
|
2017-05-03 16:28:22 +00:00
|
|
|
|
|
|
|
// Following methods shall never be called on an ExtrusionEntityCollection.
|
2015-07-23 13:53:02 +00:00
|
|
|
Polyline as_polyline() const {
|
2018-09-18 08:09:58 +00:00
|
|
|
throw std::runtime_error("Calling as_polyline() on a ExtrusionEntityCollection");
|
2015-07-23 13:53:02 +00:00
|
|
|
return Polyline();
|
|
|
|
};
|
2018-09-17 13:12:13 +00:00
|
|
|
|
|
|
|
void collect_polylines(Polylines &dst) const override {
|
|
|
|
for (ExtrusionEntity* extrusion_entity : this->entities)
|
|
|
|
extrusion_entity->collect_polylines(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
double length() const override {
|
2018-09-18 08:09:58 +00:00
|
|
|
throw std::runtime_error("Calling length() on a ExtrusionEntityCollection");
|
2016-11-03 23:10:35 +00:00
|
|
|
return 0.;
|
|
|
|
}
|
2013-07-18 17:09:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|