FIX: repair: fix the state not correct issue after repair

Change-Id: Ic4aaeaeeee921294e0a5ab6d82517dc28f8822c8
This commit is contained in:
lane.wei 2022-12-30 23:49:16 +08:00 committed by Lane.Wei
parent 54aae68874
commit f0908f2a63
5 changed files with 29 additions and 19 deletions

View file

@ -2570,6 +2570,7 @@ size_t ModelVolume::split(unsigned int max_extruders)
if (idx == 0) { if (idx == 0) {
this->set_mesh(std::move(mesh)); this->set_mesh(std::move(mesh));
this->calculate_convex_hull(); this->calculate_convex_hull();
this->invalidate_convex_hull_2d();
// Assign a new unique ID, so that a new GLVolume will be generated. // Assign a new unique ID, so that a new GLVolume will be generated.
this->set_new_unique_id(); this->set_new_unique_id();
// reset the source to disable reload from disk // reset the source to disable reload from disk

View file

@ -756,6 +756,10 @@ public:
const std::shared_ptr<const TriangleMesh>& get_convex_hull_shared_ptr() const { return m_convex_hull; } const std::shared_ptr<const TriangleMesh>& get_convex_hull_shared_ptr() const { return m_convex_hull; }
//BBS: add convex_hell_2d related logic //BBS: add convex_hell_2d related logic
const Polygon& get_convex_hull_2d(const Transform3d &trafo_instance) const; const Polygon& get_convex_hull_2d(const Transform3d &trafo_instance) const;
void invalidate_convex_hull_2d()
{
m_convex_hull_2d.clear();
}
// Get count of errors in the mesh // Get count of errors in the mesh
int get_repaired_errors_count() const; int get_repaired_errors_count() const;

View file

@ -4707,10 +4707,13 @@ void ObjectList::fix_through_netfabb()
std::string res; std::string res;
if (!fix_model_by_win10_sdk_gui(*(object(obj_idx)), vol_idx, progress_dlg, msg, res)) if (!fix_model_by_win10_sdk_gui(*(object(obj_idx)), vol_idx, progress_dlg, msg, res))
return false; return false;
wxGetApp().plater()->changed_mesh(obj_idx); //wxGetApp().plater()->changed_mesh(obj_idx);
plater->changed_mesh(obj_idx); plater->changed_mesh(obj_idx);
plater->get_partplate_list().notify_instance_update(obj_idx, 0);
plater->sidebar().obj_list()->update_plate_values_for_items();
if (res.empty()) if (res.empty())
succes_models.push_back(model_name); succes_models.push_back(model_name);
else else

View file

@ -70,7 +70,7 @@ GLGizmoSimplify::GLGizmoSimplify(GLCanvas3D & parent,
{} {}
GLGizmoSimplify::~GLGizmoSimplify() GLGizmoSimplify::~GLGizmoSimplify()
{ {
stop_worker_thread_request(); stop_worker_thread_request();
if (m_worker.joinable()) if (m_worker.joinable())
m_worker.join(); m_worker.join();
@ -173,10 +173,10 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
// Whether to trigger calculation after rendering is done. // Whether to trigger calculation after rendering is done.
bool start_process = false; bool start_process = false;
// Check selection of new volume // Check selection of new volume
// Do not reselect object when processing // Do not reselect object when processing
if (act_volume != m_volume) { if (act_volume != m_volume) {
bool change_window_position = (m_volume == nullptr); bool change_window_position = (m_volume == nullptr);
// select different model // select different model
@ -193,13 +193,13 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
// Start processing. If we switched from another object, process will // Start processing. If we switched from another object, process will
// stop the background thread and it will restart itself later. // stop the background thread and it will restart itself later.
start_process = true; start_process = true;
// set window position // set window position
if (m_move_to_center && change_window_position) { if (m_move_to_center && change_window_position) {
m_move_to_center = false; m_move_to_center = false;
auto parent_size = m_parent.get_canvas_size(); auto parent_size = m_parent.get_canvas_size();
ImVec2 pos(parent_size.get_width() / 2 - m_gui_cfg->window_offset_x, ImVec2 pos(parent_size.get_width() / 2 - m_gui_cfg->window_offset_x,
parent_size.get_height() / 2 - m_gui_cfg->window_offset_y); parent_size.get_height() / 2 - m_gui_cfg->window_offset_y);
ImGui::SetNextWindowPos(pos, ImGuiCond_Always); ImGui::SetNextWindowPos(pos, ImGuiCond_Always);
}else if (change_window_position) { }else if (change_window_position) {
ImVec2 pos = ImGui::GetMousePos(); ImVec2 pos = ImGui::GetMousePos();
@ -212,7 +212,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
// maximal bottom right value // maximal bottom right value
auto parent_size = m_parent.get_canvas_size(); auto parent_size = m_parent.get_canvas_size();
ImVec2 br( ImVec2 br(
parent_size.get_width() - (2 * m_gui_cfg->window_offset_x + m_gui_cfg->window_padding), parent_size.get_width() - (2 * m_gui_cfg->window_offset_x + m_gui_cfg->window_padding),
parent_size.get_height() - (2 * m_gui_cfg->window_offset_y + m_gui_cfg->window_padding)); parent_size.get_height() - (2 * m_gui_cfg->window_offset_y + m_gui_cfg->window_padding));
if (pos.x > br.x) pos.x = br.x; if (pos.x > br.x) pos.x = br.x;
if (pos.y > br.y) pos.y = br.y; if (pos.y > br.y) pos.y = br.y;
@ -466,7 +466,7 @@ void GLGizmoSimplify::process()
m_worker.join(); m_worker.join();
} }
// Copy configuration that will be used. // Copy configuration that will be used.
m_state.config = m_configuration; m_state.config = m_configuration;
m_state.mv = m_volume; m_state.mv = m_volume;
m_state.status = State::running; m_state.status = State::running;
@ -542,11 +542,12 @@ void GLGizmoSimplify::apply_simplify() {
mv->set_mesh(std::move(*m_state.result)); mv->set_mesh(std::move(*m_state.result));
m_state.result.reset(); m_state.result.reset();
mv->calculate_convex_hull(); mv->calculate_convex_hull();
mv->invalidate_convex_hull_2d();
mv->set_new_unique_id(); mv->set_new_unique_id();
mv->get_object()->invalidate_bounding_box(); mv->get_object()->invalidate_bounding_box();
mv->get_object()->ensure_on_bed(); mv->get_object()->ensure_on_bed();
// fix hollowing, sla support points, modifiers, ... // fix hollowing, sla support points, modifiers, ...
plater->changed_mesh(object_idx); plater->changed_mesh(object_idx);
// Fix warning icon in object list // Fix warning icon in object list
wxGetApp().obj_list()->update_item_error_icon(object_idx, -1); wxGetApp().obj_list()->update_item_error_icon(object_idx, -1);
@ -559,7 +560,7 @@ bool GLGizmoSimplify::on_is_activable() const
m_parent.get_selection().is_single_volume(); m_parent.get_selection().is_single_volume();
} }
void GLGizmoSimplify::on_set_state() void GLGizmoSimplify::on_set_state()
{ {
// Closing gizmo. e.g. selecting another one // Closing gizmo. e.g. selecting another one
if (GLGizmoBase::m_state == GLGizmoBase::Off) { if (GLGizmoBase::m_state == GLGizmoBase::Off) {
@ -574,12 +575,12 @@ void GLGizmoSimplify::on_set_state()
} }
} }
void GLGizmoSimplify::create_gui_cfg() { void GLGizmoSimplify::create_gui_cfg() {
if (m_gui_cfg.has_value()) return; if (m_gui_cfg.has_value()) return;
int space_size = m_imgui->calc_text_size(":MM").x; int space_size = m_imgui->calc_text_size(":MM").x;
GuiCfg cfg; GuiCfg cfg;
cfg.top_left_width = std::max(m_imgui->calc_text_size(tr_mesh_name).x, cfg.top_left_width = std::max(m_imgui->calc_text_size(tr_mesh_name).x,
m_imgui->calc_text_size(tr_triangles).x) m_imgui->calc_text_size(tr_triangles).x)
+ space_size; + space_size;
const float radio_size = ImGui::GetFrameHeight(); const float radio_size = ImGui::GetFrameHeight();
@ -591,7 +592,7 @@ void GLGizmoSimplify::create_gui_cfg() {
cfg.input_width = cfg.bottom_left_width * 1.5; cfg.input_width = cfg.bottom_left_width * 1.5;
cfg.window_offset_x = (cfg.bottom_left_width + cfg.input_width)/2; cfg.window_offset_x = (cfg.bottom_left_width + cfg.input_width)/2;
cfg.window_offset_y = ImGui::GetTextLineHeightWithSpacing() * 5; cfg.window_offset_y = ImGui::GetTextLineHeightWithSpacing() * 5;
m_gui_cfg = cfg; m_gui_cfg = cfg;
} }
@ -605,7 +606,7 @@ void GLGizmoSimplify::request_rerender(bool force) {
} }
void GLGizmoSimplify::set_center_position() { void GLGizmoSimplify::set_center_position() {
m_move_to_center = true; m_move_to_center = true;
} }
@ -619,7 +620,7 @@ void GLGizmoSimplify::init_model(const indexed_triangle_set& its)
m_parent.toggle_model_objects_visibility(true); // selected volume may have changed m_parent.toggle_model_objects_visibility(true); // selected volume may have changed
m_parent.toggle_model_objects_visibility(false, m_c->selection_info()->model_object(), m_parent.toggle_model_objects_visibility(false, m_c->selection_info()->model_object(),
m_c->selection_info()->get_active_instance(), m_volume); m_c->selection_info()->get_active_instance(), m_volume);
if (const Selection&sel = m_parent.get_selection(); sel.get_volume_idxs().size() == 1) if (const Selection&sel = m_parent.get_selection(); sel.get_volume_idxs().size() == 1)
m_glmodel.set_color(-1, sel.get_volume(*sel.get_volume_idxs().begin())->color); m_glmodel.set_color(-1, sel.get_volume(*sel.get_volume_idxs().begin())->color);
m_triangle_count = its.indices.size(); m_triangle_count = its.indices.size();

View file

@ -82,7 +82,7 @@ static HRESULT winrt_activate_instance(const std::wstring &class_name, IInspecta
{ {
HSTRING hClassName; HSTRING hClassName;
HRESULT hr = (*s_WindowsCreateString)(class_name.c_str(), class_name.size(), &hClassName); HRESULT hr = (*s_WindowsCreateString)(class_name.c_str(), class_name.size(), &hClassName);
if (S_OK != hr) if (S_OK != hr)
return hr; return hr;
hr = (*s_RoActivateInstance)(hClassName, pinst); hr = (*s_RoActivateInstance)(hClassName, pinst);
(*s_WindowsDeleteString)(hClassName); (*s_WindowsDeleteString)(hClassName);
@ -320,7 +320,7 @@ public:
// returt FALSE, if fixing was canceled // returt FALSE, if fixing was canceled
// fix_result is empty, if fixing finished successfully // fix_result is empty, if fixing finished successfully
// fix_result containes a message if fixing failed // fix_result containes a message if fixing failed
bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, GUI::ProgressDialog& progress_dialog, const wxString& msg_header, std::string& fix_result) bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, GUI::ProgressDialog& progress_dialog, const wxString& msg_header, std::string& fix_result)
{ {
std::mutex mutex; std::mutex mutex;
@ -379,7 +379,7 @@ bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, GUI::
model.clear_materials(); model.clear_materials();
boost::filesystem::path path_dst = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); boost::filesystem::path path_dst = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
path_dst += ".3mf"; path_dst += ".3mf";
fix_model_by_win10_sdk(path_src.string().c_str(), path_dst.string(), on_progress, fix_model_by_win10_sdk(path_src.string().c_str(), path_dst.string(), on_progress,
[&canceled]() { if (canceled) throw RepairCanceledException(); }); [&canceled]() { if (canceled) throw RepairCanceledException(); });
boost::filesystem::remove(path_src); boost::filesystem::remove(path_src);
// PresetBundle bundle; // PresetBundle bundle;
@ -403,6 +403,7 @@ bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, GUI::
for (size_t i = 0; i < volumes.size(); ++ i) { for (size_t i = 0; i < volumes.size(); ++ i) {
volumes[i]->set_mesh(std::move(meshes_repaired[i])); volumes[i]->set_mesh(std::move(meshes_repaired[i]));
volumes[i]->calculate_convex_hull(); volumes[i]->calculate_convex_hull();
volumes[i]->invalidate_convex_hull_2d();
volumes[i]->set_new_unique_id(); volumes[i]->set_new_unique_id();
} }
model_object.invalidate_bounding_box(); model_object.invalidate_bounding_box();