Added function for the sidetext changing

+ some code reorganization
This commit is contained in:
YuSanka 2018-07-04 14:52:36 +02:00
parent 38768a7bda
commit 60f703e7c7
7 changed files with 115 additions and 82 deletions

View file

@ -547,8 +547,11 @@ boost::any& Choice::get_value()
// boost::any m_value;
wxString ret_str = static_cast<wxComboBox*>(window)->GetValue();
if (m_opt_id == "support")
return m_value = boost::any(ret_str);//ret_str;
// options from right panel
std::vector <std::string> right_panel_options{ "support", "scale_unit" };
for (auto rp_option: right_panel_options)
if (m_opt_id == rp_option)
return m_value = boost::any(ret_str);
if (m_opt.type != coEnum)
/*m_value = */get_value_by_opt_type(ret_str);

View file

@ -188,6 +188,10 @@ public:
return false;
}
void set_side_text_ptr(wxStaticText* side_text) {
m_side_text = side_text;
}
protected:
MyButton* m_Undo_btn = nullptr;
// Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
@ -202,6 +206,8 @@ protected:
// Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one.
const wxColour* m_label_color = nullptr;
wxStaticText* m_side_text = nullptr;
// current value
boost::any m_value;

View file

@ -909,47 +909,6 @@ void add_expert_mode_part( wxWindow* parent, wxBoxSizer* sizer,
// add_collapsible_panes(parent, sizer);
}
Line add_og_to_object_settings(const std::string& option_name, const std::string& sidetext, int def_value = 0)
{
Line line = { _(option_name), "" };
ConfigOptionDef def;
def.label = L("X");
def.type = coInt;
def.default_value = new ConfigOptionInt(def_value);
def.sidetext = sidetext;
def.width = 70;
const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
Option option = Option(def, lower_name + "_X");
option.opt.full_width = true;
line.append_option(option);
def.label = L("Y");
option = Option(def, lower_name + "_Y");
line.append_option(option);
def.label = L("Z");
option = Option(def, lower_name + "_Z");
line.append_option(option);
if (option_name == "Scale")
{
def.label = L("Units");
def.type = coStrings;
def.gui_type = "select_open";
def.enum_labels.push_back(L("%"));
def.enum_labels.push_back(L("mm"));
def.default_value = new ConfigOptionStrings{ "%" };
def.sidetext = " ";
option = Option(def, lower_name + "_unit");
line.append_option(option);
}
return line;
}
void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer)
{
DynamicPrintConfig* config = &g_PresetBundle->prints.get_edited_preset().config;
@ -1078,37 +1037,7 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl
add_objects_list(parent, sizer);
// Frequently Object Settings
optgroup = std::make_shared<ConfigOptionsGroup>(parent, _(L("Object Settings")), config);
optgroup->label_width = 100;
optgroup->set_grid_vgap(5);
// def.label = L("Name");
// def.type = coString;
// def.tooltip = L("Object name");
// def.full_width = true;
// def.default_value = new ConfigOptionString{ "BlaBla_object.stl" };
// optgroup->append_single_option_line(Option(def, "object_name"));
optgroup->set_flag(ogSIDE_OPTIONS_VERTICAL);
optgroup->sidetext_width = 25;
optgroup->append_line(add_og_to_object_settings(L("Position"), L("mm")));
optgroup->append_line(add_og_to_object_settings(L("Rotation"), "°", 1));
optgroup->append_line(add_og_to_object_settings(L("Scale"), "%", 2));
optgroup->set_flag(ogDEFAULT);
def.label = L("Place on bed");
def.type = coBool;
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
def.gui_type = "";
def.sidetext = "";
def.default_value = new ConfigOptionBool{ false };
optgroup->append_single_option_line(Option(def, "place_on_bed"));
sizer->Add(optgroup->sizer, 0, wxEXPAND | wxLEFT | wxTOP, 20);
m_optgroups.push_back(optgroup); // ogFrequentlyObjectSettings
add_object_settings(parent, sizer);
}
void show_frequently_changed_parameters(bool show)

View file

@ -65,7 +65,7 @@ void init_mesh_icons(){
bool is_parts_changed(){return m_parts_changed;}
bool is_part_settings_changed(){ return m_part_settings_changed; }
static wxString dots("", wxConvUTF8);
static wxString dots("…", wxConvUTF8);
// ****** from GUI.cpp
wxBoxSizer* content_objects_list(wxWindow *win)
@ -308,6 +308,98 @@ wxBoxSizer* content_settings(wxWindow *win)
return sizer;
}
void add_objects_list(wxWindow* parent, wxBoxSizer* sizer)
{
const auto ol_sizer = content_objects_list(parent);
sizer->Add(ol_sizer, 1, wxEXPAND | wxTOP, 20);
set_objects_list_sizer(ol_sizer);
}
Line add_og_to_object_settings(const std::string& option_name, const std::string& sidetext, int def_value = 0)
{
Line line = { _(option_name), "" };
ConfigOptionDef def;
def.type = coInt;
def.default_value = new ConfigOptionInt(def_value);
def.sidetext = sidetext;
def.width = 70;
const std::string lower_name = boost::algorithm::to_lower_copy(option_name);
std::vector<std::string> axes{ "x", "y", "z" };
for (auto axis : axes) {
def.label = boost::algorithm::to_upper_copy(axis);
Option option = Option(def, lower_name + "_" + axis);
option.opt.full_width = true;
line.append_option(option);
}
if (option_name == "Scale")
{
def.label = L("Units");
def.type = coStrings;
def.gui_type = "select_open";
def.enum_labels.push_back(L("%"));
def.enum_labels.push_back(L("mm"));
def.default_value = new ConfigOptionStrings{ "%" };
def.sidetext = " ";
Option option = Option(def, lower_name + "_unit");
line.append_option(option);
}
return line;
}
void add_object_settings(wxWindow* parent, wxBoxSizer* sizer)
{
auto optgroup = std::make_shared<ConfigOptionsGroup>(parent, _(L("Object Settings")));
optgroup->label_width = 100;
optgroup->set_grid_vgap(5);
optgroup->m_on_change = [](t_config_option_key opt_key, boost::any value){
if (opt_key == "scale_unit"){
const wxString& selection = boost::any_cast<wxString>(value);
std::vector<std::string> axes{ "x", "y", "z" };
for (auto axis : axes) {
std::string key = "scale_" + axis;
get_optgroup(ogFrequentlyObjectSettings)->set_side_text(key, selection);
}
}
};
// def.label = L("Name");
// def.type = coString;
// def.tooltip = L("Object name");
// def.full_width = true;
// def.default_value = new ConfigOptionString{ "BlaBla_object.stl" };
// optgroup->append_single_option_line(Option(def, "object_name"));
optgroup->set_flag(ogSIDE_OPTIONS_VERTICAL);
optgroup->sidetext_width = 25;
optgroup->append_line(add_og_to_object_settings(L("Position"), L("mm")));
optgroup->append_line(add_og_to_object_settings(L("Rotation"), "°", 1));
optgroup->append_line(add_og_to_object_settings(L("Scale"), "%", 2));
optgroup->set_flag(ogDEFAULT);
ConfigOptionDef def;
def.label = L("Place on bed");
def.type = coBool;
def.tooltip = L("Automatic placing of models on printing bed in Y axis");
def.gui_type = "";
def.sidetext = "";
def.default_value = new ConfigOptionBool{ false };
optgroup->append_single_option_line(Option(def, "place_on_bed"));
sizer->Add(optgroup->sizer, 0, wxEXPAND | wxLEFT | wxTOP, 20);
optgroup->disable();
get_optgroups().push_back(optgroup); // ogFrequentlyObjectSettings
}
// add Collapsible Pane to sizer
wxCollapsiblePane* add_collapsible_pane(wxWindow* parent, wxBoxSizer* sizer_parent, const wxString& name, std::function<wxSizer *(wxWindow *)> content_function)
@ -331,13 +423,6 @@ wxCollapsiblePane* add_collapsible_pane(wxWindow* parent, wxBoxSizer* sizer_pare
return collpane;
}
void add_objects_list(wxWindow* parent, wxBoxSizer* sizer)
{
const auto ol_sizer = content_objects_list(parent);
sizer->Add(ol_sizer, 1, wxEXPAND | wxTOP, 20);
set_objects_list_sizer(ol_sizer);
}
void add_collapsible_panes(wxWindow* parent, wxBoxSizer* sizer)
{
// *** Objects List ***

View file

@ -40,6 +40,7 @@ struct OBJECT_PARAMETERS
void add_collapsible_panes(wxWindow* parent, wxBoxSizer* sizer);
void add_objects_list(wxWindow* parent, wxBoxSizer* sizer);
void add_object_settings(wxWindow* parent, wxBoxSizer* sizer);
void show_collpane_settings(bool expert_mode);
// Add object to the list

View file

@ -230,6 +230,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
wxSize(sidetext_width, -1)/*wxDefaultSize*/, wxALIGN_LEFT);
sidetext->SetFont(sidetext_font);
sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, m_flag == ogSIDE_OPTIONS_VERTICAL ? 0 : 4);
field->set_side_text_ptr(sidetext);
}
// add side widget if any

View file

@ -128,6 +128,14 @@ public:
return out;
}
bool set_side_text(const t_config_option_key& opt_key, const wxString& side_text) {
if (m_fields.find(opt_key) == m_fields.end()) return false;
auto st = m_fields.at(opt_key)->m_side_text;
if (!st) return false;
st->SetLabel(side_text);
return true;
}
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
void set_flag(ogDrawFlag flag) { m_flag = flag; }