forked from bambulab/BambuStudio
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferences.cpp
More file actions
1686 lines (1447 loc) · 69.3 KB
/
Copy pathPreferences.cpp
File metadata and controls
1686 lines (1447 loc) · 69.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Preferences.hpp"
#include "GUI_App.hpp"
#include "MainFrame.hpp"
#include "OpenGLManager.hpp"
#include "Plater.hpp"
#include "MsgDialog.hpp"
#include "I18N.hpp"
#include "UxProgramTermsDialog.hpp"
#include "libslic3r/AppConfig.hpp"
#include "ReleaseNote.hpp"
#include "Tabbook.hpp"
#include "fila_manager/wgtFilaManagerFeature.h"
#include "Gizmos/GLGizmoBase.hpp"
#include "Widgets/Button.hpp"
#include "Widgets/ComboBox.hpp"
#include "Widgets/CheckBox.hpp"
#include "Widgets/LinkLabel.hpp"
#include "Widgets/RadioBox.hpp"
#include "Widgets/StaticLine.hpp"
#include "Widgets/TextInput.hpp"
#include <wx/listimpl.cpp>
#ifdef __WINDOWS__
#ifdef _MSW_DARK_MODE
#include "dark_mode.hpp"
#endif // _MSW_DARK_MODE
#endif //__WINDOWS__
#define DESIGN_GRAY900_COLOR wxColour(38, 46, 48)
#define DESIGN_GRAY800_COLOR wxColour(50, 58, 61)
#define DESIGN_GRAY600_COLOR wxColour(144, 144, 144)
#define DESIGN_GRAY400_COLOR wxColour(166, 169, 170)
#define DESIGN_CONTENT_BG_COLOR *wxWHITE
#define DESIGN_SIDEBAR_BG_COLOR wxColour(241, 241, 241)
#define DESIGN_HIGHLIGHT_COLOR wxColour(0, 174, 66) // BBL green
#define DESIGN_PAGE_PADDING FromDIP(12) // padding around page content
#define DESIGN_ITEM_SPACING FromDIP(3) // vertical spacing between items
#define DESIGN_SECTION_SPACING DESIGN_PAGE_PADDING // vertical spacing between titled sections on a page
#define DESIGN_ITEM_INDENT FromDIP(23) // left side offset for all editable properties, indent relative to section titles
#define DESIGN_INPUT_PAD FromDIP(8) // horizontal space between label(s) and input widget
#define DESIGN_LABEL_W 100 // common width of labels on left side of input (forms an even column)
#define DESIGN_COMBO_W 140
#define DESIGN_COMBO_LRG_W 160
#define DESIGN_INPUT_W 100 // default text box width
#define DESIGN_BUTTON_RADIUS 12
#define DESIGN_BUTTON_SIZE wxSize(58, 22)
namespace Slic3r { namespace GUI {
WX_DEFINE_LIST(RadioSelectorList);
// Scrollable panel container for property pages.
class ScrolledPanel : public wxScrolledWindow
{
bool m_has_top_title { false };
wxBoxSizer *m_content_sizer;
public:
ScrolledPanel(wxWindow* parent, bool top_level = true) :
m_content_sizer{ new wxBoxSizer(wxVERTICAL) },
wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL)
{
if (top_level)
SetScrollRate(FromDIP(15), FromDIP(15));
SetBackgroundColour(DESIGN_CONTENT_BG_COLOR);
SetSizer(new wxBoxSizer(wxVERTICAL));
GetSizer()->Add(m_content_sizer, 0, wxEXPAND | wxALL, top_level ? DESIGN_PAGE_PADDING : 0);
}
wxSizerItem* Add(wxSizerItem *item)
{
if (item->GetBorder() == wxDefaultCoord)
item->SetBorder(DESIGN_ITEM_SPACING);
if (!item->GetFlag())
item->SetFlag(wxTOP | wxEXPAND);
return m_content_sizer->Add(item);
}
wxSizerItem* Add(wxWindow *window, int padding = wxDefaultCoord, int flag = 0) {
return Add(new wxSizerItem(window, 0, flag, padding));
}
wxSizerItem* Add(wxSizer *sizer, int padding = wxDefaultCoord, int flag = 0) {
return Add(new wxSizerItem(sizer, 0, flag, padding));
}
wxSizerItem* AddTitle(const wxString &title, const wxString &tooltip = wxEmptyString, int padding = wxDefaultCoord, int flag = 0)
{
auto line = new StaticLine(this, false, title);
line->SetFont(::Label::Head_13);
line->SetToolTip(tooltip);
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(line, 1, wxEXPAND | wxBOTTOM, FromDIP(3));
if (padding == wxDefaultCoord)
padding = m_has_top_title ? DESIGN_SECTION_SPACING : 0;
m_has_top_title = true;
return Add(sizer, padding, flag);
}
wxSizerItem* AddSubtitle(const wxString &title, const wxString &tooltip = wxEmptyString)
{
auto text = new wxStaticText(this, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, 0);
text->SetForegroundColour(DESIGN_GRAY800_COLOR);
text->SetFont(::Label::Head_11);
text->SetToolTip(tooltip);
return Add(text, FromDIP(5), wxTOP | wxLEFT | wxEXPAND);
}
ScrolledPanel* Finalize()
{
GetSizer()->SetSizeHints(this);
return this;
}
bool ShouldScrollToChildOnFocus(wxWindow* /* child */) override { return false; }
};
// ----------------------------------------------------------------------------
// PreferencesDialog
// ----------------------------------------------------------------------------
// static
int PreferencesDialog::m_last_selected_page = 0;
// Static utility functions
static wxStaticText* new_static_text(wxWindow *parent, const wxString &text, const wxString &tooltip = wxEmptyString, int width = DESIGN_LABEL_W, int style = 0)
{
if (!width)
width = DESIGN_LABEL_W;
auto ctrl = new wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxSize(parent->FromDIP(width), -1), style | wxBORDER_NONE);
ctrl->SetForegroundColour(DESIGN_GRAY900_COLOR);
ctrl->SetFont(::Label::Body_13);
ctrl->SetToolTip(tooltip);
// ctrl->Wrap(-1);
return ctrl;
}
static TextInput* new_text_input(wxWindow *parent, const wxString &text, const wxString &tooltip, int validator = wxFILTER_DIGITS) {
auto ctrl = new TextInput(
parent, text, wxEmptyString, wxEmptyString, wxDefaultPosition,
parent->FromDIP(wxSize(DESIGN_INPUT_W, -1)), wxTE_PROCESS_ENTER
);
ctrl->SetToolTip(tooltip);
if (validator > -1)
ctrl->GetTextCtrl()->SetValidator(wxTextValidator(validator));
return ctrl;
}
static ComboBox* new_combobox(wxWindow *parent, const wxString &tooltip = wxEmptyString, std::vector<ComboBox*> *list = nullptr, int width = DESIGN_COMBO_LRG_W)
{
if (!width)
width = DESIGN_COMBO_LRG_W;
auto combobox = new ::ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(parent->FromDIP(width), -1), 0, nullptr, wxCB_READONLY);
combobox->SetFont(::Label::Body_13);
combobox->GetDropDown().SetFont(::Label::Body_13);
combobox->SetToolTip(tooltip);
if (list)
list->push_back(combobox);
return combobox;
}
static wxBoxSizer* new_labeled_combobox(
wxWindow *parent, ComboBox *&combobox, const wxString &label, const wxString &tooltip = wxEmptyString,
std::vector<ComboBox *> *list = nullptr, int label_width = DESIGN_LABEL_W, int cb_width = DESIGN_COMBO_LRG_W
)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, parent->DESIGN_ITEM_INDENT);
auto combo_title = new_static_text(parent, label, tooltip, label_width);
sizer->Add(combo_title, 0, wxALIGN_CENTER | wxALL, parent->FromDIP(3));
combobox = new_combobox(parent, tooltip, list, cb_width);
if (label_width < 0)
sizer->AddSpacer(parent->DESIGN_INPUT_PAD);
sizer->Add(combobox, 0, wxALIGN_CENTER);
return sizer;
}
static Button* new_button(wxWindow *parent, const wxString &title, const wxString &tooltip, std::vector<Button*> *list = nullptr, const wxSize &size = DESIGN_BUTTON_SIZE)
{
static const StateColor bg_color(
std::make_pair(wxColour(255, 255, 255), (int)StateColor::Disabled),
std::make_pair(wxColour(206, 206, 206), (int)StateColor::Pressed),
std::make_pair(wxColour(238, 238, 238), (int)StateColor::Hovered),
std::make_pair(wxColour(255, 255, 255), (int)StateColor::Enabled),
std::make_pair(wxColour(255, 255, 255), (int)StateColor::Normal)
);
static const StateColor bd_color(
std::make_pair(wxColour(144, 144, 144), (int)StateColor::Disabled),
std::make_pair(wxColour(38, 46, 48), (int)StateColor::Enabled)
);
static const StateColor text_color(
std::make_pair(wxColour(144, 144, 144), (int)StateColor::Disabled),
std::make_pair(wxColour(38, 46, 48), (int)StateColor::Enabled)
);
auto ctrl = new Button(parent, title);
ctrl->SetBackgroundColor(bg_color);
ctrl->SetBorderColor(bd_color);
ctrl->SetTextColor(text_color);
ctrl->SetFont(Label::Body_10);
ctrl->SetCornerRadius(parent->FromDIP(DESIGN_BUTTON_RADIUS));
ctrl->SetToolTip(tooltip);
if (size != wxDefaultSize)
ctrl->SetMinSize(parent->FromDIP(size));
if (list)
list->push_back(ctrl);
return ctrl;
}
// Editor widget builders
wxBoxSizer *PreferencesDialog::create_item_combobox(const wxString &title, wxWindow *parent, const wxString &tooltip, const std::string ¶m,
const std::vector<wxString> &label_list, const std::vector<std::string> &value_list, std::function<void(int)> callback, int title_width, int combox_width)
{
ComboBox *combobox = nullptr;
wxBoxSizer *sizer_combox = new_labeled_combobox(parent, combobox, title, tooltip, &m_combobox_list, title_width, combox_width);
auto get_value_idx = [value_list](const std::string &value) {
size_t idx = 0;
auto iter = std::find(value_list.begin(), value_list.end(), value);
if (iter != value_list.end())
idx = std::distance(value_list.begin(), iter);
return idx;
};
for (const wxString &label : label_list)
combobox->Append(label);
auto old_value = app_config->get(param);
if (!old_value.empty()) {
combobox->SetSelection(get_value_idx(old_value));
}
else {
combobox->SetSelection(0);
}
//// save config
combobox->GetDropDown().Bind(wxEVT_COMBOBOX, [=](wxCommandEvent &e) {
app_config->set(param, value_list[e.GetSelection()]);
app_config->save();
if (callback) {
callback(e.GetSelection());
}
e.Skip();
});
return sizer_combox;
}
wxBoxSizer *PreferencesDialog::create_item_language_combobox(
const wxString &title, wxWindow *parent, const wxString &tooltip, const std::string ¶m, const std::vector<const wxLanguageInfo *> &vlist)
{
ComboBox *combobox = nullptr;
wxBoxSizer *sizer_combox = new_labeled_combobox(parent, combobox, title, tooltip, &m_combobox_list);
auto language = app_config->get(param);
m_current_language_selected = -1;
for (size_t i = 0; i < vlist.size(); ++i) {
auto language_name = vlist[i]->Description;
if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_CHINESE_SIMPLIFIED)) {
language_name = wxString::FromUTF8("\xe4\xb8\xad\xe6\x96\x87\x28\xe7\xae\x80\xe4\xbd\x93\x29");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_CHINESE_TRADITIONAL)) {
language_name = wxString::FromUTF8("\xe4\xb8\xad\xe6\x96\x87\x28\xe7\xb9\x81\xe9\xab\x94\x29");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_SPANISH)) {
language_name = wxString::FromUTF8("\x45\x73\x70\x61\xc3\xb1\x6f\x6c");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_GERMAN)) {
language_name = wxString::FromUTF8("Deutsch");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_SWEDISH)) {
language_name = wxString::FromUTF8("\x53\x76\x65\x6e\x73\x6b\x61"); //Svenska
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_DUTCH)) {
language_name = wxString::FromUTF8("Nederlands");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_FRENCH)) {
language_name = wxString::FromUTF8("\x46\x72\x61\x6E\xC3\xA7\x61\x69\x73");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_HUNGARIAN)) {
language_name = wxString::FromUTF8("Magyar");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_JAPANESE)) {
language_name = wxString::FromUTF8("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_ITALIAN)) {
language_name = wxString::FromUTF8("\x69\x74\x61\x6c\x69\x61\x6e\x6f");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_KOREAN)) {
language_name = wxString::FromUTF8("\xED\x95\x9C\xEA\xB5\xAD\xEC\x96\xB4");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_RUSSIAN)) {
language_name = wxString::FromUTF8("\xD0\xA0\xD1\x83\xD1\x81\xD1\x81\xD0\xBA\xD0\xB8\xD0\xB9");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_CZECH)) {
if (wxGetApp().app_config->get("language") == "ja_JP") {
language_name = wxString::FromUTF8("\x43\x7A\x65\x63\x68");
}
else{
language_name = wxString::FromUTF8("\xC4\x8D\x65\xC5\xA1\x74\x69\x6E\x61");
}
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_UKRAINIAN)) {
if (wxGetApp().app_config->get("language") == "ja_JP") {
language_name = wxString::FromUTF8("\x55\x6B\x72\x61\x69\x6E\x69\x61\x6E");
} else {
language_name = wxString::FromUTF8("\xD0\xA3\xD0\xBA\xD1\x80\xD0\xB0\xD1\x97\xD0\xBD\xD1\x81\xD1\x8C\xD0\xBA\xD0\xB0");
}
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_PORTUGUESE_BRAZILIAN)) {
language_name = wxString::FromUTF8("\x50\x6F\x72\x74\x75\x67\x75\xC3\xAA\x73\x20\x28\x42\x72\x61\x73\x69\x6C\x29");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_TURKISH)) {
language_name = wxString::FromUTF8("\x54\xC3\xBC\x72\x6B\xC3\xA7\x65");
}
else if (vlist[i] == wxLocale::GetLanguageInfo(wxLANGUAGE_POLISH)) {
language_name = wxString::FromUTF8("Polski");
}
if (language == vlist[i]->CanonicalName) {
m_current_language_selected = i;
}
combobox->Append(language_name);
}
if (m_current_language_selected == -1 && language.size() >= 5) {
language = language.substr(0, 2);
for (size_t i = 0; i < vlist.size(); ++i) {
if (vlist[i]->CanonicalName.StartsWith(language)) {
m_current_language_selected = i;
break;
}
}
}
combobox->SetSelection(m_current_language_selected);
combobox->Bind(wxEVT_LEFT_DOWN, [this, combobox](wxMouseEvent &e) {
m_current_language_selected = combobox->GetSelection();
e.Skip();
});
combobox->Bind(wxEVT_COMBOBOX, [this, param, vlist, combobox](wxCommandEvent &e) {
if (combobox->GetSelection() == m_current_language_selected)
return;
if (e.GetString().mb_str() != app_config->get(param)) {
{
//check if the project has changed
if (wxGetApp().plater()->is_project_dirty()) {
auto result = MessageDialog(static_cast<wxWindow*>(this), _L("The current project has unsaved changes, save it before continuing?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE).ShowModal();
if (result == wxID_YES) {
wxGetApp().plater()->save_project();
}
}
// the dialog needs to be destroyed before the call to switch_language()
// or sometimes the application crashes into wxDialogBase() destructor
// so we put it into an inner scope
MessageDialog msg_wingow(nullptr, _L("Switching the language requires application restart.\n") + "\n" + _L("Do you want to continue?"),
_L("Language selection"), wxICON_QUESTION | wxOK | wxCANCEL);
if (msg_wingow.ShowModal() == wxID_CANCEL) {
combobox->SetSelection(m_current_language_selected);
return;
}
}
auto check = [this](bool yes_or_no) {
// if (yes_or_no)
// return true;
int act_btns = UnsavedChangesDialog::ActionButtons::SAVE;
return wxGetApp().check_and_keep_current_preset_changes(_L("Switching application language"),
_L("Switching application language while some presets are modified."), act_btns);
};
m_current_language_selected = combobox->GetSelection();
if (m_current_language_selected >= 0 && m_current_language_selected < vlist.size()) {
app_config->set(param, vlist[m_current_language_selected]->CanonicalName.ToUTF8().data());
app_config->save();
wxGetApp().load_language(vlist[m_current_language_selected]->CanonicalName, false);
Close();
// Reparent(nullptr);
GetParent()->RemoveChild(this);
Label::initSysFont(app_config->get_language_code());
wxGetApp().recreate_GUI(_L("Changing application language"));
}
}
e.Skip();
});
return sizer_combox;
}
wxBoxSizer *PreferencesDialog::create_item_region_combobox(const wxString &title, wxWindow *parent, const wxString &tooltip, const std::vector<wxString> &vlist)
{
static const std::vector<wxString> local_regions = {"Asia-Pacific", "China", "Europe", "North America", "Others"};
ComboBox *combobox = nullptr;
wxBoxSizer *sizer_combox = new_labeled_combobox(parent, combobox, title, tooltip, &m_combobox_list);
for (const wxString &v : vlist)
combobox->Append(v);
AppConfig * config = GUI::wxGetApp().app_config;
int current_region = 0;
if (!config->get("region").empty()) {
std::string country_code = config->get("region");
for (auto i = 0; i < vlist.size(); i++) {
if (local_regions[i].ToStdString() == country_code) {
combobox->SetSelection(i);
current_region = i;
}
}
}
combobox->GetDropDown().Bind(wxEVT_COMBOBOX, [=](wxCommandEvent &e) {
auto region_index = e.GetSelection();
auto region = local_regions[region_index];
combobox->SetSelection(region_index);
NetworkAgent* agent = wxGetApp().getAgent();
AppConfig* config = GUI::wxGetApp().app_config;
if (agent) {
MessageDialog msg_wingow(this, _L("Changing the region will log out your account.\n") + "\n" + _L("Do you want to continue?"), _L("Region selection"),
wxICON_QUESTION | wxOK | wxCANCEL);
if (msg_wingow.ShowModal() == wxID_CANCEL) {
combobox->SetSelection(current_region);
return;
} else {
wxGetApp().request_user_logout();
config->set("region", region.ToStdString());
wxGetApp().update_log_sink_region();
auto area = config->get_country_code();
if (agent) {
agent->set_country_code(area);
}
EndModal(wxID_CANCEL);
}
} else {
config->set("region", region.ToStdString());
wxGetApp().update_log_sink_region();
}
wxGetApp().update_publish_status();
//e.Skip();
});
return sizer_combox;
}
wxBoxSizer *PreferencesDialog::create_item_input(
const wxString &title, const wxString &title2, wxWindow *parent, const wxString &tooltip,
const std::string ¶m, std::function<void(const wxString&)> onchange, int label_width /* = 0 */
)
{
auto input = new_text_input(parent, app_config->get(param), tooltip);
wxBoxSizer *sizer_input = new wxBoxSizer(wxHORIZONTAL);
sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, DESIGN_ITEM_INDENT);
sizer_input->Add(new_static_text(parent, title, tooltip, label_width), 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(3));
if (label_width < 0)
sizer_input->AddSpacer(DESIGN_INPUT_PAD);
sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL);
if (!title2.IsEmpty())
sizer_input->Add(new_static_text(parent, title2, tooltip, -1), 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(3));
const auto set_value_to_app = [=](wxEvent &e) {
e.Skip();
const auto value = input->GetTextCtrl()->GetValue();
if (value == app_config->get(param))
return;
app_config->set(param, value.ToStdString());
app_config->save();
if (onchange)
onchange(value);
};
input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, set_value_to_app);
input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, set_value_to_app);
return sizer_input;
}
TextInput *PreferencesDialog::create_range_input(
wxWindow *parent, const wxString &tooltip, const std::string ¶m, float range_min, float range_max, int precision, std::function<void(const wxString&)> onchange
)
{
const auto format_str = [=](const float val){
std::stringstream ss;
ss << std::fixed << std::setprecision(precision) << val;
return ss.str();
};
// validate current value
const float float_value = std::atof(app_config->get(param).c_str());
const float check_value = std::clamp(float_value, range_min, range_max);
if (float_value != check_value) {
app_config->set(param, format_str(check_value));
app_config->save();
}
auto input = new_text_input(parent, app_config->get(param), tooltip, wxFILTER_NUMERIC);
const auto set_value_to_app = [=](wxEvent &e) {
e.Skip();
const auto value = format_str(std::clamp<float>(std::atof(input->GetTextCtrl()->GetValue().c_str()), range_min, range_max));
if (value == app_config->get(param))
return;
app_config->set(param, value);
app_config->save();
if (onchange) {
onchange(value);
}
input->GetTextCtrl()->SetValue(value);
};
input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, set_value_to_app);
input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, set_value_to_app);
return input;
}
wxBoxSizer *PreferencesDialog::create_item_range_input(
const wxString &title, wxWindow *parent, const wxString &tooltip, const std::string ¶m,
float range_min, float range_max, int precision, std::function<void(const wxString&)> onchange, int label_width /* = 0 */
)
{
auto input = create_range_input(parent, tooltip, param, range_min, range_max, precision, onchange);
wxBoxSizer *sizer_input = new wxBoxSizer(wxHORIZONTAL);
sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, DESIGN_ITEM_INDENT);
sizer_input->Add(new_static_text(parent, title, tooltip, label_width), 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(3));
if (label_width < 0)
sizer_input->AddSpacer(DESIGN_INPUT_PAD);
sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL);
return sizer_input;
}
wxBoxSizer *PreferencesDialog::create_item_range_two_input(
const wxString & title,
wxWindow * parent,
const wxString & tooltip,
const std::string & param,
const std::string & param1,
float range_min,
float range_max,
int precision,
std::function<void(const wxString&)> onchange,
std::function<void(const wxString&)> onchange1,
int label_width /* = 0 */
)
{
auto input = create_range_input(parent, tooltip, param, range_min, range_max, precision, onchange);
auto input1 = create_range_input(parent, tooltip, param1, range_min, range_max, precision, onchange1);
wxBoxSizer *sizer_input = new wxBoxSizer(wxHORIZONTAL);
sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, DESIGN_ITEM_INDENT);
sizer_input->Add(new_static_text(parent, title, tooltip, label_width), 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(3));
if (label_width < 0)
sizer_input->AddSpacer(DESIGN_INPUT_PAD);
sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL, 0);
sizer_input->AddSpacer(DESIGN_INPUT_PAD);
sizer_input->Add(input1, 0, wxALIGN_CENTER_VERTICAL, 0);
return sizer_input;
}
wxBoxSizer *PreferencesDialog::create_item_backup_input(const wxString &title, wxWindow *parent, const wxString &tooltip)
{
static const std::string param("backup_interval");
auto input = new_text_input(parent, app_config->get(param), tooltip);
const auto save_value = [=](wxEvent &e) {
e.Skip();
const wxString value = input->GetTextCtrl()->GetValue();
if (value == app_config->get(param))
return;
app_config->set(param, value.ToStdString());
app_config->save();
long interval = 0;
value.ToLong(&interval);
Slic3r::set_backup_interval(interval);
m_backup_interval_time = value;
};
input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, save_value);
input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, save_value);
input->Enable(app_config->get_bool("backup_switch"));
input->Refresh();
m_backup_interval_textinput = input;
wxBoxSizer *sizer_input = new wxBoxSizer(wxHORIZONTAL);
sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(3));
sizer_input->Add(new_static_text(parent, title, tooltip, -1), 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(3));
sizer_input->AddSpacer(DESIGN_INPUT_PAD);
sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL, 0);
sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(3));
sizer_input->Add(new_static_text(parent, _L("Second"), tooltip, -1), 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(3));
return sizer_input;
}
wxBoxSizer* PreferencesDialog::create_item_darkmode_checkbox(const wxString &title, wxWindow* parent, const wxString &tooltip, const std::string ¶m)
{
//// save config
auto callback = [this, param](int value) {
app_config->set(param, value ? "1" : "0");
app_config->save();
wxGetApp().Update_dark_mode_flag();
wxGetApp().force_colors_update();
wxGetApp().update_ui_from_settings();
wxGetApp().UpdateDlgDarkUI(this);
SimpleEvent evt = SimpleEvent(EVT_GLCANVAS_COLOR_MODE_CHANGED);
wxPostEvent(wxGetApp().plater(), evt);
};
return create_item_checkbox(title, parent, tooltip, param, callback);
}
// TODO: Move special handling of individual properties in the change handler into their own callbacks.
wxBoxSizer *PreferencesDialog::create_item_checkbox(
const wxString &title, wxWindow *parent, const wxString &tooltip,
const std::string ¶m, std::function<void(int)> callback /* = nullptr */
)
{
wxBoxSizer *m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL);
m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, DESIGN_ITEM_INDENT);
auto checkbox = new ::CheckBox(parent);
checkbox->SetToolTip(tooltip);
m_checkbox_list.push_back(checkbox);
if (!param.empty()) {
bool current_value = app_config->get_bool(param);
// special exception for reversed item label vs. actual config value
if (param == "no_warn_when_modified_gcodes")
current_value = !current_value;
checkbox->SetValue(current_value);
}
m_sizer_checkbox->Add(checkbox, 0, wxALIGN_CENTER, 0);
m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, 8);
auto checkbox_title = new_static_text(parent, title, tooltip, -1);
const auto size = checkbox_title->GetTextExtent(title);
checkbox_title->SetMinSize(wxSize(size.x + FromDIP(5), -1));
m_sizer_checkbox->Add(checkbox_title, 0, wxALIGN_CENTER | wxALL, 3);
//// save config
checkbox->Bind(wxEVT_TOGGLEBUTTON, [=](wxCommandEvent &e)
{
bool value = checkbox->GetValue();
if (!param.empty()) {
// special exception for reversed item label vs. actual config value
if (param == "no_warn_when_modified_gcodes")
value = !value;
app_config->set_bool(param, value);
app_config->save();
}
if (callback) {
callback(e.GetInt());
}
else if (param == "firstguide") {
if (NetworkAgent* agent = GUI::wxGetApp().getAgent(); agent && !value) {
agent->track_enable(false);
agent->track_remove_files();
}
wxGetApp().save_privacy_policy_history(value, "preferences");
}
else if (param == "staff_pick_switch") {
wxGetApp().switch_staff_pick(value);
}
// backup
else if (param == "backup_switch") {
std::string backup_interval = "10";
app_config->get("backup_interval", backup_interval);
Slic3r::set_backup_interval(value ? boost::lexical_cast<long>(backup_interval) : 0);
if (m_backup_interval_textinput != nullptr) { m_backup_interval_textinput->Enable(value); }
}
else if (param == "sync_user_preset") {
if (value) {
wxGetApp().start_sync_user_preset();
} else {
wxGetApp().stop_sync_user_preset();
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " sync_user_preset: " << (value ? "true" : "false");
}
#ifdef __WXMSW__
else if (param == "associate_3mf") {
if (value) {
wxGetApp().associate_files(L"3mf");
} else {
wxGetApp().disassociate_files(L"3mf");
}
}
else if (param == "associate_stl") {
if (value) {
wxGetApp().associate_files(L"stl");
} else {
wxGetApp().disassociate_files(L"stl");
}
}
else if (param == "associate_step") {
if (value) {
wxGetApp().associate_files(L"step");
} else {
wxGetApp().disassociate_files(L"step");
}
}
#endif // __WXMSW__
else if (param == "developer_mode")
{
Slic3r::GUI::wxGetApp().save_mode(value ? comDevelop : comAdvanced);
m_developer_mode_def = value;
}
// webview dump_vedio
else if (param == "internal_developer_mode") {
Slic3r::GUI::wxGetApp().update_internal_development();
if (value)
Slic3r::GUI::wxGetApp().mainframe->show_log_window();
m_internal_developer_mode_def = value;
}
else if (param == "show_print_history") {
if (wxGetApp().mainframe && wxGetApp().mainframe->m_webview)
wxGetApp().mainframe->m_webview->ShowUserPrintTask(value, value);
}
else if (param == "enable_lod") {
MessageDialog msg_wingow(this,
_L("Please note that the model show will undergo certain changes at small pixels case.\nEnabled LOD requires application restart.") + "\n" + _L("Do you want to continue?"),
_L("Enable LOD"), wxICON_WARNING | wxYES_NO | wxYES_DEFAULT | wxCENTRE);
if (msg_wingow.ShowModal() == wxID_YES) {
if (wxGetApp().plater()->is_project_dirty()) {
MessageDialog save_dlg(this, _L("The current project has unsaved changes, save it before continuing?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxICON_WARNING | wxYES_NO | wxYES_DEFAULT | wxCENTRE);
if (save_dlg.ShowModal() == wxID_YES)
wxGetApp().plater()->save_project();
}
Close();
GetParent()->RemoveChild(this);
wxGetApp().recreate_GUI(_L("Enable LOD"));
}
else {
checkbox->SetValue(!value);
app_config->set_bool(param, !value);
app_config->save();
}
}
else if (param == "enable_record_gcodeviewer_option_item"){
SimpleEvent evt(EVT_ENABLE_GCODE_OPTION_ITEM_CHANGED);
wxPostEvent(wxGetApp().plater(), evt);
}
else if (param == "enable_high_low_temp_mixed_printing") {
if (value) {
const wxString warning_title = _L("Bed Temperature Difference Warning");
const wxString warning_message =
_L("Using filaments with significantly different temperatures may cause:\n"
"• Extruder clogging\n"
"• Nozzle damage\n"
"• Layer adhesion issues\n\n"
"Continue with enabling this feature?") + "\n";
std::function<void(const wxString&)> link_callback = [](const wxString&) {
const std::string lang_code = wxGetApp().app_config->get("language");
const wxString region = (lang_code.find("zh") != std::string::npos) ? L"zh" : L"en";
const wxString wiki_url = wxString::Format(
L"https://wiki.bambulab.com/%s/filament-acc/filament/h2d-filament-config-limit",
region
);
wxGetApp().open_browser_with_warning_dialog(wiki_url);
};
MessageDialog msg_dialog(
this,
warning_message,
warning_title,
wxICON_WARNING | wxYES_NO | wxYES_DEFAULT | wxCENTRE,
wxEmptyString,
_L("Click Wiki for help."),
link_callback
);
if (msg_dialog.ShowModal() != wxID_YES) {
checkbox->SetValue(false);
app_config->set_bool(param, false);
app_config->save();
}
}
}
e.Skip();
});
//// for debug mode
if (param == "developer_mode") { m_developer_mode_ckeckbox = checkbox; }
else if (param == "internal_developer_mode") { m_internal_developer_mode_ckeckbox = checkbox; }
return m_sizer_checkbox;
}
wxWindow* PreferencesDialog::create_item_downloads(wxWindow* parent, const std::string ¶m)
{
auto item_panel = new wxWindow(parent, wxID_ANY);
item_panel->SetBackgroundColour(DESIGN_CONTENT_BG_COLOR);
auto label = new_static_text(item_panel, _L("Downloads Folder:"), wxEmptyString, -1);
auto m_staticTextPath = new_static_text(item_panel, wxString::FromUTF8(app_config->get(param)), wxEmptyString, -1, wxST_ELLIPSIZE_END);
auto m_button_download = new_button(item_panel, _L("Browse"), _L("Select default folder for downloads."), &m_button_list);
m_button_download->Bind(wxEVT_BUTTON, [=](auto& e) {
const wxString defaultPath = wxString::FromUTF8(app_config->get(param));
wxDirDialog dialog(const_cast<PreferencesDialog*>(this), _L("Choose Download Directory"), defaultPath, wxDD_NEW_DIR_BUTTON);
if (dialog.ShowModal() == wxID_OK) {
const wxString download_path = dialog.GetPath();
app_config->set(param, download_path.ToUTF8().data());
m_staticTextPath->SetLabelText(download_path);
item_panel->Layout();
}
});
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, DESIGN_ITEM_INDENT);
sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(5));
sizer->AddSpacer(DESIGN_INPUT_PAD);
sizer->Add(m_staticTextPath, 0, wxALIGN_CENTER_VERTICAL);
sizer->Add(m_button_download, 0, wxALL, FromDIP(5));
item_panel->SetSizer(sizer);
item_panel->Layout();
return item_panel;
}
wxWindow *PreferencesDialog::create_item_radiobox(
const wxString &title,
wxWindow *parent,
const wxString &tooltip,
int groupid,
const std::string ¶m,
bool select /* = false */
)
{
wxWindow *item = new wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(28)));
item->SetBackgroundColour(DESIGN_CONTENT_BG_COLOR);
RadioBox *radiobox = new RadioBox(item);
radiobox->SetValue(select);
radiobox->SetToolTip(tooltip);
radiobox->SetPosition(wxPoint(DESIGN_ITEM_INDENT, (item->GetSize().GetHeight() - radiobox->GetSize().GetHeight()) / 2));
RadioSelector *rs = new RadioSelector;
rs->m_groupid = groupid;
rs->m_param_name = param;
rs->m_radiobox = radiobox;
rs->m_selected = select;
m_radio_group.Append(rs);
radiobox->Bind(wxEVT_LEFT_DOWN, [=](wxMouseEvent &event) {
// Ensure only one button is selected in exclusive groups.
int groupid = -1;
const int event_id = event.GetId();
for (auto rs : std::as_const(m_radio_group)) {
if (RadioBox *rb = rs->m_radiobox; rb && rb->GetId() == event_id) {
groupid = rs->m_groupid;
break;
}
}
if (groupid < 0)
return;
for (auto rs : std::as_const(m_radio_group))
if (RadioBox *rb = rs->m_radiobox; rb && rs->m_groupid == groupid)
rb->SetValue(rb->GetId() == event_id);
});
wxStaticText *text = new_static_text(item, title, tooltip, -1);
text->SetPosition(wxPoint(DESIGN_ITEM_INDENT + radiobox->GetSize().GetWidth() + 10, (item->GetSize().GetHeight() - text->GetSize().GetHeight()) / 2));
return item;
}
//
// Begin implementation
//
PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style)
: DPIDialog(parent, id, _L("Preferences"), pos, size, style)
{
create();
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) {
try {
NetworkAgent* agent = GUI::wxGetApp().getAgent();
if (agent) {
json j;
std::string value;
value = wxGetApp().app_config->get("auto_calculate_flush");
j["auto_flushing"] = value;
agent->track_event("preferences_changed", j.dump());
}
} catch(...) {}
event.Skip();
});
}
PreferencesDialog::~PreferencesDialog()
{
m_radio_group.DeleteContents(true);
}
void PreferencesDialog::create()
{
app_config = get_app_config();
m_backup_interval_time = app_config->get("backup_interval");
m_original_use_12h_time_format = app_config->get_bool("use_12h_time_format");
// set icon for dialog
const std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
SetSizeHints(wxDefaultSize, wxDefaultSize); // ensure dialog is resizable
SetBackgroundColour(DESIGN_CONTENT_BG_COLOR);
// The page display and navigation handler.
m_page_book = new Tabbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, nullptr, wxBK_LEFT);
// Customize the navigation button list sidebar control.
auto *ctrl = m_page_book->GetBtnsListCtrl();
ctrl->SetBackgroundColour(DESIGN_SIDEBAR_BG_COLOR);
// make scrollable vertically
ctrl->SetScrollRate(0, FromDIP(10));
// option to have vertical scrollbar use allotted sidebar space instead of expanding the sidebar area horizontally
// ctrl->SetUseClientAreaForScrollbar(true);
// Add top padding above buttons.
ctrl->SetListTopPadding(DESIGN_PAGE_PADDING);
// Reduce button padding around text label.
ctrl->SetPaddingSize({ FromDIP(20), FromDIP(16) });
// Use natural button size by default (we'll adjust width after adding pages).
ctrl->SetButtonSize(wxDefaultSize);
// No button borders
ctrl->SetButtonBorderWidth(0);
// Make selected or hovered button background match the content page background color, otherwise same as sidebar
ctrl->SetButtonBGColors(StateColor(
std::make_pair(DESIGN_CONTENT_BG_COLOR, (int)StateColor::Checked),
std::make_pair(DESIGN_CONTENT_BG_COLOR, (int)StateColor::Hovered),
std::make_pair(DESIGN_SIDEBAR_BG_COLOR, (int)StateColor::Normal)
));
// Add all our pages.
m_page_book->Add(create_general_page(), _L("General"), _L("Settings affecting basic application behaviors."));
m_page_book->Add(create_online_page(), _L("Online"), _L("Configure features requiring an Internet connection."));
m_page_book->Add(create_projects_page(), _L("Projects"), _L("Settings related to working with projects."));
m_page_book->Add(create_files_page(), _L("File Handling"), _L("Settings related to opening and importing files of various types, including 3MF projects."));
m_page_book->Add(create_3Dview_page(), _L("3D View"), _L("The \"Prepare\" and \"Preview\" 3D workspace and graphics settings."));
m_page_book->Add(create_advanced_page(), _L("Advanced"), _L("Other settings for more advanced control over program behavior."));
// Set nav button width to increase padding on the right side, with constraint in case of some erroneous translation.
ctrl->SetButtonSize({ std::min(int(ctrl->GetBestSize().x * 1.33), FromDIP(240)), -1 });
// Final layout
auto main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_page_book, 1, wxEXPAND /* | wxTOP, FromDIP(10) */);
SetSizer(main_sizer);
// Resize and position the dialog.
set_window_size();
CenterOnParent();
// update for dark mode
wxGetApp().UpdateDlgDarkUI(this);
// Ensure static selection ID is valid after all pages have been added.