Removed mutable members from class Selection

This commit is contained in:
enricoturri1966 2021-04-16 15:25:03 +02:00
parent a393df59d7
commit 4c464b35f9
2 changed files with 45 additions and 57 deletions

View file

@ -1102,39 +1102,32 @@ void Selection::erase()
if (is_single_full_object()) if (is_single_full_object())
wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itObject, get_object_idx(), 0); wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itObject, get_object_idx(), 0);
else if (is_multiple_full_object()) else if (is_multiple_full_object()) {
{
std::vector<ItemForDelete> items; std::vector<ItemForDelete> items;
items.reserve(m_cache.content.size()); items.reserve(m_cache.content.size());
for (ObjectIdxsToInstanceIdxsMap::iterator it = m_cache.content.begin(); it != m_cache.content.end(); ++it) for (ObjectIdxsToInstanceIdxsMap::iterator it = m_cache.content.begin(); it != m_cache.content.end(); ++it) {
{
items.emplace_back(ItemType::itObject, it->first, 0); items.emplace_back(ItemType::itObject, it->first, 0);
} }
wxGetApp().obj_list()->delete_from_model_and_list(items); wxGetApp().obj_list()->delete_from_model_and_list(items);
} }
else if (is_multiple_full_instance()) else if (is_multiple_full_instance()) {
{
std::set<std::pair<int, int>> instances_idxs; std::set<std::pair<int, int>> instances_idxs;
for (ObjectIdxsToInstanceIdxsMap::iterator obj_it = m_cache.content.begin(); obj_it != m_cache.content.end(); ++obj_it) for (ObjectIdxsToInstanceIdxsMap::iterator obj_it = m_cache.content.begin(); obj_it != m_cache.content.end(); ++obj_it) {
{ for (InstanceIdxsList::reverse_iterator inst_it = obj_it->second.rbegin(); inst_it != obj_it->second.rend(); ++inst_it) {
for (InstanceIdxsList::reverse_iterator inst_it = obj_it->second.rbegin(); inst_it != obj_it->second.rend(); ++inst_it)
{
instances_idxs.insert(std::make_pair(obj_it->first, *inst_it)); instances_idxs.insert(std::make_pair(obj_it->first, *inst_it));
} }
} }
std::vector<ItemForDelete> items; std::vector<ItemForDelete> items;
items.reserve(instances_idxs.size()); items.reserve(instances_idxs.size());
for (const std::pair<int, int>& i : instances_idxs) for (const std::pair<int, int>& i : instances_idxs) {
{
items.emplace_back(ItemType::itInstance, i.first, i.second); items.emplace_back(ItemType::itInstance, i.first, i.second);
} }
wxGetApp().obj_list()->delete_from_model_and_list(items); wxGetApp().obj_list()->delete_from_model_and_list(items);
} }
else if (is_single_full_instance()) else if (is_single_full_instance())
wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itInstance, get_object_idx(), get_instance_idx()); wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itInstance, get_object_idx(), get_instance_idx());
else if (is_mixed()) else if (is_mixed()) {
{
std::set<ItemForDelete> items_set; std::set<ItemForDelete> items_set;
std::map<int, int> volumes_in_obj; std::map<int, int> volumes_in_obj;
@ -1186,11 +1179,9 @@ void Selection::erase()
wxGetApp().obj_list()->delete_from_model_and_list(items); wxGetApp().obj_list()->delete_from_model_and_list(items);
} }
else else {
{
std::set<std::pair<int, int>> volumes_idxs; std::set<std::pair<int, int>> volumes_idxs;
for (unsigned int i : m_list) for (unsigned int i : m_list) {
{
const GLVolume* v = (*m_volumes)[i]; const GLVolume* v = (*m_volumes)[i];
// Only remove volumes associated with ModelVolumes from the object list. // Only remove volumes associated with ModelVolumes from the object list.
// Temporary meshes (SLA supports or pads) are not managed by the object list. // Temporary meshes (SLA supports or pads) are not managed by the object list.
@ -1200,8 +1191,7 @@ void Selection::erase()
std::vector<ItemForDelete> items; std::vector<ItemForDelete> items;
items.reserve(volumes_idxs.size()); items.reserve(volumes_idxs.size());
for (const std::pair<int, int>& v : volumes_idxs) for (const std::pair<int, int>& v : volumes_idxs) {
{
items.emplace_back(ItemType::itVolume, v.first, v.second); items.emplace_back(ItemType::itVolume, v.first, v.second);
} }
@ -1214,7 +1204,7 @@ void Selection::render(float scale_factor) const
if (!m_valid || is_empty()) if (!m_valid || is_empty())
return; return;
m_scale_factor = scale_factor; *const_cast<float*>(&m_scale_factor) = scale_factor;
// render cumulative bounding box of selected volumes // render cumulative bounding box of selected volumes
render_selected_volumes(); render_selected_volumes();
@ -1224,7 +1214,7 @@ void Selection::render(float scale_factor) const
#if ENABLE_RENDER_SELECTION_CENTER #if ENABLE_RENDER_SELECTION_CENTER
void Selection::render_center(bool gizmo_is_dragging) const void Selection::render_center(bool gizmo_is_dragging) const
{ {
if (!m_valid || is_empty() || (m_quadric == nullptr)) if (!m_valid || is_empty() || m_quadric == nullptr)
return; return;
Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center(); Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center();
@ -1250,8 +1240,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) const
GLShaderProgram* shader = nullptr; GLShaderProgram* shader = nullptr;
if (!boost::starts_with(sidebar_field, "layer")) if (!boost::starts_with(sidebar_field, "layer")) {
{
shader = wxGetApp().get_shader("gouraud_light"); shader = wxGetApp().get_shader("gouraud_light");
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -1735,18 +1724,16 @@ void Selection::do_remove_volume(unsigned int volume_idx)
void Selection::do_remove_instance(unsigned int object_idx, unsigned int instance_idx) void Selection::do_remove_instance(unsigned int object_idx, unsigned int instance_idx)
{ {
for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) {
{
GLVolume* v = (*m_volumes)[i]; GLVolume* v = (*m_volumes)[i];
if ((v->object_idx() == (int)object_idx) && (v->instance_idx() == (int)instance_idx)) if (v->object_idx() == (int)object_idx && v->instance_idx() == (int)instance_idx)
do_remove_volume(i); do_remove_volume(i);
} }
} }
void Selection::do_remove_object(unsigned int object_idx) void Selection::do_remove_object(unsigned int object_idx)
{ {
for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) {
{
GLVolume* v = (*m_volumes)[i]; GLVolume* v = (*m_volumes)[i];
if (v->object_idx() == (int)object_idx) if (v->object_idx() == (int)object_idx)
do_remove_volume(i); do_remove_volume(i);
@ -1755,47 +1742,48 @@ void Selection::do_remove_object(unsigned int object_idx)
void Selection::calc_bounding_box() const void Selection::calc_bounding_box() const
{ {
m_bounding_box = BoundingBoxf3(); BoundingBoxf3* bounding_box = const_cast<BoundingBoxf3*>(&m_bounding_box);
if (m_valid) *bounding_box = BoundingBoxf3();
{ if (m_valid) {
for (unsigned int i : m_list) for (unsigned int i : m_list) {
{ bounding_box->merge((*m_volumes)[i]->transformed_convex_hull_bounding_box());
m_bounding_box.merge((*m_volumes)[i]->transformed_convex_hull_bounding_box());
} }
} }
m_bounding_box_dirty = false; *const_cast<bool*>(&m_bounding_box_dirty) = false;
} }
void Selection::calc_unscaled_instance_bounding_box() const void Selection::calc_unscaled_instance_bounding_box() const
{ {
m_unscaled_instance_bounding_box = BoundingBoxf3(); BoundingBoxf3* unscaled_instance_bounding_box = const_cast<BoundingBoxf3*>(&m_unscaled_instance_bounding_box);
if (m_valid) { *unscaled_instance_bounding_box = BoundingBoxf3();
for (unsigned int i : m_list) { if (m_valid) {
const GLVolume &volume = *(*m_volumes)[i]; for (unsigned int i : m_list) {
const GLVolume& volume = *(*m_volumes)[i];
if (volume.is_modifier) if (volume.is_modifier)
continue; continue;
Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, true, false) * volume.get_volume_transformation().get_matrix(); Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, true, false) * volume.get_volume_transformation().get_matrix();
trafo.translation()(2) += volume.get_sla_shift_z(); trafo.translation()(2) += volume.get_sla_shift_z();
m_unscaled_instance_bounding_box.merge(volume.transformed_convex_hull_bounding_box(trafo)); unscaled_instance_bounding_box->merge(volume.transformed_convex_hull_bounding_box(trafo));
} }
} }
m_unscaled_instance_bounding_box_dirty = false; *const_cast<bool*>(&m_unscaled_instance_bounding_box_dirty) = false;
} }
void Selection::calc_scaled_instance_bounding_box() const void Selection::calc_scaled_instance_bounding_box() const
{ {
m_scaled_instance_bounding_box = BoundingBoxf3(); BoundingBoxf3* scaled_instance_bounding_box = const_cast<BoundingBoxf3*>(&m_scaled_instance_bounding_box);
*scaled_instance_bounding_box = BoundingBoxf3();
if (m_valid) { if (m_valid) {
for (unsigned int i : m_list) { for (unsigned int i : m_list) {
const GLVolume &volume = *(*m_volumes)[i]; const GLVolume& volume = *(*m_volumes)[i];
if (volume.is_modifier) if (volume.is_modifier)
continue; continue;
Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, false, false) * volume.get_volume_transformation().get_matrix(); Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, false, false) * volume.get_volume_transformation().get_matrix();
trafo.translation()(2) += volume.get_sla_shift_z(); trafo.translation()(2) += volume.get_sla_shift_z();
m_scaled_instance_bounding_box.merge(volume.transformed_convex_hull_bounding_box(trafo)); scaled_instance_bounding_box->merge(volume.transformed_convex_hull_bounding_box(trafo));
} }
} }
m_scaled_instance_bounding_box_dirty = false; *const_cast<bool*>(&m_scaled_instance_bounding_box_dirty) = false;
} }
void Selection::render_selected_volumes() const void Selection::render_selected_volumes() const

View file

@ -206,14 +206,14 @@ private:
IndicesList m_list; IndicesList m_list;
Cache m_cache; Cache m_cache;
Clipboard m_clipboard; Clipboard m_clipboard;
mutable BoundingBoxf3 m_bounding_box; BoundingBoxf3 m_bounding_box;
mutable bool m_bounding_box_dirty; bool m_bounding_box_dirty;
// Bounding box of a selection, with no instance scaling applied. This bounding box // Bounding box of a selection, with no instance scaling applied. This bounding box
// is useful for absolute scaling of tilted objects in world coordinate space. // is useful for absolute scaling of tilted objects in world coordinate space.
mutable BoundingBoxf3 m_unscaled_instance_bounding_box; BoundingBoxf3 m_unscaled_instance_bounding_box;
mutable bool m_unscaled_instance_bounding_box_dirty; bool m_unscaled_instance_bounding_box_dirty;
mutable BoundingBoxf3 m_scaled_instance_bounding_box; BoundingBoxf3 m_scaled_instance_bounding_box;
mutable bool m_scaled_instance_bounding_box_dirty; bool m_scaled_instance_bounding_box_dirty;
#if ENABLE_RENDER_SELECTION_CENTER #if ENABLE_RENDER_SELECTION_CENTER
GLUquadricObj* m_quadric; GLUquadricObj* m_quadric;
@ -222,7 +222,7 @@ private:
GLModel m_arrow; GLModel m_arrow;
GLModel m_curved_arrow; GLModel m_curved_arrow;
mutable float m_scale_factor; float m_scale_factor;
public: public:
Selection(); Selection();