From 1979baf619025cd8bb1c7524e69e93546e9bba48 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Tue, 2 Apr 2019 13:26:22 +0200 Subject: [PATCH 1/3] imgui: Fix font size and scaling on Windows --- src/slic3r/GUI/GLCanvas3D.cpp | 6 +++--- src/slic3r/GUI/ImGuiWrapper.cpp | 11 +++++++---- src/slic3r/GUI/ImGuiWrapper.hpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ca3f6261b..a600f9ce1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4405,12 +4405,12 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) auto *imgui = wxGetApp().imgui(); imgui->set_display_size((float)w, (float)h); + const float font_size = 1.5f * wxGetApp().em_unit(); #if ENABLE_RETINA_GL - const float scaling = m_retina_helper->get_scale_factor(); + imgui->set_scaling(font_size, 1.0f, m_retina_helper->get_scale_factor()); #else - const float scaling = m_canvas->GetContentScaleFactor(); + imgui->set_scaling(font_size, m_canvas->GetContentScaleFactor(), 1.0f); #endif - imgui->set_scaling(m_canvas->GetFont().GetPixelSize().y, scaling); // ensures that this canvas is current _set_current(); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index b008c17a7..1b4d4edf9 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -92,16 +92,19 @@ void ImGuiWrapper::set_display_size(float w, float h) io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); } -void ImGuiWrapper::set_scaling(float font_size, float scaling) +void ImGuiWrapper::set_scaling(float font_size, float scale_style, float scale_both) { - if (m_font_size == font_size && m_style_scaling == scaling) { + font_size *= scale_both; + scale_style *= scale_both; + + if (m_font_size == font_size && m_style_scaling == scale_style) { return; } m_font_size = font_size; - ImGui::GetStyle().ScaleAllSizes(scaling / m_style_scaling); - m_style_scaling = scaling; + ImGui::GetStyle().ScaleAllSizes(scale_style / m_style_scaling); + m_style_scaling = scale_style; destroy_font(); } diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 84a60e3d1..c1bf491e1 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -35,7 +35,7 @@ public: void set_language(const std::string &language); void set_display_size(float w, float h); - void set_scaling(float font_size, float scaling); + void set_scaling(float font_size, float scale_style, float scale_both); bool update_mouse_data(wxMouseEvent &evt); bool update_key_data(wxKeyEvent &evt); From 66fce6d46c7b6c0274026ba5edbba023b84fff7f Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 2 Apr 2019 17:48:50 +0200 Subject: [PATCH 2/3] Add mirror correction to rasterized polygons. --- src/libslic3r/SLAPrint.cpp | 24 ++++++++++++++++++------ src/libslic3r/SLAPrint.hpp | 3 ++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 4663fe447..81d01958d 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -105,10 +105,10 @@ static std::vector sla_instances(const ModelObject &mo std::vector instances; for (ModelInstance *model_instance : model_object.instances) if (model_instance->is_printable()) { - instances.emplace_back(SLAPrintObject::Instance( + instances.emplace_back( model_instance->id(), Point::new_scale(model_instance->get_offset(X), model_instance->get_offset(Y)), - float(model_instance->get_rotation(Z)))); + float(model_instance->get_rotation(Z))); } return instances; } @@ -404,7 +404,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConf // which is expensive to calculate (especially the raw_mesh() call) print_object->set_trafo(sla_trafo(model_object), model_object.instances.front()->is_left_handed()); - print_object->set_instances(new_instances); + print_object->set_instances(std::move(new_instances)); print_object->config_apply(config, true); print_objects_new.emplace_back(print_object); new_objects = true; @@ -1025,7 +1025,8 @@ void SLAPrint::process() // get polygons for all instances in the object auto get_all_polygons = [flpXY](const ExPolygons& input_polygons, - const std::vector& instances) + const std::vector& instances, + bool is_lefthanded) { ClipperPolygons polygons; polygons.reserve(input_polygons.size() * instances.size()); @@ -1055,9 +1056,19 @@ void SLAPrint::process() auto pfirst = hole.front(); hole.emplace_back(pfirst); } + if(is_lefthanded) { + for(auto& p : poly.Contour) p.X = -p.X; + std::reverse(poly.Contour.begin(), poly.Contour.end()); + for(auto& h : poly.Holes) { + for(auto& p : h) p.X = -p.X; + std::reverse(h.begin(), h.end()); + } + } + sl::rotate(poly, double(instances[i].rotation)); sl::translate(poly, ClipperPoint{instances[i].shift(X), instances[i].shift(Y)}); + if (flpXY) { for(auto& p : poly.Contour) std::swap(p.X, p.Y); std::reverse(poly.Contour.begin(), poly.Contour.end()); @@ -1129,14 +1140,15 @@ void SLAPrint::process() const SLAPrintObject *po = record.print_obj(); const ExPolygons &modelslices = record.get_slice(soModel); + bool is_lefth = record.print_obj()->is_left_handed(); if (!modelslices.empty()) { - ClipperPolygons v = get_all_polygons(modelslices, po->instances()); + ClipperPolygons v = get_all_polygons(modelslices, po->instances(), is_lefth); for(ClipperPolygon& p_tmp : v) model_polygons.emplace_back(std::move(p_tmp)); } const ExPolygons &supportslices = record.get_slice(soSupport); if (!supportslices.empty()) { - ClipperPolygons v = get_all_polygons(supportslices, po->instances()); + ClipperPolygons v = get_all_polygons(supportslices, po->instances(), is_lefth); for(ClipperPolygon& p_tmp : v) supports_polygons.emplace_back(std::move(p_tmp)); } } diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index c0ab616b0..a1e382acb 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -246,7 +246,8 @@ protected: m_transformed_rmesh.invalidate([this, &trafo, left_handed](){ m_trafo = trafo; m_left_handed = left_handed; }); } - void set_instances(const std::vector &instances) { m_instances = instances; } + template inline void set_instances(InstVec&& instances) { m_instances = std::forward(instances); } + // Invalidates the step, and its depending steps in SLAPrintObject and SLAPrint. bool invalidate_step(SLAPrintObjectStep step); bool invalidate_all_steps(); From eeae1c0495ba74ab7a9f89df100db40de36e38e6 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 2 Apr 2019 18:04:23 +0200 Subject: [PATCH 3/3] Fixed update of the SLAPrint back end after mirroring in a specific case of mirroring around the X axis. Fixed some asserts on visual studio due to access to empty std::vector --- src/libslic3r/SLAPrint.cpp | 9 ++++++--- src/slic3r/GUI/GLCanvas3D.cpp | 26 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 81d01958d..7dc920517 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -94,7 +94,7 @@ static Transform3d sla_trafo(const ModelObject &model_object) offset(1) = 0.; rotation(2) = 0.; Transform3d trafo = Geometry::assemble_transform(offset, rotation, model_instance.get_scaling_factor(), model_instance.get_mirror()); - if (model_instance.is_left_handed()) + if (model_instance.is_left_handed()) trafo = Eigen::Scaling(Vec3d(-1., 1., 1.)) * trafo; return trafo; } @@ -317,8 +317,11 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConf it_print_object_status = print_object_status.end(); // Check whether a model part volume was added or removed, their transformations or order changed. bool model_parts_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::MODEL_PART); - bool sla_trafo_differs = model_object.instances.empty() != model_object_new.instances.empty() || - (! model_object.instances.empty() && ! sla_trafo(model_object).isApprox(sla_trafo(model_object_new))); + bool sla_trafo_differs = + model_object.instances.empty() != model_object_new.instances.empty() || + (! model_object.instances.empty() && + (! sla_trafo(model_object).isApprox(sla_trafo(model_object_new)) || + model_object.instances.front()->is_left_handed() != model_object_new.instances.front()->is_left_handed())); if (model_parts_differ || sla_trafo_differs) { // The very first step (the slicing step) is invalidated. One may freely remove all associated PrintObjects. if (it_print_object_status != print_object_status.end()) { diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a600f9ce1..79a3684ef 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5065,17 +5065,25 @@ void GLCanvas3D::_render_sla_slices() const if (obj->is_left_handed()) // The polygons are mirrored by X. ::glScalef(-1.0, 1.0, 1.0); - ::glColor3f(1.0f, 0.37f, 0.0f); ::glEnableClientState(GL_VERTEX_ARRAY); - ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_obj_triangles.front().data()); - ::glDrawArrays(GL_TRIANGLES, 0, bottom_obj_triangles.size()); - ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_obj_triangles.front().data()); - ::glDrawArrays(GL_TRIANGLES, 0, top_obj_triangles.size()); + ::glColor3f(1.0f, 0.37f, 0.0f); + if (!bottom_obj_triangles.empty()) { + ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_obj_triangles.front().data()); + ::glDrawArrays(GL_TRIANGLES, 0, bottom_obj_triangles.size()); + } + if (! top_obj_triangles.empty()) { + ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_obj_triangles.front().data()); + ::glDrawArrays(GL_TRIANGLES, 0, top_obj_triangles.size()); + } ::glColor3f(1.0f, 0.0f, 0.37f); - ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_sup_triangles.front().data()); - ::glDrawArrays(GL_TRIANGLES, 0, bottom_sup_triangles.size()); - ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_sup_triangles.front().data()); - ::glDrawArrays(GL_TRIANGLES, 0, top_sup_triangles.size()); + if (! bottom_sup_triangles.empty()) { + ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_sup_triangles.front().data()); + ::glDrawArrays(GL_TRIANGLES, 0, bottom_sup_triangles.size()); + } + if (! top_sup_triangles.empty()) { + ::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_sup_triangles.front().data()); + ::glDrawArrays(GL_TRIANGLES, 0, top_sup_triangles.size()); + } ::glDisableClientState(GL_VERTEX_ARRAY); ::glPopMatrix(); }