Prototype of the hiding according to view mode

+ Added mode icon near option's label
+ Fixed segmentation fault on Linux
This commit is contained in:
YuSanka 2018-10-19 13:55:29 +02:00
parent 5d94e6adb8
commit f47949504e
13 changed files with 242 additions and 53 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -61,6 +61,12 @@ enum ConfigOptionType {
coEnum = 8,
};
enum ConfigOptionMode {
comSimple,
comMiddle,
comExpert
};
// A generic value of a configuration option.
class ConfigOption {
public:
@ -982,6 +988,7 @@ public:
// By setting min=0, only nonnegative input is allowed.
int min = INT_MIN;
int max = INT_MAX;
ConfigOptionMode mode = comSimple;
// Legacy names for this configuration option.
// Used when parsing legacy configuration file.
std::vector<t_config_option_key> aliases;

File diff suppressed because it is too large Load Diff

View File

@ -482,7 +482,8 @@ ConfigMenuIDs GUI_App::get_view_mode()
return ConfigMenuModeSimple;
const auto mode = app_config->get("view_mode");
return mode == "expert" ? ConfigMenuModeExpert : ConfigMenuModeSimple;
return mode == "expert" ? ConfigMenuModeExpert :
mode == "simple" ? ConfigMenuModeSimple : ConfigMenuModeMiddle;
}
// Update view mode according to selected menu
@ -500,6 +501,11 @@ void GUI_App::update_mode()
sidebar().Layout();
mainframe->m_plater->Layout();
ConfigOptionMode opt_mode = mode == ConfigMenuModeSimple ? comSimple :
mode == ConfigMenuModeExpert ? comExpert : comMiddle;
for (auto tab : tabs_list)
tab->update_visibility(opt_mode);
}
void GUI_App::add_config_menu(wxMenuBar *menu)
@ -519,6 +525,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
local_menu->AppendSeparator();
auto mode_menu = new wxMenu();
mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeSimple, _(L("&Simple")), _(L("Simple View Mode")));
mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeMiddle, _(L("&Middle")), _(L("Middle View Mode")));
mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeExpert, _(L("&Expert")), _(L("Expert View Mode")));
mode_menu->Check(config_id_base + get_view_mode(), true);
local_menu->AppendSubMenu(mode_menu, _(L("&Mode")), _(L("Slic3r View Mode")));
@ -589,8 +596,9 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
}
});
mode_menu->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) {
std::string mode = event.GetId() - config_id_base == ConfigMenuModeExpert ?
"expert" : "simple";
int id_mode = event.GetId() - config_id_base;
std::string mode = id_mode == ConfigMenuModeExpert ? "expert" :
id_mode == ConfigMenuModeSimple ? "simple" : "middle";
app_config->set("view_mode", mode);
app_config->save();
update_mode();

View File

@ -51,6 +51,7 @@ enum ConfigMenuIDs {
ConfigMenuUpdate,
ConfigMenuPreferences,
ConfigMenuModeSimple,
ConfigMenuModeMiddle,
ConfigMenuModeExpert,
ConfigMenuLanguage,
ConfigMenuFlashFirmware,

View File

@ -221,7 +221,7 @@ void ObjectManipulation::update_settings_list()
if (cat.second.size() == 1 && cat.second[0] == "extruder")
continue;
auto optgroup = std::make_shared<ConfigOptionsGroup>(parent, cat.first, config, false, ogDEFAULT, extra_column);
auto optgroup = std::make_shared<ConfigOptionsGroup>(parent, cat.first, config, false, extra_column);
optgroup->label_width = 150;
optgroup->sidetext_width = 70;

View File

@ -156,16 +156,8 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
#endif /* __WXGTK__ */
// if we have an extra column, build it
if (extra_column) {
if (extra_column) {
grid_sizer->Add(extra_column(parent(), line), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3);
}
else {
// if the callback provides no sizer for the extra cell, put a spacer
grid_sizer->AddSpacer(1);
}
}
if (extra_column)
grid_sizer->Add(extra_column(parent(), line), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3);
// Build a label if we have it
wxStaticText* label=nullptr;
@ -182,16 +174,14 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
label->SetFont(label_font);
label->Wrap(label_width); // avoid a Linux/GTK bug
if (!line.near_label_widget)
grid_sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) |
(m_flag == ogSIDE_OPTIONS_VERTICAL ? wxTOP : wxALIGN_CENTER_VERTICAL), 5);
grid_sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) | wxALIGN_CENTER_VERTICAL, 5);
else {
// If we're here, we have some widget near the label
// so we need a horizontal sizer to arrange these things
auto sizer = new wxBoxSizer(wxHORIZONTAL);
grid_sizer->Add(sizer, 0, wxEXPAND | (staticbox ? wxALL : wxBOTTOM | wxTOP | wxLEFT), staticbox ? 0 : 1);
sizer->Add(line.near_label_widget(parent()), 0, wxRIGHT, 7);
sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) |
(m_flag == ogSIDE_OPTIONS_VERTICAL ? wxTOP : wxALIGN_CENTER_VERTICAL), 5);
sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) | wxALIGN_CENTER_VERTICAL, 5);
}
if (line.label_tooltip.compare("") != 0)
label->SetToolTip(line.label_tooltip);
@ -208,7 +198,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
// If we're here, we have more than one option or a single option with sidetext
// so we need a horizontal sizer to arrange these things
auto sizer = new wxBoxSizer(m_flag == ogSIDE_OPTIONS_VERTICAL ? wxVERTICAL : wxHORIZONTAL);
auto sizer = new wxBoxSizer(wxHORIZONTAL);
grid_sizer->Add(sizer, 0, wxEXPAND | (staticbox ? wxALL : wxBOTTOM | wxTOP | wxLEFT), staticbox ? 0 : 1);
// If we have a single option with no sidetext just add it directly to the grid sizer
if (option_set.size() == 1 && option_set.front().opt.sidetext.size() == 0 &&
@ -227,14 +217,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
for (auto opt : option_set) {
ConfigOptionDef option = opt.opt;
wxSizer* sizer_tmp;
if (m_flag == ogSIDE_OPTIONS_VERTICAL){
auto sz = new wxFlexGridSizer(1, 3, 2, 2);
sz->RemoveGrowableCol(2);
sizer_tmp = sz;
}
else
sizer_tmp = sizer;
wxSizer* sizer_tmp = sizer;
// add label if any
if (option.label != "") {
wxString str_label = _(option.label);
@ -260,7 +243,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
auto sidetext = new wxStaticText( parent(), wxID_ANY, _(option.sidetext), wxDefaultPosition,
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);
sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4);
field->set_side_text_ptr(sidetext);
}
@ -269,13 +252,10 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/*
sizer_tmp->Add(opt.side_widget(parent())/*!.target<wxWindow>()*/, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); //! requires verification
}
if (opt.opt_id != option_set.back().opt_id && m_flag != ogSIDE_OPTIONS_VERTICAL) //! istead of (opt != option_set.back())
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
{
sizer_tmp->AddSpacer(6);
}
if (m_flag == ogSIDE_OPTIONS_VERTICAL)
sizer->Add(sizer_tmp, 0, wxALIGN_RIGHT|wxALL, 0);
}
// add extra sizers if any
for (auto extra_widget : line.get_extra_widgets()) {
@ -403,6 +383,27 @@ void ConfigOptionsGroup::reload_config(){
}
void ConfigOptionsGroup::update_visibility(ConfigOptionMode mode) {
int rows = m_grid_sizer->GetEffectiveRowsCount();
if (rows != m_options.size())
return;
sizer->ShowItems(true);
int coef = 0;
const int cols = m_grid_sizer->GetCols();
for (std::map<t_config_option_key, Option>::iterator it = m_options.begin(); it != m_options.end(); ++it) {
const bool show = it->second.opt.mode <= mode;
if (!show) {
for (int i = 0; i < cols; ++i)
m_grid_sizer->Show(coef + i, show);
}
coef+= cols;
}
if (!sizer->IsShown(m_grid_sizer))
sizer->ShowItems(false);
}
boost::any ConfigOptionsGroup::config_value(const std::string& opt_key, int opt_index, bool deserialize){
if (deserialize) {

View File

@ -27,11 +27,6 @@
namespace Slic3r { namespace GUI {
enum ogDrawFlag{
ogDEFAULT,
ogSIDE_OPTIONS_VERTICAL
};
/// Widget type describes a function object that returns a wxWindow (our widget) and accepts a wxWidget (parent window).
using widget_t = std::function<wxSizer*(wxWindow*)>;//!std::function<wxWindow*(wxWindow*)>;
@ -151,7 +146,6 @@ public:
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; }
void set_grid_vgap(int gap) { m_grid_sizer->SetVGap(gap); }
void set_show_modified_btns_val(bool show) {
@ -159,9 +153,10 @@ public:
}
OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false,
ogDrawFlag flag = ogDEFAULT, column_t extra_clmn = nullptr) :
m_parent(_parent), title(title), m_show_modified_btns(is_tab_opt),
staticbox(title!=""), m_flag(flag), extra_column(extra_clmn){
column_t extra_clmn = nullptr) :
m_parent(_parent), title(title),
m_show_modified_btns(is_tab_opt),
staticbox(title!=""), extra_column(extra_clmn){
if (staticbox) {
stb = new wxStaticBox(_parent, wxID_ANY, title);
stb->SetFont(wxGetApp().bold_font());
@ -172,7 +167,7 @@ public:
if (extra_column != nullptr) num_columns++;
m_grid_sizer = new wxFlexGridSizer(0, num_columns, 1,0);
static_cast<wxFlexGridSizer*>(m_grid_sizer)->SetFlexibleDirection(wxBOTH/*wxHORIZONTAL*/);
static_cast<wxFlexGridSizer*>(m_grid_sizer)->AddGrowableCol(label_width != 0);
static_cast<wxFlexGridSizer*>(m_grid_sizer)->AddGrowableCol(label_width == 0 ? 0 : !extra_column ? 1 : 2 );
#ifdef __WXGTK__
m_panel = new wxPanel( _parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
sizer->Fit(m_panel);
@ -197,8 +192,6 @@ protected:
// "true" if option is created in preset tabs
bool m_show_modified_btns{ false };
ogDrawFlag m_flag{ ogDEFAULT };
// 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.
@ -223,8 +216,8 @@ protected:
class ConfigOptionsGroup: public OptionsGroup {
public:
ConfigOptionsGroup( wxWindow* parent, const wxString& title, DynamicPrintConfig* _config = nullptr,
bool is_tab_opt = false, ogDrawFlag flag = ogDEFAULT, column_t extra_clmn = nullptr) :
OptionsGroup(parent, title, is_tab_opt, flag, extra_clmn), m_config(_config) {}
bool is_tab_opt = false, column_t extra_clmn = nullptr) :
OptionsGroup(parent, title, is_tab_opt, extra_clmn), m_config(_config) {}
/// reference to libslic3r config, non-owning pointer (?).
DynamicPrintConfig* m_config {nullptr};
@ -252,6 +245,7 @@ public:
void back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key);
void on_kill_focus() override{ reload_config();}
void reload_config();
void update_visibility(ConfigOptionMode mode);
boost::any config_value(const std::string& opt_key, int opt_index, bool deserialize);
// return option value from config
boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1);

View File

@ -632,6 +632,14 @@ void Tab::reload_config(){
Thaw();
}
void Tab::update_visibility(ConfigOptionMode mode)
{
Freeze();
for (auto page : m_pages)
page->update_visibility(mode);
Thaw();
}
Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const
{
Field* field = nullptr;
@ -1021,7 +1029,7 @@ void TabPrint::build()
page = add_options_page(_(L("Dependencies")), "wrench.png");
optgroup = page->new_optgroup(_(L("Profile dependencies")));
line = { _(L("Compatible printers")), "" };
line = optgroup->create_single_option_line("compatible_printers");//{ _(L("Compatible printers")), "" };
line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn);
};
@ -1347,7 +1355,7 @@ void TabFilament::build()
optgroup->append_single_option_line("filament_cooling_final_speed");
optgroup->append_single_option_line("filament_minimal_purge_on_wipe_tower");
line = { _(L("Ramming")), "" };
line = optgroup->create_single_option_line("filament_ramming_parameters");// { _(L("Ramming")), "" };
line.widget = [this](wxWindow* parent){
auto ramming_dialog_btn = new wxButton(parent, wxID_ANY, _(L("Ramming settings"))+dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
auto sizer = new wxBoxSizer(wxHORIZONTAL);
@ -1387,7 +1395,7 @@ void TabFilament::build()
page = add_options_page(_(L("Dependencies")), "wrench.png");
optgroup = page->new_optgroup(_(L("Profile dependencies")));
line = { _(L("Compatible printers")), "" };
line = optgroup->create_single_option_line("compatible_printers");//{ _(L("Compatible printers")), "" };
line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn);
};
@ -1482,7 +1490,7 @@ void TabPrinter::build_fff()
auto page = add_options_page(_(L("General")), "printer_empty.png");
auto optgroup = page->new_optgroup(_(L("Size and coordinates")));
Line line{ _(L("Bed shape")), "" };
Line line = optgroup->create_single_option_line("bed_shape");//{ _(L("Bed shape")), "" };
line.widget = [this](wxWindow* parent){
auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
btn->SetFont(wxGetApp().small_font());
@ -1514,6 +1522,7 @@ void TabPrinter::build_fff()
def.label = L("Extruders");
def.tooltip = L("Number of extruders of the printer.");
def.min = 1;
def.mode = comExpert;
Option option(def, "extruders_count");
optgroup->append_single_option_line(option);
optgroup->append_single_option_line("single_extruder_multi_material");
@ -2681,6 +2690,12 @@ void Page::reload_config()
group->reload_config();
}
void Page::update_visibility(ConfigOptionMode mode)
{
for (auto group : m_optgroups)
group->update_visibility(mode);
}
Field* Page::get_field(const t_config_option_key& opt_key, int opt_index /*= -1*/) const
{
Field* field = nullptr;
@ -2704,8 +2719,22 @@ bool Page::set_value(const t_config_option_key& opt_key, const boost::any& value
// package Slic3r::GUI::Tab::Page;
ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_label_width /*= -1*/)
{
auto extra_column = [](wxWindow* parent, const Line& line)
{
std::string bmp_name;
if (line.get_options().size() == 0)
bmp_name = "error.png";
else {
auto mode = line.get_options()[0].opt.mode; //we assume that we have one option per line
bmp_name = mode == comExpert ? "mode_expert.png" :
mode == comMiddle ? "mode_middle.png" : "mode_simple.png";
}
auto bmp = new wxStaticBitmap(parent, wxID_ANY, wxBitmap(from_u8(var(bmp_name)), wxBITMAP_TYPE_PNG));
return bmp;
};
//! config_ have to be "right"
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config, true);
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config, true, extra_column);
if (noncommon_label_width >= 0)
optgroup->label_width = noncommon_label_width;
@ -2844,7 +2873,7 @@ void TabSLAMaterial::build()
page = add_options_page(_(L("Dependencies")), "wrench.png");
optgroup = page->new_optgroup(_(L("Profile dependencies")));
auto line = Line { _(L("Compatible printers")), "" };
Line line = optgroup->create_single_option_line("compatible_printers");//Line { _(L("Compatible printers")), "" };
line.widget = [this](wxWindow* parent){
return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn);
};

View File

@ -73,6 +73,7 @@ public:
size_t iconID() const { return m_iconID; }
void set_config(DynamicPrintConfig* config_in) { m_config = config_in; }
void reload_config();
void update_visibility(ConfigOptionMode mode);
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
bool set_value(const t_config_option_key& opt_key, const boost::any& value);
ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1);
@ -249,6 +250,7 @@ public:
void update_tab_ui();
void load_config(const DynamicPrintConfig& config);
virtual void reload_config();
void update_visibility(ConfigOptionMode mode);
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
bool set_value(const t_config_option_key& opt_key, const boost::any& value);
wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText);

View File

@ -261,7 +261,10 @@ public:
m_name = "Settings to modified";
}
else if (type == itInstanceRoot) {
m_name = "Instances";
m_name = "Instances";
#ifdef __WXGTK__
m_container = true;
#endif //__WXGTK__
}
else if (type == itInstance) {
m_idx = parent->GetChildCount();