3DScene mouse variables moved to c++

This commit is contained in:
Enrico Turri 2018-05-23 13:56:54 +02:00
parent b36243ba10
commit 90c50b281a
8 changed files with 192 additions and 32 deletions

View file

@ -37,14 +37,12 @@ use Slic3r::Geometry qw(PI);
__PACKAGE__->mk_accessors( qw(_quat init __PACKAGE__->mk_accessors( qw(_quat init
enable_moving enable_moving
on_viewport_changed on_viewport_changed
on_hover
on_select on_select
on_double_click on_double_click
on_right_click on_right_click
on_move on_move
on_model_update on_model_update
volumes volumes
_mouse_pos
_hover_volume_idx _hover_volume_idx
_drag_volume_idx _drag_volume_idx
@ -54,8 +52,6 @@ __PACKAGE__->mk_accessors( qw(_quat init
_dragged _dragged
_layer_height_edited _layer_height_edited
_mouse_dragging
) ); ) );
#__PACKAGE__->mk_accessors( qw(_quat _dirty init #__PACKAGE__->mk_accessors( qw(_quat _dirty init
@ -192,8 +188,8 @@ sub new {
# $self->_warning_enabled(0); # $self->_warning_enabled(0);
# $self->use_plain_shader(0); # $self->use_plain_shader(0);
# $self->_apply_zoom_to_volumes_filter(0); # $self->_apply_zoom_to_volumes_filter(0);
# $self->_mouse_dragging(0);
#============================================================================================================================== #==============================================================================================================================
$self->_mouse_dragging(0);
# Collection of GLVolume objects # Collection of GLVolume objects
$self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new); $self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new);
@ -287,7 +283,7 @@ sub new {
$self->mark_volumes_for_layer_height; $self->mark_volumes_for_layer_height;
}; };
Slic3r::GUI::_3DScene::register_on_mark_volumes_for_layer_height($self, $on_mark_volumes_for_layer_height); Slic3r::GUI::_3DScene::register_on_mark_volumes_for_layer_height_callback($self, $on_mark_volumes_for_layer_height);
#============================================================================================================================== #==============================================================================================================================
return $self; return $self;
@ -473,7 +469,10 @@ sub mouse_event {
my $pos = Slic3r::Pointf->new($e->GetPositionXY); my $pos = Slic3r::Pointf->new($e->GetPositionXY);
my $object_idx_selected = $self->{layer_height_edit_last_object_id} = ($self->layer_editing_enabled && $self->{print}) ? $self->_first_selected_object_id_for_variable_layer_height_editing : -1; my $object_idx_selected = $self->{layer_height_edit_last_object_id} = ($self->layer_editing_enabled && $self->{print}) ? $self->_first_selected_object_id_for_variable_layer_height_editing : -1;
$self->_mouse_dragging($e->Dragging); #==============================================================================================================================
Slic3r::GUI::_3DScene::set_mouse_dragging($self, $e->Dragging);
# $self->_mouse_dragging($e->Dragging);
#==============================================================================================================================
if ($e->Entering && (&Wx::wxMSW || $^O eq 'linux')) { if ($e->Entering && (&Wx::wxMSW || $^O eq 'linux')) {
# wxMSW needs focus in order to catch mouse wheel events # wxMSW needs focus in order to catch mouse wheel events
@ -662,7 +661,10 @@ sub mouse_event {
$self->_drag_start_xy(undef); $self->_drag_start_xy(undef);
$self->_dragged(undef); $self->_dragged(undef);
} elsif ($e->Moving) { } elsif ($e->Moving) {
$self->_mouse_pos($pos); #==============================================================================================================================
Slic3r::GUI::_3DScene::set_mouse_position($self, $pos);
# $self->_mouse_pos($pos);
#==============================================================================================================================
# Only refresh if picking is enabled, in that case the objects may get highlighted if the mouse cursor # Only refresh if picking is enabled, in that case the objects may get highlighted if the mouse cursor
# hovers over. # hovers over.
#============================================================================================================================== #==============================================================================================================================
@ -1474,10 +1476,12 @@ sub Render {
glLightfv_p(GL_LIGHT1, GL_POSITION, 1, 0, 1, 0); glLightfv_p(GL_LIGHT1, GL_POSITION, 1, 0, 1, 0);
#============================================================================================================================== #==============================================================================================================================
if (Slic3r::GUI::_3DScene::is_picking_enabled($self) && !$self->_mouse_dragging) { if (Slic3r::GUI::_3DScene::is_picking_enabled($self) && !Slic3r::GUI::_3DScene::is_mouse_dragging($self)) {
my $pos = Slic3r::GUI::_3DScene::get_mouse_position($self);
if ($pos) {
# if ($self->enable_picking && !$self->_mouse_dragging) { # if ($self->enable_picking && !$self->_mouse_dragging) {
# if (my $pos = $self->_mouse_pos) {
#============================================================================================================================== #==============================================================================================================================
if (my $pos = $self->_mouse_pos) {
# Render the object for picking. # Render the object for picking.
# FIXME This cannot possibly work in a multi-sampled context as the color gets mangled by the anti-aliasing. # FIXME This cannot possibly work in a multi-sampled context as the color gets mangled by the anti-aliasing.
# Better to use software ray-casting on a bounding-box hierarchy. # Better to use software ray-casting on a bounding-box hierarchy.
@ -1504,7 +1508,9 @@ sub Render {
$_->set_hover(1) for grep { $_->select_group_id == $group_id } @{$self->volumes}; $_->set_hover(1) for grep { $_->select_group_id == $group_id } @{$self->volumes};
} }
$self->on_hover->($volume_idx) if $self->on_hover; #==============================================================================================================================
# $self->on_hover->($volume_idx) if $self->on_hover;
#==============================================================================================================================
} }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} }

View file

@ -1915,7 +1915,8 @@ Pointf3 _3DScene::get_camera_target(wxGLCanvas* canvas)
void _3DScene::set_camera_target(wxGLCanvas* canvas, const Pointf3* target) void _3DScene::set_camera_target(wxGLCanvas* canvas, const Pointf3* target)
{ {
s_canvas_mgr.set_camera_target(canvas, target); if (target != nullptr)
s_canvas_mgr.set_camera_target(canvas, *target);
} }
bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas) bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas)
@ -1953,6 +1954,27 @@ void _3DScene::enable_shader(wxGLCanvas* canvas, bool enable)
s_canvas_mgr.enable_shader(canvas, enable); s_canvas_mgr.enable_shader(canvas, enable);
} }
bool _3DScene::is_mouse_dragging(wxGLCanvas* canvas)
{
return s_canvas_mgr.is_mouse_dragging(canvas);
}
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);
}
void _3DScene::zoom_to_bed(wxGLCanvas* canvas) void _3DScene::zoom_to_bed(wxGLCanvas* canvas)
{ {
s_canvas_mgr.zoom_to_bed(canvas); s_canvas_mgr.zoom_to_bed(canvas);
@ -2028,9 +2050,9 @@ void _3DScene::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* c
s_canvas_mgr.register_on_viewport_changed_callback(canvas, callback); s_canvas_mgr.register_on_viewport_changed_callback(canvas, callback);
} }
void _3DScene::register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback) void _3DScene::register_on_mark_volumes_for_layer_height_callback(wxGLCanvas* canvas, void* callback)
{ {
s_canvas_mgr.register_on_mark_volumes_for_layer_height(canvas, callback); s_canvas_mgr.register_on_mark_volumes_for_layer_height_callback(canvas, callback);
} }
//void _3DScene::_glew_init() //void _3DScene::_glew_init()

View file

@ -603,6 +603,12 @@ public:
static void enable_picking(wxGLCanvas* canvas, bool enable); static void enable_picking(wxGLCanvas* canvas, bool enable);
static void enable_shader(wxGLCanvas* canvas, bool enable); static void enable_shader(wxGLCanvas* canvas, bool enable);
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 void zoom_to_bed(wxGLCanvas* canvas); static void zoom_to_bed(wxGLCanvas* canvas);
static void zoom_to_volumes(wxGLCanvas* canvas); static void zoom_to_volumes(wxGLCanvas* canvas);
static void select_view(wxGLCanvas* canvas, const std::string& direction); static void select_view(wxGLCanvas* canvas, const std::string& direction);
@ -622,7 +628,7 @@ public:
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top); static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);
static void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback); static void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
static void register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback); static void register_on_mark_volumes_for_layer_height_callback(wxGLCanvas* canvas, void* callback);
// static void _glew_init(); // static void _glew_init();
//################################################################################################################## //##################################################################################################################

View file

@ -474,6 +474,31 @@ void GLCanvas3D::Shader::stop() const
m_shader->disable(); m_shader->disable();
} }
GLCanvas3D::Mouse::Mouse()
: m_dragging(false)
{
}
bool GLCanvas3D::Mouse::is_dragging() const
{
return m_dragging;
}
void GLCanvas3D::Mouse::set_dragging(bool dragging)
{
m_dragging = dragging;
}
const Pointf& GLCanvas3D::Mouse::get_position() const
{
return m_position;
}
void GLCanvas3D::Mouse::set_position(const Pointf& position)
{
m_position = position;
}
GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context) GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
: m_canvas(canvas) : m_canvas(canvas)
, m_context(context) , m_context(context)
@ -804,6 +829,26 @@ void GLCanvas3D::enable_shader(bool enable)
m_shader.set_enabled(enable); m_shader.set_enabled(enable);
} }
bool GLCanvas3D::is_mouse_dragging() const
{
return m_mouse.is_dragging();
}
void GLCanvas3D::set_mouse_dragging(bool dragging)
{
m_mouse.set_dragging(dragging);
}
const Pointf& GLCanvas3D::get_mouse_position() const
{
return m_mouse.get_position();
}
void GLCanvas3D::set_mouse_position(const Pointf& position)
{
m_mouse.set_position(position);
}
void GLCanvas3D::zoom_to_bed() void GLCanvas3D::zoom_to_bed()
{ {
_zoom_to_bounding_box(bed_bounding_box()); _zoom_to_bounding_box(bed_bounding_box());
@ -960,7 +1005,7 @@ void GLCanvas3D::render_objects(bool useVBOs)
{ {
if (is_picking_enabled()) if (is_picking_enabled())
{ {
m_on_mark_volumes_for_layer_height.call(); m_on_mark_volumes_for_layer_height_callback.call();
if (m_config != nullptr) if (m_config != nullptr)
{ {
@ -1093,10 +1138,10 @@ void GLCanvas3D::register_on_viewport_changed_callback(void* callback)
m_on_viewport_changed_callback.register_callback(callback); m_on_viewport_changed_callback.register_callback(callback);
} }
void GLCanvas3D::register_on_mark_volumes_for_layer_height(void* callback) void GLCanvas3D::register_on_mark_volumes_for_layer_height_callback(void* callback)
{ {
if (callback != nullptr) if (callback != nullptr)
m_on_mark_volumes_for_layer_height.register_callback(callback); m_on_mark_volumes_for_layer_height_callback.register_callback(callback);
} }
void GLCanvas3D::on_size(wxSizeEvent& evt) void GLCanvas3D::on_size(wxSizeEvent& evt)
@ -1273,7 +1318,7 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co
void GLCanvas3D::_deregister_callbacks() void GLCanvas3D::_deregister_callbacks()
{ {
m_on_viewport_changed_callback.deregister_callback(); m_on_viewport_changed_callback.deregister_callback();
m_on_mark_volumes_for_layer_height.deregister_callback(); m_on_mark_volumes_for_layer_height_callback.deregister_callback();
} }
} // namespace GUI } // namespace GUI

View file

@ -161,6 +161,21 @@ public:
void stop() const; void stop() const;
}; };
class Mouse
{
bool m_dragging;
Pointf m_position;
public:
Mouse();
bool is_dragging() const;
void set_dragging(bool dragging);
const Pointf& get_position() const;
void set_position(const Pointf& position);
};
private: private:
wxGLCanvas* m_canvas; wxGLCanvas* m_canvas;
wxGLContext* m_context; wxGLContext* m_context;
@ -170,6 +185,7 @@ private:
CuttingPlane m_cutting_plane; CuttingPlane m_cutting_plane;
LayersEditing m_layers_editing; LayersEditing m_layers_editing;
Shader m_shader; Shader m_shader;
Mouse m_mouse;
GLVolumeCollection* m_volumes; GLVolumeCollection* m_volumes;
DynamicPrintConfig* m_config; DynamicPrintConfig* m_config;
@ -181,7 +197,7 @@ private:
bool m_picking_enabled; bool m_picking_enabled;
PerlCallback m_on_viewport_changed_callback; PerlCallback m_on_viewport_changed_callback;
PerlCallback m_on_mark_volumes_for_layer_height; PerlCallback m_on_mark_volumes_for_layer_height_callback;
public: public:
GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context); GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context);
@ -253,6 +269,12 @@ public:
void enable_picking(bool enable); void enable_picking(bool enable);
void enable_shader(bool enable); void enable_shader(bool enable);
bool is_mouse_dragging() const;
void set_mouse_dragging(bool dragging);
const Pointf& get_mouse_position() const;
void set_mouse_position(const Pointf& position);
void zoom_to_bed(); void zoom_to_bed();
void zoom_to_volumes(); void zoom_to_volumes();
void select_view(const std::string& direction); void select_view(const std::string& direction);
@ -272,7 +294,7 @@ public:
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const; void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const;
void register_on_viewport_changed_callback(void* callback); void register_on_viewport_changed_callback(void* callback);
void register_on_mark_volumes_for_layer_height(void* callback); void register_on_mark_volumes_for_layer_height_callback(void* callback);
void on_size(wxSizeEvent& evt); void on_size(wxSizeEvent& evt);
void on_idle(wxIdleEvent& evt); void on_idle(wxIdleEvent& evt);

View file

@ -358,14 +358,11 @@ Pointf3 GLCanvas3DManager::get_camera_target(wxGLCanvas* canvas) const
return (it != m_canvases.end()) ? it->second->get_camera_target() : Pointf3(0.0, 0.0, 0.0); return (it != m_canvases.end()) ? it->second->get_camera_target() : Pointf3(0.0, 0.0, 0.0);
} }
void GLCanvas3DManager::set_camera_target(wxGLCanvas* canvas, const Pointf3* target) void GLCanvas3DManager::set_camera_target(wxGLCanvas* canvas, const Pointf3& target)
{ {
if (target == nullptr)
return;
CanvasesMap::iterator it = _get_canvas(canvas); CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end()) if (it != m_canvases.end())
it->second->set_camera_target(*target); it->second->set_camera_target(target);
} }
bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const
@ -414,6 +411,32 @@ void GLCanvas3DManager::enable_shader(wxGLCanvas* canvas, bool enable)
it->second->enable_shader(enable); it->second->enable_shader(enable);
} }
bool GLCanvas3DManager::is_mouse_dragging(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->is_mouse_dragging() : false;
}
void GLCanvas3DManager::set_mouse_dragging(wxGLCanvas* canvas, bool dragging)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
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);
}
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas) void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
{ {
CanvasesMap::iterator it = _get_canvas(canvas); CanvasesMap::iterator it = _get_canvas(canvas);
@ -518,11 +541,11 @@ void GLCanvas3DManager::register_on_viewport_changed_callback(wxGLCanvas* canvas
it->second->register_on_viewport_changed_callback(callback); it->second->register_on_viewport_changed_callback(callback);
} }
void GLCanvas3DManager::register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback) void GLCanvas3DManager::register_on_mark_volumes_for_layer_height_callback(wxGLCanvas* canvas, void* callback)
{ {
CanvasesMap::iterator it = _get_canvas(canvas); CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end()) if (it != m_canvases.end())
it->second->register_on_mark_volumes_for_layer_height(callback); it->second->register_on_mark_volumes_for_layer_height_callback(callback);
} }
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas) GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)

View file

@ -100,7 +100,7 @@ public:
void set_camera_distance(wxGLCanvas* canvas, float distance); void set_camera_distance(wxGLCanvas* canvas, float distance);
Pointf3 get_camera_target(wxGLCanvas* canvas) const; Pointf3 get_camera_target(wxGLCanvas* canvas) const;
void set_camera_target(wxGLCanvas* canvas, const Pointf3* target); void set_camera_target(wxGLCanvas* canvas, const Pointf3& target);
bool is_layers_editing_enabled(wxGLCanvas* canvas) const; bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
bool is_picking_enabled(wxGLCanvas* canvas) const; bool is_picking_enabled(wxGLCanvas* canvas) const;
@ -111,6 +111,12 @@ public:
void enable_picking(wxGLCanvas* canvas, bool enable); void enable_picking(wxGLCanvas* canvas, bool enable);
void enable_shader(wxGLCanvas* canvas, bool enable); void enable_shader(wxGLCanvas* canvas, bool enable);
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);
void zoom_to_bed(wxGLCanvas* canvas); void zoom_to_bed(wxGLCanvas* canvas);
void zoom_to_volumes(wxGLCanvas* canvas); void zoom_to_volumes(wxGLCanvas* canvas);
void select_view(wxGLCanvas* canvas, const std::string& direction); void select_view(wxGLCanvas* canvas, const std::string& direction);
@ -130,7 +136,7 @@ public:
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const; void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const;
void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback); void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
void register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback); void register_on_mark_volumes_for_layer_height_callback(wxGLCanvas* canvas, void* callback);
private: private:
CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas); CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas);

View file

@ -483,6 +483,36 @@ enable_shader(canvas, enable)
CODE: CODE:
_3DScene::enable_shader((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable); _3DScene::enable_shader((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
bool
is_mouse_dragging(canvas)
SV *canvas;
CODE:
RETVAL = _3DScene::is_mouse_dragging((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
OUTPUT:
RETVAL
void
set_mouse_dragging(canvas, dragging)
SV *canvas;
bool dragging;
CODE:
_3DScene::set_mouse_dragging((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), dragging);
Clone<Pointf>
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);
void void
zoom_to_bed(canvas) zoom_to_bed(canvas)
SV *canvas; SV *canvas;
@ -585,11 +615,11 @@ register_on_viewport_changed_callback(canvas, callback)
_3DScene::register_on_viewport_changed_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); _3DScene::register_on_viewport_changed_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
void void
register_on_mark_volumes_for_layer_height(canvas, callback) register_on_mark_volumes_for_layer_height_callback(canvas, callback)
SV *canvas; SV *canvas;
SV *callback; SV *callback;
CODE: CODE:
_3DScene::register_on_mark_volumes_for_layer_height((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); _3DScene::register_on_mark_volumes_for_layer_height_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);