mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06: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:
		
							parent
							
								
									9dbb2dfe0d
								
							
						
					
					
						commit
						049dfd3e08
					
				
					 9 changed files with 29 additions and 30 deletions
				
			
		|  | @ -1950,7 +1950,7 @@ void ObjectList::load_modifier(const wxArrayString& input_files, ModelObject& mo | |||
|     const BoundingBoxf3 instance_bb = model_object.instance_bounding_box(instance_idx); | ||||
| 
 | ||||
|     // First (any) GLVolume of the selected instance. They all share the same instance matrix.
 | ||||
|     const GLVolume* v = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|     const GLVolume* v = selection.get_first_volume(); | ||||
|     const Geometry::Transformation inst_transform = v->get_instance_transformation(); | ||||
|     const Transform3d inv_inst_transform = inst_transform.get_matrix(true).inverse(); | ||||
|     const Vec3d instance_offset = v->get_instance_offset(); | ||||
|  | @ -2086,7 +2086,7 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode | |||
|     ModelVolume *new_volume = model_object.add_volume(std::move(mesh), type); | ||||
| 
 | ||||
|     // First (any) GLVolume of the selected instance. They all share the same instance matrix.
 | ||||
|     const GLVolume* v = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|     const GLVolume* v = selection.get_first_volume(); | ||||
|     // Transform the new modifier to be aligned with the print bed.
 | ||||
| 	const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box(); | ||||
|     new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(v->get_instance_transformation(), mesh_bb)); | ||||
|  | @ -4350,7 +4350,7 @@ void ObjectList::update_selections() | |||
|             sels.Add(m_objects_model->GetItemById(selection.get_object_idx())); | ||||
|         } | ||||
|         else if (selection.is_single_volume() || selection.is_any_modifier()) { | ||||
|             const auto gl_vol = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|             const auto gl_vol = selection.get_first_volume(); | ||||
|             if (m_objects_model->GetVolumeIdByItem(m_objects_model->GetParent(item)) == gl_vol->volume_idx()) | ||||
|                 return; | ||||
|         } | ||||
|  | @ -4426,8 +4426,7 @@ void ObjectList::update_selections() | |||
|     { | ||||
|         if (m_selection_mode & smSettings) | ||||
|         { | ||||
|             const auto idx = *selection.get_volume_idxs().begin(); | ||||
|             const auto gl_vol = selection.get_volume(idx); | ||||
|             const auto gl_vol = selection.get_first_volume(); | ||||
|             if (gl_vol->volume_idx() >= 0) { | ||||
|                 // Only add GLVolumes with non-negative volume_ids. GLVolumes with negative volume ids
 | ||||
|                 // are not associated with ModelVolumes, but they are temporarily generated by the backend
 | ||||
|  |  | |||
|  | @ -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())) { | ||||
|  |  | |||
|  | @ -4033,7 +4033,7 @@ int Plater::priv::get_selected_volume_idx() const | |||
|     int idx = selection.get_object_idx(); | ||||
|     if ((0 > idx) || (idx > 1000)) | ||||
|         return-1; | ||||
|     const GLVolume* v = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|     const GLVolume* v = selection.get_first_volume(); | ||||
|     if (model.objects[idx]->volumes.size() > 1) | ||||
|         return v->volume_idx(); | ||||
|     return -1; | ||||
|  | @ -4844,7 +4844,7 @@ void Plater::priv::replace_with_stl() | |||
|     if (selection.is_wipe_tower() || get_selection().get_volume_idxs().size() != 1) | ||||
|         return; | ||||
| 
 | ||||
|     const GLVolume* v = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|     const GLVolume* v = selection.get_first_volume(); | ||||
|     int object_idx = v->object_idx(); | ||||
|     int volume_idx = v->volume_idx(); | ||||
| 
 | ||||
|  | @ -7154,7 +7154,7 @@ bool Plater::priv::can_edit_text() const | |||
|         return true; | ||||
| 
 | ||||
|     if (selection.is_single_volume()) { | ||||
|         const GLVolume *gl_volume      = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|         const GLVolume *gl_volume      = selection.get_first_volume(); | ||||
|         int             out_object_idx = gl_volume->object_idx(); | ||||
|         ModelObject *   model_object   = selection.get_model()->objects[out_object_idx]; | ||||
|         int             out_volume_idx = gl_volume->volume_idx(); | ||||
|  | @ -10334,7 +10334,7 @@ void Plater::export_stl(bool extended, bool selection_only) | |||
|             if (selection.get_mode() == Selection::Instance) | ||||
|                 mesh = mesh_to_export(*model_object, (model_object->instances.size() > 1) ? -1 : selection.get_instance_idx()); | ||||
|             else { | ||||
|                 const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); | ||||
|                 const GLVolume* volume = selection.get_first_volume(); | ||||
|                 mesh = model_object->volumes[volume->volume_idx()]->mesh(); | ||||
|                 mesh.transform(volume->get_volume_transformation().get_matrix(), true); | ||||
|             } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 enricoturri1966
						enricoturri1966