Merge branch 'master' into sender

This commit is contained in:
Alessandro Ranellucci 2015-01-04 19:36:28 +01:00
commit 3ab4d4b094
16 changed files with 192 additions and 61 deletions

View file

@ -201,10 +201,10 @@ sub _init_menubar {
$self->_append_menu_item($self->{plater_menu}, "Export G-code...", 'Export current plate as G-code', sub {
$plater->export_gcode;
});
$self->_append_menu_item($self->{plater_menu}, "Export STL...", 'Export current plate as STL', sub {
$self->_append_menu_item($self->{plater_menu}, "Export plate as STL...", 'Export current plate as STL', sub {
$plater->export_stl;
});
$self->_append_menu_item($self->{plater_menu}, "Export AMF...", 'Export current plate as AMF', sub {
$self->_append_menu_item($self->{plater_menu}, "Export plate as AMF...", 'Export current plate as AMF', sub {
$plater->export_amf;
});

View file

@ -14,6 +14,8 @@ sub BUILD {
$self->growler(Growl::GNTP->new(AppName => 'Slic3r', AppIcon => $icon));
$self->growler->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
};
# if register() fails (for example because of a timeout), disable growler at all
$self->growler(undef) if $@;
}
}

View file

@ -1009,6 +1009,9 @@ sub export_gcode {
$self->on_export_completed($result);
}
# this updates buttons status
$self->object_list_changed;
return $self->{export_gcode_output_file};
}
@ -1094,6 +1097,9 @@ sub on_export_completed {
$self->send_gcode if $send_gcode;
$self->{print_file} = undef;
$self->{send_gcode_file} = undef;
# this updates buttons status
$self->object_list_changed;
}
sub do_print {
@ -1122,7 +1128,7 @@ sub send_gcode {
$self->statusbar->StartBusy;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->timeout(180);
my $res = $ua->post(
"http://" . $self->{config}->octoprint_host . "/api/files/local",
@ -1158,6 +1164,19 @@ sub export_stl {
Slic3r::thread_cleanup() if $Slic3r::have_threads;
}
sub export_object_stl {
my $self = shift;
my ($obj_idx, $object) = $self->selected_object;
return if !defined $obj_idx;
my $model_object = $self->{model}->objects->[$obj_idx];
my $output_file = $self->_get_export_file('STL') or return;
Slic3r::Format::STL->write_file($output_file, $model_object->mesh, binary => 1);
$self->statusbar->SetStatusText("STL file exported to $output_file");
}
sub export_amf {
my $self = shift;
@ -1405,6 +1424,11 @@ sub object_list_changed {
$self->{"btn_$_"}->$method
for grep $self->{"btn_$_"}, qw(reset arrange export_gcode export_stl print send_gcode);
if ($self->{export_gcode_output_file} || $self->{send_gcode_file}) {
$self->{btn_export_gcode}->Disable;
$self->{btn_send_gcode}->Disable;
}
if ($self->{htoolbar}) {
$self->{htoolbar}->EnableTool($_, $have_objects)
for (TB_RESET, TB_ARRANGE);
@ -1584,6 +1608,10 @@ sub object_menu {
$frame->_append_menu_item($menu, "Settings…", 'Open the object editor dialog', sub {
$self->object_settings_dialog;
});
$menu->AppendSeparator();
$frame->_append_menu_item($menu, "Export object as STL…", 'Export this single object as STL file', sub {
$self->export_object_stl;
});
return $menu;
}

View file

@ -8,7 +8,7 @@ use OpenGL qw(:glconstants :glfunctions :glufunctions :gluconstants);
use base qw(Wx::GLCanvas Class::Accessor);
use Math::Trig qw(asin);
use List::Util qw(reduce min max first);
use Slic3r::Geometry qw(X Y Z MIN MAX triangle_normal normalize deg2rad tan scale unscale);
use Slic3r::Geometry qw(X Y Z MIN MAX triangle_normal normalize deg2rad tan scale unscale scaled_epsilon);
use Slic3r::Geometry::Clipper qw(offset_ex intersection_pl);
use Wx::GLCanvas qw(:all);
@ -28,6 +28,7 @@ __PACKAGE__->mk_accessors( qw(_quat _dirty init
bed_shape
bed_triangles
bed_grid_lines
background
origin
_mouse_pos
_hover_volume_idx
@ -41,7 +42,7 @@ __PACKAGE__->mk_accessors( qw(_quat _dirty init
use constant TRACKBALLSIZE => 0.8;
use constant TURNTABLE_MODE => 1;
use constant GROUND_Z => 0.02;
use constant GROUND_Z => -0.02;
use constant SELECTED_COLOR => [0,1,0,1];
use constant HOVER_COLOR => [0.8,0.8,0,1];
use constant COLORS => [ [1,1,0], [1,0.5,0.5], [0.5,1,0.5], [0.5,0.5,1] ];
@ -60,6 +61,7 @@ sub new {
my $self = $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "",
[WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0]);
$self->background(1);
$self->_quat((0, 0, 0, 1));
$self->_stheta(45);
$self->_sphi(45);
@ -327,7 +329,15 @@ sub set_bed_shape {
for (my $y = $bed_bb->y_min; $y <= $bed_bb->y_max; $y += scale 10) {
push @lines, Slic3r::Polyline->new([$bed_bb->x_min,$y], [$bed_bb->x_max,$y]);
}
@lines = @{intersection_pl(\@lines, [ @$expolygon ])};
# clip with a slightly grown expolygon because our lines lay on the contours and
# may get erroneously clipped
@lines = @{intersection_pl(\@lines, [ @{$expolygon->offset(+scaled_epsilon)} ])};
# append bed contours
foreach my $line (map @{$_->lines}, @$expolygon) {
push @lines, $line->as_polyline;
}
my @points = ();
foreach my $polyline (@lines) {
push @points, map {+ unscale($_->x), unscale($_->y), GROUND_Z } @$polyline; #))
@ -580,7 +590,7 @@ sub Resize {
return unless $self->GetContext;
$self->_dirty(0);
$self->SetCurrent($self->GetContext);
glViewport(0, 0, $x, $y);
@ -693,8 +703,29 @@ sub Render {
glFinish();
glEnable(GL_LIGHTING);
}
# draw objects
$self->draw_volumes;
# draw fixed background
if ($self->background) {
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(0.0,0.0,0.0);
glVertex2f(-1.0,-1.0);
glVertex2f(1,-1.0);
glColor3f(10/255,98/255,144/255);
glVertex2f(1, 1);
glVertex2f(-1.0, 1);
glEnd();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
# draw ground and axes
glDisable(GL_LIGHTING);
@ -704,26 +735,29 @@ sub Render {
# draw ground
my $ground_z = GROUND_Z;
if ($self->bed_triangles) {
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(0.6, 0.7, 0.5, 0.3);
glColor4f(0.8, 0.6, 0.5, 0.4);
glNormal3d(0,0,1);
glVertexPointer_p(3, $self->bed_triangles);
glDrawArrays(GL_TRIANGLES, 0, $self->bed_triangles->elements / 3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
# draw grid
glTranslatef(0, 0, 0.02);
glLineWidth(3);
glColor3f(0.95, 0.95, 0.95);
glColor4f(0.2, 0.2, 0.2, 0.4);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer_p(3, $self->bed_grid_lines);
glDrawArrays(GL_LINES, 0, $self->bed_grid_lines->elements / 3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_BLEND);
}
my $volumes_bb = $self->volumes_bounding_box;
@ -774,6 +808,9 @@ sub Render {
glEnable(GL_LIGHTING);
# draw objects
$self->draw_volumes;
glFlush();
$self->SwapBuffers();

View file

@ -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 :treectrl :window
wxTheApp);
:button wxTheApp);
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_TREE_SEL_CHANGED);
use base qw(Wx::Panel Class::Accessor);
@ -36,8 +36,10 @@ sub new {
$self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
# buttons
$self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", wxBITMAP_TYPE_PNG));
$self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
$self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", wxBITMAP_TYPE_PNG),
wxDefaultPosition, [16,16], wxBORDER_NONE);
$self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG),
wxDefaultPosition, [16,16], wxBORDER_NONE);
$self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title));
$self->{btn_delete_preset}->SetToolTipString("Delete this preset");
$self->{btn_delete_preset}->Disable;
@ -972,11 +974,6 @@ sub build {
$optgroup->append_single_option_line('z_offset');
}
{
my $optgroup = $page->new_optgroup('Firmware');
$optgroup->append_single_option_line('gcode_flavor');
$optgroup->append_single_option_line('use_relative_e_distances');
}
{
my $optgroup = $page->new_optgroup('Capabilities');
{
@ -1058,6 +1055,11 @@ sub build {
$optgroup->append_line($host_line);
$optgroup->append_single_option_line('octoprint_apikey');
}
{
my $optgroup = $page->new_optgroup('Firmware');
$optgroup->append_single_option_line('gcode_flavor');
$optgroup->append_single_option_line('use_relative_e_distances');
}
{
my $optgroup = $page->new_optgroup('Advanced');
$optgroup->append_single_option_line('use_firmware_retraction');