diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index ae91b5247..c2f1b8fa8 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1874,7 +1874,7 @@ sub draw_active_object_annotations { $self->{layer_height_edit_shader}->disable; #============================================================================================================================== - Slic3r::GUI::_3DScene::render_layer_editing_textures($self); + Slic3r::GUI::_3DScene::render_layer_editing_textures($self, $print_object); # # Paint the tooltip. # if ($self->_variable_layer_thickness_load_overlay_image) @@ -1887,43 +1887,43 @@ sub draw_active_object_annotations { # if ($self->_variable_layer_thickness_load_reset_image) { # $self->_render_image($self->{layer_preview_reset_image}, $reset_left, $reset_right, $reset_bottom, $reset_top); # } +# +# # Paint the graph. +# #FIXME show some kind of legend. +# my $max_z = unscale($print_object->size->z); +# my $profile = $print_object->model_object->layer_height_profile; +# my $layer_height = $print_object->config->get('layer_height'); +# my $layer_height_max = 10000000000.; +# { +# # Get a maximum layer height value. +# #FIXME This is a duplicate code of Slicing.cpp. +# my $nozzle_diameters = $print_object->print->config->get('nozzle_diameter'); +# my $layer_heights_min = $print_object->print->config->get('min_layer_height'); +# my $layer_heights_max = $print_object->print->config->get('max_layer_height'); +# for (my $i = 0; $i < scalar(@{$nozzle_diameters}); $i += 1) { +# my $lh_min = ($layer_heights_min->[$i] == 0.) ? 0.07 : max(0.01, $layer_heights_min->[$i]); +# my $lh_max = ($layer_heights_max->[$i] == 0.) ? (0.75 * $nozzle_diameters->[$i]) : $layer_heights_max->[$i]; +# $layer_height_max = min($layer_height_max, max($lh_min, $lh_max)); +# } +# } +# # Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. +# $layer_height_max *= 1.12; +# # Baseline +# glColor3f(0., 0., 0.); +# glBegin(GL_LINE_STRIP); +# glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom); +# glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_top); +# glEnd(); +# # Curve +# glColor3f(0., 0., 1.); +# glBegin(GL_LINE_STRIP); +# for (my $i = 0; $i < int(@{$profile}); $i += 2) { +# my $z = $profile->[$i]; +# my $h = $profile->[$i+1]; +# glVertex3f($bar_left + $h * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom + $z * ($bar_top - $bar_bottom) / $max_z, $z); +# } +# glEnd(); #============================================================================================================================== - - # Paint the graph. - #FIXME show some kind of legend. - my $max_z = unscale($print_object->size->z); - my $profile = $print_object->model_object->layer_height_profile; - my $layer_height = $print_object->config->get('layer_height'); - my $layer_height_max = 10000000000.; - { - # Get a maximum layer height value. - #FIXME This is a duplicate code of Slicing.cpp. - my $nozzle_diameters = $print_object->print->config->get('nozzle_diameter'); - my $layer_heights_min = $print_object->print->config->get('min_layer_height'); - my $layer_heights_max = $print_object->print->config->get('max_layer_height'); - for (my $i = 0; $i < scalar(@{$nozzle_diameters}); $i += 1) { - my $lh_min = ($layer_heights_min->[$i] == 0.) ? 0.07 : max(0.01, $layer_heights_min->[$i]); - my $lh_max = ($layer_heights_max->[$i] == 0.) ? (0.75 * $nozzle_diameters->[$i]) : $layer_heights_max->[$i]; - $layer_height_max = min($layer_height_max, max($lh_min, $lh_max)); - } - } - # Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. - $layer_height_max *= 1.12; - # Baseline - glColor3f(0., 0., 0.); - glBegin(GL_LINE_STRIP); - glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom); - glVertex2f($bar_left + $layer_height * ($bar_right - $bar_left) / $layer_height_max, $bar_top); - glEnd(); - # Curve - glColor3f(0., 0., 1.); - glBegin(GL_LINE_STRIP); - for (my $i = 0; $i < int(@{$profile}); $i += 2) { - my $z = $profile->[$i]; - my $h = $profile->[$i+1]; - glVertex3f($bar_left + $h * ($bar_right - $bar_left) / $layer_height_max, $bar_bottom + $z * ($bar_top - $bar_bottom) / $max_z, $z); - } - glEnd(); # Revert the matrices. glPopMatrix(); glEnable(GL_DEPTH_TEST); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 5c3492edc..0f4b020da 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -2065,9 +2065,10 @@ void _3DScene::render_legend_texture(wxGLCanvas* canvas) s_canvas_mgr.render_legend_texture(canvas); } -void _3DScene::render_layer_editing_textures(wxGLCanvas* canvas) +void _3DScene::render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject* print_object) { - s_canvas_mgr.render_layer_editing_textures(canvas); + if (print_object != nullptr) + s_canvas_mgr.render_layer_editing_textures(canvas, *print_object); } void _3DScene::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index cc2d0d5c5..edbb42bc2 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -631,7 +631,7 @@ public: static void render_cutting_plane(wxGLCanvas* canvas); static void render_warning_texture(wxGLCanvas* canvas); static void render_legend_texture(wxGLCanvas* canvas); - static void render_layer_editing_textures(wxGLCanvas* canvas); + static void render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject* print_object); static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index a0065348a..2e0c35e7c 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -4,6 +4,7 @@ #include "../../slic3r/GUI/GLShader.hpp" #include "../../libslic3r/ClipperUtils.hpp" #include "../../libslic3r/PrintConfig.hpp" +#include "../../libslic3r/Print.hpp" #include @@ -538,12 +539,13 @@ bool GLCanvas3D::LayersEditing::is_enabled() const return m_enabled; } -void GLCanvas3D::LayersEditing::render(const GLCanvas3D& canvas) const +void GLCanvas3D::LayersEditing::render(const GLCanvas3D& canvas, const PrintObject& print_object) const { const Rect& bar_rect = _get_bar_rect_viewport(canvas); const Rect& reset_rect = _get_reset_rect_viewport(canvas); _render_tooltip_texture(canvas, bar_rect, reset_rect); _render_reset_texture(canvas, reset_rect); + _render_profile(print_object, bar_rect); } GLCanvas3D::LayersEditing::GLTextureData GLCanvas3D::LayersEditing::_load_texture_from_file(const std::string& filename) const @@ -629,6 +631,61 @@ void GLCanvas3D::LayersEditing::_render_reset_texture(const GLCanvas3D& canvas, canvas.render_texture(m_reset_texture.id, reset_rect.get_left(), reset_rect.get_right(), reset_rect.get_bottom(), reset_rect.get_top()); } +void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, const Rect& bar_rect) const +{ + // FIXME show some kind of legend. + + // Get a maximum layer height value. + // FIXME This is a duplicate code of Slicing.cpp. + double layer_height_max = DBL_MAX; + const PrintConfig& print_config = print_object.print()->config; + const std::vector& nozzle_diameters = dynamic_cast(print_config.option("nozzle_diameter"))->values; + const std::vector& layer_heights_min = dynamic_cast(print_config.option("min_layer_height"))->values; + const std::vector& layer_heights_max = dynamic_cast(print_config.option("max_layer_height"))->values; + for (unsigned int i = 0; i < (unsigned int)nozzle_diameters.size(); ++i) + { + double lh_min = (layer_heights_min[i] == 0.0) ? 0.07 : std::max(0.01, layer_heights_min[i]); + double lh_max = (layer_heights_max[i] == 0.0) ? (0.75 * nozzle_diameters[i]) : layer_heights_max[i]; + layer_height_max = std::min(layer_height_max, std::max(lh_min, lh_max)); + } + + // Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. + layer_height_max *= 1.12; + + coordf_t max_z = unscale(print_object.size.z); + double layer_height = dynamic_cast(print_object.config.option("layer_height"))->value; + float l = bar_rect.get_left(); + float w = bar_rect.get_right() - l; + float b = bar_rect.get_bottom(); + float t = bar_rect.get_top(); + float h = t - b; + float scale_x = w / (float)layer_height_max; + float scale_y = h / (float)max_z; + float x = l + (float)layer_height * scale_x; + + // Baseline + ::glColor3f(0.0f, 0.0f, 0.0f); + ::glBegin(GL_LINE_STRIP); + ::glVertex2f(x, b); + ::glVertex2f(x, t); + ::glEnd(); + + // Curve + const ModelObject* model_object = print_object.model_object(); + if (model_object->layer_height_profile_valid) + { + const std::vector& profile = model_object->layer_height_profile; + + ::glColor3f(0.0f, 0.0f, 1.0f); + ::glBegin(GL_LINE_STRIP); + for (unsigned int i = 0; i < profile.size(); i += 2) + { + ::glVertex2f(l + (float)profile[i + 1] * scale_x, b + (float)profile[i] * scale_y); + } + ::glEnd(); + } +} + Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas) const { const Size& cnv_size = canvas.get_canvas_size(); @@ -1478,9 +1535,9 @@ void GLCanvas3D::render_legend_texture() const } } -void GLCanvas3D::render_layer_editing_textures() const +void GLCanvas3D::render_layer_editing_textures(const PrintObject& print_object) const { - m_layers_editing.render(*this); + m_layers_editing.render(*this, print_object); } void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 7c32ea06c..a15e632fc 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -17,6 +17,7 @@ class GLVolumeCollection; class DynamicPrintConfig; class GLShader; class ExPolygon; +class PrintObject; namespace GUI { @@ -195,12 +196,13 @@ public: bool is_enabled() const; - void render(const GLCanvas3D& canvas) const; + void render(const GLCanvas3D& canvas, const PrintObject& print_object) const; private: GLTextureData _load_texture_from_file(const std::string& filename) const; void _render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const; void _render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const; + void _render_profile(const PrintObject& print_object, const Rect& bar_rect) const; Rect _get_bar_rect_screen(const GLCanvas3D& canvas) const; Rect _get_reset_rect_screen(const GLCanvas3D& canvas) const; Rect _get_bar_rect_viewport(const GLCanvas3D& canvas) const; @@ -363,7 +365,7 @@ public: void render_cutting_plane() const; void render_warning_texture() const; void render_legend_texture() const; - void render_layer_editing_textures() const; + void render_layer_editing_textures(const PrintObject& print_object) const; void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const; diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index adcae3ddb..c28bfb675 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -560,11 +560,11 @@ void GLCanvas3DManager::render_legend_texture(wxGLCanvas* canvas) const it->second->render_legend_texture(); } -void GLCanvas3DManager::render_layer_editing_textures(wxGLCanvas* canvas) const +void GLCanvas3DManager::render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject& print_object) const { CanvasesMap::const_iterator it = _get_canvas(canvas); if (it != m_canvases.end()) - it->second->render_layer_editing_textures(); + it->second->render_layer_editing_textures(print_object); } void GLCanvas3DManager::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index 7f64e94b4..19baaf94f 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -139,7 +139,7 @@ public: void render_cutting_plane(wxGLCanvas* canvas) const; void render_warning_texture(wxGLCanvas* canvas) const; void render_legend_texture(wxGLCanvas* canvas) const; - void render_layer_editing_textures(wxGLCanvas* canvas) const; + void render_layer_editing_textures(wxGLCanvas* canvas, const PrintObject& print_object) const; void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const; diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 306ecf53f..f87cbda44 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -633,10 +633,11 @@ render_legend_texture(canvas) _3DScene::render_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); void -render_layer_editing_textures(canvas) - SV *canvas; +render_layer_editing_textures(canvas, print_object) + SV *canvas; + PrintObject *print_object; CODE: - _3DScene::render_layer_editing_textures((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + _3DScene::render_layer_editing_textures((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), print_object); void render_texture(canvas, tex_id, left, right, bottom, top)