From 97231327e0da0de81186763e03b6eab02594f662 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 12 Jun 2014 09:29:26 +0200 Subject: [PATCH] Have Print::apply_config() return true if any step was invalidated --- lib/Slic3r/Print.pm | 18 +++++++++++++++--- xs/src/Print.cpp | 4 +++- xs/src/Print.hpp | 2 +- xs/xsp/Print.xsp | 8 ++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 838e0e74..c9853a1a 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -43,13 +43,17 @@ sub apply_config { # apply variables to placeholder parser $self->placeholder_parser->apply_config($config); + my $invalidated = 0; + # handle changes to print config my $print_diff = $self->config->diff($config); if (@$print_diff) { $self->config->apply_dynamic($config); - $self->invalidate_all_steps + my $res; + $res = $self->invalidate_all_steps if !$self->invalidate_state_by_config_options($print_diff); + $invalidated = 1 if $res; } # handle changes to object config defaults @@ -69,8 +73,11 @@ sub apply_config { my $diff = $object->config->diff($new); if (@$diff) { $object->config->apply($new); - $object->invalidate_all_steps + + my $res; + $res = $object->invalidate_all_steps if !$object->invalidate_state_by_config_options($diff); + $invalidated = 1 if $res; } } @@ -124,8 +131,10 @@ sub apply_config { if (@$region_config_diff) { $region->config->apply($new); foreach my $o (@{$self->objects}) { - $o->invalidate_all_steps + my $res; + $res = $o->invalidate_all_steps if !$o->invalidate_state_by_config_options($region_config_diff); + $invalidated = 1 if $res; } } } @@ -139,7 +148,10 @@ sub apply_config { my @model_objects = map $_->model_object, @{$self->objects}; $self->clear_objects; $self->add_model_object($_) for @model_objects; + $invalidated = 1; } + + return $invalidated; } sub has_support_material { diff --git a/xs/src/Print.cpp b/xs/src/Print.cpp index 74cbfa5c..4afb1627 100644 --- a/xs/src/Print.cpp +++ b/xs/src/Print.cpp @@ -40,11 +40,13 @@ PrintState::invalidate(StepClass step) } template -void +bool PrintState::invalidate_all() { + bool empty = this->_started.empty(); this->_started.clear(); this->_done.clear(); + return !empty; // return true if we invalidated something } template class PrintState; diff --git a/xs/src/Print.hpp b/xs/src/Print.hpp index c5590277..de9fad73 100644 --- a/xs/src/Print.hpp +++ b/xs/src/Print.hpp @@ -36,7 +36,7 @@ class PrintState void set_started(StepType step); void set_done(StepType step); void invalidate(StepType step); - void invalidate_all(); + bool invalidate_all(); }; // A PrintRegion object represents a group of volumes to print diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 6a69dcc8..6510cd38 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -87,8 +87,8 @@ _constant() bool invalidate_state_by_config_options(std::vector opt_keys); void invalidate_step(PrintObjectStep step); - void invalidate_all_steps() - %code%{ THIS->state.invalidate_all(); %}; + bool invalidate_all_steps() + %code%{ RETVAL = THIS->state.invalidate_all(); %}; bool step_done(PrintObjectStep step) %code%{ RETVAL = THIS->state.done(step); %}; void set_step_done(PrintObjectStep step) @@ -142,8 +142,8 @@ _constant() bool invalidate_state_by_config_options(std::vector opt_keys); void invalidate_step(PrintStep step); - void invalidate_all_steps() - %code%{ THIS->state.invalidate_all(); %}; + bool invalidate_all_steps() + %code%{ RETVAL = THIS->state.invalidate_all(); %}; bool step_done(PrintStep step) %code%{ RETVAL = THIS->state.done(step); %}; void set_step_done(PrintStep step)