This commit is contained in:
Enrico Turri 2019-09-02 11:56:33 +02:00
commit bbfe420769
3 changed files with 40 additions and 15 deletions

View File

@ -2152,9 +2152,36 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const
if (!m_volumes.empty())
{
// removes empty volumes
m_volumes.volumes.erase(std::remove_if(m_volumes.volumes.begin(), m_volumes.volumes.end(),
[](const GLVolume* volume) { return volume->print_zs.empty(); }), m_volumes.volumes.end());
// Remove empty volumes from both m_volumes, update m_gcode_preview_volume_index.
{
size_t idx_volume_src = 0;
size_t idx_volume_dst = 0;
size_t idx_volume_index_src = 0;
size_t idx_volume_index_dst = 0;
size_t idx_volume_of_this_type_last = (idx_volume_index_src + 1 == m_gcode_preview_volume_index.first_volumes.size()) ? m_volumes.volumes.size() : m_gcode_preview_volume_index.first_volumes[idx_volume_index_src + 1].id;
size_t idx_volume_of_this_type_first_new = 0;
for (;;) {
if (idx_volume_src == idx_volume_of_this_type_last) {
if (idx_volume_of_this_type_first_new < idx_volume_dst) {
// There are some volumes of this type left, therefore their entry in the index has to be maintained.
if (idx_volume_index_dst < idx_volume_index_src)
m_gcode_preview_volume_index.first_volumes[idx_volume_index_dst] = m_gcode_preview_volume_index.first_volumes[idx_volume_index_src];
m_gcode_preview_volume_index.first_volumes[idx_volume_index_dst].id = idx_volume_of_this_type_first_new;
++ idx_volume_index_dst;
}
if (idx_volume_of_this_type_last == m_volumes.volumes.size())
break;
++ idx_volume_index_src;
idx_volume_of_this_type_last = (idx_volume_index_src + 1 == m_gcode_preview_volume_index.first_volumes.size()) ? m_volumes.volumes.size() : m_gcode_preview_volume_index.first_volumes[idx_volume_index_src + 1].id;
idx_volume_of_this_type_first_new = idx_volume_dst;
}
if (! m_volumes.volumes[idx_volume_src]->print_zs.empty())
m_volumes.volumes[idx_volume_dst ++] = m_volumes.volumes[idx_volume_src];
++ idx_volume_src;
}
m_volumes.volumes.erase(m_volumes.volumes.begin() + idx_volume_dst, m_volumes.volumes.end());
m_gcode_preview_volume_index.first_volumes.erase(m_gcode_preview_volume_index.first_volumes.begin() + idx_volume_index_dst, m_gcode_preview_volume_index.first_volumes.end());
}
_load_fff_shells();
}
@ -5097,7 +5124,7 @@ void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_dat
unsigned int role = (unsigned int)(&filters - &roles_filters.front());
for (std::pair<float, GLVolume*> &filter : filters)
if (filter.second->indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) {
if (m_gcode_preview_volume_index.first_volumes.back().id != role)
if (m_gcode_preview_volume_index.first_volumes.back().type != GCodePreviewVolumeIndex::Extrusion || m_gcode_preview_volume_index.first_volumes.back().flag != role)
m_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Extrusion, role, (unsigned int)m_volumes.volumes.size());
GLVolume& vol = *filter.second;
filter.second = m_volumes.new_toolpath_volume(vol.color);

View File

@ -1532,7 +1532,9 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
}
// Paint a lock at the system presets.
bmps.emplace_back(m_bitmapCache->mkclear(space_icon_width, icon_height));
bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmapLock : m_bitmapCache->mkclear(normal_icon_width, icon_height));
// To avoid asserts, each added bitmap to wxBitmapCombobox should be the same size, so
// for nonsystem presets set a width of empty bitmap to m_bitmapLock->GetWidth()
bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmapLock : m_bitmapCache->mkclear(m_bitmapLock->GetWidth(), icon_height));
// (preset.is_dirty ? *m_bitmapLockOpen : *m_bitmapLock) : m_bitmapCache->mkclear(16, 16));
bitmap = m_bitmapCache->insert(bitmap_key, bmps);
}

View File

@ -786,7 +786,12 @@ wxDataViewItem ObjectDataViewModel::AddInstanceRoot(const wxDataViewItem &parent
wxDataViewItem ObjectDataViewModel::AddInstanceChild(const wxDataViewItem &parent_item, size_t num)
{
const std::vector<bool> print_indicator(num, true);
std::vector<bool> print_indicator(num, true);
// if InstanceRoot item isn't created for this moment
if (!GetInstanceRootItem(parent_item).IsOk())
// use object's printable state to first instance
print_indicator[0] = IsPrintable(parent_item);
return wxDataViewItem((void*)AddInstanceChild(parent_item, print_indicator));
}
@ -799,21 +804,12 @@ wxDataViewItem ObjectDataViewModel::AddInstanceChild(const wxDataViewItem& paren
ObjectDataViewModelNode* inst_root_node = (ObjectDataViewModelNode*)inst_root_item.GetID();
const bool just_created = inst_root_node->GetChildren().Count() == 0;
// Add instance nodes
ObjectDataViewModelNode *instance_node = nullptr;
size_t counter = 0;
while (counter < print_indicator.size()) {
instance_node = new ObjectDataViewModelNode(inst_root_node, itInstance);
// // if InstanceRoot item is just created and start to adding Instances
// if (just_created && counter == 0) {
// ObjectDataViewModelNode* obj_node = (ObjectDataViewModelNode*)parent_item.GetID();
// // use object's printable state to first instance
// instance_node->set_printable_icon(obj_node->IsPrintable());
// }
// else
instance_node->set_printable_icon(print_indicator[counter] ? piPrintable : piUnprintable);
inst_root_node->Append(instance_node);