This commit is contained in:
Vojtech Bubnik 2021-11-16 10:18:58 +01:00
commit 58c93196d5
11 changed files with 122 additions and 57 deletions

View file

@ -137,6 +137,7 @@ public:
ObjectInfo(wxWindow *parent);
wxStaticBitmap *manifold_warning_icon;
wxStaticBitmap *info_icon;
wxStaticText *info_size;
wxStaticText *info_volume;
wxStaticText *info_facets;
@ -144,7 +145,7 @@ public:
wxStaticText *info_manifold;
wxStaticText *label_volume;
wxStaticText *label_materials;
// wxStaticText *label_materials; // ysFIXME - delete after next release if anyone will not complain about this
std::vector<wxStaticText *> sla_hidden_items;
bool showing_manifold_warning_icon;
@ -161,23 +162,33 @@ ObjectInfo::ObjectInfo(wxWindow *parent) :
auto *grid_sizer = new wxFlexGridSizer(4, 5, 15);
grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
// grid_sizer->AddGrowableCol(1, 1);
// 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 init_info_label = [parent, grid_sizer](wxStaticText **info_label, wxString text_label, wxSizer* sizer_with_icon=nullptr) {
auto *text = new wxStaticText(parent, wxID_ANY, text_label + ":");
text->SetFont(wxGetApp().small_font());
*info_label = new wxStaticText(parent, wxID_ANY, "");
(*info_label)->SetFont(wxGetApp().small_font());
grid_sizer->Add(text, 0);
grid_sizer->Add(*info_label, 0);
if (sizer_with_icon) {
sizer_with_icon->Insert(0, *info_label, 0);
grid_sizer->Add(sizer_with_icon, 0, wxEXPAND);
}
else
grid_sizer->Add(*info_label, 0);
return text;
};
init_info_label(&info_size, _L("Size"));
label_volume = init_info_label(&info_volume, _L("Volume"));
info_icon = new wxStaticBitmap(parent, wxID_ANY, create_scaled_bitmap("info"));
info_icon->SetToolTip(_L("For a multipart object, this value isn't accurate.\n"
"It doesn't take account of intersections and negative volumes."));
auto* volume_info_sizer = new wxBoxSizer(wxHORIZONTAL);
volume_info_sizer->Add(info_icon, 0, wxLEFT, 10);
label_volume = init_info_label(&info_volume, _L("Volume"), volume_info_sizer);
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, "");
@ -188,7 +199,7 @@ ObjectInfo::ObjectInfo(wxWindow *parent) :
sizer_manifold->Add(info_manifold, 0, wxLEFT, 2);
Add(sizer_manifold, 0, wxEXPAND | wxTOP, 4);
sla_hidden_items = { label_volume, info_volume, label_materials, info_materials };
sla_hidden_items = { label_volume, info_volume, /*label_materials, */info_materials };
}
void ObjectInfo::show_sizer(bool show)
@ -1199,32 +1210,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<int>(model_object->materials_count())));
ModelVolume* vol = nullptr;
Transform3d t;
if (selection.is_single_volume()) {
std::vector<int> 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<int>(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<int>(model_object->facets_count()), stats.number_of_parts));
@ -1237,6 +1263,8 @@ void Sidebar::show_info_sizer()
p->object_info->manifold_warning_icon->SetToolTip(tooltip);
p->object_info->show_sizer(true);
if (vol || model_object->volumes.size() == 1)
p->object_info->info_icon->Hide();
if (p->plater->printer_technology() == ptSLA) {
for (auto item: p->object_info->sla_hidden_items)