/
Tab.cpp
6233 lines (5429 loc) · 272 KB
/
Tab.cpp
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
///|/ Copyright (c) Prusa Research 2017 - 2023 Oleksandra Iushchenko @YuSanka, Lukáš Matěna @lukasmatena, Lukáš Hejl @hejllukas, Vojtěch Bubník @bubnikv, Pavel Mikuš @Godrak, Tomáš Mészáros @tamasmeszaros, David Kocík @kocikdav, Enrico Turri @enricoturri1966, Vojtěch Král @vojtechkral
///|/ Copyright (c) 2021 Martin Budden
///|/ Copyright (c) 2021 Ilya @xorza
///|/ Copyright (c) 2019 John Drake @foxox
///|/ Copyright (c) 2019 Matthias Urlichs @smurfix
///|/ Copyright (c) 2019 Thomas Moore
///|/ Copyright (c) 2019 Sijmen Schoon
///|/ Copyright (c) 2018 Martin Loidl @LoidlM
///|/
///|/ ported from lib/Slic3r/GUI/Tab.pm:
///|/ Copyright (c) Prusa Research 2016 - 2018 Vojtěch Bubník @bubnikv, Lukáš Matěna @lukasmatena
///|/ Copyright (c) 2015 - 2017 Joseph Lenox @lordofhyphens
///|/ Copyright (c) Slic3r 2012 - 2016 Alessandro Ranellucci @alranel
///|/ Copyright (c) 2016 Chow Loong Jin @hyperair
///|/ Copyright (c) 2012 QuantumConcepts
///|/ Copyright (c) 2012 Henrik Brix Andersen @henrikbrixandersen
///|/
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
///|/
// #include "libslic3r/GCodeSender.hpp"
//#include "slic3r/Utils/Serial.hpp"
#include "Tab.hpp"
#include "PresetHints.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/GCode/GCodeProcessor.hpp"
#include "WipeTowerDialog.hpp"
#include "Search.hpp"
#include "OG_CustomCtrl.hpp"
#include <wx/app.h>
#include <wx/button.h>
#include <wx/scrolwin.h>
#include <wx/sizer.h>
#include <wx/bmpcbox.h>
#include <wx/bmpbuttn.h>
#include <wx/treectrl.h>
#include <wx/imaglist.h>
#include <wx/settings.h>
#include <wx/filedlg.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "libslic3r/libslic3r.h"
#include "wxExtensions.hpp"
#include "PresetComboBoxes.hpp"
#include <wx/wupdlock.h>
#include "GUI_App.hpp"
#include "GUI_ObjectList.hpp"
#include "Plater.hpp"
#include "MainFrame.hpp"
#include "format.hpp"
#include "UnsavedChangesDialog.hpp"
#include "SavePresetDialog.hpp"
#include "EditGCodeDialog.hpp"
#include "MsgDialog.hpp"
#include "Notebook.hpp"
#include "Widgets/Label.hpp"
#include "Widgets/TabCtrl.hpp"
#include "MarkdownTip.hpp"
#include "Search.hpp"
#include "BedShapeDialog.hpp"
#include "BedShapeDialog.hpp"
// #include "BonjourDialog.hpp"
#ifdef WIN32
#include <commctrl.h>
#endif // WIN32
namespace Slic3r {
namespace GUI {
#define DISABLE_UNDO_SYS
void Tab::Highlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID_ANY*/)
{
m_timer.SetOwner(owner, timerid);
}
void Tab::Highlighter::init(std::pair<OG_CustomCtrl*, bool*> params)
{
if (m_timer.IsRunning())
invalidate();
if (!params.first || !params.second)
return;
m_timer.Start(300, false);
m_custom_ctrl = params.first;
m_show_blink_ptr = params.second;
*m_show_blink_ptr = true;
m_custom_ctrl->Refresh();
}
void Tab::Highlighter::invalidate()
{
m_timer.Stop();
if (m_custom_ctrl && m_show_blink_ptr) {
*m_show_blink_ptr = false;
m_custom_ctrl->Refresh();
m_show_blink_ptr = nullptr;
m_custom_ctrl = nullptr;
}
m_blink_counter = 0;
}
void Tab::Highlighter::blink()
{
if (m_custom_ctrl && m_show_blink_ptr) {
*m_show_blink_ptr = !*m_show_blink_ptr;
m_custom_ctrl->Refresh();
}
else
return;
if ((++m_blink_counter) == 11)
invalidate();
}
//BBS: GUI refactor
Tab::Tab(ParamsPanel* parent, const wxString& title, Preset::Type type) :
m_parent(parent), m_title(title), m_type(type)
{
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL/*, name*/);
this->SetFont(Slic3r::GUI::wxGetApp().normal_font());
wxGetApp().UpdateDarkUI(this);
SetBackgroundColour(*wxWHITE);
m_compatible_printers.type = Preset::TYPE_PRINTER;
m_compatible_printers.key_list = "compatible_printers";
m_compatible_printers.key_condition = "compatible_printers_condition";
//m_compatible_printers.dialog_title = _L("Compatible printers");
//m_compatible_printers.dialog_label = _L("Select the printers this profile is compatible with.");
m_compatible_prints.type = Preset::TYPE_PRINT;
m_compatible_prints.key_list = "compatible_prints";
m_compatible_prints.key_condition = "compatible_prints_condition";
//m_compatible_prints.dialog_title = _L("Compatible print profiles");
//m_compatible_prints.dialog_label = _L("Select the print profiles this profile is compatible with.");
wxGetApp().tabs_list.push_back(this);
m_em_unit = em_unit(m_parent); //wxGetApp().em_unit();
m_config_manipulation = get_config_manipulation();
Bind(wxEVT_SIZE, ([](wxSizeEvent &evt) {
//for (auto page : m_pages)
// if (! page.get()->IsShown())
// page->layout_valid = false;
evt.Skip();
}));
m_highlighter.set_timer_owner(this, 0);
this->Bind(wxEVT_TIMER, [this](wxTimerEvent&)
{
m_highlighter.blink();
});
}
void Tab::set_type()
{
if (m_name == PRESET_PRINT_NAME) { m_type = Slic3r::Preset::TYPE_PRINT; }
else if (m_name == "sla_print") { m_type = Slic3r::Preset::TYPE_SLA_PRINT; }
else if (m_name == PRESET_FILAMENT_NAME) { m_type = Slic3r::Preset::TYPE_FILAMENT; }
else if (m_name == "sla_material") { m_type = Slic3r::Preset::TYPE_SLA_MATERIAL; }
else if (m_name == PRESET_PRINTER_NAME) { m_type = Slic3r::Preset::TYPE_PRINTER; }
else { m_type = Slic3r::Preset::TYPE_INVALID; assert(false); }
}
// sub new
//BBS: GUI refactor, change tab to fit into ParamsPanel
void Tab::create_preset_tab()
{
//move to ParamsPanel
/*#ifdef __WINDOWS__
SetDoubleBuffered(true);
#endif //__WINDOWS__*/
auto panel = this;
m_preset_bundle = wxGetApp().preset_bundle;
// Vertical sizer to hold the choice menu and the rest of the page.
/*#ifdef __WXOSX__
auto *main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->SetSizeHints(this);
this->SetSizer(main_sizer);
// Create additional panel to Fit() it from OnActivate()
// It's needed for tooltip showing on OSX
m_tmp_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
auto panel = m_tmp_panel;
auto sizer = new wxBoxSizer(wxVERTICAL);
m_tmp_panel->SetSizer(sizer);
m_tmp_panel->Layout();
main_sizer->Add(m_tmp_panel, 1, wxEXPAND | wxALL, 0);
#else
Tab *panel = this;
auto *sizer = new wxBoxSizer(wxVERTICAL);
sizer->SetSizeHints(panel);
panel->SetSizer(sizer);
#endif //__WXOSX__*/
// BBS: model config
if (m_type < Preset::TYPE_COUNT) {
// preset chooser
m_presets_choice = new TabPresetComboBox(panel, m_type);
// m_presets_choice->SetFont(Label::Body_10); // BBS
m_presets_choice->set_selection_changed_function([this](int selection) {
if (!m_presets_choice->selection_is_changed_according_to_physical_printers())
{
if (m_type == Preset::TYPE_PRINTER && !m_presets_choice->is_selected_physical_printer())
m_preset_bundle->physical_printers.unselect_printer();
// select preset
std::string preset_name = m_presets_choice->GetString(selection).ToUTF8().data();
select_preset(Preset::remove_suffix_modified(preset_name));
}
});
}
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
//buttons
m_scaled_buttons.reserve(6);
m_scaled_bitmaps.reserve(4);
m_top_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
// BBS: open this tab by select first
m_top_panel->SetBackgroundColour(*wxWHITE);
m_top_panel->Bind(wxEVT_LEFT_UP, [this](auto & e) {
restore_last_select_item();
});
//add_scaled_button(panel, &m_btn_compare_preset, "compare");
add_scaled_button(m_top_panel, &m_btn_save_preset, "save");
add_scaled_button(m_top_panel, &m_btn_delete_preset, "cross");
//if (m_type == Preset::Type::TYPE_PRINTER)
// add_scaled_button(panel, &m_btn_edit_ph_printer, "cog");
m_show_incompatible_presets = false;
add_scaled_bitmap(this, m_bmp_show_incompatible_presets, "flag_red");
add_scaled_bitmap(this, m_bmp_hide_incompatible_presets, "flag_green");
//add_scaled_button(panel, &m_btn_hide_incompatible_presets, m_bmp_hide_incompatible_presets.name());
//m_btn_compare_preset->SetToolTip(_L("Compare presets"));
// TRN "Save current Settings"
m_btn_save_preset->SetToolTip(wxString::Format(_L("Save current %s"), m_title));
m_btn_delete_preset->SetToolTip(_(L("Delete this preset")));
m_btn_delete_preset->Hide();
/*add_scaled_button(panel, &m_question_btn, "question");
m_question_btn->SetToolTip(_(L("Hover the cursor over buttons to find more information \n"
"or click this button.")));
add_scaled_button(panel, &m_search_btn, "search");
m_search_btn->SetToolTip(format_wxstr(_L("Search in settings [%1%]"), "Ctrl+F"));*/
// Bitmaps to be shown on the "Revert to system" aka "Lock to system" button next to each input field.
add_scaled_bitmap(this, m_bmp_value_lock , "unlock_normal");
add_scaled_bitmap(this, m_bmp_value_unlock, "lock_normal");
m_bmp_non_system = &m_bmp_white_bullet;
// Bitmaps to be shown on the "Undo user changes" button next to each input field.
add_scaled_bitmap(this, m_bmp_value_revert, "undo");
add_scaled_bitmap(this, m_bmp_white_bullet, "dot");
// Bitmap to be shown on the "edit" button before to each editable input field.
add_scaled_bitmap(this, m_bmp_edit_value, "edit");
set_tooltips_text();
add_scaled_button(m_top_panel, &m_undo_btn, m_bmp_white_bullet.name());
add_scaled_button(m_top_panel, &m_undo_to_sys_btn, m_bmp_white_bullet.name());
add_scaled_button(m_top_panel, &m_btn_search, "search");
m_btn_search->SetToolTip(_L("Search in preset"));
//search input
m_search_item = new StaticBox(m_top_panel);
StateColor box_colour(std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
StateColor box_border_colour(std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Normal));
m_search_item->SetBackgroundColor(box_colour);
m_search_item->SetBorderColor(box_border_colour);
m_search_item->SetCornerRadius(5);
//StateColor::darkModeColorFor(wxColour(238, 238, 238)), wxDefaultPosition, wxSize(m_top_panel->GetSize().GetWidth(), 3 * wxGetApp().em_unit()), 8);
auto search_sizer = new wxBoxSizer(wxHORIZONTAL);
m_search_input = new TextInput(m_search_item, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 | wxBORDER_NONE);
m_search_input->SetBackgroundColour(wxColour(238, 238, 238));
m_search_input->SetForegroundColour(wxColour(43, 52, 54));
m_search_input->SetFont(wxGetApp().bold_font());
search_sizer->Add(new wxWindow(m_search_item, wxID_ANY, wxDefaultPosition, wxSize(0, 0)), 0, wxEXPAND|wxLEFT|wxRIGHT, FromDIP(6));
search_sizer->Add(m_search_input, 1, wxEXPAND | wxALL, FromDIP(2));
//bbl for linux
//search_sizer->Add(new wxWindow(m_search_input, wxID_ANY, wxDefaultPosition, wxSize(0, 0)), 0, wxEXPAND | wxLEFT, 16);
m_search_item->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
m_search_input->SetFocus();
});
m_search_input->Bind(wxCUSTOMEVT_EXIT_SEARCH, [this](wxCommandEvent &) {
Freeze();
if (m_presets_choice) m_presets_choice->Show();
m_btn_save_preset->Show();
m_btn_search->Show();
m_search_item->Hide();
m_search_item->Refresh();
m_search_item->Update();
m_search_item->Layout();
this->GetParent()->Refresh();
this->GetParent()->Update();
this->GetParent()->Layout();
Thaw();
});
m_search_item->SetSizer(search_sizer);
m_search_item->Layout();
search_sizer->Fit(m_search_item);
m_search_item->Hide();
//m_btn_search->SetId(wxID_FIND_PROCESS);
m_btn_search->Bind(
wxEVT_BUTTON,
[this](wxCommandEvent &) {
Freeze();
if (m_presets_choice)
m_presets_choice->Hide();
m_btn_save_preset->Hide();
m_btn_search->Hide();
m_search_item->Show();
this->GetParent()->Refresh();
this->GetParent()->Update();
this->GetParent()->Layout();
wxGetApp().plater()->search(false, m_type, m_top_panel->GetParent(), m_search_input, m_btn_search);
Thaw();
});
m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); }));
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); }));
/* m_search_btn->Bind(wxEVT_BUTTON, [](wxCommandEvent) { wxGetApp().plater()->search(false); });*/
// Colors for ui "decoration"
m_sys_label_clr = wxGetApp().get_label_clr_sys();
m_modified_label_clr = wxGetApp().get_label_clr_modified();
m_default_text_clr = wxGetApp().get_label_clr_default();
m_main_sizer = new wxBoxSizer( wxVERTICAL );
m_top_sizer = new wxBoxSizer( wxHORIZONTAL );
m_top_sizer->Add(m_undo_btn, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
// BBS: model config
if (m_presets_choice) {
m_presets_choice->Reparent(m_top_panel);
m_top_sizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 8);
} else {
m_top_sizer->AddSpacer(10);
m_top_sizer->AddStretchSpacer(1);
}
const float scale_factor = /*wxGetApp().*/em_unit(this)*0.1;// GetContentScaleFactor();
#ifndef DISABLE_UNDO_SYS
m_top_sizer->Add( m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL);
m_top_sizer->AddSpacer(8);
#endif
m_top_sizer->Add( m_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 8 );
m_top_sizer->Add( m_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 8 );
m_top_sizer->Add( m_btn_search, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 8 );
m_top_sizer->Add( m_search_item, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT , 8 );
if (dynamic_cast<TabPrint*>(this) == nullptr) {
m_static_title = new Label(m_top_panel, Label::Body_12, _L("Advance"));
m_static_title->Wrap( -1 );
// BBS: open this tab by select first
m_static_title->Bind(wxEVT_LEFT_UP, [this](auto& e) {
restore_last_select_item();
});
m_top_sizer->Add( m_static_title, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 8 );
m_mode_view = new SwitchButton(m_top_panel, wxID_ABOUT);
m_top_sizer->AddSpacer(4);
m_top_sizer->Add( m_mode_view, 0, wxALIGN_CENTER_VERTICAL);
}
m_top_sizer->AddSpacer(10);
m_top_sizer->SetMinSize(-1, 3 * m_em_unit);
m_top_panel->SetSizer(m_top_sizer);
if (m_presets_choice)
m_main_sizer->Add(m_top_panel, 0, wxEXPAND | wxUP | wxDOWN, m_em_unit);
else
m_top_panel->Hide();
#if 0
#ifdef _MSW_DARK_MODE
// Sizer with buttons for mode changing
if (wxGetApp().tabs_as_menu())
#endif
m_mode_sizer = new ModeSizer(panel, int (0.5*em_unit(this)));
const float scale_factor = /*wxGetApp().*/em_unit(this)*0.1;// GetContentScaleFactor();
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 0, wxEXPAND | wxBOTTOM, 3);
m_hsizer->Add(m_presets_choice, 0, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
m_hsizer->AddSpacer(int(4*scale_factor));
m_hsizer->Add(m_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(4 * scale_factor));
m_hsizer->Add(m_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL);
if (m_btn_edit_ph_printer) {
m_hsizer->AddSpacer(int(4 * scale_factor));
m_hsizer->Add(m_btn_edit_ph_printer, 0, wxALIGN_CENTER_VERTICAL);
}
m_hsizer->AddSpacer(int(/*16*/8 * scale_factor));
m_hsizer->Add(m_btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(8 * scale_factor));
m_hsizer->Add(m_question_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(32 * scale_factor));
m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(32 * scale_factor));
m_hsizer->Add(m_search_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(8*scale_factor));
m_hsizer->Add(m_btn_compare_preset, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(16*scale_factor));
// m_hsizer->AddStretchSpacer(32);
// StretchSpacer has a strange behavior under OSX, so
// There is used just additional sizer for m_mode_sizer with right alignment
if (m_mode_sizer) {
auto mode_sizer = new wxBoxSizer(wxVERTICAL);
// Don't set the 2nd parameter to 1, making the sizer rubbery scalable in Y axis may lead
// to wrong vertical size assigned to wxBitmapComboBoxes, see GH issue #7176.
mode_sizer->Add(m_mode_sizer, 0, wxALIGN_RIGHT);
m_hsizer->Add(mode_sizer, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, wxOSX ? 15 : 10);
}
//Horizontal sizer to hold the tree and the selected page.
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 1, wxEXPAND, 0);
//left vertical sizer
m_left_sizer = new wxBoxSizer(wxVERTICAL);
m_hsizer->Add(m_left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
#endif
// tree
m_tabctrl = new TabCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1),
wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_NONE | wxWANTS_CHARS | wxTR_FULL_ROW_HIGHLIGHT);
m_tabctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable right select
m_tabctrl->SetFont(Label::Body_14);
//m_left_sizer->Add(m_tabctrl, 1, wxEXPAND);
const int img_sz = int(32 * scale_factor + 0.5f);
m_icons = new wxImageList(img_sz, img_sz, false, 1);
// Index of the last icon inserted into $self->{icons}.
m_icon_count = -1;
m_tabctrl->AssignImageList(m_icons);
wxGetApp().UpdateDarkUI(m_tabctrl);
// Delay processing of the following handler until the message queue is flushed.
// This helps to process all the cursor key events on Windows in the tree control,
// so that the cursor jumps to the last item.
// BBS: bold selection
m_tabctrl->Bind(wxEVT_TAB_SEL_CHANGING, [this](wxCommandEvent& event) {
if (m_disable_tree_sel_changed_event)
return;
const auto sel_item = m_tabctrl->GetSelection();
//OutputDebugStringA("wxEVT_TAB_SEL_CHANGING ");
//OutputDebugStringA(m_title.c_str());
//const auto selection = sel_item >= 0 ? m_tabctrl->GetItemText(sel_item) : "";
//OutputDebugString(selection);
//OutputDebugStringA("\n");
m_tabctrl->SetItemBold(sel_item, false);
});
m_tabctrl->Bind(wxEVT_TAB_SEL_CHANGED, [this](wxCommandEvent& event) {
#ifdef __linux__
// Events queue is opposite On Linux. wxEVT_SET_FOCUS invokes after wxEVT_TAB_SEL_CHANGED,
// and a result wxEVT_KILL_FOCUS doesn't invoke for the TextCtrls.
// So, call SetFocus explicitly for this control before changing of the selection
m_tabctrl->SetFocus();
#endif
if (!m_disable_tree_sel_changed_event && !m_pages.empty()) {
if (m_page_switch_running)
m_page_switch_planned = true;
else {
m_page_switch_running = true;
do {
m_page_switch_planned = false;
m_tabctrl->Update();
} while (this->tree_sel_change_delayed(event));
m_page_switch_running = false;
}
}
});
m_tabctrl->Bind(wxEVT_KEY_DOWN, &Tab::OnKeyDown, this);
m_main_sizer->Add(m_tabctrl, 1, wxEXPAND | wxALL, 0 );
this->SetSizer(m_main_sizer);
//this->Layout();
m_page_view = m_parent->get_paged_view();
// Initialize the page.
/*#ifdef __WXOSX__
auto page_parent = m_tmp_panel;
#else
auto page_parent = this;
#endif
m_page_view = new wxScrolledWindow(page_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_page_sizer = new wxBoxSizer(wxVERTICAL);
m_page_view->SetSizer(m_page_sizer);
m_page_view->SetScrollbars(1, 20, 1, 2);
m_hsizer->Add(m_page_view, 1, wxEXPAND | wxLEFT, 5);*/
//m_btn_compare_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { compare_preset(); }));
m_btn_save_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { save_preset(); }));
m_btn_delete_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { delete_preset(); }));
/*m_btn_hide_incompatible_presets->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) {
toggle_show_hide_incompatible();
}));
if (m_btn_edit_ph_printer)
m_btn_edit_ph_printer->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
if (m_preset_bundle->physical_printers.has_selection())
m_presets_choice->edit_physical_printer();
else
m_presets_choice->add_physical_printer();
});*/
// Initialize the DynamicPrintConfig by default keys/values.
build();
// ys_FIXME: Following should not be needed, the function will be called later
// (update_mode->update_visibility->rebuild_page_tree). This does not work, during the
// second call of rebuild_page_tree m_tabctrl->GetFirstVisibleItem(); returns zero
// for some unknown reason (and the page is not refreshed until user does a selection).
rebuild_page_tree();
m_completed = true;
}
void Tab::add_scaled_button(wxWindow* parent,
ScalableButton** btn,
const std::string& icon_name,
const wxString& label/* = wxEmptyString*/,
long style /*= wxBU_EXACTFIT | wxNO_BORDER*/)
{
*btn = new ScalableButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, style, true);
(*btn)->SetBackgroundColour(parent->GetBackgroundColour());
m_scaled_buttons.push_back(*btn);
}
void Tab::add_scaled_bitmap(wxWindow* parent,
ScalableBitmap& bmp,
const std::string& icon_name)
{
bmp = ScalableBitmap(parent, icon_name);
m_scaled_bitmaps.push_back(&bmp);
}
void Tab::load_initial_data()
{
m_config = &m_presets->get_edited_preset().config;
bool has_parent = m_presets->get_selected_preset_parent() != nullptr;
m_bmp_non_system = has_parent ? &m_bmp_value_unlock : &m_bmp_white_bullet;
m_ttg_non_system = has_parent ? &m_ttg_value_unlock : &m_ttg_white_bullet_ns;
m_tt_non_system = has_parent ? &m_tt_value_unlock : &m_ttg_white_bullet_ns;
}
Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages /*= false*/)
{
// Index of icon in an icon list $self->{icons}.
auto icon_idx = 0;
if (!icon.empty()) {
icon_idx = (m_icon_index.find(icon) == m_icon_index.end()) ? -1 : m_icon_index.at(icon);
if (icon_idx == -1) {
// Add a new icon to the icon list.
m_scaled_icons_list.push_back(ScalableBitmap(this, icon, 32, false, true));
//m_icons->Add(m_scaled_icons_list.back().bmp());
icon_idx = ++m_icon_count;
m_icon_index[icon] = icon_idx;
}
if (m_category_icon.find(title) == m_category_icon.end()) {
// Add new category to the category_to_icon list.
m_category_icon[title] = icon;
}
}
// Initialize the page.
//BBS: GUI refactor
PageShp page(new Page(m_page_view, title, icon_idx, this));
// page->SetBackgroundStyle(wxBG_STYLE_SYSTEM);
#ifdef __WINDOWS__
// page->SetDoubleBuffered(true);
#endif //__WINDOWS__
if (dynamic_cast<TabPrint*>(this)) {
page->m_split_multi_line = true;
page->m_option_label_at_right = true;
}
if (!is_extruder_pages)
m_pages.push_back(page);
page->set_config(m_config);
return page;
}
// Names of categories is save in English always. We translate them only for UI.
// But category "Extruder n" can't be translated regularly (using _()), so
// just for this category we should splite the title and translate "Extruder" word separately
wxString Tab::translate_category(const wxString& title, Preset::Type preset_type)
{
if (preset_type == Preset::TYPE_PRINTER && title.Contains("Extruder ")) {
return _("Extruder") + title.SubString(8, title.Last());
}
return _(title);
}
void Tab::OnActivate()
{
//BBS: GUI refactor
//noUpdates seems not working
//wxWindowUpdateLocker noUpdates(this);
/*#ifdef __WXOSX__
// wxWindowUpdateLocker noUpdates(this);
auto size = GetSizer()->GetSize();
m_tmp_panel->GetSizer()->SetMinSize(size.x + m_size_move, size.y);
Fit();
m_size_move *= -1;
#endif // __WXOSX__*/
#ifdef __WXMSW__
// Workaround for tooltips over Tree Controls displayed over excessively long
// tree control items, stealing the window focus.
//
// In case the Tab was reparented from the MainFrame to the floating dialog,
// the tooltip created by the Tree Control before reparenting is not reparented,
// but it still points to the MainFrame. If the tooltip pops up, the MainFrame
// is incorrectly focussed, stealing focus from the floating dialog.
//
// The workaround is to delete the tooltip control.
// Vojtech tried to reparent the tooltip control, but it did not work,
// and if the Tab was later reparented back to MainFrame, the tooltip was displayed
// at an incorrect position, therefore it is safer to just discard the tooltip control
// altogether.
HWND hwnd_tt = TreeView_GetToolTips(m_tabctrl->GetHandle());
if (hwnd_tt) {
HWND hwnd_toplevel = find_toplevel_parent(m_tabctrl)->GetHandle();
HWND hwnd_parent = ::GetParent(hwnd_tt);
if (hwnd_parent != hwnd_toplevel) {
::DestroyWindow(hwnd_tt);
TreeView_SetToolTips(m_tabctrl->GetHandle(), nullptr);
}
}
#endif
// BBS: select on first active
if (!m_active_page)
restore_last_select_item();
//BBS: GUI refactor
m_page_view->Freeze();
// create controls on active page
activate_selected_page([](){});
//BBS: GUI refactor
//m_main_sizer->Layout();
m_parent->Layout();
#ifdef _MSW_DARK_MODE
// Because of DarkMode we use our own Notebook (inherited from wxSiplebook) instead of wxNotebook
// And it looks like first Layout of the page doesn't update a size of the m_presets_choice
// So we have to set correct size explicitely
/* if (wxSize ok_sz = wxSize(35 * m_em_unit, m_presets_choice->GetBestSize().y);
ok_sz != m_presets_choice->GetSize()) {
m_presets_choice->SetMinSize(ok_sz);
m_presets_choice->SetSize(ok_sz);
GetSizer()->GetItem(size_t(0))->GetSizer()->Layout();
if (wxGetApp().tabs_as_menu())
m_presets_choice->update();
}*/
#endif // _MSW_DARK_MODE
Refresh();
//BBS: GUI refactor
m_page_view->Thaw();
}
void Tab::update_label_colours()
{
m_default_text_clr = wxGetApp().get_label_clr_default();
if (m_sys_label_clr == wxGetApp().get_label_clr_sys() && m_modified_label_clr == wxGetApp().get_label_clr_modified())
return;
m_sys_label_clr = wxGetApp().get_label_clr_sys();
m_modified_label_clr = wxGetApp().get_label_clr_modified();
//update options "decoration"
for (const auto& opt : m_options_list)
{
const wxColour *color = &m_sys_label_clr;
// value isn't equal to system value
if ((opt.second & osSystemValue) == 0) {
// value is equal to last saved
if ((opt.second & osInitValue) != 0)
color = &m_default_text_clr;
// value is modified
else
color = &m_modified_label_clr;
}
if (opt.first == "printable_area" ||
opt.first == "compatible_prints" || opt.first == "compatible_printers" ) {
if (Line* line = get_line(opt.first))
line->set_label_colour(color);
continue;
}
Field* field = get_field(opt.first);
if (field == nullptr) continue;
field->set_label_colour(color);
}
auto cur_item = m_tabctrl->GetFirstVisibleItem();
if (cur_item < 0 || !m_tabctrl->IsVisible(cur_item))
return;
while (cur_item >= 0) {
auto title = m_tabctrl->GetItemText(cur_item);
for (auto page : m_pages)
{
if (translate_category(page->title(), m_type) != title)
continue;
const wxColor *clr = !page->m_is_nonsys_values ? &m_sys_label_clr :
page->m_is_modified_values ? &m_modified_label_clr :
(m_type < Preset::TYPE_COUNT ? &m_default_text_clr : &m_modified_label_clr);
m_tabctrl->SetItemTextColour(cur_item, clr == &m_modified_label_clr ? *clr : StateColor(
std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
std::make_pair(*clr, (int) StateColor::Normal)));
break;
}
cur_item = m_tabctrl->GetNextVisible(cur_item);
}
decorate();
}
void Tab::decorate()
{
for (const auto& opt : m_options_list)
{
Field* field = nullptr;
bool option_without_field = false;
if (opt.first == "printable_area" ||
opt.first == "compatible_prints" || opt.first == "compatible_printers")
option_without_field = true;
if (!option_without_field) {
field = get_field(opt.first);
if (!field)
continue;
}
bool is_nonsys_value = false;
bool is_modified_value = true;
const ScalableBitmap* sys_icon = &m_bmp_value_lock;
const ScalableBitmap* icon = &m_bmp_value_revert;
const wxColour* color = m_is_default_preset ? &m_default_text_clr : &m_sys_label_clr;
const wxString* sys_tt = &m_tt_value_lock;
const wxString* tt = &m_tt_value_revert;
// value isn't equal to system value
if ((opt.second & osSystemValue) == 0) {
is_nonsys_value = true;
sys_icon = m_bmp_non_system;
sys_tt = m_tt_non_system;
// value is equal to last saved
if ((opt.second & osInitValue) != 0)
color = &m_default_text_clr;
// value is modified
else
color = &m_modified_label_clr;
}
if ((opt.second & osInitValue) != 0)
{
is_modified_value = false;
icon = &m_bmp_white_bullet;
tt = &m_tt_white_bullet;
}
if (option_without_field) {
if (Line* line = get_line(opt.first)) {
line->set_undo_bitmap(icon);
line->set_undo_to_sys_bitmap(sys_icon);
line->set_undo_tooltip(tt);
line->set_undo_to_sys_tooltip(sys_tt);
line->set_label_colour(color);
}
continue;
}
field->m_is_nonsys_value = is_nonsys_value;
field->m_is_modified_value = is_modified_value;
field->set_undo_bitmap(icon);
//BBS: GUI refactor
field->set_undo_to_sys_bitmap(sys_icon);
field->set_undo_tooltip(tt);
field->set_undo_to_sys_tooltip(sys_tt);
field->set_label_colour(color);
if (field->has_edit_ui())
field->set_edit_bitmap(&m_bmp_edit_value);
}
if (m_active_page)
m_active_page->refresh();
}
// Update UI according to changes
void Tab::update_changed_ui()
{
if (m_postpone_update_ui)
return;
const bool deep_compare = (m_type == Slic3r::Preset::TYPE_PRINTER || m_type == Slic3r::Preset::TYPE_SLA_MATERIAL);
auto dirty_options = m_presets->current_dirty_options(deep_compare);
auto nonsys_options = m_presets->current_different_from_parent_options(deep_compare);
if (m_type == Preset::TYPE_PRINTER && static_cast<TabPrinter*>(this)->m_printer_technology == ptFFF) {
TabPrinter* tab = static_cast<TabPrinter*>(this);
if (tab->m_initial_extruders_count != tab->m_extruders_count)
dirty_options.emplace_back("extruders_count");
if (tab->m_sys_extruders_count != tab->m_extruders_count)
nonsys_options.emplace_back("extruders_count");
}
for (auto& it : m_options_list)
it.second = m_opt_status_value;
for (auto opt_key : dirty_options) m_options_list[opt_key] &= ~osInitValue;
for (auto opt_key : nonsys_options) m_options_list[opt_key] &= ~osSystemValue;
update_custom_dirty();
decorate();
wxTheApp->CallAfter([this]() {
if (parent()) //To avoid a crash, parent should be exist for a moment of a tree updating
update_changed_tree_ui();
});
// BBS:
update_undo_buttons();
}
void Tab::init_options_list()
{
if (!m_options_list.empty())
m_options_list.clear();
for (const std::string& opt_key : m_config->keys())
m_options_list.emplace(opt_key, m_opt_status_value);
}
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)
{
T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
for (size_t i = 0; i < opt_cur->values.size(); i++)
map.emplace(opt_key + "#" + std::to_string(i), value);
}
void TabPrinter::init_options_list()
{
if (!m_options_list.empty())
m_options_list.clear();
for (const std::string& opt_key : m_config->keys())
{
if (opt_key == "printable_area" || opt_key == "bed_exclude_area" | opt_key == "thumbnails") {
m_options_list.emplace(opt_key, m_opt_status_value);
continue;
}
switch (m_config->option(opt_key)->type())
{
case coInts: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;
case coBools: add_correct_opts_to_options_list<ConfigOptionBools >(opt_key, m_options_list, this, m_opt_status_value); break;
case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break;
case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break;
// BBS
case coEnums: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;
default: m_options_list.emplace(opt_key, m_opt_status_value); break;
}
}
if (m_printer_technology == ptFFF)
m_options_list.emplace("extruders_count", m_opt_status_value);
}
void TabPrinter::msw_rescale()
{
Tab::msw_rescale();
if (m_reset_to_filament_color)
m_reset_to_filament_color->msw_rescale();
//BBS: GUI refactor
//Layout();
m_parent->Layout();
}
void TabSLAMaterial::init_options_list()
{
if (!m_options_list.empty())
m_options_list.clear();
for (const std::string& opt_key : m_config->keys())
{
if (opt_key == "compatible_prints" || opt_key == "compatible_printers") {
m_options_list.emplace(opt_key, m_opt_status_value);
continue;
}
switch (m_config->option(opt_key)->type())
{
case coInts: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;
case coBools: add_correct_opts_to_options_list<ConfigOptionBools >(opt_key, m_options_list, this, m_opt_status_value); break;
case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break;
case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break;
// BBS
case coEnums: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;
default: m_options_list.emplace(opt_key, m_opt_status_value); break;
}
}
}
void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page)
{
auto opt = m_options_list.find(opt_key);
if (opt == m_options_list.end())
return;
if (sys_page) sys_page = (opt->second & osSystemValue) != 0;
modified_page |= (opt->second & osInitValue) == 0;
}
void Tab::update_changed_tree_ui()
{
if (m_options_list.empty()) {
if (m_type == Preset::Type::TYPE_PLATE) {
for (auto page : m_pages) {
page->m_is_nonsys_values = false;
}
}
return;
}
auto cur_item = m_tabctrl->GetFirstVisibleItem();
if (cur_item < 0 || !m_tabctrl->IsVisible(cur_item))
return;
auto selected_item = m_tabctrl->GetSelection();
auto selection = selected_item >= 0 ? m_tabctrl->GetItemText(selected_item) : "";
while (cur_item >= 0) {
auto title = m_tabctrl->GetItemText(cur_item);
for (auto page : m_pages)
{
if (translate_category(page->title(), m_type) != title)
continue;
bool sys_page = true;
bool modified_page = false;
if (page->title() == "General") {
std::initializer_list<const char*> optional_keys{ "extruders_count", "printable_area" };
for (auto &opt_key : optional_keys) {
get_sys_and_mod_flags(opt_key, sys_page, modified_page);
}