2018-04-20 10:58:07 +00:00
|
|
|
#ifndef slic3r_OptionsGroup_hpp_
|
|
|
|
#define slic3r_OptionsGroup_hpp_
|
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/settings.h>
|
2017-12-05 14:54:01 +00:00
|
|
|
|
|
|
|
#include <map>
|
2017-12-13 13:45:10 +00:00
|
|
|
#include <functional>
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
#include "libslic3r/Config.hpp"
|
|
|
|
#include "libslic3r/PrintConfig.hpp"
|
|
|
|
|
|
|
|
#include "Field.hpp"
|
2018-10-01 13:09:31 +00:00
|
|
|
#include "GUI_App.hpp"
|
2017-12-13 13:45:10 +00:00
|
|
|
|
|
|
|
// Translate the ifdef
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
#define wxOSX true
|
|
|
|
#else
|
|
|
|
#define wxOSX false
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BORDER(a, b) ((wxOSX ? a : b))
|
|
|
|
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
|
|
|
|
/// Widget type describes a function object that returns a wxWindow (our widget) and accepts a wxWidget (parent window).
|
2017-12-19 10:59:42 +00:00
|
|
|
using widget_t = std::function<wxSizer*(wxWindow*)>;//!std::function<wxWindow*(wxWindow*)>;
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-03-02 08:08:11 +00:00
|
|
|
//auto default_label_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); //GetSystemColour
|
|
|
|
//auto modified_label_clr = *new wxColour(254, 189, 101);
|
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
/// Wraps a ConfigOptionDef and adds function object for creating a side_widget.
|
|
|
|
struct Option {
|
2018-01-05 14:11:33 +00:00
|
|
|
ConfigOptionDef opt { ConfigOptionDef() };
|
|
|
|
t_config_option_key opt_id;//! {""};
|
|
|
|
widget_t side_widget {nullptr};
|
|
|
|
bool readonly {false};
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2018-02-15 16:30:33 +00:00
|
|
|
Option(const ConfigOptionDef& _opt, t_config_option_key id) :
|
2018-02-18 22:11:43 +00:00
|
|
|
opt(_opt), opt_id(id) {}
|
2017-12-13 13:45:10 +00:00
|
|
|
};
|
|
|
|
using t_option = std::unique_ptr<Option>; //!
|
|
|
|
|
|
|
|
/// Represents option lines
|
2017-12-05 14:54:01 +00:00
|
|
|
class Line {
|
|
|
|
public:
|
2018-01-05 14:11:33 +00:00
|
|
|
wxString label {wxString("")};
|
|
|
|
wxString label_tooltip {wxString("")};
|
|
|
|
size_t full_width {0};
|
|
|
|
wxSizer* sizer {nullptr};
|
|
|
|
widget_t widget {nullptr};
|
2018-08-28 13:51:53 +00:00
|
|
|
std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr };
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2017-12-22 10:50:28 +00:00
|
|
|
void append_option(const Option& option) {
|
2018-01-05 14:11:33 +00:00
|
|
|
m_options.push_back(option);
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
void append_widget(const widget_t widget) {
|
2018-01-05 14:11:33 +00:00
|
|
|
m_extra_widgets.push_back(widget);
|
2017-12-13 13:45:10 +00:00
|
|
|
}
|
2018-02-07 16:13:52 +00:00
|
|
|
Line(wxString label, wxString tooltip) :
|
|
|
|
label(label), label_tooltip(tooltip) {}
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-01-05 14:11:33 +00:00
|
|
|
const std::vector<widget_t>& get_extra_widgets() const {return m_extra_widgets;}
|
|
|
|
const std::vector<Option>& get_options() const { return m_options; }
|
2017-12-13 13:45:10 +00:00
|
|
|
|
|
|
|
private:
|
2018-01-05 14:11:33 +00:00
|
|
|
std::vector<Option> m_options;//! {std::vector<Option>()};
|
|
|
|
std::vector<widget_t> m_extra_widgets;//! {std::vector<widget_t>()};
|
2017-12-05 14:54:01 +00:00
|
|
|
};
|
|
|
|
|
2019-04-13 21:46:52 +00:00
|
|
|
using column_t = std::function<wxWindow*(wxWindow* parent, const Line&)>;
|
2018-07-24 16:39:40 +00:00
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
using t_optionfield_map = std::map<t_config_option_key, t_field>;
|
2018-03-21 21:21:37 +00:00
|
|
|
using t_opt_map = std::map< std::string, std::pair<std::string, int> >;
|
2017-12-05 14:54:01 +00:00
|
|
|
|
|
|
|
class OptionsGroup {
|
2018-07-24 16:39:40 +00:00
|
|
|
wxStaticBox* stb;
|
2017-12-13 13:45:10 +00:00
|
|
|
public:
|
2018-01-05 14:11:33 +00:00
|
|
|
const bool staticbox {true};
|
|
|
|
const wxString title {wxString("")};
|
2019-04-13 21:46:52 +00:00
|
|
|
size_t label_width = 20 ;// {200};
|
2018-01-05 14:11:33 +00:00
|
|
|
wxSizer* sizer {nullptr};
|
|
|
|
column_t extra_column {nullptr};
|
2018-12-11 12:34:37 +00:00
|
|
|
t_change m_on_change { nullptr };
|
2019-04-23 10:35:26 +00:00
|
|
|
// To be called when the field loses focus, to assign a new initial value to the field.
|
|
|
|
// Used by the relative position / rotation / scale manipulation fields of the Object Manipulation UI.
|
2018-12-11 12:34:37 +00:00
|
|
|
t_kill_focus m_fill_empty_value { nullptr };
|
2018-12-11 12:57:50 +00:00
|
|
|
t_kill_focus m_set_focus { nullptr };
|
2018-03-06 11:34:20 +00:00
|
|
|
std::function<DynamicPrintConfig()> m_get_initial_config{ nullptr };
|
2018-03-16 16:25:11 +00:00
|
|
|
std::function<DynamicPrintConfig()> m_get_sys_config{ nullptr };
|
|
|
|
std::function<bool()> have_sys_config{ nullptr };
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2019-04-16 08:05:45 +00:00
|
|
|
std::function<void(wxWindow* win)> rescale_extra_column_item { nullptr };
|
|
|
|
std::function<void(wxWindow* win)> rescale_near_label_widget { nullptr };
|
|
|
|
|
2018-01-05 14:11:33 +00:00
|
|
|
wxFont sidetext_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
|
|
|
wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
2018-05-24 14:57:35 +00:00
|
|
|
int sidetext_width{ -1 };
|
2020-02-13 14:28:04 +00:00
|
|
|
int sublabel_width{ -1 };
|
2018-03-16 11:56:03 +00:00
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
/// 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.
|
2018-04-30 09:11:48 +00:00
|
|
|
inline wxWindow* parent() const {
|
2019-03-20 10:54:48 +00:00
|
|
|
#if 0//#ifdef __WXGTK__
|
2018-04-30 09:11:48 +00:00
|
|
|
return m_panel;
|
|
|
|
#else
|
|
|
|
return m_parent;
|
|
|
|
#endif /* __WXGTK__ */
|
|
|
|
}
|
2019-03-20 10:54:48 +00:00
|
|
|
#if 0//#ifdef __WXGTK__
|
2018-07-27 08:42:54 +00:00
|
|
|
wxWindow* get_parent() const {
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
#endif /* __WXGTK__ */
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2019-03-18 11:48:39 +00:00
|
|
|
wxWindow* ctrl_parent() const {
|
|
|
|
return this->stb ? (wxWindow*)this->stb : this->parent();
|
|
|
|
}
|
|
|
|
|
2018-11-22 14:12:09 +00:00
|
|
|
void append_line(const Line& line, wxStaticText** full_Label = nullptr);
|
2018-01-07 17:41:40 +00:00
|
|
|
Line create_single_option_line(const Option& option) const;
|
|
|
|
void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
|
2017-12-13 13:45:10 +00:00
|
|
|
|
|
|
|
// return a non-owning pointer reference
|
2018-04-13 10:35:04 +00:00
|
|
|
inline Field* get_field(const t_config_option_key& id) const{
|
2018-02-16 14:41:33 +00:00
|
|
|
if (m_fields.find(id) == m_fields.end()) return nullptr;
|
|
|
|
return m_fields.at(id).get();
|
|
|
|
}
|
2018-04-13 10:35:04 +00:00
|
|
|
bool set_value(const t_config_option_key& id, const boost::any& value, bool change_event = false) {
|
2018-02-16 14:41:33 +00:00
|
|
|
if (m_fields.find(id) == m_fields.end()) return false;
|
2018-03-15 17:06:26 +00:00
|
|
|
m_fields.at(id)->set_value(value, change_event);
|
2018-02-16 14:41:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-13 10:35:04 +00:00
|
|
|
boost::any get_value(const t_config_option_key& id) {
|
2018-02-16 14:41:33 +00:00
|
|
|
boost::any out;
|
|
|
|
if (m_fields.find(id) == m_fields.end()) ;
|
|
|
|
else
|
|
|
|
out = m_fields.at(id)->get_value();
|
|
|
|
return out;
|
|
|
|
}
|
2018-07-04 12:52:36 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-07-24 16:39:40 +00:00
|
|
|
void set_name(const wxString& new_name) {
|
|
|
|
stb->SetLabel(new_name);
|
|
|
|
}
|
|
|
|
|
2018-01-05 14:11:33 +00:00
|
|
|
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
|
|
|
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
2018-05-24 14:57:35 +00:00
|
|
|
void set_grid_vgap(int gap) { m_grid_sizer->SetVGap(gap); }
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-11-14 11:33:48 +00:00
|
|
|
void set_show_modified_btns_val(bool show) {
|
|
|
|
m_show_modified_btns = show;
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:41:16 +00:00
|
|
|
void clear_fields_except_of(const std::vector<std::string> left_fields);
|
|
|
|
|
2019-07-10 13:55:53 +00:00
|
|
|
void hide_labels() {
|
|
|
|
label_width = 0;
|
|
|
|
m_grid_sizer->SetCols(m_grid_sizer->GetEffectiveColsCount()-1);
|
|
|
|
static_cast<wxFlexGridSizer*>(m_grid_sizer)->AddGrowableCol(!extra_column ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
2018-07-24 16:39:40 +00:00
|
|
|
OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false,
|
2018-10-19 11:55:29 +00:00
|
|
|
column_t extra_clmn = nullptr) :
|
|
|
|
m_parent(_parent), title(title),
|
|
|
|
m_show_modified_btns(is_tab_opt),
|
2018-10-31 11:56:08 +00:00
|
|
|
staticbox(title!=""), extra_column(extra_clmn) {
|
2018-09-17 13:12:13 +00:00
|
|
|
if (staticbox) {
|
|
|
|
stb = new wxStaticBox(_parent, wxID_ANY, title);
|
2019-11-12 12:54:36 +00:00
|
|
|
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);
|
2018-10-01 13:09:31 +00:00
|
|
|
stb->SetFont(wxGetApp().bold_font());
|
2019-03-18 11:48:39 +00:00
|
|
|
} else
|
|
|
|
stb = nullptr;
|
2018-07-27 08:42:54 +00:00
|
|
|
sizer = (staticbox ? new wxStaticBoxSizer(stb, wxVERTICAL) : new wxBoxSizer(wxVERTICAL));
|
2017-12-13 13:45:10 +00:00
|
|
|
auto num_columns = 1U;
|
|
|
|
if (label_width != 0) num_columns++;
|
|
|
|
if (extra_column != nullptr) num_columns++;
|
2018-05-24 14:57:35 +00:00
|
|
|
m_grid_sizer = new wxFlexGridSizer(0, num_columns, 1,0);
|
2018-05-23 14:21:42 +00:00
|
|
|
static_cast<wxFlexGridSizer*>(m_grid_sizer)->SetFlexibleDirection(wxBOTH/*wxHORIZONTAL*/);
|
2018-10-19 11:55:29 +00:00
|
|
|
static_cast<wxFlexGridSizer*>(m_grid_sizer)->AddGrowableCol(label_width == 0 ? 0 : !extra_column ? 1 : 2 );
|
2019-03-20 10:54:48 +00:00
|
|
|
#if 0//#ifdef __WXGTK__
|
2018-04-30 09:11:48 +00:00
|
|
|
m_panel = new wxPanel( _parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
|
|
|
sizer->Fit(m_panel);
|
|
|
|
sizer->Add(m_panel, 0, wxEXPAND | wxALL, wxOSX||!staticbox ? 0: 5);
|
|
|
|
#else
|
2018-04-25 09:10:34 +00:00
|
|
|
sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX||!staticbox ? 0: 5);
|
2018-04-30 09:11:48 +00:00
|
|
|
#endif /* __WXGTK__ */
|
2018-01-05 14:11:33 +00:00
|
|
|
}
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
wxGridSizer* get_grid_sizer() { return m_grid_sizer; }
|
2018-08-28 13:51:53 +00:00
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
protected:
|
2018-01-16 15:28:01 +00:00
|
|
|
std::map<t_config_option_key, Option> m_options;
|
2018-01-05 14:11:33 +00:00
|
|
|
wxWindow* m_parent {nullptr};
|
2018-10-21 21:09:24 +00:00
|
|
|
std::vector<ConfigOptionMode> m_options_mode;
|
2019-04-16 08:05:45 +00:00
|
|
|
std::vector<wxWindow*> m_extra_column_item_ptrs;
|
|
|
|
std::vector<wxWindow*> m_near_label_widget_ptrs;
|
2017-12-13 13:45:10 +00:00
|
|
|
|
|
|
|
/// 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.
|
2018-01-05 14:11:33 +00:00
|
|
|
t_optionfield_map m_fields;
|
|
|
|
bool m_disabled {false};
|
|
|
|
wxGridSizer* m_grid_sizer {nullptr};
|
2018-03-07 14:05:41 +00:00
|
|
|
// "true" if option is created in preset tabs
|
2018-06-21 14:15:56 +00:00
|
|
|
bool m_show_modified_btns{ false };
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-04-30 09:11:48 +00:00
|
|
|
// This panel is needed for correct showing of the ToolTips for Button, StaticText and CheckBox
|
|
|
|
// Tooltips on GTK doesn't work inside wxStaticBoxSizer unless you insert a panel
|
|
|
|
// inside it before you insert the other controls.
|
2019-03-20 10:54:48 +00:00
|
|
|
#if 0//#ifdef__WXGTK__
|
2018-04-30 09:11:48 +00:00
|
|
|
wxPanel* m_panel {nullptr};
|
|
|
|
#endif /* __WXGTK__ */
|
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
/// Generate a wxSizer or wxWindow from a configuration option
|
|
|
|
/// Precondition: opt resolves to a known ConfigOption
|
|
|
|
/// Postcondition: fields contains a wx gui object.
|
2018-03-02 08:08:11 +00:00
|
|
|
const t_field& build_field(const t_config_option_key& id, const ConfigOptionDef& opt, wxStaticText* label = nullptr);
|
|
|
|
const t_field& build_field(const t_config_option_key& id, wxStaticText* label = nullptr);
|
|
|
|
const t_field& build_field(const Option& opt, wxStaticText* label = nullptr);
|
2018-05-24 14:57:35 +00:00
|
|
|
void add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field);
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-12-11 12:34:37 +00:00
|
|
|
virtual void on_kill_focus(const std::string& opt_key) {};
|
2018-12-11 12:57:50 +00:00
|
|
|
virtual void on_set_focus(const std::string& opt_key);
|
2018-04-13 10:35:04 +00:00
|
|
|
virtual void on_change_OG(const t_config_option_key& opt_id, const boost::any& value);
|
2018-10-31 11:56:08 +00:00
|
|
|
virtual void back_to_initial_value(const std::string& opt_key) {}
|
|
|
|
virtual void back_to_sys_value(const std::string& opt_key) {}
|
2017-12-13 13:45:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigOptionsGroup: public OptionsGroup {
|
|
|
|
public:
|
2018-07-24 16:39:40 +00:00
|
|
|
ConfigOptionsGroup( wxWindow* parent, const wxString& title, DynamicPrintConfig* _config = nullptr,
|
2018-10-19 11:55:29 +00:00
|
|
|
bool is_tab_opt = false, column_t extra_clmn = nullptr) :
|
|
|
|
OptionsGroup(parent, title, is_tab_opt, extra_clmn), m_config(_config) {}
|
2018-01-07 17:41:40 +00:00
|
|
|
|
|
|
|
/// reference to libslic3r config, non-owning pointer (?).
|
|
|
|
DynamicPrintConfig* m_config {nullptr};
|
|
|
|
bool m_full_labels {0};
|
2018-03-21 21:21:37 +00:00
|
|
|
t_opt_map m_opt_map;
|
2018-01-07 17:41:40 +00:00
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
void set_config(DynamicPrintConfig* config) { m_config = config; }
|
2018-04-13 10:35:04 +00:00
|
|
|
Option get_option(const std::string& opt_key, int opt_index = -1);
|
|
|
|
Line create_single_option_line(const std::string& title, int idx = -1) /*const*/{
|
2018-01-07 17:41:40 +00:00
|
|
|
Option option = get_option(title, idx);
|
|
|
|
return OptionsGroup::create_single_option_line(option);
|
|
|
|
}
|
2019-07-03 12:52:39 +00:00
|
|
|
Line create_single_option_line(const Option& option) const {
|
|
|
|
return OptionsGroup::create_single_option_line(option);
|
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
void append_single_option_line(const Option& option) {
|
|
|
|
OptionsGroup::append_single_option_line(option);
|
|
|
|
}
|
|
|
|
void append_single_option_line(const std::string title, int idx = -1)
|
|
|
|
{
|
|
|
|
Option option = get_option(title, idx);
|
|
|
|
append_single_option_line(option);
|
|
|
|
}
|
2018-01-05 14:11:33 +00:00
|
|
|
|
2018-04-13 10:35:04 +00:00
|
|
|
void on_change_OG(const t_config_option_key& opt_id, const boost::any& value) override;
|
|
|
|
void back_to_initial_value(const std::string& opt_key) override;
|
|
|
|
void back_to_sys_value(const std::string& opt_key) override;
|
|
|
|
void back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key);
|
2019-04-24 09:01:59 +00:00
|
|
|
void on_kill_focus(const std::string& opt_key) override;
|
2018-01-09 08:41:07 +00:00
|
|
|
void reload_config();
|
2018-10-21 21:09:24 +00:00
|
|
|
// return value shows visibility : false => all options are hidden
|
2018-11-09 17:39:07 +00:00
|
|
|
void Hide();
|
|
|
|
void Show(const bool show);
|
2018-10-21 21:09:24 +00:00
|
|
|
bool update_visibility(ConfigOptionMode mode);
|
2019-04-24 23:45:00 +00:00
|
|
|
void msw_rescale();
|
2018-04-13 10:35:04 +00:00
|
|
|
boost::any config_value(const std::string& opt_key, int opt_index, bool deserialize);
|
2018-01-09 08:41:07 +00:00
|
|
|
// return option value from config
|
2018-04-13 10:35:04 +00:00
|
|
|
boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1);
|
|
|
|
Field* get_fieldc(const t_config_option_key& opt_key, int opt_index);
|
2017-12-13 13:45:10 +00:00
|
|
|
};
|
|
|
|
|
2018-01-15 11:13:05 +00:00
|
|
|
// Static text shown among the options.
|
|
|
|
class ogStaticText :public wxStaticText{
|
|
|
|
public:
|
|
|
|
ogStaticText() {}
|
2018-10-31 11:56:08 +00:00
|
|
|
ogStaticText(wxWindow* parent, const char *text) : wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize) {}
|
|
|
|
~ogStaticText() {}
|
2018-01-15 11:13:05 +00:00
|
|
|
|
2018-04-26 10:40:17 +00:00
|
|
|
void SetText(const wxString& value, bool wrap = true);
|
2018-01-15 11:13:05 +00:00
|
|
|
};
|
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
}}
|
2018-04-20 10:58:07 +00:00
|
|
|
|
|
|
|
#endif /* slic3r_OptionsGroup_hpp_ */
|