-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathGUI_ObjectList.cpp
More file actions
8433 lines (7064 loc) · 329 KB
/
GUI_ObjectList.cpp
File metadata and controls
8433 lines (7064 loc) · 329 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 "libslic3r/libslic3r.h"
#include "libslic3r/PresetBundle.hpp"
#include "GUI_ObjectList.hpp"
#include "GUI_Factories.hpp"
// #include "GUI_ObjectLayers.hpp"
#include "GUI_App.hpp"
#include "UITour.hpp"
#include "I18N.hpp"
#include "Plater.hpp"
#include "BitmapComboBox.hpp"
#include "MainFrame.hpp"
#include "slic3r/Utils/UndoRedo.hpp"
#include "OptionsGroup.hpp"
#include "Tab.hpp"
#include "wxExtensions.hpp"
#include "libslic3r/Model.hpp"
#include "GLCanvas3D.hpp"
#include "Selection.hpp"
#include "PartPlate.hpp"
#include "format.hpp"
#include "NotificationManager.hpp"
#include "MsgDialog.hpp"
#include "Widgets/ProgressDialog.hpp"
#include "SingleChoiceDialog.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <wx/progdlg.h>
#include <wx/listbook.h>
#include <wx/numformatter.h>
#include <wx/headerctrl.h>
#include <GL/glew.h>
#include "slic3r/Utils/FixModelByWin10.hpp"
#include "libslic3r/Format/bbs_3mf.hpp"
#include "libslic3r/PrintConfig.hpp"
#ifdef __WXMSW__
#include "wx/uiaction.h"
#include <wx/renderer.h>
#endif /* __WXMSW__ */
#include "Gizmos/GLGizmoScale.hpp"
#include "PhysicalPrinterDialog.hpp"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui/imgui_internal.h>
#include "slic3r/Config/DispConfig.h"
#include "print_manage/data/DataCenter.hpp"
#include "GLTexture.hpp"
#include "print_manage/Utils.hpp"
#include "libslic3r/ModelVolume.hpp"
#include "libslic3r/ModelInstance.hpp"
namespace Slic3r
{
namespace GUI
{
wxDEFINE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
wxDEFINE_EVENT(EVT_OBJ_LIST_COLUMN_SELECT, IntEvent);
wxDEFINE_EVENT(EVT_PARTPLATE_LIST_PLATE_SELECT, IntEvent);
wxDEFINE_EVENT(EVT_UPDATE_DEVICES, wxCommandEvent);
static PrinterTechnology printer_technology() { return wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology(); }
static const Selection& scene_selection()
{
// BBS AssembleView canvas has its own selection
if (wxGetApp().plater()->get_current_canvas3D()->get_canvas_type() == GLCanvas3D::ECanvasType::CanvasAssembleView)
return wxGetApp().plater()->get_assmeble_canvas3D()->get_selection();
return wxGetApp().plater()->get_view3D_canvas3D()->get_selection();
}
// Config from current edited printer preset
static DynamicPrintConfig& printer_config() { return wxGetApp().preset_bundle->printers.get_edited_preset().config; }
static int filaments_count() { return wxGetApp().filaments_cnt(); }
static void take_snapshot(const std::string& snapshot_name)
{
Plater* plater = wxGetApp().plater();
if (plater)
plater->take_snapshot(snapshot_name);
}
class wxRenderer : public wxDelegateRendererNative
{
public:
wxRenderer() : wxDelegateRendererNative(wxRendererNative::Get()) {}
virtual void DrawItemSelectionRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) wxOVERRIDE
{
GetGeneric().DrawItemSelectionRect(win, dc, rect, flags);
}
};
ObjectList::ObjectList(wxWindow* parent) : wxDataViewCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE)
{
wxGetApp().UpdateDVCDarkUI(this, true);
#ifdef __linux__
// Temporary fix for incorrect dark mode application regarding list item's text color.
// See: https://github.com/SoftFever/CrealityPrint/issues/2086
this->SetForegroundColour(*wxBLACK);
#endif
SetFont(Label::sysFont(13));
#ifdef __WXMSW__
GenericGetHeader()->SetFont(Label::sysFont(13));
static auto render = new wxRenderer;
wxRendererNative::Set(render);
#endif
// create control
create_objects_ctrl();
m_device_list_data.set_object_list(this);
m_png_textures.reset(new ObjList_Png_Texture_Wrapper);
//BBS: add part plate related event
//Bind(EVT_PARTPLATE_LIST_PLATE_SELECT, &ObjectList::on_select_plate, this);
// describe control behavior
Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent& event) {
// detect the current mouse position here, to pass it to list_manipulation() method
// if we detect it later, the user may have moved the mouse pointer while calculations are performed, and this would mess-up the
// HitTest() call performed into list_manipulation()
if (!GetScreenRect().Contains(wxGetMousePosition())) {
return;
}
#ifndef __WXOSX__
const wxPoint mouse_pos = this->get_mouse_position_in_control();
#endif
#ifndef __APPLE__
// On Windows and Linux:
// It's not invoked KillFocus event for "temporary" panels (like "Manipulation panel", "Settings", "Layer ranges"),
// if we change selection in object list.
// But, if we call SetFocus() for ObjectList it will cause an invoking of a KillFocus event for "temporary" panels
this->SetFocus();
#else
// To avoid selection update from SetSelection() and UnselectAll() under osx
if (m_prevent_list_events)
return;
#endif // __APPLE__
/* For multiple selection with pressed SHIFT,
* event.GetItem() returns value of a first item in selection list
* instead of real last clicked item.
* So, let check last selected item in such strange way
*/
#ifdef __WXMSW__
// Workaround for entering the column editing mode on Windows. Simulate keyboard enter when another column of the active line is selected.
int new_selected_column = -1;
#endif //__WXMSW__
if (wxGetKeyState(WXK_SHIFT)) {
wxDataViewItemArray sels;
GetSelections(sels);
if (!sels.empty() && sels.front() == m_last_selected_item)
m_last_selected_item = sels.back();
else
m_last_selected_item = event.GetItem();
} else {
wxDataViewItem new_selected_item = event.GetItem();
// BBS: use wxDataViewCtrl's internal mechanism
#if 0
#ifdef __WXMSW__
// Workaround for entering the column editing mode on Windows. Simulate keyboard enter when another column of the active line is selected.
wxDataViewItem item;
wxDataViewColumn *col;
this->HitTest(this->get_mouse_position_in_control(), item, col);
new_selected_column = (col == nullptr) ? -1 : (int)col->GetModelColumn();
if (new_selected_item == m_last_selected_item && m_last_selected_column != -1 && m_last_selected_column != new_selected_column) {
// Mouse clicked on another column of the active row. Simulate keyboard enter to enter the editing mode of the current column.
wxUIActionSimulator sim;
sim.Char(WXK_RETURN);
}
#endif //__WXMSW__
#endif
m_last_selected_item = new_selected_item;
}
#ifdef __WXMSW__
m_last_selected_column = new_selected_column;
#endif //__WXMSW__
ObjectDataViewModelNode* sel_node = (ObjectDataViewModelNode*) event.GetItem().GetID();
if (sel_node && (sel_node->GetType() & ItemType::itPlate)) {
if (wxGetApp().plater()->is_preview_shown()) {
wxGetApp().plater()->select_sliced_plate(sel_node->GetPlateIdx());
} else {
wxGetApp().plater()->select_plate(sel_node->GetPlateIdx());
}
wxGetApp().plater()->deselect_all();
} else {
selection_changed();
}
#ifndef __WXMSW__
set_tooltip_for_item(this->get_mouse_position_in_control());
#endif //__WXMSW__
#ifndef __WXOSX__
list_manipulation(mouse_pos);
#endif //__WXOSX__
});
#ifdef __WXOSX__
// Key events are not correctly processed by the wxDataViewCtrl on OSX.
// Our patched wxWidgets process the keyboard accelerators.
// On the other hand, using accelerators will break in-place editing on Windows & Linux/GTK (there is no in-place editing working on OSX
// for wxDataViewCtrl for now).
// Bind(wxEVT_KEY_DOWN, &ObjectList::OnChar, this);
{
// Accelerators
// wxAcceleratorEntry entries[25];
wxAcceleratorEntry entries[26];
int index = 0;
entries[index++].Set(wxACCEL_CTRL, (int) 'C', wxID_COPY);
entries[index++].Set(wxACCEL_CTRL, (int) 'X', wxID_CUT);
entries[index++].Set(wxACCEL_CTRL, (int) 'V', wxID_PASTE);
entries[index++].Set(wxACCEL_CTRL, (int) 'M', wxID_DUPLICATE);
entries[index++].Set(wxACCEL_CTRL, (int) 'A', wxID_SELECTALL);
entries[index++].Set(wxACCEL_CTRL, (int) 'Z', wxID_UNDO);
entries[index++].Set(wxACCEL_CTRL, (int) 'Y', wxID_REDO);
entries[index++].Set(wxACCEL_NORMAL, WXK_BACK, wxID_DELETE);
// entries[index++].Set(wxACCEL_NORMAL, int('+'), wxID_ADD);
// entries[index++].Set(wxACCEL_NORMAL, WXK_NUMPAD_ADD, wxID_ADD);
// entries[index++].Set(wxACCEL_NORMAL, int('-'), wxID_REMOVE);
// entries[index++].Set(wxACCEL_NORMAL, WXK_NUMPAD_SUBTRACT, wxID_REMOVE);
// entries[index++].Set(wxACCEL_NORMAL, int('p'), wxID_PRINT);
int numbers_cnt = 0;
for (auto char_number : {'1', '2', '3', '4', '5', '6', '7', '8', '9'}) {
entries[index + numbers_cnt].Set(wxACCEL_NORMAL, int(char_number), wxID_LAST + numbers_cnt + 1);
entries[index + 9 + numbers_cnt].Set(wxACCEL_NORMAL, WXK_NUMPAD0 + numbers_cnt - 1, wxID_LAST + numbers_cnt + 1);
numbers_cnt++;
// index++;
}
wxAcceleratorTable accel(26, entries);
SetAcceleratorTable(accel);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->copy(); }, wxID_COPY);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->paste(); }, wxID_PASTE);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->select_item_all_children(); }, wxID_SELECTALL);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->remove(); }, wxID_DELETE);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->undo(); }, wxID_UNDO);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->redo(); }, wxID_REDO);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->cut(); }, wxID_CUT);
this->Bind(wxEVT_MENU, [this](wxCommandEvent& evt) { this->clone(); }, wxID_DUPLICATE);
// this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->increase_instances(); }, wxID_ADD);
// this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->decrease_instances(); }, wxID_REMOVE);
// this->Bind(wxEVT_MENU, [this](wxCommandEvent &evt) { this->toggle_printable_state(); }, wxID_PRINT);
for (int i = 1; i < 10; i++)
this->Bind(
wxEVT_MENU,
[this, i](wxCommandEvent& evt) {
if (filaments_count() > 1 && i <= filaments_count())
this->set_extruder_for_selected_items(i);
},
wxID_LAST + i);
m_accel = accel;
}
#else //__WXOSX__
Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { key_event(event); }); // doesn't work on OSX
#endif
#ifdef __WXMSW__
GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) {
// BBS
// this->SetFocus();
set_tooltip_for_item(this->get_mouse_position_in_control());
event.Skip();
});
#endif //__WXMSW__
Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &ObjectList::OnContextMenu, this);
// BBS
Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &ObjectList::OnBeginDrag, this);
Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, &ObjectList::OnDropPossible, this);
Bind(wxEVT_DATAVIEW_ITEM_DROP, &ObjectList::OnDrop, this);
Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &ObjectList::OnStartEditing, this);
Bind(wxEVT_DATAVIEW_ITEM_EDITING_STARTED, &ObjectList::OnEditingStarted, this);
Bind(wxEVT_DATAVIEW_ITEM_EDITING_DONE, &ObjectList::OnEditingDone, this);
Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &ObjectList::ItemValueChanged, this);
// BBS: dont need to do extra setting for a deleted object
// Bind(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, [this](wxCommandEvent& e) { last_volume_is_deleted(e.GetInt()); });
Bind(wxEVT_SIZE, ([this](wxSizeEvent& e) {
if (m_last_size == this->GetSize()) {
e.Skip();
return;
} else {
m_last_size = this->GetSize();
}
#ifdef __WXGTK__
// On GTK, the EnsureVisible call is postponed to Idle processing (see wxDataViewCtrl::m_ensureVisibleDefered).
// So the postponed EnsureVisible() call is planned for an item, which may not exist at the Idle processing time, if this
// wxEVT_SIZE event is succeeded by a delete of the currently active item. We are trying our luck by postponing the wxEVT_SIZE
// triggered EnsureVisible(), which seems to be working as of now.
this->CallAfter([this]() { ensure_current_item_visible(); });
#else
update_name_column_width();
// BBS
this->CallAfter([this]() { ensure_current_item_visible(); });
#endif
e.Skip();
}));
Bind(EVT_OBJ_LIST_COLUMN_SELECT, [this](IntEvent& event) {
int type = event.get_data();
if (type == 0) {
show_context_menu(true);
} else if (type == ObjList_Texture::IM_TEXTURE_NAME::texSupportPainting) {
GLGizmosManager& gizmos_mgr = wxGetApp().plater()->get_view3D_canvas3D()->get_gizmos_manager();
if (gizmos_mgr.get_current_type() != GLGizmosManager::EType::FdmSupports)
gizmos_mgr.open_gizmo(GLGizmosManager::EType::FdmSupports);
else
gizmos_mgr.reset_all_states();
} else if (type == ObjList_Texture::IM_TEXTURE_NAME::texColorPainting) {
GLGizmosManager& gizmos_mgr = wxGetApp().plater()->get_view3D_canvas3D()->get_gizmos_manager();
if (gizmos_mgr.get_current_type() != GLGizmosManager::EType::MmuSegmentation)
gizmos_mgr.open_gizmo(GLGizmosManager::EType::MmuSegmentation);
else
gizmos_mgr.reset_all_states();
}
});
Bind(EVT_UPDATE_DEVICES, [this](wxCommandEvent& evt) {
// mark to update device list
m_device_list_dirty_mark = true;
if (m_device_list_popup_opened) {
wxGetApp().plater()->get_view3D_canvas3D()->render();
}
});
m_last_size = this->GetSize();
}
ObjectList::~ObjectList()
{
if (m_objects_model)
m_objects_model->DecRef();
m_png_textures.reset();
}
bool ObjectList::ObjList_Texture::init_svg_texture()
{
bool is_dark = wxGetApp().dark_mode();
std::string svg = is_dark ? "/images/obj_list_integrate_icon_dark.svg" : "/images/obj_list_integrate_icon_light.svg";
if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + svg, texCount * 20, 40, m_texture_id)) {
m_valid = true;
} else {
m_valid = false;
}
return m_valid;
}
void ObjectList::set_min_height()
{
// BBS
#if 0
if (m_items_count == size_t(-1))
m_items_count = 7;
int list_min_height = lround(2.25 * (m_items_count + 1) * wxGetApp().em_unit()); // +1 is for height of control header
this->SetMinSize(wxSize(1, list_min_height));
#endif
}
void ObjectList::update_min_height()
{
wxDataViewItemArray all_items;
m_objects_model->GetAllChildren(wxDataViewItem(nullptr), all_items);
size_t items_cnt = all_items.Count();
#if 0
if (items_cnt < 7)
items_cnt = 7;
else if (items_cnt >= 15)
items_cnt = 15;
#else
items_cnt = 8;
#endif
if (m_items_count == items_cnt)
return;
m_items_count = items_cnt;
set_min_height();
}
void ObjectList::create_objects_ctrl()
{
// BBS
#if 0
/* Temporary workaround for the correct behavior of the Scrolled sidebar panel:
* 1. set a height of the list to some big value
* 2. change it to the normal(meaningful) min value after first whole Mainframe updating/layouting
*/
SetMinSize(wxSize(-1, 3000));
#endif
m_objects_model = new ObjectDataViewModel;
AssociateModel(m_objects_model);
m_objects_model->SetAssociatedControl(this);
#if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
EnableDragSource(wxDF_UNICODETEXT);
EnableDropTarget(wxDF_UNICODETEXT);
#endif // wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
const int em = wxGetApp().em_unit();
m_columns_width.resize(colCount);
m_columns_width[colName] = 22;
m_columns_width[colPrint] = 3;
m_columns_width[colFilament] = 5;
m_columns_width[colSupportPaint] = 3;
m_columns_width[colSinking] = 3;
m_columns_width[colColorPaint] = 3;
m_columns_width[colEditing] = 3;
// column ItemName(Icon+Text) of the view control:
// And Icon can be consisting of several bitmaps
BitmapTextRenderer* bmp_text_renderer = new BitmapTextRenderer();
bmp_text_renderer->set_can_create_editor_ctrl_function([this]() {
auto type = m_objects_model->GetItemType(GetSelection());
return type & (itVolume | itObject | itPlate);
});
// BBS
wxDataViewColumn* name_col = new wxDataViewColumn(_L("Name"), bmp_text_renderer, colName, m_columns_width[colName] * em, wxALIGN_LEFT,
wxDATAVIEW_COL_RESIZABLE);
// name_col->SetBitmap(create_scaled_bitmap("organize", nullptr, FromDIP(18)));
AppendColumn(name_col);
// column PrintableProperty (Icon) of the view control:
AppendBitmapColumn(" ", colPrint, wxOSX ? wxDATAVIEW_CELL_EDITABLE : wxDATAVIEW_CELL_INERT, 3 * em, wxALIGN_CENTER_HORIZONTAL, 0);
// column Extruder of the view control:
BitmapChoiceRenderer* bmp_choice_renderer = new BitmapChoiceRenderer();
bmp_choice_renderer->set_can_create_editor_ctrl_function(
[this]() { return m_objects_model->GetItemType(GetSelection()) & (itVolume | itLayer | itObject); });
bmp_choice_renderer->set_default_extruder_idx([this]() { return m_objects_model->GetDefaultExtruderIdx(GetSelection()); });
bmp_choice_renderer->set_has_default_extruder([this]() {
return m_objects_model->GetVolumeType(GetSelection()) == ModelVolumeType::PARAMETER_MODIFIER ||
m_objects_model->GetItemType(GetSelection()) == itLayer;
});
AppendColumn(new wxDataViewColumn(_L("Fila."), bmp_choice_renderer, colFilament, m_columns_width[colFilament] * em,
wxALIGN_CENTER_HORIZONTAL, 0));
// BBS
AppendBitmapColumn(" ", colSupportPaint, wxOSX ? wxDATAVIEW_CELL_EDITABLE : wxDATAVIEW_CELL_INERT,
m_columns_width[colSupportPaint] * em, wxALIGN_CENTER_HORIZONTAL, 0);
AppendBitmapColumn(" ", colColorPaint, wxOSX ? wxDATAVIEW_CELL_EDITABLE : wxDATAVIEW_CELL_INERT, m_columns_width[colColorPaint] * em,
wxALIGN_CENTER_HORIZONTAL, 0);
AppendBitmapColumn(" ", colSinking, wxOSX ? wxDATAVIEW_CELL_EDITABLE : wxDATAVIEW_CELL_INERT, m_columns_width[colSinking] * em,
wxALIGN_CENTER_HORIZONTAL, 0);
// column ItemEditing of the view control:
AppendBitmapColumn(" ", colEditing, wxOSX ? wxDATAVIEW_CELL_EDITABLE : wxDATAVIEW_CELL_INERT, m_columns_width[colEditing] * em,
wxALIGN_CENTER_HORIZONTAL, 0);
// for (int cn = colName; cn < colCount; cn++) {
// GetColumn(cn)->SetResizeable(cn == colName);
// }
// For some reason under OSX on 4K(5K) monitors in wxDataViewColumn constructor doesn't set width of column.
// Therefore, force set column width.
if (wxOSX) {
for (int cn = colName; cn < colCount; cn++)
GetColumn(cn)->SetWidth(m_columns_width[cn] * em);
}
}
void ObjectList::get_selected_item_indexes(int& obj_idx, int& vol_idx, const wxDataViewItem& input_item /* = wxDataViewItem(nullptr)*/)
{
const wxDataViewItem item = input_item == wxDataViewItem(nullptr) ? GetSelection() : input_item;
if (!item) {
obj_idx = vol_idx = -1;
return;
}
const ItemType type = m_objects_model->GetItemType(item);
obj_idx = type & itObject ? m_objects_model->GetIdByItem(item) :
type & itVolume ? m_objects_model->GetIdByItem(m_objects_model->GetObject(item)) :
-1;
vol_idx = type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1;
}
void ObjectList::get_selection_indexes(std::vector<int>& obj_idxs, std::vector<int>& vol_idxs)
{
wxDataViewItemArray sels;
GetSelections(sels);
if (sels.IsEmpty())
return;
if (m_objects_model->GetItemType(sels[0]) & itVolume ||
(sels.Count() == 1 && m_objects_model->GetItemType(m_objects_model->GetParent(sels[0])) & itVolume)) {
for (wxDataViewItem item : sels) {
obj_idxs.emplace_back(m_objects_model->GetIdByItem(m_objects_model->GetObject(item)));
if (sels.Count() == 1 && m_objects_model->GetItemType(m_objects_model->GetParent(item)) & itVolume)
item = m_objects_model->GetParent(item);
assert(m_objects_model->GetItemType(item) & itVolume);
vol_idxs.emplace_back(m_objects_model->GetVolumeIdByItem(item));
}
} else {
for (wxDataViewItem item : sels) {
const ItemType type = m_objects_model->GetItemType(item);
obj_idxs.emplace_back(type & itObject ? m_objects_model->GetIdByItem(item) :
m_objects_model->GetIdByItem(m_objects_model->GetObject(item)));
}
}
std::sort(obj_idxs.begin(), obj_idxs.end(), std::less<int>());
obj_idxs.erase(std::unique(obj_idxs.begin(), obj_idxs.end()), obj_idxs.end());
}
int ObjectList::get_repaired_errors_count(const int obj_idx, const int vol_idx /*= -1*/) const
{
return obj_idx >= 0 ? (*m_objects)[obj_idx]->get_repaired_errors_count(vol_idx) : 0;
}
static std::string get_warning_icon_name(const TriangleMeshStats& stats)
{
return stats.manifold() ? (stats.repaired() ? "obj_warning" : "") : "obj_warning";
}
MeshErrorsInfo ObjectList::get_mesh_errors_info(const int obj_idx,
const int vol_idx /*= -1*/,
wxString* sidebar_info /*= nullptr*/,
int* non_manifold_edges) const
{
if (obj_idx < 0)
return {{}, {}}; // hide tooltip
if (m_objects->size() <= obj_idx)
return {{}, {}}; // hide tooltip
const TriangleMeshStats& stats = vol_idx == -1 ? (*m_objects)[obj_idx]->get_object_stl_stats() :
(*m_objects)[obj_idx]->volumes[vol_idx]->mesh().stats();
if (!stats.repaired() && stats.manifold()) {
// if (sidebar_info)
// *sidebar_info = _L("No errors");
return {{}, {}}; // hide tooltip
}
wxString tooltip, auto_repaired_info, remaining_info;
// Create tooltip string, if there are errors
if (stats.repaired()) {
const int errors = get_repaired_errors_count(obj_idx, vol_idx);
auto_repaired_info = format_wxstr(_L_PLURAL("%1$d error repaired", "%1$d errors repaired", errors), errors);
tooltip += auto_repaired_info + "\n";
}
if (!stats.manifold()) {
remaining_info = format_wxstr(_L_PLURAL("Error: %1$d non-manifold edge.", "Error: %1$d non-manifold edges.", stats.open_edges),
stats.open_edges);
tooltip += _L("Remaining errors") + ":\n";
tooltip += "\t" + format_wxstr(_L_PLURAL("%1$d non-manifold edge", "%1$d non-manifold edges", stats.open_edges), stats.open_edges) +
"\n";
}
if (sidebar_info) {
*sidebar_info = stats.manifold() ? auto_repaired_info : (remaining_info + (stats.repaired() ? ("\n" + auto_repaired_info) : ""));
}
if (non_manifold_edges)
*non_manifold_edges = stats.open_edges;
if (is_windows10() && !sidebar_info)
tooltip += "\n" + _L("Left click the icon to fix model object");
return {tooltip, get_warning_icon_name(stats)};
}
MeshErrorsInfo ObjectList::get_mesh_errors_info(wxString* sidebar_info /*= nullptr*/, int* non_manifold_edges)
{
wxDataViewItem item = GetSelection();
if (!item)
return {"", ""};
int obj_idx, vol_idx;
get_selected_item_indexes(obj_idx, vol_idx);
if (obj_idx < 0) { // child of ObjectItem is selected
if (sidebar_info)
obj_idx = m_objects_model->GetObjectIdByItem(item);
else
return {"", ""};
}
if (obj_idx < 0) {
return {"", ""};
}
// assert(obj_idx >= 0);
return get_mesh_errors_info(obj_idx, vol_idx, sidebar_info, non_manifold_edges);
}
void ObjectList::set_tooltip_for_item(const wxPoint& pt)
{
wxDataViewItem item;
wxDataViewColumn* col;
HitTest(pt, item, col);
/* GetMainWindow() return window, associated with wxDataViewCtrl.
* And for this window we should to set tooltips.
* Just this->SetToolTip(tooltip) => has no effect.
*/
if (!item || GetSelectedItemsCount() > 1) {
GetMainWindow()->SetToolTip(""); // hide tooltip
return;
}
wxString tooltip = "";
ObjectDataViewModelNode* node = (ObjectDataViewModelNode*) item.GetID();
if (col->GetModelColumn() == (unsigned int) colEditing) {
if (node->IsActionEnabled())
#ifdef __WXOSX__
tooltip = _(L("Right button click the icon to drop the object settings"));
#else
tooltip = _(L("Click the icon to reset all settings of the object"));
#endif //__WXMSW__
} else if (col->GetModelColumn() == (unsigned int) colPrint)
#ifdef __WXOSX__
tooltip = _(L("Right button click the icon to drop the object printable property"));
#else
tooltip = _(L("Click the icon to toggle printable property of the object"));
#endif //__WXMSW__
// BBS
else if (col->GetModelColumn() == (unsigned int) colSupportPaint) {
if (node->HasSupportPainting())
tooltip = _(L("Click the icon to edit support painting of the object"));
} else if (col->GetModelColumn() == (unsigned int) colColorPaint) {
if (node->HasColorPainting())
tooltip = _(L("Click the icon to edit color painting of the object"));
} else if (col->GetModelColumn() == (unsigned int) colSinking) {
if (node->HasSinking())
tooltip = _(L("Click the icon to shift this object to the bed"));
} else if (col->GetModelColumn() == (unsigned int) colName && (pt.x >= 2 * wxGetApp().em_unit() && pt.x <= 4 * wxGetApp().em_unit())) {
if (const ItemType type = m_objects_model->GetItemType(item); type & (itObject | itVolume)) {
int obj_idx = m_objects_model->GetObjectIdByItem(item);
int vol_idx = type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1;
tooltip = get_mesh_errors_info(obj_idx, vol_idx).tooltip;
}
}
GetMainWindow()->SetToolTip(tooltip);
}
int ObjectList::get_selected_obj_idx() const
{
if (GetSelectedItemsCount() == 1)
return m_objects_model->GetIdByItem(m_objects_model->GetObject(GetSelection()));
return -1;
}
ModelConfig& ObjectList::get_item_config(const wxDataViewItem& item) const
{
static ModelConfig s_empty_config;
assert(item);
const ItemType type = m_objects_model->GetItemType(item);
if (type & itPlate)
return s_empty_config;
const int obj_idx = m_objects_model->GetObjectIdByItem(item);
const int vol_idx = type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1;
assert(obj_idx >= 0 || ((type & itVolume) && vol_idx >= 0));
return type & itVolume ? (*m_objects)[obj_idx]->volumes[vol_idx]->config :
type & itLayer ? (*m_objects)[obj_idx]->layer_config_ranges[m_objects_model->GetLayerRangeByItem(item)] :
(*m_objects)[obj_idx]->config;
}
void ObjectList::update_filament_values_for_items(const size_t filaments_count)
{
for (size_t i = 0; i < m_objects->size(); ++i) {
wxDataViewItem item = m_objects_model->GetItemById(i);
if (!item)
continue;
auto object = (*m_objects)[i];
wxString extruder;
if (!object->config.has("extruder") || size_t(object->config.extruder()) > filaments_count) {
extruder = "1";
object->config.set_key_value("extruder", new ConfigOptionInt(1));
} else {
extruder = wxString::Format("%d", object->config.extruder());
}
m_objects_model->SetExtruder(extruder, item);
static const char* keys[] = {"support_filament", "support_interface_filament"};
for (auto key : keys)
if (object->config.has(key) && object->config.opt_int(key) > filaments_count)
object->config.erase(key);
if (object->volumes.size() > 1) {
for (size_t id = 0; id < object->volumes.size(); id++) {
item = m_objects_model->GetItemByVolumeId(i, id);
if (!item)
continue;
if (!object->volumes[id]->config.has("extruder") || size_t(object->volumes[id]->config.extruder()) > filaments_count) {
extruder = wxString::Format("%d", object->config.extruder());
} else {
extruder = wxString::Format("%d", object->volumes[id]->config.extruder());
}
m_objects_model->SetExtruder(extruder, item);
for (auto key : keys)
if (object->volumes[id]->config.has(key) && object->volumes[id]->config.opt_int(key) > filaments_count)
object->volumes[id]->config.erase(key);
}
}
}
// BBS
wxGetApp().plater()->update();
}
void ObjectList::update_filament_values_for_items_when_delete_filament(const size_t filament_id, const int replace_id)
{
int replace_filament_id = replace_id == -1 ? 1 : (replace_id + 1);
for (size_t i = 0; i < m_objects->size(); ++i) {
wxDataViewItem item = m_objects_model->GetItemById(i);
if (!item)
continue;
auto object = (*m_objects)[i];
wxString extruder;
if (!object->config.has("extruder")) {
extruder = std::to_string(1);
object->config.set_key_value("extruder", new ConfigOptionInt(1));
} else if (size_t(object->config.extruder()) == filament_id + 1) {
extruder = std::to_string(replace_filament_id);
object->config.set_key_value("extruder", new ConfigOptionInt(replace_filament_id));
} else {
int new_extruder = object->config.extruder() > filament_id ? object->config.extruder() - 1 : object->config.extruder();
extruder = wxString::Format("%d", new_extruder);
object->config.set_key_value("extruder", new ConfigOptionInt(new_extruder));
}
m_objects_model->SetExtruder(extruder, item);
static const char* keys[] = {"support_filament", "support_interface_filament"};
for (auto key : keys) {
if (object->config.has(key)) {
if (object->config.opt_int(key) == filament_id + 1)
object->config.erase(key);
else {
int new_value = object->config.opt_int(key) > filament_id ? object->config.opt_int(key) - 1 :
object->config.opt_int(key);
object->config.set_key_value(key, new ConfigOptionInt(new_value));
}
}
}
// if (object->volumes.size() > 1) {
for (size_t id = 0; id < object->volumes.size(); id++) {
item = m_objects_model->GetItemByVolumeId(i, id);
if (!item)
continue;
for (auto key : keys) {
if (object->volumes[id]->config.has(key)) {
if (object->volumes[id]->config.opt_int(key) == filament_id + 1)
object->volumes[id]->config.erase(key);
else {
int new_value = object->volumes[id]->config.opt_int(key) > filament_id ?
object->volumes[id]->config.opt_int(key) - 1 :
object->volumes[id]->config.opt_int(key);
object->config.set_key_value(key, new ConfigOptionInt(new_value));
}
}
}
if (!object->volumes[id]->config.has("extruder")) {
continue;
} else if (size_t(object->volumes[id]->config.extruder()) == filament_id + 1) {
object->volumes[id]->config.set_key_value("extruder", new ConfigOptionInt(replace_filament_id));
} else {
int new_extruder = object->volumes[id]->config.extruder() > filament_id ? object->volumes[id]->config.extruder() - 1 :
object->volumes[id]->config.extruder();
extruder = wxString::Format("%d", new_extruder);
object->volumes[id]->config.set_key_value("extruder", new ConfigOptionInt(new_extruder));
}
m_objects_model->SetExtruder(extruder, item);
}
//}
item = m_objects_model->GetItemById(i);
ObjectDataViewModelNode* object_node = static_cast<ObjectDataViewModelNode*>(item.GetID());
if (object_node->GetChildCount() == 0)
continue;
// update height_range
for (size_t i = 0; i < object_node->GetChildCount(); i++) {
ObjectDataViewModelNode* layer_root_node = object_node->GetNthChild(i);
if (layer_root_node->GetType() != ItemType::itLayerRoot)
continue;
for (size_t j = 0; j < layer_root_node->GetChildCount(); j++) {
ObjectDataViewModelNode* layer_node = layer_root_node->GetNthChild(j);
auto layer_item = wxDataViewItem((void*) layer_root_node->GetNthChild(j));
if (!layer_item)
continue;
auto l_iter = object->layer_config_ranges.find(layer_node->GetLayerRange());
if (l_iter != object->layer_config_ranges.end()) {
auto& layer_range_item = *(l_iter);
if (layer_range_item.second.has("extruder") && layer_range_item.second.option("extruder")->getInt() == filament_id + 1) {
int new_extruder = replace_id == -1 ? 0 : (replace_id + 1);
extruder = new_extruder <= 1 ? _(L("default")) : wxString::Format("%d", new_extruder);
layer_range_item.second.set("extruder", new_extruder);
} else {
int layer_filament_id = layer_range_item.second.option("extruder")->getInt();
int new_extruder = layer_filament_id > filament_id ? layer_filament_id - 1 : layer_filament_id;
extruder = new_extruder <= 1 ? _(L("default")) : wxString::Format("%d", new_extruder);
layer_range_item.second.set("extruder", new_extruder);
}
m_objects_model->SetExtruder(extruder, layer_item);
}
}
}
}
// BBS
wxGetApp().plater()->update();
}
void ObjectList::update_plate_values_for_items()
{
#ifdef __WXOSX__
AssociateModel(nullptr);
#endif
PartPlateList& list = wxGetApp().plater()->get_partplate_list();
for (size_t i = 0; i < m_objects->size(); ++i) {
wxDataViewItem item = m_objects_model->GetItemById(i);
if (!item)
continue;
int plate_idx = list.find_instance_belongs(i, 0);
wxDataViewItem old_parent = m_objects_model->GetParent(item);
ObjectDataViewModelNode* old_parent_node = (ObjectDataViewModelNode*) old_parent.GetID();
int old_plate_idx = old_parent_node->GetPlateIdx();
if (plate_idx == old_plate_idx)
continue;
// hotfix for wxDataViewCtrl selection not updated after wxDataViewModel::ItemDeleted()
Unselect(item);
bool is_old_parent_expanded = IsExpanded(old_parent);
bool is_expanded = IsExpanded(item);
m_objects_model->OnPlateChange(plate_idx, item);
if (is_old_parent_expanded)
Expand(old_parent);
ExpandAncestors(item);
Expand(item);
Select(item);
}
#ifdef __WXOSX__
AssociateModel(m_objects_model);
#endif
}
// BBS
void ObjectList::update_name_for_items()
{
m_objects_model->UpdateItemNames();
wxGetApp().plater()->update();
}
void ObjectList::object_config_options_changed(const ObjectVolumeID& ov_id)
{
if (ov_id.object == nullptr)
return;
ModelObjectPtrs& objects = wxGetApp().model().objects;
ModelObject* mo = ov_id.object;
ModelVolume* mv = ov_id.volume;
wxDataViewItem obj_item = m_objects_model->GetObjectItem(mo);
if (mv != nullptr) {
size_t vol_idx;
for (vol_idx = 0; vol_idx < mo->volumes.size(); vol_idx++) {
if (mo->volumes[vol_idx] == mv)
break;
}
assert(vol_idx < mo->volumes.size());
SettingsFactory::Bundle cat_options = SettingsFactory::get_bundle(&mv->config.get(), false);
wxDataViewItem vol_item = m_objects_model->GetVolumeItem(obj_item, vol_idx);
if (cat_options.size() > 0) {
add_settings_item(vol_item, &mv->config.get());
} else {
m_objects_model->DeleteSettings(vol_item);
}
} else {
SettingsFactory::Bundle cat_options = SettingsFactory::get_bundle(&mo->config.get(), true);
if (cat_options.size() > 0) {
add_settings_item(obj_item, &mo->config.get());
} else {
m_objects_model->DeleteSettings(obj_item);
}
}
}
void ObjectList::printable_state_changed(const std::vector<ObjectVolumeID>& ov_ids)
{
std::vector<size_t> obj_idxs;
for (const ObjectVolumeID ov_id : ov_ids) {
if (ov_id.object == nullptr)
continue;
ModelInstance* mi = ov_id.object->instances[0];
wxDataViewItem obj_item = m_objects_model->GetObjectItem(ov_id.object);
m_objects_model->SetObjectPrintableState(mi->printable ? piPrintable : piUnprintable, obj_item);
int obj_idx = m_objects_model->GetObjectIdByItem(obj_item);
obj_idxs.emplace_back(static_cast<size_t>(obj_idx));
}
sort(obj_idxs.begin(), obj_idxs.end());
obj_idxs.erase(unique(obj_idxs.begin(), obj_idxs.end()), obj_idxs.end());
// update printable state on canvas
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
// update scene
wxGetApp().plater()->update();
}
void ObjectList::assembly_plate_object_name() { m_objects_model->assembly_name(); }
void ObjectList::selected_object(ObjectDataViewModelNode* item)
{
if (!item) {
return;
}
this->SetFocus();
select_item(wxDataViewItem(item));
ensure_current_item_visible();
selection_changed();
}
void ObjectList::update_objects_list_filament_column(size_t filaments_count)
{
assert(filaments_count >= 1);
if (printer_technology() == ptSLA)
filaments_count = 1;
m_prevent_update_filament_in_config = true;
// BBS: update extruder values even when filaments_count is 1, because it may be reduced from value greater than 1
if (m_objects)
update_filament_values_for_items(filaments_count);
update_filament_colors();
// set show/hide for this column
set_filament_column_hidden(filaments_count == 1);
// a workaround for a wrong last column width updating under OSX
GetColumn(colEditing)->SetWidth(25);
m_prevent_update_filament_in_config = false;
}
void ObjectList::update_objects_list_filament_column_when_delete_filament(size_t filament_id,
size_t filaments_count,
int replace_filament_id)
{
m_prevent_update_filament_in_config = true;
// BBS: update extruder values even when filaments_count is 1, because it may be reduced from value greater than 1
if (m_objects)
update_filament_values_for_items_when_delete_filament(filament_id, replace_filament_id);
update_filament_colors();