diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index fec6e422c..a25062c48 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1,3 +1,4 @@ +#include "Model.hpp" #include "libslic3r.h" #include "Exception.hpp" #include "Model.hpp" @@ -1701,9 +1702,6 @@ std::string ModelObject::get_export_filename() const TriangleMeshStats ModelObject::get_object_stl_stats() const { - if (this->volumes.size() == 1) - return this->volumes[0]->mesh().stats(); - TriangleMeshStats full_stats; full_stats.volume = 0.f; @@ -1718,7 +1716,8 @@ TriangleMeshStats ModelObject::get_object_stl_stats() const // another used satistics value if (volume->is_model_part()) { - full_stats.volume += stats.volume; + Transform3d trans = instances[0]->get_matrix() * volume->get_matrix(); + full_stats.volume += stats.volume * std::fabs(trans.matrix().block(0, 0, 3, 3).determinant()); full_stats.number_of_parts += stats.number_of_parts; } } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 04ccbb183..eb3c9bc53 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -165,7 +165,7 @@ ObjectInfo::ObjectInfo(wxWindow *parent) : // grid_sizer->AddGrowableCol(3, 1); auto init_info_label = [parent, grid_sizer](wxStaticText **info_label, wxString text_label) { - auto *text = new wxStaticText(parent, wxID_ANY, text_label+":"); + auto *text = new wxStaticText(parent, wxID_ANY, text_label + (text_label.empty() ? "" : ":")); text->SetFont(wxGetApp().small_font()); *info_label = new wxStaticText(parent, wxID_ANY, ""); (*info_label)->SetFont(wxGetApp().small_font()); @@ -177,7 +177,7 @@ ObjectInfo::ObjectInfo(wxWindow *parent) : init_info_label(&info_size, _L("Size")); label_volume = init_info_label(&info_volume, _L("Volume")); init_info_label(&info_facets, _L("Facets")); - label_materials = init_info_label(&info_materials, _L("Materials")); + label_materials = init_info_label(&info_materials, /*_L("Materials")*/""); Add(grid_sizer, 0, wxEXPAND); info_manifold = new wxStaticText(parent, wxID_ANY, ""); @@ -1199,32 +1199,47 @@ void Sidebar::update_objects_list_extruder_column(size_t extruders_count) void Sidebar::show_info_sizer() { - if (!p->plater->is_single_full_object_selection() || - m_mode < comExpert || - p->plater->model().objects.empty()) { + Selection& selection = wxGetApp().plater()->canvas3D()->get_selection(); + ModelObjectPtrs objects = p->plater->model().objects; + int obj_idx = selection.get_object_idx(); + + if (m_mode < comExpert || objects.empty() || obj_idx < 0 || obj_idx > 1000 || + objects[obj_idx]->volumes.empty() || // hack to avoid crash when deleting the last object on the bed + (selection.is_single_full_object() && objects[obj_idx]->instances.size()> 1) || + !(selection.is_single_full_instance() || selection.is_single_volume())) { p->object_info->Show(false); return; } - int obj_idx = p->plater->get_selected_object_idx(); + const ModelObject* model_object = objects[obj_idx]; - const ModelObject* model_object = p->plater->model().objects[obj_idx]; - // hack to avoid crash when deleting the last object on the bed - if (model_object->volumes.empty()) - { - p->object_info->Show(false); - return; - } + int inst_idx = selection.get_instance_idx(); + assert(inst_idx >= 0); bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; double koef = imperial_units ? ObjectManipulation::mm_to_in : 1.0f; - auto size = model_object->bounding_box().size(); - p->object_info->info_size->SetLabel(wxString::Format("%.2f x %.2f x %.2f",size(0)*koef, size(1)*koef, size(2)*koef)); - p->object_info->info_materials->SetLabel(wxString::Format("%d", static_cast(model_object->materials_count()))); + ModelVolume* vol = nullptr; + Transform3d t; + if (selection.is_single_volume()) { + std::vector obj_idxs, vol_idxs; + wxGetApp().obj_list()->get_selection_indexes(obj_idxs, vol_idxs); + assert(vol_idxs.size() == 1); + vol = model_object->volumes[vol_idxs[0]]; + t = model_object->instances[inst_idx]->get_matrix() * vol->get_matrix(); + } - const auto& stats = model_object->get_object_stl_stats(); - p->object_info->info_volume->SetLabel(wxString::Format("%.2f", stats.volume*pow(koef,3))); + Vec3d size = vol ? vol->mesh().transformed_bounding_box(t).size() : model_object->instance_bounding_box(inst_idx).size(); + p->object_info->info_size->SetLabel(wxString::Format("%.2f x %.2f x %.2f", size(0)*koef, size(1)*koef, size(2)*koef)); +// p->object_info->info_materials->SetLabel(wxString::Format("%d", static_cast(model_object->materials_count()))); + + const TriangleMeshStats& stats = vol ? vol->mesh().stats() : model_object->get_object_stl_stats(); + + double volume_val = stats.volume; + if (vol) + volume_val *= std::fabs(t.matrix().block(0, 0, 3, 3).determinant()); + + p->object_info->info_volume->SetLabel(wxString::Format("%.2f", volume_val * pow(koef,3))); p->object_info->info_facets->SetLabel(format_wxstr(_L_PLURAL("%1% (%2$d shell)", "%1% (%2$d shells)", stats.number_of_parts), static_cast(model_object->facets_count()), stats.number_of_parts));