From 2826162b5d4c0486e691aa9c06b7f1e5a02e66d9 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 23 Aug 2021 16:26:47 +0200 Subject: [PATCH 01/25] Parse hints.ini for translatable text as part of gettext_make_pot --- CMakeLists.txt | 3 ++ src/CMakeLists.txt | 1 + src/hints/CMakeLists.txt | 12 +++++ src/hints/HintsToPot.cpp | 84 +++++++++++++++++++++++++++++ src/slic3r/GUI/HintNotification.cpp | 21 ++++++++ 5 files changed, 121 insertions(+) create mode 100644 src/hints/CMakeLists.txt create mode 100644 src/hints/HintsToPot.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6002091b661..d771a730a95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -481,6 +481,7 @@ add_custom_target(gettext_make_pot COMMAND xgettext --keyword=L --keyword=_L --keyword=_u8L --keyword=L_CONTEXT:1,2c --keyword=_L_PLURAL:1,2 --add-comments=TRN --from-code=UTF-8 --debug -f "${L10N_DIR}/list.txt" -o "${L10N_DIR}/PrusaSlicer.pot" + COMMAND hintsToPot ${SLIC3R_RESOURCES_DIR} ${L10N_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Generate pot file from strings in the source tree" ) @@ -553,6 +554,8 @@ endfunction() add_subdirectory(src) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT PrusaSlicer_app_console) +add_dependencies(gettext_make_pot hintsToPot) + # Perl bindings, currently only used for the unit / integration tests of libslic3r. # Also runs the unit / integration tests. #FIXME Port the tests into C++ to finally get rid of the Perl! diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bbade8a9730..9e89e82f673 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory(qhull) add_subdirectory(Shiny) add_subdirectory(semver) add_subdirectory(libigl) +add_subdirectory(hints) # Adding libnest2d project for bin packing... add_subdirectory(libnest2d) diff --git a/src/hints/CMakeLists.txt b/src/hints/CMakeLists.txt new file mode 100644 index 00000000000..66550c78610 --- /dev/null +++ b/src/hints/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.13) +project(HintsToPot) + +add_executable(hintsToPot + HintsToPot.cpp) + +target_link_libraries(hintsToPot PRIVATE boost_libs) + +#encoding_check(HintsToPot) + + + diff --git a/src/hints/HintsToPot.cpp b/src/hints/HintsToPot.cpp new file mode 100644 index 00000000000..7c8029cdeb8 --- /dev/null +++ b/src/hints/HintsToPot.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +bool write_to_pot(boost::filesystem::path path, const std::vector>& data) +{ + boost::filesystem::ofstream file(std::move(path), std::ios_base::app); + for (const auto& element : data) + { + //Example of .pot element + //#: src/slic3r/GUI/GUI_App.cpp:1647 src/slic3r/GUI/wxExtensions.cpp:687 + //msgctxt "Mode" + //msgid "Advanced" + //msgstr "" + file << "\n#: resources/data/hints.ini: ["<< element.first << "]\nmsgid \"" << element.second << "\"\nmsgstr \"\"\n"; + } + file.close(); + return true; +} +bool read_hints_ini(boost::filesystem::path path, std::vector>& pot_elements) +{ + namespace pt = boost::property_tree; + pt::ptree tree; + boost::nowide::ifstream ifs(path.string()); + try { + pt::read_ini(ifs, tree); + } + catch (const boost::property_tree::ini_parser::ini_parser_error& err) { + std::cout << err.what() << std::endl; + return false; + } + for (const auto& section : tree) { + if (boost::starts_with(section.first, "hint:")) { + for (const auto& data : section.second) { + if (data.first == "text") + { + pot_elements.emplace_back(section.first, data.second.data()); + break; + } + } + } + } + return true; +} + +int main(int argc, char* argv[]) +{ + std::vector> data; + boost::filesystem::path path_to_ini; + boost::filesystem::path path_to_pot; + if (argc != 3) + { + std::cout << "HINTS_TO_POT FAILED: WRONG NUM OF ARGS" << std::endl; + return -1; + } + try { + path_to_ini = boost::filesystem::canonical(boost::filesystem::path(argv[1])).parent_path() / "resources" / "data" / "hints.ini"; + path_to_pot = boost::filesystem::canonical(boost::filesystem::path(argv[2])).parent_path() / "localization" /"PrusaSlicer.pot"; + } catch (std::exception&) { + std::cout << "HINTS_TO_POT FAILED: BOOST CANNONICAL" << std::endl; + return -1; + } + + if (!boost::filesystem::exists(path_to_ini)){ + std::cout << "HINTS_TO_POT FAILED: PATH TO INI DOES NOT EXISTS" << std::endl; + std::cout << path_to_ini.string() << std::endl; + return -1; + } + if (!read_hints_ini(std::move(path_to_ini), data)) { + std::cout << "HINTS_TO_POT FAILED TO READ HINTS INI" << std::endl; + return -1; + } + if (!write_to_pot(std::move(path_to_pot), data)) { + std::cout << "HINTS_TO_POT FAILED TO WRITE POT FILE" << std::endl; + return -1; + } + std::cout << "HINTS_TO_POT SUCCESS" << std::endl; + return 0; +} diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index 2b079b6ffb6..42039fa7012 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -179,6 +179,21 @@ void launch_browser_if_allowed(const std::string& url) if (wxGetApp().app_config->get("suppress_hyperlinks") != "1") wxLaunchDefaultBrowser(url); } +bool pot_exists() +{ + return true; +// return boost::filesystem::exists(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.pot")); +} +void write_pot(const std::vector& elements) +{ + boost::filesystem::ofstream file(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.pot")); + + for ( const auto &element : elements) + { + file << "msgid \"" << escape_string_cstyle(element) << "\"\nmsgstr \"\"\n\n"; + } + file.close(); +} } //namespace void HintDatabase::init() @@ -195,6 +210,8 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) { namespace pt = boost::property_tree; pt::ptree tree; + bool create_pot = !pot_exists(); + std::vector pot_elements; boost::nowide::ifstream ifs(path.string()); try { pt::read_ini(ifs, tree); @@ -221,6 +238,8 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) std::string documentation_link; //unescape text1 unescape_string_cstyle(_utf8(dict["text"]), fulltext); + if (create_pot) + pot_elements.emplace_back(fulltext); // replace and for imgui markers std::string marker_s(1, ImGui::ColorMarkerStart); std::string marker_e(1, ImGui::ColorMarkerEnd); @@ -319,6 +338,8 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) } } } + if (create_pot) + write_pot(pot_elements); } HintData* HintDatabase::get_hint(bool up) { From eb90579d3f7705c8c88741f644126876c41f1b83 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 23 Aug 2021 21:16:58 +0200 Subject: [PATCH 02/25] Fixup of e5f0099 --- src/slic3r/GUI/Plater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 29368312a3c..97ffc6cb7e1 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4878,7 +4878,7 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) _L("Select an action to apply to the file") + ": " + from_u8(filename)), 0, wxEXPAND | wxALL, 10); m_action = std::clamp(std::stoi(wxGetApp().app_config->get("drop_project_action")), - static_cast(LoadType::OpenProject) - 1, static_cast(LoadType::LoadConfig)) - 1; + static_cast(LoadType::OpenProject), static_cast(LoadType::LoadConfig)) - 1; wxStaticBox* action_stb = new wxStaticBox(this, wxID_ANY, _L("Action")); if (!wxOSX) action_stb->SetBackgroundStyle(wxBG_STYLE_PAINT); From 7536e51982c02d1a0d7fe56d95d668c8f9f2d12c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 07:46:59 +0200 Subject: [PATCH 03/25] Do not allow objects to be placed fully below bed --- src/libslic3r/Model.hpp | 1 + src/slic3r/GUI/3DScene.cpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 2 +- src/slic3r/GUI/Selection.cpp | 33 ++++++++++++++++++++++++++++++--- src/slic3r/GUI/Selection.hpp | 1 + 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 11dcfa77574..1dd16ee9174 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1177,6 +1177,7 @@ void check_model_ids_equal(const Model &model1, const Model &model2); #endif /* NDEBUG */ static const float SINKING_Z_THRESHOLD = -0.001f; +static const double SINKING_MIN_Z_THRESHOLD = 0.05; } // namespace Slic3r diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 9c0341ff45e..7a9fdc3886d 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -595,7 +595,7 @@ bool GLVolume::is_sinking() const bool GLVolume::is_below_printbed() const { - return transformed_convex_hull_bounding_box().max(2) < 0.0; + return transformed_convex_hull_bounding_box().max.z() < 0.0; } #if ENABLE_SINKING_CONTOURS diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index b9aefcc76b4..498b026056c 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -621,7 +621,7 @@ void MainFrame::update_title() if (!dirty_marker.empty() || !project.empty()) { if (!dirty_marker.empty() && project.empty()) project = _("Untitled"); - title = dirty_marker + project + " - "; + title = dirty_marker + project + " - "; } } diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index dbc25944402..acb1f11131c 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -683,7 +683,8 @@ void Selection::translate(const Vec3d& displacement, bool local) synchronize_unselected_volumes(); #endif // !DISABLE_INSTANCES_SYNCH - this->set_bounding_boxes_dirty(); + ensure_not_below_bed(); + set_bounding_boxes_dirty(); } // Rotate an object around one of the axes. Only one rotation component is expected to be changing. @@ -1712,7 +1713,7 @@ void Selection::calc_unscaled_instance_bounding_box() const if (volume.is_modifier) continue; Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, true, false) * volume.get_volume_transformation().get_matrix(); - trafo.translation()(2) += volume.get_sla_shift_z(); + trafo.translation().z() += volume.get_sla_shift_z(); unscaled_instance_bounding_box->merge(volume.transformed_convex_hull_bounding_box(trafo)); } } @@ -1729,7 +1730,7 @@ void Selection::calc_scaled_instance_bounding_box() const if (volume.is_modifier) continue; Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, false, false) * volume.get_volume_transformation().get_matrix(); - trafo.translation()(2) += volume.get_sla_shift_z(); + trafo.translation().z() += volume.get_sla_shift_z(); scaled_instance_bounding_box->merge(volume.transformed_convex_hull_bounding_box(trafo)); } } @@ -2134,6 +2135,32 @@ void Selection::ensure_on_bed() } } +void Selection::ensure_not_below_bed() +{ + typedef std::map, double> InstancesToZMap; + InstancesToZMap instances_max_z; + + for (size_t i = 0; i < m_volumes->size(); ++i) { + GLVolume* volume = (*m_volumes)[i]; + if (!volume->is_wipe_tower && !volume->is_modifier) { + const double max_z = volume->transformed_convex_hull_bounding_box().max.z(); + std::pair instance = std::make_pair(volume->object_idx(), volume->instance_idx()); + InstancesToZMap::iterator it = instances_max_z.find(instance); + if (it == instances_max_z.end()) + it = instances_max_z.insert(InstancesToZMap::value_type(instance, -DBL_MAX)).first; + + it->second = std::max(it->second, max_z); + } + } + + for (GLVolume* volume : *m_volumes) { + std::pair instance = std::make_pair(volume->object_idx(), volume->instance_idx()); + InstancesToZMap::iterator it = instances_max_z.find(instance); + if (it != instances_max_z.end() && it->second < SINKING_MIN_Z_THRESHOLD) + volume->set_instance_offset(Z, volume->get_instance_offset(Z) + SINKING_MIN_Z_THRESHOLD - it->second); + } +} + bool Selection::is_from_fully_selected_instance(unsigned int volume_idx) const { struct SameInstance diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 0e0e869ef63..b3304571f86 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -385,6 +385,7 @@ public: private: void ensure_on_bed(); + void ensure_not_below_bed(); bool is_from_fully_selected_instance(unsigned int volume_idx) const; void paste_volumes_from_clipboard(); From 27b9afd7774633ba8ab1ac9b98278b1910411be0 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 08:25:04 +0200 Subject: [PATCH 04/25] Follow-up of ab6c638e44915138ee0e0500931aefd63bba16ed -> Fixed logic to center objects loaded from 3mf files produced by 3rd part softwares --- src/slic3r/GUI/Plater.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 97ffc6cb7e1..5f156352607 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1643,7 +1643,7 @@ struct Plater::priv BoundingBox scaled_bed_shape_bb() const; std::vector load_files(const std::vector& input_files, bool load_model, bool load_config, bool used_inches = false); - std::vector load_model_objects(const ModelObjectPtrs& model_objects, bool allow_negative_z = false, bool force_center_on_bed = false); + std::vector load_model_objects(const ModelObjectPtrs& model_objects, bool allow_negative_z = false); wxString get_export_file(GUI::FileType file_type); @@ -2426,7 +2426,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ } if (one_by_one) { - auto loaded_idxs = load_model_objects(model.objects, is_project_file, !is_project_file); + if (type_3mf && !is_project_file) + model.center_instances_around_point(bed_shape_bb().center()); + auto loaded_idxs = load_model_objects(model.objects, is_project_file); obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); } else { // This must be an .stl or .obj file, which may contain a maximum of one volume. @@ -2479,7 +2481,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ // #define AUTOPLACEMENT_ON_LOAD -std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& model_objects, bool allow_negative_z, bool force_center_on_bed) +std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& model_objects, bool allow_negative_z) { const BoundingBoxf bed_shape = bed_shape_bb(); const Vec3d bed_size = Slic3r::to_3d(bed_shape.size().cast(), 1.0) - 2.0 * Vec3d::Ones(); @@ -2539,9 +2541,6 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode object->ensure_on_bed(allow_negative_z); } - if (force_center_on_bed) - model.center_instances_around_point(bed_shape.center()); - #ifdef AUTOPLACEMENT_ON_LOAD // FIXME distance should be a config value ///////////////////////////////// auto min_obj_distance = static_cast(6/SCALING_FACTOR); From 5dbf6c00b8854bf1521c70f1f7f3fb60f09b2ae4 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 24 Aug 2021 09:34:25 +0200 Subject: [PATCH 05/25] Slight refactoring of the project state. --- src/libslic3r/Preset.hpp | 4 ++-- src/slic3r/GUI/Plater.cpp | 9 +++------ src/slic3r/GUI/ProjectDirtyStateManager.cpp | 9 ++++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index d0e7561dbe9..d19cb0aaccb 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -371,7 +371,7 @@ public: const Preset& get_edited_preset() const { return m_edited_preset; } // Return the last saved preset. - const Preset& get_saved_preset() const { return m_saved_preset; } +// const Preset& get_saved_preset() const { return m_saved_preset; } // Return vendor of the first parent profile, for which the vendor is defined, or null if such profile does not exist. PresetWithVendorProfile get_preset_with_vendor_profile(const Preset &preset) const; @@ -474,7 +474,7 @@ public: // Compare the content of get_saved_preset() with get_edited_preset() configs, return true if they differ. bool saved_is_dirty() const - { return is_dirty(&this->get_edited_preset(), &this->get_saved_preset()); } + { return is_dirty(&this->get_edited_preset(), &m_saved_preset); } // Compare the content of get_saved_preset() with get_edited_preset() configs, return the list of keys where they differ. // std::vector saved_dirty_options() const // { return dirty_options(&this->get_edited_preset(), &this->get_saved_preset(), /* deep_compare */ false); } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5f156352607..fa53522d105 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4703,10 +4703,8 @@ void Plater::load_project(const wxString& filename) std::vector input_paths; input_paths.push_back(into_path(filename)); - std::vector res = load_files(input_paths); - - // if res is empty no data has been loaded - if (!res.empty()) { + if (! load_files(input_paths).empty()) { + // At least one file was loaded. p->set_project_filename(filename); reset_project_dirty_initial_presets(); update_project_dirty_from_presets(); @@ -4741,8 +4739,7 @@ void Plater::add_model(bool imperial_units/* = false*/) } Plater::TakeSnapshot snapshot(this, snapshot_label); - std::vector res = load_files(paths, true, false, imperial_units); - if (!res.empty()) + if (! load_files(paths, true, false, imperial_units).empty()) wxGetApp().mainframe->update_title(); } diff --git a/src/slic3r/GUI/ProjectDirtyStateManager.cpp b/src/slic3r/GUI/ProjectDirtyStateManager.cpp index 9efc1dd90a4..3ca764e913a 100644 --- a/src/slic3r/GUI/ProjectDirtyStateManager.cpp +++ b/src/slic3r/GUI/ProjectDirtyStateManager.cpp @@ -28,7 +28,7 @@ static const UndoRedo::Snapshot* get_active_snapshot(const UndoRedo::Stack& stac const size_t active_snapshot_time = stack.active_snapshot_time(); const auto it = std::lower_bound(snapshots.begin(), snapshots.end(), UndoRedo::Snapshot(active_snapshot_time)); const int idx = it - snapshots.begin() - 1; - const Slic3r::UndoRedo::Snapshot* ret = (0 <= idx && (size_t)idx < snapshots.size() - 1) ? + const Slic3r::UndoRedo::Snapshot* ret = (0 <= idx && idx < int(snapshots.size()) - 1) ? &snapshots[idx] : nullptr; assert(ret != nullptr); @@ -195,8 +195,7 @@ void ProjectDirtyStateManager::update_from_undo_redo_stack(UpdateType type) void ProjectDirtyStateManager::update_from_presets() { m_state.presets = false; - std::vector> selected_presets = wxGetApp().get_selected_presets(); - for (const auto& [type, name] : selected_presets) { + for (const auto& [type, name] : wxGetApp().get_selected_presets()) { m_state.presets |= !m_initial_presets[type].empty() && m_initial_presets[type] != name; } m_state.presets |= wxGetApp().has_unsaved_preset_changes(); @@ -214,6 +213,7 @@ void ProjectDirtyStateManager::reset_after_save() m_last_save.main = (saveable_snapshot != nullptr) ? saveable_snapshot->timestamp : 0; } else { + // Gizmo is active with its own Undo / Redo stack (for example the SLA support point editing gizmo). const UndoRedo::Snapshot* main_active_snapshot = get_active_snapshot(main_stack); if (boost::starts_with(main_active_snapshot->name, _utf8("Entering"))) { if (m_state.gizmos.current) @@ -231,8 +231,7 @@ void ProjectDirtyStateManager::reset_after_save() void ProjectDirtyStateManager::reset_initial_presets() { m_initial_presets = std::array(); - std::vector> selected_presets = wxGetApp().get_selected_presets(); - for (const auto& [type, name] : selected_presets) { + for (const auto& [type, name] : wxGetApp().get_selected_presets()) { m_initial_presets[type] = name; } } From cc46dd257900548508981e3527cd0893b8dcae10 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 24 Aug 2021 09:44:32 +0200 Subject: [PATCH 06/25] Force enable menu icons under GTK GTK specific: Fixed missing icons for wxMenuItem on GTK2 and GTK3 for skins that haven't enabled showing an icon for gtk_image_menu_item by forcing showing icons for every skin. --- src/slic3r/GUI/GUI_App.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 06d805eeb11..58ce12ae420 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -87,6 +87,11 @@ #include #endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG +// Needed for forcing menu icons back under gtk2 and gtk3 +#if defined(__WXGTK20__) || defined(__WXGTK3__) + #include +#endif + namespace Slic3r { namespace GUI { @@ -799,6 +804,14 @@ bool GUI_App::OnInit() bool GUI_App::on_init_inner() { + // Forcing back menu icons under gtk2 and gtk3. Solution is based on: + // https://docs.gtk.org/gtk3/class.Settings.html + // see also https://docs.wxwidgets.org/3.0/classwx_menu_item.html#a2b5d6bcb820b992b1e4709facbf6d4fb + // TODO: Find workaround for GTK4 +#if defined(__WXGTK20__) || defined(__WXGTK3__) + g_object_set (gtk_settings_get_default (), "gtk-menu-images", TRUE, NULL); +#endif + // Verify resources path const wxString resources_dir = from_u8(Slic3r::resources_dir()); wxCHECK_MSG(wxDirExists(resources_dir), false, From 3acd12c3babd5b316fd6ffa49fe08e62dd713574 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 11:23:33 +0200 Subject: [PATCH 07/25] Follow-up of 316d38807d64e377c4b1d3a71f8c9587dcc82066 -> Modified shader to work on (buggy) Intel graphics card --- resources/shaders/printbed.vs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/shaders/printbed.vs b/resources/shaders/printbed.vs index ee19098c1c0..7633017f12c 100644 --- a/resources/shaders/printbed.vs +++ b/resources/shaders/printbed.vs @@ -7,6 +7,8 @@ varying vec2 tex_coords; void main() { - gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position, 1.0); + gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position.x, v_position.y, v_position.z, 1.0); + // the following line leads to crash on some Intel graphics card + //gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position, 1.0); tex_coords = v_tex_coords; } From feacd191ee3ed02cbbd933abe085f968393efc86 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 24 Aug 2021 11:24:48 +0200 Subject: [PATCH 08/25] OctoPrint upload: ignore certificate revocation checks Fixes Hostname incorrect While test is positive (Bonjour discovery not supported for the address field) #1781 (partial fix of #1781) --- src/libslic3r/Preset.cpp | 3 ++- src/libslic3r/PrintConfig.cpp | 6 ++++++ src/slic3r/GUI/PhysicalPrinterDialog.cpp | 9 ++++++++- src/slic3r/Utils/Http.cpp | 8 ++++++++ src/slic3r/Utils/Http.hpp | 2 ++ src/slic3r/Utils/OctoPrint.cpp | 9 ++++++++- src/slic3r/Utils/OctoPrint.hpp | 1 + 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index c0a956154d7..26359b866ce 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1442,7 +1442,8 @@ const std::vector& PhysicalPrinter::printer_options() "printhost_authorization_type", // HTTP digest authentization (RFC 2617) "printhost_user", - "printhost_password" + "printhost_password", + "printhost_ignore_check" }; } return s_opts; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index e64824d0db3..dffb8ac0c23 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -310,6 +310,12 @@ void PrintConfigDef::init_common_params() // def->tooltip = L(""); def->mode = comAdvanced; def->set_default_value(new ConfigOptionString("")); + + def = this->add("printhost_ignore_check", coBool); + def->label = L("Ignore certificate revocation checks"); + // def->tooltip = L(""); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionBool(false)); def = this->add("preset_names", coStrings); def->label = L("Printer preset names"); diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index f189378a6da..9c570172c0f 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -396,6 +396,7 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr m_optgroup->append_line(cafile_hint); } else { + Line line{ "", "" }; line.full_width = 1; @@ -411,8 +412,14 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr sizer->Add(txt, 1, wxEXPAND); return sizer; }; - m_optgroup->append_line(line); + +#ifdef WIN32 + option = m_optgroup->get_option("printhost_ignore_check"); + option.opt.width = Field::def_width_wider(); + m_optgroup->append_single_option_line(option); +#endif + } for (const std::string& opt_key : std::vector{ "printhost_user", "printhost_password" }) { diff --git a/src/slic3r/Utils/Http.cpp b/src/slic3r/Utils/Http.cpp index 2afb7ed5046..69093988ab8 100644 --- a/src/slic3r/Utils/Http.cpp +++ b/src/slic3r/Utils/Http.cpp @@ -491,6 +491,14 @@ Http& Http::form_add_file(const std::string &name, const fs::path &path, const s return *this; } +Http& Http::revoke_best_effort(bool set) +{ + if(p && set){ + ::curl_easy_setopt(p->curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT); + } + return *this; +} + Http& Http::set_post_body(const fs::path &path) { if (p) { p->set_post_body(path);} diff --git a/src/slic3r/Utils/Http.hpp b/src/slic3r/Utils/Http.hpp index f34a27fbcc1..3cce250862a 100644 --- a/src/slic3r/Utils/Http.hpp +++ b/src/slic3r/Utils/Http.hpp @@ -80,6 +80,8 @@ public: // Same as above except also override the file's filename with a custom one Http& form_add_file(const std::string &name, const boost::filesystem::path &path, const std::string &filename); + Http& revoke_best_effort(bool set); + // Set the file contents as a POST request body. // The data is used verbatim, it is not additionally encoded in any way. // This can be used for hosts which do not support multipart requests. diff --git a/src/slic3r/Utils/OctoPrint.cpp b/src/slic3r/Utils/OctoPrint.cpp index ee669c36fee..3a2335b1ef7 100644 --- a/src/slic3r/Utils/OctoPrint.cpp +++ b/src/slic3r/Utils/OctoPrint.cpp @@ -25,7 +25,8 @@ namespace Slic3r { OctoPrint::OctoPrint(DynamicPrintConfig *config) : host(config->opt_string("print_host")), apikey(config->opt_string("printhost_apikey")), - cafile(config->opt_string("printhost_cafile")) + cafile(config->opt_string("printhost_cafile")), + ignore_checks(config->opt_bool("printhost_ignore_check")) {} const char* OctoPrint::get_name() const { return "OctoPrint"; } @@ -73,6 +74,9 @@ bool OctoPrint::test(wxString &msg) const msg = "Could not parse server response"; } }) +#ifdef WIN32 + .revoke_best_effort(ignore_checks) +#endif .perform_sync(); return res; @@ -137,6 +141,9 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro res = false; } }) +#ifdef WIN32 + .revoke_best_effort(ignore_checks) +#endif .perform_sync(); return res; diff --git a/src/slic3r/Utils/OctoPrint.hpp b/src/slic3r/Utils/OctoPrint.hpp index 62bdfb6fa17..42683dc62ba 100644 --- a/src/slic3r/Utils/OctoPrint.hpp +++ b/src/slic3r/Utils/OctoPrint.hpp @@ -40,6 +40,7 @@ private: std::string host; std::string apikey; std::string cafile; + bool ignore_checks; virtual void set_auth(Http &http) const; std::string make_url(const std::string &path) const; From 7746e09082f917023dc44825e58d156220edbc49 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 11:31:04 +0200 Subject: [PATCH 09/25] Fixed sequential print clearance contours not disappearing after undo --- src/slic3r/GUI/Plater.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index fa53522d105..3884fbca4de 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2944,6 +2944,9 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool if (view3D->is_layers_editing_enabled()) view3D->get_wxglcanvas()->Refresh(); + if (background_process.empty()) + view3D->get_canvas3d()->reset_sequential_print_clearance(); + if (invalidated == Print::APPLY_STATUS_INVALIDATED) { // Some previously calculated data on the Print was invalidated. // Hide the slicing results, as the current slicing status is no more valid. From 0be3198e388de6ffdf73b8f47a3bd0766f00b81c Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 12:09:30 +0200 Subject: [PATCH 10/25] Removed confirmation dialog for command Delete All --- src/slic3r/GUI/Plater.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 3884fbca4de..60215484b8c 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1658,6 +1658,7 @@ struct Plater::priv void deselect_all(); void remove(size_t obj_idx); void delete_object_from_model(size_t obj_idx); + void delete_all_objects_from_model(); void reset(); void mirror(Axis axis); void split_object(); @@ -1944,7 +1945,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) // 3DScene/Toolbar: view3D_canvas->Bind(EVT_GLTOOLBAR_ADD, &priv::on_action_add, this); view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE, [q](SimpleEvent&) { q->remove_selected(); }); - view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE_ALL, [q](SimpleEvent&) { q->reset_with_confirm(); }); + view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE_ALL, [this](SimpleEvent&) { delete_all_objects_from_model(); }); +// view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE_ALL, [q](SimpleEvent&) { q->reset_with_confirm(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_ARRANGE, [this](SimpleEvent&) { this->q->arrange(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_COPY, [q](SimpleEvent&) { q->copy_selection_to_clipboard(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_PASTE, [q](SimpleEvent&) { q->paste_from_clipboard(); }); @@ -2753,6 +2755,32 @@ void Plater::priv::delete_object_from_model(size_t obj_idx) object_list_changed(); } +void Plater::priv::delete_all_objects_from_model() +{ + Plater::TakeSnapshot snapshot(q, _L("Delete All Objects")); + + if (view3D->is_layers_editing_enabled()) + view3D->enable_layers_editing(false); + + reset_gcode_toolpaths(); + gcode_result.reset(); + + view3D->get_canvas3d()->reset_sequential_print_clearance(); + + // Stop and reset the Print content. + background_process.reset(); + model.clear_objects(); + update(); + // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. + sidebar->obj_list()->delete_all_objects_from_list(); + object_list_changed(); + + // The hiding of the slicing results, if shown, is not taken care by the background process, so we do it here + sidebar->show_sliced_info_sizer(false); + + model.custom_gcode_per_print_z.gcodes.clear(); +} + void Plater::priv::reset() { Plater::TakeSnapshot snapshot(q, _L("Reset Project")); From 5b92355e172a4529302c25f5fcaab41dedd9c1c5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 12:17:47 +0200 Subject: [PATCH 11/25] Fixed update of project dirty state after discarding config changes --- src/libslic3r/Preset.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index d19cb0aaccb..849dd7b8096 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -395,7 +395,7 @@ public: void discard_current_changes() { m_presets[m_idx_selected].reset_dirty(); m_edited_preset = m_presets[m_idx_selected]; - update_saved_preset_from_current_preset(); +// update_saved_preset_from_current_preset(); } // Return a preset by its name. If the preset is active, a temporary copy is returned. From 90651b25f34c8b4f085fc99694053f00cce206eb Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Aug 2021 12:39:21 +0200 Subject: [PATCH 12/25] Fixed object below bed after deleting part --- src/slic3r/GUI/Selection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index acb1f11131c..ba4577bfb0d 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1149,6 +1149,7 @@ void Selection::erase() } wxGetApp().obj_list()->delete_from_model_and_list(items); + ensure_not_below_bed(); } } From f0514bcfe73dc0b638bbf554bba687f82c12bba0 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 23 Aug 2021 15:51:06 +0200 Subject: [PATCH 13/25] Do not print brim when object has raft, it is not supported and makes no sense --- src/libslic3r/Brim.cpp | 6 +++++- src/libslic3r/Print.hpp | 8 ++++++-- src/libslic3r/PrintConfig.cpp | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp index e73bed2c9f4..f4455fdd558 100644 --- a/src/libslic3r/Brim.cpp +++ b/src/libslic3r/Brim.cpp @@ -71,12 +71,16 @@ static ConstPrintObjectPtrs get_top_level_objects_with_brim(const Print &print, Polygons islands; ConstPrintObjectPtrs island_to_object; for(size_t print_object_idx = 0; print_object_idx < print.objects().size(); ++print_object_idx) { + const PrintObject *object = print.objects()[print_object_idx]; + + if (! object->has_brim()) + continue; + Polygons islands_object; islands_object.reserve(bottom_layers_expolygons[print_object_idx].size()); for (const ExPolygon &ex_poly : bottom_layers_expolygons[print_object_idx]) islands_object.emplace_back(ex_poly.contour); - const PrintObject *object = print.objects()[print_object_idx]; islands.reserve(islands.size() + object->instances().size() * islands_object.size()); for (const PrintInstance &instance : object->instances()) for (Polygon &poly : islands_object) { diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 491960705cd..0056aee3335 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -271,7 +271,11 @@ public: // Centering offset of the sliced mesh from the scaled and rotated mesh of the model. const Point& center_offset() const { return m_center_offset; } - bool has_brim() const { return this->config().brim_type != btNoBrim && this->config().brim_width.value > 0.; } + bool has_brim() const { + return this->config().brim_type != btNoBrim + && this->config().brim_width.value > 0. + && ! this->has_raft(); + } // This is the *total* layer count (including support layers) // this value is not supposed to be compared with Layer::id @@ -321,7 +325,7 @@ public: bool has_raft() const { return m_config.raft_layers > 0; } bool has_support_material() const { return this->has_support() || this->has_raft(); } // Checks if the model object is painted using the multi-material painting gizmo. - bool is_mm_painted() const { return this->model_object()->is_mm_painted(); }; + bool is_mm_painted() const { return this->model_object()->is_mm_painted(); } // returns 0-based indices of extruders used to print the object (without brim, support and other helper extrusions) std::vector object_extruders() const; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index dffb8ac0c23..c46ac04d696 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -471,7 +471,8 @@ void PrintConfigDef::init_fff_params() def = this->add("brim_width", coFloat); def->label = L("Brim width"); def->category = L("Skirt and brim"); - def->tooltip = L("Horizontal width of the brim that will be printed around each object on the first layer."); + def->tooltip = L("Horizontal width of the brim that will be printed around each object on the first layer." + "When raft is used, no brim is generated (use raft_first_layer_expansion)."); def->sidetext = L("mm"); def->min = 0; def->max = 200; From 81e5893eaa927415371bcfb3074a679ca66f4e7b Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 24 Aug 2021 13:10:35 +0200 Subject: [PATCH 14/25] Initialization of various Preset list of config options was made thread safe. --- src/libslic3r/Preset.cpp | 403 ++++++++++++++++++--------------------- 1 file changed, 185 insertions(+), 218 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 26359b866ce..bb083e03ce5 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -413,212 +413,181 @@ void Preset::set_visible_from_appconfig(const AppConfig &app_config) } } -const std::vector& Preset::print_options() -{ - static std::vector s_opts { - "layer_height", "first_layer_height", "perimeters", "spiral_vase", "slice_closing_radius", "slicing_mode", - "top_solid_layers", "top_solid_min_thickness", "bottom_solid_layers", "bottom_solid_min_thickness", - "extra_perimeters", "ensure_vertical_shell_thickness", "avoid_crossing_perimeters", "thin_walls", "overhangs", - "seam_position", "external_perimeters_first", "fill_density", "fill_pattern", "top_fill_pattern", "bottom_fill_pattern", - "infill_every_layers", "infill_only_where_needed", "solid_infill_every_layers", "fill_angle", "bridge_angle", - "solid_infill_below_area", "only_retract_when_crossing_perimeters", "infill_first", - "ironing", "ironing_type", "ironing_flowrate", "ironing_speed", "ironing_spacing", - "max_print_speed", "max_volumetric_speed", "avoid_crossing_perimeters_max_detour", - "fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_dist", +static std::vector s_Preset_print_options { + "layer_height", "first_layer_height", "perimeters", "spiral_vase", "slice_closing_radius", "slicing_mode", + "top_solid_layers", "top_solid_min_thickness", "bottom_solid_layers", "bottom_solid_min_thickness", + "extra_perimeters", "ensure_vertical_shell_thickness", "avoid_crossing_perimeters", "thin_walls", "overhangs", + "seam_position", "external_perimeters_first", "fill_density", "fill_pattern", "top_fill_pattern", "bottom_fill_pattern", + "infill_every_layers", "infill_only_where_needed", "solid_infill_every_layers", "fill_angle", "bridge_angle", + "solid_infill_below_area", "only_retract_when_crossing_perimeters", "infill_first", + "ironing", "ironing_type", "ironing_flowrate", "ironing_speed", "ironing_spacing", + "max_print_speed", "max_volumetric_speed", "avoid_crossing_perimeters_max_detour", + "fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_dist", #ifdef HAS_PRESSURE_EQUALIZER - "max_volumetric_extrusion_rate_slope_positive", "max_volumetric_extrusion_rate_slope_negative", + "max_volumetric_extrusion_rate_slope_positive", "max_volumetric_extrusion_rate_slope_negative", #endif /* HAS_PRESSURE_EQUALIZER */ - "perimeter_speed", "small_perimeter_speed", "external_perimeter_speed", "infill_speed", "solid_infill_speed", - "top_solid_infill_speed", "support_material_speed", "support_material_xy_spacing", "support_material_interface_speed", - "bridge_speed", "gap_fill_speed", "gap_fill_enabled", "travel_speed", "travel_speed_z", "first_layer_speed", "perimeter_acceleration", "infill_acceleration", - "bridge_acceleration", "first_layer_acceleration", "default_acceleration", "skirts", "skirt_distance", "skirt_height", "draft_shield", - "min_skirt_length", "brim_width", "brim_offset", "brim_type", "support_material", "support_material_auto", "support_material_threshold", "support_material_enforce_layers", - "raft_layers", "raft_first_layer_density", "raft_first_layer_expansion", "raft_contact_distance", "raft_expansion", - "support_material_pattern", "support_material_with_sheath", "support_material_spacing", "support_material_closing_radius", "support_material_style", - "support_material_synchronize_layers", "support_material_angle", "support_material_interface_layers", "support_material_bottom_interface_layers", - "support_material_interface_pattern", "support_material_interface_spacing", "support_material_interface_contact_loops", - "support_material_contact_distance", "support_material_bottom_contact_distance", - "support_material_buildplate_only", "dont_support_bridges", "thick_bridges", "notes", "complete_objects", "extruder_clearance_radius", - "extruder_clearance_height", "gcode_comments", "gcode_label_objects", "output_filename_format", "post_process", "perimeter_extruder", - "infill_extruder", "solid_infill_extruder", "support_material_extruder", "support_material_interface_extruder", - "ooze_prevention", "standby_temperature_delta", "interface_shells", "extrusion_width", "first_layer_extrusion_width", - "perimeter_extrusion_width", "external_perimeter_extrusion_width", "infill_extrusion_width", "solid_infill_extrusion_width", - "top_infill_extrusion_width", "support_material_extrusion_width", "infill_overlap", "infill_anchor", "infill_anchor_max", "bridge_flow_ratio", "clip_multipart_objects", - "elefant_foot_compensation", "xy_size_compensation", "threads", "resolution", "wipe_tower", "wipe_tower_x", "wipe_tower_y", - "wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_brim_width", "wipe_tower_bridging", "single_extruder_multi_material_priming", "mmu_segmented_region_max_width", - "wipe_tower_no_sparse_layers", "compatible_printers", "compatible_printers_condition", "inherits" - }; - return s_opts; -} + "perimeter_speed", "small_perimeter_speed", "external_perimeter_speed", "infill_speed", "solid_infill_speed", + "top_solid_infill_speed", "support_material_speed", "support_material_xy_spacing", "support_material_interface_speed", + "bridge_speed", "gap_fill_speed", "gap_fill_enabled", "travel_speed", "travel_speed_z", "first_layer_speed", "perimeter_acceleration", "infill_acceleration", + "bridge_acceleration", "first_layer_acceleration", "default_acceleration", "skirts", "skirt_distance", "skirt_height", "draft_shield", + "min_skirt_length", "brim_width", "brim_offset", "brim_type", "support_material", "support_material_auto", "support_material_threshold", "support_material_enforce_layers", + "raft_layers", "raft_first_layer_density", "raft_first_layer_expansion", "raft_contact_distance", "raft_expansion", + "support_material_pattern", "support_material_with_sheath", "support_material_spacing", "support_material_closing_radius", "support_material_style", + "support_material_synchronize_layers", "support_material_angle", "support_material_interface_layers", "support_material_bottom_interface_layers", + "support_material_interface_pattern", "support_material_interface_spacing", "support_material_interface_contact_loops", + "support_material_contact_distance", "support_material_bottom_contact_distance", + "support_material_buildplate_only", "dont_support_bridges", "thick_bridges", "notes", "complete_objects", "extruder_clearance_radius", + "extruder_clearance_height", "gcode_comments", "gcode_label_objects", "output_filename_format", "post_process", "perimeter_extruder", + "infill_extruder", "solid_infill_extruder", "support_material_extruder", "support_material_interface_extruder", + "ooze_prevention", "standby_temperature_delta", "interface_shells", "extrusion_width", "first_layer_extrusion_width", + "perimeter_extrusion_width", "external_perimeter_extrusion_width", "infill_extrusion_width", "solid_infill_extrusion_width", + "top_infill_extrusion_width", "support_material_extrusion_width", "infill_overlap", "infill_anchor", "infill_anchor_max", "bridge_flow_ratio", "clip_multipart_objects", + "elefant_foot_compensation", "xy_size_compensation", "threads", "resolution", "wipe_tower", "wipe_tower_x", "wipe_tower_y", + "wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_brim_width", "wipe_tower_bridging", "single_extruder_multi_material_priming", "mmu_segmented_region_max_width", + "wipe_tower_no_sparse_layers", "compatible_printers", "compatible_printers_condition", "inherits" +}; -const std::vector& Preset::filament_options() -{ - static std::vector s_opts { - "filament_colour", "filament_diameter", "filament_type", "filament_soluble", "filament_notes", "filament_max_volumetric_speed", - "extrusion_multiplier", "filament_density", "filament_cost", "filament_spool_weight", "filament_loading_speed", "filament_loading_speed_start", "filament_load_time", - "filament_unloading_speed", "filament_unloading_speed_start", "filament_unload_time", "filament_toolchange_delay", "filament_cooling_moves", - "filament_cooling_initial_speed", "filament_cooling_final_speed", "filament_ramming_parameters", "filament_minimal_purge_on_wipe_tower", - "temperature", "first_layer_temperature", "bed_temperature", "first_layer_bed_temperature", "fan_always_on", "cooling", "min_fan_speed", - "max_fan_speed", "bridge_fan_speed", "disable_fan_first_layers", "full_fan_speed_layer", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed", - "start_filament_gcode", "end_filament_gcode", - // Retract overrides - "filament_retract_length", "filament_retract_lift", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_speed", "filament_deretract_speed", "filament_retract_restart_extra", "filament_retract_before_travel", - "filament_retract_layer_change", "filament_wipe", "filament_retract_before_wipe", - // Profile compatibility - "filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits" - }; - return s_opts; -} +static std::vector s_Preset_filament_options { + "filament_colour", "filament_diameter", "filament_type", "filament_soluble", "filament_notes", "filament_max_volumetric_speed", + "extrusion_multiplier", "filament_density", "filament_cost", "filament_spool_weight", "filament_loading_speed", "filament_loading_speed_start", "filament_load_time", + "filament_unloading_speed", "filament_unloading_speed_start", "filament_unload_time", "filament_toolchange_delay", "filament_cooling_moves", + "filament_cooling_initial_speed", "filament_cooling_final_speed", "filament_ramming_parameters", "filament_minimal_purge_on_wipe_tower", + "temperature", "first_layer_temperature", "bed_temperature", "first_layer_bed_temperature", "fan_always_on", "cooling", "min_fan_speed", + "max_fan_speed", "bridge_fan_speed", "disable_fan_first_layers", "full_fan_speed_layer", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed", + "start_filament_gcode", "end_filament_gcode", + // Retract overrides + "filament_retract_length", "filament_retract_lift", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_speed", "filament_deretract_speed", "filament_retract_restart_extra", "filament_retract_before_travel", + "filament_retract_layer_change", "filament_wipe", "filament_retract_before_wipe", + // Profile compatibility + "filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits" +}; -const std::vector& Preset::machine_limits_options() -{ - static std::vector s_opts; - if (s_opts.empty()) { - s_opts = { - "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", "machine_max_acceleration_travel", - "machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e", - "machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e", - "machine_min_extruding_rate", "machine_min_travel_rate", - "machine_max_jerk_x", "machine_max_jerk_y", "machine_max_jerk_z", "machine_max_jerk_e", - }; - } - return s_opts; -} +static std::vector s_Preset_machine_limits_options { + "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", "machine_max_acceleration_travel", + "machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e", + "machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e", + "machine_min_extruding_rate", "machine_min_travel_rate", + "machine_max_jerk_x", "machine_max_jerk_y", "machine_max_jerk_z", "machine_max_jerk_e", +}; + +static std::vector s_Preset_printer_options { + "printer_technology", + "bed_shape", "bed_custom_texture", "bed_custom_model", "z_offset", "gcode_flavor", "use_relative_e_distances", + "use_firmware_retraction", "use_volumetric_e", "variable_layer_height", + //FIXME the print host keys are left here just for conversion from the Printer preset to Physical Printer preset. + "host_type", "print_host", "printhost_apikey", "printhost_cafile", + "single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode", + "color_change_gcode", "pause_print_gcode", "template_custom_gcode", + "between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction", + "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height", + "default_print_profile", "inherits", + "remaining_times", "silent_mode", + "machine_limits_usage", "thumbnails" +}; + +static std::vector s_Preset_sla_print_options { + "layer_height", + "faded_layers", + "supports_enable", + "support_head_front_diameter", + "support_head_penetration", + "support_head_width", + "support_pillar_diameter", + "support_small_pillar_diameter_percent", + "support_max_bridges_on_pillar", + "support_pillar_connection_mode", + "support_buildplate_only", + "support_pillar_widening_factor", + "support_base_diameter", + "support_base_height", + "support_base_safety_distance", + "support_critical_angle", + "support_max_bridge_length", + "support_max_pillar_link_distance", + "support_object_elevation", + "support_points_density_relative", + "support_points_minimal_distance", + "slice_closing_radius", + "slicing_mode", + "pad_enable", + "pad_wall_thickness", + "pad_wall_height", + "pad_brim_size", + "pad_max_merge_distance", + // "pad_edge_radius", + "pad_wall_slope", + "pad_object_gap", + "pad_around_object", + "pad_around_object_everywhere", + "pad_object_connector_stride", + "pad_object_connector_width", + "pad_object_connector_penetration", + "hollowing_enable", + "hollowing_min_thickness", + "hollowing_quality", + "hollowing_closing_distance", + "output_filename_format", + "default_sla_print_profile", + "compatible_printers", + "compatible_printers_condition", + "inherits" +}; + +static std::vector s_Preset_sla_material_options { + "material_type", + "initial_layer_height", + "bottle_cost", + "bottle_volume", + "bottle_weight", + "material_density", + "exposure_time", + "initial_exposure_time", + "material_correction", + "material_notes", + "material_vendor", + "default_sla_material_profile", + "compatible_prints", "compatible_prints_condition", + "compatible_printers", "compatible_printers_condition", "inherits" +}; + +static std::vector s_Preset_sla_printer_options { + "printer_technology", + "bed_shape", "bed_custom_texture", "bed_custom_model", "max_print_height", + "display_width", "display_height", "display_pixels_x", "display_pixels_y", + "display_mirror_x", "display_mirror_y", + "display_orientation", + "fast_tilt_time", "slow_tilt_time", "area_fill", + "relative_correction", + "absolute_correction", + "elefant_foot_compensation", + "elefant_foot_min_width", + "gamma_correction", + "min_exposure_time", "max_exposure_time", + "min_initial_exposure_time", "max_initial_exposure_time", + //FIXME the print host keys are left here just for conversion from the Printer preset to Physical Printer preset. + "print_host", "printhost_apikey", "printhost_cafile", + "printer_notes", + "inherits" +}; + +const std::vector& Preset::print_options() { return s_Preset_print_options; } +const std::vector& Preset::filament_options() { return s_Preset_filament_options; } +const std::vector& Preset::machine_limits_options() { return s_Preset_machine_limits_options; } +// The following nozzle options of a printer profile will be adjusted to match the size +// of the nozzle_diameter vector. +const std::vector& Preset::nozzle_options() { return print_config_def.extruder_option_keys(); } +const std::vector& Preset::sla_print_options() { return s_Preset_sla_print_options; } +const std::vector& Preset::sla_material_options() { return s_Preset_sla_material_options; } +const std::vector& Preset::sla_printer_options() { return s_Preset_sla_printer_options; } const std::vector& Preset::printer_options() { - static std::vector s_opts; - if (s_opts.empty()) { - s_opts = { - "printer_technology", - "bed_shape", "bed_custom_texture", "bed_custom_model", "z_offset", "gcode_flavor", "use_relative_e_distances", - "use_firmware_retraction", "use_volumetric_e", "variable_layer_height", - //FIXME the print host keys are left here just for conversion from the Printer preset to Physical Printer preset. - "host_type", "print_host", "printhost_apikey", "printhost_cafile", - "single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode", - "color_change_gcode", "pause_print_gcode", "template_custom_gcode", - "between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction", - "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height", - "default_print_profile", "inherits", - "remaining_times", "silent_mode", - "machine_limits_usage", "thumbnails" - }; - s_opts.insert(s_opts.end(), Preset::machine_limits_options().begin(), Preset::machine_limits_options().end()); - s_opts.insert(s_opts.end(), Preset::nozzle_options().begin(), Preset::nozzle_options().end()); - } - return s_opts; -} - -// The following nozzle options of a printer profile will be adjusted to match the size -// of the nozzle_diameter vector. -const std::vector& Preset::nozzle_options() -{ - return print_config_def.extruder_option_keys(); -} - -const std::vector& Preset::sla_print_options() -{ - static std::vector s_opts; - if (s_opts.empty()) { - s_opts = { - "layer_height", - "faded_layers", - "supports_enable", - "support_head_front_diameter", - "support_head_penetration", - "support_head_width", - "support_pillar_diameter", - "support_small_pillar_diameter_percent", - "support_max_bridges_on_pillar", - "support_pillar_connection_mode", - "support_buildplate_only", - "support_pillar_widening_factor", - "support_base_diameter", - "support_base_height", - "support_base_safety_distance", - "support_critical_angle", - "support_max_bridge_length", - "support_max_pillar_link_distance", - "support_object_elevation", - "support_points_density_relative", - "support_points_minimal_distance", - "slice_closing_radius", - "slicing_mode", - "pad_enable", - "pad_wall_thickness", - "pad_wall_height", - "pad_brim_size", - "pad_max_merge_distance", - // "pad_edge_radius", - "pad_wall_slope", - "pad_object_gap", - "pad_around_object", - "pad_around_object_everywhere", - "pad_object_connector_stride", - "pad_object_connector_width", - "pad_object_connector_penetration", - "hollowing_enable", - "hollowing_min_thickness", - "hollowing_quality", - "hollowing_closing_distance", - "output_filename_format", - "default_sla_print_profile", - "compatible_printers", - "compatible_printers_condition", - "inherits" - }; - } - return s_opts; -} - -const std::vector& Preset::sla_material_options() -{ - static std::vector s_opts; - if (s_opts.empty()) { - s_opts = { - "material_type", - "initial_layer_height", - "bottle_cost", - "bottle_volume", - "bottle_weight", - "material_density", - "exposure_time", - "initial_exposure_time", - "material_correction", - "material_notes", - "material_vendor", - "default_sla_material_profile", - "compatible_prints", "compatible_prints_condition", - "compatible_printers", "compatible_printers_condition", "inherits" - }; - } - return s_opts; -} - -const std::vector& Preset::sla_printer_options() -{ - static std::vector s_opts; - if (s_opts.empty()) { - s_opts = { - "printer_technology", - "bed_shape", "bed_custom_texture", "bed_custom_model", "max_print_height", - "display_width", "display_height", "display_pixels_x", "display_pixels_y", - "display_mirror_x", "display_mirror_y", - "display_orientation", - "fast_tilt_time", "slow_tilt_time", "area_fill", - "relative_correction", - "absolute_correction", - "elefant_foot_compensation", - "elefant_foot_min_width", - "gamma_correction", - "min_exposure_time", "max_exposure_time", - "min_initial_exposure_time", "max_initial_exposure_time", - //FIXME the print host keys are left here just for conversion from the Printer preset to Physical Printer preset. - "print_host", "printhost_apikey", "printhost_cafile", - "printer_notes", - "inherits" - }; - } + static std::vector s_opts = [](){ + std::vector opts = s_Preset_printer_options; + append(opts, s_Preset_machine_limits_options); + append(opts, Preset::nozzle_options()); + return opts; + }(); return s_opts; } @@ -1426,27 +1395,25 @@ std::string PhysicalPrinter::separator() return " * "; } +static std::vector s_PhysicalPrinter_opts { + "preset_name", // temporary option to compatibility with older Slicer + "preset_names", + "printer_technology", + "host_type", + "print_host", + "printhost_apikey", + "printhost_cafile", + "printhost_port", + "printhost_authorization_type", + // HTTP digest authentization (RFC 2617) + "printhost_user", + "printhost_password", + "printhost_ignore_check" +}; + const std::vector& PhysicalPrinter::printer_options() { - static std::vector s_opts; - if (s_opts.empty()) { - s_opts = { - "preset_name", // temporary option to compatibility with older Slicer - "preset_names", - "printer_technology", - "host_type", - "print_host", - "printhost_apikey", - "printhost_cafile", - "printhost_port", - "printhost_authorization_type", - // HTTP digest authentization (RFC 2617) - "printhost_user", - "printhost_password", - "printhost_ignore_check" - }; - } - return s_opts; + return s_PhysicalPrinter_opts; } static constexpr auto legacy_print_host_options = { From 60261f2b8b16f305abd3ddb579d1dd5948e0e327 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 24 Aug 2021 13:57:52 +0200 Subject: [PATCH 15/25] Follow-up to OctoPrint upload: ignore certificate revocation checks 6b03b66167dd17bc6c804f58b9af124082e80287 Renamed the new "printhost_ignore_check" option to "printhost_ssl_ignore_revoke" Improved the Physical Printers dialog in regard to the new option checkbox (added tooltip to the checkbox, moved it to the end of options). Disabled the host_xxx options at the command line interface, they no more work after these options were separated to Physical Printers profiles. Little refactoring of Http.cpp/hpp, OctoPrint.cpp/hpp Private local variables prefixed with m_, some renaming for clarity. --- src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 49 +++++++++++++++--------- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 13 +++---- src/slic3r/Utils/Http.cpp | 4 +- src/slic3r/Utils/Http.hpp | 6 ++- src/slic3r/Utils/OctoPrint.cpp | 48 +++++++++++------------ src/slic3r/Utils/OctoPrint.hpp | 26 ++++++------- 7 files changed, 82 insertions(+), 66 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index bb083e03ce5..3883c4980b3 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1408,7 +1408,7 @@ static std::vector s_PhysicalPrinter_opts { // HTTP digest authentization (RFC 2617) "printhost_user", "printhost_password", - "printhost_ignore_check" + "printhost_ssl_ignore_revoke" }; const std::vector& PhysicalPrinter::printer_options() diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index c46ac04d696..f010bad3997 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -232,6 +232,16 @@ void PrintConfigDef::init_common_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionString("")); + def = this->add("elefant_foot_compensation", coFloat); + def->label = L("Elephant foot compensation"); + def->category = L("Advanced"); + def->tooltip = L("The first layer will be shrunk in the XY plane by the configured value " + "to compensate for the 1st layer squish aka an Elephant Foot effect."); + def->sidetext = L("mm"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(0.)); + def = this->add("thumbnails", coPoints); def->label = L("G-code thumbnails"); def->tooltip = L("Picture sizes to be stored into a .gcode and .sl1 / .sl1s files, in the following format: \"XxY, XxY, ...\""); @@ -264,6 +274,7 @@ void PrintConfigDef::init_common_params() "Print host behind HAProxy with basic auth enabled can be accessed by putting the user name and password into the URL " "in the following format: https://username:password@your-octopi-address/"); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); def = this->add("printhost_apikey", coString); @@ -271,6 +282,7 @@ void PrintConfigDef::init_common_params() def->tooltip = L("Slic3r can upload G-code files to a printer host. This field should contain " "the API Key or the password required for authentication."); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); def = this->add("printhost_port", coString); @@ -278,6 +290,7 @@ void PrintConfigDef::init_common_params() def->tooltip = L("Name of the printer"); def->gui_type = ConfigOptionDef::GUIType::select_open; def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); def = this->add("printhost_cafile", coString); @@ -285,36 +298,32 @@ void PrintConfigDef::init_common_params() def->tooltip = L("Custom CA certificate file can be specified for HTTPS OctoPrint connections, in crt/pem format. " "If left blank, the default OS CA certificate repository is used."); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); - def = this->add("elefant_foot_compensation", coFloat); - def->label = L("Elephant foot compensation"); - def->category = L("Advanced"); - def->tooltip = L("The first layer will be shrunk in the XY plane by the configured value " - "to compensate for the 1st layer squish aka an Elephant Foot effect."); - def->sidetext = L("mm"); - def->min = 0; - def->mode = comAdvanced; - def->set_default_value(new ConfigOptionFloat(0.)); - // Options used by physical printers def = this->add("printhost_user", coString); def->label = L("User"); // def->tooltip = L(""); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); def = this->add("printhost_password", coString); def->label = L("Password"); // def->tooltip = L(""); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); - def = this->add("printhost_ignore_check", coBool); - def->label = L("Ignore certificate revocation checks"); - // def->tooltip = L(""); + // Only available on Windows. + def = this->add("printhost_ssl_ignore_revoke", coBool); + def->label = L("Ignore HTTPS certificate revocation checks"); + def->tooltip = L("Ignore HTTPS certificate revocation checks in case of missing or offline distribution points. " + "One may want to enable this option for self signed certificates if connection fails."); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionBool(false)); def = this->add("preset_names", coStrings); @@ -323,12 +332,6 @@ void PrintConfigDef::init_common_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionStrings()); - // temporary workaround for compatibility with older Slicer - { - def = this->add("preset_name", coString); - def->set_default_value(new ConfigOptionString()); - } - def = this->add("printhost_authorization_type", coEnum); def->label = L("Authorization Type"); // def->tooltip = L(""); @@ -338,7 +341,14 @@ void PrintConfigDef::init_common_params() def->enum_labels.push_back(L("API key")); def->enum_labels.push_back(L("HTTP digest")); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionEnum(atKeyPassword)); + + // temporary workaround for compatibility with older Slicer + { + def = this->add("preset_name", coString); + def->set_default_value(new ConfigOptionString()); + } } void PrintConfigDef::init_fff_params() @@ -1816,6 +1826,7 @@ void PrintConfigDef::init_fff_params() def->enum_labels.push_back("AstroBox"); def->enum_labels.push_back("Repetier"); def->mode = comAdvanced; + def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionEnum(htOctoPrint)); def = this->add("only_retract_when_crossing_perimeters", coBool); diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index 9c570172c0f..519abab43fb 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -413,13 +413,6 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr return sizer; }; m_optgroup->append_line(line); - -#ifdef WIN32 - option = m_optgroup->get_option("printhost_ignore_check"); - option.opt.width = Field::def_width_wider(); - m_optgroup->append_single_option_line(option); -#endif - } for (const std::string& opt_key : std::vector{ "printhost_user", "printhost_password" }) { @@ -428,6 +421,12 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr m_optgroup->append_single_option_line(option); } +#ifdef WIN32 + option = m_optgroup->get_option("printhost_ssl_ignore_revoke"); + option.opt.width = Field::def_width_wider(); + m_optgroup->append_single_option_line(option); +#endif + m_optgroup->activate(); Field* printhost_field = m_optgroup->get_field("print_host"); diff --git a/src/slic3r/Utils/Http.cpp b/src/slic3r/Utils/Http.cpp index 69093988ab8..06598f8f5da 100644 --- a/src/slic3r/Utils/Http.cpp +++ b/src/slic3r/Utils/Http.cpp @@ -491,7 +491,9 @@ Http& Http::form_add_file(const std::string &name, const fs::path &path, const s return *this; } -Http& Http::revoke_best_effort(bool set) +// Tells libcurl to ignore certificate revocation checks in case of missing or offline distribution points for those SSL backends where such behavior is present. +// This option is only supported for Schannel (the native Windows SSL library). +Http& Http::ssl_revoke_best_effort(bool set) { if(p && set){ ::curl_easy_setopt(p->curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT); diff --git a/src/slic3r/Utils/Http.hpp b/src/slic3r/Utils/Http.hpp index 3cce250862a..52e48a394cf 100644 --- a/src/slic3r/Utils/Http.hpp +++ b/src/slic3r/Utils/Http.hpp @@ -80,7 +80,11 @@ public: // Same as above except also override the file's filename with a custom one Http& form_add_file(const std::string &name, const boost::filesystem::path &path, const std::string &filename); - Http& revoke_best_effort(bool set); +#ifdef WIN32 + // Tells libcurl to ignore certificate revocation checks in case of missing or offline distribution points for those SSL backends where such behavior is present. + // This option is only supported for Schannel (the native Windows SSL library). + Http& ssl_revoke_best_effort(bool set); +#endif // WIN32 // Set the file contents as a POST request body. // The data is used verbatim, it is not additionally encoded in any way. diff --git a/src/slic3r/Utils/OctoPrint.cpp b/src/slic3r/Utils/OctoPrint.cpp index 3a2335b1ef7..f9ae4af5a1c 100644 --- a/src/slic3r/Utils/OctoPrint.cpp +++ b/src/slic3r/Utils/OctoPrint.cpp @@ -23,10 +23,10 @@ namespace pt = boost::property_tree; namespace Slic3r { OctoPrint::OctoPrint(DynamicPrintConfig *config) : - host(config->opt_string("print_host")), - apikey(config->opt_string("printhost_apikey")), - cafile(config->opt_string("printhost_cafile")), - ignore_checks(config->opt_bool("printhost_ignore_check")) + m_host(config->opt_string("print_host")), + m_apikey(config->opt_string("printhost_apikey")), + m_cafile(config->opt_string("printhost_cafile")), + m_ssl_revoke_best_effort(config->opt_bool("printhost_ssl_ignore_revoke")) {} const char* OctoPrint::get_name() const { return "OctoPrint"; } @@ -75,7 +75,7 @@ bool OctoPrint::test(wxString &msg) const } }) #ifdef WIN32 - .revoke_best_effort(ignore_checks) + .ssl_revoke_best_effort(m_ssl_revoke_best_effort) #endif .perform_sync(); @@ -142,7 +142,7 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro } }) #ifdef WIN32 - .revoke_best_effort(ignore_checks) + .ssl_revoke_best_effort(m_ssl_revoke_best_effort) #endif .perform_sync(); @@ -156,31 +156,31 @@ bool OctoPrint::validate_version_text(const boost::optional &versio void OctoPrint::set_auth(Http &http) const { - http.header("X-Api-Key", apikey); + http.header("X-Api-Key", m_apikey); - if (! cafile.empty()) { - http.ca_file(cafile); + if (!m_cafile.empty()) { + http.ca_file(m_cafile); } } std::string OctoPrint::make_url(const std::string &path) const { - if (host.find("http://") == 0 || host.find("https://") == 0) { - if (host.back() == '/') { - return (boost::format("%1%%2%") % host % path).str(); + if (m_host.find("http://") == 0 || m_host.find("https://") == 0) { + if (m_host.back() == '/') { + return (boost::format("%1%%2%") % m_host % path).str(); } else { - return (boost::format("%1%/%2%") % host % path).str(); + return (boost::format("%1%/%2%") % m_host % path).str(); } } else { - return (boost::format("http://%1%/%2%") % host % path).str(); + return (boost::format("http://%1%/%2%") % m_host % path).str(); } } SL1Host::SL1Host(DynamicPrintConfig *config) : OctoPrint(config), - authorization_type(dynamic_cast*>(config->option("printhost_authorization_type"))->value), - username(config->opt_string("printhost_user")), - password(config->opt_string("printhost_password")) + m_authorization_type(dynamic_cast*>(config->option("printhost_authorization_type"))->value), + m_username(config->opt_string("printhost_user")), + m_password(config->opt_string("printhost_password")) { } @@ -206,12 +206,12 @@ bool SL1Host::validate_version_text(const boost::optional &version_ void SL1Host::set_auth(Http &http) const { - switch (authorization_type) { + switch (m_authorization_type) { case atKeyPassword: http.header("X-Api-Key", get_apikey()); break; case atUserPassword: - http.auth_digest(username, password); + http.auth_digest(m_username, m_password); break; } @@ -223,9 +223,9 @@ void SL1Host::set_auth(Http &http) const // PrusaLink PrusaLink::PrusaLink(DynamicPrintConfig* config) : OctoPrint(config), - authorization_type(dynamic_cast*>(config->option("printhost_authorization_type"))->value), - username(config->opt_string("printhost_user")), - password(config->opt_string("printhost_password")) + m_authorization_type(dynamic_cast*>(config->option("printhost_authorization_type"))->value), + m_username(config->opt_string("printhost_user")), + m_password(config->opt_string("printhost_password")) { } @@ -250,12 +250,12 @@ bool PrusaLink::validate_version_text(const boost::optional& versio void PrusaLink::set_auth(Http& http) const { - switch (authorization_type) { + switch (m_authorization_type) { case atKeyPassword: http.header("X-Api-Key", get_apikey()); break; case atUserPassword: - http.auth_digest(username, password); + http.auth_digest(m_username, m_password); break; } diff --git a/src/slic3r/Utils/OctoPrint.hpp b/src/slic3r/Utils/OctoPrint.hpp index 42683dc62ba..48035b7951a 100644 --- a/src/slic3r/Utils/OctoPrint.hpp +++ b/src/slic3r/Utils/OctoPrint.hpp @@ -29,18 +29,18 @@ public: bool has_auto_discovery() const override { return true; } bool can_test() const override { return true; } bool can_start_print() const override { return true; } - std::string get_host() const override { return host; } - const std::string& get_apikey() const { return apikey; } - const std::string& get_cafile() const { return cafile; } + std::string get_host() const override { return m_host; } + const std::string& get_apikey() const { return m_apikey; } + const std::string& get_cafile() const { return m_cafile; } protected: virtual bool validate_version_text(const boost::optional &version_text) const; private: - std::string host; - std::string apikey; - std::string cafile; - bool ignore_checks; + std::string m_host; + std::string m_apikey; + std::string m_cafile; + bool m_ssl_revoke_best_effort; virtual void set_auth(Http &http) const; std::string make_url(const std::string &path) const; @@ -65,10 +65,10 @@ private: void set_auth(Http &http) const override; // Host authorization type. - AuthorizationType authorization_type; + AuthorizationType m_authorization_type; // username and password for HTTP Digest Authentization (RFC RFC2617) - std::string username; - std::string password; + std::string m_username; + std::string m_password; }; class PrusaLink : public OctoPrint @@ -90,10 +90,10 @@ private: void set_auth(Http& http) const override; // Host authorization type. - AuthorizationType authorization_type; + AuthorizationType m_authorization_type; // username and password for HTTP Digest Authentization (RFC RFC2617) - std::string username; - std::string password; + std::string m_username; + std::string m_password; }; } From 2498f42b72a0f68ab4566c6a64d1bf349da0c14d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 24 Aug 2021 16:48:05 +0200 Subject: [PATCH 16/25] Hints notification random weighted order with saving used hints to cache/hints.cereal --- src/libslic3r/AppConfig.cpp | 3 - src/slic3r/GUI/HintNotification.cpp | 224 ++++++++++++++++++++-------- src/slic3r/GUI/HintNotification.hpp | 21 ++- 3 files changed, 180 insertions(+), 68 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 4166658f5a2..177d8d708b3 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -167,9 +167,6 @@ void AppConfig::set_defaults() if (get("show_splash_screen").empty()) set("show_splash_screen", "1"); - if (get("last_hint").empty()) - set("last_hint", "0"); - if (get("show_hints").empty()) set("show_hints", "1"); diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index 42039fa7012..cd92cf48019 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -14,6 +14,31 @@ #include #include #include +#include +#include +#include + +#define HINTS_CEREAL_VERSION 1 +// structure for writing used hints into binary file with version +struct CerealData +{ + std::vector my_data; + // cereal will supply the version automatically when loading or saving + // The version number comes from the CEREAL_CLASS_VERSION macro + template + void serialize(Archive& ar, std::uint32_t const version) + { + // You can choose different behaviors depending on the version + // This is useful if you need to support older variants of your codebase + // interacting with newer ones + if (version > HINTS_CEREAL_VERSION) + throw Slic3r::IOError("Version of hints.cereal is higher than current version."); + else + ar(my_data); + } +}; +// version of used hints binary file +CEREAL_CLASS_VERSION(CerealData, HINTS_CEREAL_VERSION); namespace Slic3r { namespace GUI { @@ -31,6 +56,41 @@ inline void push_style_color(ImGuiCol idx, const ImVec4& col, bool fading_out, f else ImGui::PushStyleColor(idx, col); } + + + + + +void write_used_binary(const std::vector& ids) +{ + boost::filesystem::ofstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal"), std::ios::binary); + cereal::BinaryOutputArchive archive(file); + CerealData cd { ids }; + try + { + archive(cd); + } + catch (const std::exception& ex) + { + BOOST_LOG_TRIVIAL(error) << "Failed to write to hints.cereal. " << ex.what(); + } +} +void read_used_binary(std::vector& ids) +{ + boost::filesystem::ifstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal")); + cereal::BinaryInputArchive archive(file); + CerealData cd; + try + { + archive(cd); + } + catch (const std::exception& ex) + { + BOOST_LOG_TRIVIAL(error) << "Failed to load to hints.cereal. " << ex.what(); + return; + } + ids = cd.my_data; +} enum TagCheckResult { TagCheckAffirmative, @@ -179,30 +239,19 @@ void launch_browser_if_allowed(const std::string& url) if (wxGetApp().app_config->get("suppress_hyperlinks") != "1") wxLaunchDefaultBrowser(url); } -bool pot_exists() -{ - return true; -// return boost::filesystem::exists(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.pot")); -} -void write_pot(const std::vector& elements) -{ - boost::filesystem::ofstream file(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.pot")); - - for ( const auto &element : elements) - { - file << "msgid \"" << escape_string_cstyle(element) << "\"\nmsgstr \"\"\n\n"; - } - file.close(); -} } //namespace - +HintDatabase::~HintDatabase() +{ + if (m_initialized) { + write_used_binary(m_used_ids); + } +} void HintDatabase::init() { load_hints_from_file(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.ini")); const AppConfig* app_config = wxGetApp().app_config; - m_hint_id = std::atoi(app_config->get("last_hint").c_str()); m_initialized = true; } @@ -210,8 +259,6 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) { namespace pt = boost::property_tree; pt::ptree tree; - bool create_pot = !pot_exists(); - std::vector pot_elements; boost::nowide::ifstream ifs(path.string()); try { pt::read_ini(ifs, tree); @@ -227,19 +274,24 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) for (const auto& data : section.second) { dict.emplace(data.first, data.second.data()); } - - //unescaping and translating all texts and saving all data common for all hint types + // unique id string [hint:id] (trim "hint:") + std::string id_string = section.first.substr(5); + id_string = std::to_string(std::hash{}(id_string)); + // unescaping and translating all texts and saving all data common for all hint types std::string fulltext; std::string text1; std::string hypertext_text; std::string follow_text; + // tags std::string disabled_tags; std::string enabled_tags; + // optional link to documentation (accessed from button) std::string documentation_link; + // randomized weighted order variables + size_t weight = 1; + bool was_displayed = is_used(id_string); //unescape text1 unescape_string_cstyle(_utf8(dict["text"]), fulltext); - if (create_pot) - pot_elements.emplace_back(fulltext); // replace and for imgui markers std::string marker_s(1, ImGui::ColorMarkerStart); std::string marker_e(1, ImGui::ColorMarkerEnd); @@ -295,37 +347,41 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) documentation_link = dict["documentation_link"]; } + if (dict.find("weight") != dict.end()) { + weight = (size_t)std::max(1, std::atoi(dict["weight"].c_str())); + } + // create HintData if (dict.find("hypertext_type") != dict.end()) { //link to internet if(dict["hypertext_type"] == "link") { std::string hypertext_link = dict["hypertext_link"]; - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, [hypertext_link]() { launch_browser_if_allowed(hypertext_link); } }; + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, [hypertext_link]() { launch_browser_if_allowed(hypertext_link); } }; m_loaded_hints.emplace_back(hint_data); // highlight settings } else if (dict["hypertext_type"] == "settings") { std::string opt = dict["hypertext_settings_opt"]; Preset::Type type = static_cast(std::atoi(dict["hypertext_settings_type"].c_str())); std::wstring category = boost::nowide::widen(dict["hypertext_settings_category"]); - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [opt, type, category]() { GUI::wxGetApp().sidebar().jump_to_option(opt, type, category); } }; + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [opt, type, category]() { GUI::wxGetApp().sidebar().jump_to_option(opt, type, category); } }; m_loaded_hints.emplace_back(hint_data); // open preferences } else if(dict["hypertext_type"] == "preferences") { int page = static_cast(std::atoi(dict["hypertext_preferences_page"].c_str())); - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, [page]() { wxGetApp().open_preferences(page); } }; + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, [page]() { wxGetApp().open_preferences(page); } }; m_loaded_hints.emplace_back(hint_data); } else if (dict["hypertext_type"] == "plater") { std::string item = dict["hypertext_plater_item"]; - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [item]() { wxGetApp().plater()->canvas3D()->highlight_toolbar_item(item); } }; + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [item]() { wxGetApp().plater()->canvas3D()->highlight_toolbar_item(item); } }; m_loaded_hints.emplace_back(hint_data); } else if (dict["hypertext_type"] == "gizmo") { std::string item = dict["hypertext_gizmo_item"]; - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [item]() { wxGetApp().plater()->canvas3D()->highlight_gizmo(item); } }; + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, true, documentation_link, [item]() { wxGetApp().plater()->canvas3D()->highlight_gizmo(item); } }; m_loaded_hints.emplace_back(hint_data); } else if (dict["hypertext_type"] == "gallery") { - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, []() { + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link, []() { // Deselect all objects, otherwise gallery wont show. wxGetApp().plater()->canvas3D()->deselect_all(); wxGetApp().obj_list()->load_shape_object_from_gallery(); } }; @@ -333,19 +389,17 @@ void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) } } else { // plain text without hypertext - HintData hint_data{ text1, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link }; + HintData hint_data{ id_string, text1, weight, was_displayed, hypertext_text, follow_text, disabled_tags, enabled_tags, false, documentation_link }; m_loaded_hints.emplace_back(hint_data); } } } - if (create_pot) - write_pot(pot_elements); } -HintData* HintDatabase::get_hint(bool up) +HintData* HintDatabase::get_hint(bool new_hint/* = true*/) { if (! m_initialized) { init(); - //return false; + new_hint = true; } if (m_loaded_hints.empty()) { @@ -353,23 +407,84 @@ HintData* HintDatabase::get_hint(bool up) return nullptr; } - // shift id - m_hint_id = (up ? m_hint_id + 1 : m_hint_id ); - m_hint_id %= m_loaded_hints.size(); + if (new_hint) + m_hint_id = get_next(); - AppConfig* app_config = wxGetApp().app_config; - app_config->set("last_hint", std::to_string(m_hint_id)); - - //data = &m_loaded_hints[m_hint_id]; - /* - data.text = m_loaded_hints[m_hint_id].text; - data.hypertext = m_loaded_hints[m_hint_id].hypertext; - data.follow_text = m_loaded_hints[m_hint_id].follow_text; - data.callback = m_loaded_hints[m_hint_id].callback; - */ return &m_loaded_hints[m_hint_id]; } +size_t HintDatabase::get_next() +{ + if (!m_sorted_hints) + { + auto compare_wieght = [](const HintData& a, const HintData& b){ return a.weight < b.weight; }; + std::sort(m_loaded_hints.begin(), m_loaded_hints.end(), compare_wieght); + m_sorted_hints = true; + srand(time(NULL)); + } + std::vector candidates; // index in m_loaded_hints + // total weight + size_t total_weight = 0; + for (size_t i = 0; i < m_loaded_hints.size(); i++) { + if (!m_loaded_hints[i].was_displayed && tags_check(m_loaded_hints[i].disabled_tags, m_loaded_hints[i].enabled_tags)) { + candidates.emplace_back(i); + total_weight += m_loaded_hints[i].weight; + } + } + // all were shown + if (total_weight == 0) { + clear_used(); + for (size_t i = 0; i < m_loaded_hints.size(); i++) { + m_loaded_hints[i].was_displayed = false; + if (tags_check(m_loaded_hints[i].disabled_tags, m_loaded_hints[i].enabled_tags)) { + candidates.emplace_back(i); + total_weight += m_loaded_hints[i].weight; + } + } + } + size_t random_number = rand() % total_weight + 1; + size_t current_weight = 0; + for (size_t i = 0; i < candidates.size(); i++) { + current_weight += m_loaded_hints[candidates[i]].weight; + if (random_number <= current_weight) { + set_used(m_loaded_hints[candidates[i]].id_string); + m_loaded_hints[candidates[i]].was_displayed = true; + return candidates[i]; + } + } + BOOST_LOG_TRIVIAL(error) << "Hint notification random number generator failed."; + return 0; +} + +bool HintDatabase::is_used(const std::string& id) +{ + // load used ids from file + if (!m_used_ids_loaded) { + read_used_binary(m_used_ids); + m_used_ids_loaded = true; + } + // check if id is in used + for (const std::string& used_id : m_used_ids) { + if (used_id == id) + { + return true; + } + } + return false; +} +void HintDatabase::set_used(const std::string& id) +{ + // check needed? + if (!is_used(id)) + { + m_used_ids.emplace_back(id); + } +} +void HintDatabase::clear_used() +{ + m_used_ids.clear(); +} + void NotificationManager::HintNotification::count_spaces() { //determine line width @@ -865,23 +980,12 @@ void NotificationManager::HintNotification::open_documentation() launch_browser_if_allowed(m_documentation_link); } } -void NotificationManager::HintNotification::retrieve_data(int recursion_counter) +void NotificationManager::HintNotification::retrieve_data(bool new_hint/* = true*/) { - HintData* hint_data = HintDatabase::get_instance().get_hint(recursion_counter >= 0 ? true : false); + HintData* hint_data = HintDatabase::get_instance().get_hint(new_hint); if (hint_data == nullptr) close(); - if (hint_data != nullptr && !tags_check(hint_data->disabled_tags, hint_data->enabled_tags)) - { - // Content for different user - retrieve another - size_t count = HintDatabase::get_instance().get_count(); - if ((int)count < recursion_counter) { - BOOST_LOG_TRIVIAL(error) << "Hint notification failed to load data due to recursion counter."; - } else { - retrieve_data(recursion_counter + 1); - } - return; - } if(hint_data != nullptr) { NotificationData nd { NotificationType::DidYouKnowHint, diff --git a/src/slic3r/GUI/HintNotification.hpp b/src/slic3r/GUI/HintNotification.hpp index 78e02a848cb..c1e7c0ed3c6 100644 --- a/src/slic3r/GUI/HintNotification.hpp +++ b/src/slic3r/GUI/HintNotification.hpp @@ -9,7 +9,10 @@ namespace GUI { // Database of hints updatable struct HintData { + std::string id_string; std::string text; + size_t weight; + bool was_displayed; std::string hypertext; std::string follow_text; std::string disabled_tags; @@ -33,11 +36,12 @@ private: : m_hint_id(0) {} public: + ~HintDatabase(); HintDatabase(HintDatabase const&) = delete; void operator=(HintDatabase const&) = delete; // return true if HintData filled; - HintData* get_hint(bool up = true); + HintData* get_hint(bool new_hint = true); size_t get_count() { if (!m_initialized) return 0; @@ -46,10 +50,17 @@ public: private: void init(); void load_hints_from_file(const boost::filesystem::path& path); + bool is_used(const std::string& id); + void set_used(const std::string& id); + void clear_used(); + // Returns position in m_loaded_hints with next hint chosed randomly with weights + size_t get_next(); size_t m_hint_id; bool m_initialized { false }; std::vector m_loaded_hints; - + bool m_sorted_hints { false }; + std::vector m_used_ids; + bool m_used_ids_loaded { false }; }; // Notification class - shows current Hint ("Did you know") class NotificationManager::HintNotification : public NotificationManager::PopNotification @@ -58,10 +69,10 @@ public: HintNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, bool new_hint) : PopNotification(n, id_provider, evt_handler) { - retrieve_data(new_hint ? 0 : -1); + retrieve_data(new_hint); } virtual void init() override; - void open_next() { retrieve_data(0); } + void open_next() { retrieve_data(); } protected: virtual void set_next_window_size(ImGuiWrapper& imgui) override; virtual void count_spaces() override; @@ -87,7 +98,7 @@ protected: const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y); // recursion counter -1 tells to retrieve same hint as last time - void retrieve_data(int recursion_counter = 0); + void retrieve_data(bool new_hint = true); void open_documentation(); bool m_has_hint_data { false }; From f22ca22fe1dacf3513de8871c4b07b90085956db Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 24 Aug 2021 17:09:49 +0200 Subject: [PATCH 17/25] comments in hints.ini --- resources/data/hints.ini | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/data/hints.ini b/resources/data/hints.ini index 28a13236d66..95060f9ec6f 100644 --- a/resources/data/hints.ini +++ b/resources/data/hints.ini @@ -49,7 +49,13 @@ # Algorithm shows hint only if ALL enabled tags are affirmative. (so never do enabled_tags = FFF; SLA;) # Algorithm shows hint only if not in all disabled tags. # if there are both disabled and preferred, only preferred that are not in disabled are valid. - +# +# +# Notifications shows in random order, already shown notifications are saved at cache/hints.cereal (as binary - human non-readable) +# You can affect random ordering by seting weigh +# weight = 5 +# Weight must be larger or equal to 1. Default weight is 1. +# Weight defines probability as weight : sum_of_all_weights. [hint:Fuzzy skin] text = Fuzzy skin\nDid you know that you can create rough fibre-like texture on the sides of your models using theFuzzy skinfeature? You can also use modifiers to apply fuzzy-skin only to a portion of your model. From 504ffd6fb894eb120a8d3f35adb7e3bfe1677bf3 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 24 Aug 2021 17:23:58 +0200 Subject: [PATCH 18/25] Refactoring + throwing exception from random generator in hints --- src/slic3r/GUI/HintNotification.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index cd92cf48019..990e4d37a98 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -20,7 +20,7 @@ #define HINTS_CEREAL_VERSION 1 // structure for writing used hints into binary file with version -struct CerealData +struct HintsCerealData { std::vector my_data; // cereal will supply the version automatically when loading or saving @@ -38,7 +38,7 @@ struct CerealData } }; // version of used hints binary file -CEREAL_CLASS_VERSION(CerealData, HINTS_CEREAL_VERSION); +CEREAL_CLASS_VERSION(HintsCerealData, HINTS_CEREAL_VERSION); namespace Slic3r { namespace GUI { @@ -65,7 +65,7 @@ void write_used_binary(const std::vector& ids) { boost::filesystem::ofstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal"), std::ios::binary); cereal::BinaryOutputArchive archive(file); - CerealData cd { ids }; + HintsCerealData cd { ids }; try { archive(cd); @@ -79,7 +79,7 @@ void read_used_binary(std::vector& ids) { boost::filesystem::ifstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal")); cereal::BinaryInputArchive archive(file); - CerealData cd; + HintsCerealData cd; try { archive(cd); @@ -407,8 +407,17 @@ HintData* HintDatabase::get_hint(bool new_hint/* = true*/) return nullptr; } - if (new_hint) - m_hint_id = get_next(); + try + { + if (new_hint) + m_hint_id = get_next(); + } + catch (const std::exception&) + { + return nullptr; + } + + return &m_loaded_hints[m_hint_id]; } @@ -442,6 +451,10 @@ size_t HintDatabase::get_next() } } } + if (total_weight == 0) { + BOOST_LOG_TRIVIAL(error) << "Hint notification random number generator failed. No suitable hint was found."; + throw std::exception(); + } size_t random_number = rand() % total_weight + 1; size_t current_weight = 0; for (size_t i = 0; i < candidates.size(); i++) { @@ -453,7 +466,7 @@ size_t HintDatabase::get_next() } } BOOST_LOG_TRIVIAL(error) << "Hint notification random number generator failed."; - return 0; + throw std::exception(); } bool HintDatabase::is_used(const std::string& id) From aba8309f74bb52c09cddb33602dfaef4455b7bd9 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 24 Aug 2021 17:31:34 +0200 Subject: [PATCH 19/25] Erase updatedItemsInfo type from multiple-showing notifications list. --- src/slic3r/GUI/NotificationManager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 2bc9aaaabf2..2be8ba26baa 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -538,7 +538,7 @@ private: // Timestamp of last rendering int64_t m_last_render { 0LL }; // Notification types that can be shown multiple types at once (compared by text) - const std::vector m_multiple_types = { NotificationType::CustomNotification, NotificationType::PlaterWarning, NotificationType::ProgressBar, NotificationType::PrintHostUpload, NotificationType::UpdatedItemsInfo }; + const std::vector m_multiple_types = { NotificationType::CustomNotification, NotificationType::PlaterWarning, NotificationType::ProgressBar, NotificationType::PrintHostUpload }; //prepared (basic) notifications static const NotificationData basic_notifications[]; }; From 84c6547d0cbf54a4d080a4e3f2a2a8b9e6655135 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 25 Aug 2021 09:11:20 +0200 Subject: [PATCH 20/25] Fixed deletion of objects/volumes by pressing Del key while the mouse cursor is hovering the objects list in sidebar --- src/slic3r/GUI/GUI_ObjectList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 0c555454d35..1e290beae83 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1049,7 +1049,7 @@ void ObjectList::key_event(wxKeyEvent& event) || event.GetKeyCode() == WXK_BACK #endif //__WXOSX__ ) { - remove(); + wxGetApp().plater()->remove_selected(); } else if (event.GetKeyCode() == WXK_F5) wxGetApp().plater()->reload_all_from_disk(); From 9c65d3b7ba90ba5df10c8798b09de9d9a8858427 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Wed, 25 Aug 2021 09:34:32 +0200 Subject: [PATCH 21/25] Fix of d3f11a6ab7a7c350439929e9ebf2b03ef4989477 --- src/slic3r/Utils/Http.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/Utils/Http.cpp b/src/slic3r/Utils/Http.cpp index 06598f8f5da..f1614017f0b 100644 --- a/src/slic3r/Utils/Http.cpp +++ b/src/slic3r/Utils/Http.cpp @@ -491,6 +491,7 @@ Http& Http::form_add_file(const std::string &name, const fs::path &path, const s return *this; } +#ifdef WIN32 // Tells libcurl to ignore certificate revocation checks in case of missing or offline distribution points for those SSL backends where such behavior is present. // This option is only supported for Schannel (the native Windows SSL library). Http& Http::ssl_revoke_best_effort(bool set) @@ -500,6 +501,7 @@ Http& Http::ssl_revoke_best_effort(bool set) } return *this; } +#endif // WIN32 Http& Http::set_post_body(const fs::path &path) { From 32638573ca7794fd1e7a60873e1229a60db63fd8 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 25 Aug 2021 09:52:27 +0200 Subject: [PATCH 22/25] Delete unused variable --- src/slic3r/GUI/HintNotification.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index 990e4d37a98..1d5931c4867 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -248,12 +248,8 @@ HintDatabase::~HintDatabase() } void HintDatabase::init() { - load_hints_from_file(std::move(boost::filesystem::path(resources_dir()) / "data" / "hints.ini")); - - const AppConfig* app_config = wxGetApp().app_config; m_initialized = true; - } void HintDatabase::load_hints_from_file(const boost::filesystem::path& path) { From fb2d957495547e637f3ad002619487713602f6f3 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 25 Aug 2021 12:01:41 +0200 Subject: [PATCH 23/25] Fixed invalidation when first_layer_height is changed --- src/libslic3r/Print.cpp | 3 ++- src/libslic3r/PrintObject.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index b3a1bc9939d..48737f8302e 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -159,7 +159,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n || opt_key == "wipe_tower_rotation_angle") { steps.emplace_back(psSkirtBrim); } else if ( - opt_key == "nozzle_diameter" + opt_key == "first_layer_height" + || opt_key == "nozzle_diameter" || opt_key == "resolution" // Spiral Vase forces different kind of slicing than the normal model: // In Spiral Vase mode, holes are closed and only the largest area contour is kept at each layer. diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index ae981653100..ee09e0f5b79 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -535,7 +535,6 @@ bool PrintObject::invalidate_state_by_config_options( steps.emplace_back(posPerimeters); } else if ( opt_key == "layer_height" - || opt_key == "first_layer_height" || opt_key == "mmu_segmented_region_max_width" || opt_key == "raft_layers" || opt_key == "raft_contact_distance" From 3e283d0acb94354ed57d6141c2af5ccf2168b77d Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 25 Aug 2021 12:39:46 +0200 Subject: [PATCH 24/25] Fixed update of backend after the changes introduced with b3010a817bdc8e63b2ad2f9d281be3ba89216ba7 (Do not allow objects to be placed fully below bed) and pop object on the bed when only one part is left --- src/libslic3r/Model.cpp | 53 +++++++++++++++++++++++++++++-- src/libslic3r/Model.hpp | 2 ++ src/slic3r/GUI/GUI_ObjectList.cpp | 11 +++---- src/slic3r/GUI/Plater.cpp | 3 +- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 235c357978b..8eb5bb3890f 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -956,9 +956,22 @@ void ModelObject::center_around_origin(bool include_modifiers) void ModelObject::ensure_on_bed(bool allow_negative_z) { - const double min_z = get_min_z(); - if (!allow_negative_z || min_z > SINKING_Z_THRESHOLD) - translate_instances({ 0.0, 0.0, -min_z }); + double z_offset = 0.0; + + if (allow_negative_z) { + if (volumes.size() == 1) + z_offset = -get_min_z(); + else { + const double max_z = get_max_z(); + if (max_z < SINKING_MIN_Z_THRESHOLD) + z_offset = SINKING_MIN_Z_THRESHOLD - max_z; + } + } + else + z_offset = -get_min_z(); + + if (z_offset != 0.0) + translate_instances(z_offset * Vec3d::UnitZ()); } void ModelObject::translate_instances(const Vec3d& vector) @@ -1429,6 +1442,19 @@ double ModelObject::get_min_z() const } } +double ModelObject::get_max_z() const +{ + if (instances.empty()) + return 0.0; + else { + double max_z = -DBL_MAX; + for (size_t i = 0; i < instances.size(); ++i) { + max_z = std::max(max_z, get_instance_max_z(i)); + } + return max_z; + } +} + double ModelObject::get_instance_min_z(size_t instance_idx) const { double min_z = DBL_MAX; @@ -1450,6 +1476,27 @@ double ModelObject::get_instance_min_z(size_t instance_idx) const return min_z + inst->get_offset(Z); } +double ModelObject::get_instance_max_z(size_t instance_idx) const +{ + double max_z = -DBL_MAX; + + const ModelInstance* inst = instances[instance_idx]; + const Transform3d& mi = inst->get_matrix(true); + + for (const ModelVolume* v : volumes) { + if (!v->is_model_part()) + continue; + + const Transform3d mv = mi * v->get_matrix(); + const TriangleMesh& hull = v->get_convex_hull(); + for (const stl_facet& facet : hull.stl.facet_start) + for (int i = 0; i < 3; ++i) + max_z = std::max(max_z, (mv * facet.vertex[i].cast()).z()); + } + + return max_z + inst->get_offset(Z); +} + unsigned int ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_volume) { unsigned int num_printable = 0; diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 1dd16ee9174..25f19e79282 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -358,7 +358,9 @@ public: void bake_xy_rotation_into_meshes(size_t instance_idx); double get_min_z() const; + double get_max_z() const; double get_instance_min_z(size_t instance_idx) const; + double get_instance_max_z(size_t instance_idx) const; // Called by Print::validate() from the UI thread. unsigned int check_instances_print_volume_state(const BoundingBoxf3& print_volume); diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 1e290beae83..23ce819dd47 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1920,16 +1920,15 @@ bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, con if (vol->is_model_part()) ++solid_cnt; if (volume->is_model_part() && solid_cnt == 1) { - Slic3r::GUI::show_error(nullptr, _(L("From Object List You can't delete the last solid part from object."))); + Slic3r::GUI::show_error(nullptr, _L("From Object List You can't delete the last solid part from object.")); return false; } - take_snapshot(_(L("Delete Subobject"))); + take_snapshot(_L("Delete Subobject")); object->delete_volume(idx); - if (object->volumes.size() == 1) - { + if (object->volumes.size() == 1) { const auto last_volume = object->volumes[0]; if (!last_volume->config.empty()) { object->config.apply(last_volume->config); @@ -1948,11 +1947,11 @@ bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, con } else if (type == itInstance) { if (object->instances.size() == 1) { - Slic3r::GUI::show_error(nullptr, _(L("Last instance of an object cannot be deleted."))); + Slic3r::GUI::show_error(nullptr, _L("Last instance of an object cannot be deleted.")); return false; } - take_snapshot(_(L("Delete Instance"))); + take_snapshot(_L("Delete Instance")); object->delete_instance(idx); } else diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 60215484b8c..72b2c5909d6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6200,8 +6200,7 @@ void Plater::changed_object(int obj_idx) if (obj_idx < 0) return; // recenter and re - align to Z = 0 - auto model_object = p->model.objects[obj_idx]; - model_object->ensure_on_bed(this->p->printer_technology != ptSLA); + p->model.objects[obj_idx]->ensure_on_bed(p->printer_technology != ptSLA); if (this->p->printer_technology == ptSLA) { // Update the SLAPrint from the current Model, so that the reload_scene() // pulls the correct data, update the 3D scene. From d0b3e6d1ed68f31001a3faa3e655cda36147eb6e Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 25 Aug 2021 13:01:08 +0200 Subject: [PATCH 25/25] Fix UI glitches when "fill bed" fails to add any additional instances --- src/slic3r/GUI/Jobs/FillBedJob.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/Jobs/FillBedJob.cpp b/src/slic3r/GUI/Jobs/FillBedJob.cpp index 1948c8fbbfc..870f31f2fcc 100644 --- a/src/slic3r/GUI/Jobs/FillBedJob.cpp +++ b/src/slic3r/GUI/Jobs/FillBedJob.cpp @@ -147,26 +147,28 @@ void FillBedJob::finalize() size_t inst_cnt = model_object->instances.size(); - for (ArrangePolygon &ap : m_selected) { - if (ap.bed_idx != arrangement::UNARRANGED && (ap.priority != 0 || ap.bed_idx == 0)) - ap.apply(); - } + int added_cnt = std::accumulate(m_selected.begin(), m_selected.end(), 0, [](int s, auto &ap) { + return s + int(ap.priority == 0 && ap.bed_idx == 0); + }); - model_object->ensure_on_bed(); + if (added_cnt > 0) { + for (ArrangePolygon &ap : m_selected) { + if (ap.bed_idx != arrangement::UNARRANGED && (ap.priority != 0 || ap.bed_idx == 0)) + ap.apply(); + } - m_plater->update(); + model_object->ensure_on_bed(); - int added_cnt = std::accumulate(m_selected.begin(), m_selected.end(), 0, - [](int s, auto &ap) { - return s + int(ap.priority == 0 && ap.bed_idx == 0); - }); + m_plater->update(); - // FIXME: somebody explain why this is needed for increase_object_instances - if (inst_cnt == 1) added_cnt++; + // FIXME: somebody explain why this is needed for increase_object_instances + if (inst_cnt == 1) added_cnt++; - if (added_cnt > 0) m_plater->sidebar() .obj_list()->increase_object_instances(m_object_idx, size_t(added_cnt)); + } + + Job::finalize(); } }} // namespace Slic3r::GUI