mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-30 14:22:07 +00:00
Added method const GLVolume* Selection::get_first_volume() const to simplify client code
(cherry picked from commit prusa3d/PrusaSlicer@0e3490620e)
This commit is contained in:
committed by
Noisyfox
parent
9dbb2dfe0d
commit
049dfd3e08
@@ -621,7 +621,7 @@ void GLGizmoAdvancedCut::perform_cut(const Selection& selection)
|
||||
wxCHECK_RET(instance_idx >= 0 && object_idx >= 0, "GLGizmoAdvancedCut: Invalid object selection");
|
||||
|
||||
// m_cut_z is the distance from the bed. Subtract possible SLA elevation.
|
||||
const GLVolume* first_glvolume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* first_glvolume = selection.get_first_volume();
|
||||
|
||||
// perform cut
|
||||
{
|
||||
|
||||
@@ -341,7 +341,7 @@ BoundingBoxf3 GLGizmoPainterBase::bounding_box() const
|
||||
void GLGizmoPainterBase::update_contours(const TriangleMesh& vol_mesh, float cursor_z, float max_z, float min_z) const
|
||||
{
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
const GLVolume* first_glvolume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* first_glvolume = selection.get_first_volume();
|
||||
const BoundingBoxf3& box = first_glvolume->transformed_convex_hull_bounding_box();
|
||||
|
||||
const ModelObject* model_object = wxGetApp().model().objects[selection.get_object_idx()];
|
||||
|
||||
@@ -432,7 +432,7 @@ Transform3d GLGizmoRotate::local_transform(const Selection& selection) const
|
||||
}
|
||||
|
||||
if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes())
|
||||
ret = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true) * ret;
|
||||
ret = selection.get_first_volume()->get_instance_transformation().get_matrix(true, false, true, true) * ret;
|
||||
|
||||
return Geometry::assemble_transform(m_center) * ret;
|
||||
}
|
||||
@@ -466,7 +466,7 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, cons
|
||||
}
|
||||
|
||||
if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes())
|
||||
m = m * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true).inverse();
|
||||
m = m * selection.get_first_volume()->get_instance_transformation().get_matrix(true, false, true, true).inverse();
|
||||
|
||||
m.translate(-m_center);
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ std::string GLGizmoScale3D::get_tooltip() const
|
||||
|
||||
Vec3f scale = 100.0f * Vec3f::Ones();
|
||||
if (single_instance)
|
||||
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor().cast<float>();
|
||||
scale = 100.0f * selection.get_first_volume()->get_instance_scaling_factor().cast<float>();
|
||||
else if (single_volume)
|
||||
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_scaling_factor().cast<float>();
|
||||
scale = 100.0f * selection.get_first_volume()->get_volume_scaling_factor().cast<float>();
|
||||
|
||||
if (m_hover_id == 0 || m_hover_id == 1 || m_grabbers[0].dragging || m_grabbers[1].dragging)
|
||||
return "X: " + format(scale.x(), 4) + "%";
|
||||
@@ -105,7 +105,7 @@ void GLGizmoScale3D::data_changed()
|
||||
if (enable_scale_xyz) {
|
||||
// all volumes in the selection belongs to the same instance, any of
|
||||
// them contains the needed data, so we take the first
|
||||
const GLVolume *volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume *volume = selection.get_first_volume();
|
||||
if (selection.is_single_full_instance()) {
|
||||
set_scale(volume->get_instance_scaling_factor());
|
||||
} else if (selection.is_single_volume() ||
|
||||
@@ -211,7 +211,7 @@ void GLGizmoScale3D::on_render()
|
||||
}
|
||||
|
||||
// gets transform from first selected volume
|
||||
const GLVolume* v = selection.get_volume(*idxs.begin());
|
||||
const GLVolume* v = selection.get_first_volume();
|
||||
m_transform = v->get_instance_transformation().get_matrix();
|
||||
// gets angles from first selected volume
|
||||
angles = v->get_instance_rotation();
|
||||
@@ -220,7 +220,7 @@ void GLGizmoScale3D::on_render()
|
||||
m_offsets_transform = offsets_transform;
|
||||
}
|
||||
else if (single_volume) {
|
||||
const GLVolume* v = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* v = selection.get_first_volume();
|
||||
m_box = v->bounding_box();
|
||||
m_transform = v->world_matrix();
|
||||
angles = Geometry::extract_euler_angles(m_transform);
|
||||
|
||||
@@ -652,7 +652,7 @@ void GLGizmoText::on_render_input_window(float x, float y, float bottom_limit)
|
||||
|
||||
const Selection &selection = m_parent.get_selection();
|
||||
if (selection.is_single_full_instance() || selection.is_single_full_object()) {
|
||||
const GLVolume * gl_volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume * gl_volume = selection.get_first_volume();
|
||||
int object_idx = gl_volume->object_idx();
|
||||
if (object_idx != m_object_idx || (object_idx == m_object_idx && m_volume_idx != -1)) {
|
||||
m_object_idx = object_idx;
|
||||
@@ -917,7 +917,7 @@ ModelVolume *GLGizmoText::get_selected_single_volume(int &out_object_idx, int &o
|
||||
{
|
||||
if (m_parent.get_selection().is_single_volume() || m_parent.get_selection().is_single_modifier()) {
|
||||
const Selection &selection = m_parent.get_selection();
|
||||
const GLVolume * gl_volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume * gl_volume = selection.get_first_volume();
|
||||
out_object_idx = gl_volume->object_idx();
|
||||
ModelObject *model_object = selection.get_model()->objects[out_object_idx];
|
||||
out_volume_idx = gl_volume->volume_idx();
|
||||
|
||||
@@ -119,7 +119,7 @@ void SelectionInfo::on_update()
|
||||
const Selection& selection = get_pool()->get_canvas()->get_selection();
|
||||
if (selection.is_single_full_instance()) {
|
||||
m_model_object = selection.get_model()->objects[selection.get_object_idx()];
|
||||
m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z();
|
||||
m_z_shift = selection.get_first_volume()->get_sla_shift_z();
|
||||
}
|
||||
else
|
||||
m_model_object = nullptr;
|
||||
|
||||
@@ -86,7 +86,7 @@ void GizmoObjectManipulation::update_settings_value(const Selection& selection)
|
||||
ObjectList* obj_list = wxGetApp().obj_list();
|
||||
if (selection.is_single_full_instance()) {
|
||||
// all volumes in the selection belongs to the same instance, any of them contains the needed instance data, so we take the first one
|
||||
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* volume = selection.get_first_volume();
|
||||
m_new_position = volume->get_instance_offset();
|
||||
|
||||
if (m_world_coordinates) {
|
||||
@@ -118,7 +118,7 @@ void GizmoObjectManipulation::update_settings_value(const Selection& selection)
|
||||
}
|
||||
else if (selection.is_single_modifier() || selection.is_single_volume()) {
|
||||
// the selection contains a single volume
|
||||
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* volume = selection.get_first_volume();
|
||||
m_new_position = volume->get_volume_offset();
|
||||
m_new_rotation = volume->get_volume_rotation() * (180. / M_PI);
|
||||
m_new_scale = volume->get_volume_scaling_factor() * 100.;
|
||||
@@ -217,7 +217,7 @@ void GizmoObjectManipulation::update_reset_buttons_visibility()
|
||||
const Selection& selection = m_glcanvas.get_selection();
|
||||
|
||||
if (selection.is_single_full_instance() || selection.is_single_modifier() || selection.is_single_volume()) {
|
||||
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* volume = selection.get_first_volume();
|
||||
Vec3d rotation;
|
||||
Vec3d scale;
|
||||
double min_z = 0.;
|
||||
@@ -331,14 +331,14 @@ void GizmoObjectManipulation::change_size_value(int axis, double value)
|
||||
|
||||
Vec3d ref_size = m_cache.size;
|
||||
if (selection.is_single_volume() || selection.is_single_modifier()) {
|
||||
Vec3d instance_scale = wxGetApp().model().objects[selection.get_volume(*selection.get_volume_idxs().begin())->object_idx()]->instances[0]->get_transformation().get_scaling_factor();
|
||||
ref_size = selection.get_volume(*selection.get_volume_idxs().begin())->bounding_box().size();
|
||||
Vec3d instance_scale = wxGetApp().model().objects[selection.get_first_volume()->object_idx()]->instances[0]->get_transformation().get_scaling_factor();
|
||||
ref_size = selection.get_first_volume()->bounding_box().size();
|
||||
ref_size = Vec3d(instance_scale[0] * ref_size[0], instance_scale[1] * ref_size[1], instance_scale[2] * ref_size[2]);
|
||||
}
|
||||
else if (selection.is_single_full_instance())
|
||||
ref_size = m_world_coordinates ?
|
||||
selection.get_unscaled_instance_bounding_box().size() :
|
||||
wxGetApp().model().objects[selection.get_volume(*selection.get_volume_idxs().begin())->object_idx()]->raw_mesh_bounding_box().size();
|
||||
wxGetApp().model().objects[selection.get_first_volume()->object_idx()]->raw_mesh_bounding_box().size();
|
||||
|
||||
this->do_scale(axis, 100. * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2)));
|
||||
|
||||
@@ -391,7 +391,7 @@ void GizmoObjectManipulation::reset_position_value()
|
||||
Selection& selection = m_glcanvas.get_selection();
|
||||
|
||||
if (selection.is_single_volume() || selection.is_single_modifier()) {
|
||||
GLVolume* volume = const_cast<GLVolume*>(selection.get_volume(*selection.get_volume_idxs().begin()));
|
||||
GLVolume* volume = const_cast<GLVolume*>(selection.get_first_volume());
|
||||
volume->set_volume_offset(Vec3d::Zero());
|
||||
}
|
||||
else if (selection.is_single_full_instance()) {
|
||||
@@ -414,7 +414,7 @@ void GizmoObjectManipulation::reset_rotation_value()
|
||||
Selection& selection = m_glcanvas.get_selection();
|
||||
|
||||
if (selection.is_single_volume() || selection.is_single_modifier()) {
|
||||
GLVolume* volume = const_cast<GLVolume*>(selection.get_volume(*selection.get_volume_idxs().begin()));
|
||||
GLVolume* volume = const_cast<GLVolume*>(selection.get_first_volume());
|
||||
volume->set_volume_rotation(Vec3d::Zero());
|
||||
}
|
||||
else if (selection.is_single_full_instance()) {
|
||||
@@ -450,7 +450,7 @@ void GizmoObjectManipulation::set_uniform_scaling(const bool new_value)
|
||||
if (selection.is_single_full_instance() && m_world_coordinates && !new_value) {
|
||||
// Verify whether the instance rotation is multiples of 90 degrees, so that the scaling in world coordinates is possible.
|
||||
// all volumes in the selection belongs to the same instance, any of them contains the needed instance data, so we take the first one
|
||||
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||
const GLVolume* volume = selection.get_first_volume();
|
||||
// Is the angle close to a multiple of 90 degrees?
|
||||
|
||||
if (! Geometry::is_rotation_ninety_degrees(volume->get_instance_rotation())) {
|
||||
|
||||
Reference in New Issue
Block a user