From b1f5e7e8fa9713066c909c86ac4bf4f5d719b56e Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 14 Feb 2018 20:35:59 +0100 Subject: [PATCH] Removed the GCodePreviewData from the Print class, it does not belong here, as the GCode is generated outside of the Print class. Exported the GCodePreviewData as GCode::PreviewData to Perl. When exporting the G-code with a command line Slic3r, the GCodeAnalyzer is now supressed for performance reasons. Removed obsolete Perl module Slic3r::GUI::Plater::3DToolpaths. --- lib/Slic3r.pm | 1 + lib/Slic3r/GUI/3DScene.pm | 6 +- lib/Slic3r/GUI/Plater.pm | 11 +- lib/Slic3r/GUI/Plater/3DPreview.pm | 21 ++-- lib/Slic3r/GUI/Plater/3DToolpaths.pm | 159 --------------------------- lib/Slic3r/Print.pm | 2 +- xs/src/libslic3r/GCode.cpp | 10 +- xs/src/libslic3r/GCode.hpp | 9 +- xs/src/libslic3r/GCode/Analyzer.cpp | 47 ++++---- xs/src/libslic3r/GCode/Analyzer.hpp | 12 +- xs/src/libslic3r/Print.cpp | 83 -------------- xs/src/libslic3r/Print.hpp | 23 ---- xs/src/perlglue.cpp | 1 + xs/src/slic3r/GUI/3DScene.cpp | 109 +++++++++--------- xs/src/slic3r/GUI/3DScene.hpp | 25 +++-- xs/xsp/GCode.xsp | 27 ++++- xs/xsp/GUI_3DScene.xsp | 5 +- xs/xsp/Print.xsp | 9 -- xs/xsp/my.map | 4 + xs/xsp/typemap.xspt | 3 + 20 files changed, 166 insertions(+), 401 deletions(-) delete mode 100644 lib/Slic3r/GUI/Plater/3DToolpaths.pm diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 66039ddf0..30d516217 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -136,6 +136,7 @@ sub thread_cleanup { *Slic3r::Flow::DESTROY = sub {}; *Slic3r::GCode::DESTROY = sub {}; *Slic3r::GCode::PlaceholderParser::DESTROY = sub {}; + *Slic3r::GCode::PreviewData::DESTROY = sub {}; *Slic3r::GCode::Sender::DESTROY = sub {}; *Slic3r::Geometry::BoundingBox::DESTROY = sub {}; *Slic3r::Geometry::BoundingBoxf::DESTROY = sub {}; diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index f63dad079..03055a582 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -4,7 +4,7 @@ # Slic3r::GUI::3DScene; # # Slic3r::GUI::Plater::3D derives from Slic3r::GUI::3DScene, -# Slic3r::GUI::Plater::3DPreview, Slic3r::GUI::Plater::3DToolpaths, +# Slic3r::GUI::Plater::3DPreview, # Slic3r::GUI::Plater::ObjectCutDialog and Slic3r::GUI::Plater::ObjectPartsPanel # own $self->{canvas} of the Slic3r::GUI::3DScene type. # @@ -2029,10 +2029,10 @@ sub load_wipe_tower_toolpaths { } sub load_gcode_preview { - my ($self, $print, $colors) = @_; + my ($self, $print, $gcode_preview_data, $colors) = @_; $self->SetCurrent($self->GetContext) if $self->UseVBOs; - Slic3r::GUI::_3DScene::load_gcode_preview($print, $self->volumes, $colors, $self->UseVBOs); + Slic3r::GUI::_3DScene::load_gcode_preview($print, $gcode_preview_data, $self->volumes, $colors, $self->UseVBOs); } sub set_toolpaths_range { diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index ba59e89be..17a39184d 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -60,6 +60,7 @@ sub new { $self->{print} = Slic3r::Print->new; # List of Perl objects Slic3r::GUI::Plater::Object, representing a 2D preview of the platter. $self->{objects} = []; + $self->{gcode_preview_data} = Slic3r::GCode::PreviewData->new; $self->{print}->set_status_cb(sub { my ($percent, $message) = @_; @@ -140,7 +141,7 @@ sub new { # Initialize 3D toolpaths preview if ($Slic3r::GUI::have_OpenGL) { - $self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print}, $self->{config}); + $self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print}, $self->{gcode_preview_data}, $self->{config}); $self->{preview3D}->canvas->on_viewport_changed(sub { $self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas); }); @@ -785,7 +786,7 @@ sub remove { splice @{$self->{objects}}, $obj_idx, 1; $self->{model}->delete_object($obj_idx); $self->{print}->delete_object($obj_idx); - $self->{print}->clear_gcode_preview_data; + $self->{gcode_preview_data}->reset; $self->{list}->DeleteItem($obj_idx); $self->object_list_changed; @@ -806,7 +807,7 @@ sub reset { @{$self->{objects}} = (); $self->{model}->clear_objects; $self->{print}->clear_objects; - $self->{print}->clear_gcode_preview_data; + $self->{gcode_preview_data}->reset; $self->{list}->DeleteAllItems; $self->object_list_changed; @@ -1267,7 +1268,7 @@ sub reslice { # Rather perform one additional unnecessary update of the print object instead of skipping a pending async update. $self->async_apply_config; # Reset gcode data - $self->{print}->clear_gcode_preview_data; + $self->{gcode_preview_data}->reset; $self->statusbar->SetCancelCallback(sub { $self->stop_background_process; $self->statusbar->SetStatusText("Slicing cancelled"); @@ -1381,7 +1382,7 @@ sub on_process_completed { $self->{export_thread} = Slic3r::spawn_thread(sub { eval { - $_thread_self->{print}->export_gcode(output_file => $_thread_self->{export_gcode_output_file}); + $_thread_self->{print}->export_gcode(output_file => $_thread_self->{export_gcode_output_file}, gcode_preview_data => $_thread_self->{gcode_preview_data}); }; my $export_completed_event = Wx::CommandEvent->new($EXPORT_COMPLETED_EVENT); if ($@) { diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index 6f96b8a96..10232b31d 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -8,11 +8,11 @@ use Wx qw(:misc :sizer :slider :statictext :keycode wxWHITE wxCB_READONLY); use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX EVT_CHOICE EVT_CHECKLISTBOX); use base qw(Wx::Panel Class::Accessor); -__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider_low slider_high single_layer auto_zoom)); +__PACKAGE__->mk_accessors(qw(print gcode_preview_data enabled _loaded canvas slider_low slider_high single_layer auto_zoom)); sub new { my $class = shift; - my ($parent, $print, $config) = @_; + my ($parent, $print, $gcode_preview_data, $config) = @_; my $self = $class->SUPER::new($parent, -1, wxDefaultPosition); $self->{config} = $config; @@ -192,7 +192,7 @@ sub new { }); EVT_CHOICE($self, $choice_view_type, sub { my $selection = $choice_view_type->GetCurrentSelection(); - $self->print->set_gcode_preview_type($selection); + $self->gcode_preview_data->set_type($selection); $self->auto_zoom(0); $self->reload_print; $self->auto_zoom(1); @@ -200,31 +200,31 @@ sub new { EVT_CHECKLISTBOX($self, $combochecklist_features, sub { my $flags = Slic3r::GUI::combochecklist_get_flags($combochecklist_features); - $self->print->set_gcode_preview_extrusion_flags($flags); + $self->gcode_preview_data->set_extrusion_flags($flags); $self->auto_zoom(0); $self->refresh_print; $self->auto_zoom(1); }); EVT_CHECKBOX($self, $checkbox_travel, sub { - $self->print->set_gcode_preview_travel_visible($checkbox_travel->IsChecked()); + $self->gcode_preview_data->set_travel_visible($checkbox_travel->IsChecked()); $self->auto_zoom(0); $self->refresh_print; $self->auto_zoom(1); }); EVT_CHECKBOX($self, $checkbox_retractions, sub { - $self->print->set_gcode_preview_retractions_visible($checkbox_retractions->IsChecked()); + $self->gcode_preview_data->set_retractions_visible($checkbox_retractions->IsChecked()); $self->auto_zoom(0); $self->refresh_print; $self->auto_zoom(1); }); EVT_CHECKBOX($self, $checkbox_unretractions, sub { - $self->print->set_gcode_preview_unretractions_visible($checkbox_unretractions->IsChecked()); + $self->gcode_preview_data->set_unretractions_visible($checkbox_unretractions->IsChecked()); $self->auto_zoom(0); $self->refresh_print; $self->auto_zoom(1); }); EVT_CHECKBOX($self, $checkbox_shells, sub { - $self->print->set_gcode_preview_shells_visible($checkbox_shells->IsChecked()); + $self->gcode_preview_data->set_shells_visible($checkbox_shells->IsChecked()); $self->auto_zoom(0); $self->refresh_print; $self->auto_zoom(1); @@ -236,6 +236,7 @@ sub new { # init canvas $self->print($print); + $self->gcode_preview_data($gcode_preview_data); # sets colors for gcode preview extrusion roles my @extrusion_roles_colors = ( @@ -252,7 +253,7 @@ sub new { 'Support material interface' => '00007F', 'Wipe tower' => 'B3E3AB', ); - $self->print->set_gcode_extrusion_paths_colors(\@extrusion_roles_colors); + $self->gcode_preview_data->set_extrusion_paths_colors(\@extrusion_roles_colors); $self->reload_print; @@ -354,7 +355,7 @@ sub load_print { } if ($self->IsShown) { - $self->canvas->load_gcode_preview($self->print, \@colors); + $self->canvas->load_gcode_preview($self->print, $self->gcode_preview_data, \@colors); # # load skirt and brim # $self->canvas->load_print_toolpaths($self->print, \@colors); diff --git a/lib/Slic3r/GUI/Plater/3DToolpaths.pm b/lib/Slic3r/GUI/Plater/3DToolpaths.pm deleted file mode 100644 index 776d8217b..000000000 --- a/lib/Slic3r/GUI/Plater/3DToolpaths.pm +++ /dev/null @@ -1,159 +0,0 @@ -package Slic3r::GUI::Plater::3DToolpaths; -use strict; -use warnings; -use utf8; - -use Slic3r::Print::State ':steps'; -use Wx qw(:misc :sizer :slider :statictext wxWHITE); -use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN); -use base qw(Wx::Panel Class::Accessor); - -__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider)); - -sub new { - my $class = shift; - my ($parent, $print) = @_; - - my $self = $class->SUPER::new($parent, -1, wxDefaultPosition); - - # init GUI elements - my $canvas = Slic3r::GUI::3DScene->new($self); - $self->canvas($canvas); - my $slider = Wx::Slider->new( - $self, -1, - 0, # default - 0, # min - # we set max to a bogus non-zero value because the MSW implementation of wxSlider - # will skip drawing the slider if max <= min: - 1, # max - wxDefaultPosition, - wxDefaultSize, - wxVERTICAL | wxSL_INVERSE, - ); - $self->slider($slider); - - my $z_label = $self->{z_label} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, - [40,-1], wxALIGN_CENTRE_HORIZONTAL); - $z_label->SetFont($Slic3r::GUI::small_font); - - my $vsizer = Wx::BoxSizer->new(wxVERTICAL); - $vsizer->Add($slider, 1, wxALL | wxEXPAND | wxALIGN_CENTER, 3); - $vsizer->Add($z_label, 0, wxALL | wxEXPAND | wxALIGN_CENTER, 3); - - my $sizer = Wx::BoxSizer->new(wxHORIZONTAL); - $sizer->Add($canvas, 1, wxALL | wxEXPAND, 0); - $sizer->Add($vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5); - - EVT_SLIDER($self, $slider, sub { - $self->set_z($self->{layers_z}[$slider->GetValue]) - if $self->enabled; - }); - EVT_KEY_DOWN($canvas, sub { - my ($s, $event) = @_; - if ($event->HasModifiers) { - $event->Skip; - } else { - my $key = $event->GetKeyCode; - if ($key == 85 || $key == 315) { - $slider->SetValue($slider->GetValue + 1); - $self->set_z($self->{layers_z}[$slider->GetValue]); - } elsif ($key == 68 || $key == 317) { - $slider->SetValue($slider->GetValue - 1); - $self->set_z($self->{layers_z}[$slider->GetValue]); - } else { - $event->Skip; - } - } - }); - - $self->SetSizer($sizer); - $self->SetMinSize($self->GetSize); - $sizer->SetSizeHints($self); - - # init canvas - $self->print($print); - $self->reload_print; - - return $self; -} - -sub reload_print { - my ($self) = @_; - - $self->canvas->reset_objects; - $self->_loaded(0); - $self->load_print; -} - -sub load_print { - my ($self) = @_; - - return if $self->_loaded; - - # we require that there's at least one object and the posSlice step - # is performed on all of them (this ensures that _shifted_copies was - # populated and we know the number of layers) - if (!$self->print->object_step_done(STEP_SLICE)) { - $self->enabled(0); - $self->slider->Hide; - $self->canvas->Refresh; # clears canvas - return; - } - - my $z_idx; - { - my %z = (); # z => 1 - foreach my $object (@{$self->{print}->objects}) { - foreach my $layer (@{$object->layers}, @{$object->support_layers}) { - $z{$layer->print_z} = 1; - } - } - $self->enabled(1); - $self->{layers_z} = [ sort { $a <=> $b } keys %z ]; - $self->slider->SetRange(0, scalar(@{$self->{layers_z}})-1); - if (($z_idx = $self->slider->GetValue) <= $#{$self->{layers_z}} && $self->slider->GetValue != 0) { - # use $z_idx - } else { - $self->slider->SetValue(scalar(@{$self->{layers_z}})-1); - $z_idx = @{$self->{layers_z}} ? -1 : undef; - } - $self->slider->Show; - $self->Layout; - } - - if ($self->IsShown) { - $self->canvas->load_gcode_preview($self->print); - -# # load skirt and brim -# $self->canvas->load_print_toolpaths($self->print); -# -# foreach my $object (@{$self->print->objects}) { -# $self->canvas->load_print_object_toolpaths($object); -# -# # Show the objects in very transparent color. -# #my @volume_ids = $self->canvas->load_object($object->model_object); -# #$self->canvas->volumes->[$_]->color->[3] = 0.2 for @volume_ids; -# } - - $self->canvas->zoom_to_volumes; - $self->_loaded(1); - } - - $self->set_z($self->{layers_z}[$z_idx]); -} - -sub set_z { - my ($self, $z) = @_; - - return if !$self->enabled; - $self->{z_label}->SetLabel(sprintf '%.2f', $z); - $self->canvas->set_toolpaths_range(0, $z); - $self->canvas->Refresh if $self->IsShown; -} - -sub set_bed_shape { - my ($self, $bed_shape) = @_; - $self->canvas->set_bed_shape($bed_shape); -} - -1; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 12ad2f12f..4d112536a 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -81,7 +81,7 @@ sub export_gcode { $self->status_cb->(90, "Exporting G-code" . ($output_file ? " to $output_file" : "")); # The following line may die for multiple reasons. - Slic3r::GCode->new->do_export($self, $output_file); + Slic3r::GCode->new->do_export($self, $output_file, $params{gcode_preview_data}); # run post-processing scripts if (@{$self->config->post_process}) { diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index c256268e5..8c14b4adb 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -348,7 +348,7 @@ std::vector>> GCode::collec return layers_to_print; } -void GCode::do_export(Print *print, const char *path) +void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_data) { PROFILE_CLEAR(); @@ -363,7 +363,7 @@ void GCode::do_export(Print *print, const char *path) throw std::runtime_error(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n"); this->m_placeholder_parser_failed_templates.clear(); - this->_do_export(*print, file); + this->_do_export(*print, file, preview_data); fflush(file); if (ferror(file)) { fclose(file); @@ -394,7 +394,7 @@ void GCode::do_export(Print *print, const char *path) PROFILE_OUTPUT(debug_out_path("gcode-export-profile.txt").c_str()); } -void GCode::_do_export(Print &print, FILE *file) +void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) { PROFILE_FUNC(); @@ -404,6 +404,7 @@ void GCode::_do_export(Print &print, FILE *file) // resets analyzer m_analyzer.reset(); + m_enable_analyzer = preview_data != nullptr; // resets analyzer's tracking data m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm; @@ -820,7 +821,8 @@ void GCode::_do_export(Print &print, FILE *file) } // starts analizer calculations - m_analyzer.calc_gcode_preview_data(print); + if (preview_data != nullptr) + m_analyzer.calc_gcode_preview_data(*preview_data); } std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override) diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index 6e42c52d0..f35f2d5e9 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -26,6 +26,7 @@ namespace Slic3r { // Forward declarations. class GCode; +class GCodePreviewData; class AvoidCrossingPerimeters { public: @@ -119,7 +120,7 @@ public: m_enable_loop_clipping(true), m_enable_cooling_markers(false), m_enable_extrusion_role_markers(false), - m_enable_analyzer(true), + m_enable_analyzer(false), m_layer_count(0), m_layer_index(-1), m_layer(nullptr), @@ -136,7 +137,7 @@ public: ~GCode() {} // throws std::runtime_exception - void do_export(Print *print, const char *path); + void do_export(Print *print, const char *path, GCodePreviewData *preview_data = nullptr); // Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests. const Pointf& origin() const { return m_origin; } @@ -153,8 +154,6 @@ public: // inside the generated string and after the G-code export finishes. std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override = nullptr); bool enable_cooling_markers() const { return m_enable_cooling_markers; } - bool enable_analyzer() const { return m_enable_analyzer; } - void enable_analyzer(bool enable) { m_enable_analyzer = enable; } // For Perl bindings, to be used exclusively by unit tests. unsigned int layer_count() const { return m_layer_count; } @@ -162,7 +161,7 @@ public: void apply_print_config(const PrintConfig &print_config); protected: - void _do_export(Print &print, FILE *file); + void _do_export(Print &print, FILE *file, GCodePreviewData *preview_data); // Object and support extrusions of the same PrintObject at the same print_z. struct LayerToPrint diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 938f0371d..f8d196f23 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -123,22 +123,22 @@ const std::string& GCodeAnalyzer::process_gcode(const std::string& gcode) return m_process_output; } -void GCodeAnalyzer::calc_gcode_preview_data(Print& print) +void GCodeAnalyzer::calc_gcode_preview_data(GCodePreviewData& preview_data) { // resets preview data - print.gcode_preview.reset(); + preview_data.reset(); // calculates extrusion layers - _calc_gcode_preview_extrusion_layers(print); + _calc_gcode_preview_extrusion_layers(preview_data); // calculates travel - _calc_gcode_preview_travel(print); + _calc_gcode_preview_travel(preview_data); // calculates retractions - _calc_gcode_preview_retractions(print); + _calc_gcode_preview_retractions(preview_data); // calculates unretractions - _calc_gcode_preview_unretractions(print); + _calc_gcode_preview_unretractions(preview_data); } bool GCodeAnalyzer::is_valid_extrusion_role(ExtrusionRole role) @@ -601,7 +601,7 @@ bool GCodeAnalyzer::_is_valid_extrusion_role(int value) const return ((int)erNone <= value) && (value <= (int)erMixed); } -void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) +void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& preview_data) { struct Helper { @@ -619,7 +619,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) return layers.back(); } - static void store_polyline(const Polyline& polyline, const Metadata& data, float z, Print& print) + static void store_polyline(const Polyline& polyline, const Metadata& data, float z, GCodePreviewData& preview_data) { // if the polyline is valid, create the extrusion path from it and store it if (polyline.is_valid()) @@ -629,7 +629,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) path.feedrate = data.feedrate; path.extruder_id = data.extruder_id; - get_layer_at_z(print.gcode_preview.extrusion.layers, z).paths.push_back(path); + get_layer_at_z(preview_data.extrusion.layers, z).paths.push_back(path); } } }; @@ -653,7 +653,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) { // store current polyline polyline.remove_duplicate_points(); - Helper::store_polyline(polyline, data, z, print); + Helper::store_polyline(polyline, data, z, preview_data); // reset current polyline polyline = Polyline(); @@ -679,23 +679,24 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) // store last polyline polyline.remove_duplicate_points(); - Helper::store_polyline(polyline, data, z, print); + Helper::store_polyline(polyline, data, z, preview_data); // updates preview ranges data - print.gcode_preview.extrusion.ranges.height.set_from(height_range); - print.gcode_preview.extrusion.ranges.width.set_from(width_range); - print.gcode_preview.extrusion.ranges.feedrate.set_from(feedrate_range); + preview_data.extrusion.ranges.height.set_from(height_range); + preview_data.extrusion.ranges.width.set_from(width_range); + preview_data.extrusion.ranges.feedrate.set_from(feedrate_range); } -void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print) +void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) { struct Helper { - static void store_polyline(const Polyline3& polyline, GCodePreviewData::Travel::EType type, GCodePreviewData::Travel::Polyline::EDirection direction, float feedrate, unsigned int extruder_id, Print& print) + static void store_polyline(const Polyline3& polyline, GCodePreviewData::Travel::EType type, GCodePreviewData::Travel::Polyline::EDirection direction, + float feedrate, unsigned int extruder_id, GCodePreviewData& preview_data) { // if the polyline is valid, store it if (polyline.is_valid()) - print.gcode_preview.travel.polylines.emplace_back(type, direction, feedrate, extruder_id, polyline); + preview_data.travel.polylines.emplace_back(type, direction, feedrate, extruder_id, polyline); } }; @@ -720,7 +721,7 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print) { // store current polyline polyline.remove_duplicate_points(); - Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, print); + Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data); // reset current polyline polyline = Polyline3(); @@ -742,10 +743,10 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print) // store last polyline polyline.remove_duplicate_points(); - Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, print); + Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data); } -void GCodeAnalyzer::_calc_gcode_preview_retractions(Print& print) +void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_data) { TypeToMovesMap::iterator retraction_moves = m_moves_map.find(GCodeMove::Retract); if (retraction_moves == m_moves_map.end()) @@ -755,11 +756,11 @@ void GCodeAnalyzer::_calc_gcode_preview_retractions(Print& print) { // store position Point3 position(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z)); - print.gcode_preview.retraction.positions.emplace_back(position, move.data.width, move.data.height); + preview_data.retraction.positions.emplace_back(position, move.data.width, move.data.height); } } -void GCodeAnalyzer::_calc_gcode_preview_unretractions(Print& print) +void GCodeAnalyzer::_calc_gcode_preview_unretractions(GCodePreviewData& preview_data) { TypeToMovesMap::iterator unretraction_moves = m_moves_map.find(GCodeMove::Unretract); if (unretraction_moves == m_moves_map.end()) @@ -769,7 +770,7 @@ void GCodeAnalyzer::_calc_gcode_preview_unretractions(Print& print) { // store position Point3 position(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z)); - print.gcode_preview.unretraction.positions.emplace_back(position, move.data.width, move.data.height); + preview_data.unretraction.positions.emplace_back(position, move.data.width, move.data.height); } } diff --git a/xs/src/libslic3r/GCode/Analyzer.hpp b/xs/src/libslic3r/GCode/Analyzer.hpp index bfb2d668c..7939d432d 100644 --- a/xs/src/libslic3r/GCode/Analyzer.hpp +++ b/xs/src/libslic3r/GCode/Analyzer.hpp @@ -10,7 +10,7 @@ namespace Slic3r { -class Print; +class GCodePreviewData; class GCodeAnalyzer { @@ -116,7 +116,7 @@ public: const std::string& process_gcode(const std::string& gcode); // Calculates all data needed for gcode visualization - void calc_gcode_preview_data(Print& print); + void calc_gcode_preview_data(GCodePreviewData& preview_data); static bool is_valid_extrusion_role(ExtrusionRole role); @@ -216,10 +216,10 @@ private: // Checks if the given int is a valid extrusion role (contained into enum ExtrusionRole) bool _is_valid_extrusion_role(int value) const; - void _calc_gcode_preview_extrusion_layers(Print& print); - void _calc_gcode_preview_travel(Print& print); - void _calc_gcode_preview_retractions(Print& print); - void _calc_gcode_preview_unretractions(Print& print); + void _calc_gcode_preview_extrusion_layers(GCodePreviewData& preview_data); + void _calc_gcode_preview_travel(GCodePreviewData& preview_data); + void _calc_gcode_preview_retractions(GCodePreviewData& preview_data); + void _calc_gcode_preview_unretractions(GCodePreviewData& preview_data); }; } // namespace Slic3r diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 5fb81124c..c689929c6 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -66,89 +66,6 @@ bool Print::reload_model_instances() return invalidated; } -void Print::clear_gcode_preview_data() -{ - gcode_preview.reset(); -} - -void Print::set_gcode_preview_type(unsigned char type) -{ - if ((0 <= type) && (type < GCodePreviewData::Extrusion::Num_View_Types)) - gcode_preview.extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; -} - -void Print::set_gcode_preview_extrusion_flags(unsigned int flags) -{ - gcode_preview.extrusion.role_flags = flags; -} - -bool Print::is_gcode_preview_extrusion_role_enabled(ExtrusionRole role) -{ - return gcode_preview.extrusion.is_role_flag_set(role); -} - -void Print::set_gcode_preview_travel_visible(bool visible) -{ - gcode_preview.travel.is_visible = visible; -} - -void Print::set_gcode_preview_retractions_visible(bool visible) -{ - gcode_preview.retraction.is_visible = visible; -} - -void Print::set_gcode_preview_unretractions_visible(bool visible) -{ - gcode_preview.unretraction.is_visible = visible; -} - -void Print::set_gcode_preview_shells_visible(bool visible) -{ - gcode_preview.shell.is_visible = visible; -} - -void Print::set_gcode_extrusion_paths_colors(const std::vector& colors) -{ - unsigned int size = (unsigned int)colors.size(); - - if (size % 2 != 0) - return; - - for (unsigned int i = 0; i < size; i += 2) - { - const std::string& color_str = colors[i + 1]; - - if (color_str.size() == 6) - { - bool valid = true; - for (int c = 0; c < 6; ++c) - { - if (::isxdigit(color_str[c]) == 0) - { - valid = false; - break; - } - } - - if (valid) - { - unsigned int color; - std::stringstream ss; - ss << std::hex << color_str; - ss >> color; - - float den = 1.0f / 255.0f; - - float r = (float)((color & 0xFF0000) >> 16) * den; - float g = (float)((color & 0x00FF00) >> 8) * den; - float b = (float)(color & 0x0000FF) * den; - - gcode_preview.set_extrusion_role_color(colors[i], r, g, b, 1.0f); - } - } - } -} - PrintRegion* Print::add_region() { regions.push_back(new PrintRegion(this)); diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index f08b4ec15..c56e64c6c 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -15,7 +15,6 @@ #include "Slicing.hpp" #include "GCode/ToolOrdering.hpp" #include "GCode/WipeTower.hpp" -#include "GCode/PreviewData.hpp" #include "tbb/atomic.h" @@ -241,7 +240,6 @@ public: // ordered collections of extrusion paths to build skirt loops and brim ExtrusionEntityCollection skirt, brim; - GCodePreviewData gcode_preview; Print() : total_used_filament(0), total_extruded_volume(0) { restart(); } ~Print() { clear_objects(); } @@ -255,27 +253,6 @@ public: void reload_object(size_t idx); bool reload_model_instances(); - void clear_gcode_preview_data(); - void set_gcode_preview_type(unsigned char type); - void set_gcode_preview_extrusion_flags(unsigned int flags); - bool is_gcode_preview_extrusion_role_enabled(ExtrusionRole role); - void set_gcode_preview_travel_visible(bool visible); - void set_gcode_preview_retractions_visible(bool visible); - void set_gcode_preview_unretractions_visible(bool visible); - void set_gcode_preview_shells_visible(bool visible); - - // Sets the extrusion path colors from the given strings vector. - // Data in the vector should be formatted as follows: - // std::vector role_colors = - // { , , - // , , - // , , - // ... - // , }; - // where should be a string from GCodePreviewData::Extrusion::Default_Extrusion_Role_Names[] - // and an RGB color in hex format (i.e. red = FF0000) - void set_gcode_extrusion_paths_colors(const std::vector& colors); - // methods for handling regions PrintRegion* get_region(size_t idx) { return regions.at(idx); } const PrintRegion* get_region(size_t idx) const { return regions.at(idx); } diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 948fcfd93..5f3b5f691 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -15,6 +15,7 @@ REGISTER_CLASS(Filler, "Filler"); REGISTER_CLASS(Flow, "Flow"); REGISTER_CLASS(CoolingBuffer, "GCode::CoolingBuffer"); REGISTER_CLASS(GCode, "GCode"); +REGISTER_CLASS(GCodePreviewData, "GCode::PreviewData"); REGISTER_CLASS(GCodeSender, "GCode::Sender"); REGISTER_CLASS(Layer, "Layer"); REGISTER_CLASS(SupportLayer, "Layer::Support"); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index b5fc9245e..616d43496 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -6,6 +6,7 @@ #include "../../libslic3r/ExtrusionEntity.hpp" #include "../../libslic3r/ExtrusionEntityCollection.hpp" #include "../../libslic3r/Geometry.hpp" +#include "../../libslic3r/GCode/PreviewData.hpp" #include "../../libslic3r/Print.hpp" #include "../../libslic3r/Slicing.hpp" #include "GCode/Analyzer.hpp" @@ -1128,13 +1129,13 @@ _3DScene::LegendTexture::~LegendTexture() _destroy_texture(); } -bool _3DScene::LegendTexture::generate_texture(const Print& print, const std::vector& tool_colors) +bool _3DScene::LegendTexture::generate_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors) { _destroy_texture(); // collects items to render - const std::string& title = print.gcode_preview.get_legend_title(); - const GCodePreviewData::LegendItemsList& items = print.gcode_preview.get_legend_items(tool_colors); + const std::string& title = preview_data.get_legend_title(); + const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors); unsigned int items_count = (unsigned int)items.size(); if (items_count == 0) @@ -1240,7 +1241,7 @@ bool _3DScene::LegendTexture::generate_texture(const Print& print, const std::ve memDC.SelectObject(wxNullBitmap); - return _create_texture(print, bitmap); + return _create_texture(preview_data, bitmap); } unsigned int _3DScene::LegendTexture::get_texture_id() const @@ -1263,7 +1264,7 @@ void _3DScene::LegendTexture::reset_texture() _destroy_texture(); } -bool _3DScene::LegendTexture::_create_texture(const Print& print, const wxBitmap& bitmap) +bool _3DScene::LegendTexture::_create_texture(const GCodePreviewData& preview_data, const wxBitmap& bitmap) { if ((m_tex_width == 0) || (m_tex_height == 0)) return false; @@ -1341,9 +1342,9 @@ static inline std::vector parse_colors(const std::vector &sc return output; } -void _3DScene::load_gcode_preview(const Print* print, GLVolumeCollection* volumes, const std::vector& str_tool_colors, bool use_VBOs) +void _3DScene::load_gcode_preview(const Print* print, const GCodePreviewData* preview_data, GLVolumeCollection* volumes, const std::vector& str_tool_colors, bool use_VBOs) { - if ((print == nullptr) || (volumes == nullptr)) + if ((preview_data == nullptr) || (volumes == nullptr)) return; if (volumes->empty()) @@ -1352,10 +1353,10 @@ void _3DScene::load_gcode_preview(const Print* print, GLVolumeCollection* volume s_gcode_preview_volume_index.reset(); - _load_gcode_extrusion_paths(*print, *volumes, tool_colors, use_VBOs); - _load_gcode_travel_paths(*print, *volumes, tool_colors, use_VBOs); - _load_gcode_retractions(*print, *volumes, use_VBOs); - _load_gcode_unretractions(*print, *volumes, use_VBOs); + _load_gcode_extrusion_paths(*preview_data, *volumes, tool_colors, use_VBOs); + _load_gcode_travel_paths(*preview_data, *volumes, tool_colors, use_VBOs); + _load_gcode_retractions(*preview_data, *volumes, use_VBOs); + _load_gcode_unretractions(*preview_data, *volumes, use_VBOs); if (volumes->empty()) { @@ -1364,14 +1365,14 @@ void _3DScene::load_gcode_preview(const Print* print, GLVolumeCollection* volume } else { - _generate_legend_texture(*print, tool_colors); + _generate_legend_texture(*preview_data, tool_colors); _load_shells(*print, *volumes, use_VBOs); volumes->set_render_interleaved_only_volumes(GLVolumeCollection::RenderInterleavedOnlyVolumes(true, 0.25f)); } } - _update_gcode_volumes_visibility(*print, *volumes); + _update_gcode_volumes_visibility(*preview_data, *volumes); } unsigned int _3DScene::get_legend_texture_id() @@ -1751,7 +1752,7 @@ void _3DScene::_load_wipe_tower_toolpaths( BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end"; } -void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs) +void _3DScene::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs) { // helper functions to select data in dependence of the extrusion view type struct Helper @@ -1831,12 +1832,12 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio // detects filters FiltersList filters; - for (const GCodePreviewData::Extrusion::Layer& layer : print.gcode_preview.extrusion.layers) + for (const GCodePreviewData::Extrusion::Layer& layer : preview_data.extrusion.layers) { for (const ExtrusionPath& path : layer.paths) { ExtrusionRole role = path.role(); - float path_filter = Helper::path_filter(print.gcode_preview.extrusion.view_type, path); + float path_filter = Helper::path_filter(preview_data.extrusion.view_type, path); if (std::find(filters.begin(), filters.end(), Filter(path_filter, role)) == filters.end()) filters.emplace_back(path_filter, role); } @@ -1851,7 +1852,7 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio { s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Extrusion, (unsigned int)filter.role, (unsigned int)volumes.volumes.size()); - GLVolume* volume = new GLVolume(Helper::path_color(print.gcode_preview, tool_colors, filter.value).rgba); + GLVolume* volume = new GLVolume(Helper::path_color(preview_data, tool_colors, filter.value).rgba); if (volume != nullptr) { filter.volume = volume; @@ -1877,11 +1878,11 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio } // populates volumes - for (const GCodePreviewData::Extrusion::Layer& layer : print.gcode_preview.extrusion.layers) + for (const GCodePreviewData::Extrusion::Layer& layer : preview_data.extrusion.layers) { for (const ExtrusionPath& path : layer.paths) { - float path_filter = Helper::path_filter(print.gcode_preview.extrusion.view_type, path); + float path_filter = Helper::path_filter(preview_data.extrusion.view_type, path); FiltersList::iterator filter = std::find(filters.begin(), filters.end(), Filter(path_filter, path.role())); if (filter != filters.end()) { @@ -1906,27 +1907,27 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio } } -void _3DScene::_load_gcode_travel_paths(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs) +void _3DScene::_load_gcode_travel_paths(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs) { size_t initial_volumes_count = volumes.volumes.size(); s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Travel, 0, (unsigned int)initial_volumes_count); bool res = true; - switch (print.gcode_preview.extrusion.view_type) + switch (preview_data.extrusion.view_type) { case GCodePreviewData::Extrusion::Feedrate: { - res = _travel_paths_by_feedrate(print, volumes); + res = _travel_paths_by_feedrate(preview_data, volumes); break; } case GCodePreviewData::Extrusion::Tool: { - res = _travel_paths_by_tool(print, volumes, tool_colors); + res = _travel_paths_by_tool(preview_data, volumes, tool_colors); break; } default: { - res = _travel_paths_by_type(print, volumes); + res = _travel_paths_by_type(preview_data, volumes); break; } } @@ -1961,7 +1962,7 @@ void _3DScene::_load_gcode_travel_paths(const Print& print, GLVolumeCollection& } } -bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& volumes) +bool _3DScene::_travel_paths_by_type(const GCodePreviewData& preview_data, GLVolumeCollection& volumes) { // Helper structure for types struct Type @@ -1987,7 +1988,7 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol // detects types TypesList types; - for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) { if (std::find(types.begin(), types.end(), Type(polyline.type)) == types.end()) types.emplace_back(polyline.type); @@ -2000,7 +2001,7 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol // creates a new volume for each type for (Type& type : types) { - GLVolume* volume = new GLVolume(print.gcode_preview.travel.type_colors[type.value].rgba); + GLVolume* volume = new GLVolume(preview_data.travel.type_colors[type.value].rgba); if (volume == nullptr) return false; else @@ -2011,7 +2012,7 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol } // populates volumes - for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) { TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type)); if (type != types.end()) @@ -2020,14 +2021,14 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol type->volume->offsets.push_back(type->volume->indexed_vertex_array.quad_indices.size()); type->volume->offsets.push_back(type->volume->indexed_vertex_array.triangle_indices.size()); - polyline3_to_verts(polyline.polyline, print.gcode_preview.travel.width, print.gcode_preview.travel.height, *type->volume); + polyline3_to_verts(polyline.polyline, preview_data.travel.width, preview_data.travel.height, *type->volume); } } return true; } -bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& volumes) +bool _3DScene::_travel_paths_by_feedrate(const GCodePreviewData& preview_data, GLVolumeCollection& volumes) { // Helper structure for feedrate struct Feedrate @@ -2053,7 +2054,7 @@ bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& // detects feedrates FeedratesList feedrates; - for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) { if (std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)) == feedrates.end()) feedrates.emplace_back(polyline.feedrate); @@ -2066,7 +2067,7 @@ bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& // creates a new volume for each feedrate for (Feedrate& feedrate : feedrates) { - GLVolume* volume = new GLVolume(print.gcode_preview.get_extrusion_feedrate_color(feedrate.value).rgba); + GLVolume* volume = new GLVolume(preview_data.get_extrusion_feedrate_color(feedrate.value).rgba); if (volume == nullptr) return false; else @@ -2077,7 +2078,7 @@ bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& } // populates volumes - for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) { FeedratesList::iterator feedrate = std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)); if (feedrate != feedrates.end()) @@ -2086,14 +2087,14 @@ bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.quad_indices.size()); feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.triangle_indices.size()); - polyline3_to_verts(polyline.polyline, print.gcode_preview.travel.width, print.gcode_preview.travel.height, *feedrate->volume); + polyline3_to_verts(polyline.polyline, preview_data.travel.width, preview_data.travel.height, *feedrate->volume); } } return true; } -bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors) +bool _3DScene::_travel_paths_by_tool(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, const std::vector& tool_colors) { // Helper structure for tool struct Tool @@ -2119,7 +2120,7 @@ bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& vol // detects tools ToolsList tools; - for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) { if (std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id)) == tools.end()) tools.emplace_back(polyline.extruder_id); @@ -2143,7 +2144,7 @@ bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& vol } // populates volumes - for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : preview_data.travel.polylines) { ToolsList::iterator tool = std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id)); if (tool != tools.end()) @@ -2152,27 +2153,27 @@ bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& vol tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.quad_indices.size()); tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.triangle_indices.size()); - polyline3_to_verts(polyline.polyline, print.gcode_preview.travel.width, print.gcode_preview.travel.height, *tool->volume); + polyline3_to_verts(polyline.polyline, preview_data.travel.width, preview_data.travel.height, *tool->volume); } } return true; } -void _3DScene::_load_gcode_retractions(const Print& print, GLVolumeCollection& volumes, bool use_VBOs) +void _3DScene::_load_gcode_retractions(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, bool use_VBOs) { s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Retraction, 0, (unsigned int)volumes.volumes.size()); // nothing to render, return - if (print.gcode_preview.retraction.positions.empty()) + if (preview_data.retraction.positions.empty()) return; - GLVolume* volume = new GLVolume(print.gcode_preview.retraction.color.rgba); + GLVolume* volume = new GLVolume(preview_data.retraction.color.rgba); if (volume != nullptr) { volumes.volumes.emplace_back(volume); - for (const GCodePreviewData::Retraction::Position& position : print.gcode_preview.retraction.positions) + for (const GCodePreviewData::Retraction::Position& position : preview_data.retraction.positions) { volume->print_zs.push_back(unscale(position.position.z)); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); @@ -2187,20 +2188,20 @@ void _3DScene::_load_gcode_retractions(const Print& print, GLVolumeCollection& v } } -void _3DScene::_load_gcode_unretractions(const Print& print, GLVolumeCollection& volumes, bool use_VBOs) +void _3DScene::_load_gcode_unretractions(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, bool use_VBOs) { s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Unretraction, 0, (unsigned int)volumes.volumes.size()); // nothing to render, return - if (print.gcode_preview.unretraction.positions.empty()) + if (preview_data.unretraction.positions.empty()) return; - GLVolume* volume = new GLVolume(print.gcode_preview.unretraction.color.rgba); + GLVolume* volume = new GLVolume(preview_data.unretraction.color.rgba); if (volume != nullptr) { volumes.volumes.emplace_back(volume); - for (const GCodePreviewData::Retraction::Position& position : print.gcode_preview.unretraction.positions) + for (const GCodePreviewData::Retraction::Position& position : preview_data.unretraction.positions) { volume->print_zs.push_back(unscale(position.position.z)); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); @@ -2215,7 +2216,7 @@ void _3DScene::_load_gcode_unretractions(const Print& print, GLVolumeCollection& } } -void _3DScene::_update_gcode_volumes_visibility(const Print& print, GLVolumeCollection& volumes) +void _3DScene::_update_gcode_volumes_visibility(const GCodePreviewData& preview_data, GLVolumeCollection& volumes) { unsigned int size = (unsigned int)s_gcode_preview_volume_index.first_volumes.size(); for (unsigned int i = 0; i < size; ++i) @@ -2231,27 +2232,27 @@ void _3DScene::_update_gcode_volumes_visibility(const Print& print, GLVolumeColl { case GCodePreviewVolumeIndex::Extrusion: { - volume->is_active = print.gcode_preview.extrusion.is_role_flag_set((ExtrusionRole)s_gcode_preview_volume_index.first_volumes[i].flag); + volume->is_active = preview_data.extrusion.is_role_flag_set((ExtrusionRole)s_gcode_preview_volume_index.first_volumes[i].flag); break; } case GCodePreviewVolumeIndex::Travel: { - volume->is_active = print.gcode_preview.travel.is_visible; + volume->is_active = preview_data.travel.is_visible; break; } case GCodePreviewVolumeIndex::Retraction: { - volume->is_active = print.gcode_preview.retraction.is_visible; + volume->is_active = preview_data.retraction.is_visible; break; } case GCodePreviewVolumeIndex::Unretraction: { - volume->is_active = print.gcode_preview.unretraction.is_visible; + volume->is_active = preview_data.unretraction.is_visible; break; } case GCodePreviewVolumeIndex::Shell: { - volume->is_active = print.gcode_preview.shell.is_visible; + volume->is_active = preview_data.shell.is_visible; break; } default: @@ -2264,9 +2265,9 @@ void _3DScene::_update_gcode_volumes_visibility(const Print& print, GLVolumeColl } } -void _3DScene::_generate_legend_texture(const Print& print, const std::vector& tool_colors) +void _3DScene::_generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors) { - s_legend_texture.generate_texture(print, tool_colors); + s_legend_texture.generate_texture(preview_data, tool_colors); } void _3DScene::_load_shells(const Print& print, GLVolumeCollection& volumes, bool use_VBOs) diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 7566b284a..bf3515ac5 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -15,6 +15,7 @@ class Print; class PrintObject; class Model; class ModelObject; +class GCodePreviewData; // A container for interleaved arrays of 3D vertices and normals, // possibly indexed by triangles and / or quads. @@ -423,7 +424,7 @@ class _3DScene LegendTexture(); ~LegendTexture(); - bool generate_texture(const Print& print, const std::vector& tool_colors); + bool generate_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors); unsigned int get_texture_id() const; unsigned int get_texture_width() const; @@ -432,7 +433,7 @@ class _3DScene void reset_texture(); private: - bool _create_texture(const Print& print, const wxBitmap& bitmap); + bool _create_texture(const GCodePreviewData& preview_data, const wxBitmap& bitmap); void _destroy_texture(); }; @@ -441,7 +442,7 @@ class _3DScene public: static void _glew_init(); - static void load_gcode_preview(const Print* print, GLVolumeCollection* volumes, const std::vector& str_tool_colors, bool use_VBOs); + static void load_gcode_preview(const Print* print, const GCodePreviewData* preview_data, GLVolumeCollection* volumes, const std::vector& str_tool_colors, bool use_VBOs); static unsigned int get_legend_texture_id(); static unsigned int get_legend_texture_width(); @@ -469,20 +470,20 @@ public: private: // generates gcode extrusion paths geometry - static void _load_gcode_extrusion_paths(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs); + static void _load_gcode_extrusion_paths(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs); // generates gcode travel paths geometry - static void _load_gcode_travel_paths(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs); - static bool _travel_paths_by_type(const Print& print, GLVolumeCollection& volumes); - static bool _travel_paths_by_feedrate(const Print& print, GLVolumeCollection& volumes); - static bool _travel_paths_by_tool(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors); + static void _load_gcode_travel_paths(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs); + static bool _travel_paths_by_type(const GCodePreviewData& preview_data, GLVolumeCollection& volumes); + static bool _travel_paths_by_feedrate(const GCodePreviewData& preview_data, GLVolumeCollection& volumes); + static bool _travel_paths_by_tool(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, const std::vector& tool_colors); // generates gcode retractions geometry - static void _load_gcode_retractions(const Print& print, GLVolumeCollection& volumes, bool use_VBOs); + static void _load_gcode_retractions(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, bool use_VBOs); // generates gcode unretractions geometry - static void _load_gcode_unretractions(const Print& print, GLVolumeCollection& volumes, bool use_VBOs); + static void _load_gcode_unretractions(const GCodePreviewData& preview_data, GLVolumeCollection& volumes, bool use_VBOs); // sets gcode geometry visibility according to user selection - static void _update_gcode_volumes_visibility(const Print& print, GLVolumeCollection& volumes); + static void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data, GLVolumeCollection& volumes); // generates the legend texture in dependence of the current shown view type - static void _generate_legend_texture(const Print& print, const std::vector& tool_colors); + static void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors); // generates objects and wipe tower geometry static void _load_shells(const Print& print, GLVolumeCollection& volumes, bool use_VBOs); }; diff --git a/xs/xsp/GCode.xsp b/xs/xsp/GCode.xsp index 9e6df85dc..4d62e3f81 100644 --- a/xs/xsp/GCode.xsp +++ b/xs/xsp/GCode.xsp @@ -4,6 +4,7 @@ #include #include "libslic3r/GCode.hpp" #include "libslic3r/GCode/CoolingBuffer.hpp" +#include "libslic3r/GCode/PreviewData.hpp" %} %name{Slic3r::GCode::CoolingBuffer} class CoolingBuffer { @@ -17,10 +18,10 @@ %name{Slic3r::GCode} class GCode { GCode(); ~GCode(); - void do_export(Print *print, const char *path) + void do_export(Print *print, const char *path, GCodePreviewData *preview_data) %code%{ try { - THIS->do_export(print, path); + THIS->do_export(print, path, preview_data); } catch (std::exception& e) { croak(e.what()); } @@ -50,3 +51,25 @@ Ref config() %code{% RETVAL = const_cast(static_cast(static_cast(&THIS->config()))); %}; }; + +%name{Slic3r::GCode::PreviewData} class GCodePreviewData { + GCodePreviewData(); + ~GCodePreviewData(); + void reset(); + void set_type(int type) + %code%{ + if ((0 <= type) && (type < GCodePreviewData::Extrusion::Num_View_Types)) + THIS->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; + %}; + void set_extrusion_flags(int flags) + %code%{ THIS->extrusion.role_flags = (unsigned int)flags; %}; + void set_travel_visible(bool visible) + %code%{ THIS->travel.is_visible = visible; %}; + void set_retractions_visible(bool visible) + %code%{ THIS->retraction.is_visible = visible; %}; + void set_unretractions_visible(bool visible) + %code%{ THIS->unretraction.is_visible = visible; %}; + void set_shells_visible(bool visible) + %code%{ THIS->shell.is_visible = visible; %}; + void set_extrusion_paths_colors(std::vector colors); +}; diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 7520ce6c2..c06c659b1 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -195,12 +195,13 @@ _load_wipe_tower_toolpaths(print, volumes, tool_colors, use_VBOs) _3DScene::_load_wipe_tower_toolpaths(print, volumes, tool_colors, use_VBOs != 0); void -load_gcode_preview(print, volumes, str_tool_colors, use_VBOs) +load_gcode_preview(print, preview_data, volumes, str_tool_colors, use_VBOs) Print *print; + GCodePreviewData *preview_data; GLVolumeCollection *volumes; std::vector str_tool_colors; int use_VBOs; CODE: - _3DScene::load_gcode_preview(print, volumes, str_tool_colors, use_VBOs != 0); + _3DScene::load_gcode_preview(print, preview_data, volumes, str_tool_colors, use_VBOs != 0); %} diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 5749c20db..cbc04a804 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -165,15 +165,6 @@ _constant() size_t object_count() %code%{ RETVAL = THIS->objects.size(); %}; - void clear_gcode_preview_data(); - void set_gcode_preview_type(unsigned char type); - void set_gcode_preview_extrusion_flags(unsigned int flags); - void set_gcode_preview_travel_visible(bool visible); - void set_gcode_preview_retractions_visible(bool visible); - void set_gcode_preview_unretractions_visible(bool visible); - void set_gcode_preview_shells_visible(bool visible); - void set_gcode_extrusion_paths_colors(std::vector colors); - PrintRegionPtrs* regions() %code%{ RETVAL = &THIS->regions; %}; Ref get_region(int idx); diff --git a/xs/xsp/my.map b/xs/xsp/my.map index ba4f52f46..64aa15f09 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -191,6 +191,10 @@ GCode* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T +GCodePreviewData* O_OBJECT_SLIC3R +Ref O_OBJECT_SLIC3R_T +Clone O_OBJECT_SLIC3R_T + MotionPlanner* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index d6c74659c..33bcb2fd2 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -155,6 +155,9 @@ %typemap{Ref}{simple}; %typemap{Clone}{simple}; +%typemap{GCodePreviewData*}; +%typemap{Ref}{simple}; +%typemap{Clone}{simple}; %typemap{Points}; %typemap{Pointfs};