Skip to content

Commit

Permalink
Merge branch 'master_slic3rPE_PR'
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Oct 31, 2018
2 parents 280bb5d + b8dca4c commit e7cfb20
Show file tree
Hide file tree
Showing 110 changed files with 6,004 additions and 2,916 deletions.
24 changes: 0 additions & 24 deletions lib/Slic3r/GUI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -356,28 +356,4 @@ sub set_menu_item_icon {
}
}

sub save_window_pos {
my ($self, $window, $name) = @_;

$self->{app_config}->set("${name}_pos", join ',', $window->GetScreenPositionXY);
$self->{app_config}->set("${name}_size", join ',', $window->GetSizeWH);
$self->{app_config}->set("${name}_maximized", $window->IsMaximized);
$self->{app_config}->save;
}

sub restore_window_pos {
my ($self, $window, $name) = @_;
if ($self->{app_config}->has("${name}_pos")) {
my $size = [ split ',', $self->{app_config}->get("${name}_size"), 2 ];
$window->SetSize($size);

my $display = Wx::Display->new->GetClientArea();
my $pos = [ split ',', $self->{app_config}->get("${name}_pos"), 2 ];
if (($pos->[0] + $size->[0]/2) < $display->GetRight && ($pos->[1] + $size->[1]/2) < $display->GetBottom) {
$window->Move($pos);
}
$window->Maximize(1) if $self->{app_config}->get("${name}_maximized");
}
}

1;
4 changes: 2 additions & 2 deletions lib/Slic3r/GUI/MainFrame.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ sub new {
$self->Fit;
$self->SetMinSize([760, 490]);
$self->SetSize($self->GetMinSize);
wxTheApp->restore_window_pos($self, "main_frame");
Slic3r::GUI::restore_window_size($self, "main_frame");
$self->Show;
$self->Layout;
}
Expand All @@ -101,7 +101,7 @@ sub new {
return;
}
# save window size
wxTheApp->save_window_pos($self, "main_frame");
Slic3r::GUI::save_window_size($self, "main_frame");
# Save the slic3r.ini. Usually the ini file is saved from "on idle" callback,
# but in rare cases it may not have been called yet.
wxTheApp->{app_config}->save;
Expand Down
31 changes: 29 additions & 2 deletions lib/Slic3r/GUI/Plater.pm
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,15 @@ sub load_files {
$model->convert_multipart_object(scalar(@$nozzle_dmrs)) if $dialog->ShowModal() == wxID_YES;
}

# objects imported from 3mf require a call to center_around_origin to have gizmos working properly and this call
# need to be done after looks_like_multipart_object detection
if ($input_file =~ /.3[mM][fF]$/)
{
foreach my $model_object (@{$model->objects}) {
$model_object->center_around_origin; # also aligns object to Z = 0
}
}

if ($one_by_one) {
push @obj_idx, $self->load_model_objects(@{$model->objects});
} else {
Expand Down Expand Up @@ -1646,20 +1655,37 @@ sub print_info_box_show {
$grid_sizer->AddGrowableCol(1, 1);
$grid_sizer->AddGrowableCol(3, 1);
$print_info_sizer->Add($grid_sizer, 0, wxEXPAND);
my $is_wipe_tower = $self->{print}->total_wipe_tower_filament > 0;
my @info = (
L("Used Filament (m)")
=> sprintf("%.2f" , $self->{print}->total_used_filament / 1000),
=> $is_wipe_tower ?
sprintf("%.2f (%.2f %s + %.2f %s)" , $self->{print}->total_used_filament / 1000,
($self->{print}->total_used_filament - $self->{print}->total_wipe_tower_filament) / 1000,
L("objects"),
$self->{print}->total_wipe_tower_filament / 1000,
L("wipe tower")) :
sprintf("%.2f" , $self->{print}->total_used_filament / 1000),

L("Used Filament (mm³)")
=> sprintf("%.2f" , $self->{print}->total_extruded_volume),
L("Used Filament (g)"),
=> sprintf("%.2f" , $self->{print}->total_weight),
L("Cost"),
=> sprintf("%.2f" , $self->{print}->total_cost),
=> $is_wipe_tower ?
sprintf("%.2f (%.2f %s + %.2f %s)" , $self->{print}->total_cost,
($self->{print}->total_cost - $self->{print}->total_wipe_tower_cost),
L("objects"),
$self->{print}->total_wipe_tower_cost,
L("wipe tower")) :
sprintf("%.2f" , $self->{print}->total_cost),
L("Estimated printing time (normal mode)")
=> $self->{print}->estimated_normal_print_time,
L("Estimated printing time (silent mode)")
=> $self->{print}->estimated_silent_print_time
);
# if there is a wipe tower, insert number of toolchanges info into the array:
splice (@info, 8, 0, L("Number of tool changes") => sprintf("%.d", $self->{print}->m_wipe_tower_number_of_toolchanges)) if ($is_wipe_tower);

while ( my $label = shift @info) {
my $value = shift @info;
next if $value eq "N/A";
Expand All @@ -1674,6 +1700,7 @@ sub print_info_box_show {

$scrolled_window_sizer->Show(2, $show);
$scrolled_window_panel->Layout;
$self->Layout;
}

sub do_print {
Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/GUI/Plater/ObjectCutDialog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ sub _update {
my @expolygons = ();
foreach my $volume (@{$self->{model_object}->volumes}) {
next if !$volume->mesh;
next if $volume->modifier;
next if !$volume->model_part;
my $expp = $volume->mesh->slice([ $z_cut ])->[0];
push @expolygons, @$expp;
}
Expand Down
93 changes: 75 additions & 18 deletions lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use base 'Wx::Panel';
use constant ICON_OBJECT => 0;
use constant ICON_SOLIDMESH => 1;
use constant ICON_MODIFIERMESH => 2;
use constant ICON_SUPPORT_ENFORCER => 3;
use constant ICON_SUPPORT_BLOCKER => 4;

sub new {
my ($class, $parent, %params) = @_;
Expand All @@ -35,7 +37,7 @@ sub new {
y => 0,
z => 0,
};

# create TreeCtrl
my $tree = $self->{tree} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [300, 100],
wxTR_NO_BUTTONS | wxSUNKEN_BORDER | wxTR_HAS_VARIABLE_ROW_HEIGHT
Expand All @@ -46,6 +48,8 @@ sub new {
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("brick.png"), wxBITMAP_TYPE_PNG)); # ICON_OBJECT
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("package.png"), wxBITMAP_TYPE_PNG)); # ICON_SOLIDMESH
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("plugin.png"), wxBITMAP_TYPE_PNG)); # ICON_MODIFIERMESH
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("support_enforcer.png"), wxBITMAP_TYPE_PNG)); # ICON_SUPPORT_ENFORCER
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("support_blocker.png"), wxBITMAP_TYPE_PNG)); # ICON_SUPPORT_BLOCKER

my $rootId = $tree->AddRoot("Object", ICON_OBJECT);
$tree->SetPlData($rootId, { type => 'object' });
Expand Down Expand Up @@ -89,7 +93,14 @@ sub new {
$self->{btn_move_down}->SetFont($Slic3r::GUI::small_font);

# part settings panel
$self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self, on_change => sub { $self->{part_settings_changed} = 1; $self->_update_canvas; });
$self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self, on_change => sub {
my ($key, $value) = @_;
wxTheApp->CallAfter(sub {
$self->set_part_type($value) if ($key eq "part_type");
$self->{part_settings_changed} = 1;
$self->_update_canvas;
});
});
my $settings_sizer = Wx::StaticBoxSizer->new($self->{staticbox} = Wx::StaticBox->new($self, -1, "Part Settings"), wxVERTICAL);
$settings_sizer->Add($self->{settings_panel}, 1, wxEXPAND | wxALL, 0);

Expand Down Expand Up @@ -225,8 +236,11 @@ sub reload_tree {
my $selectedId = $rootId;
foreach my $volume_id (0..$#{$object->volumes}) {
my $volume = $object->volumes->[$volume_id];

my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH;
my $icon =
$volume->modifier ? ICON_MODIFIERMESH :
$volume->support_enforcer ? ICON_SUPPORT_ENFORCER :
$volume->support_blocker ? ICON_SUPPORT_BLOCKER :
ICON_SOLIDMESH;
my $itemId = $tree->AppendItem($rootId, $volume->name || $volume_id, $icon);
if ($volume_id == $selected_volume_idx) {
$selectedId = $itemId;
Expand Down Expand Up @@ -288,6 +302,8 @@ sub selection_changed {

if (my $itemData = $self->get_selection) {
my ($config, @opt_keys);
my $type = Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_OBJECT;
my $support = 0;
if ($itemData->{type} eq 'volume') {
# select volume in 3D preview
if ($self->{canvas}) {
Expand All @@ -301,16 +317,24 @@ sub selection_changed {
# attach volume config to settings panel
my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];

if ($volume->modifier) {
if (! $volume->model_part) {
$self->{optgroup_movers}->enable;
if ($volume->support_enforcer || $volume->support_blocker) {
$support = 1;
$type = $volume->support_enforcer ?
Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_SUPPORT_ENFORCER :
Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_SUPPORT_BLOCKER;
} else {
$type = Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_MODIFIER;
}
} else {
$type = Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_PART;
$self->{optgroup_movers}->disable;
}
$config = $volume->config;
$self->{staticbox}->SetLabel('Part Settings');

# get default values
@opt_keys = @{Slic3r::Config::PrintRegion->new->get_keys};
@opt_keys = $support ? () : @{Slic3r::Config::PrintRegion->new->get_keys};
} elsif ($itemData->{type} eq 'object') {
# select nothing in 3D preview

Expand All @@ -323,33 +347,54 @@ sub selection_changed {
# get default values
my $default_config = Slic3r::Config::new_from_defaults_keys(\@opt_keys);

# decide which settings will be shown by default
# decide which settings will be shown by default
if ($itemData->{type} eq 'object') {
$config->set_ifndef('wipe_into_objects', 0);
$config->set_ifndef('wipe_into_infill', 0);
}

# append default extruder
push @opt_keys, 'extruder';
$default_config->set('extruder', 0);
$config->set_ifndef('extruder', 0);
if (! $support) {
push @opt_keys, 'extruder';
$default_config->set('extruder', 0);
$config->set_ifndef('extruder', 0);
}
$self->{settings_panel}->set_type($type);
$self->{settings_panel}->set_default_config($default_config);
$self->{settings_panel}->set_config($config);
$self->{settings_panel}->set_opt_keys(\@opt_keys);

# disable minus icon to remove the settings
if ($itemData->{type} eq 'object') {
$self->{settings_panel}->set_fixed_options([qw(extruder), qw(wipe_into_infill), qw(wipe_into_objects)]);
} else {
$self->{settings_panel}->set_fixed_options([qw(extruder)]);
}

my $fixed_options =
($itemData->{type} eq 'object') ? [qw(extruder), qw(wipe_into_infill), qw(wipe_into_objects)] :
$support ? [] : [qw(extruder)];
$self->{settings_panel}->set_fixed_options($fixed_options);
$self->{settings_panel}->enable;
}

Slic3r::GUI::_3DScene::render($self->{canvas}) if $self->{canvas};
}

sub set_part_type
{
my ($self, $part_type) = @_;
if (my $itemData = $self->get_selection) {
if ($itemData->{type} eq 'volume') {
my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];
if ($part_type == Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_MODIFIER ||
$part_type == Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_PART) {
$volume->set_modifier($part_type == Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_MODIFIER);
} elsif ($part_type == Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_SUPPORT_ENFORCER) {
$volume->set_support_enforcer;
} elsif ($part_type == Slic3r::GUI::Plater::OverrideSettingsPanel->TYPE_SUPPORT_BLOCKER) {
$volume->set_support_blocker;
}
# We want the icon of the selected item to be changed as well.
$self->reload_tree($itemData->{volume_id});
}
}
}

sub on_btn_load {
my ($self, $is_modifier) = @_;

Expand All @@ -362,13 +407,25 @@ sub on_btn_load {
}

foreach my $object (@{$model->objects}) {
my $delta_x = 0.0;
my $delta_y = 0.0;
my $delta_z = 0.0;
if (($self->{model_object}->origin_translation->x != 0.0) || ($self->{model_object}->origin_translation->y != 0.0) || ($self->{model_object}->origin_translation->z != 0.0)) {
$object->center_around_origin;
$delta_x = $self->{model_object}->origin_translation->x - $object->origin_translation->x;
$delta_y = $self->{model_object}->origin_translation->y - $object->origin_translation->y;
$delta_z = $self->{model_object}->origin_translation->z - $object->origin_translation->z;
}
foreach my $volume (@{$object->volumes}) {
my $new_volume = $self->{model_object}->add_volume($volume);
$new_volume->set_modifier($is_modifier);
$new_volume->set_name(basename($input_file));

# apply the same translation we applied to the object
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation});
if (($delta_x != 0.0) || ($delta_y != 0.0) || ($delta_z != 0.0)) {
$new_volume->mesh->translate($delta_x, $delta_y, $delta_z);
$new_volume->convex_hull->translate($delta_x, $delta_y, $delta_z);
}

# set a default extruder value, since user can't add it manually
$new_volume->config->set_ifndef('extruder', 0);
Expand Down
4 changes: 2 additions & 2 deletions lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sub new {
$self->{layers}->Closing;

# save window size
wxTheApp->save_window_pos($self, "object_settings");
Slic3r::GUI::save_window_size($self, "object_settings");

$self->EndModal(wxID_OK);
$self->{parts}->Destroy;
Expand All @@ -49,7 +49,7 @@ sub new {

$self->Layout;

wxTheApp->restore_window_pos($self, "object_settings");
Slic3r::GUI::restore_window_size($self, "object_settings");

return $self;
}
Expand Down
Loading

0 comments on commit e7cfb20

Please sign in to comment.