Plater & GLCanvas3D: Fix instance_moved event, add event handlers

This commit is contained in:
Vojtech Kral 2018-10-09 17:14:59 +02:00
parent 895bdf7918
commit bd85ca721e
3 changed files with 59 additions and 31 deletions

View file

@ -2476,7 +2476,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ROTATE_OBJECT, Event<int>);
wxDEFINE_EVENT(EVT_GLCANVAS_SCALE_UNIFORMLY, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_INCREASE_OBJECTS, Event<int>);
wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_MOVES, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>);
wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>);
@ -6268,7 +6268,7 @@ void GLCanvas3D::_on_move()
}
if (object_moved)
post_event(SimpleEvent(EVT_GLCANVAS_WIPETOWER_MOVED));
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_MOVED));
if (wipe_tower_origin != Vec3d::Zero())
post_event(Vec3dEvent(EVT_GLCANVAS_WIPETOWER_MOVED, std::move(wipe_tower_origin)));
@ -6354,7 +6354,7 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
}
if (object_moved)
post_event(SimpleEvent(EVT_GLCANVAS_WIPETOWER_MOVED));
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_MOVED));
if (wipe_tower_origin != Vec3d::Zero())
post_event(Vec3dEvent(EVT_GLCANVAS_WIPETOWER_MOVED, std::move(wipe_tower_origin)));

View file

@ -110,7 +110,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ROTATE_OBJECT, Event<int>); // data: -1 => rotate left, +1 => rotate right
wxDECLARE_EVENT(EVT_GLCANVAS_SCALE_UNIFORMLY, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_INCREASE_OBJECTS, Event<int>); // data: +1 => increase, -1 => decrease
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVES, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>);
wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>);

View file

@ -729,13 +729,11 @@ struct Plater::priv
void on_action_selectbyparts(SimpleEvent&);
#endif // !ENABLE_EXTENDED_SELECTION
void on_object_select(ObjectSelectEvent&);
void on_viewport_changed(SimpleEvent&);
void on_right_click(Vec2dEvent&);
void on_model_update(SimpleEvent&);
void on_remove_object(SimpleEvent&);
void on_arrange(SimpleEvent&);
void on_scale_uniformly(SimpleEvent&);
void on_instance_moves(SimpleEvent&);
void on_wipetower_moved(Vec3dEvent&);
void on_enable_action_buttons(Event<bool>&);
void on_update_geometry(Vec3dsEvent<2>&);
@ -816,17 +814,17 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
sidebar->Bind(wxEVT_COMBOBOX, &priv::on_select_preset, this);
// 3DScene events:
canvas3D->Bind(EVT_GLCANVAS_OBJECT_SELECT, [](ObjectSelectEvent&) { /*TODO*/ });
canvas3D->Bind(EVT_GLCANVAS_OBJECT_SELECT, &priv::on_object_select, this);
canvas3D->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this);
// canvas3D->Bind(EVT_GLCANVAS_DOUBLE_CLICK, [](SimpleEvent&) { }); // XXX: remove?
canvas3D->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this);
canvas3D->Bind(EVT_GLCANVAS_MODEL_UPDATE, &priv::on_model_update, this);
canvas3D->Bind(EVT_GLCANVAS_REMOVE_OBJECT, &priv::on_remove_object, this);
canvas3D->Bind(EVT_GLCANVAS_ARRANGE, &priv::on_arrange, this);
canvas3D->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
canvas3D->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); });
canvas3D->Bind(EVT_GLCANVAS_ROTATE_OBJECT, [this](Event<int> &evt) { /*TODO: call rotate */ });
canvas3D->Bind(EVT_GLCANVAS_SCALE_UNIFORMLY, &priv::on_scale_uniformly, this);
canvas3D->Bind(EVT_GLCANVAS_SCALE_UNIFORMLY, [this](SimpleEvent&) { scale(); });
canvas3D->Bind(EVT_GLCANVAS_INCREASE_OBJECTS, [this](Event<int> &evt) { evt.data == 1 ? increase() : decrease(); });
canvas3D->Bind(EVT_GLCANVAS_INSTANCE_MOVES, &priv::on_instance_moves, this);
canvas3D->Bind(EVT_GLCANVAS_INSTANCE_MOVED, [this](SimpleEvent&) { update(); });
canvas3D->Bind(EVT_GLCANVAS_WIPETOWER_MOVED, &priv::on_wipetower_moved, this);
canvas3D->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, &priv::on_enable_action_buttons, this);
canvas3D->Bind(EVT_GLCANVAS_UPDATE_GEOMETRY, &priv::on_update_geometry, this);
@ -1573,6 +1571,19 @@ void Plater::priv::on_action_selectbyparts(SimpleEvent&)
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::on_object_select(ObjectSelectEvent &evt)
{
const auto obj_idx = evt.object_id();
const auto vol_idx = evt.volume_id();
// TODO:
// if (($obj_idx != -1) && ($vol_idx == -1)) {
// # Ignore the special objects (the wipe tower proxy and such).
// $self->select_object((defined($obj_idx) && $obj_idx >= 0 && $obj_idx < 1000) ? $obj_idx : undef);
// $self->item_changed_selection($obj_idx) if (defined($obj_idx));
// }
}
void Plater::priv::on_viewport_changed(SimpleEvent& evt)
{
wxObject* o = evt.GetEventObject();
@ -1592,29 +1603,47 @@ void Plater::priv::on_model_update(SimpleEvent&)
// TODO
}
void Plater::priv::on_remove_object(SimpleEvent&)
{
// TODO
}
void Plater::priv::on_arrange(SimpleEvent&)
{
// TODO
}
void Plater::priv::on_scale_uniformly(SimpleEvent&)
{
// TODO
// my ($scale) = @_;
// my ($obj_idx, $object) = $self->selected_object;
const auto obj_idx = selected_object();
if (! obj_idx) { return; }
// return if !defined $obj_idx;
// my $model_object = $self->{model}->objects->[$obj_idx];
// my $model_instance = $model_object->instances->[0];
// $self->stop_background_process;
// my $variation = $scale / $model_instance->scaling_factor;
// #FIXME Scale the layer height profile?
// foreach my $range (@{ $model_object->layer_height_ranges }) {
// $range->[0] *= $variation;
// $range->[1] *= $variation;
// }
// $_->set_scaling_factor($scale) for @{ $model_object->instances };
// # Set object scale on c++ side
// # Slic3r::GUI::set_object_scale($obj_idx, $model_object->instances->[0]->scaling_factor * 100);
// # $object->transform_thumbnail($self->{model}, $obj_idx);
// #update print and start background processing
// $self->{print}->add_model_object($model_object, $obj_idx);
// $self->selection_changed(1); # refresh info (size, volume etc.)
// $self->update;
// $self->schedule_background_process;
}
void Plater::priv::on_instance_moves(SimpleEvent&)
void Plater::priv::on_wipetower_moved(Vec3dEvent &evt)
{
// TODO
}
void Plater::priv::on_wipetower_moved(Vec3dEvent&)
{
// TODO
DynamicPrintConfig cfg;
cfg.opt<ConfigOptionFloat>("wipe_tower_x", true)->value = evt.data(0);
cfg.opt<ConfigOptionFloat>("wipe_tower_y", true)->value = evt.data(1);
main_frame->get_preset_tab("print")->load_config(cfg);
}
void Plater::priv::on_enable_action_buttons(Event<bool>&)
@ -1628,7 +1657,6 @@ void Plater::priv::on_update_geometry(Vec3dsEvent<2>&)
}
// Plater / Public
Plater::Plater(wxWindow *parent, MainFrame *main_frame)