2017-12-13 13:45:10 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/settings.h>
|
|
|
|
//#include <wx/window.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 "libslic3r/libslic3r.h"
|
|
|
|
|
|
|
|
#include "Field.hpp"
|
|
|
|
//#include "slic3r_gui.hpp"
|
|
|
|
#include "GUI.hpp"
|
|
|
|
|
|
|
|
// 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
|
|
|
using column_t = std::function<wxSizer*(const Line&)>;
|
|
|
|
|
|
|
|
/// 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-01-05 14:11:33 +00:00
|
|
|
Option(const ConfigOptionDef& _opt, t_config_option_key id) :
|
|
|
|
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};
|
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-01-05 14:11:33 +00:00
|
|
|
Line(std::string label, std::string tooltip) :
|
|
|
|
label(wxString(label)), label_tooltip(wxString(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
|
|
|
};
|
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
using t_optionfield_map = std::map<t_config_option_key, t_field>;
|
2017-12-05 14:54:01 +00:00
|
|
|
|
|
|
|
class OptionsGroup {
|
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("")};
|
|
|
|
size_t label_width {200};
|
|
|
|
wxSizer* sizer {nullptr};
|
|
|
|
column_t extra_column {nullptr};
|
|
|
|
t_change m_on_change {nullptr};
|
2017-12-05 14:54:01 +00:00
|
|
|
|
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) };
|
2017-12-05 14:54:01 +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-01-05 14:11:33 +00:00
|
|
|
inline wxWindow* parent() const { return m_parent; }
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2018-01-07 17:41:40 +00:00
|
|
|
void append_line(const Line& line);
|
|
|
|
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-01-05 14:11:33 +00:00
|
|
|
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; } }
|
2017-12-13 13:45:10 +00:00
|
|
|
//! 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; } }
|
|
|
|
// }
|
2018-01-05 14:11:33 +00:00
|
|
|
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) { ; } }
|
2017-12-13 13:45:10 +00:00
|
|
|
|
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(); }
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-01-05 14:11:33 +00:00
|
|
|
OptionsGroup(wxWindow* _parent, std::string title, const ConfigDef& configs) :
|
2018-01-07 17:41:40 +00:00
|
|
|
m_options(configs.options), m_parent(_parent), title(wxString(title)) {
|
2017-12-13 13:45:10 +00:00
|
|
|
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++;
|
2018-01-05 14:11:33 +00:00
|
|
|
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);
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-01-05 14:11:33 +00:00
|
|
|
sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX ? 0: 5);
|
|
|
|
}
|
2017-12-13 13:45:10 +00:00
|
|
|
|
|
|
|
protected:
|
2018-01-07 17:41:40 +00:00
|
|
|
const t_optiondef_map& m_options;
|
2018-01-05 14:11:33 +00:00
|
|
|
wxWindow* m_parent {nullptr};
|
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};
|
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-01-05 14:11:33 +00:00
|
|
|
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);
|
2017-12-13 13:45:10 +00:00
|
|
|
|
2018-01-05 14:11:33 +00:00
|
|
|
virtual void _on_kill_focus (t_config_option_key id);
|
|
|
|
virtual void on_change_OG(t_config_option_key opt_id, boost::any value);
|
2017-12-13 13:45:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigOptionsGroup: public OptionsGroup {
|
|
|
|
public:
|
2018-01-05 14:11:33 +00:00
|
|
|
ConfigOptionsGroup(wxWindow* parent, std::string title, DynamicPrintConfig* _config) :
|
2018-01-07 17:41:40 +00:00
|
|
|
OptionsGroup(parent, title, *_config->def()), m_config(_config) {}
|
|
|
|
|
|
|
|
/// reference to libslic3r config, non-owning pointer (?).
|
|
|
|
DynamicPrintConfig* m_config {nullptr};
|
|
|
|
bool m_full_labels {0};
|
|
|
|
std::map< std::string, std::pair<std::string, int> > m_opt_map;
|
|
|
|
|
|
|
|
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*/{
|
|
|
|
Option option = get_option(title, idx);
|
|
|
|
return OptionsGroup::create_single_option_line(option);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
void on_change_OG(t_config_option_key opt_id, boost::any value) override;
|
2018-01-09 08:41:07 +00:00
|
|
|
void reload_config();
|
|
|
|
boost::any config_value(std::string opt_key, int opt_index, bool deserialize);
|
|
|
|
// return option value from config
|
|
|
|
boost::any get_config_value(DynamicPrintConfig& config, std::string opt_key, int opt_index = -1);
|
2018-01-11 09:33:17 +00:00
|
|
|
Field* get_fieldc(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.
|
|
|
|
// Currently used for the filament cooling legend only.
|
|
|
|
class ogStaticText :public wxStaticText{
|
|
|
|
public:
|
|
|
|
ogStaticText() {}
|
|
|
|
ogStaticText(wxWindow* parent, const char *text) : wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize){}
|
|
|
|
~ogStaticText(){}
|
|
|
|
|
|
|
|
void SetText(wxString value);
|
|
|
|
};
|
|
|
|
|
2017-12-13 13:45:10 +00:00
|
|
|
}}
|