From ea2e07ec748128f4541fabae82e6dd379deb4af1 Mon Sep 17 00:00:00 2001
From: YuSanka <yusanka@gmail.com>
Date: Sun, 25 Aug 2019 09:44:32 +0200
Subject: [PATCH 1/4] Fixed application crash, when change focus from
 overridden option to empty space in ObjectList.

---
 src/slic3r/GUI/GUI_ObjectSettings.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/slic3r/GUI/GUI_ObjectSettings.cpp b/src/slic3r/GUI/GUI_ObjectSettings.cpp
index 1b884cc24..c90e1e4ed 100644
--- a/src/slic3r/GUI/GUI_ObjectSettings.cpp
+++ b/src/slic3r/GUI/GUI_ObjectSettings.cpp
@@ -175,6 +175,9 @@ void ObjectSettings::update_config_values(DynamicPrintConfig* config)
     const auto printer_technology   = wxGetApp().plater()->printer_technology();
     const bool is_object_settings   = objects_model->GetItemType(objects_model->GetParent(item)) == itObject;
 
+    if (!item || !objects_model->IsSettingsItem(item) || !config)
+        return;
+
     // update config values according to configuration hierarchy
     DynamicPrintConfig  main_config   = printer_technology == ptFFF ?
                                         wxGetApp().preset_bundle->prints.get_edited_preset().config :

From ed2bad6709be341fd2732ffae37b46a15100af51 Mon Sep 17 00:00:00 2001
From: YuSanka <yusanka@gmail.com>
Date: Sun, 25 Aug 2019 10:31:18 +0200
Subject: [PATCH 2/4] Unified calculation of icon size for preset
 BitmapComboBox

---
 src/slic3r/GUI/PresetBundle.cpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp
index 3aee71c4c..d6e99b014 100644
--- a/src/slic3r/GUI/PresetBundle.cpp
+++ b/src/slic3r/GUI/PresetBundle.cpp
@@ -1487,11 +1487,16 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
      * and scale them in respect to em_unit value
      */
     const float scale_f = ui->em_unit() * 0.1f;
-    const int icon_height       = 16 * scale_f + 0.5f;
-    const int normal_icon_width = 16 * scale_f + 0.5f;
+
+    // To avoid the errors of number rounding for different combination of monitor configuration,
+    // let use scaled 8px, as a smallest icon unit 
+    const int icon_unit         = 8 * scale_f + 0.5f;
+    const int icon_height       = 2 * icon_unit;    //16 * scale_f + 0.5f;
+    const int normal_icon_width = 2 * icon_unit;    //16 * scale_f + 0.5f;
+    const int thin_icon_width   = icon_unit;        //8 * scale_f + 0.5f;
+    const int wide_icon_width   = 3 * icon_unit;    //24 * scale_f + 0.5f;
+
     const int space_icon_width  = 2  * scale_f + 0.5f;
-    const int wide_icon_width   = 24 * scale_f + 0.5f;
-    const int thin_icon_width   = 8  * scale_f + 0.5f;
 
 	for (int i = this->filaments().front().is_visible ? 0 : 1; i < int(this->filaments().size()); ++i) {
         const Preset &preset    = this->filaments.preset(i);

From 7f589e79f71207c300ed6b18971ce0641e854e33 Mon Sep 17 00:00:00 2001
From: Enrico Turri <enricoturri@seznam.cz>
Date: Mon, 26 Aug 2019 09:06:21 +0200
Subject: [PATCH 3/4] Follow-up of 32dc4709a48bea7089d7d84d22e89e4db98baa49 ->
 A more general fix

---
 src/slic3r/GUI/GLCanvas3D.cpp         |  5 -----
 src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 13 +++++++++++++
 src/slic3r/GUI/Gizmos/GLGizmoBase.hpp |  3 ++-
 src/slic3r/GUI/Gizmos/GLGizmoCut.cpp  |  1 +
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp
index 8c15d0fb6..3e668c4d8 100644
--- a/src/slic3r/GUI/GLCanvas3D.cpp
+++ b/src/slic3r/GUI/GLCanvas3D.cpp
@@ -2264,12 +2264,7 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
         return;
 
     if (m_gizmos.on_char(evt))
-    {
-        // FIXME: Without the following call to render(), the gimgui dialogs are not shown the first time the user tries to open them using the keyboard shortcuts
-        //        (it looks like as if 2 render calls are needed before they show up)
-        render();
         return;
-    }
 
 //#ifdef __APPLE__
 //    ctrlMask |= wxMOD_RAW_CONTROL;
diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp
index 29e5e5686..cb18bdb16 100644
--- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp
+++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp
@@ -145,6 +145,7 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, u
     , m_hover_id(-1)
     , m_dragging(false)
     , m_imgui(wxGetApp().imgui())
+    , m_first_input_window_render(true)
 {
     ::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 4 * sizeof(float));
     ::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 4 * sizeof(float));
@@ -273,6 +274,18 @@ std::string GLGizmoBase::format(float value, unsigned int decimals) const
     return Slic3r::string_printf("%.*f", decimals, value);
 }
 
+void GLGizmoBase::render_input_window(float x, float y, float bottom_limit)
+{
+    on_render_input_window(x, y, bottom_limit);
+    if (m_first_input_window_render)
+    {
+        // for some reason, the imgui dialogs are not shown on screen in the 1st frame where they are rendered, but show up only with the 2nd rendered frame
+        // so, we forces another frame rendering the first time the imgui window is shown
+        m_parent.set_as_dirty();
+        m_first_input_window_render = false;
+    }
+}
+
 // Produce an alpha channel checksum for the red green blue components. The alpha channel may then be used to verify, whether the rgb components
 // were not interpolated by alpha blending or multi sampling.
 unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char green, unsigned char blue)
diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp
index 7b73c62c2..18053dcd6 100644
--- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp
+++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp
@@ -99,6 +99,7 @@ protected:
     float m_highlight_color[4];
     mutable std::vector<Grabber> m_grabbers;
     ImGuiWrapper* m_imgui;
+    bool m_first_input_window_render;
 
 public:
     GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
@@ -144,7 +145,7 @@ public:
 
     void render() const { on_render(); }
     void render_for_picking() const { on_render_for_picking(); }
-    void render_input_window(float x, float y, float bottom_limit) { on_render_input_window(x, y, bottom_limit); }
+    void render_input_window(float x, float y, float bottom_limit);
 
 protected:
     virtual bool on_init() = 0;
diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp
index 481bec956..76a9ed603 100644
--- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp
+++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp
@@ -141,6 +141,7 @@ void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit)
     m_imgui->set_next_window_pos(x, y, ImGuiCond_Always);
 
     m_imgui->set_next_window_bg_alpha(0.5f);
+
     m_imgui->begin(_(L("Cut")), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
 
     ImGui::PushItemWidth(m_imgui->scaled(5.0f));

From b5c57fc134ffd01e42ca12363e3973cc410b8b72 Mon Sep 17 00:00:00 2001
From: Enrico Turri <enricoturri@seznam.cz>
Date: Mon, 26 Aug 2019 09:35:04 +0200
Subject: [PATCH 4/4] Follow-up of c7cdb2fd3e19ae9560f540b65e2d47759cdb59d0 ->
 Fixed localization of error messages for .3mf and .amf version check

---
 src/libslic3r/Format/3mf.cpp | 9 ++++++++-
 src/libslic3r/Format/AMF.cpp | 9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp
index 9da0d4fd9..5e0878884 100644
--- a/src/libslic3r/Format/3mf.cpp
+++ b/src/libslic3r/Format/3mf.cpp
@@ -4,6 +4,8 @@
 #include "../GCode.hpp"
 #include "../Geometry.hpp"
 
+#include "../I18N.hpp"
+
 #include "3mf.hpp"
 
 #include <limits>
@@ -202,6 +204,11 @@ bool is_valid_object_type(const std::string& type)
 
 namespace Slic3r {
 
+//! macro used to mark string used at localization,
+//! return same string
+#define L(s) (s)
+#define _(s) Slic3r::I18N::translate(s)
+
     // Base class with error messages management
     class _3MF_Base
     {
@@ -1416,7 +1423,7 @@ namespace Slic3r {
 
             if (m_check_version && (m_version > VERSION_3MF))
             {
-                std::string msg = "The selected 3mf file has been saved with a newer version of " + std::string(SLIC3R_APP_NAME) + " and is not compatibile.";
+                std::string msg = _(L("The selected 3mf file has been saved with a newer version of " + std::string(SLIC3R_APP_NAME) + " and is not compatibile."));
                 throw std::runtime_error(msg.c_str());
             }
         }
diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp
index be15f833b..033e64aa0 100644
--- a/src/libslic3r/Format/AMF.cpp
+++ b/src/libslic3r/Format/AMF.cpp
@@ -11,6 +11,8 @@
 #include "../GCode.hpp"
 #include "../PrintConfig.hpp"
 #include "../Utils.hpp"
+#include "../I18N.hpp"
+
 #include "AMF.hpp"
 
 #include <boost/filesystem/operations.hpp>
@@ -42,6 +44,11 @@ const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config";
 namespace Slic3r
 {
 
+//! macro used to mark string used at localization,
+//! return same string
+#define L(s) (s)
+#define _(s) Slic3r::I18N::translate(s)
+
 struct AMFParserContext
 {
     AMFParserContext(XML_Parser parser, DynamicPrintConfig* config, Model* model) :
@@ -803,7 +810,7 @@ bool extract_model_from_archive(mz_zip_archive& archive, const mz_zip_archive_fi
 
     if (check_version && (ctx.m_version > VERSION_AMF))
     {
-        std::string msg = "The selected amf file has been saved with a newer version of " + std::string(SLIC3R_APP_NAME) + " and is not compatibile.";
+        std::string msg = _(L("The selected amf file has been saved with a newer version of " + std::string(SLIC3R_APP_NAME) + " and is not compatibile."));
         throw std::runtime_error(msg.c_str());
     }