Console for sending manual commands in manual printer control

This commit is contained in:
Alessandro Ranellucci 2017-03-11 00:06:23 +01:00
parent 6d371884a1
commit f018c20a6d
2 changed files with 100 additions and 43 deletions

View File

@ -7,7 +7,7 @@ use utf8;
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
use Slic3r::Geometry qw(PI X Y unscale); use Slic3r::Geometry qw(PI X Y unscale);
use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap :textctrl
wxBORDER_NONE wxTAB_TRAVERSAL); wxBORDER_NONE wxTAB_TRAVERSAL);
use Wx::Event qw(EVT_CLOSE EVT_BUTTON); use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
use base qw(Wx::Dialog Class::Accessor); use base qw(Wx::Dialog Class::Accessor);
@ -107,7 +107,7 @@ sub new {
my $optgroup = Slic3r::GUI::OptionsGroup->new( my $optgroup = Slic3r::GUI::OptionsGroup->new(
parent => $self, parent => $self,
title => 'Settings', title => 'Manual motion settings',
on_change => sub { on_change => sub {
my ($opt_id, $value) = @_; my ($opt_id, $value) = @_;
$self->config2->{$opt_id} = $value; $self->config2->{$opt_id} = $value;
@ -133,53 +133,101 @@ sub new {
)); ));
$optgroup->append_line($line); $optgroup->append_line($line);
} }
my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
$left_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10);
$left_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
my $right_sizer = Wx::BoxSizer->new(wxVERTICAL);
{ {
my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( my $optgroup = Slic3r::GUI::OptionsGroup->new(
opt_id => 'temperature', parent => $self,
type => 's', title => 'Temperature',
label => 'Temperature', on_change => sub {
default => '', my ($opt_id, $value) = @_;
sidetext => '°C', $self->config2->{$opt_id} = $value;
default => $self->config2->{temperature}, },
)); );
$line->append_button("Set", "tick.png", sub { $right_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
if (!looks_like_number($self->config2->{temperature})) { {
Slic3r::GUI::show_error($self, "Invalid temperature."); my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
return; opt_id => 'temperature',
} type => 's',
my $cmd = $self->writer->set_temperature($self->config2->{temperature}); label => 'Extruder',
$self->sender->send($cmd, 1); default => '',
}); sidetext => '°C',
$optgroup->append_line($line); 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',
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 $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( my $box = Wx::StaticBox->new($self, -1, "Console");
opt_id => 'bed_temperature', my $sbsizer = Wx::StaticBoxSizer->new($box, wxVERTICAL);
type => 's', $right_sizer->Add($sbsizer, 1, wxEXPAND, 0);
label => 'Bed Temperature',
default => '', my $log = $self->{log_textctrl} = Wx::TextCtrl->new($box, -1, "", wxDefaultPosition, wxDefaultSize,
sidetext => '°C', wxTE_MULTILINE | wxBORDER_NONE);
default => $self->config2->{bed_temperature}, $log->SetBackgroundColour($box->GetBackgroundColour);
)); $log->SetFont($Slic3r::GUI::small_font);
$line->append_button("Set", "tick.png", sub { $log->SetEditable(0);
if (!looks_like_number($self->config2->{bed_temperature})) { $sbsizer->Add($self->{log_textctrl}, 1, wxEXPAND, 0);
Slic3r::GUI::show_error($self, "Invalid bed temperature.");
return; my $cmd_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
} my $cmd_textctrl = Wx::TextCtrl->new($box, -1, '');
my $cmd = $self->writer->set_bed_temperature($self->config2->{bed_temperature}); $cmd_sizer->Add($cmd_textctrl, 1, wxEXPAND, 0);
$self->sender->send($cmd, 1);
my $btn = Wx::Button->new($box, -1,
"Send", 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->("cog_go.png"), wxBITMAP_TYPE_PNG));
}
$cmd_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 5);
EVT_BUTTON($box, $btn, sub {
return if $cmd_textctrl->GetValue eq '';
$self->sender->send($cmd_textctrl->GetValue, 1);
$cmd_textctrl->SetValue('');
}); });
$optgroup->append_line($line);
$sbsizer->Add($cmd_sizer, 0, wxEXPAND | wxTOP, 2);
} }
my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
$main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10); my $main_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); $main_sizer->Add($left_sizer, 1, wxEXPAND | wxRIGHT, 10);
#$main_sizer->Add($self->CreateButtonSizer(wxCLOSE), 0, wxEXPAND); $main_sizer->Add($right_sizer, 0, wxEXPAND, 0);
#EVT_BUTTON($self, wxID_CLOSE, sub { $self->Close });
$self->SetSizer($main_sizer); $self->SetSizer($main_sizer);
$self->SetMinSize($self->GetSize); $self->SetMinSize($self->GetSize);
#$main_sizer->SetSizeHints($self); $main_sizer->SetSizeHints($self);
$self->Layout; $self->Layout;
# needed to actually free memory # needed to actually free memory
@ -191,6 +239,12 @@ sub new {
return $self; return $self;
} }
sub update_log {
my ($self, $log) = @_;
$self->{log_textctrl}->SetValue($log);
}
sub abs_xy_move { sub abs_xy_move {
my ($self, $pos) = @_; my ($self, $pos) = @_;

View File

@ -44,6 +44,8 @@ sub new {
} }
} }
$self->{log_textctrl}->AppendText("$_\n") for @{$self->sender->purge_log}; $self->{log_textctrl}->AppendText("$_\n") for @{$self->sender->purge_log};
$self->{manual_control_dialog}->update_log($self->{log_textctrl}->GetValue)
if $self->{manual_control_dialog};
{ {
my $temp = $self->sender->getT; my $temp = $self->sender->getT;
if ($temp eq '') { if ($temp eq '') {
@ -176,9 +178,10 @@ sub new {
$btn->Hide; $btn->Hide;
$left_sizer->Add($btn, 0, wxTOP, 15); $left_sizer->Add($btn, 0, wxTOP, 15);
EVT_BUTTON($self, $btn, sub { EVT_BUTTON($self, $btn, sub {
my $dlg = Slic3r::GUI::Controller::ManualControlDialog->new $self->{manual_control_dialog} = my $dlg = Slic3r::GUI::Controller::ManualControlDialog->new
($self, $self->config, $self->sender, $self->manual_control_config); ($self, $self->config, $self->sender, $self->manual_control_config);
$dlg->ShowModal; $dlg->ShowModal;
undef $self->{manual_control_dialog};
}); });
} }
@ -285,7 +288,7 @@ sub _update_connection_controls {
$self->{btn_manual_control}->Hide; $self->{btn_manual_control}->Hide;
$self->{btn_manual_control}->Disable; $self->{btn_manual_control}->Disable;
if ($self->is_connected || 1) { if ($self->is_connected) {
$self->{btn_connect}->Hide; $self->{btn_connect}->Hide;
$self->{btn_manual_control}->Show; $self->{btn_manual_control}->Show;
if (!$self->printing || $self->printing->paused) { if (!$self->printing || $self->printing->paused) {