From b20caa4e31e1bf296162166a25a79cfda275f0ea Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Jan 2014 20:16:54 +0100 Subject: [PATCH] Completed parts visualization with highlighting --- lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm | 23 +++++++++++++++-------- lib/Slic3r/GUI/SkeinPanel.pm | 6 +++++- lib/Slic3r/Model.pm | 2 -- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm index 595a89a599..9ec29d3b7e 100644 --- a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm +++ b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm @@ -37,12 +37,15 @@ sub new { $material_id //= '_'; if (!exists $nodes{$material_id}) { - $nodes{$material_id} = $tree->AppendItem($rootId, $object->model->get_material_name($material_id), ICON_MATERIAL); + my $material_name = $material_id eq '' + ? 'default' + : $object->model->get_material_name($material_id); + $nodes{$material_id} = $tree->AppendItem($rootId, "Material: $material_name", ICON_MATERIAL); } my $name = $volume->modifier ? 'Modifier mesh' : 'Solid mesh'; my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH; my $itemId = $tree->AppendItem($nodes{$material_id}, $name, $icon); - $tree->SetItemData($itemId, { + $tree->SetPlData($itemId, { type => 'volume', volume_id => $volume_id, }); @@ -73,14 +76,18 @@ sub new { EVT_TREE_SEL_CHANGED($self, $tree, sub { my ($self, $event) = @_; + # deselect all meshes + $_->{selected} = 0 for @{$canvas->volumes}; + my $nodeId = $tree->GetSelection; - printf "nodeId = %s\n", $nodeId; - my $itemData = $tree->GetItemData($nodeId); - if ($itemData && $itemData->{type} eq 'volume') { - $canvas->volumes->[ $itemData->{volume_id} ]{selected} = 1; - } else { - $_->{selected} = 0 for @{$canvas->volumes}; + if ($nodeId->IsOk) { + my $itemData = $tree->GetPlData($nodeId); + if ($itemData && $itemData->{type} eq 'volume') { + $canvas->volumes->[ $itemData->{volume_id} ]{selected} = 1; + } } + + $canvas->Render; }); diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index 371698e0a9..0665ba3ce0 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -355,7 +355,11 @@ sub combine_stls { my $new_object = $new_model->add_object; for my $m (0 .. $#models) { my $model = $models[$m]; - $new_model->set_material($m, { Name => basename($input_files[$m]) }); + + my $material_name = basename($input_files[$m]); + $material_name =~ s/\.(stl|obj)$//i; + + $new_model->set_material($m, { Name => $material_name }); $new_object->add_volume( material_id => $m, mesh => $model->objects->[0]->volumes->[0]->mesh, diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 04734145ba..10184a0778 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -296,8 +296,6 @@ sub get_material_name { my $name; if (exists $self->materials->{$material_id}) { $name //= $self->materials->{$material_id}->attributes->{$_} for qw(Name name); - } elsif ($material_id eq '_') { - $name = 'Default material'; } $name //= $material_id; return $name;