Thread-safe integration of ExtrusionPath::Collection
This commit is contained in:
parent
c030e38908
commit
1b285f3f46
12 changed files with 81 additions and 104 deletions
|
@ -43,6 +43,14 @@ use overload
|
|||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
sub new {
|
||||
my ($class, @paths) = @_;
|
||||
|
||||
my $self = $class->_new;
|
||||
$self->append(@paths);
|
||||
return $self;
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionLoop;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
class ExtrusionEntityCollection
|
||||
class ExtrusionEntityCollection : public ExtrusionEntity
|
||||
{
|
||||
public:
|
||||
ExtrusionEntitiesPtr entities;
|
||||
|
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 5;
|
||||
use Test::More tests => 8;
|
||||
|
||||
my $points = [
|
||||
[100, 100],
|
||||
|
@ -22,16 +22,23 @@ my $loop = Slic3r::ExtrusionLoop->new(
|
|||
role => Slic3r::ExtrusionPath::EXTR_ROLE_FILL,
|
||||
);
|
||||
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new;
|
||||
isa_ok $collection, 'Slic3r::ExtrusionPath::Collection', 'collection object';
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new($path);
|
||||
isa_ok $collection, 'Slic3r::ExtrusionPath::Collection', 'collection object with items in constructor';
|
||||
|
||||
$collection->append($collection);
|
||||
is scalar(@$collection), 2, 'append ExtrusionPath::Collection';
|
||||
|
||||
$collection->append($path);
|
||||
is scalar(@$collection), 1, 'append ExtrusionPath';
|
||||
is scalar(@$collection), 3, 'append ExtrusionPath';
|
||||
|
||||
$collection->append($loop);
|
||||
is scalar(@$collection), 2, 'append ExtrusionLoop';
|
||||
is scalar(@$collection), 4, 'append ExtrusionLoop';
|
||||
|
||||
isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection', 'correct object returned for collection';
|
||||
isa_ok $collection->[2], 'Slic3r::ExtrusionPath', 'correct object returned for path';
|
||||
isa_ok $collection->[3], 'Slic3r::ExtrusionLoop', 'correct object returned for loop';
|
||||
|
||||
is scalar(@{$collection->[1]}), 1, 'appended collection was duplicated';
|
||||
|
||||
isa_ok $collection->[0], 'Slic3r::ExtrusionPath', 'correct object returned for path';
|
||||
isa_ok $collection->[1], 'Slic3r::ExtrusionLoop', 'correct object returned for loop';
|
||||
|
||||
__END__
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
%}
|
||||
|
||||
%name{Slic3r::ExtrusionPath::Collection} class ExtrusionEntityCollection {
|
||||
ExtrusionEntityCollection();
|
||||
%name{_new} ExtrusionEntityCollection();
|
||||
~ExtrusionEntityCollection();
|
||||
void clear()
|
||||
%code{% THIS->entities.clear(); %};
|
||||
|
@ -23,8 +23,10 @@ ExtrusionEntityCollection::arrayref()
|
|||
// return COPIES
|
||||
if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(*it)) {
|
||||
sv_setref_pv( sv, "Slic3r::ExtrusionPath", new ExtrusionPath(*(ExtrusionPath*)*it) );
|
||||
} else {
|
||||
} else if (ExtrusionLoop* path = dynamic_cast<ExtrusionLoop*>(*it)) {
|
||||
sv_setref_pv( sv, "Slic3r::ExtrusionLoop", new ExtrusionLoop(*(ExtrusionLoop*)*it) );
|
||||
} else {
|
||||
sv_setref_pv( sv, "Slic3r::ExtrusionPath::Collection", new ExtrusionEntityCollection(*(ExtrusionEntityCollection*)*it) );
|
||||
}
|
||||
av_store(av, i++, sv);
|
||||
}
|
||||
|
@ -40,8 +42,10 @@ ExtrusionEntityCollection::append(...)
|
|||
// append COPIES
|
||||
if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(entity)) {
|
||||
THIS->entities.push_back( new ExtrusionPath(*path) );
|
||||
} else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(entity)) {
|
||||
THIS->entities.push_back( new ExtrusionLoop(*loop) );
|
||||
} else {
|
||||
THIS->entities.push_back( new ExtrusionLoop(*(ExtrusionLoop*)entity) );
|
||||
THIS->entities.push_back( new ExtrusionEntityCollection(*(ExtrusionEntityCollection*)entity) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue