Files
OrcaSlicer/src/slic3r/GUI/Preferences.hpp
T
SoftFever d64e10f4dd Regroup the slicer's MCP commands and let each run from its arguments
Outside the Design tab an agent had 175 commands, 50 of them in the tool
list. There are now 118, named by what they act on (`object_`, `plate_`,
`preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes
its target and values in the call, acts on the selection when it names no
target and says what it acted on; an old name is refused. Printers and
system filaments install and uninstall, preferences read and write, plugins
enable, reload, uninstall and refresh, and objects reorder, with no dialog
to drive.

The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the
rows these commands share with the menus are fixed. For a person: an object
row that cannot run says why instead of "Select an object first.", rows
that failed no longer claim success, Duplicate Plate can be undone, and
Refresh Plugins picked while a refresh runs now runs after it instead of
beside it.
2026-11-18 16:50:32 +08:00

183 lines
9.0 KiB
C++

#ifndef slic3r_Preferences_hpp_
#define slic3r_Preferences_hpp_
#include "GUI.hpp"
#include "GUI_Utils.hpp"
#include <wx/chartype.h>
#include <functional>
#include <tuple>
#include <wx/dialog.h>
#include <wx/string.h>
#include <wx/gdicmn.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/timer.h>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <wx/toplevel.h>
#include "Widgets/ComboBox.hpp"
#include "Widgets/CheckBox.hpp"
#include "Widgets/TextInput.hpp"
#include "Widgets/SpinInput.hpp"
#include "Widgets/TabCtrl.hpp"
#include "Widgets/Label.hpp"
#include "Widgets/Button.hpp"
#include "Widgets/RadioGroup.hpp"
#include "slic3r/Utils/bambu_networking.hpp"
namespace Slic3r { namespace GUI {
namespace Ops { struct Preference; }
#define DESIGN_GRAY900_COLOR wxColour("#363636") // Label color
#define DESIGN_GRAY600_COLOR wxColour("#ACACAC") // Dimmed text color
#define DESIGN_WINDOW_SIZE wxSize(FromDIP(640), FromDIP(640))
#define DESIGN_TITLE_SIZE wxSize(FromDIP(280), -1)
#define DESIGN_COMBOBOX_SIZE wxSize(FromDIP(120), -1)
#define DESIGN_LARGE_COMBOBOX_SIZE wxSize(FromDIP(120), -1)
#define DESIGN_INPUT_SIZE wxSize(FromDIP(120), -1)
#define DESIGN_LEFT_MARGIN 25
// The tabs other dialogs and window_open {window: "preferences"} open Preferences on.
enum class PreferencesTab { General, Files, Behaviour, Control, Graphics, Online, Developer };
class PreferencesDialog : public DPIDialog
{
private:
AppConfig *app_config;
protected:
wxBoxSizer * m_sizer_body;
wxScrolledWindow* m_parent;
TabCtrl* m_pref_tabs;
std::map<PreferencesTab, int> m_tab_index; // position of each tab in m_pref_tabs
// bool m_settings_layout_changed {false};
bool m_seq_top_layer_only_changed{false};
bool m_recreate_GUI{false};
std::string m_pending_language;
public:
bool seq_top_layer_only_changed() const { return m_seq_top_layer_only_changed; }
bool recreate_GUI() const { return m_recreate_GUI; }
const std::string& pending_language() const { return m_pending_language; }
void on_dpi_changed(const wxRect &suggested_rect) override;
public:
PreferencesDialog(wxWindow * parent,
wxWindowID id = wxID_ANY,
const wxString &title = wxT(""),
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX);
~PreferencesDialog();
// Shows `tab`, or the tab of `option` (a control named after its AppConfig key), scrolled to that control and focused.
void select_tab(PreferencesTab tab, const std::string& option = {});
wxString m_backup_interval_time;
wxTimer m_filament_height_timer;
wxTimer m_mcp_status_timer; // refreshes the MCP status while another window holds the port
void create();
// debug mode
::CheckBox * m_developer_mode_ckeckbox = {nullptr};
::CheckBox * m_internal_developer_mode_ckeckbox = {nullptr};
::CheckBox * m_dark_mode_ckeckbox = {nullptr};
::CheckBox * m_sync_user_preset_checkbox = {nullptr};
::CheckBox * m_bambu_cloud_checkbox = {nullptr};
::Label * m_mcp_intro = {nullptr};
::Label * m_mcp_status_dot = {nullptr};
::Label * m_mcp_status = {nullptr};
::Label * m_mcp_address = {nullptr};
RadioGroup * m_mcp_transport = {nullptr};
::Label * m_mcp_transport_hint = {nullptr};
::Label * m_mcp_agent_hint = {nullptr};
::Button * m_mcp_copy_button = {nullptr};
::CheckBox * m_skip_identical_frames_checkbox = {nullptr};
::TextInput *m_backup_interval_textinput = {nullptr};
::SpinInput *m_dim_previous_layers_brightness_input = {nullptr};
// Disabled while persistent outlines are off.
wxWindow * m_persistent_outline_color_button = {nullptr};
wxStaticText *m_download_path_text = {nullptr}; // the downloads folder, in its row
wxBoxSizer * m_download_path_row = {nullptr};
::ComboBox * m_network_version_combo = {nullptr};
std::vector<NetworkLibraryVersionInfo> m_available_versions;
wxString m_developer_mode_def;
wxString m_internal_developer_mode_def;
wxString m_backup_interval_def;
wxString m_iot_environment_def;
std::vector<wxFlexGridSizer*> f_sizers;
wxBoxSizer *create_item_title(wxString title);
wxBoxSizer *create_item_label(wxString label, const wxString tooltip = "", const wxString wiki_url = "");
wxBoxSizer *create_item_combobox(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist, std::vector<std::string> config_name_index, std::function<void(std::string)> onchange = {}, const wxString wiki_url = "");
wxBoxSizer *create_item_region_combobox(wxString title, wxString tooltip);
wxBoxSizer *create_item_language_combobox(wxString title, wxString tooltip);
wxBoxSizer *create_item_loglevel_combobox(wxString title, wxString tooltip, std::vector<wxString> vlist);
wxBoxSizer *create_item_checkbox(wxString title, wxString tooltip, std::string param, const wxString secondary_title = "", const wxString wiki_url = "");
wxBoxSizer *create_item_darkmode(wxString title,wxString tooltip, std::string param);
void set_dark_mode();
wxBoxSizer *create_item_button(wxString title, wxString title2, wxString tooltip, wxString tooltip2, std::function<void()> onclick, const wxString wiki_url = "");
wxBoxSizer *create_item_downloads(wxString title, wxString tooltip);
// Shows the downloads folder the app configuration holds in its row. Ops::apply_preference() calls it.
void show_download_path();
wxBoxSizer *create_item_input(wxString title, wxString title2, wxString tooltip, std::string param, std::function<void(wxString)> onchange = {}, const wxString wiki_url = "");
wxBoxSizer *create_item_spinctrl(wxString title, wxString title2, wxString side_label, wxString tooltip, std::string param, int min, int max, std::function<void(int)> onchange = nullptr, const wxString wiki_url = "");
wxBoxSizer *create_camera_orbit_mult_input(wxString title, wxString tooltip);
wxBoxSizer *create_item_decimal_input(wxString title, wxString title2, wxString tooltip, std::string param, double min, double max, int decimals, const wxString wiki_url = "");
wxBoxSizer *create_item_backup(wxString title, wxString tooltip);
wxBoxSizer *create_item_auto_reslice(wxString title, wxString checkbox_tooltip, wxString delay_tooltip);
wxBoxSizer *create_item_bambu_cloud(wxString title, wxString tooltip);
wxBoxSizer *create_item_mcp_server(wxString title, wxString tooltip);
wxBoxSizer *create_item_mcp_port(wxString title, wxString tooltip);
wxBoxSizer *create_item_mcp_address(wxString title, wxString tooltip);
wxBoxSizer *create_item_mcp_transport(wxString title, wxString tooltip);
wxBoxSizer *create_item_mcp_connect(wxString title, wxString tooltip);
wxBoxSizer *create_item_mcp_python(wxString title, wxString tooltip);
wxBoxSizer *with_mcp_hint(wxBoxSizer *row, ::Label *hint);
void update_mcp_status(const std::string& note = {});
wxBoxSizer *create_item_network_plugin_version(wxString title, wxString tooltip);
#ifdef WIN32
wxBoxSizer *create_item_link_association(wxString url_prefix, wxString website_name);
#endif // WIN32
void create_items();
// The rows of `tab`'s preferences (Ops::preferences()), in the table's order under their sections' titles, with
// the rows that go with them.
void add_preference_rows(wxFlexGridSizer *g_sizer, const std::string &tab);
// The row of a preference of the table's kinds, built from its entry.
wxBoxSizer *create_preference_row(const Ops::Preference &p);
// The row of a preference whose control is built by a function of its own (Ops::Preference::own_row); none for a
// preference whose control is in another's row.
wxBoxSizer *create_own_row(wxFlexGridSizer *g_sizer, const Ops::Preference &p);
// What the dialog adds after preference `p`'s row `row`: the rows of its section that store no preference of the
// table, and the state of controls that follow the rows built so far.
void add_rows_after(wxFlexGridSizer *g_sizer, const Ops::Preference &p, wxBoxSizer *row);
// What a number field's change of `key` does: Ops::apply_preference(), or later for the filament area's height.
void preference_changed(const std::string &key);
void create_sync_page();
wxBoxSizer* create_debug_page();
// BBS
void create_select_domain_widget();
void Split(const std::string &src, const std::string &separator, std::vector<wxString> &dest);
int m_current_language_selected = {0};
private:
std::tuple<wxBoxSizer*, ComboBox*> create_item_combobox_base(wxString title, wxString tooltip, std::string param, std::vector<wxString> vlist, unsigned int current_index, const wxString wiki_url = "");
};
}} // namespace Slic3r::GUI
#endif /* slic3r_Preferences_hpp_ */