Another set of 3DScene methods moved to c++

This commit is contained in:
Enrico Turri 2018-06-04 15:42:34 +02:00
parent 9729c71691
commit d74b85f3fe
13 changed files with 151 additions and 62 deletions

View file

@ -24,8 +24,11 @@ use OpenGL qw(:glconstants :glfunctions :glufunctions :gluconstants);
use base qw(Wx::GLCanvas Class::Accessor);
use Math::Trig qw(asin tan);
use List::Util qw(reduce min max first);
use Slic3r::Geometry qw(X Y normalize scale unscale scaled_epsilon);
use Slic3r::Geometry::Clipper qw(offset_ex intersection_pl JT_ROUND);
#==============================================================================================================================
use Slic3r::Geometry qw(X Y);
#use Slic3r::Geometry qw(X Y normalize scale unscale scaled_epsilon);
#use Slic3r::Geometry::Clipper qw(offset_ex intersection_pl JT_ROUND);
#==============================================================================================================================
use Wx::GLCanvas qw(:all);
use Slic3r::Geometry qw(PI);
@ -33,9 +36,7 @@ use Slic3r::Geometry qw(PI);
# volumes: reference to vector of Slic3r::GUI::3DScene::Volume.
# _camera_type: 'perspective' or 'ortho'
#==============================================================================================================================
__PACKAGE__->mk_accessors( qw(init
on_viewport_changed
on_select
__PACKAGE__->mk_accessors( qw(
volumes
) );
#__PACKAGE__->mk_accessors( qw(_quat _dirty init
@ -1268,12 +1269,10 @@ sub DestroyGL {
}
}
sub Render {
my ($self, $dc) = @_;
#==============================================================================================================================
Slic3r::GUI::_3DScene::render($self);
#sub Render {
# my ($self, $dc) = @_;
#
# # prevent calling SetCurrent() when window is not shown yet
# return unless Slic3r::GUI::_3DScene::is_shown_on_screen($self);
## return unless $self->IsShownOnScreen;
@ -1497,10 +1496,8 @@ sub Render {
# $self->draw_active_object_annotations;
#
# $self->SwapBuffers();
#==============================================================================================================================
}
#==============================================================================================================================
#}
#
#sub draw_volumes {
# # $fakecolor is a boolean indicating, that the objects shall be rendered in a color coding the object index for picking.
# my ($self, $fakecolor) = @_;
@ -2264,18 +2261,20 @@ sub load_gcode_preview {
#==============================================================================================================================
}
sub set_toolpaths_range {
my ($self, $min_z, $max_z) = @_;
$self->volumes->set_range($min_z, $max_z);
}
sub reset_legend_texture {
Slic3r::GUI::_3DScene::reset_legend_texture();
}
sub get_current_print_zs {
my ($self, $active_only) = @_;
return $self->volumes->get_current_print_zs($active_only);
}
#==============================================================================================================================
#sub set_toolpaths_range {
# my ($self, $min_z, $max_z) = @_;
# $self->volumes->set_range($min_z, $max_z);
#}
#
#sub reset_legend_texture {
# Slic3r::GUI::_3DScene::reset_legend_texture();
#}
#
#sub get_current_print_zs {
# my ($self, $active_only) = @_;
# return $self->volumes->get_current_print_zs($active_only);
#}
#==============================================================================================================================
1;

View file

@ -152,6 +152,8 @@ sub new {
$self->{"print_info_box_show"}->(0);
}
});
Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D}, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); });
# $self->{canvas3D}->set_on_model_update(sub {
# if (wxTheApp->{app_config}->get("background_processing")) {
@ -161,15 +163,9 @@ sub new {
# $self->{"print_info_box_show"}->(0);
# }
# });
#==============================================================================================================================
$self->{canvas3D}->on_viewport_changed(sub {
#==============================================================================================================================
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D});
# $self->{canvas3D}->on_viewport_changed(sub {
# $self->{preview3D}->canvas->set_viewport_from_scene($self->{canvas3D});
#==============================================================================================================================
});
#==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D}, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); });
# });
#==============================================================================================================================
}
@ -184,14 +180,11 @@ sub new {
# Initialize 3D toolpaths preview
if ($Slic3r::GUI::have_OpenGL) {
$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 {
#==============================================================================================================================
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas);
# $self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas);
#==============================================================================================================================
});
#==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{preview3D}->canvas, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas); });
# $self->{preview3D}->canvas->on_viewport_changed(sub {
# $self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas);
# });
#==============================================================================================================================
$self->{preview_notebook}->AddPage($self->{preview3D}, L('Preview'));
$self->{preview3D_page_idx} = $self->{preview_notebook}->GetPageCount-1;
@ -1900,9 +1893,10 @@ sub list_item_deselected {
$self->{canvas}->Refresh;
#==============================================================================================================================
Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D}) if $self->{canvas3D};
Slic3r::GUI::_3DScene::render($self->{canvas3D}) if $self->{canvas3D};
# $self->{canvas3D}->deselect_volumes if $self->{canvas3D};
# $self->{canvas3D}->Render if $self->{canvas3D};
#==============================================================================================================================
$self->{canvas3D}->Render if $self->{canvas3D};
}
undef $self->{_lecursor};
}
@ -1915,7 +1909,10 @@ sub list_item_selected {
$self->select_object($obj_idx);
$self->{canvas}->Refresh;
$self->{canvas3D}->update_volumes_selection if $self->{canvas3D};
$self->{canvas3D}->Render if $self->{canvas3D};
#==============================================================================================================================
Slic3r::GUI::_3DScene::render($self->{canvas3D}) if $self->{canvas3D};
# $self->{canvas3D}->Render if $self->{canvas3D};
#==============================================================================================================================
undef $self->{_lecursor};
}

View file

@ -42,13 +42,17 @@ sub new {
$self->{objects_volumes_idxs} = [];
$self->on_select(sub {
#==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_select_callback($self, sub {
my ($volume_idx) = @_;
$self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
if ($self->{on_select_object});
});
#==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_select_callback($self, $self->on_select);
});
# $self->on_select(sub {
# my ($volume_idx) = @_;
# $self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
# if ($self->{on_select_object});
# });
#==============================================================================================================================
#==============================================================================================================================

View file

@ -310,7 +310,10 @@ sub refresh_print {
sub reset_gcode_preview_data {
my ($self) = @_;
$self->gcode_preview_data->reset;
$self->canvas->reset_legend_texture();
#==============================================================================================================================
Slic3r::GUI::_3DScene::reset_legend_texture();
# $self->canvas->reset_legend_texture();
#==============================================================================================================================
}
sub load_print {
@ -335,7 +338,10 @@ sub load_print {
if ($n_layers == 0) {
$self->reset_sliders;
$self->canvas->reset_legend_texture();
#==============================================================================================================================
Slic3r::GUI::_3DScene::reset_legend_texture();
# $self->canvas->reset_legend_texture();
#==============================================================================================================================
$self->canvas->Refresh; # clears canvas
return;
}
@ -379,14 +385,20 @@ sub load_print {
#$self->canvas->volumes->[$_]->color->[3] = 0.2 for @volume_ids;
}
$self->show_hide_ui_elements('simple');
$self->canvas->reset_legend_texture();
#==============================================================================================================================
Slic3r::GUI::_3DScene::reset_legend_texture();
# $self->canvas->reset_legend_texture();
#==============================================================================================================================
} else {
$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');
# recalculates zs and update sliders accordingly
$self->{layers_z} = $self->canvas->get_current_print_zs(1);
#==============================================================================================================================
$self->{layers_z} = Slic3r::GUI::_3DScene::get_current_print_zs($self->canvas, 1);
# $self->{layers_z} = $self->canvas->get_current_print_zs(1);
#==============================================================================================================================
$n_layers = scalar(@{$self->{layers_z}});
if ($n_layers == 0) {
# all layers filtered out
@ -472,7 +484,10 @@ sub set_z_range
$self->{z_label_low}->SetLabel(sprintf '%.2f', $z_low);
$self->{z_label_high}->SetLabel(sprintf '%.2f', $z_high);
my $layers_z = $self->canvas->get_current_print_zs(0);
#==============================================================================================================================
my $layers_z = Slic3r::GUI::_3DScene::get_current_print_zs($self->canvas, 0);
# my $layers_z = $self->canvas->get_current_print_zs(0);
#==============================================================================================================================
for (my $i = 0; $i < scalar(@{$layers_z}); $i += 1) {
if (($z_low - 1e-6 < @{$layers_z}[$i]) && (@{$layers_z}[$i] < $z_low + 1e-6)) {
$self->{z_label_low_idx}->SetLabel(sprintf '%d', $i + 1);
@ -486,7 +501,10 @@ sub set_z_range
}
}
$self->canvas->set_toolpaths_range($z_low - 1e-6, $z_high + 1e-6);
#==============================================================================================================================
Slic3r::GUI::_3DScene::set_toolpaths_range($self->canvas, $z_low - 1e-6, $z_high + 1e-6);
# $self->canvas->set_toolpaths_range($z_low - 1e-6, $z_high + 1e-6);
#==============================================================================================================================
$self->canvas->Refresh if $self->IsShown;
}

View file

@ -267,13 +267,14 @@ sub _update {
#==============================================================================================================================
Slic3r::GUI::_3DScene::set_cutting_plane($self->{canvas}, $self->{cut_options}{z}, [@expolygons]);
Slic3r::GUI::_3DScene::update_volumes_colors_by_extruder($self->{canvas});
Slic3r::GUI::_3DScene::render($self->{canvas});
# $self->{canvas}->SetCuttingPlane(
# $self->{cut_options}{z},
# [@expolygons],
# );
# $self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->{config});
# $self->{canvas}->Render;
#==============================================================================================================================
$self->{canvas}->Render;
}
}

View file

@ -159,11 +159,18 @@ sub new {
#==============================================================================================================================
$canvas->select_by('volume');
$canvas->on_select(sub {
#==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_select_callback($canvas, sub {
my ($volume_idx) = @_;
# convert scene volume to model object volume
$self->reload_tree(($volume_idx == -1) ? undef : $canvas->volumes->[$volume_idx]->volume_idx);
});
# $canvas->on_select(sub {
# my ($volume_idx) = @_;
# # convert scene volume to model object volume
# $self->reload_tree(($volume_idx == -1) ? undef : $canvas->volumes->[$volume_idx]->volume_idx);
# });
#==============================================================================================================================
$canvas->load_object($self->{model_object}, undef, undef, [0]);
#==============================================================================================================================
@ -348,7 +355,10 @@ sub selection_changed {
$self->{settings_panel}->enable;
}
$self->{canvas}->Render if $self->{canvas};
#==============================================================================================================================
Slic3r::GUI::_3DScene::render($self->{canvas}) if $self->{canvas};
# $self->{canvas}->Render if $self->{canvas};
#==============================================================================================================================
}
sub on_btn_load {
@ -510,10 +520,11 @@ sub _parts_changed {
#==============================================================================================================================
Slic3r::GUI::_3DScene::zoom_to_volumes($self->{canvas});
Slic3r::GUI::_3DScene::update_volumes_colors_by_extruder($self->{canvas});
Slic3r::GUI::_3DScene::render($self->{canvas});
# $self->{canvas}->zoom_to_volumes;
# $self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
# $self->{canvas}->Render;
#==============================================================================================================================
$self->{canvas}->Render;
}
}
@ -569,9 +580,10 @@ sub _update_canvas {
#==============================================================================================================================
Slic3r::GUI::_3DScene::update_volumes_colors_by_extruder($self->{canvas});
Slic3r::GUI::_3DScene::render($self->{canvas});
# $self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
# $self->{canvas}->Render;
#==============================================================================================================================
$self->{canvas}->Render;
}
}
@ -600,9 +612,10 @@ sub _update {
$self->{canvas}->load_object($_, undef, [0]) for @objects;
#==============================================================================================================================
Slic3r::GUI::_3DScene::update_volumes_colors_by_extruder($self->{canvas});
Slic3r::GUI::_3DScene::render($self->{canvas});
# $self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
# $self->{canvas}->Render;
#==============================================================================================================================
$self->{canvas}->Render;
}
1;

View file

@ -1903,6 +1903,16 @@ void _3DScene::render(wxGLCanvas* canvas)
s_canvas_mgr.render(canvas);
}
std::vector<double> _3DScene::get_current_print_zs(wxGLCanvas* canvas, bool active_only)
{
return s_canvas_mgr.get_current_print_zs(canvas, active_only);
}
void _3DScene::set_toolpaths_range(wxGLCanvas* canvas, double low, double high)
{
s_canvas_mgr.set_toolpaths_range(canvas, low, high);
}
void _3DScene::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback)
{
s_canvas_mgr.register_on_viewport_changed_callback(canvas, callback);

View file

@ -587,6 +587,9 @@ public:
static void render(wxGLCanvas* canvas);
static std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only);
static void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);
static void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
static void register_on_double_click_callback(wxGLCanvas* canvas, void* callback);
static void register_on_right_click_callback(wxGLCanvas* canvas, void* callback);

View file

@ -1317,6 +1317,17 @@ void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, fl
::glEnable(GL_LIGHTING);
}
std::vector<double> GLCanvas3D::get_current_print_zs(bool active_only) const
{
return (m_volumes != nullptr) ? m_volumes->get_current_print_zs(active_only) : std::vector<double>();
}
void GLCanvas3D::set_toolpaths_range(double low, double high)
{
if (m_volumes != nullptr)
m_volumes->set_range(low, high);
}
void GLCanvas3D::register_on_viewport_changed_callback(void* callback)
{
if (callback != nullptr)

View file

@ -376,6 +376,9 @@ public:
void render();
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const;
std::vector<double> get_current_print_zs(bool active_only) const;
void set_toolpaths_range(double low, double high);
void register_on_viewport_changed_callback(void* callback);
void register_on_double_click_callback(void* callback);
void register_on_right_click_callback(void* callback);

View file

@ -430,6 +430,19 @@ void GLCanvas3DManager::render(wxGLCanvas* canvas) const
it->second->render();
}
std::vector<double> GLCanvas3DManager::get_current_print_zs(wxGLCanvas* canvas, bool active_only) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->get_current_print_zs(active_only) : std::vector<double>();
}
void GLCanvas3DManager::set_toolpaths_range(wxGLCanvas* canvas, double low, double high)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_toolpaths_range(low, high);
}
void GLCanvas3DManager::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback)
{
CanvasesMap::iterator it = _get_canvas(canvas);

View file

@ -91,6 +91,9 @@ public:
void render(wxGLCanvas* canvas) const;
std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only) const;
void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);
void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
void register_on_double_click_callback(wxGLCanvas* canvas, void* callback);
void register_on_right_click_callback(wxGLCanvas* canvas, void* callback);

View file

@ -93,9 +93,6 @@
int count()
%code{% RETVAL = THIS->volumes.size(); %};
std::vector<double> get_current_print_zs(bool active_only)
%code{% RETVAL = THIS->get_current_print_zs(active_only); %};
void set_range(double low, double high);
void render_VBOs() const;
@ -389,6 +386,23 @@ render(canvas)
CODE:
_3DScene::render((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
std::vector<double>
get_current_print_zs(canvas, active_only)
SV *canvas;
bool active_only;
CODE:
RETVAL = _3DScene::get_current_print_zs((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), active_only);
OUTPUT:
RETVAL
void
set_toolpaths_range(canvas, low, high)
SV *canvas;
double low;
double high;
CODE:
_3DScene::set_toolpaths_range((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), low, high);
void
register_on_viewport_changed_callback(canvas, callback)
SV *canvas;