From 085110c4d987ee46f2c4d982469677f41aba3dd3 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 11 Jun 2018 13:48:02 +0200 Subject: [PATCH] Removed 3DScene volumes from perl --- lib/Slic3r/GUI/3DScene.pm | 19 +++----- lib/Slic3r/GUI/Plater.pm | 5 ++- lib/Slic3r/GUI/Plater/3DPreview.pm | 3 +- lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm | 25 ++++++++--- xs/src/slic3r/GUI/3DScene.cpp | 19 +++++++- xs/src/slic3r/GUI/3DScene.hpp | 5 ++- xs/src/slic3r/GUI/GLCanvas3D.cpp | 55 +++++++++++++++++++---- xs/src/slic3r/GUI/GLCanvas3D.hpp | 5 ++- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 25 +++++++++-- xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 5 ++- xs/xsp/GUI_3DScene.xsp | 38 +++++++++++++--- 11 files changed, 160 insertions(+), 44 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 5f33b17ab..e40beda26 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -34,9 +34,6 @@ use Wx::GLCanvas qw(:all); # volumes: reference to vector of Slic3r::GUI::3DScene::Volume. #============================================================================================================================== -__PACKAGE__->mk_accessors( qw( - volumes - ) ); #__PACKAGE__->mk_accessors( qw(_quat _dirty init # enable_picking # enable_moving @@ -165,17 +162,11 @@ sub new { # $self->use_plain_shader(0); # $self->_apply_zoom_to_volumes_filter(0); # $self->_mouse_dragging(0); -#============================================================================================================================== - - # Collection of GLVolume objects - $self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new); -#============================================================================================================================== - Slic3r::GUI::_3DScene::set_volumes($self, $self->volumes); - Slic3r::GUI::_3DScene::reset_volumes($self); -#============================================================================================================================== - - # 3D point in model space -#============================================================================================================================== +# +# # Collection of GLVolume objects +# $self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new); +# +# # 3D point in model space # $self->_camera_type('ortho'); ## $self->_camera_type('perspective'); # $self->_camera_target(Slic3r::Pointf3->new(0,0,0)); diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index f74bc7d82..85d9426fb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -2109,7 +2109,10 @@ sub object_list_changed { } my $export_in_progress = $self->{export_gcode_output_file} || $self->{send_gcode_file}; - my $model_fits = $self->{canvas3D} ? $self->{canvas3D}->volumes->check_outside_state($self->{config}) : 1; +#============================================================================================================================== + my $model_fits = $self->{canvas3D} ? Slic3r::GUI::_3DScene::check_volumes_outside_state($self->{canvas3D}, $self->{config}) : 1; +# my $model_fits = $self->{canvas3D} ? $self->{canvas3D}->volumes->check_outside_state($self->{config}) : 1; +#============================================================================================================================== my $method = ($have_objects && ! $export_in_progress && $model_fits) ? 'Enable' : 'Disable'; $self->{"btn_$_"}->$method for grep $self->{"btn_$_"}, qw(reslice export_gcode print send_gcode); diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index 55198eeb6..86a862c75 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -398,10 +398,11 @@ sub load_print { # $self->canvas->reset_legend_texture(); #============================================================================================================================== } else { - $self->{force_sliders_full_range} = (scalar(@{$self->canvas->volumes}) == 0); #============================================================================================================================== + $self->{force_sliders_full_range} = (Slic3r::GUI::_3DScene::get_volumes_count($self->canvas) == 0); Slic3r::GUI::_3DScene::set_print($self->canvas, $self->print); Slic3r::GUI::_3DScene::load_gcode_preview($self->canvas, $self->gcode_preview_data, \@colors); +# $self->{force_sliders_full_range} = (scalar(@{$self->canvas->volumes}) == 0); # $self->canvas->load_gcode_preview($self->print, $self->gcode_preview_data, \@colors); #============================================================================================================================== $self->show_hide_ui_elements('full'); diff --git a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm index 135d75233..546ec5445 100644 --- a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm +++ b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm @@ -280,7 +280,10 @@ sub selection_changed { # deselect all meshes if ($self->{canvas}) { - $_->set_selected(0) for @{$self->{canvas}->volumes}; +#============================================================================================================================== + Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas}); +# $_->set_selected(0) for @{$self->{canvas}->volumes}; +#============================================================================================================================== } # disable things as if nothing is selected @@ -308,7 +311,10 @@ sub selection_changed { if ($itemData->{type} eq 'volume') { # select volume in 3D preview if ($self->{canvas}) { - $self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1); +#============================================================================================================================== + Slic3r::GUI::_3DScene::select_volume($self->{canvas}, $itemData->{volume_id}); +# $self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1); +#============================================================================================================================== } $self->{btn_delete}->Enable; $self->{btn_split}->Enable; @@ -450,7 +456,10 @@ sub on_btn_move_up { if ($itemData && $itemData->{type} eq 'volume') { my $volume_id = $itemData->{volume_id}; if ($self->{model_object}->move_volume_up($volume_id)) { - $self->{canvas}->volumes->move_volume_up($volume_id); +#============================================================================================================================== + Slic3r::GUI::_3DScene::move_volume_up($self->{canvas}, $volume_id); +# $self->{canvas}->volumes->move_volume_up($volume_id); +#============================================================================================================================== $self->{parts_changed} = 1; $self->reload_tree($volume_id - 1); } @@ -463,7 +472,10 @@ sub on_btn_move_down { if ($itemData && $itemData->{type} eq 'volume') { my $volume_id = $itemData->{volume_id}; if ($self->{model_object}->move_volume_down($volume_id)) { - $self->{canvas}->volumes->move_volume_down($volume_id); +#============================================================================================================================== + Slic3r::GUI::_3DScene::move_volume_down($self->{canvas}, $volume_id); +# $self->{canvas}->volumes->move_volume_down($volume_id); +#============================================================================================================================== $self->{parts_changed} = 1; $self->reload_tree($volume_id + 1); } @@ -570,7 +582,10 @@ sub _update_canvas { # restore selection, if any if (my $itemData = $self->get_selection) { if ($itemData->{type} eq 'volume') { - $self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1); +#============================================================================================================================== + Slic3r::GUI::_3DScene::select_volume($self->{canvas}, $itemData->{volume_id}); +# $self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1); +#============================================================================================================================== } } diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 21204b0ff..4f95f4ba6 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1802,9 +1802,9 @@ bool _3DScene::is_shown_on_screen(wxGLCanvas* canvas) return s_canvas_mgr.is_shown_on_screen(canvas); } -void _3DScene::set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes) +unsigned int _3DScene::get_volumes_count(wxGLCanvas* canvas) { - s_canvas_mgr.set_volumes(canvas, volumes); + return s_canvas_mgr.get_volumes_count(canvas); } void _3DScene::reset_volumes(wxGLCanvas* canvas) @@ -1827,6 +1827,21 @@ void _3DScene::update_volumes_selection(wxGLCanvas* canvas, const std::vector& selections) { s_canvas_mgr.set_objects_selections(canvas, selections); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 8e82849e8..1f179b009 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -558,11 +558,14 @@ public: static bool is_shown_on_screen(wxGLCanvas* canvas); - static void set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes); + static unsigned int get_volumes_count(wxGLCanvas* canvas); static void reset_volumes(wxGLCanvas* canvas); static void deselect_volumes(wxGLCanvas* canvas); static void select_volume(wxGLCanvas* canvas, unsigned int id); static void update_volumes_selection(wxGLCanvas* canvas, const std::vector& selections); + static bool check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config); + static bool move_volume_up(wxGLCanvas* canvas, unsigned int id); + static bool move_volume_down(wxGLCanvas* canvas, unsigned int id); static void set_objects_selections(wxGLCanvas* canvas, const std::vector& selections); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index e5f352bf7..7d39d97d3 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -24,10 +24,6 @@ #include #include -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -#include "SVG.hpp" -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - static const float TRACKBALLSIZE = 0.8f; static const float GIMBALL_LOCK_THETA_MAX = 180.0f; static const float GROUND_Z = -0.02f; @@ -661,7 +657,6 @@ bool GLCanvas3D::Bed::_are_equal(const Pointfs& bed_1, const Pointfs& bed_2) return true; } -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GLCanvas3D::Axes::Axes() : length(0.0f) @@ -1212,15 +1207,18 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context) , m_reload_delayed(false) { if (m_canvas != nullptr) + { m_timer = new wxTimer(m_canvas); + m_volumes = new GLVolumeCollection; + } } GLCanvas3D::~GLCanvas3D() { if (m_volumes != nullptr) { - set_current(); - m_volumes->release_geometry(); + reset_volumes(); + delete m_volumes; } if (m_timer != nullptr) @@ -1317,9 +1315,9 @@ bool GLCanvas3D::is_shown_on_screen() const return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false; } -void GLCanvas3D::set_volumes(GLVolumeCollection* volumes) +unsigned int GLCanvas3D::get_volumes_count() const { - m_volumes = volumes; + return (m_volumes != nullptr) ? (unsigned int)m_volumes->volumes.size() : 0; } void GLCanvas3D::reset_volumes() @@ -1372,6 +1370,45 @@ void GLCanvas3D::update_volumes_selection(const std::vector& selections) } } +bool GLCanvas3D::check_volumes_outside_state(const DynamicPrintConfig* config) const +{ + return (m_volumes != nullptr) ? m_volumes->check_outside_state(config) : false; +} + +bool GLCanvas3D::move_volume_up(unsigned int id) +{ + if (m_volumes != nullptr) + { + if ((id > 0) && (id < (unsigned int)m_volumes->volumes.size())) + { + std::swap(m_volumes->volumes[id - 1], m_volumes->volumes[id]); + std::swap(m_volumes->volumes[id - 1]->composite_id, m_volumes->volumes[id]->composite_id); + std::swap(m_volumes->volumes[id - 1]->select_group_id, m_volumes->volumes[id]->select_group_id); + std::swap(m_volumes->volumes[id - 1]->drag_group_id, m_volumes->volumes[id]->drag_group_id); + return true; + } + } + + return false; +} + +bool GLCanvas3D::move_volume_down(unsigned int id) +{ + if (m_volumes != nullptr) + { + if ((id >= 0) && (id + 1 < (unsigned int)m_volumes->volumes.size())) + { + std::swap(m_volumes->volumes[id + 1], m_volumes->volumes[id]); + std::swap(m_volumes->volumes[id + 1]->composite_id, m_volumes->volumes[id]->composite_id); + std::swap(m_volumes->volumes[id + 1]->select_group_id, m_volumes->volumes[id]->select_group_id); + std::swap(m_volumes->volumes[id + 1]->drag_group_id, m_volumes->volumes[id]->drag_group_id); + return true; + } + } + + return false; +} + void GLCanvas3D::set_objects_selections(const std::vector& selections) { m_objects_selections = selections; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index dde96ff41..2bdf9e692 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -419,11 +419,14 @@ public: bool is_shown_on_screen() const; - void set_volumes(GLVolumeCollection* volumes); + unsigned int get_volumes_count() const; void reset_volumes(); void deselect_volumes(); void select_volume(unsigned int id); void update_volumes_selection(const std::vector& selections); + bool check_volumes_outside_state(const DynamicPrintConfig* config) const; + bool move_volume_up(unsigned int id); + bool move_volume_down(unsigned int id); void set_objects_selections(const std::vector& selections); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index e01f85396..54bd54ba8 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -226,11 +226,10 @@ bool GLCanvas3DManager::is_shown_on_screen(wxGLCanvas* canvas) const return (it != m_canvases.end()) ? it->second->is_shown_on_screen() : false; } -void GLCanvas3DManager::set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes) +unsigned int GLCanvas3DManager::get_volumes_count(wxGLCanvas* canvas) const { - CanvasesMap::iterator it = _get_canvas(canvas); - if (it != m_canvases.end()) - it->second->set_volumes(volumes); + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->get_volumes_count() : 0; } void GLCanvas3DManager::reset_volumes(wxGLCanvas* canvas) @@ -261,6 +260,24 @@ void GLCanvas3DManager::update_volumes_selection(wxGLCanvas* canvas, const std:: it->second->update_volumes_selection(selections); } +bool GLCanvas3DManager::check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config) const +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->check_volumes_outside_state(config) : false; +} + +bool GLCanvas3DManager::move_volume_up(wxGLCanvas* canvas, unsigned int id) +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->move_volume_up(id) : false; +} + +bool GLCanvas3DManager::move_volume_down(wxGLCanvas* canvas, unsigned int id) +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->move_volume_down(id) : false; +} + void GLCanvas3DManager::set_objects_selections(wxGLCanvas* canvas, const std::vector& selections) { CanvasesMap::iterator it = _get_canvas(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index 76f8ffcb5..435993acd 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -53,11 +53,14 @@ public: bool is_shown_on_screen(wxGLCanvas* canvas) const; - void set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes); + unsigned int get_volumes_count(wxGLCanvas* canvas) const; void reset_volumes(wxGLCanvas* canvas); void deselect_volumes(wxGLCanvas* canvas); void select_volume(wxGLCanvas* canvas, unsigned int id); void update_volumes_selection(wxGLCanvas* canvas, const std::vector& selections); + bool check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config) const; + bool move_volume_up(wxGLCanvas* canvas, unsigned int id); + bool move_volume_down(wxGLCanvas* canvas, unsigned int id); void set_objects_selections(wxGLCanvas* canvas, const std::vector& selections); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index f8d22843e..8deb6419d 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -199,12 +199,13 @@ is_shown_on_screen(canvas) OUTPUT: RETVAL -void -set_volumes(canvas, volumes) - SV *canvas; - GLVolumeCollection *volumes; +unsigned int +get_volumes_count(canvas) + SV *canvas; CODE: - _3DScene::set_volumes((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), volumes); + RETVAL = _3DScene::get_volumes_count((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + OUTPUT: + RETVAL void reset_volumes(canvas) @@ -232,6 +233,33 @@ update_volumes_selection(canvas, selections) CODE: _3DScene::update_volumes_selection((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), selections); +bool +check_volumes_outside_state(canvas, config) + SV *canvas; + DynamicPrintConfig *config; + CODE: + RETVAL = _3DScene::check_volumes_outside_state((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), config); + OUTPUT: + RETVAL + +bool +move_volume_up(canvas, id) + SV *canvas; + unsigned int id; + CODE: + RETVAL = _3DScene::move_volume_up((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), id); + OUTPUT: + RETVAL + +bool +move_volume_down(canvas, id) + SV *canvas; + unsigned int id; + CODE: + RETVAL = _3DScene::move_volume_down((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), id); + OUTPUT: + RETVAL + void set_objects_selections(canvas, selections) SV *canvas;