ObjectList improvements: Added warning icon for Parts with a repaired errors

This commit is contained in:
YuSanka 2019-04-29 15:27:59 +02:00
parent c752394abd
commit 2a47f0dc92
9 changed files with 180 additions and 89 deletions

View file

@ -1485,9 +1485,10 @@ stl_stats ModelObject::get_object_stl_stats() const
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;
if (vol_idx >= 0)
return this->volumes[vol_idx]->get_mesh_errors_count();
const stl_stats& stats = get_object_stl_stats();
return stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
@ -1558,6 +1559,14 @@ void ModelVolume::calculate_convex_hull()
m_convex_hull = mesh.convex_hull_3d();
}
int ModelVolume::get_mesh_errors_count() const
{
const stl_stats& stats = this->mesh.stl.stats;
return stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
}
const TriangleMesh& ModelVolume::get_convex_hull() const
{
return m_convex_hull;

View file

@ -375,6 +375,8 @@ public:
void calculate_convex_hull();
const TriangleMesh& get_convex_hull() const;
// Get count of errors in the mesh
int get_mesh_errors_count() const;
// Helpers for loading / storing into AMF / 3MF files.
static ModelVolumeType type_from_string(const std::string &s);

View file

@ -438,8 +438,8 @@ void ObjectList::update_name_in_model(const wxDataViewItem& item) const
void ObjectList::init_icons()
{
m_bmp_modifiermesh = ScalableBitmap(nullptr, "add_modifier"); // Add part
m_bmp_solidmesh = ScalableBitmap(nullptr, "add_part"); // Add modifier
m_bmp_solidmesh = ScalableBitmap(nullptr, "add_part"); // Add part
m_bmp_modifiermesh = ScalableBitmap(nullptr, "add_modifier"); // Add modifier
m_bmp_support_enforcer = ScalableBitmap(nullptr, "support_enforcer");// Add support enforcer
m_bmp_support_blocker = ScalableBitmap(nullptr, "support_blocker"); // Add support blocker
@ -455,6 +455,8 @@ void ObjectList::init_icons()
// init icon for manifold warning
m_bmp_manifold_warning = ScalableBitmap(nullptr, "exclamation");
// Set warning bitmap for the model
m_objects_model->SetWarningBitmap(&m_bmp_manifold_warning.bmp());
// init bitmap for "Split to sub-objects" context menu
m_bmp_split = ScalableBitmap(nullptr, "split_parts_SMALL");
@ -468,8 +470,8 @@ void ObjectList::rescale_icons()
m_bmp_vector.clear();
m_bmp_vector.reserve(4); // bitmaps for different types of parts
for (ScalableBitmap* bitmap : std::vector<ScalableBitmap*> {
&m_bmp_modifiermesh, // Add part
&m_bmp_solidmesh, // Add modifier
&m_bmp_solidmesh, // Add part
&m_bmp_modifiermesh, // Add modifier
&m_bmp_support_enforcer, // Add support enforcer
&m_bmp_support_blocker }) // Add support blocker
{
@ -480,6 +482,9 @@ void ObjectList::rescale_icons()
m_objects_model->SetVolumeBitmaps(m_bmp_vector);
m_bmp_manifold_warning.msw_rescale();
// Set warning bitmap for the model
m_objects_model->SetWarningBitmap(&m_bmp_manifold_warning.bmp());
m_bmp_split.msw_rescale();
m_bmp_cog.msw_rescale();
@ -541,7 +546,8 @@ void ObjectList::paste_volumes_into_list(int obj_idx, const ModelVolumePtrs& vol
for (const ModelVolume* volume : volumes)
{
auto vol_item = m_objects_model->AddVolumeChild(object_item, volume->name, volume->type(),
const wxDataViewItem& vol_item = m_objects_model->AddVolumeChild(object_item, volume->name, volume->type(),
volume->get_mesh_errors_count()>0 ,
volume->config.has("extruder") ? volume->config.option<ConfigOptionInt>("extruder")->value : 0);
auto opt_keys = volume->config.keys();
if (!opt_keys.empty() && !((opt_keys.size() == 1) && (opt_keys[0] == "extruder")))
@ -617,12 +623,13 @@ void ObjectList::OnContextMenu(wxDataViewEvent&)
if (title == " ")
show_context_menu();
else if (title == _("Name") && pt.x > 1.6f*wxGetApp().em_unit() && pt.x < 3.2f*wxGetApp().em_unit())
else if (title == _("Name"))
{
int obj_idx, vol_idx;
get_selected_item_indexes(obj_idx, vol_idx, item);
if (is_windows10() && get_mesh_errors_count(obj_idx, vol_idx) > 0)
if (is_windows10() && get_mesh_errors_count(obj_idx, vol_idx) > 0 &&
pt.x > 2*wxGetApp().em_unit() && pt.x < 4*wxGetApp().em_unit() )
fix_through_netfabb();
}
@ -1374,21 +1381,23 @@ void ObjectList::load_subobject(ModelVolumeType type)
int obj_idx = m_objects_model->GetIdByItem(item);
if (obj_idx < 0) return;
wxArrayString part_names;
load_part((*m_objects)[obj_idx], part_names, type);
std::vector<std::pair<wxString, bool>> volumes_info;
load_part((*m_objects)[obj_idx], volumes_info, type);
changed_object(obj_idx);
for (int i = 0; i < part_names.size(); ++i) {
const wxDataViewItem sel_item = m_objects_model->AddVolumeChild(item, part_names.Item(i), type);
if (i == part_names.size() - 1)
select_item(sel_item);
}
wxDataViewItem sel_item;
for (const auto& volume : volumes_info )
sel_item = m_objects_model->AddVolumeChild(item, volume.first, type, volume.second);
if (sel_item)
select_item(sel_item);
}
void ObjectList::load_part( ModelObject* model_object,
wxArrayString& part_names,
std::vector<std::pair<wxString, bool>> &volumes_info,
ModelVolumeType type)
{
wxWindow* parent = wxGetApp().tab_panel()->GetPage(0);
@ -1424,7 +1433,7 @@ void ObjectList::load_part( ModelObject* model_object,
new_volume->set_type(type);
new_volume->name = boost::filesystem::path(input_file).filename().string();
part_names.Add(from_u8(new_volume->name));
volumes_info.push_back(std::make_pair(from_u8(new_volume->name), new_volume->get_mesh_errors_count()>0));
// set a default extruder value, since user can't add it manually
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
@ -1580,7 +1589,8 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode
changed_object(obj_idx);
const auto object_item = m_objects_model->GetTopParent(GetSelection());
select_item(m_objects_model->AddVolumeChild(object_item, name, type));
select_item(m_objects_model->AddVolumeChild(object_item, name, type,
new_volume->get_mesh_errors_count()>0));
#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME
selection_changed();
#endif //no __WXOSX__ //__WXMSW__
@ -1612,6 +1622,10 @@ void ObjectList::del_subobject_item(wxDataViewItem& item)
else if (!del_subobject_from_object(obj_idx, idx, type))
return;
// If last volume item with warning was deleted, unmark object item
if (type == itVolume && (*m_objects)[obj_idx]->get_mesh_errors_count() == 0)
m_objects_model->DeleteWarningIcon(m_objects_model->GetParent(item));
m_objects_model->Delete(item);
}
@ -1718,18 +1732,18 @@ void ObjectList::split()
else
parent = item;
for (auto id = 0; id < model_object->volumes.size(); id++) {
const auto vol_item = m_objects_model->AddVolumeChild(parent, from_u8(model_object->volumes[id]->name),
model_object->volumes[id]->is_modifier() ?
ModelVolumeType::PARAMETER_MODIFIER : ModelVolumeType::MODEL_PART,
model_object->volumes[id]->config.has("extruder") ?
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value : 0,
for (const ModelVolume* volume : model_object->volumes) {
const wxDataViewItem& vol_item = m_objects_model->AddVolumeChild(parent, from_u8(volume->name),
volume->is_modifier() ? ModelVolumeType::PARAMETER_MODIFIER : ModelVolumeType::MODEL_PART,
volume->get_mesh_errors_count()>0,
volume->config.has("extruder") ?
volume->config.option<ConfigOptionInt>("extruder")->value : 0,
false);
// add settings to the part, if it has those
auto opt_keys = model_object->volumes[id]->config.keys();
auto opt_keys = volume->config.keys();
if ( !(opt_keys.size() == 1 && opt_keys[0] == "extruder") ) {
select_item(m_objects_model->AddSettingsChild(vol_item));
/*Collapse*/Expand(vol_item);
Expand(vol_item);
}
}
@ -1896,28 +1910,23 @@ void ObjectList::add_object_to_list(size_t obj_idx)
const wxString& item_name = from_u8(model_object->name);
const auto item = m_objects_model->Add(item_name,
!model_object->config.has("extruder") ? 0 :
model_object->config.option<ConfigOptionInt>("extruder")->value);
// Add error icon if detected auto-repaire
if (get_mesh_errors_count(obj_idx) > 0) {
wxVariant variant;
variant << DataViewBitmapText(item_name, m_bmp_manifold_warning.bmp());
m_objects_model->SetValue(variant, item, 0);
}
model_object->config.option<ConfigOptionInt>("extruder")->value,
get_mesh_errors_count(obj_idx) > 0);
// add volumes to the object
if (model_object->volumes.size() > 1) {
for (auto id = 0; id < model_object->volumes.size(); id++) {
auto vol_item = m_objects_model->AddVolumeChild(item,
from_u8(model_object->volumes[id]->name),
model_object->volumes[id]->type(),
!model_object->volumes[id]->config.has("extruder") ? 0 :
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value,
for (const ModelVolume* volume : model_object->volumes) {
const wxDataViewItem& vol_item = m_objects_model->AddVolumeChild(item,
from_u8(volume->name),
volume->type(),
volume->get_mesh_errors_count()>0,
!volume->config.has("extruder") ? 0 :
volume->config.option<ConfigOptionInt>("extruder")->value,
false);
auto opt_keys = model_object->volumes[id]->config.keys();
auto opt_keys = volume->config.keys();
if (!opt_keys.empty() && !(opt_keys.size() == 1 && opt_keys[0] == "extruder")) {
select_item(m_objects_model->AddSettingsChild(vol_item));
/*Collapse*/Expand(vol_item);
Expand(vol_item);
}
}
Expand(item);
@ -1931,7 +1940,7 @@ void ObjectList::add_object_to_list(size_t obj_idx)
auto opt_keys = model_object->config.keys();
if (!opt_keys.empty() && !(opt_keys.size() == 1 && opt_keys[0] == "extruder")) {
select_item(m_objects_model->AddSettingsChild(item));
/*Collapse*/Expand(item);
Expand(item);
}
#ifndef __WXOSX__
@ -2732,11 +2741,15 @@ void ObjectList::update_item_error_icon(const int obj_idx, const int vol_idx) co
if (!item)
return;
if (get_mesh_errors_count(obj_idx, vol_idx) == 0) {
// delete Error_icon if all errors are fixed
wxVariant variant;
variant << DataViewBitmapText(from_u8((*m_objects)[obj_idx]->name), wxNullBitmap);
m_objects_model->SetValue(variant, item, 0);
if (get_mesh_errors_count(obj_idx, vol_idx) == 0)
{
// if whole object has no errors more,
if (get_mesh_errors_count(obj_idx) == 0)
// unmark all items in the object
m_objects_model->DeleteWarningIcon(vol_idx >= 0 ? m_objects_model->GetParent(item) : item, true);
else
// unmark fixed item only
m_objects_model->DeleteWarningIcon(item);
}
}

View file

@ -216,7 +216,7 @@ public:
void update_opt_keys(t_config_option_keys& t_optopt_keys);
void load_subobject(ModelVolumeType type);
void load_part(ModelObject* model_object, wxArrayString& part_names, ModelVolumeType type);
void load_part(ModelObject* model_object, std::vector<std::pair<wxString, bool>> &volumes_info, ModelVolumeType type);
void load_generic_subobject(const std::string& type_name, const ModelVolumeType type);
void del_object(const int obj_idx);
void del_subobject_item(wxDataViewItem& item);

View file

@ -21,7 +21,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
OG_Settings(parent, true)
#ifndef __APPLE__
, m_focused_option("")
, m_manifold_warning_bmp(create_scaled_bitmap(parent, "exclamation"))
, m_manifold_warning_bmp(ScalableBitmap(parent, "exclamation"))
#endif // __APPLE__
{
m_og->set_name(_(L("Object Manipulation")));
@ -367,8 +367,7 @@ void ObjectManipulation::emulate_kill_focus()
void ObjectManipulation::update_manifold_warning_icon_state(const wxString& tooltip)
{
m_fix_throught_netfab_bitmap->SetBitmap(tooltip.IsEmpty() ? wxNullBitmap : m_manifold_warning_bmp);
m_fix_throught_netfab_bitmap->SetBitmap(tooltip.IsEmpty() ? wxNullBitmap : m_manifold_warning_bmp.bmp());
m_fix_throught_netfab_bitmap->SetToolTip(tooltip);
}
@ -559,5 +558,13 @@ void ObjectManipulation::on_fill_empty_value(const std::string& opt_key)
m_og->set_value(opt_key, double_to_string(value));
}
void ObjectManipulation::msw_rescale()
{
m_manifold_warning_bmp.msw_rescale();
m_fix_throught_netfab_bitmap->SetBitmap(m_manifold_warning_bmp.bmp());
get_og()->msw_rescale();
}
} //namespace GUI
} //namespace Slic3r

View file

@ -79,7 +79,7 @@ class ObjectManipulation : public OG_Settings
bool m_uniform_scale {true};
LockButton* m_lock_bnt{ nullptr };
wxBitmap m_manifold_warning_bmp;
ScalableBitmap m_manifold_warning_bmp;
wxStaticBitmap* m_fix_throught_netfab_bitmap;
#ifndef __APPLE__
@ -112,6 +112,7 @@ public:
#endif // __APPLE__
void update_manifold_warning_icon_state(const wxString& tooltip);
void msw_rescale();
private:
void reset_settings_value();

View file

@ -896,8 +896,7 @@ void Sidebar::msw_rescale()
p->frequently_changed_parameters->get_og(false)->msw_rescale();
p->object_list->msw_rescale();
p->object_manipulation->get_og()->msw_rescale();
p->object_manipulation->msw_rescale();
p->object_settings->msw_rescale();
p->object_info->msw_rescale();

View file

@ -420,14 +420,21 @@ ObjectDataViewModel::~ObjectDataViewModel()
m_bitmap_cache = nullptr;
}
wxDataViewItem ObjectDataViewModel::Add(const wxString &name, const int extruder)
wxDataViewItem ObjectDataViewModel::Add(const wxString &name,
const int extruder,
const bool has_errors/* = false*/)
{
const wxString extruder_str = extruder == 0 ? "default" : wxString::Format("%d", extruder);
auto root = new ObjectDataViewModelNode(name, extruder_str);
// Add error icon if detected auto-repaire
if (has_errors)
root->m_bmp = *m_warning_bmp;
m_objects.push_back(root);
// notify control
wxDataViewItem child((void*)root);
wxDataViewItem parent((void*)NULL);
ItemAdded(parent, child);
return child;
}
@ -435,6 +442,7 @@ wxDataViewItem ObjectDataViewModel::Add(const wxString &name, const int extruder
wxDataViewItem ObjectDataViewModel::AddVolumeChild( const wxDataViewItem &parent_item,
const wxString &name,
const Slic3r::ModelVolumeType volume_type,
const bool has_errors/* = false*/,
const int extruder/* = 0*/,
const bool create_frst_child/* = true*/)
{
@ -448,9 +456,14 @@ wxDataViewItem ObjectDataViewModel::AddVolumeChild( const wxDataViewItem &parent
if (insert_position < 0 || root->GetNthChild(insert_position)->m_type != itInstanceRoot)
insert_position = -1;
const bool obj_errors = root->m_bmp.IsOk();
if (create_frst_child && root->m_volumes_cnt == 0)
{
const auto node = new ObjectDataViewModelNode(root, root->m_name, *m_volume_bmps[0], extruder_str, 0);
const Slic3r::ModelVolumeType type = Slic3r::ModelVolumeType::MODEL_PART;
const auto node = new ObjectDataViewModelNode(root, root->m_name, GetVolumeIcon(type, obj_errors), extruder_str, 0);
node->m_volume_type = type;
insert_position < 0 ? root->Append(node) : root->Insert(node, insert_position);
// notify control
const wxDataViewItem child((void*)node);
@ -458,12 +471,15 @@ wxDataViewItem ObjectDataViewModel::AddVolumeChild( const wxDataViewItem &parent
root->m_volumes_cnt++;
if (insert_position > 0) insert_position++;
node->m_volume_type = volume_type;
}
const auto node = new ObjectDataViewModelNode(root, name, *m_volume_bmps[int(volume_type)], extruder_str, root->m_volumes_cnt);
const auto node = new ObjectDataViewModelNode(root, name, GetVolumeIcon(volume_type, has_errors), extruder_str, root->m_volumes_cnt);
insert_position < 0 ? root->Append(node) : root->Insert(node, insert_position);
// if part with errors is added, but object wasn't marked, then mark it
if (!obj_errors && has_errors)
root->SetBitmap(*m_warning_bmp);
// notify control
const wxDataViewItem child((void*)node);
ItemAdded(parent_item, child);
@ -1228,15 +1244,61 @@ void ObjectDataViewModel::Rescale()
node->msw_rescale();
if (node->m_type & itVolume)
node->m_bmp = *m_volume_bmps[node->volume_type()];
node->m_bmp = GetVolumeIcon(node->m_volume_type, node->m_bmp.GetWidth() != node->m_bmp.GetHeight());
if (node->m_type & itObject && node->m_bmp.IsOk())
node->m_bmp = create_scaled_bitmap(nullptr, "exclamation");
node->m_bmp = *m_warning_bmp;
ItemChanged(item);
}
}
wxBitmap ObjectDataViewModel::GetVolumeIcon(const Slic3r::ModelVolumeType vol_type, const bool is_marked/* = false*/)
{
if (!is_marked)
return *m_volume_bmps[static_cast<int>(vol_type)];
std::string scaled_bitmap_name = "warning" + std::to_string(static_cast<int>(vol_type));
scaled_bitmap_name += "-em" + std::to_string(Slic3r::GUI::wxGetApp().em_unit());
wxBitmap *bmp = m_bitmap_cache->find(scaled_bitmap_name);
if (bmp == nullptr) {
std::vector<wxBitmap> bmps;
bmps.emplace_back(*m_warning_bmp);
bmps.emplace_back(*m_volume_bmps[static_cast<int>(vol_type)]);
bmp = m_bitmap_cache->insert(scaled_bitmap_name, bmps);
}
return *bmp;
}
void ObjectDataViewModel::DeleteWarningIcon(const wxDataViewItem& item, const bool unmark_object/* = false*/)
{
if (!item.IsOk())
return;
ObjectDataViewModelNode *node = (ObjectDataViewModelNode*)item.GetID();
if (!node->GetBitmap().IsOk() || !(node->GetType() & (itVolume | itObject)))
return;
if (node->GetType() & itVolume) {
node->SetBitmap(*m_volume_bmps[static_cast<int>(node->volume_type())]);
return;
}
node->SetBitmap(wxNullBitmap);
if (unmark_object)
{
wxDataViewItemArray children;
GetChildren(item, children);
for (const wxDataViewItem& child : children)
DeleteWarningIcon(child);
}
}
//-----------------------------------------------------------------------------
// PrusaDataViewBitmapText
//-----------------------------------------------------------------------------
@ -2351,8 +2413,7 @@ void ModeButton::SetState(const bool state)
void ModeButton::focus_button(const bool focus)
{
wxFont font = GetFont();
const wxFont& new_font = focus ? font.Bold() : font.GetBaseFont();
const wxFont& new_font = focus ? Slic3r::GUI::wxGetApp().bold_font() : Slic3r::GUI::wxGetApp().normal_font();
SetFont(new_font);
@ -2378,11 +2439,7 @@ ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 10*/) :
m_mode_btns.reserve(3);
for (const auto& button : buttons) {
// int x, y;
// parent->GetTextExtent(button.first, &x, &y, nullptr, nullptr, &Slic3r::GUI::wxGetApp().bold_font());
// const wxSize size = wxSize(x + button.second.GetWidth() + Slic3r::GUI::wxGetApp().em_unit(),
// y + Slic3r::GUI::wxGetApp().em_unit());
m_mode_btns.push_back(new ModeButton(parent, wxID_ANY, button.second, button.first/*, size*/));
m_mode_btns.push_back(new ModeButton(parent, wxID_ANY, button.second, button.first));
}
for (auto btn : m_mode_btns)

View file

@ -323,14 +323,10 @@ public:
return false;
}
void SetBitmap(const wxBitmap &icon)
{
m_bmp = icon;
}
ItemType GetType() const {
return m_type;
}
void SetBitmap(const wxBitmap &icon) { m_bmp = icon; }
const wxBitmap& GetBitmap() const { return m_bmp; }
const wxString& GetName() const { return m_name; }
ItemType GetType() const { return m_type; }
void SetIdx(const int& idx) {
m_idx = idx;
@ -339,9 +335,7 @@ public:
m_name = wxString::Format("Instance_%d", m_idx + 1);
}
int GetIdx() const {
return m_idx;
}
int GetIdx() const { return m_idx; }
// use this function only for childrens
void AssignAllVal(ObjectDataViewModelNode& from_node)
@ -374,10 +368,10 @@ public:
// Set action icons for node
void set_action_icon();
void update_settings_digest_bitmaps();
bool update_settings_digest(const std::vector<std::string>& categories);
int volume_type() const { return int(m_volume_type); }
void msw_rescale();
void update_settings_digest_bitmaps();
bool update_settings_digest(const std::vector<std::string>& categories);
int volume_type() const { return int(m_volume_type); }
void msw_rescale();
private:
friend class ObjectDataViewModel;
};
@ -393,6 +387,7 @@ class ObjectDataViewModel :public wxDataViewModel
{
std::vector<ObjectDataViewModelNode*> m_objects;
std::vector<wxBitmap*> m_volume_bmps;
wxBitmap* m_warning_bmp;
wxDataViewCtrl* m_ctrl{ nullptr };
@ -400,10 +395,13 @@ public:
ObjectDataViewModel();
~ObjectDataViewModel();
wxDataViewItem Add(const wxString &name, const int extruder);
wxDataViewItem Add( const wxString &name,
const int extruder,
const bool has_errors = false);
wxDataViewItem AddVolumeChild( const wxDataViewItem &parent_item,
const wxString &name,
const Slic3r::ModelVolumeType volume_type,
const bool has_errors = false,
const int extruder = 0,
const bool create_frst_child = true);
wxDataViewItem AddSettingsChild(const wxDataViewItem &parent_item);
@ -475,11 +473,16 @@ public:
const std::vector<std::string>& categories);
void SetVolumeBitmaps(const std::vector<wxBitmap*>& volume_bmps) { m_volume_bmps = volume_bmps; }
void SetWarningBitmap(wxBitmap* bitmap) { m_warning_bmp = bitmap; }
void SetVolumeType(const wxDataViewItem &item, const Slic3r::ModelVolumeType type);
void SetAssociatedControl(wxDataViewCtrl* ctrl) { m_ctrl = ctrl; }
// Rescale bitmaps for existing Items
void Rescale();
wxBitmap GetVolumeIcon(const Slic3r::ModelVolumeType vol_type,
const bool is_marked = false);
void DeleteWarningIcon(const wxDataViewItem& item, const bool unmark_object = false);
};
// ----------------------------------------------------------------------------