Implemented ModeSizer with ModeButtons for the mode view changing from the settings tabs and plater

This commit is contained in:
YuSanka 2019-01-10 11:05:58 +01:00
parent 71359d756f
commit c62a51ead1
15 changed files with 199 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

View File

@ -63,7 +63,7 @@ enum ConfigOptionType {
}; };
enum ConfigOptionMode { enum ConfigOptionMode {
comSimple, comSimple = 0,
comAdvanced, comAdvanced,
comExpert comExpert
}; };

View File

@ -556,21 +556,23 @@ Tab* GUI_App::get_tab(Preset::Type type)
return nullptr; return nullptr;
} }
ConfigMenuIDs GUI_App::get_view_mode() ConfigOptionMode GUI_App::get_mode()
{ {
if (!app_config->has("view_mode")) if (!app_config->has("view_mode"))
return ConfigMenuModeSimple; return comSimple;
const auto mode = app_config->get("view_mode"); const auto mode = app_config->get("view_mode");
return mode == "expert" ? ConfigMenuModeExpert : return mode == "expert" ? comExpert :
mode == "simple" ? ConfigMenuModeSimple : ConfigMenuModeAdvanced; mode == "simple" ? comSimple : comAdvanced;
} }
ConfigOptionMode GUI_App::get_opt_mode() { void GUI_App::save_mode(const /*ConfigOptionMode*/int mode)
const ConfigMenuIDs mode = wxGetApp().get_view_mode(); {
const std::string mode_str = mode == comExpert ? "expert" :
return mode == ConfigMenuModeSimple ? comSimple : mode == comSimple ? "simple" : "advanced";
mode == ConfigMenuModeExpert ? comExpert : comAdvanced; app_config->set("view_mode", mode_str);
app_config->save();
update_mode();
} }
// Update view mode according to selected menu // Update view mode according to selected menu
@ -578,13 +580,15 @@ void GUI_App::update_mode()
{ {
wxWindowUpdateLocker noUpdates(&sidebar()); wxWindowUpdateLocker noUpdates(&sidebar());
ConfigMenuIDs mode = wxGetApp().get_view_mode(); const ConfigOptionMode mode = wxGetApp().get_mode();
obj_list()->get_sizer()->Show(mode == ConfigMenuModeExpert); obj_list()->get_sizer()->Show(mode == comExpert);
sidebar().set_mode_value(mode); sidebar().set_mode_value(mode);
// sidebar().show_buttons(mode == ConfigMenuModeExpert); // sidebar().show_buttons(mode == comExpert);
obj_list()->update_selections(); obj_list()->update_selections();
sidebar().update_mode_sizer(mode);
sidebar().Layout(); sidebar().Layout();
for (auto tab : tabs_list) for (auto tab : tabs_list)
@ -612,7 +616,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeSimple, _(L("Simple")), _(L("Simple View Mode"))); mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeSimple, _(L("Simple")), _(L("Simple View Mode")));
mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeAdvanced, _(L("Advanced")), _(L("Advanced View Mode"))); mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeAdvanced, _(L("Advanced")), _(L("Advanced View Mode")));
mode_menu->AppendRadioItem(config_id_base + ConfigMenuModeExpert, _(L("Expert")), _(L("Expert 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); mode_menu->Check(config_id_base + ConfigMenuModeSimple + get_mode(), true);
local_menu->AppendSubMenu(mode_menu, _(L("Mode")), _(L("Slic3r View Mode"))); local_menu->AppendSubMenu(mode_menu, _(L("Mode")), _(L("Slic3r View Mode")));
local_menu->AppendSeparator(); local_menu->AppendSeparator();
local_menu->Append(config_id_base + ConfigMenuLanguage, _(L("Change Application Language"))); local_menu->Append(config_id_base + ConfigMenuLanguage, _(L("Change Application Language")));
@ -682,11 +686,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
}); });
mode_menu->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) { mode_menu->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) {
int id_mode = event.GetId() - config_id_base; int id_mode = event.GetId() - config_id_base;
std::string mode = id_mode == ConfigMenuModeExpert ? "expert" : save_mode(id_mode - ConfigMenuModeSimple);
id_mode == ConfigMenuModeSimple ? "simple" : "advanced";
app_config->set("view_mode", mode);
app_config->save();
update_mode();
}); });
menu->Append(local_menu, _(L("&Configuration"))); menu->Append(local_menu, _(L("&Configuration")));
} }

View File

@ -134,8 +134,8 @@ public:
void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers); void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers);
Tab* get_tab(Preset::Type type); Tab* get_tab(Preset::Type type);
ConfigMenuIDs get_view_mode(); ConfigOptionMode get_mode();
ConfigOptionMode get_opt_mode(); void save_mode(const /*ConfigOptionMode*/int mode) ;
void update_mode(); void update_mode();
void add_config_menu(wxMenuBar *menu); void add_config_menu(wxMenuBar *menu);

View File

@ -680,7 +680,7 @@ void ObjectList::append_menu_items_add_volume(wxMenu* menu)
menu->Destroy(settings_id); menu->Destroy(settings_id);
} }
if (wxGetApp().get_view_mode() == ConfigMenuModeSimple) if (wxGetApp().get_mode() == comSimple)
{ {
append_menu_item(menu, wxID_ANY, _(L("Add part")), "", append_menu_item(menu, wxID_ANY, _(L("Add part")), "",
[this](wxCommandEvent&) { load_subobject(ModelVolume::MODEL_PART); }, *m_bmp_vector[ModelVolume::MODEL_PART]); [this](wxCommandEvent&) { load_subobject(ModelVolume::MODEL_PART); }, *m_bmp_vector[ModelVolume::MODEL_PART]);
@ -719,7 +719,7 @@ wxMenuItem* ObjectList::append_menu_item_settings(wxMenu* menu)
if (settings_id != wxNOT_FOUND) if (settings_id != wxNOT_FOUND)
menu->Destroy(settings_id); menu->Destroy(settings_id);
if (wxGetApp().get_view_mode() == ConfigMenuModeSimple) if (wxGetApp().get_mode() == comSimple)
return nullptr; return nullptr;
auto menu_item = new wxMenuItem(menu, wxID_ANY, _(L("Add settings"))); auto menu_item = new wxMenuItem(menu, wxID_ANY, _(L("Add settings")));

View File

@ -224,7 +224,7 @@ void ObjectManipulation::Show(const bool show)
m_og->Show(show); m_og->Show(show);
if (show && wxGetApp().get_view_mode() != ConfigMenuModeSimple) { if (show && wxGetApp().get_mode() != comSimple) {
m_og->get_grid_sizer()->Show(size_t(0), false); m_og->get_grid_sizer()->Show(size_t(0), false);
m_og->get_grid_sizer()->Show(size_t(1), false); m_og->get_grid_sizer()->Show(size_t(1), false);
} }

View File

@ -434,6 +434,7 @@ struct Sidebar::priv
wxScrolledWindow *scrolled; wxScrolledWindow *scrolled;
PrusaModeSizer *mode_sizer;
wxFlexGridSizer *sizer_presets; wxFlexGridSizer *sizer_presets;
PresetComboBox *combo_print; PresetComboBox *combo_print;
std::vector<PresetComboBox*> combos_filament; std::vector<PresetComboBox*> combos_filament;
@ -492,6 +493,9 @@ Sidebar::Sidebar(Plater *parent)
auto *scrolled_sizer = new wxBoxSizer(wxVERTICAL); auto *scrolled_sizer = new wxBoxSizer(wxVERTICAL);
p->scrolled->SetSizer(scrolled_sizer); p->scrolled->SetSizer(scrolled_sizer);
// Sizer with buttons for mode changing
p->mode_sizer = new PrusaModeSizer(p->scrolled);
// The preset chooser // The preset chooser
p->sizer_presets = new wxFlexGridSizer(5, 2, 1, 2); p->sizer_presets = new wxFlexGridSizer(5, 2, 1, 2);
p->sizer_presets->AddGrowableCol(1, 1); p->sizer_presets->AddGrowableCol(1, 1);
@ -558,6 +562,7 @@ Sidebar::Sidebar(Plater *parent)
p->sliced_info = new SlicedInfo(p->scrolled); p->sliced_info = new SlicedInfo(p->scrolled);
// Sizer in the scrolled area // Sizer in the scrolled area
scrolled_sizer->Add(p->mode_sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
scrolled_sizer->Add(p->sizer_presets, 0, wxEXPAND | wxLEFT, 2); scrolled_sizer->Add(p->sizer_presets, 0, wxEXPAND | wxLEFT, 2);
scrolled_sizer->Add(p->sizer_params, 1, wxEXPAND); scrolled_sizer->Add(p->sizer_params, 1, wxEXPAND);
scrolled_sizer->Add(p->object_info, 0, wxEXPAND | wxTOP | wxLEFT, 20); scrolled_sizer->Add(p->object_info, 0, wxEXPAND | wxTOP | wxLEFT, 20);
@ -673,6 +678,11 @@ void Sidebar::update_presets(Preset::Type preset_type)
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
} }
void Sidebar::update_mode_sizer(const Slic3r::ConfigOptionMode& mode)
{
p->mode_sizer->SetMode(mode);
}
ObjectManipulation* Sidebar::obj_manipul() ObjectManipulation* Sidebar::obj_manipul()
{ {
return p->object_manipulation; return p->object_manipulation;
@ -711,7 +721,7 @@ void Sidebar::update_objects_list_extruder_column(int extruders_count)
void Sidebar::show_info_sizer() void Sidebar::show_info_sizer()
{ {
if (!p->plater->is_single_full_object_selection() || if (!p->plater->is_single_full_object_selection() ||
m_mode < ConfigMenuModeExpert || m_mode < comExpert ||
p->plater->model().objects.empty()) { p->plater->model().objects.empty()) {
p->object_info->Show(false); p->object_info->Show(false);
return; return;

View File

@ -57,7 +57,7 @@ private:
class Sidebar : public wxPanel class Sidebar : public wxPanel
{ {
/*ConfigMenuIDs*/int m_mode; /*ConfigOptionMode*/int m_mode;
public: public:
Sidebar(Plater *parent); Sidebar(Plater *parent);
Sidebar(Sidebar &&) = delete; Sidebar(Sidebar &&) = delete;
@ -69,6 +69,7 @@ public:
void init_filament_combo(PresetComboBox **combo, const int extr_idx); void init_filament_combo(PresetComboBox **combo, const int extr_idx);
void remove_unused_filament_combos(const int current_extruder_count); void remove_unused_filament_combos(const int current_extruder_count);
void update_presets(Slic3r::Preset::Type preset_type); void update_presets(Slic3r::Preset::Type preset_type);
void update_mode_sizer(const Slic3r::ConfigOptionMode& mode);
ObjectManipulation* obj_manipul(); ObjectManipulation* obj_manipul();
ObjectList* obj_list(); ObjectList* obj_list();
@ -84,7 +85,7 @@ public:
void show_reslice(bool show); void show_reslice(bool show);
void show_send(bool show); void show_send(bool show);
bool is_multifilament(); bool is_multifilament();
void set_mode_value(const /*ConfigMenuIDs*/int mode) { m_mode = mode; } void set_mode_value(const /*ConfigOptionMode*/int mode) { m_mode = mode; }
std::vector<PresetComboBox*>& combos_filament(); std::vector<PresetComboBox*>& combos_filament();
private: private:

View File

@ -168,6 +168,9 @@ void Tab::create_preset_tab()
m_modified_label_clr = wxGetApp().get_label_clr_modified(); m_modified_label_clr = wxGetApp().get_label_clr_modified();
m_default_text_clr = wxGetApp().get_label_clr_default(); m_default_text_clr = wxGetApp().get_label_clr_default();
// Sizer with buttons for mode changing
m_mode_sizer = new PrusaModeSizer(panel);
m_hsizer = new wxBoxSizer(wxHORIZONTAL); m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 0, wxBOTTOM, 3); sizer->Add(m_hsizer, 0, wxBOTTOM, 3);
m_hsizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); m_hsizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
@ -182,6 +185,8 @@ void Tab::create_preset_tab()
m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(32); m_hsizer->AddSpacer(32);
m_hsizer->Add(m_question_btn, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_question_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddStretchSpacer(32);
m_hsizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
//Horizontal sizer to hold the tree and the selected page. //Horizontal sizer to hold the tree and the selected page.
m_hsizer = new wxBoxSizer(wxHORIZONTAL); m_hsizer = new wxBoxSizer(wxHORIZONTAL);
@ -669,7 +674,7 @@ void Tab::reload_config()
void Tab::update_visibility() void Tab::update_visibility()
{ {
const ConfigOptionMode mode = wxGetApp().get_opt_mode(); const ConfigOptionMode mode = wxGetApp().get_mode();
Freeze(); Freeze();
for (auto page : m_pages) for (auto page : m_pages)
@ -685,6 +690,9 @@ void Tab::update_visibility()
wxTheApp->CallAfter([this]() { wxTheApp->CallAfter([this]() {
update_changed_tree_ui(); update_changed_tree_ui();
}); });
// update mode for ModeSizer
m_mode_sizer->SetMode(mode);
} }
Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const

View File

@ -31,6 +31,7 @@
#include "BedShapeDialog.hpp" #include "BedShapeDialog.hpp"
#include "Event.hpp" #include "Event.hpp"
class PrusaModeSizer;
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -123,6 +124,8 @@ protected:
wxTreeCtrl* m_treectrl; wxTreeCtrl* m_treectrl;
wxImageList* m_icons; wxImageList* m_icons;
PrusaModeSizer* m_mode_sizer;
struct PresetDependencies { struct PresetDependencies {
Preset::Type type = Preset::TYPE_INVALID; Preset::Type type = Preset::TYPE_INVALID;
wxCheckBox *checkbox = nullptr; wxCheckBox *checkbox = nullptr;

View File

@ -2195,7 +2195,6 @@ PrusaLockButton::PrusaLockButton( wxWindow *parent,
m_bmp_lock_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_lock_off.png")), wxBITMAP_TYPE_PNG); m_bmp_lock_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_lock_off.png")), wxBITMAP_TYPE_PNG);
m_bmp_unlock_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_unlock_on.png")), wxBITMAP_TYPE_PNG); m_bmp_unlock_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_unlock_on.png")), wxBITMAP_TYPE_PNG);
m_bmp_unlock_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_unlock_off.png")), wxBITMAP_TYPE_PNG); m_bmp_unlock_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_unlock_off.png")), wxBITMAP_TYPE_PNG);
m_lock_icon_dim = m_bmp_lock_on.GetSize().x;
#ifdef __WXMSW__ #ifdef __WXMSW__
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
@ -2234,6 +2233,104 @@ void PrusaLockButton::enter_button(const bool enter)
Update(); Update();
} }
// ----------------------------------------------------------------------------
// PrusaModeButton
// ----------------------------------------------------------------------------
PrusaModeButton::PrusaModeButton( wxWindow *parent,
wxWindowID id,
const wxString& mode/* = wxEmptyString*/,
const wxBitmap& bmp_on/* = wxNullBitmap*/,
const wxPoint& pos/* = wxDefaultPosition*/,
const wxSize& size/* = wxDefaultSize*/) :
wxButton(parent, id, mode, pos, size, wxBU_EXACTFIT | wxNO_BORDER),
m_bmp_on(bmp_on)
{
#ifdef __WXMSW__
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__
m_bmp_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("mode_off_sq.png")), wxBITMAP_TYPE_PNG);
SetBitmap(m_bmp_on);
//button events
Bind(wxEVT_BUTTON, &PrusaModeButton::OnButton, this);
Bind(wxEVT_ENTER_WINDOW, &PrusaModeButton::OnEnterBtn, this);
Bind(wxEVT_LEAVE_WINDOW, &PrusaModeButton::OnLeaveBtn, this);
}
void PrusaModeButton::OnButton(wxCommandEvent& event)
{
m_is_selected = true;
focus_button(m_is_selected);
event.Skip();
}
void PrusaModeButton::SetState(const bool state)
{
m_is_selected = state;
focus_button(m_is_selected);
}
void PrusaModeButton::focus_button(const bool focus)
{
const wxBitmap& bmp = focus ? m_bmp_on : m_bmp_off;
SetBitmap(bmp);
const wxFont& new_font = focus ? Slic3r::GUI::wxGetApp().bold_font() : Slic3r::GUI::wxGetApp().small_font();
SetFont(new_font);
Refresh();
Update();
}
// ----------------------------------------------------------------------------
// PrusaModeSizer
// ----------------------------------------------------------------------------
PrusaModeSizer::PrusaModeSizer(wxWindow *parent) :
wxFlexGridSizer(3, 0, 5)
{
SetFlexibleDirection(wxHORIZONTAL);
const wxBitmap bmp_simple_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("mode_simple_sq.png")), wxBITMAP_TYPE_PNG);
const wxBitmap bmp_advanced_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("mode_middle_sq.png")), wxBITMAP_TYPE_PNG);
const wxBitmap bmp_expert_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("mode_expert_sq.png")), wxBITMAP_TYPE_PNG);
mode_btns.reserve(3);
mode_btns.push_back(new PrusaModeButton(parent, wxID_ANY, "Simple", bmp_simple_on));
mode_btns.push_back(new PrusaModeButton(parent, wxID_ANY, "Advanced", bmp_advanced_on));
mode_btns.push_back(new PrusaModeButton(parent, wxID_ANY, "Expert", bmp_expert_on));
for (auto btn : mode_btns)
{
btn->Bind(wxEVT_BUTTON, [btn, this](wxCommandEvent &event) {
event.Skip();
int mode_id = 0;
for (auto cur_btn : mode_btns) {
if (cur_btn == btn)
break;
else
mode_id++;
}
Slic3r::GUI::wxGetApp().save_mode(mode_id);
});
Add(btn);
}
}
void PrusaModeSizer::SetMode(const Slic3r::ConfigOptionMode& mode)
{
for (int m = 0; m < mode_btns.size(); m++)
mode_btns[m]->SetState(m == mode);
}
// ************************************** EXPERIMENTS *************************************** // ************************************** EXPERIMENTS ***************************************
// ***************************************************************************** // *****************************************************************************

View File

@ -8,6 +8,7 @@
#include <wx/collpane.h> #include <wx/collpane.h>
#include <wx/wupdlock.h> #include <wx/wupdlock.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/sizer.h>
#include <wx/slider.h> #include <wx/slider.h>
#include <vector> #include <vector>
@ -863,8 +864,57 @@ private:
wxBitmap m_bmp_lock_off; wxBitmap m_bmp_lock_off;
wxBitmap m_bmp_unlock_on; wxBitmap m_bmp_unlock_on;
wxBitmap m_bmp_unlock_off; wxBitmap m_bmp_unlock_off;
};
int m_lock_icon_dim;
// ----------------------------------------------------------------------------
// PrusaModeButton
// ----------------------------------------------------------------------------
class PrusaModeButton : public wxButton
{
public:
PrusaModeButton(
wxWindow *parent,
wxWindowID id,
const wxString& mode = wxEmptyString,
const wxBitmap& bmp_on = wxNullBitmap,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);
~PrusaModeButton() {}
void OnButton(wxCommandEvent& event);
void OnEnterBtn(wxMouseEvent& event) { focus_button(true); event.Skip(); }
void OnLeaveBtn(wxMouseEvent& event) { focus_button(m_is_selected); event.Skip(); }
void SetState(const bool state);
protected:
void focus_button(const bool focus);
private:
bool m_is_selected = false;
wxBitmap m_bmp_on;
wxBitmap m_bmp_off;
};
// ----------------------------------------------------------------------------
// PrusaModeSizer
// ----------------------------------------------------------------------------
class PrusaModeSizer : public wxFlexGridSizer
{
public:
PrusaModeSizer( wxWindow *parent);
~PrusaModeSizer() {}
void SetMode(const Slic3r::ConfigOptionMode& mode);
private:
std::vector<PrusaModeButton*> mode_btns;
}; };