Refactoring: get_mesh_errors_count() moved to ModelObject

+ added get_object_stl_stats() to ModelObject
This commit is contained in:
YuSanka 2019-04-24 16:04:47 +02:00
parent 356e1207d6
commit b4d5287d0c
6 changed files with 78 additions and 47 deletions

View File

@ -1451,6 +1451,48 @@ std::string ModelObject::get_export_filename() const
return ret;
}
stl_stats ModelObject::get_object_stl_stats() const
{
if (this->volumes.size() == 1)
return this->volumes[0]->mesh.stl.stats;
stl_stats full_stats;
// initialise full_stats
full_stats.degenerate_facets= 0;
full_stats.edges_fixed = 0;
full_stats.facets_removed = 0;
full_stats.facets_added = 0;
full_stats.facets_reversed = 0;
full_stats.backwards_edges = 0;
full_stats.normals_fixed = 0;
// fill full_stats from all objet's meshes
for (ModelVolume* volume : this->volumes)
{
const stl_stats& stats = volume->mesh.stl.stats;
full_stats.degenerate_facets+= stats.degenerate_facets;
full_stats.edges_fixed += stats.edges_fixed;
full_stats.facets_removed += stats.facets_removed;
full_stats.facets_added += stats.facets_added;
full_stats.facets_reversed += stats.facets_reversed;
full_stats.backwards_edges += stats.backwards_edges;
}
return full_stats;
}
int ModelObject::get_mesh_errors_count(const int vol_idx /*= -1*/) const
{
const stl_stats& stats = vol_idx == -1 ?
get_object_stl_stats() :
this->volumes[vol_idx]->mesh.stl.stats;
return stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
}
void ModelVolume::set_material_id(t_model_material_id material_id)
{
m_material_id = material_id;

View File

@ -277,6 +277,11 @@ public:
std::string get_export_filename() const;
// Get full stl statistics for all object's meshes
stl_stats get_object_stl_stats() const;
// Get count of errors in the mesh( or all object's meshes, if volume index isn't defined)
int get_mesh_errors_count(const int vol_idx = -1) const;
protected:
friend class Print;
friend class SLAPrint;

View File

@ -216,23 +216,7 @@ int ObjectList::get_mesh_errors_count(const int obj_idx, const int vol_idx /*= -
if (obj_idx < 0)
return 0;
int errors = 0;
std::vector<ModelVolume*> volumes;
if (vol_idx == -1)
volumes = (*m_objects)[obj_idx]->volumes;
else
volumes.emplace_back((*m_objects)[obj_idx]->volumes[vol_idx]);
for (ModelVolume* volume : volumes)
{
const stl_stats& stats = volume->mesh.stl.stats;
errors += stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
}
return errors;
return (*m_objects)[obj_idx]->get_mesh_errors_count(vol_idx);
}
wxString ObjectList::get_mesh_errors_list(const int obj_idx, const int vol_idx /*= -1*/) const
@ -245,33 +229,19 @@ wxString ObjectList::get_mesh_errors_list(const int obj_idx, const int vol_idx /
// Create tooltip string, if there are errors
wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors):\n")), errors);
std::vector<ModelVolume*> volumes;
if (vol_idx == -1)
volumes = (*m_objects)[obj_idx]->volumes;
else
volumes.emplace_back((*m_objects)[obj_idx]->volumes[vol_idx]);
const stl_stats& stats = vol_idx == -1 ?
(*m_objects)[obj_idx]->get_object_stl_stats() :
(*m_objects)[obj_idx]->volumes[vol_idx]->mesh.stl.stats;
std::map<std::string, int> error_msg = {
{L("degenerate facets") , 0},
{L("edges fixed") , 0},
{L("facets removed") , 0},
{L("facets added") , 0},
{L("facets reversed") , 0},
{L("backwards edges") , 0}
{ L("degenerate facets"), stats.degenerate_facets },
{ L("edges fixed"), stats.edges_fixed },
{ L("facets removed"), stats.facets_removed },
{ L("facets added"), stats.facets_added },
{ L("facets reversed"), stats.facets_reversed },
{ L("backwards edges"), stats.backwards_edges }
};
for (ModelVolume* volume : volumes)
{
const stl_stats& stats = volume->mesh.stl.stats;
error_msg[L("degenerate facets")] += stats.degenerate_facets;
error_msg[L("edges fixed")] += stats.edges_fixed;
error_msg[L("facets removed")] += stats.facets_removed;
error_msg[L("facets added")] += stats.facets_added;
error_msg[L("facets reversed")] += stats.facets_reversed;
error_msg[L("backwards edges")] += stats.backwards_edges;
}
for (const auto& error : error_msg)
if (error.second > 0)
tooltip += wxString::Format(_("\t%d %s\n"), error.second, error.first);
@ -1170,13 +1140,15 @@ void ObjectList::append_menu_items_osx(wxMenu* menu)
menu->AppendSeparator();
}
void ObjectList::append_menu_item_fix_through_netfabb(wxMenu* menu)
wxMenuItem* ObjectList::append_menu_item_fix_through_netfabb(wxMenu* menu)
{
if (!is_windows10())
return;
append_menu_item(menu, wxID_ANY, _(L("Fix through the Netfabb")), "",
// if (!is_windows10())
// return;
wxMenuItem* menu_item = append_menu_item(menu, wxID_ANY, _(L("Fix through the Netfabb")), "",
[this](wxCommandEvent&) { fix_through_netfabb(); }, "", menu);
menu->AppendSeparator();
return menu_item;
}
void ObjectList::append_menu_item_export_stl(wxMenu* menu) const

View File

@ -204,7 +204,7 @@ public:
wxMenuItem* append_menu_item_change_type(wxMenu* menu);
wxMenuItem* append_menu_item_instance_to_object(wxMenu* menu);
void append_menu_items_osx(wxMenu* menu);
void append_menu_item_fix_through_netfabb(wxMenu* menu);
wxMenuItem* append_menu_item_fix_through_netfabb(wxMenu* menu);
void append_menu_item_export_stl(wxMenu* menu) const ;
void append_menu_item_change_extruder(wxMenu* menu) const;
void append_menu_item_delete(wxMenu* menu);

View File

@ -8,6 +8,7 @@
class wxStaticText;
class PrusaLockButton;
class wxStaticBitmap;
namespace Slic3r {
namespace GUI {

View File

@ -926,7 +926,7 @@ void Sidebar::show_info_sizer()
p->object_info->info_size->SetLabel(wxString::Format("%.2f x %.2f x %.2f",size(0), size(1), size(2)));
p->object_info->info_materials->SetLabel(wxString::Format("%d", static_cast<int>(model_object->materials_count())));
auto& stats = model_object->volumes.front()->mesh.stl.stats;
const auto& stats = model_object->get_object_stl_stats();//model_object->volumes.front()->mesh.stl.stats;
p->object_info->info_volume->SetLabel(wxString::Format("%.2f", stats.volume));
p->object_info->info_facets->SetLabel(wxString::Format(_(L("%d (%d shells)")), static_cast<int>(model_object->facets_count()), stats.number_of_parts));
@ -1284,6 +1284,7 @@ struct Plater::priv
bool can_split_to_volumes() const;
bool can_arrange() const;
bool can_layers_editing() const;
bool can_fix_through_netfabb() const;
private:
bool init_object_menu();
@ -2886,7 +2887,7 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/
menu->AppendSeparator();
}
sidebar->obj_list()->append_menu_item_fix_through_netfabb(menu);
wxMenuItem* item_fix_through_netfabb = sidebar->obj_list()->append_menu_item_fix_through_netfabb(menu);
wxMenu* mirror_menu = new wxMenu();
if (mirror_menu == nullptr)
@ -2906,6 +2907,7 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/
{
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_mirror()); }, item_mirror->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_delete()); }, item_delete->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_fix_through_netfabb()); }, item_fix_through_netfabb->GetId());
}
return true;
@ -3075,6 +3077,15 @@ bool Plater::priv::can_delete_all() const
return !model.objects.empty();
}
bool Plater::priv::can_fix_through_netfabb() const
{
int obj_idx = get_selected_object_idx();
if (obj_idx < 0)
return false;
return model.objects[obj_idx]->get_mesh_errors_count() > 0;
}
bool Plater::priv::can_increase_instances() const
{
if (arranging || rotoptimizing) {