From 6bf009edee89e6713c5c85af1e5dcf764c23bad5 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 31 May 2018 16:04:59 +0200 Subject: [PATCH] 3DScene mouse event handler partially moved to c++ - part 2 --- lib/Slic3r/GUI/3DScene.pm | 2 - lib/Slic3r/GUI/Plater.pm | 13 +- lib/Slic3r/GUI/Plater/3D.pm | 22 +- xs/src/libslic3r/Utils.hpp | 2 +- xs/src/libslic3r/utils.cpp | 17 +- xs/src/slic3r/GUI/3DScene.cpp | 21 +- xs/src/slic3r/GUI/3DScene.hpp | 5 +- xs/src/slic3r/GUI/GLCanvas3D.cpp | 273 ++++++++++++++---------- xs/src/slic3r/GUI/GLCanvas3D.hpp | 12 +- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 27 +-- xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 5 +- xs/xsp/GUI_3DScene.xsp | 31 ++- 12 files changed, 257 insertions(+), 173 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 4715b6ecf..019873936 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -37,8 +37,6 @@ use Slic3r::Geometry qw(PI); __PACKAGE__->mk_accessors( qw(_quat init on_viewport_changed on_select - on_move - on_model_update volumes _drag_volume_idx diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 35468aad5..2ff798899 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -143,7 +143,8 @@ sub new { $cfg->set('wipe_tower_y', $new_pos_3f->y); $self->GetFrame->{options_tabs}{print}->load_config($cfg); }); - $self->{canvas3D}->set_on_model_update(sub { +#============================================================================================================================== + Slic3r::GUI::_3DScene::register_on_model_update_callback($self->{canvas3D}, sub { if (wxTheApp->{app_config}->get("background_processing")) { $self->schedule_background_process; } else { @@ -151,6 +152,16 @@ sub new { $self->{"print_info_box_show"}->(0); } }); + +# $self->{canvas3D}->set_on_model_update(sub { +# if (wxTheApp->{app_config}->get("background_processing")) { +# $self->schedule_background_process; +# } else { +# # Hide the print info box, it is no more valid. +# $self->{"print_info_box_show"}->(0); +# } +# }); +#============================================================================================================================== $self->{canvas3D}->on_viewport_changed(sub { #============================================================================================================================== Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); diff --git a/lib/Slic3r/GUI/Plater/3D.pm b/lib/Slic3r/GUI/Plater/3D.pm index 04aca9aaf..ff4e2ad29 100644 --- a/lib/Slic3r/GUI/Plater/3D.pm +++ b/lib/Slic3r/GUI/Plater/3D.pm @@ -50,9 +50,19 @@ sub new { #============================================================================================================================== Slic3r::GUI::_3DScene::register_on_select_callback($self, $self->on_select); #============================================================================================================================== - $self->on_move(sub { + +#============================================================================================================================== + Slic3r::GUI::_3DScene::register_on_move_callback($self, sub { +# $self->on_move(sub { +#============================================================================================================================== my @volume_idxs = @_; + +#============================================================================================================================== + print "cucu"; +#============================================================================================================================== + + my %done = (); # prevent moving instances twice my $object_moved; my $wipe_tower_moved; @@ -186,10 +196,12 @@ sub set_on_wipe_tower_moved { $self->{on_wipe_tower_moved} = $cb; } -sub set_on_model_update { - my ($self, $cb) = @_; - $self->on_model_update($cb); -} +#============================================================================================================================== +#sub set_on_model_update { +# my ($self, $cb) = @_; +# $self->on_model_update($cb); +#} +#============================================================================================================================== sub set_on_enable_action_buttons { my ($self, $cb) = @_; diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp index 8e4d654de..45e83b1b8 100644 --- a/xs/src/libslic3r/Utils.hpp +++ b/xs/src/libslic3r/Utils.hpp @@ -95,7 +95,7 @@ public: void call() const; void call(int i) const; void call(int i, int j) const; - // void call(const std::vector &ints); + void call(const std::vector& ints) const; // void call(); // void call(int i); // void call(int i, int j); diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index c691073a4..883f5e753 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -238,9 +238,8 @@ void PerlCallback::call(int i, int j) const LEAVE; } -/* //############################################################################################################## -void PerlCallback::call(const std::vector &ints) const +void PerlCallback::call(const std::vector& ints) const //void PerlCallback::call(const std::vector &ints) //############################################################################################################## { @@ -250,16 +249,22 @@ void PerlCallback::call(const std::vector &ints) const ENTER; SAVETMPS; PUSHMARK(SP); - AV* av = newAV(); +//############################################################################################################## for (int i : ints) - av_push(av, newSViv(i)); - XPUSHs(av); + { + XPUSHs(sv_2mortal(newSViv(i))); + } + +// AV* av = newAV(); +// for (int i : ints) +// av_push(av, newSViv(i)); +// XPUSHs(av); +//############################################################################################################## PUTBACK; perl_call_sv(SvRV((SV*)m_callback), G_DISCARD); FREETMPS; LEAVE; } -*/ #ifdef WIN32 #ifndef NOMINMAX diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 12c1fc180..d2ae0a4af 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1999,17 +1999,6 @@ void _3DScene::set_mouse_dragging(wxGLCanvas* canvas, bool dragging) s_canvas_mgr.set_mouse_dragging(canvas, dragging); } -Pointf _3DScene::get_mouse_position(wxGLCanvas* canvas) -{ - return s_canvas_mgr.get_mouse_position(canvas); -} - -void _3DScene::set_mouse_position(wxGLCanvas* canvas, const Pointf* position) -{ - if (position != nullptr) - s_canvas_mgr.set_mouse_position(canvas, *position); -} - int _3DScene::get_hover_volume_id(wxGLCanvas* canvas) { return s_canvas_mgr.get_hover_volume_id(canvas); @@ -2195,6 +2184,16 @@ void _3DScene::register_on_select_callback(wxGLCanvas* canvas, void* callback) s_canvas_mgr.register_on_select_callback(canvas, callback); } +void _3DScene::register_on_model_update_callback(wxGLCanvas* canvas, void* callback) +{ + s_canvas_mgr.register_on_model_update_callback(canvas, callback); +} + +void _3DScene::register_on_move_callback(wxGLCanvas* canvas, void* callback) +{ + s_canvas_mgr.register_on_move_callback(canvas, callback); +} + //void _3DScene::_glew_init() //{ // glewInit(); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 11969df6c..a41188435 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -613,9 +613,6 @@ public: static bool is_mouse_dragging(wxGLCanvas* canvas); static void set_mouse_dragging(wxGLCanvas* canvas, bool dragging); - static Pointf get_mouse_position(wxGLCanvas* canvas); - static void set_mouse_position(wxGLCanvas* canvas, const Pointf* position); - static int get_hover_volume_id(wxGLCanvas* canvas); static void set_hover_volume_id(wxGLCanvas* canvas, int id); @@ -668,6 +665,8 @@ public: static void register_on_double_click_callback(wxGLCanvas* canvas, void* callback); static void register_on_right_click_callback(wxGLCanvas* canvas, void* callback); static void register_on_select_callback(wxGLCanvas* canvas, void* callback); + static void register_on_model_update_callback(wxGLCanvas* canvas, void* callback); + static void register_on_move_callback(wxGLCanvas* canvas, void* callback); // static void _glew_init(); //################################################################################################################## diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 31c7b81b2..53f301ad5 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -301,6 +301,16 @@ const BoundingBoxf3& GLCanvas3D::Bed::get_bounding_box() const return m_bounding_box; } +bool GLCanvas3D::Bed::contains(const Point& point) const +{ + return m_polygon.contains(point); +} + +Point GLCanvas3D::Bed::point_projection(const Point& point) const +{ + return m_polygon.point_projection(point); +} + void GLCanvas3D::Bed::render() const { unsigned int triangles_vcount = m_triangles.get_data_size() / 3; @@ -1049,19 +1059,19 @@ void GLCanvas3D::Mouse::set_position(const Pointf& position) } GLCanvas3D::Drag::Drag() - : m_start_mouse_position(DBL_MAX, DBL_MAX) + : m_start_position_2D(INT_MAX, INT_MAX) , m_volume_idx(-1) { } -const Point& GLCanvas3D::Drag::get_start_mouse_position() const +const Point& GLCanvas3D::Drag::get_start_position_2D() const { - return m_start_mouse_position; + return m_start_position_2D; } -void GLCanvas3D::Drag::set_start_mouse_position(const Point& position) +void GLCanvas3D::Drag::set_start_position_2D(const Point& position) { - m_start_mouse_position = position; + m_start_position_2D = position; } const Pointf3& GLCanvas3D::Drag::get_start_position_3D() const @@ -1843,6 +1853,18 @@ void GLCanvas3D::register_on_select_callback(void* callback) m_on_select_callback.register_callback(callback); } +void GLCanvas3D::register_on_model_update_callback(void* callback) +{ + if (callback != nullptr) + m_on_model_update_callback.register_callback(callback); +} + +void GLCanvas3D::register_on_move_callback(void* callback) +{ + if (callback != nullptr) + m_on_move_callback.register_callback(callback); +} + void GLCanvas3D::on_size(wxSizeEvent& evt) { set_dirty(true); @@ -1954,14 +1976,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) int selected_object_idx = (is_layers_editing_enabled() && (m_print != nullptr)) ? get_layers_editing_first_selected_object_id(m_print->objects.size()) : -1; set_layers_editing_last_object_id(selected_object_idx); - set_mouse_dragging(evt.Dragging()); +// set_mouse_dragging(false); if (evt.Entering()) { #if defined(__WXMSW__) || defined(__WXGTK__) // On Windows and Linux needs focus in order to catch key events m_canvas->SetFocus(); - m_drag.set_start_mouse_position(Point(INT_MAX, INT_MAX)); + m_drag.set_start_position_2D(Point(INT_MAX, INT_MAX)); #endif } else if (evt.LeftDClick()) @@ -1979,7 +2001,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // A volume is selected and the mouse is inside the layer thickness bar. // Start editing the layer height. set_layers_editing_state(1); - perform_layer_editing_action(evt.GetY(), evt.ShiftDown(), evt.RightDown()); + perform_layer_editing_action(pos.y, evt.ShiftDown(), evt.RightDown()); } else if ((selected_object_idx != -1) && reset_rect_contains(pos.x, pos.y)) { @@ -2056,105 +2078,136 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } } -// } elsif($e->Dragging && $e->LeftIsDown && (Slic3r::GUI::_3DScene::get_layers_editing_state($self) == 0) && defined($self->_drag_volume_idx)) { -// # Get new position at the same Z of the initial click point. -// my $cur_pos = Slic3r::Linef3->new( -// $self->mouse_to_3d($e->GetX, $e->GetY, 0), -// $self->mouse_to_3d($e->GetX, $e->GetY, 1)) -// ->intersect_plane($self->_drag_start_pos->z); -// -// # Clip the new position, so the object center remains close to the bed. -// { -// $cur_pos->translate(@{$self->_drag_volume_center_offset}); -// my $cur_pos2 = Slic3r::Point->new(scale($cur_pos->x), scale($cur_pos->y)); -// if (!$self->bed_polygon->contains_point($cur_pos2)) { -// my $ip = $self->bed_polygon->point_projection($cur_pos2); -// $cur_pos->set_x(unscale($ip->x)); -// $cur_pos->set_y(unscale($ip->y)); -// } -// $cur_pos->translate(@{$self->_drag_volume_center_offset->negative}); -// } -// -// # Calculate the translation vector. -// my $vector = $self->_drag_start_pos->vector_to($cur_pos); -// # Get the volume being dragged. -// my $volume = $self->volumes->[$self->_drag_volume_idx]; -// # Get all volumes belonging to the same group, if any. -// my @volumes = ($volume->drag_group_id == -1) ? -// ($volume) : -// grep $_->drag_group_id == $volume->drag_group_id, @{$self->volumes}; -// # Apply new temporary volume origin and ignore Z. -// $_->translate($vector->x, $vector->y, 0) for @volumes; -// $self->_drag_start_pos($cur_pos); -// $self->_dragged(1); -// $self->Refresh; -// $self->Update; -// } elsif($e->Dragging) { -// if ((Slic3r::GUI::_3DScene::get_layers_editing_state($self) > 0) && ($object_idx_selected != -1)) { -// Slic3r::GUI::_3DScene::perform_layer_editing_action($self, $e->GetY, $e->ShiftDown, $e->RightIsDown) if (Slic3r::GUI::_3DScene::get_layers_editing_state($self) == 1); -// } elsif($e->LeftIsDown) { -//# if dragging over blank area with left button, rotate -// if (defined $self->_drag_start_pos) { -// my $orig = $self->_drag_start_pos; -// if (TURNTABLE_MODE) { -// # Turntable mode is enabled by default. -// Slic3r::GUI::_3DScene::set_camera_phi($self, Slic3r::GUI::_3DScene::get_camera_phi($self) + ($pos->x - $orig->x) * TRACKBALLSIZE); -// Slic3r::GUI::_3DScene::set_camera_theta($self, Slic3r::GUI::_3DScene::get_camera_theta($self) - ($pos->y - $orig->y) * TRACKBALLSIZE); -// } -// else { -// my $size = $self->GetClientSize; -// my @quat = trackball( -// $orig->x / ($size->width / 2) - 1, -// 1 - $orig->y / ($size->height / 2), # / -// $pos->x / ($size->width / 2) - 1, -// 1 - $pos->y / ($size->height / 2), # / -// ); -// $self->_quat(mulquats($self->_quat, \@quat)); -// } -// $self->on_viewport_changed->() if $self->on_viewport_changed; -// $self->Refresh; -// $self->Update; -// } -// $self->_drag_start_pos($pos); -// } elsif($e->MiddleIsDown || $e->RightIsDown) { -// # If dragging over blank area with right button, pan. -// if (defined $self->_drag_start_xy) { -// # get point in model space at Z = 0 -// my $cur_pos = $self->mouse_to_3d($e->GetX, $e->GetY, 0); -// my $orig = $self->mouse_to_3d($self->_drag_start_xy->x, $self->_drag_start_xy->y, 0); -// my $camera_target = Slic3r::GUI::_3DScene::get_camera_target($self); -// $camera_target->translate(@{$orig->vector_to($cur_pos)->negative}); -// Slic3r::GUI::_3DScene::set_camera_target($self, $camera_target); -// $self->on_viewport_changed->() if $self->on_viewport_changed; -// $self->Refresh; -// $self->Update; -// } -// $self->_drag_start_xy($pos); -// } -// } elsif($e->LeftUp || $e->MiddleUp || $e->RightUp) { -// if (Slic3r::GUI::_3DScene::get_layers_editing_state($self) > 0) { -// Slic3r::GUI::_3DScene::set_layers_editing_state($self, 0); -// Slic3r::GUI::_3DScene::stop_timer($self); -// $self->on_model_update->() -// if ($object_idx_selected != -1 && $self->on_model_update); -// } elsif($self->on_move && defined($self->_drag_volume_idx) && $self->_dragged) { -// # get all volumes belonging to the same group, if any -// my @volume_idxs; -// my $group_id = $self->volumes->[$self->_drag_volume_idx]->drag_group_id; -// if ($group_id == -1) { -// @volume_idxs = ($self->_drag_volume_idx); -// } -// else { -// @volume_idxs = grep $self->volumes->[$_]->drag_group_id == $group_id, -// 0..$#{$self->volumes}; -// } -// $self->on_move->(@volume_idxs); -// } -// $self->_drag_volume_idx(undef); -// $self->_drag_start_pos(undef); -// $self->_drag_start_xy(undef); -// $self->_dragged(undef); -// } + else if (evt.Dragging() && evt.LeftIsDown() && (get_layers_editing_state() == 0) && (m_drag.get_volume_idx() != -1)) + { + // Get new position at the same Z of the initial click point. + float z0 = 0.0f; + float z1 = 1.0f; + Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_drag.get_start_position_3D().z); + + // Clip the new position, so the object center remains close to the bed. + cur_pos.translate(m_drag.get_volume_center_offset()); + Point cur_pos2(scale_(cur_pos.x), scale_(cur_pos.y)); + if (!m_bed.contains(cur_pos2)) + { + Point ip = m_bed.point_projection(cur_pos2); + cur_pos.x = unscale(ip.x); + cur_pos.y = unscale(ip.y); + } + cur_pos.translate(m_drag.get_volume_center_offset().negative()); + + // Calculate the translation vector. + Vectorf3 vector = m_drag.get_start_position_3D().vector_to(cur_pos); + // Get the volume being dragged. + GLVolume* volume = m_volumes->volumes[m_drag.get_volume_idx()]; + // Get all volumes belonging to the same group, if any. + std::vector volumes; + if (volume->drag_group_id == -1) + volumes.push_back(volume); + else + { + for (GLVolume* v : m_volumes->volumes) + { + if ((v != nullptr) && (v->drag_group_id == volume->drag_group_id)) + volumes.push_back(v); + } + } + + // Apply new temporary volume origin and ignore Z. + for (GLVolume* v : volumes) + { + v->origin.translate(vector.x, vector.y, 0.0); + } + + m_drag.set_start_position_3D(cur_pos); + set_mouse_dragging(true); + m_canvas->Refresh(); + m_canvas->Update(); + } + else if (evt.Dragging()) + { + if ((get_layers_editing_state() > 0) && (selected_object_idx != -1)) + { + if (get_layers_editing_state() == 1) + perform_layer_editing_action(pos.y, evt.ShiftDown(), evt.RightIsDown()); + } + // } elsif($e->LeftIsDown) { + //# if dragging over blank area with left button, rotate + // if (defined $self->_drag_start_pos) { + // my $orig = $self->_drag_start_pos; + // if (TURNTABLE_MODE) { + // # Turntable mode is enabled by default. + // Slic3r::GUI::_3DScene::set_camera_phi($self, Slic3r::GUI::_3DScene::get_camera_phi($self) + ($pos->x - $orig->x) * TRACKBALLSIZE); + // Slic3r::GUI::_3DScene::set_camera_theta($self, Slic3r::GUI::_3DScene::get_camera_theta($self) - ($pos->y - $orig->y) * TRACKBALLSIZE); + // } + // else { + // my $size = $self->GetClientSize; + // my @quat = trackball( + // $orig->x / ($size->width / 2) - 1, + // 1 - $orig->y / ($size->height / 2), # / + // $pos->x / ($size->width / 2) - 1, + // 1 - $pos->y / ($size->height / 2), # / + // ); + // $self->_quat(mulquats($self->_quat, \@quat)); + // } + // $self->on_viewport_changed->() if $self->on_viewport_changed; + // $self->Refresh; + // $self->Update; + // } + // $self->_drag_start_pos($pos); + // } elsif($e->MiddleIsDown || $e->RightIsDown) { + // # If dragging over blank area with right button, pan. + // if (defined $self->_drag_start_xy) { + // # get point in model space at Z = 0 + // my $cur_pos = $self->mouse_to_3d($e->GetX, $e->GetY, 0); + // my $orig = $self->mouse_to_3d($self->_drag_start_xy->x, $self->_drag_start_xy->y, 0); + // my $camera_target = Slic3r::GUI::_3DScene::get_camera_target($self); + // $camera_target->translate(@{$orig->vector_to($cur_pos)->negative}); + // Slic3r::GUI::_3DScene::set_camera_target($self, $camera_target); + // $self->on_viewport_changed->() if $self->on_viewport_changed; + // $self->Refresh; + // $self->Update; + // } + // $self->_drag_start_xy($pos); + // } + } + else if (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()) + { + if (get_layers_editing_state() > 0) + { + set_layers_editing_state(0); + stop_timer(); + + if (selected_object_idx != -1) + m_on_model_update_callback.call(); + } + else if ((m_drag.get_volume_idx() != -1) && m_mouse.is_dragging()) + { + // get all volumes belonging to the same group, if any + std::vector volume_idxs; + int vol_id = m_drag.get_volume_idx(); + int group_id = m_volumes->volumes[vol_id]->drag_group_id; + if (group_id == -1) + { + volume_idxs.push_back(vol_id); + } + else + { + for (int i = 0; i < m_volumes->volumes.size(); ++i) + { + if (m_volumes->volumes[i]->drag_group_id == group_id) + volume_idxs.push_back(i); + } + } + + m_on_move_callback.call(volume_idxs); + } + + m_drag.set_volume_idx(-1); + m_drag.set_start_position_3D(Pointf3(DBL_MAX, DBL_MAX, DBL_MAX)); + m_drag.set_start_position_2D(Point(INT_MAX, INT_MAX)); + set_mouse_dragging(false); + } else if (evt.Moving()) { set_mouse_position(Pointf((coordf_t)pos.x, (coordf_t)pos.y)); @@ -2300,6 +2353,8 @@ void GLCanvas3D::_deregister_callbacks() m_on_double_click_callback.deregister_callback(); m_on_right_click_callback.deregister_callback(); m_on_select_callback.deregister_callback(); + m_on_model_update_callback.deregister_callback(); + m_on_move_callback.deregister_callback(); } void GLCanvas3D::_mark_volumes_for_layer_height() const @@ -2655,12 +2710,12 @@ Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) GLint y = viewport[3] - (GLint)mouse_pos.y; GLfloat mouse_z; if (z == nullptr) - ::glReadPixels((GLint)mouse_pos.x, (GLint)mouse_pos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z); + ::glReadPixels((GLint)mouse_pos.x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z); else mouse_z = *z; GLdouble out_x, out_y, out_z; - ::gluUnProject((GLdouble)mouse_pos.x, (GLdouble)mouse_pos.y, mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z); + ::gluUnProject((GLdouble)mouse_pos.x, (GLdouble)y, mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z); return Pointf3((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z); } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 7d490984f..404d65e26 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -136,6 +136,8 @@ public: void set_shape(const Pointfs& shape); const BoundingBoxf3& get_bounding_box() const; + bool contains(const Point& point) const; + Point point_projection(const Point& point) const; void render() const; @@ -308,7 +310,7 @@ public: class Drag { - Point m_start_mouse_position; + Point m_start_position_2D; Pointf3 m_start_position_3D; Vectorf3 m_volume_center_offset; int m_volume_idx; @@ -316,8 +318,8 @@ public: public: Drag(); - const Point& get_start_mouse_position() const; - void set_start_mouse_position(const Point& mouse_position); + const Point& get_start_position_2D() const; + void set_start_position_2D(const Point& position); const Pointf3& get_start_position_3D() const; void set_start_position_3D(const Pointf3& position); @@ -360,6 +362,8 @@ private: PerlCallback m_on_double_click_callback; PerlCallback m_on_right_click_callback; PerlCallback m_on_select_callback; + PerlCallback m_on_model_update_callback; + PerlCallback m_on_move_callback; public: GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context); @@ -492,6 +496,8 @@ public: void register_on_double_click_callback(void* callback); void register_on_right_click_callback(void* callback); void register_on_select_callback(void* callback); + void register_on_model_update_callback(void* callback); + void register_on_move_callback(void* callback); void on_size(wxSizeEvent& evt); void on_idle(wxIdleEvent& evt); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index c1eb7f37a..e9a4d6ce8 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -476,19 +476,6 @@ void GLCanvas3DManager::set_mouse_dragging(wxGLCanvas* canvas, bool dragging) it->second->set_mouse_dragging(dragging); } -Pointf GLCanvas3DManager::get_mouse_position(wxGLCanvas* canvas) const -{ - CanvasesMap::const_iterator it = _get_canvas(canvas); - return (it != m_canvases.end()) ? it->second->get_mouse_position() : Pointf(); -} - -void GLCanvas3DManager::set_mouse_position(wxGLCanvas* canvas, const Pointf& position) -{ - CanvasesMap::iterator it = _get_canvas(canvas); - if (it != m_canvases.end()) - it->second->set_mouse_position(position); -} - int GLCanvas3DManager::get_hover_volume_id(wxGLCanvas* canvas) const { CanvasesMap::const_iterator it = _get_canvas(canvas); @@ -738,6 +725,20 @@ void GLCanvas3DManager::register_on_select_callback(wxGLCanvas* canvas, void* ca it->second->register_on_select_callback(callback); } +void GLCanvas3DManager::register_on_model_update_callback(wxGLCanvas* canvas, void* callback) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->register_on_model_update_callback(callback); +} + +void GLCanvas3DManager::register_on_move_callback(wxGLCanvas* canvas, void* callback) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->register_on_move_callback(callback); +} + GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas) { return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index da6e00e7b..bf6ac91ee 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -113,9 +113,6 @@ public: bool is_mouse_dragging(wxGLCanvas* canvas) const; void set_mouse_dragging(wxGLCanvas* canvas, bool dragging); - Pointf get_mouse_position(wxGLCanvas* canvas) const; - void set_mouse_position(wxGLCanvas* canvas, const Pointf& position); - int get_hover_volume_id(wxGLCanvas* canvas) const; void set_hover_volume_id(wxGLCanvas* canvas, int id); @@ -168,6 +165,8 @@ public: void register_on_double_click_callback(wxGLCanvas* canvas, void* callback); void register_on_right_click_callback(wxGLCanvas* canvas, void* callback); void register_on_select_callback(wxGLCanvas* canvas, void* callback); + void register_on_model_update_callback(wxGLCanvas* canvas, void* callback); + void register_on_move_callback(wxGLCanvas* canvas, void* callback); private: CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 8023efab2..21b872cfd 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -555,21 +555,6 @@ set_mouse_dragging(canvas, dragging) CODE: _3DScene::set_mouse_dragging((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), dragging); -Clone -get_mouse_position(canvas) - SV *canvas; - CODE: - RETVAL = _3DScene::get_mouse_position((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); - OUTPUT: - RETVAL - -void -set_mouse_position(canvas, position) - SV *canvas; - Pointf *position; - CODE: - _3DScene::set_mouse_position((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), position); - int get_hover_volume_id(canvas) SV *canvas; @@ -846,7 +831,21 @@ register_on_select_callback(canvas, callback) SV *callback; CODE: _3DScene::register_on_select_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); - + +void +register_on_model_update_callback(canvas, callback) + SV *canvas; + SV *callback; + CODE: + _3DScene::register_on_model_update_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); + +void +register_on_move_callback(canvas, callback) + SV *canvas; + SV *callback; + CODE: + _3DScene::register_on_move_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); + unsigned int finalize_legend_texture()