Merge remote-tracking branch 'remotes/origin/master' into vb_wold_object_manipulation

This commit is contained in:
bubnikv 2019-05-03 19:13:47 +02:00
commit a8241ad7f7
10 changed files with 421 additions and 153 deletions
src/slic3r/GUI

View file

@ -211,6 +211,76 @@ void ObjectList::create_popup_menus()
create_instance_popupmenu(&m_menu_instance);
}
void ObjectList::get_selected_item_indexes(int& obj_idx, int& vol_idx, const wxDataViewItem& input_item/* = wxDataViewItem(0)*/)
{
const wxDataViewItem item = input_item == wxDataViewItem(0) ? GetSelection() : input_item;
if (!item)
{
obj_idx = vol_idx = -1;
return;
}
const ItemType type = m_objects_model->GetItemType(item);
obj_idx = type & itObject ? m_objects_model->GetIdByItem(item) :
type & itVolume ? m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item)) : -1;
vol_idx = type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1;
}
int ObjectList::get_mesh_errors_count(const int obj_idx, const int vol_idx /*= -1*/) const
{
if (obj_idx < 0)
return 0;
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
{
const int errors = get_mesh_errors_count(obj_idx, vol_idx);
if (errors == 0)
return ""; // hide tooltip
// Create tooltip string, if there are errors
wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors):\n")), errors);
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"), 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 (const auto& error : error_msg)
if (error.second > 0)
tooltip += wxString::Format("\t%d %s\n", error.second, _(error.first));
if (is_windows10())
tooltip += _(L("Right button click the icon to fix STL through Netfabb"));
return tooltip;
}
wxString ObjectList::get_mesh_errors_list()
{
if (!GetSelection())
return "";
int obj_idx, vol_idx;
get_selected_item_indexes(obj_idx, vol_idx);
return get_mesh_errors_list(obj_idx, vol_idx);
}
void ObjectList::set_tooltip_for_item(const wxPoint& pt)
{
wxDataViewItem item;
@ -218,40 +288,24 @@ void ObjectList::set_tooltip_for_item(const wxPoint& pt)
HitTest(pt, item, col);
if (!item) return;
/* GetMainWindow() return window, associated with wxDataViewCtrl.
* And for this window we should to set tooltips.
* Just this->SetToolTip(tooltip) => has no effect.
*/
if (col->GetTitle() == " " && GetSelectedItemsCount()<2)
GetMainWindow()->SetToolTip(_(L("Right button click the icon to change the object settings")));
else if (col->GetTitle() == _("Name") &&
m_objects_model->GetBitmap(item).GetRefData() == m_bmp_manifold_warning.bmp().GetRefData()) {
int obj_idx = m_objects_model->GetIdByItem(item);
auto& stats = (*m_objects)[obj_idx]->volumes[0]->mesh.stl.stats;
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors):\n")), errors);
std::map<std::string, int> error_msg;
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 (auto error : error_msg)
{
if (error.second > 0)
tooltip += wxString::Format(_("\t%d %s\n"), error.second, error.first);
else if (col->GetTitle() == _("Name"))
{
#ifdef __WXMSW__
if (pt.x < 2 * wxGetApp().em_unit() || pt.x > 4 * wxGetApp().em_unit()) {
GetMainWindow()->SetToolTip(""); // hide tooltip
return;
}
// OR
// tooltip += wxString::Format(_(L("%d degenerate facets, %d edges fixed, %d facets removed, "
// "%d facets added, %d facets reversed, %d backwards edges")),
// stats.degenerate_facets, stats.edges_fixed, stats.facets_removed,
// stats.facets_added, stats.facets_reversed, stats.backwards_edges);
if (is_windows10())
tooltip += _(L("Right button click the icon to fix STL through Netfabb"));
GetMainWindow()->SetToolTip(tooltip);
#endif //__WXMSW__
int obj_idx, vol_idx;
get_selected_item_indexes(obj_idx, vol_idx, item);
GetMainWindow()->SetToolTip(get_mesh_errors_list(obj_idx, vol_idx));
}
else
GetMainWindow()->SetToolTip(""); // hide tooltip
@ -413,8 +467,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
@ -430,6 +484,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");
@ -443,8 +499,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
{
@ -455,6 +511,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();
@ -516,7 +575,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")))
@ -592,10 +652,13 @@ void ObjectList::OnContextMenu(wxDataViewEvent&)
if (title == " ")
show_context_menu();
else if (title == _("Name") && pt.x >15 &&
m_objects_model->GetBitmap(item).GetRefData() == m_bmp_manifold_warning.bmp().GetRefData())
else if (title == _("Name"))
{
if (is_windows10())
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 &&
pt.x > 2*wxGetApp().em_unit() && pt.x < 4*wxGetApp().em_unit() )
fix_through_netfabb();
}
@ -955,6 +1018,7 @@ void ObjectList::get_freq_settings_choice(const wxString& bundle_name)
{
const std::vector<std::string>& options = get_options_for_bundle(bundle_name);
assert(m_config);
auto opt_keys = m_config->keys();
const DynamicPrintConfig& from_config = wxGetApp().preset_bundle->prints.get_edited_preset().config;
@ -984,6 +1048,10 @@ void ObjectList::update_settings_item()
const auto settings_item = m_objects_model->IsSettingsItem(item) ? item : m_objects_model->GetSettingsItem(item);
select_item(settings_item ? settings_item :
m_objects_model->AddSettingsChild(item));
// update object selection on Plater
if (!m_prevent_canvas_selection_update)
update_selections_on_canvas();
}
else {
auto panel = wxGetApp().sidebar().scrolled_panel();
@ -1153,13 +1221,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")), "",
return nullptr;
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
@ -1345,21 +1415,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);
@ -1395,7 +1467,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));
@ -1544,7 +1616,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__
@ -1576,6 +1649,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);
}
@ -1682,18 +1759,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);
}
}
@ -1766,6 +1843,7 @@ void ObjectList::changed_object(const int obj_idx/* = -1*/) const
void ObjectList::part_selection_changed()
{
int obj_idx = -1;
int volume_id = -1;
m_config = nullptr;
wxString og_name = wxEmptyString;
@ -1812,7 +1890,7 @@ void ObjectList::part_selection_changed()
}
else if (m_objects_model->GetItemType(item) == itVolume) {
og_name = _(L("Part manipulation"));
const auto volume_id = m_objects_model->GetVolumeIdByItem(item);
volume_id = m_objects_model->GetVolumeIdByItem(item);
m_config = &(*m_objects)[obj_idx]->volumes[volume_id]->config;
update_and_show_manipulations = true;
}
@ -1832,7 +1910,11 @@ void ObjectList::part_selection_changed()
if (update_and_show_manipulations) {
wxGetApp().obj_manipul()->get_og()->set_name(" " + og_name + " ");
wxGetApp().obj_manipul()->get_og()->set_value("object_name", m_objects_model->GetName(GetSelection()));
if (item) {
wxGetApp().obj_manipul()->get_og()->set_value("object_name", m_objects_model->GetName(item));
wxGetApp().obj_manipul()->update_warning_icon_state(get_mesh_errors_list(obj_idx, volume_id));
}
}
if (update_and_show_settings)
@ -1852,34 +1934,26 @@ void ObjectList::part_selection_changed()
void ObjectList::add_object_to_list(size_t obj_idx)
{
auto model_object = (*m_objects)[obj_idx];
wxString item_name = from_u8(model_object->name);
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
auto stats = model_object->volumes[0]->mesh.stl.stats;
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
if (errors > 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);
@ -1893,7 +1967,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__
@ -2087,6 +2161,11 @@ void ObjectList::update_selections()
if (m_objects_model->GetVolumeIdByItem(m_objects_model->GetParent(item)) == gl_vol->volume_idx())
return;
}
// but if there is selected only one of several instances by context menu,
// then select this instance in ObjectList
if (selection.is_single_full_instance())
sels.Add(m_objects_model->GetItemByInstanceId(selection.get_object_idx(), selection.get_instance_idx()));
}
else if (selection.is_single_full_object() || selection.is_multiple_full_object())
{
@ -2677,18 +2756,10 @@ void ObjectList::rename_item()
update_name_in_model(item);
}
void ObjectList::fix_through_netfabb() const
void ObjectList::fix_through_netfabb()
{
const wxDataViewItem item = GetSelection();
if (!item)
return;
const ItemType type = m_objects_model->GetItemType(item);
const int obj_idx = type & itObject ? m_objects_model->GetIdByItem(item) :
type & itVolume ? m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item)) : -1;
const int vol_idx = type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1;
int obj_idx, vol_idx;
get_selected_item_indexes(obj_idx, vol_idx);
wxGetApp().plater()->fix_through_netfabb(obj_idx, vol_idx);
@ -2702,28 +2773,27 @@ void ObjectList::update_item_error_icon(const int obj_idx, const int vol_idx) co
if (!item)
return;
auto model_object = (*m_objects)[obj_idx];
const stl_stats& stats = model_object->volumes[vol_idx<0 ? 0 : vol_idx]->mesh.stl.stats;
const int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
if (errors == 0) {
// delete Error_icon if all errors are fixed
wxVariant variant;
variant << DataViewBitmapText(from_u8(model_object->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);
}
}
void ObjectList::msw_rescale()
{
const int em = wxGetApp().em_unit();
// update min size !!! A width of control shouldn't be a wxDefaultCoord
SetMinSize(wxSize(1, 15 * wxGetApp().em_unit()));
SetMinSize(wxSize(1, 15 * em));
GetColumn(0)->SetWidth(19 * wxGetApp().em_unit());
GetColumn(1)->SetWidth(8 * wxGetApp().em_unit());
GetColumn(2)->SetWidth(int(2 * wxGetApp().em_unit()));
GetColumn(0)->SetWidth(19 * em);
GetColumn(1)->SetWidth( 8 * em);
GetColumn(2)->SetWidth( 2 * em);
// rescale all icons, used by ObjectList
rescale_icons();