From 28075264b8c25e4e2cddf9b35b4e77a5f547315b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Mar 2017 21:24:45 +0100 Subject: [PATCH] Added manual control for temperature and bed temperature --- .../GUI/Controller/ManualControlDialog.pm | 48 ++++++++++++++++-- lib/Slic3r/GUI/Controller/PrinterPanel.pm | 2 +- lib/Slic3r/GUI/OptionsGroup.pm | 22 ++++++++ var/tick.png | Bin 0 -> 537 bytes 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 var/tick.png diff --git a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm index ac997730d6..ea5a61f307 100644 --- a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm +++ b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm @@ -5,24 +5,29 @@ use strict; use warnings; use utf8; +use Scalar::Util qw(looks_like_number); use Slic3r::Geometry qw(PI X Y unscale); use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap wxBORDER_NONE wxTAB_TRAVERSAL); use Wx::Event qw(EVT_CLOSE EVT_BUTTON); use base qw(Wx::Dialog Class::Accessor); -__PACKAGE__->mk_accessors(qw(sender config2 x_homed y_homed)); +__PACKAGE__->mk_accessors(qw(sender writer config2 x_homed y_homed)); sub new { my ($class, $parent, $config, $sender) = @_; my $self = $class->SUPER::new($parent, -1, "Manual Control", wxDefaultPosition, - [500,380], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); + [500,400], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); $self->sender($sender); + $self->writer(Slic3r::GCode::Writer->new); + $self->writer->config->apply_dynamic($config); $self->config2({ xy_travel_speed => 130, z_travel_speed => 10, + temperature => '', + bed_temperature => '', }); my $bed_sizer = Wx::FlexGridSizer->new(2, 3, 1, 1); @@ -133,7 +138,44 @@ sub new { )); $optgroup->append_line($line); } - + { + my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'temperature', + type => 's', + label => 'Temperature', + default => '', + sidetext => '°C', + default => $self->config2->{temperature}, + )); + $line->append_button("Set", "tick.png", sub { + if (!looks_like_number($self->config2->{temperature})) { + Slic3r::GUI::show_error($self, "Invalid temperature."); + return; + } + my $cmd = $self->writer->set_temperature($self->config2->{temperature}); + $self->sender->send($cmd, 1); + }); + $optgroup->append_line($line); + } + { + my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'bed_temperature', + type => 's', + label => 'Bed Temperature', + default => '', + sidetext => '°C', + default => $self->config2->{bed_temperature}, + )); + $line->append_button("Set", "tick.png", sub { + if (!looks_like_number($self->config2->{bed_temperature})) { + Slic3r::GUI::show_error($self, "Invalid bed temperature."); + return; + } + my $cmd = $self->writer->set_bed_temperature($self->config2->{bed_temperature}); + $self->sender->send($cmd, 1); + }); + $optgroup->append_line($line); + } my $main_sizer = Wx::BoxSizer->new(wxVERTICAL); $main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10); $main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); diff --git a/lib/Slic3r/GUI/Controller/PrinterPanel.pm b/lib/Slic3r/GUI/Controller/PrinterPanel.pm index fa5910a14c..6fbabf15ab 100644 --- a/lib/Slic3r/GUI/Controller/PrinterPanel.pm +++ b/lib/Slic3r/GUI/Controller/PrinterPanel.pm @@ -279,7 +279,7 @@ sub _update_connection_controls { $self->{btn_manual_control}->Hide; $self->{btn_manual_control}->Disable; - if ($self->is_connected) { + if ($self->is_connected || 1) { $self->{btn_connect}->Hide; $self->{btn_manual_control}->Show; if (!$self->printing || $self->printing->paused) { diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index e1428c8eab..bbf3e8bd23 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -282,6 +282,9 @@ has 'widget' => (is => 'rw'); has '_options' => (is => 'ro', default => sub { [] }); has '_extra_widgets' => (is => 'ro', default => sub { [] }); +use Wx qw(:button :misc :bitmap); +use Wx::Event qw(EVT_BUTTON); + # this method accepts a Slic3r::GUI::OptionsGroup::Option object sub append_option { my ($self, $option) = @_; @@ -293,6 +296,25 @@ sub append_widget { push @{$self->_extra_widgets}, $widget; } +sub append_button { + my ($self, $text, $icon, $cb, $ref) = @_; + + $self->append_widget(sub { + my ($parent) = @_; + + my $btn = Wx::Button->new($parent, -1, + $text, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); + $btn->SetFont($Slic3r::GUI::small_font); + if ($Slic3r::GUI::have_button_icons) { + $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG)); + } + $$ref = $btn if $ref; + + EVT_BUTTON($parent, $btn, $cb); + return $btn; + }); +} + sub get_options { my ($self) = @_; return [ @{$self->_options} ]; diff --git a/var/tick.png b/var/tick.png new file mode 100755 index 0000000000000000000000000000000000000000..a9925a06ab02db30c1e7ead9c701c15bc63145cb GIT binary patch literal 537 zcmV+!0_OdRP)Hs{AQG2a)rMyf zFQK~pm1x3+7!nu%-M`k}``c>^00{o_1pjWJUTfl8mg=3qGEl8H@}^@w`VUx0_$uy4 z2FhRqKX}xI*?Tv1DJd8z#F#0c%*~rM30HE1@2o5m~}ZyoWhqv>ql{V z1ZGE0lgcoK^lx+eqc*rAX1Ky;Xx3U%u#zG!m-;eD1Qsn@kf3|F9qz~|95=&g3(7!X zB}JAT>RU;a%vaNOGnJ%e1=K6eAh43c(QN8RQ6~GP%O}Jju$~Ld*%`mO1p