Small refactoring
This commit is contained in:
parent
302b37dcd1
commit
86ac9ed91e
3 changed files with 244 additions and 244 deletions
|
@ -3724,7 +3724,7 @@ std::vector<int> GLCanvas3D::load_object(const Model& model, int obj_idx)
|
||||||
void GLCanvas3D::mirror_selection(Axis axis)
|
void GLCanvas3D::mirror_selection(Axis axis)
|
||||||
{
|
{
|
||||||
m_selection.mirror(axis);
|
m_selection.mirror(axis);
|
||||||
_on_mirror();
|
do_mirror();
|
||||||
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4318,7 +4318,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||||
case Gizmos::Scale:
|
case Gizmos::Scale:
|
||||||
{
|
{
|
||||||
m_selection.scale(m_gizmos.get_scale(), false);
|
m_selection.scale(m_gizmos.get_scale(), false);
|
||||||
_on_scale();
|
do_scale();
|
||||||
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
break;
|
break;
|
||||||
|
@ -4326,7 +4326,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||||
case Gizmos::Rotate:
|
case Gizmos::Rotate:
|
||||||
{
|
{
|
||||||
m_selection.rotate(m_gizmos.get_rotation(), false);
|
m_selection.rotate(m_gizmos.get_rotation(), false);
|
||||||
_on_rotate();
|
do_rotate();
|
||||||
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
break;
|
break;
|
||||||
|
@ -4390,7 +4390,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||||
if (m_gizmos.get_current_type() == Gizmos::Flatten) {
|
if (m_gizmos.get_current_type() == Gizmos::Flatten) {
|
||||||
// Rotate the object so the normal points downward:
|
// Rotate the object so the normal points downward:
|
||||||
m_selection.flattening_rotate(m_gizmos.get_flattening_normal());
|
m_selection.flattening_rotate(m_gizmos.get_flattening_normal());
|
||||||
_on_flatten();
|
do_flatten();
|
||||||
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4613,7 +4613,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||||
else if ((m_mouse.drag.move_volume_idx != -1) && m_mouse.dragging)
|
else if ((m_mouse.drag.move_volume_idx != -1) && m_mouse.dragging)
|
||||||
{
|
{
|
||||||
m_regenerate_volumes = false;
|
m_regenerate_volumes = false;
|
||||||
_on_move();
|
do_move();
|
||||||
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
wxGetApp().obj_manipul()->update_settings_value(m_selection);
|
||||||
}
|
}
|
||||||
else if (m_gizmos.get_current_type() == Gizmos::SlaSupports && m_hover_volume_id != -1)
|
else if (m_gizmos.get_current_type() == Gizmos::SlaSupports && m_hover_volume_id != -1)
|
||||||
|
@ -4651,17 +4651,17 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||||
case Gizmos::Move:
|
case Gizmos::Move:
|
||||||
{
|
{
|
||||||
m_regenerate_volumes = false;
|
m_regenerate_volumes = false;
|
||||||
_on_move();
|
do_move();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Gizmos::Scale:
|
case Gizmos::Scale:
|
||||||
{
|
{
|
||||||
_on_scale();
|
do_scale();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Gizmos::Rotate:
|
case Gizmos::Rotate:
|
||||||
{
|
{
|
||||||
_on_rotate();
|
do_rotate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -4770,6 +4770,232 @@ void GLCanvas3D::set_external_gizmo_widgets_parent(wxWindow *parent)
|
||||||
m_external_gizmo_widgets_parent = parent;
|
m_external_gizmo_widgets_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::do_move()
|
||||||
|
{
|
||||||
|
if (m_model == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
||||||
|
bool object_moved = false;
|
||||||
|
Vec3d wipe_tower_origin = Vec3d::Zero();
|
||||||
|
|
||||||
|
Selection::EMode selection_mode = m_selection.get_mode();
|
||||||
|
|
||||||
|
for (const GLVolume* v : m_volumes.volumes)
|
||||||
|
{
|
||||||
|
int object_idx = v->object_idx();
|
||||||
|
int instance_idx = v->instance_idx();
|
||||||
|
int volume_idx = v->volume_idx();
|
||||||
|
|
||||||
|
std::pair<int, int> done_id(object_idx, instance_idx);
|
||||||
|
|
||||||
|
if ((0 <= object_idx) && (object_idx < (int)m_model->objects.size()))
|
||||||
|
{
|
||||||
|
done.insert(done_id);
|
||||||
|
|
||||||
|
// Move instances/volumes
|
||||||
|
ModelObject* model_object = m_model->objects[object_idx];
|
||||||
|
if (model_object != nullptr)
|
||||||
|
{
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
if (selection_mode == Selection::Instance)
|
||||||
|
{
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
||||||
|
object_moved = true;
|
||||||
|
}
|
||||||
|
else if (selection_mode == Selection::Volume)
|
||||||
|
{
|
||||||
|
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
|
||||||
|
object_moved = true;
|
||||||
|
}
|
||||||
|
if (object_moved)
|
||||||
|
#else
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
||||||
|
object_moved = true;
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
model_object->invalidate_bounding_box();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (object_idx == 1000)
|
||||||
|
// Move a wipe tower proxy.
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
wipe_tower_origin = v->get_volume_offset();
|
||||||
|
#else
|
||||||
|
wipe_tower_origin = v->get_offset();
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixes sinking/flying instances
|
||||||
|
for (const std::pair<int, int>& i : done)
|
||||||
|
{
|
||||||
|
ModelObject* m = m_model->objects[i.first];
|
||||||
|
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||||
|
m_selection.translate(i.first, i.second, shift);
|
||||||
|
m->translate_instance(i.second, shift);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object_moved)
|
||||||
|
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_MOVED));
|
||||||
|
|
||||||
|
if (wipe_tower_origin != Vec3d::Zero())
|
||||||
|
post_event(Vec3dEvent(EVT_GLCANVAS_WIPETOWER_MOVED, std::move(wipe_tower_origin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::do_rotate()
|
||||||
|
{
|
||||||
|
if (m_model == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
||||||
|
|
||||||
|
Selection::EMode selection_mode = m_selection.get_mode();
|
||||||
|
|
||||||
|
for (const GLVolume* v : m_volumes.volumes)
|
||||||
|
{
|
||||||
|
int object_idx = v->object_idx();
|
||||||
|
if ((object_idx < 0) || ((int)m_model->objects.size() <= object_idx))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int instance_idx = v->instance_idx();
|
||||||
|
int volume_idx = v->volume_idx();
|
||||||
|
|
||||||
|
done.insert(std::pair<int, int>(object_idx, instance_idx));
|
||||||
|
|
||||||
|
// Rotate instances/volumes.
|
||||||
|
ModelObject* model_object = m_model->objects[object_idx];
|
||||||
|
if (model_object != nullptr)
|
||||||
|
{
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
if (selection_mode == Selection::Instance)
|
||||||
|
{
|
||||||
|
model_object->instances[instance_idx]->set_rotation(v->get_instance_rotation());
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
||||||
|
}
|
||||||
|
else if (selection_mode == Selection::Volume)
|
||||||
|
{
|
||||||
|
model_object->volumes[volume_idx]->set_rotation(v->get_volume_rotation());
|
||||||
|
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
model_object->instances[instance_idx]->set_rotation(v->get_rotation());
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
model_object->invalidate_bounding_box();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixes sinking/flying instances
|
||||||
|
for (const std::pair<int, int>& i : done)
|
||||||
|
{
|
||||||
|
ModelObject* m = m_model->objects[i.first];
|
||||||
|
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||||
|
m_selection.translate(i.first, i.second, shift);
|
||||||
|
m->translate_instance(i.second, shift);
|
||||||
|
}
|
||||||
|
|
||||||
|
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::do_scale()
|
||||||
|
{
|
||||||
|
if (m_model == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
||||||
|
|
||||||
|
Selection::EMode selection_mode = m_selection.get_mode();
|
||||||
|
|
||||||
|
for (const GLVolume* v : m_volumes.volumes)
|
||||||
|
{
|
||||||
|
int object_idx = v->object_idx();
|
||||||
|
if ((object_idx < 0) || ((int)m_model->objects.size() <= object_idx))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int instance_idx = v->instance_idx();
|
||||||
|
int volume_idx = v->volume_idx();
|
||||||
|
|
||||||
|
done.insert(std::pair<int, int>(object_idx, instance_idx));
|
||||||
|
|
||||||
|
// Rotate instances/volumes
|
||||||
|
ModelObject* model_object = m_model->objects[object_idx];
|
||||||
|
if (model_object != nullptr)
|
||||||
|
{
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
if (selection_mode == Selection::Instance)
|
||||||
|
{
|
||||||
|
model_object->instances[instance_idx]->set_scaling_factor(v->get_instance_scaling_factor());
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
||||||
|
}
|
||||||
|
else if (selection_mode == Selection::Volume)
|
||||||
|
{
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
||||||
|
model_object->volumes[volume_idx]->set_scaling_factor(v->get_volume_scaling_factor());
|
||||||
|
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
model_object->instances[instance_idx]->set_scaling_factor(v->get_scaling_factor());
|
||||||
|
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
model_object->invalidate_bounding_box();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixes sinking/flying instances
|
||||||
|
for (const std::pair<int, int>& i : done)
|
||||||
|
{
|
||||||
|
ModelObject* m = m_model->objects[i.first];
|
||||||
|
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||||
|
m_selection.translate(i.first, i.second, shift);
|
||||||
|
m->translate_instance(i.second, shift);
|
||||||
|
}
|
||||||
|
|
||||||
|
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::do_flatten()
|
||||||
|
{
|
||||||
|
do_rotate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::do_mirror()
|
||||||
|
{
|
||||||
|
if (m_model == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
||||||
|
|
||||||
|
Selection::EMode selection_mode = m_selection.get_mode();
|
||||||
|
|
||||||
|
for (const GLVolume* v : m_volumes.volumes)
|
||||||
|
{
|
||||||
|
int object_idx = v->object_idx();
|
||||||
|
if ((object_idx < 0) || ((int)m_model->objects.size() <= object_idx))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int instance_idx = v->instance_idx();
|
||||||
|
int volume_idx = v->volume_idx();
|
||||||
|
|
||||||
|
done.insert(std::pair<int, int>(object_idx, instance_idx));
|
||||||
|
|
||||||
|
// Mirror instances/volumes
|
||||||
|
ModelObject* model_object = m_model->objects[object_idx];
|
||||||
|
if (model_object != nullptr)
|
||||||
|
{
|
||||||
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
if (selection_mode == Selection::Instance)
|
||||||
|
model_object->instances[instance_idx]->set_mirror(v->get_instance_mirror());
|
||||||
|
else if (selection_mode == Selection::Volume)
|
||||||
|
model_object->volumes[volume_idx]->set_mirror(v->get_volume_mirror());
|
||||||
|
#else
|
||||||
|
model_object->instances[instance_idx]->set_mirror(v->get_mirror());
|
||||||
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||||
|
model_object->invalidate_bounding_box();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
||||||
|
}
|
||||||
|
|
||||||
bool GLCanvas3D::_is_shown_on_screen() const
|
bool GLCanvas3D::_is_shown_on_screen() const
|
||||||
{
|
{
|
||||||
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
|
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
|
||||||
|
@ -6616,232 +6842,6 @@ void GLCanvas3D::_show_warning_texture_if_needed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLCanvas3D::_on_move()
|
|
||||||
{
|
|
||||||
if (m_model == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
|
||||||
bool object_moved = false;
|
|
||||||
Vec3d wipe_tower_origin = Vec3d::Zero();
|
|
||||||
|
|
||||||
Selection::EMode selection_mode = m_selection.get_mode();
|
|
||||||
|
|
||||||
for (const GLVolume* v : m_volumes.volumes)
|
|
||||||
{
|
|
||||||
int object_idx = v->object_idx();
|
|
||||||
int instance_idx = v->instance_idx();
|
|
||||||
int volume_idx = v->volume_idx();
|
|
||||||
|
|
||||||
std::pair<int, int> done_id(object_idx, instance_idx);
|
|
||||||
|
|
||||||
if ((0 <= object_idx) && (object_idx < (int)m_model->objects.size()))
|
|
||||||
{
|
|
||||||
done.insert(done_id);
|
|
||||||
|
|
||||||
// Move instances/volumes
|
|
||||||
ModelObject* model_object = m_model->objects[object_idx];
|
|
||||||
if (model_object != nullptr)
|
|
||||||
{
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
if (selection_mode == Selection::Instance)
|
|
||||||
{
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
|
||||||
object_moved = true;
|
|
||||||
}
|
|
||||||
else if (selection_mode == Selection::Volume)
|
|
||||||
{
|
|
||||||
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
|
|
||||||
object_moved = true;
|
|
||||||
}
|
|
||||||
if (object_moved)
|
|
||||||
#else
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
|
||||||
object_moved = true;
|
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
model_object->invalidate_bounding_box();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (object_idx == 1000)
|
|
||||||
// Move a wipe tower proxy.
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
wipe_tower_origin = v->get_volume_offset();
|
|
||||||
#else
|
|
||||||
wipe_tower_origin = v->get_offset();
|
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fixes sinking/flying instances
|
|
||||||
for (const std::pair<int, int>& i : done)
|
|
||||||
{
|
|
||||||
ModelObject* m = m_model->objects[i.first];
|
|
||||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
|
||||||
m_selection.translate(i.first, i.second, shift);
|
|
||||||
m->translate_instance(i.second, shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object_moved)
|
|
||||||
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_MOVED));
|
|
||||||
|
|
||||||
if (wipe_tower_origin != Vec3d::Zero())
|
|
||||||
post_event(Vec3dEvent(EVT_GLCANVAS_WIPETOWER_MOVED, std::move(wipe_tower_origin)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLCanvas3D::_on_rotate()
|
|
||||||
{
|
|
||||||
if (m_model == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
|
||||||
|
|
||||||
Selection::EMode selection_mode = m_selection.get_mode();
|
|
||||||
|
|
||||||
for (const GLVolume* v : m_volumes.volumes)
|
|
||||||
{
|
|
||||||
int object_idx = v->object_idx();
|
|
||||||
if ((object_idx < 0) || ((int)m_model->objects.size() <= object_idx))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int instance_idx = v->instance_idx();
|
|
||||||
int volume_idx = v->volume_idx();
|
|
||||||
|
|
||||||
done.insert(std::pair<int, int>(object_idx, instance_idx));
|
|
||||||
|
|
||||||
// Rotate instances/volumes.
|
|
||||||
ModelObject* model_object = m_model->objects[object_idx];
|
|
||||||
if (model_object != nullptr)
|
|
||||||
{
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
if (selection_mode == Selection::Instance)
|
|
||||||
{
|
|
||||||
model_object->instances[instance_idx]->set_rotation(v->get_instance_rotation());
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
|
||||||
}
|
|
||||||
else if (selection_mode == Selection::Volume)
|
|
||||||
{
|
|
||||||
model_object->volumes[volume_idx]->set_rotation(v->get_volume_rotation());
|
|
||||||
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
model_object->instances[instance_idx]->set_rotation(v->get_rotation());
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
model_object->invalidate_bounding_box();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fixes sinking/flying instances
|
|
||||||
for (const std::pair<int, int>& i : done)
|
|
||||||
{
|
|
||||||
ModelObject* m = m_model->objects[i.first];
|
|
||||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
|
||||||
m_selection.translate(i.first, i.second, shift);
|
|
||||||
m->translate_instance(i.second, shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLCanvas3D::_on_scale()
|
|
||||||
{
|
|
||||||
if (m_model == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
|
||||||
|
|
||||||
Selection::EMode selection_mode = m_selection.get_mode();
|
|
||||||
|
|
||||||
for (const GLVolume* v : m_volumes.volumes)
|
|
||||||
{
|
|
||||||
int object_idx = v->object_idx();
|
|
||||||
if ((object_idx < 0) || ((int)m_model->objects.size() <= object_idx))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int instance_idx = v->instance_idx();
|
|
||||||
int volume_idx = v->volume_idx();
|
|
||||||
|
|
||||||
done.insert(std::pair<int, int>(object_idx, instance_idx));
|
|
||||||
|
|
||||||
// Rotate instances/volumes
|
|
||||||
ModelObject* model_object = m_model->objects[object_idx];
|
|
||||||
if (model_object != nullptr)
|
|
||||||
{
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
if (selection_mode == Selection::Instance)
|
|
||||||
{
|
|
||||||
model_object->instances[instance_idx]->set_scaling_factor(v->get_instance_scaling_factor());
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
|
||||||
}
|
|
||||||
else if (selection_mode == Selection::Volume)
|
|
||||||
{
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
|
|
||||||
model_object->volumes[volume_idx]->set_scaling_factor(v->get_volume_scaling_factor());
|
|
||||||
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
model_object->instances[instance_idx]->set_scaling_factor(v->get_scaling_factor());
|
|
||||||
model_object->instances[instance_idx]->set_offset(v->get_offset());
|
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
model_object->invalidate_bounding_box();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fixes sinking/flying instances
|
|
||||||
for (const std::pair<int, int>& i : done)
|
|
||||||
{
|
|
||||||
ModelObject* m = m_model->objects[i.first];
|
|
||||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
|
||||||
m_selection.translate(i.first, i.second, shift);
|
|
||||||
m->translate_instance(i.second, shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLCanvas3D::_on_flatten()
|
|
||||||
{
|
|
||||||
_on_rotate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLCanvas3D::_on_mirror()
|
|
||||||
{
|
|
||||||
if (m_model == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::set<std::pair<int, int>> done; // keeps track of modified instances
|
|
||||||
|
|
||||||
Selection::EMode selection_mode = m_selection.get_mode();
|
|
||||||
|
|
||||||
for (const GLVolume* v : m_volumes.volumes)
|
|
||||||
{
|
|
||||||
int object_idx = v->object_idx();
|
|
||||||
if ((object_idx < 0) || ((int)m_model->objects.size() <= object_idx))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int instance_idx = v->instance_idx();
|
|
||||||
int volume_idx = v->volume_idx();
|
|
||||||
|
|
||||||
done.insert(std::pair<int, int>(object_idx, instance_idx));
|
|
||||||
|
|
||||||
// Mirror instances/volumes
|
|
||||||
ModelObject* model_object = m_model->objects[object_idx];
|
|
||||||
if (model_object != nullptr)
|
|
||||||
{
|
|
||||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
if (selection_mode == Selection::Instance)
|
|
||||||
model_object->instances[instance_idx]->set_mirror(v->get_instance_mirror());
|
|
||||||
else if (selection_mode == Selection::Volume)
|
|
||||||
model_object->volumes[volume_idx]->set_mirror(v->get_volume_mirror());
|
|
||||||
#else
|
|
||||||
model_object->instances[instance_idx]->set_mirror(v->get_mirror());
|
|
||||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
|
||||||
model_object->invalidate_bounding_box();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
||||||
{
|
{
|
||||||
static const float INV_255 = 1.0f / 255.0f;
|
static const float INV_255 = 1.0f / 255.0f;
|
||||||
|
|
|
@ -846,6 +846,12 @@ public:
|
||||||
|
|
||||||
void set_external_gizmo_widgets_parent(wxWindow *parent);
|
void set_external_gizmo_widgets_parent(wxWindow *parent);
|
||||||
|
|
||||||
|
void do_move();
|
||||||
|
void do_rotate();
|
||||||
|
void do_scale();
|
||||||
|
void do_flatten();
|
||||||
|
void do_mirror();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _is_shown_on_screen() const;
|
bool _is_shown_on_screen() const;
|
||||||
void _force_zoom_to_bed();
|
void _force_zoom_to_bed();
|
||||||
|
@ -929,13 +935,7 @@ private:
|
||||||
void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data);
|
void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data);
|
||||||
void _update_toolpath_volumes_outside_state();
|
void _update_toolpath_volumes_outside_state();
|
||||||
void _show_warning_texture_if_needed();
|
void _show_warning_texture_if_needed();
|
||||||
public:
|
|
||||||
void _on_move();
|
|
||||||
void _on_rotate();
|
|
||||||
void _on_scale();
|
|
||||||
void _on_flatten();
|
|
||||||
void _on_mirror();
|
|
||||||
private:
|
|
||||||
// generates the legend texture in dependence of the current shown view type
|
// generates the legend texture in dependence of the current shown view type
|
||||||
void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
|
void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
|
||||||
|
|
||||||
|
|
|
@ -404,7 +404,7 @@ void ObjectManipulation::change_position_value(const Vec3d& position)
|
||||||
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
||||||
canvas->get_selection().start_dragging();
|
canvas->get_selection().start_dragging();
|
||||||
canvas->get_selection().translate(displacement);
|
canvas->get_selection().translate(displacement);
|
||||||
canvas->_on_move();
|
canvas->do_move();
|
||||||
|
|
||||||
cache_position = position;
|
cache_position = position;
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
|
||||||
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
||||||
canvas->get_selection().start_dragging();
|
canvas->get_selection().start_dragging();
|
||||||
canvas->get_selection().rotate(rad_rotation, false);
|
canvas->get_selection().rotate(rad_rotation, false);
|
||||||
canvas->_on_rotate();
|
canvas->do_rotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectManipulation::change_scale_value(const Vec3d& scale)
|
void ObjectManipulation::change_scale_value(const Vec3d& scale)
|
||||||
|
@ -437,7 +437,7 @@ void ObjectManipulation::change_scale_value(const Vec3d& scale)
|
||||||
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D());
|
||||||
canvas->get_selection().start_dragging();
|
canvas->get_selection().start_dragging();
|
||||||
canvas->get_selection().scale(scaling_factor, false);
|
canvas->get_selection().scale(scaling_factor, false);
|
||||||
canvas->_on_scale();
|
canvas->do_scale();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& v)
|
void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& v)
|
||||||
|
|
Loading…
Reference in a new issue