mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-20 05:07:51 -06:00
"on_change" function call correctly work now. Start adding of Tab::update().
It's need to think about config->set_key_value(...): at cpp side it's non-trivial.
This commit is contained in:
parent
f8a48f5c13
commit
e62c17bddf
9 changed files with 617 additions and 262 deletions
|
@ -33,118 +33,119 @@ class StaticText;
|
|||
|
||||
/// Wraps a ConfigOptionDef and adds function object for creating a side_widget.
|
||||
struct Option {
|
||||
ConfigOptionDef opt { ConfigOptionDef() };
|
||||
t_config_option_key opt_id;//! {""};
|
||||
widget_t side_widget {nullptr};
|
||||
bool readonly {false};
|
||||
ConfigOptionDef opt { ConfigOptionDef() };
|
||||
t_config_option_key opt_id;//! {""};
|
||||
widget_t side_widget {nullptr};
|
||||
bool readonly {false};
|
||||
|
||||
Option(const ConfigOptionDef& _opt, t_config_option_key id) : opt(_opt), opt_id(id) {};
|
||||
Option(const ConfigOptionDef& _opt, t_config_option_key id) :
|
||||
opt(_opt), opt_id(id) {}
|
||||
};
|
||||
using t_option = std::unique_ptr<Option>; //!
|
||||
|
||||
/// Represents option lines
|
||||
class Line {
|
||||
public:
|
||||
wxString label {wxString("")};
|
||||
wxString label_tooltip {wxString("")};
|
||||
size_t full_width {0};
|
||||
wxSizer* sizer {nullptr};
|
||||
widget_t widget {nullptr};
|
||||
wxString label {wxString("")};
|
||||
wxString label_tooltip {wxString("")};
|
||||
size_t full_width {0};
|
||||
wxSizer* sizer {nullptr};
|
||||
widget_t widget {nullptr};
|
||||
|
||||
void append_option(const Option& option) {
|
||||
_options.push_back(option);
|
||||
m_options.push_back(option);
|
||||
}
|
||||
void append_widget(const widget_t widget) {
|
||||
_extra_widgets.push_back(widget);
|
||||
m_extra_widgets.push_back(widget);
|
||||
}
|
||||
Line(std::string label, std::string tooltip) : label(wxString(label)), label_tooltip(wxString(tooltip)) {} ;
|
||||
Line(std::string label, std::string tooltip) :
|
||||
label(wxString(label)), label_tooltip(wxString(tooltip)) {}
|
||||
|
||||
const std::vector<widget_t>& get_extra_widgets() const {return _extra_widgets;}
|
||||
const std::vector<Option>& get_options() const { return _options; }
|
||||
const std::vector<widget_t>& get_extra_widgets() const {return m_extra_widgets;}
|
||||
const std::vector<Option>& get_options() const { return m_options; }
|
||||
|
||||
private:
|
||||
std::vector<Option> _options;//! {std::vector<Option>()};
|
||||
std::vector<widget_t> _extra_widgets;//! {std::vector<widget_t>()};
|
||||
std::vector<Option> m_options;//! {std::vector<Option>()};
|
||||
std::vector<widget_t> m_extra_widgets;//! {std::vector<widget_t>()};
|
||||
};
|
||||
|
||||
using t_optionfield_map = std::map<t_config_option_key, t_field>;
|
||||
|
||||
class OptionsGroup {
|
||||
public:
|
||||
const bool staticbox {true};
|
||||
const wxString title {wxString("")};
|
||||
size_t label_width {200};
|
||||
wxSizer* sizer {nullptr};
|
||||
column_t extra_column {nullptr};
|
||||
t_change m_on_change {nullptr};
|
||||
|
||||
const bool staticbox {true};
|
||||
const wxString title {wxString("")};
|
||||
size_t label_width {200};
|
||||
wxSizer* sizer {nullptr};
|
||||
column_t extra_column {nullptr};
|
||||
// t_change on_change {nullptr};
|
||||
wxFont sidetext_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
||||
wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
||||
|
||||
/// Returns a copy of the pointer of the parent wxWindow.
|
||||
/// Accessor function is because users are not allowed to change the parent
|
||||
/// but defining it as const means a lot of const_casts to deal with wx functions.
|
||||
inline wxWindow* parent() const { return _parent; }
|
||||
inline wxWindow* parent() const { return m_parent; }
|
||||
|
||||
wxFont sidetext_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
||||
wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
||||
|
||||
|
||||
void append_line(const Line& line);
|
||||
/*virtual*/ Line create_single_option_line(const Option& option) const;
|
||||
inline void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
|
||||
void append_line(const Line& line);
|
||||
Line create_single_option_line(const Option& option) const;
|
||||
inline void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
|
||||
|
||||
// return a non-owning pointer reference
|
||||
inline const Field* get_field(t_config_option_key id) const { try { return fields.at(id).get(); } catch (std::out_of_range e) { return nullptr; } }
|
||||
inline /*const*/ Field* get_field(t_config_option_key id) const { try { return m_fields.at(id).get(); } catch (std::out_of_range e) { return nullptr; } }
|
||||
//! inline const Option& get_option(t_config_option_key id) const { try { return options.at(id).get(); } catch (std::out_of_range e) { return nullptr; } }
|
||||
// }
|
||||
//! inline void set_value(t_config_option_key id, boost::any value) { try { fields.at(id).set_value(value); } catch (std::out_of_range e) {;} }
|
||||
inline void set_value(t_config_option_key id, boost::any value) { try { m_fields.at(id)->set_value(value); } catch (std::out_of_range e) {;} }
|
||||
boost::any get_value(t_config_option_key id) { try { return m_fields.at(id)->get_value(); } catch (std::out_of_range e) { ; } }
|
||||
|
||||
inline void enable() { for (auto& field : fields) field.second->enable(); }
|
||||
inline void disable() { for (auto& field : fields) field.second->disable(); }
|
||||
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
||||
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
||||
|
||||
|
||||
|
||||
OptionsGroup(wxWindow* _parent, std::string title, const ConfigDef& configs) : options(configs.options), _parent(_parent), title(wxString(title)) {
|
||||
OptionsGroup(wxWindow* _parent, std::string title, const ConfigDef& configs) :
|
||||
m_options_map(configs.options), m_parent(_parent), title(wxString(title)) {
|
||||
sizer = (staticbox ? new wxStaticBoxSizer(new wxStaticBox(_parent, wxID_ANY, title), wxVERTICAL) : new wxBoxSizer(wxVERTICAL));
|
||||
auto num_columns = 1U;
|
||||
if (label_width != 0) num_columns++;
|
||||
if (extra_column != nullptr) num_columns++;
|
||||
_grid_sizer = new wxFlexGridSizer(0, num_columns, 0,0);
|
||||
static_cast<wxFlexGridSizer*>(_grid_sizer)->SetFlexibleDirection(wxHORIZONTAL);
|
||||
static_cast<wxFlexGridSizer*>(_grid_sizer)->AddGrowableCol(label_width != 0);
|
||||
m_grid_sizer = new wxFlexGridSizer(0, num_columns, 0,0);
|
||||
static_cast<wxFlexGridSizer*>(m_grid_sizer)->SetFlexibleDirection(wxHORIZONTAL);
|
||||
static_cast<wxFlexGridSizer*>(m_grid_sizer)->AddGrowableCol(label_width != 0);
|
||||
|
||||
sizer->Add(_grid_sizer, 0, wxEXPAND | wxALL, wxOSX ? 0: 5);
|
||||
};
|
||||
sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX ? 0: 5);
|
||||
}
|
||||
|
||||
protected:
|
||||
const t_optiondef_map& options;
|
||||
wxWindow* _parent {nullptr};
|
||||
const t_optiondef_map& m_options_map;
|
||||
wxWindow* m_parent {nullptr};
|
||||
|
||||
/// Field list, contains unique_ptrs of the derived type.
|
||||
/// using types that need to know what it is beyond the public interface
|
||||
/// need to cast based on the related ConfigOptionDef.
|
||||
t_optionfield_map fields;
|
||||
bool _disabled {false};
|
||||
wxGridSizer* _grid_sizer {nullptr};
|
||||
t_optionfield_map m_fields;
|
||||
bool m_disabled {false};
|
||||
wxGridSizer* m_grid_sizer {nullptr};
|
||||
|
||||
/// Generate a wxSizer or wxWindow from a configuration option
|
||||
/// Precondition: opt resolves to a known ConfigOption
|
||||
/// Postcondition: fields contains a wx gui object.
|
||||
const t_field& build_field(const t_config_option_key& id, const ConfigOptionDef& opt);
|
||||
const t_field& build_field(const t_config_option_key& id);
|
||||
const t_field& build_field(const Option& opt);
|
||||
|
||||
virtual void _on_kill_focus (t_config_option_key id);
|
||||
//! virtual void _on_change(t_config_option_key id, config_value value);
|
||||
|
||||
const t_field& build_field(const t_config_option_key& id, const ConfigOptionDef& opt);
|
||||
const t_field& build_field(const t_config_option_key& id);
|
||||
const t_field& build_field(const Option& opt);
|
||||
|
||||
virtual void _on_kill_focus (t_config_option_key id);
|
||||
virtual void on_change_OG(t_config_option_key opt_id, boost::any value);
|
||||
};
|
||||
|
||||
class ConfigOptionsGroup: public OptionsGroup {
|
||||
public:
|
||||
/// reference to libslic3r config, non-owning pointer (?).
|
||||
const DynamicPrintConfig* config {nullptr};
|
||||
bool full_labels {0};
|
||||
ConfigOptionsGroup(wxWindow* parent, std::string title, DynamicPrintConfig* _config) : OptionsGroup(parent, title, *(_config->def())), config(_config) {}
|
||||
const DynamicPrintConfig* m_config {nullptr};
|
||||
bool m_full_labels {0};
|
||||
ConfigOptionsGroup(wxWindow* parent, std::string title, DynamicPrintConfig* _config) :
|
||||
OptionsGroup(parent, title, *(_config->def())), m_config(_config) {}
|
||||
|
||||
void on_change_OG(t_config_option_key opt_id, boost::any value) override;
|
||||
};
|
||||
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue