Some incomplete work for interactive part editor
This commit is contained in:
parent
fd43ada293
commit
3f4f27fa5d
@ -4,7 +4,7 @@ use warnings;
|
||||
use utf8;
|
||||
|
||||
use Wx qw(:misc :sizer :treectrl wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG);
|
||||
use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING);
|
||||
use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING EVT_TREE_SEL_CHANGED);
|
||||
use base 'Wx::Panel';
|
||||
|
||||
use constant ICON_MATERIAL => 0;
|
||||
@ -18,10 +18,8 @@ sub new {
|
||||
|
||||
my $object = $self->{model_object} = $params{model_object};
|
||||
|
||||
$self->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
|
||||
|
||||
# create TreeCtrl
|
||||
my $tree = $self->{tree} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [-1, 200],
|
||||
my $tree = $self->{tree} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [200, 200],
|
||||
wxTR_NO_BUTTONS | wxSUNKEN_BORDER | wxTR_HAS_VARIABLE_ROW_HEIGHT | wxTR_HIDE_ROOT
|
||||
| wxTR_MULTIPLE | wxTR_NO_BUTTONS);
|
||||
{
|
||||
@ -33,7 +31,8 @@ sub new {
|
||||
|
||||
my $rootId = $tree->AddRoot("");
|
||||
my %nodes = (); # material_id => nodeId
|
||||
foreach my $volume (@{$object->volumes}) {
|
||||
foreach my $volume_id (0..$#{$object->volumes}) {
|
||||
my $volume = $object->volumes->[$volume_id];
|
||||
my $material_id = $volume->material_id;
|
||||
$material_id //= '_';
|
||||
|
||||
@ -42,19 +41,49 @@ sub new {
|
||||
}
|
||||
my $name = $volume->modifier ? 'Modifier mesh' : 'Solid mesh';
|
||||
my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH;
|
||||
$tree->AppendItem($nodes{$material_id}, $name, $icon);
|
||||
my $itemId = $tree->AppendItem($nodes{$material_id}, $name, $icon);
|
||||
$tree->SetItemData($itemId, {
|
||||
type => 'volume',
|
||||
volume_id => $volume_id,
|
||||
});
|
||||
}
|
||||
$tree->ExpandAll;
|
||||
}
|
||||
|
||||
# left pane with tree
|
||||
my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||
$left_sizer->Add($tree, 0, wxEXPAND | wxALL, 10);
|
||||
|
||||
# right pane with preview canvas
|
||||
my $canvas = $self->{canvas} = Slic3r::GUI::PreviewCanvas->new($self, $self->{model_object});
|
||||
$canvas->SetSize([500,500]);
|
||||
|
||||
$self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
$self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxALL, 0);
|
||||
$self->{sizer}->Add($canvas, 1, wxEXPAND | wxALL, 0);
|
||||
|
||||
$self->SetSizer($self->{sizer});
|
||||
$self->{sizer}->SetSizeHints($self);
|
||||
|
||||
# attach events
|
||||
EVT_TREE_ITEM_COLLAPSING($self, $tree, sub {
|
||||
my ($self, $event) = @_;
|
||||
$event->Veto;
|
||||
});
|
||||
EVT_TREE_SEL_CHANGED($self, $tree, sub {
|
||||
my ($self, $event) = @_;
|
||||
|
||||
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};
|
||||
}
|
||||
});
|
||||
|
||||
$self->{sizer}->Add($tree, 0, wxEXPAND | wxALL, 10);
|
||||
|
||||
$self->SetSizer($self->{sizer});
|
||||
$self->{sizer}->SetSizeHints($self);
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ __PACKAGE__->mk_accessors( qw(quat dirty init mview_init
|
||||
|
||||
use constant TRACKBALLSIZE => 0.8;
|
||||
use constant TURNTABLE_MODE => 1;
|
||||
use constant SELECTED_COLOR => [0,1,0];
|
||||
use constant COLORS => [ [1,1,1], [1,0.5,0.5], [0.5,1,0.5], [0.5,0.5,1] ];
|
||||
|
||||
sub new {
|
||||
@ -447,7 +448,11 @@ sub draw_mesh {
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
glNormalPointer_p($volume->{norms});
|
||||
glColor3f(@{ $volume->{color} });
|
||||
if ($volume->{selected}) {
|
||||
glColor3f(@{ &SELECTED_COLOR });
|
||||
} else {
|
||||
glColor3f(@{ $volume->{color} });
|
||||
}
|
||||
glDrawArrays(GL_TRIANGLES, 0, $volume->{verts}->elements / 3);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use utf8;
|
||||
use File::Basename qw(basename);
|
||||
use List::Util qw(first);
|
||||
use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :window :systemsettings);
|
||||
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_TREE_SEL_CHANGED);
|
||||
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN);
|
||||
use base 'Wx::ScrolledWindow';
|
||||
|
||||
sub new {
|
||||
|
Loading…
Reference in New Issue
Block a user