class 3D on_select callback moved to c++
This commit is contained in:
parent
bf2fd54578
commit
96d9879d72
@ -78,7 +78,10 @@ sub new {
|
||||
my $on_select_object = sub {
|
||||
my ($obj_idx) = @_;
|
||||
# Ignore the special objects (the wipe tower proxy and such).
|
||||
$self->select_object((defined($obj_idx) && $obj_idx < 1000) ? $obj_idx : undef);
|
||||
#==============================================================================================================================
|
||||
$self->select_object((defined($obj_idx) && $obj_idx >= 0 && $obj_idx < 1000) ? $obj_idx : undef);
|
||||
# $self->select_object((defined($obj_idx) && $obj_idx < 1000) ? $obj_idx : undef);
|
||||
#==============================================================================================================================
|
||||
};
|
||||
my $on_double_click = sub {
|
||||
$self->object_settings_dialog if $self->selected_object;
|
||||
@ -116,8 +119,8 @@ sub new {
|
||||
if ($Slic3r::GUI::have_OpenGL) {
|
||||
$self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{print}, $self->{config});
|
||||
$self->{preview_notebook}->AddPage($self->{canvas3D}, L('3D'));
|
||||
$self->{canvas3D}->set_on_select_object($on_select_object);
|
||||
#==============================================================================================================================
|
||||
Slic3r::GUI::_3DScene::register_on_select_object_callback($self->{canvas3D}, $on_select_object);
|
||||
Slic3r::GUI::_3DScene::register_on_double_click_callback($self->{canvas3D}, $on_double_click);
|
||||
Slic3r::GUI::_3DScene::register_on_right_click_callback($self->{canvas3D}, sub { $on_right_click->($self->{canvas3D}, @_); });
|
||||
Slic3r::GUI::_3DScene::register_on_arrange_callback($self->{canvas3D}, sub { $self->arrange });
|
||||
@ -151,6 +154,7 @@ sub new {
|
||||
|
||||
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_select_object($on_select_object);
|
||||
# $self->{canvas3D}->set_on_double_click($on_double_click);
|
||||
# $self->{canvas3D}->set_on_right_click(sub { $on_right_click->($self->{canvas3D}, @_); });
|
||||
# $self->{canvas3D}->set_on_arrange(sub { $self->arrange });
|
||||
|
@ -10,9 +10,9 @@ use Wx qw(:misc :pen :brush :sizer :font :cursor :keycode wxTAB_TRAVERSAL);
|
||||
#==============================================================================================================================
|
||||
use base qw(Slic3r::GUI::3DScene Class::Accessor);
|
||||
|
||||
use Wx::Locale gettext => 'L';
|
||||
|
||||
#==============================================================================================================================
|
||||
#use Wx::Locale gettext => 'L';
|
||||
#
|
||||
#__PACKAGE__->mk_accessors(qw(
|
||||
# on_arrange on_rotate_object_left on_rotate_object_right on_scale_object_uniformly
|
||||
# on_remove_object on_increase_objects on_decrease_objects on_enable_action_buttons));
|
||||
@ -28,37 +28,24 @@ sub new {
|
||||
Slic3r::GUI::_3DScene::enable_moving($self, 1);
|
||||
Slic3r::GUI::_3DScene::set_select_by($self, 'object');
|
||||
Slic3r::GUI::_3DScene::set_drag_by($self, 'instance');
|
||||
Slic3r::GUI::_3DScene::set_model($self, $model);
|
||||
Slic3r::GUI::_3DScene::set_print($self, $print);
|
||||
Slic3r::GUI::_3DScene::set_config($self, $config);
|
||||
# $self->enable_picking(1);
|
||||
# $self->enable_moving(1);
|
||||
# $self->select_by('object');
|
||||
# $self->drag_by('instance');
|
||||
#
|
||||
# $self->{objects} = $objects;
|
||||
#==============================================================================================================================
|
||||
$self->{model} = $model;
|
||||
#==============================================================================================================================
|
||||
# $self->{model} = $model;
|
||||
# $self->{print} = $print;
|
||||
#==============================================================================================================================
|
||||
$self->{config} = $config;
|
||||
#==============================================================================================================================
|
||||
Slic3r::GUI::_3DScene::set_model($self, $model);
|
||||
Slic3r::GUI::_3DScene::set_print($self, $print);
|
||||
Slic3r::GUI::_3DScene::set_config($self, $config);
|
||||
#==============================================================================================================================
|
||||
$self->{on_select_object} = sub {};
|
||||
#==============================================================================================================================
|
||||
# $self->{config} = $config;
|
||||
# $self->{on_select_object} = sub {};
|
||||
# $self->{on_instances_moved} = sub {};
|
||||
# $self->{on_wipe_tower_moved} = sub {};
|
||||
#
|
||||
# $self->{objects_volumes_idxs} = [];
|
||||
#==============================================================================================================================
|
||||
|
||||
#==============================================================================================================================
|
||||
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});
|
||||
});
|
||||
#
|
||||
# $self->on_select(sub {
|
||||
# my ($volume_idx) = @_;
|
||||
# $self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
|
||||
@ -139,12 +126,12 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_on_select_object {
|
||||
my ($self, $cb) = @_;
|
||||
$self->{on_select_object} = $cb;
|
||||
}
|
||||
|
||||
#==============================================================================================================================
|
||||
#sub set_on_select_object {
|
||||
# my ($self, $cb) = @_;
|
||||
# $self->{on_select_object} = $cb;
|
||||
#}
|
||||
#
|
||||
#sub set_on_double_click {
|
||||
# my ($self, $cb) = @_;
|
||||
# $self->on_double_click($cb);
|
||||
|
@ -2002,9 +2002,9 @@ void _3DScene::register_on_right_click_callback(wxGLCanvas* canvas, void* callba
|
||||
s_canvas_mgr.register_on_right_click_callback(canvas, callback);
|
||||
}
|
||||
|
||||
void _3DScene::register_on_select_callback(wxGLCanvas* canvas, void* callback)
|
||||
void _3DScene::register_on_select_object_callback(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
s_canvas_mgr.register_on_select_callback(canvas, callback);
|
||||
s_canvas_mgr.register_on_select_object_callback(canvas, callback);
|
||||
}
|
||||
|
||||
void _3DScene::register_on_model_update_callback(wxGLCanvas* canvas, void* callback)
|
||||
|
@ -613,7 +613,7 @@ public:
|
||||
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);
|
||||
static void register_on_select_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_on_select_object_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_on_model_update_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_on_remove_object_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_on_arrange_callback(wxGLCanvas* canvas, void* callback);
|
||||
|
@ -1935,10 +1935,10 @@ void GLCanvas3D::register_on_right_click_callback(void* callback)
|
||||
m_on_right_click_callback.register_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3D::register_on_select_callback(void* callback)
|
||||
void GLCanvas3D::register_on_select_object_callback(void* callback)
|
||||
{
|
||||
if (callback != nullptr)
|
||||
m_on_select_callback.register_callback(callback);
|
||||
m_on_select_object_callback.register_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3D::register_on_model_update_callback(void* callback)
|
||||
@ -2255,7 +2255,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
}
|
||||
|
||||
// propagate event through callback
|
||||
m_on_select_callback.call(volume_idx);
|
||||
if (m_picking_enabled)
|
||||
_on_select(volume_idx);
|
||||
|
||||
// The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y,
|
||||
// an converts the screen space coordinate to unscaled object space.
|
||||
@ -2632,7 +2633,7 @@ void GLCanvas3D::_deregister_callbacks()
|
||||
m_on_viewport_changed_callback.deregister_callback();
|
||||
m_on_double_click_callback.deregister_callback();
|
||||
m_on_right_click_callback.deregister_callback();
|
||||
m_on_select_callback.deregister_callback();
|
||||
m_on_select_object_callback.deregister_callback();
|
||||
m_on_model_update_callback.deregister_callback();
|
||||
m_on_remove_object_callback.deregister_callback();
|
||||
m_on_arrange_callback.deregister_callback();
|
||||
@ -3710,10 +3711,19 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
|
||||
m_on_wipe_tower_moved_callback.call(wipe_tower_origin.x, wipe_tower_origin.y);
|
||||
}
|
||||
|
||||
void GLCanvas3D::_on_select(int volume_idx)
|
||||
{
|
||||
if ((m_volumes != nullptr) && (volume_idx < (int)m_volumes->volumes.size()))
|
||||
m_on_select_object_callback.call((volume_idx == -1) ? -1 : m_volumes->volumes[volume_idx]->object_idx());
|
||||
}
|
||||
|
||||
std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
||||
{
|
||||
static const float INV_255 = 1.0f / 255.0f;
|
||||
|
||||
std::vector<float> output(colors.size() * 4, 1.0f);
|
||||
for (size_t i = 0; i < colors.size(); ++i) {
|
||||
for (size_t i = 0; i < colors.size(); ++i)
|
||||
{
|
||||
const std::string& color = colors[i];
|
||||
const char* c = color.data() + 1;
|
||||
if ((color.size() == 7) && (color.front() == '#'))
|
||||
@ -3725,7 +3735,7 @@ std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& col
|
||||
if ((digit1 == -1) || (digit2 == -1))
|
||||
break;
|
||||
|
||||
output[i * 4 + j] = float(digit1 * 16 + digit2) / 255.0f;
|
||||
output[i * 4 + j] = float(digit1 * 16 + digit2) * INV_255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ private:
|
||||
PerlCallback m_on_viewport_changed_callback;
|
||||
PerlCallback m_on_double_click_callback;
|
||||
PerlCallback m_on_right_click_callback;
|
||||
PerlCallback m_on_select_callback;
|
||||
PerlCallback m_on_select_object_callback;
|
||||
PerlCallback m_on_model_update_callback;
|
||||
PerlCallback m_on_remove_object_callback;
|
||||
PerlCallback m_on_arrange_callback;
|
||||
@ -461,7 +461,7 @@ public:
|
||||
void register_on_viewport_changed_callback(void* callback);
|
||||
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_select_object_callback(void* callback);
|
||||
void register_on_model_update_callback(void* callback);
|
||||
void register_on_remove_object_callback(void* callback);
|
||||
void register_on_arrange_callback(void* callback);
|
||||
@ -547,6 +547,7 @@ private:
|
||||
void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data);
|
||||
|
||||
void _on_move(const std::vector<int>& volume_idxs);
|
||||
void _on_select(int volume_idx);
|
||||
|
||||
static std::vector<float> _parse_colors(const std::vector<std::string>& colors);
|
||||
};
|
||||
|
@ -563,11 +563,11 @@ void GLCanvas3DManager::register_on_right_click_callback(wxGLCanvas* canvas, voi
|
||||
it->second->register_on_right_click_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::register_on_select_callback(wxGLCanvas* canvas, void* callback)
|
||||
void GLCanvas3DManager::register_on_select_object_callback(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->register_on_select_callback(callback);
|
||||
it->second->register_on_select_object_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::register_on_model_update_callback(wxGLCanvas* canvas, void* callback)
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
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);
|
||||
void register_on_select_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_on_select_object_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_on_model_update_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_on_remove_object_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_on_arrange_callback(wxGLCanvas* canvas, void* callback);
|
||||
|
@ -482,11 +482,11 @@ register_on_right_click_callback(canvas, callback)
|
||||
_3DScene::register_on_right_click_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||
|
||||
void
|
||||
register_on_select_callback(canvas, callback)
|
||||
register_on_select_object_callback(canvas, callback)
|
||||
SV *canvas;
|
||||
SV *callback;
|
||||
CODE:
|
||||
_3DScene::register_on_select_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||
_3DScene::register_on_select_object_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||
|
||||
void
|
||||
register_on_model_update_callback(canvas, callback)
|
||||
|
Loading…
Reference in New Issue
Block a user