From a0090fccb5c8ba0484df721a5b5376a2dd92cf8b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 14 Jun 2018 23:31:15 +0200 Subject: [PATCH] Button "Load Lambda" (in the Object Settings) works now --- xs/src/slic3r/GUI/GUI.cpp | 3 +- xs/src/slic3r/GUI/GUI.hpp | 21 +++++--- xs/src/slic3r/GUI/GUI_ObjectParts.cpp | 61 ++++++++++++++++++++++-- xs/src/slic3r/GUI/GUI_ObjectParts.hpp | 9 +++- xs/src/slic3r/GUI/LambdaObjectDialog.cpp | 29 ++++++++++- xs/src/slic3r/GUI/LambdaObjectDialog.hpp | 1 + 6 files changed, 107 insertions(+), 17 deletions(-) diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 6b4195e94..f738ca693 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -1028,8 +1028,7 @@ wxBoxSizer* content_edit_object_buttons(wxWindow* win) btn_load_lambda_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&) { - auto dlg = new LambdaObjectDialog(win); - dlg->ShowModal(); + on_btn_load(win, true, true); }); btn_delete->Bind(wxEVT_BUTTON, [](wxEvent&) diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 12eef0b62..fdad1e291 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -68,6 +68,13 @@ enum ogGroup{ ogPartSettings }; +enum LambdaTypeIDs{ + LambdaTypeBox, + LambdaTypeCylinder, + LambdaTypeSphere, + LambdaTypeSlab +}; + class Tab; class ConfigOptionsGroup; typedef std::vector ModelObjectPtrs; @@ -91,13 +98,13 @@ inline t_file_wild_card& get_file_wild_card() { struct OBJECT_PARAMETERS { - std::string type = "box"; - double dim[3];// = { 1.0, 1.0, 1.0 }; - int cyl_r = 1; - int cyl_h = 1; - double sph_rho = 1.0; - double slab_h = 1.0; - double slab_z = 0.0; + LambdaTypeIDs type = LambdaTypeBox; + double dim[3];// = { 1.0, 1.0, 1.0 }; + int cyl_r = 1; + int cyl_h = 1; + double sph_rho = 1.0; + double slab_h = 1.0; + double slab_z = 0.0; }; void disable_screensaver(); diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp index 2f88b58f7..5aa0d8b15 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "LambdaObjectDialog.hpp" namespace Slic3r { @@ -17,7 +18,8 @@ bool m_part_settings_changed = false; bool is_parts_changed(){return m_parts_changed;} bool is_part_settings_changed(){ return m_part_settings_changed; } -void load_part(wxWindow* parent, ModelObject* model_object, wxArrayString& part_names, bool is_modifier) +void load_part( wxWindow* parent, ModelObject* model_object, + wxArrayString& part_names, const bool is_modifier) { wxArrayString input_files; open_model(parent, input_files); @@ -47,7 +49,6 @@ void load_part(wxWindow* parent, ModelObject* model_object, wxArrayString& part_ new_volume->mesh.translate( model_object->origin_translation.x, model_object->origin_translation.y, model_object->origin_translation.y ); - // set a default extruder value, since user can't add it manually new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); @@ -57,7 +58,56 @@ void load_part(wxWindow* parent, ModelObject* model_object, wxArrayString& part_ } } -void on_btn_load(wxWindow* parent, bool is_modifier /*= false*/) +void load_lambda( wxWindow* parent, ModelObject* model_object, + wxArrayString& part_names, const bool is_modifier) +{ + auto dlg = new LambdaObjectDialog(parent); + if (dlg->ShowModal() == wxID_CANCEL) { + return; + } + + std::string name = "lambda-"; + TriangleMesh mesh; + + auto params = dlg->ObjectParameters(); + switch (params.type) + { + case LambdaTypeBox:{ + mesh = make_cube(params.dim[0], params.dim[1], params.dim[2]); + name += "Box"; + break;} + case LambdaTypeCylinder:{ + mesh = make_cylinder(params.cyl_r, params.cyl_h); + name += "Cylinder"; + break;} + case LambdaTypeSphere:{ + mesh = make_sphere(params.sph_rho); + name += "Sphere"; + break;} + case LambdaTypeSlab:{ + const auto& size = model_object->bounding_box().size(); + mesh = make_cube(size.x*1.5, size.y*1.5, params.slab_h); + // box sets the base coordinate at 0, 0, move to center of plate and move it up to initial_z + mesh.translate(-size.x*1.5 / 2.0, -size.y*1.5 / 2.0, params.slab_z); + name += "Slab"; + break; } + default: + break; + } + mesh.repair(); + + auto new_volume = model_object->add_volume(mesh); + new_volume->modifier = is_modifier; + new_volume->name = name; + // set a default extruder value, since user can't add it manually + new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); + + part_names.Add(name); + + m_parts_changed = true; +} + +void on_btn_load(wxWindow* parent, bool is_modifier /*= false*/, bool is_lambda/* = false*/) { auto objects_ctrl = get_objects_ctrl(); auto item = objects_ctrl->GetSelection(); @@ -73,7 +123,10 @@ void on_btn_load(wxWindow* parent, bool is_modifier /*= false*/) if (obj_idx < 0) return; wxArrayString part_names; ModelObjectPtrs& objects = get_objects(); - load_part(parent, objects[obj_idx], part_names, is_modifier); + if (is_lambda) + load_lambda(parent, objects[obj_idx], part_names, is_modifier); + else + load_part(parent, objects[obj_idx], part_names, is_modifier); parts_changed(obj_idx); diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp index cf07bb242..40bcc012e 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp @@ -9,8 +9,13 @@ bool is_parts_changed(); bool is_part_settings_changed(); void load_part( wxWindow* parent, ModelObject* model_object, - wxArrayString& part_names, bool is_modifier); -void on_btn_load(wxWindow* parent, bool is_modifier = false); + wxArrayString& part_names, const bool is_modifier); + +void load_lambda(wxWindow* parent, ModelObject* model_object, + wxArrayString& part_names, const bool is_modifier); + +void on_btn_load(wxWindow* parent, bool is_modifier = false, bool is_lambda = false); + void parts_changed(int obj_idx); } //namespace GUI } //namespace Slic3r diff --git a/xs/src/slic3r/GUI/LambdaObjectDialog.cpp b/xs/src/slic3r/GUI/LambdaObjectDialog.cpp index 5657c7a71..b5479fb12 100644 --- a/xs/src/slic3r/GUI/LambdaObjectDialog.cpp +++ b/xs/src/slic3r/GUI/LambdaObjectDialog.cpp @@ -13,7 +13,7 @@ static wxString dots("…", wxConvUTF8); LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent) { Create(parent, wxID_ANY, _(L("Lambda Object")), - wxDefaultPosition, wxSize(500, 500), + wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); // instead of double dim[3] = { 1.0, 1.0, 1.0 }; @@ -24,7 +24,8 @@ LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent) sizer = new wxBoxSizer(wxVERTICAL); // modificator options - m_modificator_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxSize(300, -1), wxCHB_TOP); + m_modificator_options_book = new wxChoicebook( this, wxID_ANY, wxDefaultPosition, + wxDefaultSize, wxCHB_TOP); sizer->Add(m_modificator_options_book, 1, wxEXPAND| wxALL, 10); auto optgroup = init_modificator_options_page(_(L("Box"))); @@ -37,6 +38,7 @@ LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent) }; ConfigOptionDef def; + def.width = 70; def.type = coFloat; def.default_value = new ConfigOptionFloat{ 1.0 }; def.label = L("L"); @@ -102,6 +104,29 @@ LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent) option = Option(def, "slab_z"); optgroup->append_single_option_line(option); + Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent e) + { + auto page_idx = m_modificator_options_book->GetSelection(); + if (page_idx < 0) return; + switch (page_idx) + { + case 0: + object_parameters.type = LambdaTypeBox; + break; + case 1: + object_parameters.type = LambdaTypeCylinder; + break; + case 2: + object_parameters.type = LambdaTypeSphere; + break; + case 3: + object_parameters.type = LambdaTypeSlab; + break; + default: + break; + } + })); + auto button_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL); diff --git a/xs/src/slic3r/GUI/LambdaObjectDialog.hpp b/xs/src/slic3r/GUI/LambdaObjectDialog.hpp index 712722b2d..a70c12449 100644 --- a/xs/src/slic3r/GUI/LambdaObjectDialog.hpp +++ b/xs/src/slic3r/GUI/LambdaObjectDialog.hpp @@ -21,6 +21,7 @@ public: ~LambdaObjectDialog(){} bool CanClose() { return true; } // ??? + OBJECT_PARAMETERS& ObjectParameters(){ return object_parameters; } ConfigOptionsGroupShp init_modificator_options_page(wxString title);