mirror of https://github.com/vitalif/Slic3r
More work here and there
parent
51b976721d
commit
0883d0f4eb
|
@ -12,13 +12,14 @@ use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex inter
|
||||||
offset2 union union_pt_chained JT_ROUND JT_SQUARE);
|
offset2 union union_pt_chained JT_ROUND JT_SQUARE);
|
||||||
use Slic3r::Print::State ':steps';
|
use Slic3r::Print::State ':steps';
|
||||||
|
|
||||||
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => \&init_config);
|
has 'config' => (is => 'rw', default => sub { Slic3r::Config::Print->new }, trigger => \&init_config);
|
||||||
|
has 'default_object_config' => (is => 'rw', default => sub { Slic3r::Config::PrintObject->new });
|
||||||
|
has 'default_region_config' => (is => 'rw', default => sub { Slic3r::Config::PrintRegion->new });
|
||||||
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
||||||
has 'objects' => (is => 'rw', default => sub {[]});
|
has 'objects' => (is => 'rw', default => sub {[]});
|
||||||
has 'status_cb' => (is => 'rw');
|
has 'status_cb' => (is => 'rw');
|
||||||
has 'extruders' => (is => 'rw', default => sub {[]});
|
has 'extruders' => (is => 'rw', default => sub {[]});
|
||||||
has 'regions' => (is => 'rw', default => sub {[]});
|
has 'regions' => (is => 'rw', default => sub {[]});
|
||||||
has 'has_support_material' => (is => 'lazy');
|
|
||||||
has '_state' => (is => 'ro', default => sub { Slic3r::Print::State->new });
|
has '_state' => (is => 'ro', default => sub { Slic3r::Print::State->new });
|
||||||
|
|
||||||
# ordered collection of extrusion paths to build skirt loops
|
# ordered collection of extrusion paths to build skirt loops
|
||||||
|
@ -70,11 +71,12 @@ sub apply_config {
|
||||||
my ($self, $config) = @_;
|
my ($self, $config) = @_;
|
||||||
|
|
||||||
$self->config->apply($config);
|
$self->config->apply($config);
|
||||||
|
$self->default_object_config->apply($config);
|
||||||
|
$self->default_region_config->apply($config);
|
||||||
$self->init_config;
|
$self->init_config;
|
||||||
$_->init_config for @{$self->objects};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _build_has_support_material {
|
sub has_support_material {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return (first { $_->config->support_material } @{$self->objects})
|
return (first { $_->config->support_material } @{$self->objects})
|
||||||
|| (first { $_->config->raft_layers > 0 } @{$self->objects})
|
|| (first { $_->config->raft_layers > 0 } @{$self->objects})
|
||||||
|
@ -91,13 +93,15 @@ sub add_model_object {
|
||||||
foreach my $volume_id (0..$#{$object->volumes}) {
|
foreach my $volume_id (0..$#{$object->volumes}) {
|
||||||
my $volume = $object->volumes->[$volume_id];
|
my $volume = $object->volumes->[$volume_id];
|
||||||
|
|
||||||
# get the config applied to this volume
|
# get the config applied to this volume: start from our global defaults
|
||||||
my $config;
|
my $config = Slic3r::Config::RegionConfig->new;
|
||||||
|
$config->apply($self->default_region_config);
|
||||||
|
|
||||||
|
# override the defaults with per-object config and then with per-material config
|
||||||
|
$config->apply($object->config);
|
||||||
if (defined $volume->material_id) {
|
if (defined $volume->material_id) {
|
||||||
my $config = $object->model->materials->{ $volume->material_id }->config;
|
my $material_config = $object->model->materials->{ $volume->material_id }->config;
|
||||||
} else {
|
$config->apply($material_config);
|
||||||
$config = Slic3r::Config->new;
|
|
||||||
$config->set('extruder', 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# find an existing print region with the same config
|
# find an existing print region with the same config
|
||||||
|
@ -112,10 +116,10 @@ sub add_model_object {
|
||||||
|
|
||||||
# if no region exists with the same config, create a new one
|
# if no region exists with the same config, create a new one
|
||||||
if (!defined $region_id) {
|
if (!defined $region_id) {
|
||||||
push @{$self->regions}, Slic3r::Print::Region->new(
|
push @{$self->regions}, my $r = Slic3r::Print::Region->new(
|
||||||
print => $self,
|
print => $self,
|
||||||
config => $config->clone,
|
|
||||||
);
|
);
|
||||||
|
$r->config->apply($config);
|
||||||
$region_id = $#{$self->regions};
|
$region_id = $#{$self->regions};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +134,14 @@ sub add_model_object {
|
||||||
model_object => $object,
|
model_object => $object,
|
||||||
region_volumes => [ map $volumes{$_}, 0..$#{$self->regions} ],
|
region_volumes => [ map $volumes{$_}, 0..$#{$self->regions} ],
|
||||||
copies => [ map Slic3r::Point->new_scale(@{ $_->offset }), @{ $object->instances } ],
|
copies => [ map Slic3r::Point->new_scale(@{ $_->offset }), @{ $object->instances } ],
|
||||||
config_overrides => $object->config,
|
|
||||||
layer_height_ranges => $object->layer_height_ranges,
|
layer_height_ranges => $object->layer_height_ranges,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# apply config to print object
|
||||||
|
$o->config->apply($self->default_object_config);
|
||||||
|
$o->config->apply($object->config);
|
||||||
|
|
||||||
|
# store print object at the given position
|
||||||
if (defined $obj_idx) {
|
if (defined $obj_idx) {
|
||||||
splice @{$self->objects}, $obj_idx, 0, $o;
|
splice @{$self->objects}, $obj_idx, 0, $o;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,8 +13,7 @@ has 'print' => (is => 'ro', weak_ref => 1, required => 1);
|
||||||
has 'model_object' => (is => 'ro', required => 1);
|
has 'model_object' => (is => 'ro', required => 1);
|
||||||
has 'region_volumes' => (is => 'rw', default => sub { [] }); # by region_id
|
has 'region_volumes' => (is => 'rw', default => sub { [] }); # by region_id
|
||||||
has 'copies' => (is => 'ro'); # Slic3r::Point objects in scaled G-code coordinates
|
has 'copies' => (is => 'ro'); # Slic3r::Point objects in scaled G-code coordinates
|
||||||
has 'config_overrides' => (is => 'rw', default => sub { Slic3r::Config->new });
|
has 'config' => (is => 'rw', required => 1); # Slic3r::Config::PrintObject
|
||||||
has 'config' => (is => 'rw');
|
|
||||||
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
||||||
|
|
||||||
has 'size' => (is => 'rw'); # XYZ in scaled coordinates
|
has 'size' => (is => 'rw'); # XYZ in scaled coordinates
|
||||||
|
@ -28,8 +27,6 @@ has '_state' => (is => 'ro', default => sub { Slic3r::Print::State->n
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$self->init_config;
|
|
||||||
|
|
||||||
# translate meshes so that we work with smaller coordinates
|
# translate meshes so that we work with smaller coordinates
|
||||||
{
|
{
|
||||||
# compute the bounding box of the supplied meshes
|
# compute the bounding box of the supplied meshes
|
||||||
|
@ -97,11 +94,6 @@ sub delete_all_copies {
|
||||||
$self->_trigger_copies;
|
$self->_trigger_copies;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub init_config {
|
|
||||||
my $self = shift;
|
|
||||||
$self->config(Slic3r::Config->merge($self->print->config, $self->config_overrides));
|
|
||||||
}
|
|
||||||
|
|
||||||
sub layer_count {
|
sub layer_count {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return scalar @{ $self->layers };
|
return scalar @{ $self->layers };
|
||||||
|
|
|
@ -8,7 +8,7 @@ use Slic3r::Flow ':roles';
|
||||||
# sharing the same config (including the same assigned extruder(s))
|
# sharing the same config (including the same assigned extruder(s))
|
||||||
|
|
||||||
has 'print' => (is => 'ro', required => 1, weak_ref => 1);
|
has 'print' => (is => 'ro', required => 1, weak_ref => 1);
|
||||||
has 'config' => (is => 'ro', required => 1);
|
has 'config' => (is => 'ro', required => 1); # Slic3r::Config::RegionConfig
|
||||||
|
|
||||||
sub flow {
|
sub flow {
|
||||||
my ($self, $role, $layer_height, $bridge, $first_layer, $width) = @_;
|
my ($self, $role, $layer_height, $bridge, $first_layer, $width) = @_;
|
||||||
|
|
|
@ -35,6 +35,14 @@ ConfigBase::serialize(const t_config_option_key opt_key) {
|
||||||
|
|
||||||
void
|
void
|
||||||
ConfigBase::set_deserialize(const t_config_option_key opt_key, std::string str) {
|
ConfigBase::set_deserialize(const t_config_option_key opt_key, std::string str) {
|
||||||
|
if (this->def->count(opt_key) == 0) throw "Calling set_deserialize() on unknown option";
|
||||||
|
ConfigOptionDef* optdef = &(*this->def)[opt_key];
|
||||||
|
if (!optdef->shortcut.empty()) {
|
||||||
|
for (std::vector<t_config_option_key>::iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it)
|
||||||
|
this->set_deserialize(*it, str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ConfigOption* opt = this->option(opt_key, true);
|
ConfigOption* opt = this->option(opt_key, true);
|
||||||
assert(opt != NULL);
|
assert(opt != NULL);
|
||||||
opt->deserialize(str);
|
opt->deserialize(str);
|
||||||
|
@ -61,6 +69,20 @@ ConfigBase::get_abs_value(const t_config_option_key opt_key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
ConfigBase::get_abs_value(const t_config_option_key opt_key, double ratio_over) {
|
||||||
|
// get stored option value
|
||||||
|
ConfigOptionFloatOrPercent* opt = dynamic_cast<ConfigOptionFloatOrPercent*>(this->option(opt_key));
|
||||||
|
assert(opt != NULL);
|
||||||
|
|
||||||
|
// compute absolute value
|
||||||
|
if (opt->percent) {
|
||||||
|
return ratio_over * opt->value / 100;
|
||||||
|
} else {
|
||||||
|
return opt->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
SV*
|
SV*
|
||||||
ConfigBase::as_hash() {
|
ConfigBase::as_hash() {
|
||||||
|
|
|
@ -393,6 +393,7 @@ class ConfigBase
|
||||||
std::string serialize(const t_config_option_key opt_key);
|
std::string serialize(const t_config_option_key opt_key);
|
||||||
void set_deserialize(const t_config_option_key opt_key, std::string str);
|
void set_deserialize(const t_config_option_key opt_key, std::string str);
|
||||||
double get_abs_value(const t_config_option_key opt_key);
|
double get_abs_value(const t_config_option_key opt_key);
|
||||||
|
double get_abs_value(const t_config_option_key opt_key, double ratio_over);
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
SV* as_hash();
|
SV* as_hash();
|
||||||
|
|
|
@ -986,7 +986,7 @@ class PrintRegionConfig : public virtual StaticConfig
|
||||||
ConfigOptionFloatOrPercent top_infill_extrusion_width;
|
ConfigOptionFloatOrPercent top_infill_extrusion_width;
|
||||||
ConfigOptionInt top_solid_layers;
|
ConfigOptionInt top_solid_layers;
|
||||||
|
|
||||||
PrintObjectConfig() {
|
PrintRegionConfig() {
|
||||||
this->def = &PrintConfigDef::def;
|
this->def = &PrintConfigDef::def;
|
||||||
|
|
||||||
this->bottom_solid_layers.value = 3;
|
this->bottom_solid_layers.value = 3;
|
||||||
|
@ -1135,7 +1135,7 @@ class PrintConfig : public virtual StaticConfig
|
||||||
ConfigOptionFloat z_offset;
|
ConfigOptionFloat z_offset;
|
||||||
|
|
||||||
PrintConfig() {
|
PrintConfig() {
|
||||||
this->def = &PrintConfig::PrintConfigDef;
|
this->def = &PrintConfigDef::def;
|
||||||
|
|
||||||
this->avoid_crossing_perimeters.value = false;
|
this->avoid_crossing_perimeters.value = false;
|
||||||
this->bed_size.point = Pointf(200,200);
|
this->bed_size.point = Pointf(200,200);
|
||||||
|
|
|
@ -15,15 +15,13 @@
|
||||||
void set_deserialize(t_config_option_key opt_key, std::string str);
|
void set_deserialize(t_config_option_key opt_key, std::string str);
|
||||||
std::string serialize(t_config_option_key opt_key);
|
std::string serialize(t_config_option_key opt_key);
|
||||||
double get_abs_value(t_config_option_key opt_key);
|
double get_abs_value(t_config_option_key opt_key);
|
||||||
|
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
||||||
void apply(DynamicPrintConfig* other)
|
void apply(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
void apply_static(PrintConfig* other)
|
void apply_static(PrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
std::vector<std::string> get_keys()
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
%code{% THIS->keys(&RETVAL); %};
|
||||||
%{
|
|
||||||
|
|
||||||
%}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Config::Print} class PrintConfig {
|
%name{Slic3r::Config::Print} class PrintConfig {
|
||||||
|
@ -36,13 +34,45 @@
|
||||||
void set_deserialize(t_config_option_key opt_key, std::string str);
|
void set_deserialize(t_config_option_key opt_key, std::string str);
|
||||||
std::string serialize(t_config_option_key opt_key);
|
std::string serialize(t_config_option_key opt_key);
|
||||||
double get_abs_value(t_config_option_key opt_key);
|
double get_abs_value(t_config_option_key opt_key);
|
||||||
|
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
||||||
void apply_dynamic(DynamicPrintConfig* other)
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
std::vector<std::string> get_keys()
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
%code{% THIS->keys(&RETVAL); %};
|
||||||
%{
|
};
|
||||||
|
|
||||||
%}
|
%name{Slic3r::Config::Print} class PrintConfig {
|
||||||
|
PrintConfig();
|
||||||
|
~PrintConfig();
|
||||||
|
bool has(t_config_option_key opt_key);
|
||||||
|
SV* as_hash();
|
||||||
|
SV* get(t_config_option_key opt_key);
|
||||||
|
void set(t_config_option_key opt_key, SV* value);
|
||||||
|
void set_deserialize(t_config_option_key opt_key, std::string str);
|
||||||
|
std::string serialize(t_config_option_key opt_key);
|
||||||
|
double get_abs_value(t_config_option_key opt_key);
|
||||||
|
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
||||||
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
|
%code{% THIS->apply(*other, true); %};
|
||||||
|
std::vector<std::string> get_keys()
|
||||||
|
%code{% THIS->keys(&RETVAL); %};
|
||||||
|
};
|
||||||
|
|
||||||
|
%name{Slic3r::Config::Print} class PrintConfig {
|
||||||
|
PrintConfig();
|
||||||
|
~PrintConfig();
|
||||||
|
bool has(t_config_option_key opt_key);
|
||||||
|
SV* as_hash();
|
||||||
|
SV* get(t_config_option_key opt_key);
|
||||||
|
void set(t_config_option_key opt_key, SV* value);
|
||||||
|
void set_deserialize(t_config_option_key opt_key, std::string str);
|
||||||
|
std::string serialize(t_config_option_key opt_key);
|
||||||
|
double get_abs_value(t_config_option_key opt_key);
|
||||||
|
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
||||||
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
|
%code{% THIS->apply(*other, true); %};
|
||||||
|
std::vector<std::string> get_keys()
|
||||||
|
%code{% THIS->keys(&RETVAL); %};
|
||||||
};
|
};
|
||||||
|
|
||||||
%package{Slic3r::Config};
|
%package{Slic3r::Config};
|
||||||
|
@ -53,8 +83,7 @@ PROTOTYPES: DISABLE
|
||||||
SV*
|
SV*
|
||||||
print_config_def()
|
print_config_def()
|
||||||
CODE:
|
CODE:
|
||||||
PrintConfig config;
|
t_optiondef_map* def = &PrintConfigDef::def;
|
||||||
t_optiondef_map* def = config.def;
|
|
||||||
|
|
||||||
HV* options_hv = newHV();
|
HV* options_hv = newHV();
|
||||||
for (t_optiondef_map::iterator oit = def->begin(); oit != def->end(); ++oit) {
|
for (t_optiondef_map::iterator oit = def->begin(); oit != def->end(); ++oit) {
|
||||||
|
|
Loading…
Reference in New Issue