Expose static PrintConfig objects to Perl and test apply()
This commit is contained in:
parent
56d4da2ac7
commit
e0c0a42a8b
@ -11,8 +11,13 @@ ConfigBase::apply(ConfigBase &other, bool ignore_nonexistent) {
|
|||||||
// loop through options and apply them
|
// loop through options and apply them
|
||||||
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
|
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
|
||||||
ConfigOption* my_opt = this->option(*it);
|
ConfigOption* my_opt = this->option(*it);
|
||||||
if (my_opt == NULL && ignore_nonexistent == false) throw "Attempt to apply non-existent option";
|
if (my_opt == NULL) {
|
||||||
*my_opt = *(other.option(*it));
|
if (ignore_nonexistent == false) throw "Attempt to apply non-existent option";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not the most efficient way, but easier than casting pointers to subclasses
|
||||||
|
my_opt->deserialize( other.option(*it)->serialize() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,9 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 33;
|
use Test::More tests => 67;
|
||||||
|
|
||||||
{
|
|
||||||
my $config = Slic3r::Config->new;
|
|
||||||
|
|
||||||
|
foreach my $config (Slic3r::Config->new, Slic3r::Config::Print->new) {
|
||||||
$config->set('layer_height', 0.3);
|
$config->set('layer_height', 0.3);
|
||||||
ok abs($config->get('layer_height') - 0.3) < 1e-4, 'set/get float';
|
ok abs($config->get('layer_height') - 0.3) < 1e-4, 'set/get float';
|
||||||
is $config->serialize('layer_height'), '0.3', 'serialize float';
|
is $config->serialize('layer_height'), '0.3', 'serialize float';
|
||||||
@ -77,4 +75,13 @@ use Test::More tests => 33;
|
|||||||
is_deeply $config->get('wipe'), [0,1,1], 'deserialize bools';
|
is_deeply $config->get('wipe'), [0,1,1], 'deserialize bools';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $config = Slic3r::Config->new;
|
||||||
|
$config->set('perimeters', 2);
|
||||||
|
|
||||||
|
my $config2 = Slic3r::Config::Print->new;
|
||||||
|
$config2->apply_dynamic($config);
|
||||||
|
is $config2->get('perimeters'), 2, 'apply (dynamic -> static)';
|
||||||
|
}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -17,3 +17,18 @@
|
|||||||
|
|
||||||
%}
|
%}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
%name{Slic3r::Config::Print} class PrintConfig {
|
||||||
|
PrintConfig();
|
||||||
|
~PrintConfig();
|
||||||
|
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);
|
||||||
|
float get_abs_value(t_config_option_key opt_key);
|
||||||
|
void apply_dynamic(DynamicPrintConfig* other, bool ignore_nonexistent = false)
|
||||||
|
%code{% THIS->apply(*other, ignore_nonexistent); %};
|
||||||
|
%{
|
||||||
|
|
||||||
|
%}
|
||||||
|
};
|
||||||
|
@ -2,6 +2,7 @@ std::vector<Points::size_type> T_STD_VECTOR_INT
|
|||||||
t_config_option_key T_STD_STRING
|
t_config_option_key T_STD_STRING
|
||||||
|
|
||||||
DynamicPrintConfig* O_OBJECT
|
DynamicPrintConfig* O_OBJECT
|
||||||
|
PrintConfig* O_OBJECT
|
||||||
ZTable* O_OBJECT
|
ZTable* O_OBJECT
|
||||||
TriangleMesh* O_OBJECT
|
TriangleMesh* O_OBJECT
|
||||||
Point* O_OBJECT
|
Point* O_OBJECT
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
%typemap{AV*};
|
%typemap{AV*};
|
||||||
%typemap{Point*};
|
%typemap{Point*};
|
||||||
%typemap{DynamicPrintConfig*};
|
%typemap{DynamicPrintConfig*};
|
||||||
|
%typemap{PrintConfig*};
|
||||||
%typemap{ExPolygon*};
|
%typemap{ExPolygon*};
|
||||||
%typemap{ExPolygonCollection*};
|
%typemap{ExPolygonCollection*};
|
||||||
%typemap{Line*};
|
%typemap{Line*};
|
||||||
|
Loading…
Reference in New Issue
Block a user