From 0ef90159047cdb0f54c645bf52134ccf459805a8 Mon Sep 17 00:00:00 2001 From: Ian Bassi Date: Mon, 26 Oct 2026 15:01:47 -0300 Subject: [PATCH] Ask for the size of a primitive when adding it (#16848) --- localization/i18n/list.txt | 1 + src/libslic3r/AppConfig.cpp | 3 + src/libslic3r/TriangleMesh.cpp | 8 +- src/libslic3r/TriangleMesh.hpp | 4 +- src/slic3r/CMakeLists.txt | 2 + src/slic3r/GUI/GUI_ObjectList.cpp | 118 ++++++++++-- src/slic3r/GUI/GUI_ObjectList.hpp | 5 +- src/slic3r/GUI/Plater.cpp | 2 +- src/slic3r/GUI/Preferences.cpp | 4 + src/slic3r/GUI/PrimitiveSizeDialog.cpp | 169 ++++++++++++++++++ src/slic3r/GUI/PrimitiveSizeDialog.hpp | 50 ++++++ tests/libslic3r/test_indexed_triangle_set.cpp | 12 ++ 12 files changed, 352 insertions(+), 26 deletions(-) create mode 100644 src/slic3r/GUI/PrimitiveSizeDialog.cpp create mode 100644 src/slic3r/GUI/PrimitiveSizeDialog.hpp diff --git a/localization/i18n/list.txt b/localization/i18n/list.txt index 116f2942fa..8f9dda0673 100644 --- a/localization/i18n/list.txt +++ b/localization/i18n/list.txt @@ -177,6 +177,7 @@ src/slic3r/GUI/Plater.cpp src/slic3r/GUI/Preferences.cpp src/slic3r/GUI/PresetComboBoxes.cpp src/slic3r/GUI/PresetHints.cpp +src/slic3r/GUI/PrimitiveSizeDialog.cpp src/slic3r/GUI/ProgressStatusBar.cpp src/slic3r/GUI/PlateSettingsDialog.cpp src/slic3r/GUI/PrivacyUpdateDialog.cpp diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 13fb716298..4d6cd3391f 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -705,6 +705,9 @@ void AppConfig::set_defaults() if (get("is_split_compound").empty()) { set_bool("is_split_compound", false); } + if (get("enable_primitive_size_dialog").empty()) { + set_bool("enable_primitive_size_dialog", true); + } if(get("installed_networking").empty()) { set_bool("installed_networking", false); diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index a7170bb57b..6495154279 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -1023,16 +1023,16 @@ indexed_triangle_set its_make_frustum(double r, double h, double fa) // Generate the mesh for a torus // r: major radius (distance from center of tube to center of torus) // h: minor radius (radius of the tube) -// fa: angular step in radians (smaller = more segments) -indexed_triangle_set its_make_torus(double r, double h, double fa) +// fa_major, fa_minor: angular steps in radians around the main ring and the tube (smaller = more segments) +indexed_triangle_set its_make_torus(double r, double h, double fa_major, double fa_minor) { indexed_triangle_set mesh; auto& vertices = mesh.vertices; auto& facets = mesh.indices; // Number of segments around the main ring and the tube - size_t n_major = (size_t)ceil(2. * PI / fa); - size_t n_minor = (size_t)ceil(2. * PI / fa); + size_t n_major = (size_t)ceil(2. * PI / fa_major); + size_t n_minor = (size_t)ceil(2. * PI / fa_minor); double major_step = 2. * PI / n_major; double minor_step = 2. * PI / n_minor; diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index 0265062ce2..32f41c5403 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -365,7 +365,7 @@ indexed_triangle_set its_make_prism(float width, float length, float height); indexed_triangle_set its_make_cylinder(double r, double h, double fa=(2*PI/180)); indexed_triangle_set its_make_cone(double r, double h, double fa=(2*PI/180)); indexed_triangle_set its_make_frustum(double r, double h, double fa=(2*PI/180)); -indexed_triangle_set its_make_torus(double r, double h, double fa); +indexed_triangle_set its_make_torus(double r, double h, double fa_major, double fa_minor); indexed_triangle_set its_make_frustum_dowel(double r, double h, int sectorCount); indexed_triangle_set its_make_pyramid(float base, float height); indexed_triangle_set its_make_sphere(double radius, double fa); @@ -381,7 +381,7 @@ inline TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/180)) inline TriangleMesh make_cone(double r, double h, double fa=(2*PI/180)) { return TriangleMesh(its_make_cone(r, h, fa)); } inline TriangleMesh make_pyramid(float base, float height) { return TriangleMesh(its_make_pyramid(base, height)); } inline TriangleMesh make_sphere(double rho, double fa=(2*PI/90)) { return TriangleMesh(its_make_sphere(rho, fa)); } -inline TriangleMesh make_torus(double r, double h, double fa=(PI/60)) { return TriangleMesh(its_make_torus(r, h, fa)); } +inline TriangleMesh make_torus(double r, double h, double fa=(PI/60)) { return TriangleMesh(its_make_torus(r, h, fa, fa)); } bool its_write_stl_ascii(const char *file, const char *label, const std::vector &indices, const std::vector &vertices); inline bool its_write_stl_ascii(const char *file, const char *label, const indexed_triangle_set &its) { return its_write_stl_ascii(file, label, its.indices, its.vertices); } diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index bf63999267..22e49fdc60 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -469,6 +469,8 @@ set(SLIC3R_GUI_SOURCES GUI/PresetComboBoxes.hpp GUI/PresetHints.cpp GUI/PresetHints.hpp + GUI/PrimitiveSizeDialog.cpp + GUI/PrimitiveSizeDialog.hpp GUI/PrinterCloudAuthDialog.cpp GUI/PrinterCloudAuthDialog.hpp GUI/Printer/PrinterFileSystem.cpp diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 5f0328d785..2a9076dcd1 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1,4 +1,5 @@ #include "libslic3r/libslic3r.h" +#include "libslic3r/AppConfig.hpp" #include "libslic3r/PresetBundle.hpp" #include "libslic3r/LifecycleEvents.hpp" #include "GUI_ObjectList.hpp" @@ -26,6 +27,7 @@ #include "Widgets/ProgressDialog.hpp" #include "SingleChoiceDialog.hpp" #include "StepMeshDialog.hpp" +#include "PrimitiveSizeDialog.hpp" #include "slic3r/GUI/Event.hpp" @@ -65,6 +67,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -2502,41 +2507,112 @@ void ObjectList::load_modifier(const wxArrayString& input_files, ModelObject& mo } } -static TriangleMesh create_mesh(const std::string& type_name, const BoundingBoxf3& bb) +// The dimensions the size dialog asks for, filled with the default size of the primitive. +static std::vector primitive_size_fields(const std::string& type_name) { const double side = wxGetApp().plater()->canvas3D()->get_size_proportional_to_max_bed_size(0.1); + if (type_name == "Cube") + return {{_L("X"), side}, {_L("Y"), side}, {_L("Z"), side}}; + if (type_name == "Cylinder" || type_name == "Cone") + return {{_L("Diameter"), side}, {_L("Height"), side}}; + if (type_name == "Sphere") + return {{_L("Diameter"), side}}; + if (type_name == "Disc") + return {{_L("Diameter"), side}, {_L("Height"), 0.2}}; + if (type_name == "Torus") + // TRN Size of a torus (ring): the diameter of its hole and the thickness of the ring. + return {{_L("Inner diameter"), 0.75 * side}, {_L("Tube diameter"), 0.25 * side}}; + return {}; +} + +// Replaces the default values with the size the user saved for the primitive, stored as space separated numbers. +static void apply_saved_primitive_size(std::vector& fields, const std::string& saved) +{ + std::vector tokens; + boost::split(tokens, saved, boost::is_space(), boost::token_compress_on); + if (tokens.size() != fields.size()) + return; + std::vector values; + for (const std::string& token : tokens) { + const double value = string_to_double_decimal_point(token); + if (!std::isfinite(value) || value <= 0.) + return; + values.push_back(value); + } + for (size_t i = 0; i < fields.size(); ++i) + fields[i].value = values[i]; +} + +// interactive starts from the size the user saved and asks for the size unless the user turned the dialog off; +// otherwise the primitive gets its built-in default size. nullopt when the user cancels. +static std::optional> primitive_size(const std::string& type_name, bool interactive) +{ + std::vector fields = primitive_size_fields(type_name); + AppConfig* app_config = wxGetApp().app_config; + if (interactive && !fields.empty()) { + apply_saved_primitive_size(fields, app_config->get("primitive_size", type_name)); + if (app_config->get_bool("enable_primitive_size_dialog")) { + PrimitiveSizeDialog dlg(wxGetApp().mainframe, _L(type_name), fields); + if (dlg.ShowModal() != wxID_OK) + return std::nullopt; + if (dlg.dont_show_again()) + app_config->set_bool("enable_primitive_size_dialog", false); + if (dlg.save_as_default()) { + std::string saved; + for (double value : dlg.get_values()) + saved += (saved.empty() ? "" : " ") + float_to_string_decimal_point(value); + app_config->set_str("primitive_size", type_name, saved); + } + return dlg.get_values(); + } + } + std::vector size; + for (const PrimitiveSizeDialog::Field& field : fields) + size.push_back(field.value); + return size; +} + +// Angle step that keeps the facets of a circle of this radius within 0.002 mm of it, in 16 to 720 segments. +static double primitive_angle_step(double radius) +{ + const double step = 2. * std::acos(1. - std::min(1., 0.002 / radius)); + return std::clamp(step, 2. * PI / 720., 2. * PI / 16.); +} + +// size holds the values of primitive_size_fields(type_name). +static TriangleMesh create_mesh(const std::string& type_name, const std::vector& size, const BoundingBoxf3& bb) +{ TriangleMesh mesh; if (type_name == "Cube") // Sitting on the print bed, left front front corner at (0, 0). - mesh = TriangleMesh(its_make_cube(side, side, side)); - else if (type_name == "Cylinder") + mesh = TriangleMesh(its_make_cube(size[0], size[1], size[2])); + else if (type_name == "Cylinder" || type_name == "Disc") // Centered around 0, sitting on the print bed. - // The cylinder has the same volume as the box above. - mesh = TriangleMesh(its_make_cylinder(0.5 * side, side)); + mesh = TriangleMesh(its_make_cylinder(0.5 * size[0], size[1], primitive_angle_step(0.5 * size[0]))); else if (type_name == "Sphere") // Centered around 0, half the sphere below the print bed, half above. - // The sphere has the same volume as the box above. - mesh = TriangleMesh(its_make_sphere(0.5 * side, PI / 90)); + mesh = TriangleMesh(its_make_sphere(0.5 * size[0], primitive_angle_step(0.5 * size[0]))); else if (type_name == "Slab") // Sitting on the print bed, left front front corner at (0, 0). mesh = TriangleMesh(its_make_cube(bb.size().x() * 1.5, bb.size().y() * 1.5, bb.size().z() * 0.5)); else if (type_name == "Cone") - mesh = TriangleMesh(its_make_cone(0.5 * side, side)); - else if (type_name == "Disc") - mesh = TriangleMesh(its_make_cylinder(0.5 * side, 0.2f)); - else if (type_name == "Torus") - mesh = TriangleMesh(its_make_torus(0.5 * side, 0.125 * side,(PI / 60))); + mesh = TriangleMesh(its_make_cone(0.5 * size[0], size[1], primitive_angle_step(0.5 * size[0]))); + else if (type_name == "Torus") { + const double tube_radius = 0.5 * size[1]; + const double radius = 0.5 * size[0] + tube_radius; + mesh = TriangleMesh(its_make_torus(radius, tube_radius, primitive_angle_step(radius + tube_radius), primitive_angle_step(tube_radius))); + } return mesh; } -void ObjectList::load_generic_subobject(const std::string& type_name, const ModelVolumeType type) +void ObjectList::load_generic_subobject(const std::string& type_name, const ModelVolumeType type, bool interactive) { // BBS: single snapshot Plater::SingleSnapshot single(wxGetApp().plater()); if (type == ModelVolumeType::INVALID) { - load_shape_object(type_name); + load_shape_object(type_name, interactive); return; } @@ -2555,6 +2631,10 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode if (instance_idx == -1) return; + const std::optional> size = primitive_size(type_name, interactive); + if (!size) + return; + take_snapshot(_u8L("Add primitive")); // Selected object @@ -2562,7 +2642,7 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode // Bounding box of the selected instance in world coordinate system including the translation, without modifiers. BoundingBoxf3 instance_bb = model_object.instance_bounding_box(instance_idx); - TriangleMesh mesh = create_mesh(type_name, instance_bb); + TriangleMesh mesh = create_mesh(type_name, *size, instance_bb); // Mesh will be centered when loading. ModelVolume *new_volume = model_object.add_volume(std::move(mesh), type); @@ -2636,7 +2716,7 @@ void ObjectList::switch_to_object_process() } } -void ObjectList::load_shape_object(const std::string &type_name) +void ObjectList::load_shape_object(const std::string &type_name, bool interactive) { const Selection& selection = wxGetApp().plater()->canvas3D()->get_selection(); //assert(selection.get_object_idx() == -1); // Add nothing is something is selected on 3DScene @@ -2647,11 +2727,15 @@ void ObjectList::load_shape_object(const std::string &type_name) if (obj_idx < 0) return; + const std::optional> size = primitive_size(type_name, interactive); + if (!size) + return; + Plater::TakeSnapshot snapshot(wxGetApp().plater(), _u8L("Add Primitive")); // Create mesh BoundingBoxf3 bb; - TriangleMesh mesh = create_mesh(type_name, bb); + TriangleMesh mesh = create_mesh(type_name, *size, bb); // Rotate the largest overhang area toward the part cooling fan so new shapes start in a // cooling friendly orientation. Skip the plain cube: the pressure advance pattern // calibration reuses it as an axis-aligned anchor and scales it by its bounding box, diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 1c86d9cfdb..36446b4af1 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -314,8 +314,9 @@ public: // ! ysFIXME - delete commented code after testing and rename "load_modifier" to something common //void load_part(ModelObject& model_object, std::vector& added_volumes, ModelVolumeType type, bool from_galery = false); void load_modifier(const wxArrayString& input_files, ModelObject& model_object, std::vector& added_volumes, ModelVolumeType type, bool from_galery = false); - void load_generic_subobject(const std::string& type_name, const ModelVolumeType type); - void load_shape_object(const std::string &type_name); + // interactive uses the size the user enters or saved as default; otherwise the shape gets its built-in default size. + void load_generic_subobject(const std::string& type_name, const ModelVolumeType type, bool interactive = true); + void load_shape_object(const std::string &type_name, bool interactive); void load_mesh_object(const TriangleMesh &mesh, const wxString &name, bool center = true); // One object holding one part per mesh; the parts keep their placement relative to each other. void load_mesh_object(const std::vector> &parts, const wxString &name, bool center = true); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index fa1c4944d1..61d3c3a82e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -16991,7 +16991,7 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) auto cur_plate = get_partplate_list().get_plate(0); // add "handle" cube - sidebar().obj_list()->load_generic_subobject("Cube", ModelVolumeType::INVALID); + sidebar().obj_list()->load_generic_subobject("Cube", ModelVolumeType::INVALID, false); auto *cube = model().objects[0]; CalibPressureAdvancePattern pa_pattern( diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index e3137ff131..2f860ad81a 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1884,6 +1884,10 @@ void PreferencesDialog::create_items() auto item_auto_arrange = create_item_checkbox(_L("Auto arrange plate after cloning"), "", "auto_arrange"); g_sizer->Add(item_auto_arrange); + auto item_primitive_dialog = create_item_checkbox(_L("Show options when adding a primitive"), + _L("If enabled, a dialog asks for the dimensions of a primitive shape before it is added."), "enable_primitive_size_dialog"); + g_sizer->Add(item_primitive_dialog); + //// CONTROL > Slicing g_sizer->Add(create_item_title(_L("Slicing")), 1, wxEXPAND); diff --git a/src/slic3r/GUI/PrimitiveSizeDialog.cpp b/src/slic3r/GUI/PrimitiveSizeDialog.cpp new file mode 100644 index 0000000000..fbd19cc81d --- /dev/null +++ b/src/slic3r/GUI/PrimitiveSizeDialog.cpp @@ -0,0 +1,169 @@ +#include "PrimitiveSizeDialog.hpp" + +#include "Field.hpp" +#include "GUI_App.hpp" +#include "GUI_Utils.hpp" +#include "I18N.hpp" +#include "MainFrame.hpp" +#include "MsgDialog.hpp" +#include "Widgets/Button.hpp" +#include "Widgets/CheckBox.hpp" +#include "Widgets/DialogButtons.hpp" +#include "Widgets/Label.hpp" +#include "Widgets/TextInput.hpp" +#include "libslic3r/LocalesUtils.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Slic3r { namespace GUI { + +static constexpr int input_width = 120; + +// The number in the input, with either decimal separator; false when it is not a finite number. +static bool parse_input(const ::TextInput* input, double& value) +{ + const char dec_sep = is_decimal_separator_point() ? '.' : ','; + const char dec_sep_alt = dec_sep == '.' ? ',' : '.'; + wxString str = input->GetTextCtrl()->GetValue(); + str.Replace(dec_sep_alt, dec_sep, false); + return str.ToDouble(&value) && std::isfinite(value); +} + +PrimitiveSizeDialog::PrimitiveSizeDialog(wxWindow* parent, const wxString& title, const std::vector& fields) + : DPIDialog(parent ? parent : static_cast(wxGetApp().mainframe), wxID_ANY, title, wxDefaultPosition, wxDefaultSize, + wxCAPTION | wxCLOSE_BOX) +{ + SetBackgroundColour(*wxWHITE); + SetFont(Label::Body_14); + + auto grid = new wxFlexGridSizer(2, FromDIP(8), FromDIP(20)); + for (size_t i = 0; i < fields.size(); ++i) { + auto input = new ::TextInput(this, double_to_string(fields[i].value, 2), _L("mm"), "", wxDefaultPosition, + FromDIP(wxSize(input_width, -1))); + input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); + input->Bind(wxEVT_TEXT, [this, i](wxCommandEvent& e) { + e.Skip(); + on_input_changed(i); + }); + input->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent&) { + if (read_values()) + EndModal(wxID_OK); + }); + grid->Add(new wxStaticText(this, wxID_ANY, fields[i].label), 0, wxALIGN_CENTER_VERTICAL); + grid->Add(input, 0, wxALIGN_CENTER_VERTICAL); + m_inputs.push_back(input); + m_last_values.push_back(fields[i].value); + } + + auto sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add(grid, 1, wxEXPAND | wxALL, FromDIP(10)); + + if (fields.size() > 1) + m_uniform_scale = add_checkbox(sizer, _L("Uniform scale"), _L("Changing one dimension changes the others in proportion.")); + m_save_default = add_checkbox(sizer, _L("Save these settings as default"), + _L("If enabled, these dimensions are used for this shape from now on, also when this dialog is not shown.")); + m_dont_show = add_checkbox(sizer, _L("Don't show again"), + _L("If enabled, shapes are added at their default size without asking. The dialog can be turned back on in Preferences.")); + + auto dlg_btns = new DialogButtons(this, {"OK", "Cancel"}); + dlg_btns->GetOK()->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { + if (read_values()) + EndModal(wxID_OK); + }); + sizer->Add(dlg_btns, 0, wxEXPAND); + SetSizerAndFit(sizer); + CenterOnParent(); + wxGetApp().UpdateDlgDarkUI(this); + + if (!m_inputs.empty()) { + m_inputs.front()->GetTextCtrl()->SetFocus(); + m_inputs.front()->GetTextCtrl()->SelectAll(); + } +} + +bool PrimitiveSizeDialog::save_as_default() const { return m_save_default->GetValue(); } + +bool PrimitiveSizeDialog::dont_show_again() const { return m_dont_show->GetValue(); } + +::CheckBox* PrimitiveSizeDialog::add_checkbox(wxSizer* sizer, const wxString& label, const wxString& tooltip) +{ + auto checkbox = new ::CheckBox(this); + auto text = new wxStaticText(this, wxID_ANY, label); + checkbox->SetToolTip(tooltip); + text->SetToolTip(tooltip); + auto toggle = [checkbox](wxMouseEvent&) { checkbox->SetValue(!checkbox->GetValue()); }; + text->Bind(wxEVT_LEFT_DOWN, toggle); + text->Bind(wxEVT_LEFT_DCLICK, toggle); + + auto row = new wxBoxSizer(wxHORIZONTAL); + row->Add(checkbox, 0, wxALIGN_CENTER_VERTICAL); + row->Add(text, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(5)); + sizer->Add(row, 0, wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(10)); + return checkbox; +} + +void PrimitiveSizeDialog::on_input_changed(size_t idx) +{ + double value = 0.; + if (!parse_input(m_inputs[idx], value) || value <= 0.) + return; + if (m_uniform_scale && m_uniform_scale->GetValue()) { + const double ratio = value / m_last_values[idx]; + for (size_t i = 0; i < m_inputs.size(); ++i) + if (i != idx) { + m_last_values[i] *= ratio; + m_inputs[i]->GetTextCtrl()->ChangeValue(double_to_string(m_last_values[i], 2)); + } + } + m_last_values[idx] = value; +} + +bool PrimitiveSizeDialog::read_values() +{ + std::vector values; + for (::TextInput* input : m_inputs) { + double value = 0.; + const bool is_number = parse_input(input, value); + if (!is_number || value <= 0.) { + MessageDialog msg_dlg(this, is_number ? _L("The size must be greater than zero") : _L("Invalid numeric input."), + wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + input->GetTextCtrl()->SetFocus(); + input->GetTextCtrl()->SelectAll(); + return false; + } + values.push_back(value); + } + m_values = std::move(values); + return true; +} + +void PrimitiveSizeDialog::on_dpi_changed(const wxRect& suggested_rect) +{ + for (::TextInput* input : m_inputs) { + input->SetMinSize(FromDIP(wxSize(input_width, -1))); + input->Rescale(); + } + if (m_uniform_scale) + m_uniform_scale->Rescale(); + m_save_default->Rescale(); + m_dont_show->Rescale(); + GetSizer()->SetSizeHints(this); + Refresh(); +} + +}} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PrimitiveSizeDialog.hpp b/src/slic3r/GUI/PrimitiveSizeDialog.hpp new file mode 100644 index 0000000000..8d41a80e4a --- /dev/null +++ b/src/slic3r/GUI/PrimitiveSizeDialog.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include "GUI_Utils.hpp" + +#include +#include +#include +#include + +class CheckBox; +class TextInput; +class wxSizer; +class wxWindow; + +namespace Slic3r { namespace GUI { + +// Asks for the dimensions of a primitive shape, in mm, before it is generated. +class PrimitiveSizeDialog : public DPIDialog +{ +public: + struct Field + { + wxString label; + double value; + }; + + PrimitiveSizeDialog(wxWindow* parent, const wxString& title, const std::vector& fields); + + const std::vector& get_values() const { return m_values; } + bool save_as_default() const; + bool dont_show_again() const; + +protected: + void on_dpi_changed(const wxRect& suggested_rect) override; + +private: + ::CheckBox* add_checkbox(wxSizer* sizer, const wxString& label, const wxString& tooltip); + void on_input_changed(size_t idx); + bool read_values(); + + std::vector<::TextInput*> m_inputs; + // The last valid value of each input, which uniform scaling multiplies. + std::vector m_last_values; + ::CheckBox* m_uniform_scale{nullptr}; + ::CheckBox* m_save_default{nullptr}; + ::CheckBox* m_dont_show{nullptr}; + std::vector m_values; +}; + +}} // namespace Slic3r::GUI diff --git a/tests/libslic3r/test_indexed_triangle_set.cpp b/tests/libslic3r/test_indexed_triangle_set.cpp index 41bd09e354..651d4282b8 100644 --- a/tests/libslic3r/test_indexed_triangle_set.cpp +++ b/tests/libslic3r/test_indexed_triangle_set.cpp @@ -542,3 +542,15 @@ TEST_CASE("Smoothing a vertex shared by one large flat group and thousands of sm // Scanning every face once per group, or every group for each face, takes hundreds of times longer. CHECK(ratio < 100.); } + +TEST_CASE("A torus has its own segment counts around the ring and around the tube", "[its]") +{ + const double r = 20.; + const double h = 2.; + const indexed_triangle_set torus = its_make_torus(r, h, 0.05, 0.3); + // ceil(2 pi / 0.05) = 126 segments around the ring, ceil(2 pi / 0.3) = 21 around the tube. + CHECK(torus.vertices.size() == 126 * 21); + CHECK(torus.indices.size() == 2 * 126 * 21); + // The true torus holds 2 pi^2 r h^2; 21 segments around the tube lose about 1.5 % of it. + CHECK_THAT(its_mass_properties(torus).volume, WithinRel(2. * PI * PI * r * h * h, 0.02)); +}