@@ -27,7 +27,6 @@ main_window::main_window(const wxString& title)
2727 _parts_list.initialize (_controls.notebook_panels [0 ]);
2828 _results_list.initialize (_controls.notebook_panels [2 ]);
2929 bind_all_controls ();
30- enable_part_settings (false );
3130
3231 wxGLAttributes attrs;
3332 attrs.PlatformDefaults ().Defaults ().EndList ();
@@ -45,33 +44,71 @@ main_window::main_window(const wxString& title)
4544}
4645
4746void main_window::on_select_parts (const std::vector<std::size_t >& indices) {
48- const auto size = indices.size ();
49- _controls.delete_part_button ->Enable (size != 0 );
50- _controls.reload_part_button ->Enable (size != 0 );
51- _controls.copy_part_button ->Enable (size == 1 );
52- _controls.mirror_part_button ->Enable (size == 1 );
53- if (size == 1 ) {
54- set_part (indices[ 0 ] );
55- } else {
56- unset_part () ;
47+ const bool any_selected = not indices.empty ();
48+ _controls.delete_part_button ->Enable (any_selected );
49+ _controls.reload_part_button ->Enable (any_selected );
50+ _controls.copy_part_button ->Enable (any_selected );
51+ _controls.mirror_part_button ->Enable (any_selected );
52+ enable_part_settings (any_selected);
53+ _current_parts. clear ( );
54+ if ( not any_selected) {
55+ return ;
5756 }
58- }
5957
60- void main_window::set_part (const std::size_t index) {
61- enable_part_settings (true );
62- _current_part = _parts_list.at (index);
63- _current_part_index.emplace (index);
64- _controls.quantity_spinner ->SetValue (_current_part->quantity );
65- _controls.min_hole_spinner ->SetValue (_current_part->min_hole );
66- _controls.minimize_checkbox ->SetValue (_current_part->rotate_min_box );
67- _controls.rotation_dropdown ->SetSelection (_current_part->rotation_index );
68- _viewport->set_mesh (_current_part->mesh , _current_part->centroid );
69- }
58+ std::optional<int > quantity{};
59+ std::optional<int > min_hole{};
60+ std::optional<bool > rotate_min_box{};
61+ std::optional<int > rotation_index{};
62+ bool first_time = true ;
63+ for (const std::size_t index : indices) {
64+ calc::part& part = _parts_list.at (index);
65+ _current_parts.emplace_back (&part, index);
66+ if (first_time) {
67+ first_time = false ;
68+ quantity.emplace (part.quantity );
69+ min_hole.emplace (part.min_hole );
70+ rotate_min_box.emplace (part.rotate_min_box );
71+ rotation_index.emplace (part.rotation_index );
72+ } else {
73+ if (quantity.has_value () and *quantity != part.quantity ) {
74+ quantity.reset ();
75+ }
76+ if (min_hole.has_value () and *min_hole != part.min_hole ) {
77+ min_hole.reset ();
78+ }
79+ if (rotate_min_box.has_value () and *rotate_min_box != part.rotate_min_box ) {
80+ rotate_min_box.reset ();
81+ }
82+ if (rotation_index.has_value () and *rotation_index != part.rotation_index ) {
83+ rotation_index.reset ();
84+ }
85+ }
86+ }
87+ if (quantity.has_value ()) {
88+ _controls.quantity_spinner ->SetValue (*quantity);
89+ } else {
90+ _controls.quantity_spinner ->SetValue (" " );
91+ }
92+ if (min_hole.has_value ()) {
93+ _controls.min_hole_spinner ->SetValue (*min_hole);
94+ } else {
95+ _controls.min_hole_spinner ->SetValue (" " );
96+ }
97+ if (rotate_min_box.has_value ()) {
98+ _controls.minimize_checkbox ->SetValue (*rotate_min_box);
99+ } else {
100+ _controls.minimize_checkbox ->Set3StateValue (wxCHK_UNDETERMINED);
101+ }
102+ if (rotation_index.has_value ()) {
103+ _controls.rotation_dropdown ->SetSelection (*rotation_index);
104+ } else {
105+ _controls.rotation_dropdown ->SetSelection (wxNOT_FOUND);
106+ }
70107
71- void main_window::unset_part ( ) {
72- enable_part_settings ( false ) ;
73- _current_part. reset ( );
74- _current_part_index. reset ();
108+ if (_current_parts. size () == 1 ) {
109+ const calc::part& part = *_current_parts[ 0 ]. part ;
110+ _viewport-> set_mesh (part. mesh , part. centroid );
111+ }
75112}
76113
77114void main_window::enable_part_settings (bool enable) {
@@ -113,9 +150,7 @@ void main_window::on_switch_tab(wxBookCtrlEvent& event) {
113150 switch (event.GetSelection ()) {
114151 case 0 : {
115152 _parts_list.get_selected (selected);
116- if (selected.size () == 1 ) {
117- set_part (selected[0 ]);
118- }
153+ on_select_parts (selected);
119154 break ;
120155 }
121156 case 2 : {
@@ -207,7 +242,7 @@ void main_window::on_stacking_success(calc::stack_result result, const std::chro
207242
208243void main_window::enable_on_stacking (const bool starting) {
209244 const bool enable = not starting;
210- enable_part_settings (enable and _current_part_index. has_value ());
245+ enable_part_settings (enable and not _current_parts. empty ());
211246 _parts_list.control ()->Enable (enable);
212247 for (wxMenuItem* item : _disableable_menu_items) {
213248 item->Enable (enable);
@@ -328,7 +363,7 @@ wxMenuBar* main_window::make_menu_bar() {
328363
329364 auto preferences_menu = new wxMenu ();
330365 preferences_menu->AppendCheckItem ((int )menu_item::pref_scroll, " Invert &scroll" , " Change the viewport scroll direction" );
331- preferences_menu->AppendCheckItem ((int )menu_item::pref_extra, " Display &extra parts" , " Display the extra part quantity separately" );
366+ preferences_menu->AppendCheckItem ((int )menu_item::pref_extra, " Display &extra parts" , " Display the quantity of extra parts separately" );
332367 menu_bar->Append (preferences_menu, " &Preferences" );
333368
334369 auto help_menu = new wxMenu ();
@@ -354,16 +389,23 @@ void main_window::bind_all_controls() {
354389 _controls.delete_part_button ->Bind (wxEVT_BUTTON, &main_window::on_delete_part, this );
355390 _controls.reload_part_button ->Bind (wxEVT_BUTTON, &main_window::on_reload_part, this );
356391 _controls.copy_part_button ->Bind (wxEVT_BUTTON, [this ](wxCommandEvent& event) {
357- _parts_list.append (*_current_part);
392+ for (auto & current_part : _current_parts) {
393+ _parts_list.append (*current_part.part );
394+ }
358395 _parts_list.update_label ();
359396 event.Skip ();
360397 });
361398 _controls.mirror_part_button ->Bind (wxEVT_BUTTON, [this ](wxCommandEvent& event) {
362- _current_part->mirrored = not _current_part->mirrored ;
363- _current_part->mesh .mirror_x ();
364- _current_part->mesh .set_baseline ({ 0 , 0 , 0 });
365- _parts_list.reload_text (_current_part_index.value ());
366- set_part (_current_part_index.value ());
399+ static thread_local std::vector<std::size_t > indices{};
400+ indices.clear ();
401+ for (auto & current_part : _current_parts) {
402+ indices.push_back (current_part.index );
403+ current_part.part ->mirrored = not current_part.part ->mirrored ;
404+ current_part.part ->mesh .mirror_x ();
405+ current_part.part ->mesh .set_baseline ({ 0 , 0 , 0 });
406+ _parts_list.reload_text (current_part.index );
407+ }
408+ on_select_parts (indices);
367409 event.Skip ();
368410 });
369411
@@ -373,21 +415,29 @@ void main_window::bind_all_controls() {
373415 _controls.sinterbox_result_button ->Bind (wxEVT_BUTTON, &main_window::on_sinterbox_result, this );
374416
375417 _controls.quantity_spinner ->Bind (wxEVT_SPINCTRL, [this ](wxSpinEvent& event) {
376- _current_part->quantity = event.GetPosition ();
377- _parts_list.reload_quantity (_current_part_index.value ());
418+ for (auto & current_part : _current_parts) {
419+ current_part.part ->quantity = event.GetPosition ();
420+ _parts_list.reload_quantity (current_part.index );
421+ }
378422 event.Skip ();
379423 });
380424 _controls.min_hole_spinner ->Bind (wxEVT_SPINCTRL, [this ](wxSpinEvent& event) {
381- _current_part->min_hole = event.GetPosition ();
425+ for (auto & current_part : _current_parts) {
426+ current_part.part ->min_hole = event.GetPosition ();
427+ }
382428 event.Skip ();
383429 });
384430 _controls.minimize_checkbox ->Bind (wxEVT_CHECKBOX, [this ](wxCommandEvent& event) {
385- _current_part->rotate_min_box = event.IsChecked ();
431+ for (auto & current_part : _current_parts) {
432+ current_part.part ->rotate_min_box = event.IsChecked ();
433+ }
386434 event.Skip ();
387435 });
388436
389437 _controls.rotation_dropdown ->Bind (wxEVT_CHOICE, [this ](wxCommandEvent& event) {
390- _current_part->rotation_index = _controls.rotation_dropdown ->GetSelection ();
438+ for (auto & current_part : _current_parts) {
439+ current_part.part ->rotation_index = _controls.rotation_dropdown ->GetSelection ();
440+ }
391441 event.Skip ();
392442 });
393443
@@ -411,7 +461,7 @@ void main_window::on_new(wxCommandEvent& event) {
411461 {
412462 _controls.reset_values ();
413463 _parts_list.delete_all ();
414- unset_part ( );
464+ on_select_parts ({} );
415465 _results_list.delete_all ();
416466 unset_result ();
417467 _viewport->remove_mesh ();
@@ -450,7 +500,7 @@ void main_window::on_import_part(wxCommandEvent& event) {
450500 }
451501 _parts_list.update_label ();
452502 if (paths.size () == 1 ) {
453- const calc::part& part = * _parts_list.at (_parts_list.rows () - 1 );
503+ const calc::part& part = _parts_list.at (_parts_list.rows () - 1 );
454504 _viewport->set_mesh (part.mesh , part.centroid );
455505 }
456506
0 commit comments