Turn fill_density into percentage

This commit is contained in:
Alessandro Ranellucci 2014-03-22 16:23:33 +01:00
parent 30aa255bb5
commit 7421a7bf63
11 changed files with 54 additions and 16 deletions

View File

@ -200,7 +200,7 @@ The author of the Silk icon set is Mark James.
--top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: 3) --top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: 3)
--bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: 3) --bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: 3)
--solid-layers Shortcut for setting the two options above at once --solid-layers Shortcut for setting the two options above at once
--fill-density Infill density (range: 0-1, default: 0.4) --fill-density Infill density (range: 0%-100%, default: 40%)
--fill-angle Infill angle in degrees (range: 0-90, default: 45) --fill-angle Infill angle in degrees (range: 0-90, default: 45)
--fill-pattern Pattern to use to fill non-solid layers (default: honeycomb) --fill-pattern Pattern to use to fill non-solid layers (default: honeycomb)
--solid-fill-pattern Pattern to use to fill solid layers (default: rectilinear) --solid-fill-pattern Pattern to use to fill solid layers (default: rectilinear)

View File

@ -119,6 +119,11 @@ sub _handle_legacy {
if ($opt_key eq 'gcode_flavor' && $value eq 'makerbot') { if ($opt_key eq 'gcode_flavor' && $value eq 'makerbot') {
$value = 'makerware'; $value = 'makerware';
} }
if ($opt_key eq 'fill_density' && $value <= 1) {
# fill_density was turned into a percent value
$value *= 100;
$value = "$value"; # force update of the PV value, workaround for bug https://rt.cpan.org/Ticket/Display.html?id=94110
}
# For historical reasons, the world's full of configs having these very low values; # For historical reasons, the world's full of configs having these very low values;
# to avoid unexpected behavior we need to ignore them. Banning these two hard-coded # to avoid unexpected behavior we need to ignore them. Banning these two hard-coded
@ -258,9 +263,9 @@ sub validate {
# --fill-density # --fill-density
die "Invalid value for --fill-density\n" die "Invalid value for --fill-density\n"
if $self->fill_density < 0 || $self->fill_density > 1; if $self->fill_density < 0 || $self->fill_density > 100;
die "The selected fill pattern is not supposed to work at 100% density\n" die "The selected fill pattern is not supposed to work at 100% density\n"
if $self->fill_density == 1 if $self->fill_density == 100
&& !first { $_ eq $self->fill_pattern } @{$Options->{solid_fill_pattern}{values}}; && !first { $_ eq $self->fill_pattern } @{$Options->{solid_fill_pattern}{values}};
# --infill-every-layers # --infill-every-layers
@ -343,10 +348,11 @@ sub validate {
@values = ($self->$opt_key); @values = ($self->$opt_key);
} }
foreach my $value (@values) { foreach my $value (@values) {
if ($type eq 'i' || $type eq 'f') { if ($type eq 'i' || $type eq 'f' || $opt->{type} eq 'percent') {
$value =~ s/%$// if $opt->{type} eq 'percent';
die "Invalid value for $opt_key\n" die "Invalid value for $opt_key\n"
if ($type eq 'i' && $value !~ /^-?\d+$/) if ($type eq 'i' && $value !~ /^-?\d+$/)
|| ($type eq 'f' && $value !~ /^-?(?:\d+|\d*\.\d+)$/) || (($type eq 'f' || $opt->{type} eq 'percent') && $value !~ /^-?(?:\d+|\d*\.\d+)$/)
|| (defined $opt->{min} && $value < $opt->{min}) || (defined $opt->{min} && $value < $opt->{min})
|| (defined $opt->{max} && $value > $opt->{max}); || (defined $opt->{max} && $value > $opt->{max});
} elsif ($type eq 's' && $opt->{type} eq 'select') { } elsif ($type eq 's' && $opt->{type} eq 'select') {

View File

@ -192,7 +192,7 @@ sub make_fill {
# force 100% density and rectilinear fill for external surfaces # force 100% density and rectilinear fill for external surfaces
if ($surface->surface_type != S_TYPE_INTERNAL) { if ($surface->surface_type != S_TYPE_INTERNAL) {
$density = 1; $density = 100;
$filler = $layerm->config->solid_fill_pattern; $filler = $layerm->config->solid_fill_pattern;
if ($is_bridge) { if ($is_bridge) {
$filler = 'rectilinear'; $filler = 'rectilinear';
@ -209,7 +209,7 @@ sub make_fill {
$f->angle($layerm->config->fill_angle); $f->angle($layerm->config->fill_angle);
my ($params, @polylines) = $f->fill_surface( my ($params, @polylines) = $f->fill_surface(
$surface, $surface,
density => $density, density => $density/100,
flow => $flow, flow => $flow,
); );
next unless @polylines; next unless @polylines;

View File

@ -165,7 +165,7 @@ sub _build_field {
my $field; my $field;
my $tooltip = $opt->{tooltip}; my $tooltip = $opt->{tooltip};
if ($opt->{type} =~ /^(i|f|s|s@)$/) { if ($opt->{type} =~ /^(i|f|s|s@|percent)$/) {
my $style = 0; my $style = 0;
$style = wxTE_MULTILINE if $opt->{multiline}; $style = wxTE_MULTILINE if $opt->{multiline};
# default width on Windows is too large # default width on Windows is too large

View File

@ -604,7 +604,7 @@ sub bridge_over_infill {
for my $region_id (0..$#{$self->print->regions}) { for my $region_id (0..$#{$self->print->regions}) {
my $fill_density = $self->print->regions->[$region_id]->config->fill_density; my $fill_density = $self->print->regions->[$region_id]->config->fill_density;
next if $fill_density == 1 || $fill_density == 0; next if $fill_density == 100 || $fill_density == 0;
for my $layer_id (1..$#{$self->layers}) { for my $layer_id (1..$#{$self->layers}) {
my $layer = $self->layers->[$layer_id]; my $layer = $self->layers->[$layer_id];

View File

@ -301,7 +301,7 @@ $j
--top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: $config->{top_solid_layers}) --top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: $config->{top_solid_layers})
--bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: $config->{bottom_solid_layers}) --bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: $config->{bottom_solid_layers})
--solid-layers Shortcut for setting the two options above at once --solid-layers Shortcut for setting the two options above at once
--fill-density Infill density (range: 0-1, default: $config->{fill_density}) --fill-density Infill density (range: 0%-100%, default: $config->{fill_density}%)
--fill-angle Infill angle in degrees (range: 0-90, default: $config->{fill_angle}) --fill-angle Infill angle in degrees (range: 0-90, default: $config->{fill_angle})
--fill-pattern Pattern to use to fill non-solid layers (default: $config->{fill_pattern}) --fill-pattern Pattern to use to fill non-solid layers (default: $config->{fill_pattern})
--solid-fill-pattern Pattern to use to fill solid layers (default: $config->{solid_fill_pattern}) --solid-fill-pattern Pattern to use to fill solid layers (default: $config->{solid_fill_pattern})

View File

@ -172,7 +172,7 @@ for my $pattern (qw(rectilinear honeycomb hilbertcurve concentric)) {
$config->set('fill_pattern', $pattern); $config->set('fill_pattern', $pattern);
$config->set('perimeters', 1); $config->set('perimeters', 1);
$config->set('skirts', 0); $config->set('skirts', 0);
$config->set('fill_density', 0.2); $config->set('fill_density', 20);
$config->set('layer_height', 0.05); $config->set('layer_height', 0.05);
$config->set('perimeter_extruder', 1); $config->set('perimeter_extruder', 1);
$config->set('infill_extruder', 2); $config->set('infill_extruder', 2);

View File

@ -95,6 +95,8 @@ ConfigBase::get(t_config_option_key opt_key) {
if (opt == NULL) return &PL_sv_undef; if (opt == NULL) return &PL_sv_undef;
if (ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt)) { if (ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt)) {
return newSVnv(optv->value); return newSVnv(optv->value);
} else if (ConfigOptionPercent* optv = dynamic_cast<ConfigOptionPercent*>(opt)) {
return newSVnv(optv->value);
} else if (ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt)) { } else if (ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt)) {
AV* av = newAV(); AV* av = newAV();
av_fill(av, optv->values.size()-1); av_fill(av, optv->values.size()-1);
@ -257,6 +259,8 @@ DynamicConfig::option(const t_config_option_key opt_key, bool create) {
opt = new ConfigOptionString (); opt = new ConfigOptionString ();
} else if (optdef->type == coStrings) { } else if (optdef->type == coStrings) {
opt = new ConfigOptionStrings (); opt = new ConfigOptionStrings ();
} else if (optdef->type == coPercent) {
opt = new ConfigOptionPercent ();
} else if (optdef->type == coFloatOrPercent) { } else if (optdef->type == coFloatOrPercent) {
opt = new ConfigOptionFloatOrPercent (); opt = new ConfigOptionFloatOrPercent ();
} else if (optdef->type == coPoint) { } else if (optdef->type == coPoint) {

View File

@ -181,6 +181,30 @@ class ConfigOptionStrings : public ConfigOption, public ConfigOptionVector<std::
}; };
}; };
class ConfigOptionPercent : public ConfigOption
{
public:
double value;
ConfigOptionPercent() : value(0) {};
double get_abs_value(double ratio_over) const {
return ratio_over * this->value / 100;
};
std::string serialize() const {
std::ostringstream ss;
ss << this->value;
std::string s(ss.str());
s += "%";
return s;
};
void deserialize(std::string str) {
// don't try to parse the trailing % since it's optional
sscanf(str.c_str(), "%lf", &this->value);
};
};
class ConfigOptionFloatOrPercent : public ConfigOption class ConfigOptionFloatOrPercent : public ConfigOption
{ {
public: public:
@ -360,6 +384,7 @@ enum ConfigOptionType {
coInts, coInts,
coString, coString,
coStrings, coStrings,
coPercent,
coFloatOrPercent, coFloatOrPercent,
coPoint, coPoint,
coPoints, coPoints,

View File

@ -241,11 +241,12 @@ class PrintConfigDef
Options["fill_angle"].cli = "fill-angle=i"; Options["fill_angle"].cli = "fill-angle=i";
Options["fill_angle"].max = 359; Options["fill_angle"].max = 359;
Options["fill_density"].type = coFloat; Options["fill_density"].type = coPercent;
Options["fill_density"].label = "Fill density"; Options["fill_density"].label = "Fill density";
Options["fill_density"].category = "Infill"; Options["fill_density"].category = "Infill";
Options["fill_density"].tooltip = "Density of internal infill, expressed in the range 0 - 1."; Options["fill_density"].tooltip = "Density of internal infill, expressed in the range 0% - 100%.";
Options["fill_density"].cli = "fill-density=f"; Options["fill_density"].sidetext = "%";
Options["fill_density"].cli = "fill-density=s";
Options["fill_pattern"].type = coEnum; Options["fill_pattern"].type = coEnum;
Options["fill_pattern"].label = "Fill pattern"; Options["fill_pattern"].label = "Fill pattern";
@ -962,7 +963,7 @@ class PrintRegionConfig : public virtual StaticConfig
ConfigOptionInt bottom_solid_layers; ConfigOptionInt bottom_solid_layers;
ConfigOptionBool extra_perimeters; ConfigOptionBool extra_perimeters;
ConfigOptionInt fill_angle; ConfigOptionInt fill_angle;
ConfigOptionFloat fill_density; ConfigOptionPercent fill_density;
ConfigOptionEnum<InfillPattern> fill_pattern; ConfigOptionEnum<InfillPattern> fill_pattern;
ConfigOptionInt infill_extruder; ConfigOptionInt infill_extruder;
ConfigOptionFloatOrPercent infill_extrusion_width; ConfigOptionFloatOrPercent infill_extrusion_width;
@ -984,7 +985,7 @@ class PrintRegionConfig : public virtual StaticConfig
this->bottom_solid_layers.value = 3; this->bottom_solid_layers.value = 3;
this->extra_perimeters.value = true; this->extra_perimeters.value = true;
this->fill_angle.value = 45; this->fill_angle.value = 45;
this->fill_density.value = 0.4; this->fill_density.value = 40;
this->fill_pattern.value = ipHoneycomb; this->fill_pattern.value = ipHoneycomb;
this->infill_extruder.value = 1; this->infill_extruder.value = 1;
this->infill_extrusion_width.value = 0; this->infill_extrusion_width.value = 0;

View File

@ -131,6 +131,8 @@ print_config_def()
const char* opt_type; const char* opt_type;
if (optdef->type == coFloat || optdef->type == coFloats || optdef->type == coFloatOrPercent) { if (optdef->type == coFloat || optdef->type == coFloats || optdef->type == coFloatOrPercent) {
opt_type = "f"; opt_type = "f";
} else if (optdef->type == coPercent) {
opt_type = "percent";
} else if (optdef->type == coInt || optdef->type == coInts) { } else if (optdef->type == coInt || optdef->type == coInts) {
opt_type = "i"; opt_type = "i";
} else if (optdef->type == coString) { } else if (optdef->type == coString) {