Sidebar: Next refactoring and beautification

+ Deleted long time unused or commented code
+ Some unrelated functions are moved from Plater to Sidebar
This commit is contained in:
YuSanka 2023-11-03 12:48:45 +01:00
parent 69650f703d
commit feac3b62ed
10 changed files with 413 additions and 492 deletions

View File

@ -184,8 +184,9 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent)
(project_config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values = std::vector<double>(matrix.begin(), matrix.end());
(project_config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values = std::vector<double>(extruders.begin(), extruders.end());
// Update Project dirty state, update application title bar.
wxGetApp().plater()->update_project_dirty_from_presets();
wxPostEvent(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent));
Plater* plater = wxGetApp().plater();
plater->update_project_dirty_from_presets();
wxPostEvent(plater, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, plater));
}
}));

View File

@ -28,8 +28,6 @@ namespace Slic3r {
namespace GUI {
wxDECLARE_EVENT(EVT_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent);
class ConfigOptionsGroup;
class FreqChangedParams

View File

@ -760,7 +760,7 @@ void MainFrame::init_tabpanel()
// Show a correct number of filament fields.
// nozzle_diameter is undefined when SLA printer is selected
if (full_config.has("nozzle_diameter")) {
m_plater->on_extruders_change(full_config.option<ConfigOptionFloats>("nozzle_diameter")->values.size());
m_plater->sidebar().set_extruders_count(full_config.option<ConfigOptionFloats>("nozzle_diameter")->values.size());
}
}
}
@ -2027,24 +2027,6 @@ void MainFrame::on_presets_changed(SimpleEvent &event)
}
}
// #ys_FIXME_to_delete
void MainFrame::on_value_changed(wxCommandEvent& event)
{
auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
wxASSERT(tab != nullptr);
if (tab == nullptr)
return;
auto opt_key = event.GetString();
if (m_plater) {
m_plater->on_config_change(*tab->get_config()); // propagate config change events to the plater
if (opt_key == "extruders_count") {
auto value = event.GetInt();
m_plater->on_extruders_change(value);
}
}
}
void MainFrame::on_config_changed(DynamicPrintConfig* config) const
{
if (m_plater)

View File

@ -100,7 +100,6 @@ class MainFrame : public DPIFrame
std::string get_dir_name(const wxString &full_name) const;
void on_presets_changed(SimpleEvent&);
void on_value_changed(wxCommandEvent&);
bool can_start_new_project() const;
bool can_export_model() const;

View File

@ -392,7 +392,7 @@ struct Plater::priv
bool is_legend_shown() const { return (current_panel == preview) && preview->get_canvas3d()->is_legend_shown(); }
void show_legend(bool show) { if (current_panel == preview) preview->get_canvas3d()->show_legend(show); }
bool is_sidebar_collapsed() const { return sidebar->is_collapsed(); }
bool is_sidebar_collapsed() const { return sidebar->is_collapsed; }
void collapse_sidebar(bool collapse);
bool is_view3D_layers_editing_enabled() const { return (current_panel == view3D) && view3D->get_canvas3d()->is_layers_editing_enabled(); }
@ -503,7 +503,6 @@ struct Plater::priv
void reload_all_from_disk();
void set_current_panel(wxPanel* panel);
void on_select_preset(wxCommandEvent&);
void on_slicing_update(SlicingStatusEvent&);
void on_slicing_completed(wxCommandEvent&);
void on_process_completed(SlicingProcessCompletedEvent&);
@ -689,9 +688,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
if (wxGetApp().is_editor()) {
// Preset change event
sidebar->Bind(wxEVT_COMBOBOX, &priv::on_select_preset, this);
sidebar->Bind(EVT_OBJ_LIST_OBJECT_SELECT, [this](wxEvent&) { priv::selection_changed(); });
sidebar->Bind(EVT_SCHEDULE_BACKGROUND_PROCESS, [this](SimpleEvent&) { this->schedule_background_process(); });
this->q->Bind(EVT_OBJ_LIST_OBJECT_SELECT, [this](wxEvent&) { priv::selection_changed(); });
this->q->Bind(EVT_SCHEDULE_BACKGROUND_PROCESS, [this](SimpleEvent&) { this->schedule_background_process(); });
}
wxGLCanvas* view3D_canvas = view3D->get_wxglcanvas();
@ -986,6 +984,10 @@ void Plater::priv::update_ui_from_settings()
preview->get_canvas3d()->update_ui_from_settings();
sidebar->update_ui_from_settings();
// update Cut gizmo, if it's open
q->canvas3D()->update_gizmos_on_off_state();
q->set_current_canvas_as_dirty();
q->get_current_canvas3D()->request_extra_frame();
}
// Called after the print technology was changed.
@ -1979,7 +1981,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
{
// Validation of the background data failed.
const wxString invalid_str = _L("Invalid data");
for (auto btn : {ActionButtonType::abReslice, ActionButtonType::abSendGCode, ActionButtonType::abExport})
for (auto btn : {ActionButtonType::Reslice, ActionButtonType::SendGCode, ActionButtonType::Export})
sidebar->set_btn_label(btn, invalid_str);
process_completed_with_error = true;
}
@ -1993,13 +1995,13 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
(return_state & UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE) != 0 )
notification_manager->set_slicing_progress_hidden();
sidebar->set_btn_label(ActionButtonType::abExport, _(label_btn_export));
sidebar->set_btn_label(ActionButtonType::abSendGCode, _(label_btn_send));
sidebar->set_btn_label(ActionButtonType::Export, _(label_btn_export));
sidebar->set_btn_label(ActionButtonType::SendGCode, _(label_btn_send));
dirty_state.update_from_preview();
const wxString slice_string = background_process.running() && wxGetApp().get_mode() == comSimple ?
_L("Slicing") + dots : _L("Slice now");
sidebar->set_btn_label(ActionButtonType::abReslice, slice_string);
sidebar->set_btn_label(ActionButtonType::Reslice, slice_string);
if (background_process.finished())
show_action_buttons(false);
@ -2628,74 +2630,6 @@ void Plater::priv::set_current_panel(wxPanel* panel)
current_panel->SetFocusFromKbd();
}
void Plater::priv::on_select_preset(wxCommandEvent &evt)
{
PlaterPresetComboBox* combo = static_cast<PlaterPresetComboBox*>(evt.GetEventObject());
Preset::Type preset_type = combo->get_type();
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender"),
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
// So, use GetSelection() from event parameter
int selection = evt.GetSelection();
auto idx = combo->get_extruder_idx();
//! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox,
//! but the OSX version derived from wxOwnerDrawnCombo.
//! So, to get selected string we do
//! combo->GetString(combo->GetSelection())
//! instead of
//! combo->GetStringSelection().ToUTF8().data());
std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type,
Preset::remove_suffix_modified(into_u8(combo->GetString(selection))), idx);
std::string last_selected_ph_printer_name = combo->get_selected_ph_printer_name();
bool select_preset = !combo->selection_is_changed_according_to_physical_printers();
// TODO: ?
if (preset_type == Preset::TYPE_FILAMENT) {
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
TabFilament* tab = dynamic_cast<TabFilament*>(wxGetApp().get_tab(Preset::TYPE_FILAMENT));
if (tab && combo->get_extruder_idx() == tab->get_active_extruder() && !tab->select_preset(preset_name)) {
// revert previously selection
const std::string& old_name = wxGetApp().preset_bundle->filaments.get_edited_preset().name;
wxGetApp().preset_bundle->set_filament_preset(idx, old_name);
}
else
// Synchronize config.ini with the current selections.
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
combo->update();
}
else if (select_preset) {
wxWindowUpdateLocker noUpdates(sidebar->presets_panel());
wxGetApp().get_tab(preset_type)->select_preset(preset_name, false, last_selected_ph_printer_name);
}
if (preset_type != Preset::TYPE_PRINTER || select_preset) {
// update plater with new config
q->on_config_change(wxGetApp().preset_bundle->full_config());
}
if (preset_type == Preset::TYPE_PRINTER) {
/* Settings list can be changed after printer preset changing, so
* update all settings items for all item had it.
* Furthermore, Layers editing is implemented only for FFF printers
* and for SLA presets they should be deleted
*/
wxGetApp().obj_list()->update_object_list_by_printer_technology();
}
#ifdef __WXMSW__
// From the Win 2004 preset combobox lose a focus after change the preset selection
// and that is why the up/down arrow doesn't work properly
// (see https://github.com/prusa3d/PrusaSlicer/issues/5531 ).
// So, set the focus to the combobox explicitly
combo->SetFocus();
#endif
}
void Plater::priv::on_slicing_update(SlicingStatusEvent &evt)
{
if (evt.status.percent >= -1) {
@ -2913,7 +2847,7 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt)
if (evt.invalidate_plater())
{
const wxString invalid_str = _L("Invalid data");
for (auto btn : { ActionButtonType::abReslice, ActionButtonType::abSendGCode, ActionButtonType::abExport })
for (auto btn : { ActionButtonType::Reslice, ActionButtonType::SendGCode, ActionButtonType::Export })
sidebar->set_btn_label(btn, invalid_str);
process_completed_with_error = true;
}
@ -2943,7 +2877,7 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt)
if (evt.cancelled()) {
if (wxGetApp().get_mode() == comSimple)
sidebar->set_btn_label(ActionButtonType::abReslice, "Slice now");
sidebar->set_btn_label(ActionButtonType::Reslice, "Slice now");
show_action_buttons(true);
} else {
if(wxGetApp().get_mode() == comSimple) {
@ -3517,7 +3451,6 @@ void Plater::priv::show_action_buttons(const bool ready_to_slice_) const
sidebar->show_export(true) |
sidebar->show_send(send_gcode_shown) |
sidebar->show_export_removable(removable_media_status.has_removable_drives))
// sidebar->show_eject(removable_media_status.has_eject))
sidebar->Layout();
}
else
@ -3529,7 +3462,6 @@ void Plater::priv::show_action_buttons(const bool ready_to_slice_) const
sidebar->show_export(!ready_to_slice) |
sidebar->show_send(send_gcode_shown && !ready_to_slice) |
sidebar->show_export_removable(!ready_to_slice && removable_media_status.has_removable_drives))
// sidebar->show_eject(!ready_to_slice && removable_media_status.has_eject))
sidebar->Layout();
}
}
@ -5759,10 +5691,10 @@ void Plater::reslice()
if (p->background_process.running())
{
if (wxGetApp().get_mode() == comSimple)
p->sidebar->set_btn_label(ActionButtonType::abReslice, _L("Slicing") + dots);
p->sidebar->set_btn_label(ActionButtonType::Reslice, _L("Slicing") + dots);
else
{
p->sidebar->set_btn_label(ActionButtonType::abReslice, _L("Slice now"));
p->sidebar->set_btn_label(ActionButtonType::Reslice, _L("Slice now"));
p->show_action_buttons(false);
}
}
@ -5955,36 +5887,6 @@ void Plater::undo_redo_topmost_string_getter(const bool is_undo, std::string& ou
out_text = "";
}
void Plater::on_extruders_change(size_t num_extruders)
{
auto& choices = sidebar().combos_filament();
if (num_extruders == choices.size())
return;
dynamic_cast<TabFilament*>(wxGetApp().get_tab(Preset::TYPE_FILAMENT))->update_extruder_combobox();
wxWindowUpdateLocker noUpdates_scrolled_panel(&sidebar()/*.scrolled_panel()*/);
size_t i = choices.size();
while ( i < num_extruders )
{
PlaterPresetComboBox* choice/*{ nullptr }*/;
sidebar().init_filament_combo(&choice, i);
choices.push_back(choice);
// initialize selection
choice->update();
++i;
}
// remove unused choices if any
sidebar().remove_unused_filament_combos(num_extruders);
sidebar().Layout();
sidebar().scrolled_panel()->Refresh();
}
bool Plater::update_filament_colors_in_full_config()
{
// There is a case, when we use filament_color instead of extruder_color (when extruder_color == "").

View File

@ -54,6 +54,8 @@ namespace UndoRedo {
namespace GUI {
wxDECLARE_EVENT(EVT_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent);
class MainFrame;
class GLCanvas3D;
class Mouse3DController;
@ -242,7 +244,6 @@ public:
void enter_gizmos_stack();
void leave_gizmos_stack();
void on_extruders_change(size_t extruders_count);
bool update_filament_colors_in_full_config();
void on_config_change(const DynamicPrintConfig &config);
void force_filament_colors_update();

View File

@ -16,7 +16,7 @@
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "GUI_App.hpp"
#include "Mainframe.hpp"
#include "MainFrame.hpp"
#include "Tab.hpp"
#define FTS_FUZZY_MATCH_IMPLEMENTATION

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@
#include <vector>
#include <wx/panel.h>
#include <wx/string.h>
#include "libslic3r/Preset.hpp"
#include "GUI.hpp"
@ -27,15 +28,17 @@
class wxButton;
class wxScrolledWindow;
class wxString;
class ScalableButton;
class ModeSizer;
namespace Slic3r {
namespace GUI {
wxDECLARE_EVENT(EVT_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent);
class ConfigOptionsGroup;
class FreqChangedParams;
class ObjectInfo;
class SlicedInfo;
class ObjectManipulation;
class ObjectSettings;
class ObjectLayers;
@ -44,14 +47,56 @@ class PlaterPresetComboBox;
class Plater;
enum class ActionButtonType : int {
abReslice,
abExport,
abSendGCode
Reslice,
Export,
SendGCode
};
class Sidebar : public wxPanel
{
ConfigOptionMode m_mode{ConfigOptionMode::comSimple};
Plater* m_plater { nullptr };
wxScrolledWindow* m_scrolled_panel { nullptr };
wxPanel* m_presets_panel { nullptr }; // Used for MSW better layouts
ModeSizer* m_mode_sizer { nullptr };
wxFlexGridSizer* m_presets_sizer { nullptr };
wxBoxSizer* m_filaments_sizer { nullptr };
PlaterPresetComboBox* m_combo_print { nullptr };
PlaterPresetComboBox* m_combo_sla_print { nullptr };
PlaterPresetComboBox* m_combo_sla_material{ nullptr };
PlaterPresetComboBox* m_combo_printer { nullptr };
std::vector<PlaterPresetComboBox*> m_combos_filament;
ObjectList* m_object_list { nullptr };
ObjectInfo* m_object_info { nullptr };
SlicedInfo* m_sliced_info { nullptr };
wxButton* m_btn_export_gcode { nullptr };
wxButton* m_btn_reslice { nullptr };
ScalableButton* m_btn_send_gcode { nullptr };
ScalableButton* m_btn_export_gcode_removable{ nullptr }; //exports to removable drives (appears only if removable drive is connected)
std::unique_ptr<FreqChangedParams> m_frequently_changed_parameters;
std::unique_ptr<ObjectManipulation> m_object_manipulation;
std::unique_ptr<ObjectSettings> m_object_settings;
std::unique_ptr<ObjectLayers> m_object_layers;
#ifdef _WIN32
wxString m_reslice_btn_tooltip;
#endif
void init_filament_combo(PlaterPresetComboBox **combo, int extr_idx);
void remove_unused_filament_combos(const size_t current_extruder_count);
void update_all_preset_comboboxes();
void update_reslice_btn_tooltip();
void show_preset_comboboxes();
void on_select_preset(wxCommandEvent& evt);
public:
Sidebar(Plater *parent);
Sidebar(Sidebar &&) = delete;
@ -60,53 +105,43 @@ public:
Sidebar &operator=(const Sidebar &) = delete;
~Sidebar();
void init_filament_combo(PlaterPresetComboBox **combo, const int extr_idx);
void remove_unused_filament_combos(const size_t current_extruder_count);
void update_all_preset_comboboxes();
void update_presets(Preset::Type preset_type);
void update_mode_sizer() const;
void change_top_border_for_mode_sizer(bool increase_border);
void update_reslice_btn_tooltip() const;
void msw_rescale();
void sys_color_changed();
void update_mode_markers();
ObjectManipulation* obj_manipul();
ObjectList* obj_list();
ObjectSettings* obj_settings();
ObjectLayers* obj_layers();
wxScrolledWindow* scrolled_panel();
wxPanel* presets_panel();
ConfigOptionsGroup* og_freq_chng_params(const bool is_fff);
wxButton* get_wiping_dialog_button();
void update_objects_list_extruder_column(size_t extruders_count);
void show_info_sizer();
void show_sliced_info_sizer(const bool show);
void update_sliced_info_sizer();
void enable_buttons(bool enable);
void set_btn_label(const ActionButtonType btn_type, const wxString& label) const;
bool show_reslice(bool show) const;
bool show_export(bool show) const;
bool show_send(bool show) const;
bool show_eject(bool show)const;
bool show_export_removable(bool show) const;
bool get_eject_shown() const;
bool is_multifilament();
void update_mode();
bool is_collapsed();
void collapse(bool collapse);
void update_ui_from_settings();
void show_info_sizer();
void show_sliced_info_sizer(const bool show);
void update_sliced_info_sizer();
void enable_buttons(bool enable);
void set_btn_label(const ActionButtonType btn_type, const wxString& label) const;
bool show_reslice(bool show) const;
bool show_export(bool show) const;
bool show_send(bool show) const;
bool show_export_removable(bool show) const;
void collapse(bool collapse);
void change_top_border_for_mode_sizer(bool increase_border);
void set_extruders_count(size_t extruders_count);
void update_mode();
void update_ui_from_settings();
void update_objects_list_extruder_column(size_t extruders_count);
void update_presets(Preset::Type preset_type);
void update_mode_markers();
void msw_rescale();
void sys_color_changed();
#ifdef _MSW_DARK_MODE
void show_mode_sizer(bool show);
void show_mode_sizer(bool show);
#endif
std::vector<PlaterPresetComboBox*>& combos_filament();
private:
struct priv;
std::unique_ptr<priv> p;
bool is_collapsed{ false };
};
} // namespace GUI

View File

@ -691,7 +691,7 @@ void Tab::init_options_list()
}
template<class T>
void add_correct_opts_to_options_list(const std::string &opt_key, std::map<std::string, int>& map, Tab *tab, const int& value)
void add_correct_opts_to_options_list(const std::string &opt_key, std::map<std::string, int>& map, Tab *tab, int value)
{
T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
for (size_t i = 0; i < opt_cur->values.size(); i++)
@ -1146,7 +1146,7 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
update_wiping_button_visibility();
if (opt_key == "extruders_count")
wxGetApp().plater()->on_extruders_change(boost::any_cast<size_t>(value));
wxGetApp().sidebar().set_extruders_count(boost::any_cast<size_t>(value));
if (m_postpone_update_ui) {
// It means that not all values are rolled to the system/last saved values jet.