mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-10 23:35:13 -06:00
ENH: step mesh operation adjustment
1.Put commctrl.h into pch precompilation(OCCT conflicts) 2.Replace input wxWidgets to support loss focus verification(STUDIO-8101) 3.Optimize slider interaction and trigger mesh when push up slider(STUDIO-8099) 4.Optimize step loading method, separate import of step and mesh 5.Fix dialog cancel button logic; 6.mesh tasks into sub-threads to prevent blocking the UI; JIRA: STUDIO-8101 STUDIO-8099 Change-Id: I50bbb43953a5128f358c6880032d20693531333b (cherry picked from commit ed7ab6b505a2becf8f38edb3c43b96e51eac3317)
This commit is contained in:
parent
e1477e642c
commit
f91b520bb8
11 changed files with 326 additions and 94 deletions
|
@ -1,11 +1,15 @@
|
|||
#include "StepMeshDialog.hpp"
|
||||
#include "BBLStatusBar.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "Widgets/Button.hpp"
|
||||
#include "MainFrame.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <wx/event.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/slider.h>
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "MainFrame.hpp"
|
||||
#include "Widgets/Button.hpp"
|
||||
#include "Widgets/TextInput.hpp"
|
||||
#include <chrono>
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
|
@ -14,7 +18,7 @@ static int _scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit(
|
|||
static int _ITEM_WIDTH() { return _scale(30); }
|
||||
#define MIN_DIALOG_WIDTH FromDIP(400)
|
||||
#define SLIDER_WIDTH FromDIP(150)
|
||||
#define TEXT_CTRL_WIDTH FromDIP(40)
|
||||
#define TEXT_CTRL_WIDTH FromDIP(50)
|
||||
#define BUTTON_SIZE wxSize(FromDIP(58), FromDIP(24))
|
||||
#define BUTTON_BORDER FromDIP(int(400 - 58 * 2) / 8)
|
||||
#define SLIDER_SCALE(val) ((val) / 0.001)
|
||||
|
@ -23,18 +27,28 @@ static int _ITEM_WIDTH() { return _scale(30); }
|
|||
#define SLIDER_UNSCALE_10(val) ((val) * 0.01)
|
||||
#define LEFT_RIGHT_PADING FromDIP(20)
|
||||
|
||||
wxDEFINE_EVENT(wxEVT_THREAD_DONE, wxCommandEvent);
|
||||
|
||||
void StepMeshDialog::on_dpi_changed(const wxRect& suggested_rect) {
|
||||
};
|
||||
|
||||
bool StepMeshDialog:: validate_number_range(const wxString& value, double min, double max) {
|
||||
double num;
|
||||
if (!value.ToDouble(&num)) {
|
||||
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, fs::path file)
|
||||
StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file)
|
||||
: DPIDialog(parent ? parent : static_cast<wxWindow *>(wxGetApp().mainframe),
|
||||
wxID_ANY,
|
||||
_(L("Step file import parameters")),
|
||||
|
@ -42,6 +56,8 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_file(file)
|
||||
{
|
||||
Bind(wxEVT_THREAD_DONE, &StepMeshDialog::on_task_done, this);
|
||||
|
||||
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico")
|
||||
% Slic3r::resources_dir()).str();
|
||||
SetIcon(wxIcon(Slic3r::encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
|
||||
|
@ -64,34 +80,28 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
wxSize(SLIDER_WIDTH, -1),
|
||||
wxSL_HORIZONTAL);
|
||||
linear_sizer->Add(linear_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
|
||||
wxTextValidator valid_number(wxFILTER_NUMERIC);
|
||||
wxTextCtrl* linear_textctrl = new wxTextCtrl(this, wxID_ANY,
|
||||
m_linear_last,
|
||||
wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1),
|
||||
0, valid_number);
|
||||
linear_sizer->Add(linear_textctrl, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
|
||||
// textctrl loss focus
|
||||
linear_textctrl->Bind(wxEVT_KILL_FOCUS, ([this, linear_textctrl](wxFocusEvent& e) {
|
||||
wxString value = linear_textctrl->GetValue();
|
||||
if(!validate_number_range(value, 0.001, 0.1)) {
|
||||
linear_textctrl->SetValue(m_linear_last);
|
||||
|
||||
auto linear_input = new ::TextInput(this, m_linear_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1));
|
||||
linear_input->GetTextCtrl()->SetFont(Label::Body_12);
|
||||
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 < angle deflection < 0.1)"), wxEmptyString, wxICON_WARNING | wxOK);
|
||||
msg_dlg.ShowModal();
|
||||
linear_input->GetTextCtrl()->SetValue(m_linear_last);
|
||||
}
|
||||
m_linear_last = value;
|
||||
update_mesh_number_text();
|
||||
e.Skip();
|
||||
}));
|
||||
// slider bind textctrl
|
||||
linear_slider->Bind(wxEVT_SLIDER, ([this, linear_slider, linear_textctrl](wxCommandEvent& e) {
|
||||
double slider_value = SLIDER_UNSCALE(linear_slider->GetValue());
|
||||
linear_textctrl->SetValue(wxString::Format("%.3f", slider_value));
|
||||
m_linear_last = wxString::Format("%.3f", slider_value);
|
||||
update_mesh_number_text();
|
||||
}));
|
||||
// textctrl bind slider
|
||||
linear_textctrl->Bind(wxEVT_TEXT, ([this, linear_textctrl, linear_slider](wxCommandEvent& e) {
|
||||
linear_input->Bind(wxEVT_TEXT, ([this, linear_slider, linear_input](wxCommandEvent& e) {
|
||||
double slider_value_long;
|
||||
int slider_value;
|
||||
wxString value = linear_textctrl->GetValue();
|
||||
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()) {
|
||||
|
@ -99,6 +109,15 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
}
|
||||
}
|
||||
}));
|
||||
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, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
|
||||
|
||||
|
@ -114,33 +133,28 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
wxSize(SLIDER_WIDTH, -1),
|
||||
wxSL_HORIZONTAL);
|
||||
angle_sizer->Add(angle_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
|
||||
wxTextCtrl* angle_textctrl = new wxTextCtrl(this, wxID_ANY,
|
||||
m_angle_last,
|
||||
wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1),
|
||||
0, valid_number);
|
||||
angle_sizer->Add(angle_textctrl, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5));
|
||||
// textctrl loss focus
|
||||
angle_textctrl->Bind(wxEVT_KILL_FOCUS, ([this, angle_textctrl](wxFocusEvent& e) {
|
||||
wxString value = angle_textctrl->GetValue();
|
||||
if (!validate_number_range(value, 0.01, 1)) {
|
||||
angle_textctrl->SetValue(m_angle_last);
|
||||
|
||||
auto angle_input = new::TextInput(this, m_angle_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1));
|
||||
angle_input->GetTextCtrl()->SetFont(Label::Body_12);
|
||||
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);
|
||||
}
|
||||
m_angle_last = value;
|
||||
update_mesh_number_text();
|
||||
e.Skip();
|
||||
}));
|
||||
// slider bind textctrl
|
||||
angle_slider->Bind(wxEVT_SLIDER, ([this, angle_slider, angle_textctrl](wxCommandEvent& e) {
|
||||
double slider_value = SLIDER_UNSCALE_10(angle_slider->GetValue());
|
||||
angle_textctrl->SetValue(wxString::Format("%.2f", slider_value));
|
||||
m_angle_last = wxString::Format("%.2f", slider_value);
|
||||
update_mesh_number_text();
|
||||
}));
|
||||
// textctrl bind slider
|
||||
linear_textctrl->Bind(wxEVT_TEXT, ([this, angle_slider, angle_textctrl](wxCommandEvent& e) {
|
||||
angle_input->Bind(wxEVT_TEXT, ([this, angle_slider, angle_input](wxCommandEvent& e) {
|
||||
double slider_value_long;
|
||||
int slider_value;
|
||||
wxString value = angle_textctrl->GetValue();
|
||||
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()) {
|
||||
|
@ -149,11 +163,25 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
}
|
||||
}));
|
||||
|
||||
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, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
|
||||
|
||||
|
||||
mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("Number of generated surfaces: 0"));
|
||||
bSizer->Add(mesh_face_number_text, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
|
||||
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_text = new wxStaticText(this, wxID_ANY, _L("0"));
|
||||
mesh_face_number_text->SetMinSize(wxSize(FromDIP(150), -1));
|
||||
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, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
|
||||
|
||||
wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL);
|
||||
bSizer_button->SetMinSize(wxSize(FromDIP(100), -1));
|
||||
|
@ -170,7 +198,14 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
m_button_ok->SetCornerRadius(FromDIP(12));
|
||||
bSizer_button->Add(m_button_ok, 0, wxALIGN_RIGHT, BUTTON_BORDER);
|
||||
|
||||
m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { EndModal(wxID_OK); });
|
||||
m_button_ok->Bind(wxEVT_LEFT_DOWN, [this, angle_input, linear_input](wxMouseEvent& 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)) {
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
SetFocusIgnoringChildren();
|
||||
});
|
||||
|
||||
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
|
||||
|
@ -184,7 +219,10 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
m_button_cancel->SetCornerRadius(FromDIP(12));
|
||||
bSizer_button->Add(m_button_cancel, 0, wxALIGN_RIGHT | wxLEFT, BUTTON_BORDER);
|
||||
|
||||
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { EndModal(wxID_CANCEL); });
|
||||
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
|
||||
stop_task();
|
||||
EndModal(wxID_CANCEL);
|
||||
});
|
||||
|
||||
bSizer->Add(bSizer_button, 0, wxALIGN_RIGHT | wxRIGHT| wxBOTTOM, LEFT_RIGHT_PADING);
|
||||
|
||||
|
@ -193,24 +231,57 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file)
|
|||
this->Layout();
|
||||
bSizer->Fit(this);
|
||||
|
||||
this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { });
|
||||
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);
|
||||
}
|
||||
|
||||
long StepMeshDialog::get_mesh_number()
|
||||
void StepMeshDialog::on_task_done(wxCommandEvent& event)
|
||||
{
|
||||
Model model;
|
||||
long number = 0;
|
||||
const std::string file_path = m_file.string();
|
||||
bool is_cb_cancel = false;
|
||||
bool result = load_step(file_path.c_str(), &model, is_cb_cancel, get_linear_defletion(), get_angle_defletion(), nullptr, nullptr, number);
|
||||
return number;
|
||||
wxString text = event.GetString();
|
||||
mesh_face_number_text->SetLabel(text);
|
||||
if (task.valid()) {
|
||||
task.get();
|
||||
}
|
||||
}
|
||||
|
||||
void StepMeshDialog::stop_task()
|
||||
{
|
||||
if (task.valid()) {
|
||||
m_file.m_stop_mesh.store(true);
|
||||
unsigned int test = task.get();
|
||||
m_file.m_stop_mesh.store(false);
|
||||
std::cout << test << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void StepMeshDialog::update_mesh_number_text()
|
||||
{
|
||||
long number = get_mesh_number();
|
||||
wxString newText = wxString::Format("Number of generated surfaces: %d", number);
|
||||
if (m_last_linear == get_linear_defletion() && m_last_angle == get_angle_defletion())
|
||||
return;
|
||||
wxString newText = wxString::Format(_L("Calculating, please wait..."));
|
||||
mesh_face_number_text->SetLabel(newText);
|
||||
|
||||
stop_task();
|
||||
task = std::async(std::launch::async, [&] {
|
||||
unsigned int number = m_file.get_triangle_num(get_linear_defletion(), get_angle_defletion());
|
||||
if (number != 0) {
|
||||
wxString number_text = wxString::Format("%d", number);
|
||||
wxCommandEvent event(wxEVT_THREAD_DONE);
|
||||
event.SetString(number_text);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
return number;
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue