mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Merge branch 'et_gcode_viewer' of https://github.com/prusa3d/PrusaSlicer into et_gcode_viewer
This commit is contained in:
		
						commit
						afc378f317
					
				
					 17 changed files with 268 additions and 41 deletions
				
			
		|  | @ -993,6 +993,56 @@ void ModelObject::scale_mesh_after_creation(const Vec3d &versor) | |||
|     this->invalidate_bounding_box(); | ||||
| } | ||||
| 
 | ||||
| void ModelObject::convert_units(ModelObjectPtrs& new_objects, bool from_imperial, std::vector<int> volume_idxs) | ||||
| { | ||||
|     BOOST_LOG_TRIVIAL(trace) << "ModelObject::convert_units - start"; | ||||
| 
 | ||||
|     ModelObject* new_object = new_clone(*this); | ||||
| 
 | ||||
|     double koef = from_imperial ? 25.4 : 0.0393700787; | ||||
|     const Vec3d versor = Vec3d(koef, koef, koef); | ||||
| 
 | ||||
|     new_object->set_model(nullptr); | ||||
|     new_object->sla_support_points.clear(); | ||||
|     new_object->sla_drain_holes.clear(); | ||||
|     new_object->sla_points_status = sla::PointsStatus::NoPoints; | ||||
|     new_object->clear_volumes(); | ||||
|     new_object->input_file.clear(); | ||||
| 
 | ||||
|     int vol_idx = 0; | ||||
|     for (ModelVolume* volume : volumes) | ||||
|     { | ||||
|         volume->m_supported_facets.clear(); | ||||
|         if (!volume->mesh().empty()) { | ||||
|             TriangleMesh mesh(volume->mesh()); | ||||
|             mesh.require_shared_vertices(); | ||||
| 
 | ||||
|             ModelVolume* vol = new_object->add_volume(mesh); | ||||
|             vol->name = volume->name; | ||||
|             // Don't copy the config's ID.
 | ||||
|             static_cast<DynamicPrintConfig&>(vol->config) = static_cast<const DynamicPrintConfig&>(volume->config); | ||||
|             assert(vol->config.id().valid()); | ||||
|             assert(vol->config.id() != volume->config.id()); | ||||
|             vol->set_material(volume->material_id(), *volume->material()); | ||||
| 
 | ||||
|             // Perform conversion
 | ||||
|             if (volume_idxs.empty() ||  | ||||
|                 std::find(volume_idxs.begin(), volume_idxs.end(), vol_idx) != volume_idxs.end()) { | ||||
|                 vol->scale_geometry_after_creation(versor); | ||||
|                 vol->set_offset(versor.cwiseProduct(vol->get_offset())); | ||||
|             } | ||||
|             else | ||||
|                 vol->set_offset(volume->get_offset()); | ||||
|         } | ||||
|         vol_idx ++; | ||||
|     } | ||||
|     new_object->invalidate_bounding_box(); | ||||
| 
 | ||||
|     new_objects.push_back(new_object); | ||||
| 
 | ||||
|     BOOST_LOG_TRIVIAL(trace) << "ModelObject::convert_units - end"; | ||||
| } | ||||
| 
 | ||||
| size_t ModelObject::materials_count() const | ||||
| { | ||||
|     std::set<t_model_material_id> material_ids; | ||||
|  |  | |||
|  | @ -281,6 +281,7 @@ public: | |||
| 
 | ||||
|     // This method could only be called before the meshes of this ModelVolumes are not shared!
 | ||||
|     void scale_mesh_after_creation(const Vec3d& versor); | ||||
|     void convert_units(ModelObjectPtrs&new_objects, bool from_imperial, std::vector<int> volume_idxs); | ||||
| 
 | ||||
|     size_t materials_count() const; | ||||
|     size_t facets_count() const; | ||||
|  |  | |||
|  | @ -196,15 +196,18 @@ void Bed3D::Axes::render() const | |||
|     shader->start_using(); | ||||
| 
 | ||||
|     // x axis
 | ||||
|     shader->set_uniform("uniform_color", { 0.75f, 0.0f, 0.0f, 1.0f }); | ||||
|     std::array<float, 4> color = { 0.75f, 0.0f, 0.0f, 1.0f }; | ||||
|     shader->set_uniform("uniform_color", color); | ||||
|     render_axis(Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0f }).cast<float>()); | ||||
| 
 | ||||
|     // y axis
 | ||||
|     shader->set_uniform("uniform_color", { 0.0f, 0.75f, 0.0f, 1.0f }); | ||||
|     color = { 0.0f, 0.75f, 0.0f, 1.0f }; | ||||
|     shader->set_uniform("uniform_color", color); | ||||
|     render_axis(Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0f }).cast<float>()); | ||||
| 
 | ||||
|     // z axis
 | ||||
|     shader->set_uniform("uniform_color", { 0.0f, 0.0f, 0.75f, 1.0f }); | ||||
|     color = { 0.0f, 0.0f, 0.75f, 1.0f }; | ||||
|     shader->set_uniform("uniform_color", color); | ||||
|     render_axis(Geometry::assemble_transform(m_origin).cast<float>()); | ||||
| 
 | ||||
|     shader->stop_using(); | ||||
|  | @ -676,9 +679,19 @@ void Bed3D::render_model() const | |||
| 
 | ||||
|     if (!m_model.get_filename().empty()) | ||||
|     { | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|         GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); | ||||
|         if (shader != nullptr) | ||||
|         { | ||||
|             shader->start_using(); | ||||
|             m_model.render(); | ||||
|             shader->stop_using(); | ||||
|         } | ||||
| #else | ||||
|         glsafe(::glEnable(GL_LIGHTING)); | ||||
|         m_model.render(); | ||||
|         glsafe(::glDisable(GL_LIGHTING)); | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,10 @@ | |||
| #include <GL/glew.h> | ||||
| 
 | ||||
| #include "3DScene.hpp" | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
| #include "GLShader.hpp" | ||||
| #include "GUI_App.hpp" | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
| #include "libslic3r/ExtrusionEntity.hpp" | ||||
| #include "libslic3r/ExtrusionEntityCollection.hpp" | ||||
|  | @ -640,6 +644,12 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo | |||
| 
 | ||||
| void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) const | ||||
| { | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); | ||||
|     if (shader == nullptr) | ||||
|         return; | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
|     glsafe(::glEnable(GL_BLEND)); | ||||
|     glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); | ||||
| 
 | ||||
|  | @ -650,6 +660,15 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab | |||
|     glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); | ||||
|     glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); | ||||
|   | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     shader->set_uniform("print_box.min", m_print_box_min, 3); | ||||
|     shader->set_uniform("print_box.max", m_print_box_max, 3); | ||||
|     shader->set_uniform("z_range", m_z_range, 2); | ||||
|     shader->set_uniform("clipping_plane", m_clipping_plane, 4); | ||||
| #if ENABLE_SLOPE_RENDERING | ||||
|     shader->set_uniform("slope.z_range", m_slope.z_range); | ||||
| #endif // ENABLE_SLOPE_RENDERING
 | ||||
| #else | ||||
|     GLint current_program_id; | ||||
|     glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); | ||||
|     GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; | ||||
|  | @ -684,11 +703,19 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab | |||
|     if (slope_z_range_id != -1) | ||||
|         glsafe(::glUniform2fv(slope_z_range_id, 1, (const GLfloat*)m_slope.z_range.data())); | ||||
| #endif // ENABLE_SLOPE_RENDERING
 | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
|     GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func); | ||||
|     for (GLVolumeWithIdAndZ& volume : to_render) { | ||||
|         volume.first->set_render_color(); | ||||
| #if ENABLE_SLOPE_RENDERING | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|         shader->set_uniform("uniform_color", volume.first->render_color, 4); | ||||
|         shader->set_uniform("print_box.actived", volume.first->shader_outside_printer_detection_enabled); | ||||
|         shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix()); | ||||
|         shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower); | ||||
|         shader->set_uniform("slope.volume_world_normal_matrix", volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>()); | ||||
| #else | ||||
|         if (color_id >= 0) | ||||
|             glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)volume.first->render_color)); | ||||
|         else | ||||
|  | @ -708,6 +735,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab | |||
|             Matrix3f normal_matrix = volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>(); | ||||
|             glsafe(::glUniformMatrix3fv(slope_normal_matrix_id, 1, GL_FALSE, (const GLfloat*)normal_matrix.data())); | ||||
|         } | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
|         volume.first->render(); | ||||
| #else | ||||
|  | @ -1912,6 +1940,12 @@ void GLModel::reset() | |||
| 
 | ||||
| void GLModel::render() const | ||||
| { | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); | ||||
|     if (shader == nullptr) | ||||
|         return; | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
|     glsafe(::glEnable(GL_BLEND)); | ||||
|     glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); | ||||
| 
 | ||||
|  | @ -1919,16 +1953,22 @@ void GLModel::render() const | |||
|     glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); | ||||
|     glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); | ||||
| 
 | ||||
| #if !ENABLE_SHADERS_MANAGER | ||||
|     GLint current_program_id; | ||||
|     glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); | ||||
|     GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; | ||||
|     glcheck(); | ||||
| #endif // !ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
| #if ENABLE_SLOPE_RENDERING | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     shader->set_uniform("uniform_color", m_volume.render_color, 4); | ||||
| #else | ||||
|     if (color_id >= 0) | ||||
|         glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)m_volume.render_color)); | ||||
|     else | ||||
|         glsafe(::glColor4fv(m_volume.render_color)); | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
|     m_volume.render(); | ||||
| #else | ||||
|  |  | |||
|  | @ -26,12 +26,6 @@ inline void glAssertRecentCall() { } | |||
| #endif | ||||
| 
 | ||||
| namespace Slic3r { | ||||
| namespace GUI { | ||||
| class Bed3D; | ||||
| struct Camera; | ||||
| class GLToolbar; | ||||
| } // namespace GUI
 | ||||
| 
 | ||||
| class SLAPrintObject; | ||||
| enum  SLAPrintObjectStep : unsigned int; | ||||
| class DynamicPrintConfig; | ||||
|  |  | |||
|  | @ -490,16 +490,16 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G | |||
|     assert(this->last_object_id != -1); | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     GLShaderProgram* shader = wxGetApp().get_shader("variable_layer_height"); | ||||
|     assert(shader != nullptr); | ||||
|     if (shader == nullptr) | ||||
|         return; | ||||
| 
 | ||||
|     GLint current_program_id = 0; | ||||
|     glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); | ||||
|     if (shader->get_id() != static_cast<GLuint>(current_program_id)) | ||||
|     GLShaderProgram* current_shader = wxGetApp().get_current_shader(); | ||||
|     if (shader->get_id() != current_shader->get_id()) | ||||
|         // The layer editing shader is not yet active. Activate it.
 | ||||
|         shader->start_using(); | ||||
|     else | ||||
|         // The layer editing shader was already active.
 | ||||
|         current_program_id = 0; | ||||
|         current_shader = nullptr; | ||||
| 
 | ||||
|     const_cast<LayersEditing*>(this)->generate_layer_height_texture(); | ||||
| 
 | ||||
|  | @ -529,7 +529,6 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G | |||
|     GLint object_max_z_id = ::glGetUniformLocation(shader_id, "object_max_z"); | ||||
|     glcheck(); | ||||
| 
 | ||||
| 
 | ||||
|     if (z_to_texture_row_id != -1 && z_texture_row_to_normalized_id != -1 && z_cursor_id != -1 && z_cursor_band_width_id != -1 && world_matrix_id != -1) | ||||
|     { | ||||
|         const_cast<LayersEditing*>(this)->generate_layer_height_texture(); | ||||
|  | @ -568,9 +567,12 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G | |||
|         } | ||||
|         // Revert back to the previous shader.
 | ||||
|         glBindTexture(GL_TEXTURE_2D, 0); | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|         if (current_shader != nullptr) | ||||
|             current_shader->start_using(); | ||||
| #else | ||||
|         if (current_program_id > 0) | ||||
|             glsafe(::glUseProgram(current_program_id)); | ||||
| #if !ENABLE_SHADERS_MANAGER | ||||
|     } | ||||
|     else  | ||||
|     { | ||||
|  | @ -584,7 +586,7 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G | |||
| 			glvolume->render(); | ||||
| 		} | ||||
| 	} | ||||
| #endif // !ENABLE_SHADERS_MANAGER
 | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| } | ||||
| 
 | ||||
| void GLCanvas3D::LayersEditing::adjust_layer_height_profile() | ||||
|  | @ -5721,7 +5723,7 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() const | |||
| 
 | ||||
|     // set minimum scale as a auto scale for the toolbars
 | ||||
|     float new_scale = std::min(new_h_scale, new_v_scale); | ||||
|     if (fabs(new_scale - scale) > EPSILON) | ||||
|     if (fabs(new_scale - scale) > 0.01) // scale is changed by 1% and more
 | ||||
|         wxGetApp().set_auto_toolbar_icon_scale(new_scale); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ | |||
| 
 | ||||
| #include <boost/nowide/fstream.hpp> | ||||
| #include <GL/glew.h> | ||||
| #include <cassert> | ||||
| 
 | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
| #include <boost/log/trivial.hpp> | ||||
|  | @ -23,8 +24,7 @@ bool GLShaderProgram::init_from_files(const std::string& name, const ShaderFilen | |||
|     auto load_from_file = [](const std::string& filename) { | ||||
|         std::string path = resources_dir() + "/shaders/" + filename; | ||||
|         boost::nowide::ifstream s(path, boost::nowide::ifstream::binary); | ||||
|         if (!s.good()) | ||||
|         { | ||||
|         if (!s.good()) { | ||||
|             BOOST_LOG_TRIVIAL(error) << "Couldn't open file: '" << path << "'"; | ||||
|             return std::string(); | ||||
|         } | ||||
|  | @ -34,8 +34,7 @@ bool GLShaderProgram::init_from_files(const std::string& name, const ShaderFilen | |||
|         s.seekg(0, s.beg); | ||||
|         std::string source(file_length, '\0'); | ||||
|         s.read(source.data(), file_length); | ||||
|         if (!s.good()) | ||||
|         { | ||||
|         if (!s.good()) { | ||||
|             BOOST_LOG_TRIVIAL(error) << "Error while loading file: '" << path << "'"; | ||||
|             return std::string(); | ||||
|         } | ||||
|  | @ -49,8 +48,9 @@ bool GLShaderProgram::init_from_files(const std::string& name, const ShaderFilen | |||
|         sources[i] = filenames[i].empty() ? std::string() : load_from_file(filenames[i]); | ||||
|     } | ||||
| 
 | ||||
|     bool valid = (!sources[static_cast<size_t>(EShaderType::Vertex)].empty() && !sources[static_cast<size_t>(EShaderType::Fragment)].empty()) || | ||||
|         !sources[static_cast<size_t>(EShaderType::Compute)].empty(); | ||||
|     bool valid = !sources[static_cast<size_t>(EShaderType::Vertex)].empty() && !sources[static_cast<size_t>(EShaderType::Fragment)].empty() && sources[static_cast<size_t>(EShaderType::Compute)].empty(); | ||||
|     valid |= !sources[static_cast<size_t>(EShaderType::Compute)].empty() && sources[static_cast<size_t>(EShaderType::Vertex)].empty() && sources[static_cast<size_t>(EShaderType::Fragment)].empty() &&  | ||||
|               sources[static_cast<size_t>(EShaderType::Geometry)].empty() && sources[static_cast<size_t>(EShaderType::TessEvaluation)].empty() && sources[static_cast<size_t>(EShaderType::TessControl)].empty(); | ||||
| 
 | ||||
|     return valid ? init_from_texts(name, sources) : false; | ||||
| } | ||||
|  | @ -107,9 +107,11 @@ bool GLShaderProgram::init_from_texts(const std::string& name, const ShaderSourc | |||
|             auto [result, id] = create_shader(type); | ||||
|             if (result) | ||||
|                 shader_ids[i] = id; | ||||
|             else | ||||
|             { | ||||
|             else { | ||||
|                 BOOST_LOG_TRIVIAL(error) << "glCreateShader() failed for " << shader_type_as_string(type) << " shader of shader program '" << name << "'"; | ||||
| 
 | ||||
|                 // release shaders
 | ||||
|                 release_shaders(shader_ids); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|  | @ -125,7 +127,7 @@ bool GLShaderProgram::init_from_texts(const std::string& name, const ShaderSourc | |||
|                 glsafe(::glGetShaderInfoLog(id, params, ¶ms, msg.data())); | ||||
|                 BOOST_LOG_TRIVIAL(error) << "Unable to compile " << shader_type_as_string(type) << " shader of shader program '" << name << "':\n" << msg.data(); | ||||
| 
 | ||||
|                 // release shader
 | ||||
|                 // release shaders
 | ||||
|                 release_shaders(shader_ids); | ||||
|                 return false; | ||||
|             } | ||||
|  | @ -173,13 +175,10 @@ bool GLShaderProgram::init_from_texts(const std::string& name, const ShaderSourc | |||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool GLShaderProgram::start_using() const | ||||
| void GLShaderProgram::start_using() const | ||||
| { | ||||
|     if (m_id == 0) | ||||
|         return false; | ||||
| 
 | ||||
|     assert(m_id > 0); | ||||
|     glsafe(::glUseProgram(m_id)); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void GLShaderProgram::stop_using() const | ||||
|  | @ -212,6 +211,16 @@ bool GLShaderProgram::set_uniform(const char* name, float value) const | |||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 2>& value) const | ||||
| { | ||||
|     int id = get_uniform_location(name); | ||||
|     if (id >= 0) { | ||||
|         glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value.data()))); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool GLShaderProgram::set_uniform(const char* name, const std::array<float, 3>& value) const | ||||
| { | ||||
|     int id = get_uniform_location(name); | ||||
|  | @ -236,8 +245,7 @@ bool GLShaderProgram::set_uniform(const char* name, const float* value, size_t s | |||
| { | ||||
|     if (size == 1) | ||||
|         return set_uniform(name, value[0]); | ||||
|     else if (size < 5) | ||||
|     { | ||||
|     else if (size < 5) { | ||||
|         int id = get_uniform_location(name); | ||||
|         if (id >= 0) { | ||||
|             if (size == 2) | ||||
|  | @ -268,6 +276,16 @@ bool GLShaderProgram::set_uniform(const char* name, const Transform3d& value) co | |||
|     return set_uniform(name, value.cast<float>()); | ||||
| } | ||||
| 
 | ||||
| bool GLShaderProgram::set_uniform(const char* name, const Matrix3f& value) const | ||||
| { | ||||
|     int id = get_uniform_location(name); | ||||
|     if (id >= 0) { | ||||
|         glsafe(::glUniformMatrix3fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data()))); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| int GLShaderProgram::get_attrib_location(const char* name) const | ||||
| { | ||||
|     return (m_id > 0) ? ::glGetAttribLocation(m_id, name) : -1; | ||||
|  |  | |||
|  | @ -37,17 +37,19 @@ public: | |||
|     const std::string& get_name() const { return m_name; } | ||||
|     unsigned int get_id() const { return m_id; } | ||||
| 
 | ||||
|     bool start_using() const; | ||||
|     void start_using() const; | ||||
|     void stop_using() const; | ||||
| 
 | ||||
|     bool set_uniform(const char* name, int value) const; | ||||
|     bool set_uniform(const char* name, bool value) const; | ||||
|     bool set_uniform(const char* name, float value) const; | ||||
|     bool set_uniform(const char* name, const std::array<float, 2>& value) const; | ||||
|     bool set_uniform(const char* name, const std::array<float, 3>& value) const; | ||||
|     bool set_uniform(const char* name, const std::array<float, 4>& value) const; | ||||
|     bool set_uniform(const char* name, const float* value, size_t size) const; | ||||
|     bool set_uniform(const char* name, const Transform3f& value) const; | ||||
|     bool set_uniform(const char* name, const Transform3d& value) const; | ||||
|     bool set_uniform(const char* name, const Matrix3f& value) const; | ||||
| 
 | ||||
|     // returns -1 if not found
 | ||||
|     int get_attrib_location(const char* name) const; | ||||
|  |  | |||
|  | @ -1,9 +1,12 @@ | |||
| #include "libslic3r/libslic3r.h" | ||||
| #include "GLShadersManager.hpp" | ||||
| #include "3DScene.hpp" | ||||
| 
 | ||||
| #include <cassert> | ||||
| #include <algorithm> | ||||
| 
 | ||||
| #include <GL/glew.h> | ||||
| 
 | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
| 
 | ||||
| namespace Slic3r { | ||||
|  | @ -71,6 +74,17 @@ GLShaderProgram* GLShadersManager::get_shader(const std::string& shader_name) | |||
|     return (it != m_shaders.end()) ? it->get() : nullptr; | ||||
| } | ||||
| 
 | ||||
| GLShaderProgram* GLShadersManager::get_current_shader() | ||||
| { | ||||
|     GLint id = 0; | ||||
|     glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, &id)); | ||||
|     if (id == 0) | ||||
|         return false; | ||||
| 
 | ||||
|     auto it = std::find_if(m_shaders.begin(), m_shaders.end(), [id](std::unique_ptr<GLShaderProgram>& p) { return p->get_id() == id; }); | ||||
|     return (it != m_shaders.end()) ? it->get() : nullptr; | ||||
| } | ||||
| 
 | ||||
| } // namespace Slic3r
 | ||||
| 
 | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
|  |  | |||
|  | @ -22,6 +22,9 @@ public: | |||
| 
 | ||||
|     // returns nullptr if not found
 | ||||
|     GLShaderProgram* get_shader(const std::string& shader_name); | ||||
| 
 | ||||
|     // returns currently active shader, nullptr if none
 | ||||
|     GLShaderProgram* get_current_shader(); | ||||
| }; | ||||
| 
 | ||||
| } // namespace Slic3r
 | ||||
|  |  | |||
|  | @ -218,8 +218,8 @@ public: | |||
| #endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG
 | ||||
| 
 | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     // returns nullptr if not found
 | ||||
|     GLShaderProgram* get_shader(const std::string& shader_name) { return m_opengl_mgr.get_shader(shader_name); } | ||||
|     GLShaderProgram* get_current_shader() { return m_opengl_mgr.get_current_shader(); } | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -333,6 +333,34 @@ void ObjectList::get_selected_item_indexes(int& obj_idx, int& vol_idx, const wxD | |||
|     vol_idx =   type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1; | ||||
| } | ||||
| 
 | ||||
| void ObjectList::get_selection_indexes(std::vector<int>& obj_idxs, std::vector<int>& vol_idxs) | ||||
| { | ||||
|     wxDataViewItemArray sels; | ||||
|     GetSelections(sels); | ||||
|     assert(!sels.IsEmpty()); | ||||
| 
 | ||||
|     if (m_objects_model->GetItemType(sels[0]) & itVolume) { | ||||
|         for (wxDataViewItem item : sels) { | ||||
|             obj_idxs.emplace_back(m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item))); | ||||
| 
 | ||||
|             assert(m_objects_model->GetItemType(item) & itVolume); | ||||
|             vol_idxs.emplace_back(m_objects_model->GetVolumeIdByItem(item)); | ||||
|         } | ||||
|     } | ||||
|     else { | ||||
|         for (wxDataViewItem item : sels) { | ||||
|             const ItemType type = m_objects_model->GetItemType(item); | ||||
|             assert(type & itObject | itInstance | itInstanceRoot); | ||||
| 
 | ||||
|             obj_idxs.emplace_back(type & itObject ? m_objects_model->GetIdByItem(item) : | ||||
|                                   m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item))); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     std::sort(obj_idxs.begin(), obj_idxs.end(), std::greater<int>()); | ||||
|     obj_idxs.erase(std::unique(obj_idxs.begin(), obj_idxs.end()), obj_idxs.end()); | ||||
| } | ||||
| 
 | ||||
| int ObjectList::get_mesh_errors_count(const int obj_idx, const int vol_idx /*= -1*/) const | ||||
| { | ||||
|     if (obj_idx < 0) | ||||
|  | @ -1744,6 +1772,15 @@ void ObjectList::append_menu_item_scale_selection_to_fit_print_volume(wxMenu* me | |||
|         [](wxCommandEvent&) { wxGetApp().plater()->scale_selection_to_fit_print_volume(); }, "", menu); | ||||
| } | ||||
| 
 | ||||
| void ObjectList::append_menu_items_convert_unit(wxMenu* menu) | ||||
| { | ||||
|     append_menu_item(menu, wxID_ANY, _L("Convert from imperial unit"), _L("Convert from imperial unit"), | ||||
|         [](wxCommandEvent&) { wxGetApp().plater()->convert_unit(true); }, "", menu); | ||||
| 
 | ||||
|     append_menu_item(menu, wxID_ANY, _L("Convert to imperial unit"), _L("Convert to imperial unit"), | ||||
|         [](wxCommandEvent&) { wxGetApp().plater()->convert_unit(false); }, "", menu); | ||||
| } | ||||
| 
 | ||||
| void ObjectList::create_object_popupmenu(wxMenu *menu) | ||||
| { | ||||
| #ifdef __WXOSX__   | ||||
|  | @ -1751,6 +1788,7 @@ void ObjectList::create_object_popupmenu(wxMenu *menu) | |||
| #endif // __WXOSX__
 | ||||
| 
 | ||||
|     append_menu_item_reload_from_disk(menu); | ||||
|     append_menu_items_convert_unit(menu); | ||||
|     append_menu_item_export_stl(menu); | ||||
|     append_menu_item_fix_through_netfabb(menu); | ||||
|     append_menu_item_scale_selection_to_fit_print_volume(menu); | ||||
|  | @ -1775,6 +1813,7 @@ void ObjectList::create_sla_object_popupmenu(wxMenu *menu) | |||
| #endif // __WXOSX__
 | ||||
| 
 | ||||
|     append_menu_item_reload_from_disk(menu); | ||||
|     append_menu_items_convert_unit(menu); | ||||
|     append_menu_item_export_stl(menu); | ||||
|     append_menu_item_fix_through_netfabb(menu); | ||||
|     // rest of a object_sla_menu will be added later in:
 | ||||
|  | @ -1788,6 +1827,7 @@ void ObjectList::create_part_popupmenu(wxMenu *menu) | |||
| #endif // __WXOSX__
 | ||||
| 
 | ||||
|     append_menu_item_reload_from_disk(menu); | ||||
|     append_menu_items_convert_unit(menu); | ||||
|     append_menu_item_export_stl(menu); | ||||
|     append_menu_item_fix_through_netfabb(menu); | ||||
| 
 | ||||
|  | @ -4050,6 +4090,8 @@ void ObjectList::show_multi_selection_menu() | |||
|         return wxGetApp().plater()->can_reload_from_disk(); | ||||
|     }, wxGetApp().plater()); | ||||
| 
 | ||||
|     append_menu_items_convert_unit(menu); | ||||
| 
 | ||||
|     wxGetApp().plater()->PopupMenu(menu); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -210,6 +210,7 @@ public: | |||
| 
 | ||||
|     // Get obj_idx and vol_idx values for the selected (by default) or an adjusted item
 | ||||
|     void                get_selected_item_indexes(int& obj_idx, int& vol_idx, const wxDataViewItem& item = wxDataViewItem(0)); | ||||
|     void                get_selection_indexes(std::vector<int>& obj_idxs, std::vector<int>& vol_idxs); | ||||
|     // Get count of errors in the mesh
 | ||||
|     int                 get_mesh_errors_count(const int obj_idx, const int vol_idx = -1) const; | ||||
|     /* Get list of errors in the mesh. Return value is a string, used for the tooltip
 | ||||
|  | @ -252,6 +253,7 @@ public: | |||
|     void                append_menu_item_change_extruder(wxMenu* menu); | ||||
|     void                append_menu_item_delete(wxMenu* menu); | ||||
|     void                append_menu_item_scale_selection_to_fit_print_volume(wxMenu* menu); | ||||
|     void                append_menu_items_convert_unit(wxMenu* menu); | ||||
|     void                create_object_popupmenu(wxMenu *menu); | ||||
|     void                create_sla_object_popupmenu(wxMenu*menu); | ||||
|     void                create_part_popupmenu(wxMenu*menu); | ||||
|  |  | |||
|  | @ -96,8 +96,8 @@ public: | |||
|     wxGLContext* init_glcontext(wxGLCanvas& canvas); | ||||
| 
 | ||||
| #if ENABLE_SHADERS_MANAGER | ||||
|     // returns nullptr if not found
 | ||||
|     GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); } | ||||
|     GLShaderProgram* get_current_shader() { return m_shaders_manager.get_current_shader(); } | ||||
| #endif // ENABLE_SHADERS_MANAGER
 | ||||
| 
 | ||||
|     static bool are_compressed_textures_supported() { return s_compressed_textures_supported; } | ||||
|  |  | |||
|  | @ -3751,6 +3751,9 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/ | |||
| 
 | ||||
|         menu->AppendSeparator(); | ||||
| 
 | ||||
|         // "Scale to print volume" makes a sense just for whole object
 | ||||
|         sidebar->obj_list()->append_menu_item_scale_selection_to_fit_print_volume(menu); | ||||
| 
 | ||||
|         q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { | ||||
|             const Selection& selection = get_selection(); | ||||
|             int instance_idx = selection.get_instance_idx(); | ||||
|  | @ -3763,10 +3766,9 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/ | |||
|             }, menu_item_printable->GetId()); | ||||
|     } | ||||
| 
 | ||||
|     sidebar->obj_list()->append_menu_items_convert_unit(menu); | ||||
|     sidebar->obj_list()->append_menu_item_fix_through_netfabb(menu); | ||||
| 
 | ||||
|     sidebar->obj_list()->append_menu_item_scale_selection_to_fit_print_volume(menu); | ||||
| 
 | ||||
|     wxMenu* mirror_menu = new wxMenu(); | ||||
|     if (mirror_menu == nullptr) | ||||
|         return false; | ||||
|  | @ -4604,6 +4606,37 @@ void Plater::scale_selection_to_fit_print_volume() | |||
|     p->scale_selection_to_fit_print_volume(); | ||||
| } | ||||
| 
 | ||||
| void Plater::convert_unit(bool from_imperial_unit) | ||||
| { | ||||
|     std::vector<int> obj_idxs, volume_idxs; | ||||
|     wxGetApp().obj_list()->get_selection_indexes(obj_idxs, volume_idxs); | ||||
|     if (obj_idxs.empty() && volume_idxs.empty()) | ||||
|         return; | ||||
| 
 | ||||
|     TakeSnapshot snapshot(this, from_imperial_unit ? _L("Convert from imperial units") : _L("Convert to imperial units")); | ||||
|     wxBusyCursor wait; | ||||
| 
 | ||||
|     ModelObjectPtrs objects; | ||||
|     for (int obj_idx : obj_idxs) { | ||||
|         ModelObject *object = p->model.objects[obj_idx]; | ||||
|         object->convert_units(objects, from_imperial_unit, volume_idxs); | ||||
|         remove(obj_idx); | ||||
|     } | ||||
|     p->load_model_objects(objects); | ||||
|      | ||||
|     Selection& selection = p->view3D->get_canvas3d()->get_selection(); | ||||
|     size_t last_obj_idx = p->model.objects.size() - 1; | ||||
| 
 | ||||
|     if (volume_idxs.empty()) { | ||||
|         for (size_t i = 0; i < objects.size(); ++i) | ||||
|             selection.add_object((unsigned int)(last_obj_idx - i), i == 0); | ||||
|     } | ||||
|     else { | ||||
|         for (int vol_idx : volume_idxs) | ||||
|             selection.add_volume(last_obj_idx, vol_idx, 0, false); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper, bool keep_lower, bool rotate_lower) | ||||
| { | ||||
|     wxCHECK_RET(obj_idx < p->model.objects.size(), "obj_idx out of bounds"); | ||||
|  |  | |||
|  | @ -212,6 +212,7 @@ public: | |||
|     void set_number_of_copies(/*size_t num*/); | ||||
|     bool is_selection_empty() const; | ||||
|     void scale_selection_to_fit_print_volume(); | ||||
|     void convert_unit(bool from_imperial_unit); | ||||
| 
 | ||||
|     void cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false); | ||||
| 
 | ||||
|  |  | |||
|  | @ -483,11 +483,18 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher) | |||
|     search_list->GetMainWindow()->Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this); | ||||
| #endif //__WXMSW__
 | ||||
| 
 | ||||
|     // Under OSX mouse and key states didn't fill after wxEVT_DATAVIEW_SELECTION_CHANGED call
 | ||||
|     // As a result, we can't to identify what kind of actions was done
 | ||||
|     // So, under OSX is used OnKeyDown function to navigate inside the list
 | ||||
| #ifdef __APPLE__ | ||||
|     search_list->Bind(wxEVT_KEY_DOWN, &SearchDialog::OnKeyDown, this); | ||||
| #endif | ||||
| 
 | ||||
|     check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); | ||||
|     if (check_english) | ||||
|         check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); | ||||
| 
 | ||||
|     Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this); | ||||
| //    Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this);
 | ||||
|     Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this); | ||||
| 
 | ||||
|     SetSizer(topSizer); | ||||
|  | @ -585,11 +592,16 @@ void SearchDialog::OnSelect(wxDataViewEvent& event) | |||
|     if (prevent_list_events) | ||||
|         return;     | ||||
| 
 | ||||
|     // Under OSX mouse and key states didn't fill after wxEVT_DATAVIEW_SELECTION_CHANGED call
 | ||||
|     // As a result, we can't to identify what kind of actions was done
 | ||||
|     // So, under OSX is used OnKeyDown function to navigate inside the list
 | ||||
| #ifndef __APPLE__ | ||||
|     // wxEVT_DATAVIEW_SELECTION_CHANGED is processed, when selection is changed after mouse click or press the Up/Down arrows
 | ||||
|     // But this two cases should be processed in different way:
 | ||||
|     // Up/Down arrows   -> leave it as it is (just a navigation)
 | ||||
|     // LeftMouseClick   -> call the ProcessSelection function  
 | ||||
|     if (wxGetMouseState().LeftIsDown()) | ||||
| #endif //__APPLE__
 | ||||
|         ProcessSelection(search_list->GetSelection()); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Enrico Turri
						Enrico Turri