From bed1625d6b0fa92da0afb4fae2ec6d036dfbea33 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 24 Nov 2013 14:28:17 +0100 Subject: [PATCH] Split objects could not be repositioned in plater. 3D preview and stats were not available too. #1543 --- lib/Slic3r/GUI/Plater.pm | 6 ++++-- lib/Slic3r/Model.pm | 2 +- xs/src/TriangleMesh.cpp | 3 +++ xs/src/admesh/stl.h | 2 +- xs/t/01_trianglemesh.t | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 66d6d35cf..5eec59547 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -594,8 +594,10 @@ sub split_object { input_file_object_id => undef, model => $new_model, model_object_idx => $#{$new_model->objects}, - instances => [ map $bb->min_point, 1..$current_copies_num ], + mesh_stats => $mesh->stats, # so that we can free model + instances => [ map $bb->min_point->pp, 1..$current_copies_num ], ); + push @{ $self->{objects} }, $object; $self->object_loaded($#{ $self->{objects} }, no_arrange => 1); } @@ -1274,7 +1276,7 @@ has 'thumbnail_scaling_factor' => (is => 'rw', trigger => \&_transform_thumbnail has 'config' => (is => 'rw', default => sub { Slic3r::Config->new }); has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ] has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => extruder_idx } -has 'mesh_stats' => (is => 'rw'); +has 'mesh_stats' => (is => 'ro', required => 1); # statistics has 'facets' => (is => 'rw'); diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 3bddb6824..3594c9bc4 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -308,7 +308,7 @@ use Storable qw(dclone); has 'input_file' => (is => 'rw'); has 'model' => (is => 'ro', weak_ref => 1, required => 1); has 'volumes' => (is => 'ro', default => sub { [] }); -has 'instances' => (is => 'rw'); +has 'instances' => (is => 'rw'); # in unscaled coordinates has 'config' => (is => 'rw', default => sub { Slic3r::Config->new }); has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ] has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => extruder_idx } diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index bc653d8ec..9eae734c8 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -532,8 +532,11 @@ TriangleMesh::split() const mesh->stl.stats.original_num_facets = mesh->stl.stats.number_of_facets; stl_allocate(&mesh->stl); + int first = 1; for (std::deque::const_iterator facet = facets.begin(); facet != facets.end(); facet++) { mesh->stl.facet_start[facet - facets.begin()] = this->stl.facet_start[*facet]; + stl_facet_stats(&mesh->stl, this->stl.facet_start[*facet], first); + first = 0; } } diff --git a/xs/src/admesh/stl.h b/xs/src/admesh/stl.h index 332a5bf2f..ac4143858 100644 --- a/xs/src/admesh/stl.h +++ b/xs/src/admesh/stl.h @@ -178,6 +178,6 @@ extern void stl_initialize(stl_file *stl); static void stl_count_facets(stl_file *stl, char *file); extern void stl_allocate(stl_file *stl); static void stl_read(stl_file *stl, int first_facet, int first); -static void stl_facet_stats(stl_file *stl, stl_facet facet, int first); +extern void stl_facet_stats(stl_file *stl, stl_facet facet, int first); extern void stl_reallocate(stl_file *stl); extern void stl_get_size(stl_file *stl); diff --git a/xs/t/01_trianglemesh.t b/xs/t/01_trianglemesh.t index 71ae47319..127c8c925 100644 --- a/xs/t/01_trianglemesh.t +++ b/xs/t/01_trianglemesh.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 51; +use Test::More tests => 52; is Slic3r::TriangleMesh::hello_world(), 'Hello world!', 'hello world'; @@ -59,6 +59,7 @@ my $cube = { my $meshes = $m->split; is scalar(@$meshes), 1, 'split'; isa_ok $meshes->[0], 'Slic3r::TriangleMesh', 'split'; + is_deeply $m->bb3, $meshes->[0]->bb3, 'split populates stats'; } my $m2 = Slic3r::TriangleMesh->new;