Prepared callback from c++ to Perl to inform about a change of object settings

This commit is contained in:
YuSanka 2018-06-12 19:15:03 +02:00
parent 6b56f99df7
commit f5ef672815
5 changed files with 64 additions and 14 deletions

View File

@ -27,6 +27,8 @@ our $VALUE_CHANGE_EVENT = Wx::NewEventType;
our $PRESETS_CHANGED_EVENT = Wx::NewEventType; our $PRESETS_CHANGED_EVENT = Wx::NewEventType;
# 3) To inform about a change of object selection # 3) To inform about a change of object selection
our $OBJECT_SELECTION_CHANGED_EVENT = Wx::NewEventType; our $OBJECT_SELECTION_CHANGED_EVENT = Wx::NewEventType;
# 4) To inform about a change of object settings
our $OBJECT_SETTINGS_CHANGED_EVENT = Wx::NewEventType;
sub new { sub new {
my ($class, %params) = @_; my ($class, %params) = @_;
@ -117,6 +119,7 @@ sub _init_tabpanel {
if (!$self->{no_plater}) { if (!$self->{no_plater}) {
$panel->AddPage($self->{plater} = Slic3r::GUI::Plater->new($panel, $panel->AddPage($self->{plater} = Slic3r::GUI::Plater->new($panel,
event_object_selection_changed => $OBJECT_SELECTION_CHANGED_EVENT, event_object_selection_changed => $OBJECT_SELECTION_CHANGED_EVENT,
event_object_settings_changed => $OBJECT_SETTINGS_CHANGED_EVENT,
), L("Plater")); ), L("Plater"));
if (!$self->{no_controller}) { if (!$self->{no_controller}) {
$panel->AddPage($self->{controller} = Slic3r::GUI::Controller->new($panel), L("Controller")); $panel->AddPage($self->{controller} = Slic3r::GUI::Controller->new($panel), L("Controller"));
@ -173,14 +176,25 @@ sub _init_tabpanel {
} }
}); });
# The following event is emited by the C++ Tab implementation on config value change. # The following event is emited by the C++ Tab implementation on object selection change.
EVT_COMMAND($self, -1, $OBJECT_SELECTION_CHANGED_EVENT, sub { EVT_COMMAND($self, -1, $OBJECT_SELECTION_CHANGED_EVENT, sub {
my ($self, $event) = @_; my ($self, $event) = @_;
my $obj_idx = $event->GetInt; my $obj_idx = $event->GetInt;
$self->{plater}->select_object($obj_idx < 0 ? undef: $obj_idx); $self->{plater}->select_object($obj_idx < 0 ? undef: $obj_idx);
$self->{plater}->item_changed_selection($obj_idx); $self->{plater}->item_changed_selection($obj_idx);
}); });
# The following event is emited by the C++ Tab implementation on object settings change.
EVT_COMMAND($self, -1, $OBJECT_SETTINGS_CHANGED_EVENT, sub {
my ($self, $event) = @_;
my $obj_idx = $event->GetInt;
#my $line = $event->GetString;
#my ($parts_changed, $part_settings_changed) = split('',$line);
#$self->{plater}->changed_object_settings($obj_idx, $parts_changed, $part_settings_changed);
});
Slic3r::GUI::create_preset_tabs($self->{no_controller}, $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT); Slic3r::GUI::create_preset_tabs($self->{no_controller}, $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT);

View File

@ -56,6 +56,7 @@ sub new {
# store input params # store input params
$self->{event_object_selection_changed} = $params{event_object_selection_changed}; $self->{event_object_selection_changed} = $params{event_object_selection_changed};
$self->{event_object_settings_changed} = $params{event_object_settings_changed};
# C++ Slic3r::Model with Perl extensions in Slic3r/Model.pm # C++ Slic3r::Model with Perl extensions in Slic3r/Model.pm
$self->{model} = Slic3r::Model->new; $self->{model} = Slic3r::Model->new;
@ -398,13 +399,15 @@ sub new {
Slic3r::GUI::add_frequently_changed_parameters($self->{right_panel}, $frequently_changed_parameters_sizer, $presets); Slic3r::GUI::add_frequently_changed_parameters($self->{right_panel}, $frequently_changed_parameters_sizer, $presets);
my $expert_mode_part_sizer = Wx::BoxSizer->new(wxVERTICAL); my $expert_mode_part_sizer = Wx::BoxSizer->new(wxVERTICAL);
Slic3r::GUI::add_expert_mode_part($self->{right_panel}, $expert_mode_part_sizer, $self->{event_object_selection_changed}); Slic3r::GUI::add_expert_mode_part( $self->{right_panel}, $expert_mode_part_sizer,
if ($expert_mode_part_sizer->IsShown(2)==1) $self->{event_object_selection_changed},
{ $self->{event_object_settings_changed});
$expert_mode_part_sizer->Layout; # if ($expert_mode_part_sizer->IsShown(2)==1)
$expert_mode_part_sizer->Show(2, 0); # ? Why doesn't work # {
$self->{right_panel}->Layout; # $expert_mode_part_sizer->Layout;
} # $expert_mode_part_sizer->Show(2, 0); # ? Why doesn't work
# $self->{right_panel}->Layout;
# }
my $object_info_sizer; my $object_info_sizer;
{ {
@ -1960,6 +1963,29 @@ sub object_settings_dialog {
} }
} }
sub changed_object_settings {
my ($self, $obj_idx, $parts_changed, $part_settings_changed) = @_;
# update thumbnail since parts may have changed
if ($parts_changed) {
# recenter and re-align to Z = 0
my $model_object = $self->{model}->objects->[$obj_idx];
$model_object->center_around_origin;
$self->reset_thumbnail($obj_idx);
}
# update print
if ($parts_changed || $part_settings_changed) {
$self->stop_background_process;
$self->{print}->reload_object($obj_idx);
$self->schedule_background_process;
$self->{canvas}->reload_scene if $self->{canvas};
$self->{canvas3D}->reload_scene if $self->{canvas3D};
} else {
$self->resume_background_process;
}
}
# Called to update various buttons depending on whether there are any objects or # Called to update various buttons depending on whether there are any objects or
# whether background processing (export of a G-code, sending to Octoprint, forced background re-slicing) is active. # whether background processing (export of a G-code, sending to Octoprint, forced background re-slicing) is active.
sub object_list_changed { sub object_list_changed {

View File

@ -143,6 +143,7 @@ wxDataViewCtrl *m_objects_ctrl = nullptr;
MyObjectTreeModel *m_objects_model = nullptr; MyObjectTreeModel *m_objects_model = nullptr;
wxCollapsiblePane *m_collpane_settings = nullptr; wxCollapsiblePane *m_collpane_settings = nullptr;
int m_event_object_selection_changed = 0; int m_event_object_selection_changed = 0;
int m_event_object_settings_changed = 0;
bool g_prevent_list_events = false; // We use this flag to avoid circular event handling Select() bool g_prevent_list_events = false; // We use this flag to avoid circular event handling Select()
// happens to fire a wxEVT_LIST_ITEM_SELECTED on OSX, whose event handler // happens to fire a wxEVT_LIST_ITEM_SELECTED on OSX, whose event handler
// calls this method again and again and again // calls this method again and again and again
@ -1163,9 +1164,12 @@ void select_current_object(int idx)
} }
} }
void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer, int event_object_selection_changed) void add_expert_mode_part( wxWindow* parent, wxBoxSizer* sizer,
int event_object_selection_changed,
int event_object_settings_changed)
{ {
m_event_object_selection_changed = event_object_selection_changed; m_event_object_selection_changed = event_object_selection_changed;
m_event_object_settings_changed = event_object_settings_changed;
wxWindowUpdateLocker noUpdates(parent); wxWindowUpdateLocker noUpdates(parent);
// *** Objects List *** // *** Objects List ***

View File

@ -202,7 +202,9 @@ void unselect_objects();
// Select current object in the list on c++ side // Select current object in the list on c++ side
void select_current_object(int idx); void select_current_object(int idx);
void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer, int event_object_selection_changed); void add_expert_mode_part( wxWindow* parent, wxBoxSizer* sizer,
int event_object_selection_changed,
int event_object_settings_changed);
void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer); void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer);
// Update view mode according to selected menu // Update view mode according to selected menu
void update_mode(); void update_mode();

View File

@ -83,9 +83,13 @@ void add_frequently_changed_parameters(SV *ui_parent, SV *ui_sizer, SV *ui_p_siz
(wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer"), (wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer"),
(wxFlexGridSizer*)wxPli_sv_2_object(aTHX_ ui_p_sizer, "Wx::FlexGridSizer")); %}; (wxFlexGridSizer*)wxPli_sv_2_object(aTHX_ ui_p_sizer, "Wx::FlexGridSizer")); %};
void add_expert_mode_part(SV *ui_parent, SV *ui_sizer, int event) void add_expert_mode_part( SV *ui_parent, SV *ui_sizer,
%code%{ Slic3r::GUI::add_expert_mode_part((wxWindow*)wxPli_sv_2_object(aTHX_ ui_parent, "Wx::Window"), int event_object_selection_changed,
(wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer"), event); %}; int event_object_settings_changed)
%code%{ Slic3r::GUI::add_expert_mode_part( (wxWindow*)wxPli_sv_2_object(aTHX_ ui_parent, "Wx::Window"),
(wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer"),
event_object_selection_changed,
event_object_settings_changed); %};
void set_objects_from_perl( SV *ui_parent, void set_objects_from_perl( SV *ui_parent,
SV *frequently_changed_parameters_sizer, SV *frequently_changed_parameters_sizer,