WIP: Plater: Event handling boilerplate / skeletons

This commit is contained in:
Vojtech Kral 2018-10-08 19:55:30 +02:00
parent ceb295944a
commit 928c146aef
2 changed files with 124 additions and 21 deletions

View File

@ -1949,7 +1949,7 @@ sub fix_through_netfabb {
$self->remove($obj_idx); $self->remove($obj_idx);
} }
# XXX: VK: WIP # XXX: VK: done
sub export_amf { sub export_amf {
my ($self) = @_; my ($self) = @_;
return if !@{$self->{objects}}; return if !@{$self->{objects}};
@ -1966,7 +1966,7 @@ sub export_amf {
} }
} }
# XXX: VK: WIP # XXX: VK: done
sub export_3mf { sub export_3mf {
my ($self) = @_; my ($self) = @_;
return if !@{$self->{objects}}; return if !@{$self->{objects}};

View File

@ -27,6 +27,8 @@
#include "libslic3r/Utils.hpp" #include "libslic3r/Utils.hpp"
#include "libslic3r/Polygon.hpp" #include "libslic3r/Polygon.hpp"
#include "libslic3r/Format/STL.hpp" #include "libslic3r/Format/STL.hpp"
#include "libslic3r/Format/AMF.hpp"
#include "libslic3r/Format/3mf.hpp"
#include "GUI.hpp" #include "GUI.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "GUI_ObjectList.hpp" #include "GUI_ObjectList.hpp"
@ -669,13 +671,16 @@ struct Plater::priv
void remove(size_t obj_idx); void remove(size_t obj_idx);
void reset(); void reset();
void increase(size_t num = 1);
void decrease(size_t num = 1);
void on_notebook_changed(wxBookCtrlEvent &); void on_notebook_changed(wxBookCtrlEvent&);
void on_select_preset(wxCommandEvent &); void on_select_preset(wxCommandEvent&);
void on_update_print_preview(wxCommandEvent &); void on_update_print_preview(wxCommandEvent&);
void on_process_completed(wxCommandEvent &); void on_process_completed(wxCommandEvent&);
void on_layer_editing_toggled(bool enable); void on_layer_editing_toggled(bool enable);
void on_action_add(SimpleEvent&); void on_action_add(SimpleEvent&);
void on_action_arrange(SimpleEvent&); void on_action_arrange(SimpleEvent&);
void on_action_more(SimpleEvent&); void on_action_more(SimpleEvent&);
@ -686,7 +691,16 @@ struct Plater::priv
void on_action_layersediting(SimpleEvent&); void on_action_layersediting(SimpleEvent&);
void on_action_selectbyparts(SimpleEvent&); void on_action_selectbyparts(SimpleEvent&);
void on_viewport_changed(SimpleEvent& evt); 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>&);
}; };
const std::regex Plater::priv::pattern_bundle("[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)$", std::regex::icase); const std::regex Plater::priv::pattern_bundle("[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)$", std::regex::icase);
@ -763,15 +777,22 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
// Preset change event // Preset change event
sidebar->Bind(wxEVT_COMBOBOX, &priv::on_select_preset, this); sidebar->Bind(wxEVT_COMBOBOX, &priv::on_select_preset, this);
// Sidebar button events
// sidebar->p->btn_export_gcode->Bind(wxEVT_BUTTON, [q](wxCommandEvent&) { q->export_gcode(); });
// sidebar->p->btn_reslice->Bind(wxEVT_BUTTON, [q](wxCommandEvent&) { q->reslice(); });
// sidebar->p->btn_send_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
// this->send_gcode_file = this->q->export_gcode();
// });
// 3DScene events: // 3DScene events:
// TODO: more canvas3D->Bind(EVT_GLCANVAS_OBJECT_SELECT, [](ObjectSelectEvent&) { /*TODO*/ });
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_ROTATE_OBJECT, [this](Event<int> &evt) { /*TODO: call rotate */ });
canvas3D->Bind(EVT_GLCANVAS_SCALE_UNIFORMLY, &priv::on_scale_uniformly, this);
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_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);
// 3DScene/Toolbar:
canvas3D->Bind(EVT_GLTOOLBAR_ADD, &priv::on_action_add, this); canvas3D->Bind(EVT_GLTOOLBAR_ADD, &priv::on_action_add, this);
canvas3D->Bind(EVT_GLTOOLBAR_DELETE, [q](SimpleEvent&) { q->remove_selected(); } ); canvas3D->Bind(EVT_GLTOOLBAR_DELETE, [q](SimpleEvent&) { q->remove_selected(); } );
canvas3D->Bind(EVT_GLTOOLBAR_DELETE_ALL, [this](SimpleEvent&) { reset(); }); canvas3D->Bind(EVT_GLTOOLBAR_DELETE_ALL, [this](SimpleEvent&) { reset(); });
@ -784,8 +805,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
canvas3D->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this); canvas3D->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this);
canvas3D->Bind(EVT_GLTOOLBAR_SELECTBYPARTS, &priv::on_action_selectbyparts, this); canvas3D->Bind(EVT_GLTOOLBAR_SELECTBYPARTS, &priv::on_action_selectbyparts, this);
canvas3D->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); // Preview events:
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this);
q->Bind(EVT_SLICING_COMPLETED, &priv::on_update_print_preview, this); q->Bind(EVT_SLICING_COMPLETED, &priv::on_update_print_preview, this);
@ -1252,6 +1272,16 @@ void Plater::priv::reset()
update(); update();
} }
void Plater::priv::increase(size_t num)
{
// TODO
}
void Plater::priv::decrease(size_t num)
{
// TODO
}
void Plater::priv::on_notebook_changed(wxBookCtrlEvent&) void Plater::priv::on_notebook_changed(wxBookCtrlEvent&)
{ {
@ -1383,6 +1413,53 @@ void Plater::priv::on_viewport_changed(SimpleEvent& evt)
preview->set_viewport_from_scene(canvas3D); preview->set_viewport_from_scene(canvas3D);
} }
void Plater::priv::on_right_click(Vec2dEvent&)
{
// TODO
}
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
}
void Plater::priv::on_instance_moves(SimpleEvent&)
{
// TODO
}
void Plater::priv::on_wipetower_moved(Vec3dEvent&)
{
// TODO
}
void Plater::priv::on_enable_action_buttons(Event<bool>&)
{
// TODO
}
void Plater::priv::on_update_geometry(Vec3dsEvent<2>&)
{
// TODO
}
// Plater / Public // Plater / Public
Plater::Plater(wxWindow *parent, MainFrame *main_frame) Plater::Plater(wxWindow *parent, MainFrame *main_frame)
@ -1482,14 +1559,40 @@ void Plater::export_stl()
void Plater::export_amf() void Plater::export_amf()
{ {
// TODO if (p->objects.empty()) { return; }
throw 0;
auto dialog = p->get_export_file(FT_AMF);
if (! dialog) { return; }
wxString path = dialog->GetPath();
auto path_cstr = path.c_str();
if (Slic3r::store_amf(path_cstr, &p->model, &p->print, dialog->get_checkbox_value())) {
// Success
p->statusbar()->set_status_text(wxString::Format(_(L("AMF file exported to %s")), path));
} else {
// Failure
p->statusbar()->set_status_text(wxString::Format(_(L("Error exporting AMF file %s")), path));
}
} }
void Plater::export_3mf() void Plater::export_3mf()
{ {
// TODO if (p->objects.empty()) { return; }
throw 0;
auto dialog = p->get_export_file(FT_3MF);
if (! dialog) { return; }
wxString path = dialog->GetPath();
auto path_cstr = path.c_str();
if (Slic3r::store_3mf(path_cstr, &p->model, &p->print, dialog->get_checkbox_value())) {
// Success
p->statusbar()->set_status_text(wxString::Format(_(L("3MF file exported to %s")), path));
} else {
// Failure
p->statusbar()->set_status_text(wxString::Format(_(L("Error exporting 3MF file %s")), path));
}
} }