Files
OrcaSlicer/src/slic3r/GUI/StepMeshDialog.cpp
T
Damir Galeevandyw4z fa5f7e3db4 Keep original body names when importing STEP, AMF and 3MF geometry (#17050)
* Keep original body names when importing STEP, AMF and 3MF geometry

STEP, AMF and 3MF bodies keep the names stored in the file. The three formats share one geometry import path with matching dialogs, per-format Preferences and cleanup of unsupported characters. AMF body groups load as one object, nested groups are flattened, and a CAD 3MF is imported as geometry.

* Use the app's widgets in the geometry import dialogs

Check boxes, radio buttons and the name replacement field in the STEP,
AMF/3MF and name cleanup dialogs now use the app's own controls instead
of the native ones; the name cleanup preview uses the dialogs' label font.

* Address review: AMF layout, Open Project cancel, part visibility

- AMF: the import dialog offers "Separate objects (as before)" first and
  uses it by default, so files from PrusaSlicer and Slic3r, which keep a
  whole plate in one constellation, load as separate objects again. The
  assembly modes are opt-in.
- File > Open Project with a CAD 3MF replaces the project only after the
  import dialogs were answered and the file was read with geometry to load.
  A Cancel or an empty file keeps the current project, its unsaved state,
  notifications and preview state; close_with_confirm() can hand back its
  closing steps for this.
- The object list no longer changes the model while it checks whether a
  single-object import hides its parts: ModelObject::hides_imported_parts()
  is used by the list, Split to parts and its menu check, and the painting
  gizmos' list update shows or hides the parts when painting changes.
  Removing the part rows keeps the object a container for its instances.
- Progress: staged reading takes the first part of the bar and never goes
  back within a file; the load loop takes the rest.
- A constellation id equal to an object id is logged as a warning.
- set_import_volume_order() is defined next to sort_objects().

* Address review: part rename on drag, Multi-part check for unplaced AMF

- Dragging a part of an imported object cancels a name editor that is
  still open before the part rows are rebuilt. On GTK the editor opened by
  pressing the selected row outlived the deleted row and wrote its name
  into another part.
- The Multi-part check reads zero for objects the file does not place, as
  min_z() did in Release builds, instead of their mesh height: the meshes
  are already centered by then, so different heights asked the question
  where main does not.
- Non-printable AMF groups skip the Multi-part question only in the
  assembly modes; Separate objects asks as before.
- The first AMF load mode is "Load as separate objects".

---------

Co-authored-by: yw4z <ywsyildiz@gmail.com>
2026-11-03 14:14:17 +08:00

448 lines
21 KiB
C++

#include "StepMeshDialog.hpp"
#include "libslic3r/Format/STEP.hpp"
#include "slic3r/GUI/GeometryImportDialog.hpp"
#include "slic3r/GUI/GUI_Utils.hpp"
#include "slic3r/GUI/Widgets/StateColor.hpp"
#include "slic3r/GUI/Widgets/Label.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
#include "libslic3r/LocalesUtils.hpp"
#include "libslic3r/Thread.hpp"
#include <thread>
#include <wx/dialog.h>
#include <wx/colour.h>
#include <wx/event.h>
#include <wx/gdicmn.h>
#include <wx/sizer.h>
#include <wx/slider.h>
#include <wx/tglbtn.h>
#include <wx/dcmemory.h>
#include "GUI_App.hpp"
#include "I18N.hpp"
#include "MainFrame.hpp"
#include "Widgets/Button.hpp"
#include "Widgets/TextInput.hpp"
#include "Widgets/DialogButtons.hpp"
#include "Widgets/RadioGroup.hpp"
#include "Widgets/RoundedRectangle.hpp"
#include <chrono>
#include <wx/string.h>
#include <wx/textctrl.h>
#include <wx/utils.h>
#include <wx/valtext.h>
using namespace Slic3r;
using namespace Slic3r::GUI;
static int _scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit() / 10; }
static int _ITEM_WIDTH() { return _scale(30); }
#define MIN_DIALOG_WIDTH FromDIP(400)
#define SLIDER_WIDTH FromDIP(220)
#define SLIDER_HEIGHT FromDIP(25)
#define TEXT_CTRL_WIDTH FromDIP(100)
#define BUTTON_SIZE wxSize(FromDIP(58), FromDIP(24))
#define BUTTON_BORDER FromDIP(int(400 - 58 * 2) / 8)
#define SLIDER_SCALE(val) ((val) / 0.001)
#define SLIDER_UNSCALE(val) ((val) * 0.001)
#define SLIDER_SCALE_10(val) ((val) / 0.01)
#define SLIDER_UNSCALE_10(val) ((val) * 0.01)
#define LEFT_RIGHT_PADING FromDIP(20)
#define FONT_COLOR wxColour("#363636") // label color
wxDEFINE_EVENT(wxEVT_THREAD_DONE, wxCommandEvent);
class CenteredStaticText : public wxStaticText
{
public:
CenteredStaticText(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& position, const wxSize& size = wxDefaultSize, long style = 0)
: wxStaticText(parent, id, label, position, size, style) {
CenterOnPosition(position);
}
void CenterOnPosition(const wxPoint& position) {
int textWidth, textHeight;
GetTextExtent(GetLabel(), &textWidth, &textHeight);
int x = position.x - textWidth / 2;
int y = position.y - textHeight / 2;
SetPosition(wxPoint(x, y));
}
};
void StepMeshDialog::on_dpi_changed(const wxRect& suggested_rect) {
};
bool StepMeshDialog:: validate_number_range(const wxString& value, double min, double max) {
double num = 0.0;
if (value.IsEmpty()) {
return false;
}
try {
if (!value.ToDouble(&num)) {
return false;
}
} catch (...) {
return false;
}
return (num >= min && num <= max);
}
StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double linear_init, double angle_init,
Slic3r::GUI::GeometryImportOptions* import_options)
: DPIDialog(parent ? parent : static_cast<wxWindow *>(wxGetApp().mainframe),
wxID_ANY,
_(L("STEP file import parameters")),
wxDefaultPosition,
wxDefaultSize,
wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_import_options(import_options), m_file(file)
{
m_linear_last = wxString::Format("%.3f", linear_init);
m_angle_last = wxString::Format("%.2f", angle_init);
Bind(wxEVT_THREAD_DONE, &StepMeshDialog::on_task_done, this);
SetBackgroundColour(*wxWHITE);
wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL);
//bSizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1));
//auto image_bitmap = create_scaled_bitmap("step_mesh_info", this, FromDIP(120));
// wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, image_bitmap.GetSize(), wxTAB_TRAVERSAL);
// overlay_panel->SetBackgroundStyle(wxBG_STYLE_PAINT);
// wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, overlay_panel->GetSize(), 0);
// CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Smooth"),
// wxPoint(overlay_panel->GetSize().GetWidth() / 6,
// overlay_panel->GetSize().GetHeight() / 2));
// CenteredStaticText* text_2 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Rough"),
// wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6,
// overlay_panel->GetSize().GetHeight() / 2));
// CenteredStaticText* text_3 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Linear"),
// wxPoint(overlay_panel->GetSize().GetWidth() / 2,
// overlay_panel->GetSize().GetHeight() * 1.3 / 3));
// CenteredStaticText* text_4 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Angle"),
// wxPoint(overlay_panel->GetSize().GetWidth() / 2,
// overlay_panel->GetSize().GetHeight() * 2 / 3));
// CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("More faces"),
// wxPoint(overlay_panel->GetSize().GetWidth() / 6,
// overlay_panel->GetSize().GetHeight() * 2.8 / 3));
// CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Fewer faces"),
// wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6,
// overlay_panel->GetSize().GetHeight() * 2.8 / 3));
// bSizer->Add(overlay_panel, 0, wxALIGN_CENTER | wxALL, 10);
auto tip_frame = new RoundedRectangle(this, StateColor::darkModeColorFor(wxColour("#F1F1F1")), wxDefaultPosition, wxSize(-1,-1), 6, 0);
wxBoxSizer* tips_sizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticText* info = new wxStaticText(tip_frame, wxID_ANY, _L("Smaller linear and angular deflections result in higher-quality transformations but increase the processing time."));
info->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#363636")));
info->SetBackgroundColour(StateColor::darkModeColorFor(wxColour("#F1F1F1")));
info->SetFont(::Label::Body_14);
info->Wrap(FromDIP(450));
tips_sizer->Add(info, 0, wxEXPAND |wxALL , FromDIP(10));
tip_frame->SetSizer(tips_sizer);
tip_frame->Layout();
bSizer->Add(tip_frame, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
wxBoxSizer* linear_sizer = new wxBoxSizer(wxHORIZONTAL);
//linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1));
wxStaticText* linear_title = new wxStaticText(this,
wxID_ANY, _L("Linear Deflection") + ": ");
linear_title->SetFont(::Label::Body_14);
linear_title->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR));
linear_sizer->Add(linear_title, 0, wxALIGN_LEFT);
linear_sizer->AddStretchSpacer(1);
wxSlider* linear_slider = new wxSlider(this, wxID_ANY,
SLIDER_SCALE(get_linear_deflection()),
1, 100, wxDefaultPosition,
wxSize(SLIDER_WIDTH, SLIDER_HEIGHT),
wxSL_HORIZONTAL);
linear_sizer->Add(linear_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
auto linear_input = new ::TextInput(this, m_linear_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), wxTE_CENTER);
linear_input->GetTextCtrl()->SetFont(Label::Body_14);
linear_input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
linear_sizer->Add(linear_input, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
linear_input->Bind(wxEVT_KILL_FOCUS, ([this, linear_input](wxFocusEvent& e) {
wxString value = linear_input->GetTextCtrl()->GetValue();
if (validate_number_range(value, 0.001, 0.1)) {
m_linear_last = value;
update_mesh_number_text();
} else {
MessageDialog msg_dlg(nullptr, _L("Please input a valid value (0.001 < linear deflection < 0.1)"), wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
linear_input->GetTextCtrl()->SetValue(m_linear_last);
}
e.Skip();
}));
// textctrl bind slider
linear_input->Bind(wxEVT_TEXT, ([linear_slider, linear_input](wxCommandEvent& e) {
double slider_value_long;
int slider_value;
wxString value = linear_input->GetTextCtrl()->GetValue();
if (value.ToDouble(&slider_value_long)) {
slider_value = SLIDER_SCALE(slider_value_long);
if (slider_value >= linear_slider->GetMin() && slider_value <= linear_slider->GetMax()) {
linear_slider->SetValue(slider_value);
}
}
}));
linear_slider->Bind(wxEVT_SLIDER, ([this, linear_slider, linear_input](wxCommandEvent& e) {
double slider_value = SLIDER_UNSCALE(linear_slider->GetValue());
linear_input->GetTextCtrl()->SetValue(wxString::Format("%.3f", slider_value));
m_linear_last = wxString::Format("%.3f", slider_value);
}));
linear_slider->Bind(wxEVT_LEFT_UP, ([this](wxMouseEvent& e) {
update_mesh_number_text();
e.Skip();
}));
bSizer->Add(linear_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
bSizer->AddSpacer(FromDIP(5));
wxBoxSizer* angle_sizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticText* angle_title = new wxStaticText(this,
wxID_ANY, _L("Angle Deflection") + ": ");
angle_title->SetFont(::Label::Body_14);
angle_title->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR));
angle_sizer->Add(angle_title, 0, wxALIGN_LEFT);
angle_sizer->AddStretchSpacer(1);
wxSlider* angle_slider = new wxSlider(this, wxID_ANY,
SLIDER_SCALE_10(get_angle_deflection()),
1, 100, wxDefaultPosition,
wxSize(SLIDER_WIDTH, SLIDER_HEIGHT),
wxSL_HORIZONTAL);
angle_sizer->Add(angle_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
auto angle_input = new ::TextInput(this, m_angle_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), wxTE_CENTER);
angle_input->GetTextCtrl()->SetFont(Label::Body_14);
angle_input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
angle_sizer->Add(angle_input, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
angle_input->Bind(wxEVT_KILL_FOCUS, ([this, angle_input](wxFocusEvent& e) {
wxString value = angle_input->GetTextCtrl()->GetValue();
if (validate_number_range(value, 0.01, 1)) {
m_angle_last = value;
update_mesh_number_text();
} else {
MessageDialog msg_dlg(nullptr, _L("Please input a valid value (0.01 < angle deflection < 1.0)"), wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
angle_input->GetTextCtrl()->SetValue(m_angle_last);
}
e.Skip();
}));
// textctrl bind slider
angle_input->Bind(wxEVT_TEXT, ([angle_slider, angle_input](wxCommandEvent& e) {
double slider_value_long;
int slider_value;
wxString value = angle_input->GetTextCtrl()->GetValue();
if (value.ToDouble(&slider_value_long)) {
slider_value = SLIDER_SCALE_10(slider_value_long);
if (slider_value >= angle_slider->GetMin() && slider_value <= angle_slider->GetMax()) {
angle_slider->SetValue(slider_value);
}
}
}));
angle_slider->Bind(wxEVT_SLIDER, ([this, angle_slider, angle_input](wxCommandEvent& e) {
double slider_value = SLIDER_UNSCALE_10(angle_slider->GetValue());
angle_input->GetTextCtrl()->SetValue(wxString::Format("%.2f", slider_value));
m_angle_last = wxString::Format("%.2f", slider_value);
}));
angle_slider->Bind(wxEVT_LEFT_UP, ([this](wxMouseEvent& e) {
update_mesh_number_text();
e.Skip();
}));
bSizer->Add(angle_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
// App-styled check boxes, the same as in the AMF and 3MF import dialogs.
m_split_compound_checkbox = add_import_checkbox(this, *bSizer, _L("Split compound and compsolid into multiple objects"),
wxGetApp().app_config->get_bool("is_split_compound"), wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
if (m_import_options != nullptr) {
m_split_compound_checkbox.SetToolTip(_L("Loads each body of a multi-body part separately. Needed to keep the bodies' original names."));
m_split_compound_checkbox.SetValue(m_import_options->split_compound);
m_load_mode = new RadioGroup(this, {_L("Load as an assembly"), _L("Load as a single object (can be split later)")}, wxVERTICAL);
m_load_mode->SetSelection(m_import_options->load_as_assembly ? 0 : 1);
m_load_mode->SetRadioTooltip(1, _L("The original bodies and names are kept inside the object. Use Split to parts to show them as separate parts."));
bSizer->Add(m_load_mode, 0, wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
m_keep_names_checkbox = add_import_checkbox(this, *bSizer, _L("Keep original names"), m_import_options->keep_names,
wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
m_keep_names_checkbox.SetToolTip(_L("Use the body names stored in the file, when there are any. Needs Split compound for parts with several bodies."));
m_sort_names_checkbox = add_import_checkbox(this, *bSizer, _L("Sort parts by name"), m_import_options->sort_names,
wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
m_sort_names_checkbox.SetToolTip(_L("Sort the parts inside each imported assembly in the object list. This does not change the order used for slicing. Available when Keep original names is on."));
// The dialog opens with the remembered values; only the user's clicks move the linked option.
m_keep_names_checkbox.box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) {
// Body names of a multi-body part exist only after splitting it.
if (m_keep_names_checkbox.GetValue())
m_split_compound_checkbox.SetValue(true);
e.Skip();
});
m_split_compound_checkbox.box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) {
if (!m_split_compound_checkbox.GetValue() && m_keep_names_checkbox.GetValue()) {
m_keep_names_checkbox.SetValue(false);
m_sort_names_checkbox.Enable(false);
}
e.Skip();
});
Slic3r::GUI::link_sort_to_keep(m_keep_names_checkbox, m_sort_names_checkbox);
}
wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticText *mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets") + ": ");
mesh_face_number_title->SetFont(::Label::Body_14);
mesh_face_number_title->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR));
mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("Calculating, please wait..."));
mesh_face_number_text->SetFont(::Label::Body_14);
mesh_face_number_text->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR));
mesh_face_number_sizer->Add(mesh_face_number_title, 0, wxALIGN_LEFT);
mesh_face_number_sizer->Add(mesh_face_number_text, 0, wxALIGN_LEFT);
bSizer->Add(mesh_face_number_sizer, 0, wxEXPAND | wxALL, LEFT_RIGHT_PADING);
bSizer->AddSpacer(FromDIP(10));
m_save_default_checkbox = add_import_checkbox(this, *bSizer,
m_import_options ? _L("Remember my choice") : _L("Save these settings as default"), false, wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
m_save_default_checkbox.SetToolTip(_L("If enabled, the values above are stored as the defaults used for future STEP imports (and shown in Preferences)."));
bSizer->AddSpacer(FromDIP(10));
m_checkbox = add_import_checkbox(this, *bSizer,
m_import_options ? _L("Don't ask again") : _L("Don't show again"), false, wxLEFT, LEFT_RIGHT_PADING);
if (m_import_options != nullptr)
m_checkbox.SetToolTip(_L("Save these choices and apply them without asking next time. You can show this dialog again in Preferences."));
wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL);
// ORCA standardized HyperLink
auto wiki_btn = new Button(this, "", "toolbar_wiki", 0, 15);
auto wiki_url = "https://www.orcaslicer.com/wiki/import_export#step";
wiki_btn->SetToolTip(_L("Wiki Guide") + "\n" + wiki_url);
wiki_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Circle);
wiki_btn->SetCanFocus(false);
wiki_btn->Bind(wxEVT_LEFT_DOWN, ([wiki_url](auto& e) {wxLaunchDefaultBrowser(wiki_url);}));
bSizer_button->Add(wiki_btn, 0, wxALIGN_LEFT | wxLEFT | wxALIGN_CENTER_VERTICAL, LEFT_RIGHT_PADING);
bSizer_button->AddStretchSpacer(1);
auto dlg_btns = new DialogButtons(this, {"OK", "Cancel"});
bSizer_button->Add(dlg_btns, 0, wxEXPAND);
dlg_btns->GetOK()->Bind(wxEVT_BUTTON, [this, angle_input, linear_input](wxCommandEvent& e) {
stop_task();
if (validate_number_range(angle_input->GetTextCtrl()->GetValue(), 0.01, 1) &&
validate_number_range(linear_input->GetTextCtrl()->GetValue(), 0.001, 0.1)) {
if (m_import_options != nullptr) {
// The callback uses these values now; AppConfig is updated only after batch success.
m_import_options->keep_names = m_keep_names_checkbox.GetValue();
m_import_options->split_compound = m_split_compound_checkbox.GetValue();
m_import_options->sort_names = m_sort_names_checkbox.GetValue();
m_import_options->load_as_assembly = m_load_mode->GetSelection() == 0;
m_import_options->remember = m_save_default_checkbox.GetValue();
m_import_options->dont_ask = m_checkbox.GetValue();
m_import_options->linear_deflection = get_linear_deflection();
m_import_options->angle_deflection = get_angle_deflection();
m_import_options->chosen = true;
} else {
if (m_checkbox.GetValue()) {
wxGetApp().app_config->set_bool("enable_step_mesh_setting", false);
}
if (m_save_default_checkbox.GetValue()) {
wxGetApp().app_config->set_bool("is_split_compound", m_split_compound_checkbox.GetValue());
wxGetApp().app_config->set("linear_deflection", float_to_string_decimal_point(get_linear_deflection(), 3));
wxGetApp().app_config->set("angle_deflection", float_to_string_decimal_point(get_angle_deflection(), 2));
}
}
EndModal(wxID_OK);
}
SetFocusIgnoringChildren();
});
dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) {
stop_task();
EndModal(wxID_CANCEL);
});
bSizer->Add(bSizer_button, 1, wxEXPAND);
this->SetSizerAndFit(bSizer);
update_mesh_number_text();
this->Layout();
// DPIDialog centres itself before the sizer sets the final size.
CenterOnParent();
this->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
SetFocusIgnoringChildren();
});
mesh_face_number_text->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
SetFocusIgnoringChildren();
});
this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) {
stop_task();
EndModal(wxID_CANCEL);
});
wxGetApp().UpdateDlgDarkUI(this);
}
StepMeshDialog::~StepMeshDialog()
{
stop_task();
}
void StepMeshDialog::on_task_done(wxCommandEvent& event)
{
wxString text = event.GetString();
mesh_face_number_text->SetLabel(text);
if(m_task) {
if (m_task->joinable()) {
m_task->join();
delete m_task;
m_task = nullptr;
}
}
}
void StepMeshDialog::stop_task()
{
if(m_task) {
m_file.m_stop_mesh.store(true);
if (m_task->joinable()) {
m_task->join();
delete m_task;
m_task = nullptr;
}
m_file.m_stop_mesh.store(false);
}
}
void StepMeshDialog::update_mesh_number_text()
{
if ((m_last_linear == get_linear_deflection()) && (m_last_angle == get_angle_deflection()) && (m_mesh_number != 0))
return;
wxString newText = wxString::Format(_L("Calculating, please wait..."));
mesh_face_number_text->SetLabel(newText);
stop_task();
if (!m_task) {
m_task = new boost::thread(Slic3r::create_thread([this]() -> void {
m_mesh_number = m_file.get_triangle_num(get_linear_deflection(), get_angle_deflection());
if (m_mesh_number != 0) {
wxString number_text = wxString::Format("%d", m_mesh_number);
wxCommandEvent event(wxEVT_THREAD_DONE);
event.SetString(number_text);
wxPostEvent(this, event);
m_last_linear = get_linear_deflection();
m_last_angle = get_angle_deflection();
}
}));
}
}