From dfe4f54d080a9e02edb688a83593d1b6265f46fc Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 11 May 2018 22:34:40 -0500 Subject: [PATCH] stubbed methods to fire object_settings_dialog, retrieve the current selected object, etc. --- src/GUI/Plater.cpp | 116 +++++++++++++++++++++++++++++++++++++++++++++ src/GUI/Plater.hpp | 14 ++++++ 2 files changed, 130 insertions(+) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 56a93f09d..4a4174dc5 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -409,5 +409,121 @@ void Plater::on_model_change(bool force_autocenter) { this->refresh_canvases(); } +ObjRef Plater::selected_object() { + Slic3r::Log::info(LogChannel, L"Calling selected_object()"); + auto it {this->objects.begin()}; + for (it; it != this->objects.end(); it++) + if (it->selected) return it; + Slic3r::Log::info(LogChannel, L"No object selected."); + return this->objects.end(); +} + +void Plater::object_settings_dialog() { object_settings_dialog(this->selected_object()); } +void Plater::object_settings_dialog(ObjIdx obj_idx) { object_settings_dialog(this->objects.begin() + obj_idx); } +void Plater::object_settings_dialog(ObjRef obj) { + +} + +wxMenu* Plater::object_menu() { + return new wxMenu(); +} + + +void Plater::select_object(ObjRef obj) { + for (auto& o : this->objects) { + o.selected = false; + o.selected_instance = -1; + } + if (obj >= this->objects.end() && obj < this->objects.begin()) { + obj->selected = true; + obj->selected_instance = 0; + } + this->selection_changed(); // selection_changed(1) in perl +} + +void Plater::select_object(ObjIdx obj_idx) { + this->select_object(this->objects.begin() + obj_idx); +} + +void Plater::select_object() { + this->select_object(this->objects.end()); +} + +void Plater::selection_changed() { + // Remove selection in 2D plater + this->canvas2D->set_selected(-1, -1); + + auto obj = this->selected_object(); + bool have_sel {obj != this->objects.end()}; + /* + if (my $menu = $self->GetFrame->{plater_select_menu}) { + $_->Check(0) for $menu->GetMenuItems; + if ($have_sel) { + $menu->FindItemByPosition($obj_idx)->Check(1); + } + } + + my $method = $have_sel ? 'Enable' : 'Disable'; + $self->{"btn_$_"}->$method + for grep $self->{"btn_$_"}, qw(remove increase decrease rotate45cw rotate45ccw changescale split cut layers settings); + + if ($self->{htoolbar}) { + $self->{htoolbar}->EnableTool($_, $have_sel) + for (TB_REMOVE, TB_MORE, TB_FEWER, TB_45CW, TB_45CCW, TB_SCALE, TB_SPLIT, TB_CUT, TB_LAYERS, TB_SETTINGS); + } + + if ($self->{object_info_size}) { # have we already loaded the info pane? + + if ($have_sel) { + my $model_object = $self->{model}->objects->[$obj_idx]; + $self->{object_info_choice}->SetSelection($obj_idx); + $self->{object_info_copies}->SetLabel($model_object->instances_count); + my $model_instance = $model_object->instances->[0]; + { + my $size_string = sprintf "%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size}; + if ($model_instance->scaling_factor != 1) { + $size_string .= sprintf " (%s%%)", $model_instance->scaling_factor * 100; + } + $self->{object_info_size}->SetLabel($size_string); + } + $self->{object_info_materials}->SetLabel($model_object->materials_count); + + my $raw_mesh = $model_object->raw_mesh; + $raw_mesh->repair; # this calculates number_of_parts + if (my $stats = $raw_mesh->stats) { + $self->{object_info_volume}->SetLabel(sprintf('%.2f', $raw_mesh->volume * ($model_instance->scaling_factor**3))); + $self->{object_info_facets}->SetLabel(sprintf('%d (%d shells)', $model_object->facets_count, $stats->{number_of_parts})); + if (my $errors = sum(@$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)})) { + $self->{object_info_manifold}->SetLabel(sprintf("Auto-repaired (%d errors)", $errors)); + $self->{object_info_manifold_warning_icon}->Show; + + # we don't show normals_fixed because we never provide normals + # to admesh, so it generates normals for all facets + my $message = sprintf '%d degenerate facets, %d edges fixed, %d facets removed, %d facets added, %d facets reversed, %d backwards edges', + @$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)}; + $self->{object_info_manifold}->SetToolTipString($message); + $self->{object_info_manifold_warning_icon}->SetToolTipString($message); + } else { + $self->{object_info_manifold}->SetLabel("Yes"); + } + } else { + $self->{object_info_facets}->SetLabel($object->facets); + } + } else { + $self->{object_info_choice}->SetSelection(-1); + $self->{"object_info_$_"}->SetLabel("") for qw(copies size volume facets materials manifold); + $self->{object_info_manifold_warning_icon}->Hide; + $self->{object_info_manifold}->SetToolTipString(""); + } + $self->Layout; + } + # prepagate the event to the frame (a custom Wx event would be cleaner) + $self->GetFrame->on_plater_selection_changed($have_sel); +*/ + + +} + + }} // Namespace Slic3r::GUI diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index a306217ce..a91053a8b 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -119,10 +119,24 @@ private: /// Issue a repaint event to all of the canvasses. void refresh_canvases(); + /// Action to take when selection changes. Update platers, etc. + void selection_changed(); /// Run everything that needs to happen when models change. /// Includes updating canvases, reloading menus, etc. void on_model_change(bool force_autocenter = false); + + /// Searches the object vector for the first selected object and returns an iterator to it. + ObjRef selected_object(); + + /// Create and launch dialog for object settings. + void object_settings_dialog(); + void object_settings_dialog(ObjIdx obj_idx); + void object_settings_dialog(ObjRef obj); + + /// Create and launch menu for object. + wxMenu* object_menu(); + };