Merge branch 'master' into sender

This commit is contained in:
Alessandro Ranellucci 2015-03-06 22:15:43 +01:00
commit d2172b4383
47 changed files with 860 additions and 429 deletions

View file

@ -37,14 +37,10 @@ BridgeDetector::BridgeDetector(const ExPolygon &_expolygon, const ExPolygonColle
Polygons grown;
offset((Polygons)this->expolygon, &grown, this->extrusion_width);
// detect what edges lie on lower slices
for (ExPolygons::const_iterator lower = this->lower_slices.expolygons.begin();
lower != this->lower_slices.expolygons.end();
++lower) {
/* turn bridge contour and holes into polylines and then clip them
with each lower slice's contour */
intersection(grown, lower->contour, &this->_edges);
}
// detect what edges lie on lower slices by turning bridge contour and holes
// into polylines and then clipping them with each lower slice's contour
intersection(grown, this->lower_slices.contours(), &this->_edges);
#ifdef SLIC3R_DEBUG
printf(" bridge has %zu support(s)\n", this->_edges.size());
#endif

View file

@ -112,6 +112,16 @@ ExPolygonCollection::lines() const
return lines;
}
Polygons
ExPolygonCollection::contours() const
{
Polygons contours;
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
contours.push_back(it->contour);
}
return contours;
}
#ifdef SLIC3RXS
REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection");
#endif

View file

@ -30,6 +30,7 @@ class ExPolygonCollection
void simplify(double tolerance);
Polygon convex_hull() const;
Lines lines() const;
Polygons contours() const;
};
}

View file

@ -66,6 +66,15 @@ GCodeWriter::preamble()
return gcode.str();
}
std::string
GCodeWriter::postamble()
{
std::ostringstream gcode;
if (FLAVOR_IS(gcfMachinekit))
gcode << "M2 ; end of program\n";
return gcode.str();
}
std::string
GCodeWriter::set_temperature(unsigned int temperature, bool wait, int tool)
{
@ -83,7 +92,7 @@ GCodeWriter::set_temperature(unsigned int temperature, bool wait, int tool)
std::ostringstream gcode;
gcode << code << " ";
if (FLAVOR_IS(gcfMach3)) {
if (FLAVOR_IS(gcfMach3) || FLAVOR_IS(gcfMachinekit)) {
gcode << "P";
} else {
gcode << "S";
@ -118,7 +127,7 @@ GCodeWriter::set_bed_temperature(unsigned int temperature, bool wait)
std::ostringstream gcode;
gcode << code << " ";
if (FLAVOR_IS(gcfMach3)) {
if (FLAVOR_IS(gcfMach3) || FLAVOR_IS(gcfMachinekit)) {
gcode << "P";
} else {
gcode << "S";
@ -153,7 +162,7 @@ GCodeWriter::set_fan(unsigned int speed, bool dont_save)
gcode << "M126";
} else {
gcode << "M106 ";
if (FLAVOR_IS(gcfMach3)) {
if (FLAVOR_IS(gcfMach3) || FLAVOR_IS(gcfMachinekit)) {
gcode << "P";
} else {
gcode << "S";
@ -434,7 +443,10 @@ GCodeWriter::_retract(double length, double restart_extra, const std::string &co
double dE = this->_extruder->retract(length, restart_extra);
if (dE != 0) {
if (this->config.use_firmware_retraction) {
gcode << "G10 ; retract\n";
if (FLAVOR_IS(gcfMachinekit))
gcode << "G22 ; retract\n";
else
gcode << "G10 ; retract\n";
} else {
gcode << "G1 " << this->_extrusion_axis << E_NUM(this->_extruder->E)
<< " F" << this->_extruder->retract_speed_mm_min;
@ -460,7 +472,10 @@ GCodeWriter::unretract()
double dE = this->_extruder->unretract();
if (dE != 0) {
if (this->config.use_firmware_retraction) {
gcode << "G11 ; unretract\n";
if (FLAVOR_IS(gcfMachinekit))
gcode << "G23 ; unretract\n";
else
gcode << "G11 ; unretract\n";
gcode << this->reset_e();
} else {
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
@ -509,4 +524,4 @@ GCodeWriter::get_position() const
REGISTER_CLASS(GCodeWriter, "GCode::Writer");
#endif
}
}

View file

@ -24,6 +24,7 @@ class GCodeWriter {
void apply_print_config(const PrintConfig &print_config);
void set_extruders(const std::vector<unsigned int> &extruder_ids);
std::string preamble();
std::string postamble();
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1);
std::string set_bed_temperature(unsigned int temperature, bool wait = false);
std::string set_fan(unsigned int speed, bool dont_save = false);

View file

@ -61,13 +61,18 @@ LayerRegion::prepare_fill_surfaces()
the only meaningful information returned by psPerimeters. */
// if no solid layers are requested, turn top/bottom surfaces to internal
if (this->_region->config.top_solid_layers == 0) {
if (this->region()->config.top_solid_layers == 0) {
for (Surfaces::iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface) {
if (surface->surface_type == stTop)
surface->surface_type = stInternal;
if (surface->surface_type == stTop) {
if (this->layer()->object()->config.infill_only_where_needed) {
surface->surface_type = stInternalVoid;
} else {
surface->surface_type = stInternal;
}
}
}
}
if (this->_region->config.bottom_solid_layers == 0) {
if (this->region()->config.bottom_solid_layers == 0) {
for (Surfaces::iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface) {
if (surface->surface_type == stBottom || surface->surface_type == stBottomBridge)
surface->surface_type = stInternal;
@ -75,9 +80,9 @@ LayerRegion::prepare_fill_surfaces()
}
// turn too small internal regions into solid regions according to the user setting
if (this->_region->config.fill_density.value > 0) {
if (this->region()->config.fill_density.value > 0) {
// scaling an area requires two calls!
double min_area = scale_(scale_(this->_region->config.solid_infill_below_area.value));
double min_area = scale_(scale_(this->region()->config.solid_infill_below_area.value));
for (Surfaces::iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface) {
if (surface->surface_type == stInternal && surface->area() <= min_area)
surface->surface_type = stInternalSolid;

View file

@ -166,13 +166,14 @@ Print::invalidate_state_by_config_options(const std::vector<t_config_option_key>
if (*opt_key == "skirts"
|| *opt_key == "skirt_height"
|| *opt_key == "skirt_distance"
|| *opt_key == "min_skirt_length") {
|| *opt_key == "min_skirt_length"
|| *opt_key == "ooze_prevention") {
steps.insert(psSkirt);
} else if (*opt_key == "brim_width") {
steps.insert(psBrim);
steps.insert(psSkirt);
} else if (*opt_key == "nozzle_diameter") {
steps.insert(psInitExtruders);
osteps.insert(posSlice);
} else if (*opt_key == "avoid_crossing_perimeters"
|| *opt_key == "bed_shape"
|| *opt_key == "bed_temperature"
@ -266,11 +267,6 @@ Print::invalidate_step(PrintStep step)
// propagate to dependent steps
if (step == psSkirt) {
this->invalidate_step(psBrim);
} else if (step == psInitExtruders) {
FOREACH_OBJECT(this, object) {
(*object)->invalidate_step(posPerimeters);
(*object)->invalidate_step(posSupportMaterial);
}
}
return invalidated;
@ -309,13 +305,22 @@ 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);
extruders.insert((*region)->config.solid_infill_extruder - 1);
// these checks reflect the same logic used in the GUI for enabling/disabling
// extruder selection fields
if ((*region)->config.perimeters.value > 0 || this->config.brim_width.value > 0)
extruders.insert((*region)->config.perimeter_extruder - 1);
if ((*region)->config.fill_density.value > 0)
extruders.insert((*region)->config.infill_extruder - 1);
if ((*region)->config.top_solid_layers.value > 0 || (*region)->config.bottom_solid_layers.value > 0)
extruders.insert((*region)->config.solid_infill_extruder - 1);
}
FOREACH_OBJECT(this, object) {
extruders.insert((*object)->config.support_material_extruder - 1);
extruders.insert((*object)->config.support_material_interface_extruder - 1);
if ((*object)->has_support_material()) {
extruders.insert((*object)->config.support_material_extruder - 1);
extruders.insert((*object)->config.support_material_interface_extruder - 1);
}
}
return extruders;
@ -534,20 +539,16 @@ Print::apply_config(DynamicPrintConfig config)
return invalidated;
}
void
Print::init_extruders()
bool Print::has_infinite_skirt() const
{
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);
return (this->config.skirt_height == -1 && this->config.skirts > 0)
|| (this->config.ooze_prevention && this->extruders().size() > 1);
}
bool Print::has_skirt() const
{
return (this->config.skirt_height > 0 && this->config.skirts > 0)
|| this->has_infinite_skirt();
}
void
@ -625,17 +626,37 @@ Print::validate() const
}
{
std::vector<double> layer_heights;
// find the smallest nozzle diameter
std::set<size_t> extruders = this->extruders();
if (extruders.empty())
throw PrintValidationException("The supplied settings will cause an empty print.");
std::set<double> nozzle_diameters;
for (std::set<size_t>::iterator it = extruders.begin(); it != extruders.end(); ++it)
nozzle_diameters.insert(this->config.nozzle_diameter.get_at(*it));
double min_nozzle_diameter = *std::min_element(nozzle_diameters.begin(), nozzle_diameters.end());
FOREACH_OBJECT(this, i_object) {
PrintObject* object = *i_object;
layer_heights.push_back(object->config.layer_height);
layer_heights.push_back(object->config.get_abs_value("first_layer_height"));
}
double max_layer_height = *std::max_element(layer_heights.begin(), layer_heights.end());
std::set<size_t> extruders = this->extruders();
for (std::set<size_t>::iterator it = extruders.begin(); it != extruders.end(); ++it) {
if (max_layer_height > this->config.nozzle_diameter.get_at(*it))
// validate first_layer_height
double first_layer_height = object->config.get_abs_value("first_layer_height");
double first_layer_min_nozzle_diameter;
if (object->config.raft_layers > 0) {
// if we have raft layers, only support material extruder is used on first layer
size_t first_layer_extruder = object->config.raft_layers == 1
? object->config.support_material_interface_extruder-1
: object->config.support_material_extruder-1;
first_layer_min_nozzle_diameter = this->config.nozzle_diameter.get_at(first_layer_extruder);
} else {
// if we don't have raft layers, any nozzle diameter is potentially used in first layer
first_layer_min_nozzle_diameter = min_nozzle_diameter;
}
if (first_layer_height > first_layer_min_nozzle_diameter)
throw PrintValidationException("First layer height can't be greater than nozzle diameter");
// validate layer_height
if (object->config.layer_height.value > min_nozzle_diameter)
throw PrintValidationException("Layer height can't be greater than nozzle diameter");
}
}
@ -682,13 +703,15 @@ Print::total_bounding_box() const
Flow brim_flow = this->brim_flow();
extra = std::max(extra, this->config.brim_width.value + brim_flow.width/2);
}
if (this->config.skirts.value > 0) {
if (this->has_skirt()) {
int skirts = this->config.skirts.value;
if (skirts == 0 && this->has_infinite_skirt()) skirts = 1;
Flow skirt_flow = this->skirt_flow();
extra = std::max(
extra,
this->config.brim_width.value
+ this->config.skirt_distance.value
+ this->config.skirts.value * skirt_flow.spacing()
+ skirts * skirt_flow.spacing()
+ skirt_flow.width/2
);
}
@ -773,9 +796,7 @@ 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;
if ((*object)->has_support_material()) return true;
}
return false;
}

View file

@ -22,7 +22,7 @@ class ModelObject;
enum PrintStep {
psInitExtruders, psSkirt, psBrim,
psSkirt, psBrim,
};
enum PrintObjectStep {
posSlice, posPerimeters, posPrepareInfill,
@ -134,6 +134,7 @@ class PrintObject
bool invalidate_step(PrintObjectStep step);
bool invalidate_all_steps();
bool has_support_material() const;
void bridge_over_infill();
private:
@ -189,7 +190,8 @@ class Print
void add_model_object(ModelObject* model_object, int idx = -1);
bool apply_config(DynamicPrintConfig config);
void init_extruders();
bool has_infinite_skirt() const;
bool has_skirt() const;
void validate() const;
BoundingBox bounding_box() const;
BoundingBox total_bounding_box() const;

View file

@ -380,12 +380,14 @@ PrintConfigDef::build_def() {
Options["gcode_flavor"].enum_values.push_back("makerware");
Options["gcode_flavor"].enum_values.push_back("sailfish");
Options["gcode_flavor"].enum_values.push_back("mach3");
Options["gcode_flavor"].enum_values.push_back("machinekit");
Options["gcode_flavor"].enum_values.push_back("no-extrusion");
Options["gcode_flavor"].enum_labels.push_back("RepRap (Marlin/Sprinter/Repetier)");
Options["gcode_flavor"].enum_labels.push_back("Teacup");
Options["gcode_flavor"].enum_labels.push_back("MakerWare (MakerBot)");
Options["gcode_flavor"].enum_labels.push_back("Sailfish (MakerBot)");
Options["gcode_flavor"].enum_labels.push_back("Mach3/LinuxCNC");
Options["gcode_flavor"].enum_labels.push_back("Machinekit");
Options["gcode_flavor"].enum_labels.push_back("No extrusion");
Options["infill_acceleration"].type = coFloat;
@ -426,7 +428,7 @@ PrintConfigDef::build_def() {
Options["infill_only_where_needed"].type = coBool;
Options["infill_only_where_needed"].label = "Only infill where needed";
Options["infill_only_where_needed"].category = "Infill";
Options["infill_only_where_needed"].tooltip = "This option will limit infill to the areas actually needed for supporting ceilings (it will act as internal support material).";
Options["infill_only_where_needed"].tooltip = "This option will limit infill to the areas actually needed for supporting ceilings (it will act as internal support material). If enabled, slows down the G-code generation due to the multiple checks involved.";
Options["infill_only_where_needed"].cli = "infill-only-where-needed!";
Options["infill_overlap"].type = coFloatOrPercent;
@ -1028,6 +1030,40 @@ PrintConfigDef::build_def() {
t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def();
void
DynamicPrintConfig::normalize() {
if (this->has("extruder")) {
int extruder = this->option("extruder")->getInt();
this->erase("extruder");
if (extruder != 0) {
if (!this->has("infill_extruder"))
this->option("infill_extruder", true)->setInt(extruder);
if (!this->has("perimeter_extruder"))
this->option("perimeter_extruder", true)->setInt(extruder);
if (!this->has("support_material_extruder"))
this->option("support_material_extruder", true)->setInt(extruder);
if (!this->has("support_material_interface_extruder"))
this->option("support_material_interface_extruder", true)->setInt(extruder);
}
}
if (!this->has("solid_infill_extruder") && this->has("infill_extruder"))
this->option("solid_infill_extruder", true)->setInt(this->option("infill_extruder")->getInt());
if (this->has("spiral_vase") && this->opt<ConfigOptionBool>("spiral_vase", true)->value) {
{
// this should be actually done only on the spiral layers instead of all
ConfigOptionBools* opt = this->opt<ConfigOptionBools>("retract_layer_change", true);
opt->values.assign(opt->values.size(), false); // set all values to false
}
{
this->opt<ConfigOptionInt>("perimeters", true)->value = 1;
this->opt<ConfigOptionInt>("top_solid_layers", true)->value = 0;
this->opt<ConfigOptionPercent>("fill_density", true)->value = 0;
}
}
}
#ifdef SLIC3RXS
REGISTER_CLASS(DynamicPrintConfig, "Config");
REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject");

View file

@ -6,7 +6,7 @@
namespace Slic3r {
enum GCodeFlavor {
gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfNoExtrusion,
gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfMachinekit, gcfNoExtrusion,
};
enum InfillPattern {
@ -29,6 +29,7 @@ template<> inline t_config_enum_values ConfigOptionEnum<GCodeFlavor>::get_enum_v
keys_map["makerware"] = gcfMakerWare;
keys_map["sailfish"] = gcfSailfish;
keys_map["mach3"] = gcfMach3;
keys_map["machinekit"] = gcfMachinekit;
keys_map["no-extrusion"] = gcfNoExtrusion;
return keys_map;
}
@ -78,38 +79,7 @@ class DynamicPrintConfig : public DynamicConfig
this->def = &PrintConfigDef::def;
};
void normalize() {
if (this->has("extruder")) {
int extruder = this->option("extruder")->getInt();
this->erase("extruder");
if (extruder != 0) {
if (!this->has("infill_extruder"))
this->option("infill_extruder", true)->setInt(extruder);
if (!this->has("perimeter_extruder"))
this->option("perimeter_extruder", true)->setInt(extruder);
if (!this->has("support_material_extruder"))
this->option("support_material_extruder", true)->setInt(extruder);
if (!this->has("support_material_interface_extruder"))
this->option("support_material_interface_extruder", true)->setInt(extruder);
}
}
if (!this->has("solid_infill_extruder") && this->has("infill_extruder"))
this->option("solid_infill_extruder", true)->setInt(this->option("infill_extruder")->getInt());
if (this->has("spiral_vase") && this->opt<ConfigOptionBool>("spiral_vase", true)->value) {
{
// this should be actually done only on the spiral layers instead of all
ConfigOptionBools* opt = this->opt<ConfigOptionBools>("retract_layer_change", true);
opt->values.assign(opt->values.size(), false); // set all values to false
}
{
this->opt<ConfigOptionInt>("perimeters", true)->value = 1;
this->opt<ConfigOptionInt>("top_solid_layers", true)->value = 0;
this->opt<ConfigOptionPercent>("fill_density", true)->value = 0;
}
}
};
void normalize();
};
class StaticPrintConfig : public virtual StaticConfig
@ -410,7 +380,7 @@ class GCodeConfig : public virtual StaticPrintConfig
std::string get_extrusion_axis() const
{
if (this->gcode_flavor.value == gcfMach3) {
if ((this->gcode_flavor.value == gcfMach3) || (this->gcode_flavor.value == gcfMachinekit)) {
return "A";
} else if (this->gcode_flavor.value == gcfNoExtrusion) {
return "";

View file

@ -333,6 +333,14 @@ PrintObject::invalidate_all_steps()
return invalidated;
}
bool
PrintObject::has_support_material() const
{
return this->config.support_material
|| this->config.raft_layers > 0
|| this->config.support_material_enforce_layers > 0;
}
void
PrintObject::bridge_over_infill()
{
@ -340,7 +348,7 @@ PrintObject::bridge_over_infill()
size_t region_id = region - this->_print->regions.begin();
double fill_density = (*region)->config.fill_density.value;
if (fill_density == 100 || fill_density == 0) continue;
if (fill_density == 100) continue;
FOREACH_LAYER(this, layer_it) {
if (layer_it == this->layers.begin()) continue;

View file

@ -6,7 +6,7 @@
#include <iostream>
#include <sstream>
#define SLIC3R_VERSION "1.2.6-dev"
#define SLIC3R_VERSION "1.2.7-dev"
#define EPSILON 1e-4
#define SCALING_FACTOR 0.000001