Button "Load Lambda" (in the Object Settings) works now

This commit is contained in:
YuSanka 2018-06-14 23:31:15 +02:00
parent 3e0ff5e9ef
commit a0090fccb5
6 changed files with 107 additions and 17 deletions

View File

@ -1028,8 +1028,7 @@ wxBoxSizer* content_edit_object_buttons(wxWindow* win)
btn_load_lambda_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&) btn_load_lambda_modifier->Bind(wxEVT_BUTTON, [win](wxEvent&)
{ {
auto dlg = new LambdaObjectDialog(win); on_btn_load(win, true, true);
dlg->ShowModal();
}); });
btn_delete->Bind(wxEVT_BUTTON, [](wxEvent&) btn_delete->Bind(wxEVT_BUTTON, [](wxEvent&)

View File

@ -68,6 +68,13 @@ enum ogGroup{
ogPartSettings ogPartSettings
}; };
enum LambdaTypeIDs{
LambdaTypeBox,
LambdaTypeCylinder,
LambdaTypeSphere,
LambdaTypeSlab
};
class Tab; class Tab;
class ConfigOptionsGroup; class ConfigOptionsGroup;
typedef std::vector<ModelObject*> ModelObjectPtrs; typedef std::vector<ModelObject*> ModelObjectPtrs;
@ -91,7 +98,7 @@ inline t_file_wild_card& get_file_wild_card() {
struct OBJECT_PARAMETERS struct OBJECT_PARAMETERS
{ {
std::string type = "box"; LambdaTypeIDs type = LambdaTypeBox;
double dim[3];// = { 1.0, 1.0, 1.0 }; double dim[3];// = { 1.0, 1.0, 1.0 };
int cyl_r = 1; int cyl_r = 1;
int cyl_h = 1; int cyl_h = 1;

View File

@ -6,6 +6,7 @@
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include <wx/frame.h> #include <wx/frame.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "LambdaObjectDialog.hpp"
namespace Slic3r namespace Slic3r
{ {
@ -17,7 +18,8 @@ bool m_part_settings_changed = false;
bool is_parts_changed(){return m_parts_changed;} bool is_parts_changed(){return m_parts_changed;}
bool is_part_settings_changed(){ return m_part_settings_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; wxArrayString input_files;
open_model(parent, 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, new_volume->mesh.translate( model_object->origin_translation.x,
model_object->origin_translation.y, model_object->origin_translation.y,
model_object->origin_translation.y ); model_object->origin_translation.y );
// set a default extruder value, since user can't add it manually // set a default extruder value, since user can't add it manually
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); 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 objects_ctrl = get_objects_ctrl();
auto item = objects_ctrl->GetSelection(); auto item = objects_ctrl->GetSelection();
@ -73,6 +123,9 @@ void on_btn_load(wxWindow* parent, bool is_modifier /*= false*/)
if (obj_idx < 0) return; if (obj_idx < 0) return;
wxArrayString part_names; wxArrayString part_names;
ModelObjectPtrs& objects = get_objects(); ModelObjectPtrs& objects = get_objects();
if (is_lambda)
load_lambda(parent, objects[obj_idx], part_names, is_modifier);
else
load_part(parent, objects[obj_idx], part_names, is_modifier); load_part(parent, objects[obj_idx], part_names, is_modifier);
parts_changed(obj_idx); parts_changed(obj_idx);

View File

@ -9,8 +9,13 @@ bool is_parts_changed();
bool is_part_settings_changed(); bool is_part_settings_changed();
void load_part( wxWindow* parent, ModelObject* model_object, void load_part( wxWindow* parent, ModelObject* model_object,
wxArrayString& part_names, bool is_modifier); wxArrayString& part_names, const bool is_modifier);
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);
void on_btn_load(wxWindow* parent, bool is_modifier = false, bool is_lambda = false);
void parts_changed(int obj_idx); void parts_changed(int obj_idx);
} //namespace GUI } //namespace GUI
} //namespace Slic3r } //namespace Slic3r

View File

@ -13,7 +13,7 @@ static wxString dots("…", wxConvUTF8);
LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent) LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent)
{ {
Create(parent, wxID_ANY, _(L("Lambda Object")), Create(parent, wxID_ANY, _(L("Lambda Object")),
wxDefaultPosition, wxSize(500, 500), wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
// instead of double dim[3] = { 1.0, 1.0, 1.0 }; // instead of double dim[3] = { 1.0, 1.0, 1.0 };
@ -24,7 +24,8 @@ LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent)
sizer = new wxBoxSizer(wxVERTICAL); sizer = new wxBoxSizer(wxVERTICAL);
// modificator options // 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); sizer->Add(m_modificator_options_book, 1, wxEXPAND| wxALL, 10);
auto optgroup = init_modificator_options_page(_(L("Box"))); auto optgroup = init_modificator_options_page(_(L("Box")));
@ -37,6 +38,7 @@ LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent)
}; };
ConfigOptionDef def; ConfigOptionDef def;
def.width = 70;
def.type = coFloat; def.type = coFloat;
def.default_value = new ConfigOptionFloat{ 1.0 }; def.default_value = new ConfigOptionFloat{ 1.0 };
def.label = L("L"); def.label = L("L");
@ -102,6 +104,29 @@ LambdaObjectDialog::LambdaObjectDialog(wxWindow* parent)
option = Option(def, "slab_z"); option = Option(def, "slab_z");
optgroup->append_single_option_line(option); 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); auto button_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL);

View File

@ -21,6 +21,7 @@ public:
~LambdaObjectDialog(){} ~LambdaObjectDialog(){}
bool CanClose() { return true; } // ??? bool CanClose() { return true; } // ???
OBJECT_PARAMETERS& ObjectParameters(){ return object_parameters; }
ConfigOptionsGroupShp init_modificator_options_page(wxString title); ConfigOptionsGroupShp init_modificator_options_page(wxString title);