imgui: Refactor, use in cut gizmo

This commit is contained in:
Vojtech Kral 2018-11-26 10:56:07 +01:00
parent 763b443459
commit c29493a41b
15 changed files with 315 additions and 157 deletions

View file

@ -913,7 +913,9 @@ struct Plater::priv
// GUI elements
wxNotebook *notebook;
Sidebar *sidebar;
#ifndef ENABLE_IMGUI
wxPanel *panel3d;
#endif // not ENABLE_IMGUI
wxGLCanvas *canvas3Dwidget; // TODO: Use GLCanvas3D when we can
GLCanvas3D *canvas3D;
Preview *preview;
@ -1039,8 +1041,12 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
}))
, notebook(new wxNotebook(q, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM))
, sidebar(new Sidebar(q))
#ifdef ENABLE_IMGUI
, canvas3Dwidget(GLCanvas3DManager::create_wxglcanvas(notebook))
#else
, panel3d(new wxPanel(notebook, wxID_ANY))
, canvas3Dwidget(GLCanvas3DManager::create_wxglcanvas(panel3d))
#endif // ENABLE_IMGUI
, canvas3D(nullptr)
, delayed_scene_refresh(false)
#if ENABLE_NEW_MENU_LAYOUT
@ -1068,6 +1074,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->canvas3D = _3DScene::get_canvas(this->canvas3Dwidget);
this->canvas3D->allow_multisample(GLCanvas3DManager::can_multisample());
#ifdef ENABLE_IMGUI
notebook->AddPage(canvas3Dwidget, _(L("3D")));
#else
auto *panel3dsizer = new wxBoxSizer(wxVERTICAL);
panel3dsizer->Add(canvas3Dwidget, 1, wxEXPAND);
auto *panel_gizmo_widgets = new wxPanel(panel3d, wxID_ANY);
@ -1076,9 +1085,11 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
panel3d->SetSizer(panel3dsizer);
notebook->AddPage(panel3d, _(L("3D")));
preview = new GUI::Preview(notebook, config, &background_process, &gcode_preview_data, [this](){ schedule_background_process(); });
canvas3D->set_external_gizmo_widgets_parent(panel_gizmo_widgets);
#endif // ENABLE_IMGUI
preview = new GUI::Preview(notebook, config, &background_process, &gcode_preview_data, [this](){ schedule_background_process(); });
// XXX: If have OpenGL
this->canvas3D->enable_picking(true);
@ -1921,7 +1932,11 @@ void Plater::priv::fix_through_netfabb(const int obj_idx)
void Plater::priv::on_notebook_changed(wxBookCtrlEvent&)
{
const auto current_id = notebook->GetCurrentPage()->GetId();
#ifdef ENABLE_IMGUI
if (current_id == canvas3Dwidget->GetId()) {
#else
if (current_id == panel3d->GetId()) {
#endif // ENABLE_IMGUI
if (this->canvas3D->is_reload_delayed()) {
// Delayed loading of the 3D scene.
if (this->printer_technology == ptSLA) {
@ -2454,14 +2469,14 @@ bool Plater::is_selection_empty() const
return p->get_selection().is_empty();
}
void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z)
void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper, bool keep_lower, bool rotate_lower)
{
wxCHECK_RET(obj_idx < p->model.objects.size(), "obj_idx out of bounds");
auto *object = p->model.objects[obj_idx];
wxCHECK_RET(instance_idx < object->instances.size(), "instance_idx out of bounds");
const auto new_objects = object->cut(instance_idx, z);
const auto new_objects = object->cut(instance_idx, z, keep_upper, keep_lower, rotate_lower);
remove(obj_idx);
p->load_model_objects(new_objects);