mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-02 20:51:23 -07:00
Fix extruder assignment and tests
This commit is contained in:
parent
10bf334a58
commit
071097d3f1
10 changed files with 109 additions and 186 deletions
|
|
@ -4,44 +4,4 @@ namespace Slic3r {
|
|||
|
||||
t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def();
|
||||
|
||||
void
|
||||
StaticPrintConfig::prepare_extruder_option(const t_config_option_key opt_key, DynamicPrintConfig& other)
|
||||
{
|
||||
// don't apply role-based extruders if their value is zero
|
||||
if (other.has(opt_key) && other.option(opt_key)->getInt() == 0)
|
||||
other.erase(opt_key);
|
||||
|
||||
// only apply default extruder if our role-based value is zero
|
||||
// (i.e. default extruder has the lowest priority among all other values)
|
||||
if (other.has("extruder")) {
|
||||
int extruder = other.option("extruder")->getInt();
|
||||
if (extruder > 0) {
|
||||
if (!other.has(opt_key) && this->option(opt_key)->getInt() == 0)
|
||||
other.option(opt_key, true)->setInt(extruder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PrintObjectConfig::apply(const ConfigBase &other, bool ignore_nonexistent) {
|
||||
DynamicPrintConfig other_clone;
|
||||
other_clone.apply(other);
|
||||
|
||||
this->prepare_extruder_option("support_material_extruder", other_clone);
|
||||
this->prepare_extruder_option("support_material_interface_extruder", other_clone);
|
||||
|
||||
StaticConfig::apply(other_clone, ignore_nonexistent);
|
||||
};
|
||||
|
||||
void
|
||||
PrintRegionConfig::apply(const ConfigBase &other, bool ignore_nonexistent) {
|
||||
DynamicPrintConfig other_clone;
|
||||
other_clone.apply(other);
|
||||
|
||||
this->prepare_extruder_option("infill_extruder", other_clone);
|
||||
this->prepare_extruder_option("perimeter_extruder", other_clone);
|
||||
|
||||
StaticConfig::apply(other_clone, ignore_nonexistent);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -399,10 +399,9 @@ class PrintConfigDef
|
|||
Options["infill_extruder"].type = coInt;
|
||||
Options["infill_extruder"].label = "Infill extruder";
|
||||
Options["infill_extruder"].category = "Extruders";
|
||||
Options["infill_extruder"].tooltip = "The extruder to use when printing infill. First extruder is 1, while zero means use default extruder.";
|
||||
Options["infill_extruder"].sidetext = "(leave 0 for default)";
|
||||
Options["infill_extruder"].tooltip = "The extruder to use when printing infill.";
|
||||
Options["infill_extruder"].cli = "infill-extruder=i";
|
||||
Options["infill_extruder"].min = 0;
|
||||
Options["infill_extruder"].min = 1;
|
||||
|
||||
Options["infill_extrusion_width"].type = coFloatOrPercent;
|
||||
Options["infill_extrusion_width"].label = "Infill";
|
||||
|
|
@ -524,11 +523,10 @@ class PrintConfigDef
|
|||
Options["perimeter_extruder"].type = coInt;
|
||||
Options["perimeter_extruder"].label = "Perimeter extruder";
|
||||
Options["perimeter_extruder"].category = "Extruders";
|
||||
Options["perimeter_extruder"].tooltip = "The extruder to use when printing perimeters. First extruder is 1, while zero means use default extruder.";
|
||||
Options["perimeter_extruder"].sidetext = "(leave 0 for default)";
|
||||
Options["perimeter_extruder"].tooltip = "The extruder to use when printing perimeters. First extruder is 1.";
|
||||
Options["perimeter_extruder"].cli = "perimeter-extruder=i";
|
||||
Options["perimeter_extruder"].aliases.push_back("perimeters_extruder");
|
||||
Options["perimeter_extruder"].min = 0;
|
||||
Options["perimeter_extruder"].min = 1;
|
||||
|
||||
Options["perimeter_extrusion_width"].type = coFloatOrPercent;
|
||||
Options["perimeter_extrusion_width"].label = "Perimeters";
|
||||
|
|
@ -774,10 +772,9 @@ class PrintConfigDef
|
|||
Options["support_material_extruder"].type = coInt;
|
||||
Options["support_material_extruder"].label = "Support material extruder";
|
||||
Options["support_material_extruder"].category = "Extruders";
|
||||
Options["support_material_extruder"].tooltip = "The extruder to use when printing support material. This affects brim and raft too. First extruder is 1, while zero means use default extruder.";
|
||||
Options["support_material_extruder"].sidetext = "(leave 0 for default)";
|
||||
Options["support_material_extruder"].tooltip = "The extruder to use when printing support material. This affects brim and raft too.";
|
||||
Options["support_material_extruder"].cli = "support-material-extruder=i";
|
||||
Options["support_material_extruder"].min = 0;
|
||||
Options["support_material_extruder"].min = 1;
|
||||
|
||||
Options["support_material_extrusion_width"].type = coFloatOrPercent;
|
||||
Options["support_material_extrusion_width"].label = "Support material";
|
||||
|
|
@ -789,10 +786,9 @@ class PrintConfigDef
|
|||
Options["support_material_interface_extruder"].type = coInt;
|
||||
Options["support_material_interface_extruder"].label = "Support material interface extruder";
|
||||
Options["support_material_interface_extruder"].category = "Extruders";
|
||||
Options["support_material_interface_extruder"].tooltip = "The extruder to use when printing support material interface. This affects raft too. First extruder is 1, while zero means use default extruder.";
|
||||
Options["support_material_interface_extruder"].sidetext = "(leave 0 for default)";
|
||||
Options["support_material_interface_extruder"].tooltip = "The extruder to use when printing support material interface. This affects raft too.";
|
||||
Options["support_material_interface_extruder"].cli = "support-material-interface-extruder=i";
|
||||
Options["support_material_interface_extruder"].min = 0;
|
||||
Options["support_material_interface_extruder"].min = 1;
|
||||
|
||||
Options["support_material_interface_layers"].type = coInt;
|
||||
Options["support_material_interface_layers"].label = "Interface layers";
|
||||
|
|
@ -940,6 +936,21 @@ class DynamicPrintConfig : public DynamicConfig
|
|||
DynamicPrintConfig() {
|
||||
this->def = &PrintConfigDef::def;
|
||||
};
|
||||
|
||||
void normalize() {
|
||||
if (this->has("extruder")) {
|
||||
int extruder = this->option("extruder")->getInt();
|
||||
this->erase("extruder");
|
||||
if (!this->has("infill_extruder"))
|
||||
this->option("infill_extruder", true)->setInt(extruder);
|
||||
if (!this->has("perimeter_extruder"))
|
||||
this->option("infill_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);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class StaticPrintConfig : public virtual StaticConfig
|
||||
|
|
@ -948,9 +959,6 @@ class StaticPrintConfig : public virtual StaticConfig
|
|||
StaticPrintConfig() {
|
||||
this->def = &PrintConfigDef::def;
|
||||
};
|
||||
|
||||
protected:
|
||||
void prepare_extruder_option(const t_config_option_key opt_key, DynamicPrintConfig& other);
|
||||
};
|
||||
|
||||
class PrintObjectConfig : public virtual StaticPrintConfig
|
||||
|
|
@ -987,10 +995,10 @@ class PrintObjectConfig : public virtual StaticPrintConfig
|
|||
this->support_material.value = false;
|
||||
this->support_material_angle.value = 0;
|
||||
this->support_material_enforce_layers.value = 0;
|
||||
this->support_material_extruder.value = 0;
|
||||
this->support_material_extruder.value = 1;
|
||||
this->support_material_extrusion_width.value = 0;
|
||||
this->support_material_extrusion_width.percent = false;
|
||||
this->support_material_interface_extruder.value = 0;
|
||||
this->support_material_interface_extruder.value = 1;
|
||||
this->support_material_interface_layers.value = 3;
|
||||
this->support_material_interface_spacing.value = 0;
|
||||
this->support_material_pattern.value = smpHoneycomb;
|
||||
|
|
@ -1021,8 +1029,6 @@ class PrintObjectConfig : public virtual StaticPrintConfig
|
|||
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void apply(const ConfigBase &other, bool ignore_nonexistent = false);
|
||||
};
|
||||
|
||||
class PrintRegionConfig : public virtual StaticPrintConfig
|
||||
|
|
@ -1053,11 +1059,11 @@ class PrintRegionConfig : public virtual StaticPrintConfig
|
|||
this->fill_angle.value = 45;
|
||||
this->fill_density.value = 40;
|
||||
this->fill_pattern.value = ipHoneycomb;
|
||||
this->infill_extruder.value = 0;
|
||||
this->infill_extruder.value = 1;
|
||||
this->infill_extrusion_width.value = 0;
|
||||
this->infill_extrusion_width.percent = false;
|
||||
this->infill_every_layers.value = 1;
|
||||
this->perimeter_extruder.value = 0;
|
||||
this->perimeter_extruder.value = 1;
|
||||
this->perimeter_extrusion_width.value = 0;
|
||||
this->perimeter_extrusion_width.percent = false;
|
||||
this->perimeters.value = 3;
|
||||
|
|
@ -1094,8 +1100,6 @@ class PrintRegionConfig : public virtual StaticPrintConfig
|
|||
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void apply(const ConfigBase &other, bool ignore_nonexistent = false);
|
||||
};
|
||||
|
||||
class PrintConfig : public virtual StaticPrintConfig
|
||||
|
|
@ -1398,12 +1402,6 @@ class FullPrintConfig : public PrintObjectConfig, public PrintRegionConfig, publ
|
|||
if ((opt = PrintConfig::option(opt_key, create)) != NULL) return opt;
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void apply(const ConfigBase &other, bool ignore_nonexistent = false) {
|
||||
PrintObjectConfig::apply(other, ignore_nonexistent);
|
||||
PrintRegionConfig::apply(other, ignore_nonexistent);
|
||||
PrintConfig::apply(other, ignore_nonexistent);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 99;
|
||||
use Test::More tests => 94;
|
||||
|
||||
foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) {
|
||||
$config->set('layer_height', 0.3);
|
||||
|
|
@ -126,64 +126,6 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) {
|
|||
is $config->get('fill_pattern'), 'line', 'no interferences between DynamicConfig objects';
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('infill_extruder', 2);
|
||||
my $config2 = Slic3r::Config::PrintRegion->new;
|
||||
$config2->apply($config);
|
||||
is $config2->get('infill_extruder'), $config->get('infill_extruder'),
|
||||
'non-zero infill_extruder is applied';
|
||||
}
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('infill_extruder', 0);
|
||||
my $config2 = Slic3r::Config::PrintRegion->new;
|
||||
$config2->set('infill_extruder', 3);
|
||||
$config2->apply($config);
|
||||
isnt $config2->get('infill_extruder'), $config->get('infill_extruder'),
|
||||
'zero infill_extruder is not applied';
|
||||
}
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('extruder', 3);
|
||||
my $config2 = Slic3r::Config::PrintRegion->new;
|
||||
$config2->set('infill_extruder', 2);
|
||||
$config2->apply($config);
|
||||
is $config2->get('infill_extruder'), 2, 'extruder does not overwrite non-zero role extruders';
|
||||
is $config2->get('perimeter_extruder'), 3, 'extruder overwrites zero role extruders';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('support_material_extruder', 2);
|
||||
my $config2 = Slic3r::Config::PrintObject->new;
|
||||
$config2->apply($config);
|
||||
is $config2->get('support_material_extruder'), $config->get('support_material_extruder'),
|
||||
'non-zero support_material_extruder is applied';
|
||||
}
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('support_material_extruder', 0);
|
||||
my $config2 = Slic3r::Config::PrintObject->new;
|
||||
$config2->set('support_material_extruder', 3);
|
||||
$config2->apply($config);
|
||||
isnt $config2->get('support_material_extruder'), $config->get('support_material_extruder'),
|
||||
'zero support_material_extruder is not applied';
|
||||
}
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('extruder', 3);
|
||||
my $config2 = Slic3r::Config::PrintObject->new;
|
||||
$config2->set('support_material_extruder', 2);
|
||||
$config2->apply($config);
|
||||
is $config2->get('support_material_extruder'), 2, 'extruder does not overwrite non-zero role extruders';
|
||||
is $config2->get('support_material_interface_extruder'), 3, 'extruder overwrites zero role extruders';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
# the pair [0,0] is part of the test, since it checks whether the 0x0 serialized value is correctly parsed
|
||||
|
|
@ -193,4 +135,14 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) {
|
|||
is_deeply $config->get('extruder_offset'), $config2->get('extruder_offset'), 'apply dynamic over dynamic';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('extruder', 2);
|
||||
$config->set('perimeter_extruder', 3);
|
||||
$config->normalize;
|
||||
ok !$config->has('extruder'), 'extruder option is removed after normalize()';
|
||||
is $config->get('infill_extruder'), 2, 'undefined extruder is populated with default extruder';
|
||||
is $config->get('perimeter_extruder'), 3, 'defined extruder is not overwritten by default extruder';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
std::vector<std::string> get_keys()
|
||||
%code{% THIS->keys(&RETVAL); %};
|
||||
void erase(t_config_option_key opt_key);
|
||||
void normalize();
|
||||
};
|
||||
|
||||
%name{Slic3r::Config::Print} class PrintConfig {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue