Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into merill_thin…
Browse files Browse the repository at this point in the history
…wall
  • Loading branch information
supermerill committed Oct 22, 2019
2 parents 6273f0d + 4f5b935 commit 7770f70
Show file tree
Hide file tree
Showing 22 changed files with 2,361 additions and 68 deletions.
43 changes: 34 additions & 9 deletions lib/Slic3r/GUI/Plater.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ sub new {
# Stack of redo operations.
$self->{redo_stack} = [];

# Preset dialogs
$self->{'preset_dialogs'} = {};

$self->{print}->set_status_cb(sub {
my ($percent, $message) = @_;

Expand Down Expand Up @@ -372,7 +375,7 @@ sub new {
EVT_BUTTON($self, $self->{btn_increase}, sub { $self->increase; });
EVT_BUTTON($self, $self->{btn_decrease}, sub { $self->decrease; });

if ($Slic3r::GUI::Settings->{_}{extended_gui} >= 2) { # if Toolbar enabled
if ($Slic3r::GUI::Settings->{_}{rotation_controls} eq 'xyz' || $Slic3r::GUI::Settings->{_}{rotation_controls} eq 'xyz-big') {
EVT_BUTTON($self, $self->{btn_rotateX90cw}, sub { $_[0]->rotate(-90, X) });
EVT_BUTTON($self, $self->{btn_rotateX90ccw}, sub { $_[0]->rotate(90, X) });
EVT_BUTTON($self, $self->{btn_rotateY90cw}, sub { $_[0]->rotate(-90, Y) });
Expand Down Expand Up @@ -599,6 +602,7 @@ sub new {
my @info = (
fil => "Used Filament",
cost => "Cost",
tim => "Time",
);
while (my $field = shift @info) {
my $label = shift @info;
Expand Down Expand Up @@ -876,14 +880,30 @@ sub selected_presets {
return $group ? @{$presets{$group}} : %presets;
}

sub show_unique_preset_dialog {
my($self, $group) = @_;
my $dlg;
my $preset_editor;
if( $self->{'preset_dialogs'}->{$group} ) {
$dlg = $self->{'preset_dialogs'}->{$group};
}
else {
my $class = "Slic3r::GUI::PresetEditorDialog::" . ucfirst($group);
$dlg = $class->new($self);
$self->{'preset_dialogs'}->{$group} = $dlg;
}
$dlg->Show;
$preset_editor = $dlg->preset_editor;
return $preset_editor;
}

sub show_preset_editor {
my ($self, $group, $i, $panel) = @_;

wxTheApp->CallAfter(sub {
my @presets = $self->selected_presets($group);

my $preset_editor;
my $dlg;
my $mainframe = $self->GetFrame;
my $tabpanel = $mainframe->{tabpanel};
if (exists $mainframe->{preset_editor_tabs}{$group}) {
Expand All @@ -900,9 +920,7 @@ sub show_preset_editor {
$mainframe->{preset_editor_tabs}{$group} = $preset_editor = $class->new($tabpanel);
$tabpanel->AddPage($preset_editor, ucfirst($group) . " Settings");
} else {
my $class = "Slic3r::GUI::PresetEditorDialog::" . ucfirst($group);
$dlg = $class->new($self);
$preset_editor = $dlg->preset_editor;
$preset_editor = $self->show_unique_preset_dialog($group);
}

$preset_editor->select_preset_by_name($presets[$i // 0]->name);
Expand All @@ -927,10 +945,6 @@ sub show_preset_editor {
};
$preset_editor->on_select_preset($cb);
$preset_editor->on_save_preset($cb);

if ($dlg) {
$dlg->Show;
}
});
}

Expand Down Expand Up @@ -2282,6 +2296,17 @@ sub on_export_completed {
} else {
$message = "Export failed";
}
# Estimate print duration
{
my $estimator = Slic3r::GCode::TimeEstimator->new;
$estimator->parse_file($self->{export_gcode_output_file});
my $time = $estimator->time;
$self->{print_info_tim}->SetLabel(sprintf(
"%d minutes and %d seconds",
int($time / 60),
int($time % 60),
));
}
$self->{export_gcode_output_file} = undef;
$self->statusbar->SetStatusText($message);
wxTheApp->notify($message);
Expand Down
4 changes: 3 additions & 1 deletion lib/Slic3r/GUI/PresetEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ sub _update {

if (any { /$opt_key/ } qw(all_keys top_solid_layers bottom_solid_layers fill_density)) {
$self->get_field($_)->toggle($have_infill || $have_solid_infill)
for qw(fill_angle infill_extrusion_width infill_speed bridge_speed);
for qw(fill_angle infill_extrusion_width infill_speed);
}

if (any { /$opt_key/ } qw(all_keys fill_density perimeters)) {
Expand Down Expand Up @@ -1263,6 +1263,7 @@ sub title { 'Printer Settings' }
sub options {
return qw(
bed_shape z_offset z_steps_per_mm has_heatbed
fan_percentage
gcode_flavor use_relative_e_distances
serial_port serial_speed
host_type print_host octoprint_apikey
Expand Down Expand Up @@ -1429,6 +1430,7 @@ sub build {
$optgroup->append_single_option_line('z_steps_per_mm');
$optgroup->append_single_option_line('use_set_and_wait_extruder');
$optgroup->append_single_option_line('use_set_and_wait_bed');
$optgroup->append_single_option_line('fan_percentage');
}
}
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Slic3r/Print/GCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ sub export {
# disable fan
print $fh $gcodegen->writer->set_fan(0, 1)
if $self->config->cooling && $self->config->disable_fan_first_layers;

# set initial extruder so it can be used in start G-code
print $fh $gcodegen->set_extruder($self->print->extruders->[0]);

# set bed temperature
if ($self->config->has_heatbed && (my $temp = $self->config->first_layer_bed_temperature) && $self->config->start_gcode !~ /M(?:190|140)/i) {
Expand Down Expand Up @@ -223,9 +226,6 @@ sub export {
}
}

# set initial extruder only after custom start G-code
print $fh $gcodegen->set_extruder($self->print->extruders->[0]);

# do all objects for each layer
if ($self->config->complete_objects) {
# print objects from the smallest to the tallest to avoid collisions
Expand Down
1 change: 1 addition & 0 deletions package/linux/libpaths.appimage.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#/usr/lib/x86_64-linux-gnu/libstdc++.so.6 # needed because of ancient distros and slic3r (and perl for perl reasons) needs modern c++.
#/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so # Missing?
/lib/x86_64-linux-gnu/libcrypt.so.1 # Add because FEDORA.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ set(SLIC3R_TEST_SOURCES
${TESTDIR}/libslic3r/test_skirt_brim.cpp
${TESTDIR}/libslic3r/test_test_data.cpp
${TESTDIR}/libslic3r/test_trianglemesh.cpp
${TESTDIR}/libslic3r/test_extrusion_entity.cpp
${TESTDIR}/libslic3r/test_3mf.cpp
)

Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Plater/Preview3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Preview3D::Preview3D(wxWindow* parent, const wxSize& size, std::shared_ptr<Slic3
//z_label->SetFont(Slic3r::GUI::small_font);

auto* vsizer = new wxBoxSizer(wxVERTICAL);
vsizer->Add(slider, 1, wxALL | wxEXPAND | wxALIGN_CENTER, 3);
vsizer->Add(z_label, 0, wxALL | wxEXPAND | wxALIGN_CENTER, 3);
vsizer->Add(slider, 1, wxALL | wxEXPAND, 3);
vsizer->Add(z_label, 0, wxALL | wxEXPAND, 3);

auto* sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(&canvas, 1, wxALL | wxEXPAND, 0);
Expand Down
14 changes: 12 additions & 2 deletions src/slic3r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,18 @@ int CLI::run(int argc, char **argv) {
if (actions.empty()) {
#ifdef USE_WX
GUI::App *gui = new GUI::App();
gui->autosave = this->config.getString("autosave");
gui->datadir = this->config.getString("datadir");
try {
gui->autosave = this->config.getString("autosave");
} catch(Slic3r::UnknownOptionException &e) {
// if no autosave, set a sensible default.
gui->autosave = wxFileName::CreateTempFileName("slic3r_autosave_").ToStdString();
}
try {
gui->datadir = this->config.getString("datadir");
} catch(Slic3r::UnknownOptionException &e) {
// if no datadir on the CLI, set a default.
gui->datadir = GUI::home().ToStdString();
}
GUI::App::SetInstance(gui);
wxEntry(argc, argv);
#else
Expand Down
79 changes: 79 additions & 0 deletions src/test/libslic3r/test_extrusion_entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <catch.hpp>
#include "ExtrusionEntityCollection.hpp"
#include "ExtrusionEntity.hpp"
#include "Point.hpp"
#include <cstdlib>

Point random_point(float LO=-50, float HI=50) {
float x = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO)));
float y = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO)));
return Point(x, y);
}

// build a sample extrusion entity collection with random start and end points.
ExtrusionPath random_path(size_t length = 20, float LO=-50, float HI=50) {
ExtrusionPath t {erPerimeter, 1.0, 1.0, 1.0};
for (size_t j = 0; j < length; j++) {
t.polyline.append(random_point(LO, HI));
}
return t;
}

ExtrusionPaths random_paths(size_t count=10, size_t length=20, float LO=-50, float HI=50) {
ExtrusionPaths p;
for (size_t i = 0; i < count; i++)
p.push_back(random_path(length, LO, HI));
return p;
}

using namespace Slic3r;

SCENARIO("ExtrusionEntityCollection: Polygon flattening") {
srand(0xDEADBEEF); // consistent seed for test reproducibility.

// Generate one specific random path set and save it for later comparison
ExtrusionPaths nosort_path_set {random_paths()};

ExtrusionEntityCollection sub_nosort;
sub_nosort.append(nosort_path_set);
sub_nosort.no_sort = true;

ExtrusionEntityCollection sub_sort;
sub_sort.no_sort = false;
sub_sort.append(random_paths());


GIVEN("A Extrusion Entity Collection with a child that has one child that is marked as no-sort") {
ExtrusionEntityCollection sample;
ExtrusionEntityCollection output;

sample.append(sub_sort);
sample.append(sub_nosort);
sample.append(sub_sort);
WHEN("The EEC is flattened with default options (preserve_order=false)") {
sample.flatten(&output);
THEN("The output EEC contains no Extrusion Entity Collections") {
CHECK(std::count_if(output.entities.cbegin(), output.entities.cend(), [=](const ExtrusionEntity* e) {return e->is_collection();}) == 0);
}
}
WHEN("The EEC is flattened with preservation (preserve_order=true)") {
sample.flatten(&output, true);
THEN("The output EECs contains one EEC.") {
CHECK(std::count_if(output.entities.cbegin(), output.entities.cend(), [=](const ExtrusionEntity* e) {return e->is_collection();}) == 1);
}
AND_THEN("The ordered EEC contains the same order of elements than the original") {
// find the entity in the collection
for (auto e : output.entities) {
if (!e->is_collection()) continue;
ExtrusionEntityCollection* temp = dynamic_cast<ExtrusionEntityCollection*>(e);
// check each Extrusion path against nosort_path_set to see if the first and last match the same
CHECK(nosort_path_set.size() == temp->size());
for (size_t i = 0; i < nosort_path_set.size(); i++) {
CHECK(temp->entities[i]->first_point() == nosort_path_set[i].first_point());
CHECK(temp->entities[i]->last_point() == nosort_path_set[i].last_point());
}
}
}
}
}
}
46 changes: 44 additions & 2 deletions src/test/libslic3r/test_printgcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ SCENARIO( "PrintGCode basic functionality") {
REQUIRE(exported.find("M107") != std::string::npos);
}
}


WHEN("end_gcode exists with layer_num and layer_z") {
config->set("end_gcode", "; Layer_num [layer_num]\n; Layer_z [layer_z]");
config->set("layer_height", 0.1);
Expand All @@ -224,6 +222,50 @@ SCENARIO( "PrintGCode basic functionality") {
REQUIRE(exported.find("; Layer_z 20") != std::string::npos);
}
}
WHEN("current_extruder exists in start_gcode") {
config->set("start_gcode", "; Extruder [current_extruder]");
{
Slic3r::Model model;
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)};
Slic3r::Test::gcode(gcode, print);
auto exported {gcode.str()};
THEN("current_extruder is processed in the start gcode and set for first extruder") {
REQUIRE(exported.find("; Extruder 0") != std::string::npos);
}
}
config->set("solid_infill_extruder", 2);
config->set("support_material_extruder", 2);
config->set("infill_extruder", 2);
config->set("perimeter_extruder", 2);
{
Slic3r::Model model;
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)};
Slic3r::Test::gcode(gcode, print);
auto exported {gcode.str()};
THEN("current_extruder is processed in the start gcode and set for second extruder") {
REQUIRE(exported.find("; Extruder 1") != std::string::npos);
}
}
}

WHEN("layer_num represents the layer's index from z=0") {
config->set("layer_gcode", ";Layer:[layer_num] ([layer_z] mm)");
config->set("layer_height", 1.0);
config->set("first_layer_height", 1.0);

Slic3r::Model model;
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20,TestMesh::cube_20x20x20}, model, config)};
Slic3r::Test::gcode(gcode, print);

auto exported {gcode.str()};
int count = 2;
for(int pos = 0; pos != std::string::npos; count--)
pos = exported.find(";Layer:38 (20 mm)", pos+1);

THEN("layer_num and layer_z are processed in the end gcode") {\
REQUIRE(count == -1);
}
}

gcode.clear();
}
Expand Down
Loading

0 comments on commit 7770f70

Please sign in to comment.