FIX: auto-aranging can't restart with context button if canceled

jira: STUDIO-6027
Change-Id: Ie87caa205f98a40099c615d89a22000a378bef5c
(cherry picked from commit 03e48ec5d9ac4e93c533390247a6a4a6f4ae31e8)
This commit is contained in:
Arthur 2024-03-08 11:18:20 +08:00 committed by Lane.Wei
parent fc114bff4e
commit ceaf008dd4
2 changed files with 99 additions and 100 deletions

View File

@ -614,121 +614,124 @@ static std::string concat_strings(const std::set<std::string> &strings,
void ArrangeJob::finalize() { void ArrangeJob::finalize() {
// Ignore the arrange result if aborted. // Ignore the arrange result if aborted.
if (was_canceled()) return; if (!was_canceled()) {
// Unprintable items go to the last virtual bed // Unprintable items go to the last virtual bed
int beds = 0; int beds = 0;
//BBS: partplate //BBS: partplate
PartPlateList& plate_list = m_plater->get_partplate_list(); PartPlateList& plate_list = m_plater->get_partplate_list();
//clear all the relations before apply the arrangement results //clear all the relations before apply the arrangement results
if (only_on_partplate) { if (only_on_partplate) {
plate_list.clear(false, false, true, current_plate_index); plate_list.clear(false, false, true, current_plate_index);
} }
else
plate_list.clear(false, false, true, -1);
//BBS: adjust the bed_index, create new plates, get the max bed_index
for (ArrangePolygon& ap : m_selected) {
//if (ap.bed_idx < 0) continue; // bed_idx<0 means unarrangable
//BBS: partplate postprocess
if (only_on_partplate)
plate_list.postprocess_bed_index_for_current_plate(ap);
else else
plate_list.postprocess_bed_index_for_selected(ap); plate_list.clear(false, false, true, -1);
//BBS: adjust the bed_index, create new plates, get the max bed_index
for (ArrangePolygon& ap : m_selected) {
//if (ap.bed_idx < 0) continue; // bed_idx<0 means unarrangable
//BBS: partplate postprocess
if (only_on_partplate)
plate_list.postprocess_bed_index_for_current_plate(ap);
else
plate_list.postprocess_bed_index_for_selected(ap);
beds = std::max(ap.bed_idx, beds); beds = std::max(ap.bed_idx, beds);
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": arrange selected %4%: bed_id %1%, trans {%2%,%3%}") % ap.bed_idx % unscale<double>(ap.translation(X)) % unscale<double>(ap.translation(Y)) % ap.name; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": arrange selected %4%: bed_id %1%, trans {%2%,%3%}") % ap.bed_idx % unscale<double>(ap.translation(X)) % unscale<double>(ap.translation(Y)) % ap.name;
} }
//BBS: adjust the bed_index, create new plates, get the max bed_index //BBS: adjust the bed_index, create new plates, get the max bed_index
for (ArrangePolygon& ap : m_unselected) for (ArrangePolygon& ap : m_unselected) {
{ if (ap.is_virt_object)
if (ap.is_virt_object) continue;
continue;
//BBS: partplate postprocess //BBS: partplate postprocess
if (!only_on_partplate) if (!only_on_partplate)
plate_list.postprocess_bed_index_for_unselected(ap); plate_list.postprocess_bed_index_for_unselected(ap);
beds = std::max(ap.bed_idx, beds); beds = std::max(ap.bed_idx, beds);
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":arrange unselected %4%: bed_id %1%, trans {%2%,%3%}") % ap.bed_idx % unscale<double>(ap.translation(X)) % unscale<double>(ap.translation(Y)) % ap.name; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":arrange unselected %4%: bed_id %1%, trans {%2%,%3%}") % ap.bed_idx % unscale<double>(ap.translation(X)) % unscale<double>(ap.translation(Y)) % ap.name;
} }
for (ArrangePolygon& ap : m_locked) { for (ArrangePolygon& ap : m_locked) {
beds = std::max(ap.bed_idx, beds); beds = std::max(ap.bed_idx, beds);
plate_list.postprocess_arrange_polygon(ap, false); plate_list.postprocess_arrange_polygon(ap, false);
ap.apply(); ap.apply();
} }
// Apply the arrange result to all selected objects // Apply the arrange result to all selected objects
for (ArrangePolygon& ap : m_selected) { for (ArrangePolygon& ap : m_selected) {
//BBS: partplate postprocess //BBS: partplate postprocess
plate_list.postprocess_arrange_polygon(ap, true); plate_list.postprocess_arrange_polygon(ap, true);
ap.apply(); ap.apply();
} }
// Apply the arrange result to unselected objects(due to the sukodu-style column changes, the position of unselected may also be modified) // Apply the arrange result to unselected objects(due to the sukodu-style column changes, the position of unselected may also be modified)
for (ArrangePolygon& ap : m_unselected) for (ArrangePolygon& ap : m_unselected) {
{ if (ap.is_virt_object)
if (ap.is_virt_object) continue;
continue;
//BBS: partplate postprocess //BBS: partplate postprocess
plate_list.postprocess_arrange_polygon(ap, false); plate_list.postprocess_arrange_polygon(ap, false);
ap.apply(); ap.apply();
} }
// Move the unprintable items to the last virtual bed. // Move the unprintable items to the last virtual bed.
// Note ap.apply() moves relatively according to bed_idx, so we need to subtract the orignal bed_idx // Note ap.apply() moves relatively according to bed_idx, so we need to subtract the orignal bed_idx
for (ArrangePolygon& ap : m_unprintable) { for (ArrangePolygon& ap : m_unprintable) {
ap.bed_idx = beds + 1; ap.bed_idx = beds + 1;
plate_list.postprocess_arrange_polygon(ap, true); plate_list.postprocess_arrange_polygon(ap, true);
ap.apply(); ap.apply();
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":arrange m_unprintable: name: %4%, bed_id %1%, trans {%2%,%3%}") % ap.bed_idx % unscale<double>(ap.translation(X)) % unscale<double>(ap.translation(Y)) % ap.name; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":arrange m_unprintable: name: %4%, bed_id %1%, trans {%2%,%3%}") % ap.bed_idx % unscale<double>(ap.translation(X)) % unscale<double>(ap.translation(Y)) % ap.name;
} }
m_plater->update(); m_plater->update();
// BBS // BBS
//wxGetApp().obj_manipul()->set_dirty(); //wxGetApp().obj_manipul()->set_dirty();
if (!m_unarranged.empty()) { if (!m_unarranged.empty()) {
std::set<std::string> names; std::set<std::string> names;
for (ModelInstance *mi : m_unarranged) for (ModelInstance* mi : m_unarranged)
names.insert(mi->get_object()->name); names.insert(mi->get_object()->name);
m_plater->get_notification_manager()->push_notification(GUI::format( m_plater->get_notification_manager()->push_notification(GUI::format(
_L("Arrangement ignored the following objects which can't fit into a single bed:\n%s"), _L("Arrangement ignored the following objects which can't fit into a single bed:\n%s"),
concat_strings(names, "\n"))); concat_strings(names, "\n")));
} }
m_plater->get_notification_manager()->close_notification_of_type(NotificationType::ArrangeOngoing);
// unlock the plates we just locked // unlock the plates we just locked
for (int i : m_uncompatible_plates) { for (int i : m_uncompatible_plates) {
PartPlate* plate = plate_list.get_plate(i); PartPlate* plate = plate_list.get_plate(i);
if (plate) plate->lock(false); if (plate) plate->lock(false);
} }
//BBS: reload all objects due to arrange //BBS: reload all objects due to arrange
if (only_on_partplate) { if (only_on_partplate) {
plate_list.rebuild_plates_after_arrangement(!only_on_partplate, true, current_plate_index); plate_list.rebuild_plates_after_arrangement(!only_on_partplate, true, current_plate_index);
}
else {
plate_list.rebuild_plates_after_arrangement(!only_on_partplate, true);
}
// BBS: update slice context and gcode result.
m_plater->update_slicing_context_to_current_partplate();
wxGetApp().obj_list()->reload_all_plates();
m_plater->update();
m_plater->get_notification_manager()->push_notification(NotificationType::ArrangeOngoing,
NotificationManager::NotificationLevel::RegularNotificationLevel, _u8L("Arranging done."));
} }
else { else {
plate_list.rebuild_plates_after_arrangement(!only_on_partplate, true); m_plater->get_notification_manager()->push_notification(NotificationType::ArrangeOngoing,
NotificationManager::NotificationLevel::RegularNotificationLevel, _u8L("Arranging canceled."));
} }
// BBS: update slice context and gcode result.
m_plater->update_slicing_context_to_current_partplate();
wxGetApp().obj_list()->reload_all_plates();
m_plater->update();
Job::finalize(); Job::finalize();
m_plater->m_arrange_running.store(false); m_plater->m_arrange_running.store(false);
} }

View File

@ -202,19 +202,15 @@ void OrientJob::process()
void OrientJob::finalize() { void OrientJob::finalize() {
// Ignore the arrange result if aborted. // Ignore the arrange result if aborted.
if (was_canceled()) return; if (!was_canceled()) {
for (OrientMesh& mesh : m_selected) {
mesh.apply();
}
m_plater->update();
for (OrientMesh& mesh : m_selected) // BBS
{ //wxGetApp().obj_manipul()->set_dirty();
mesh.apply();
} }
m_plater->update();
// BBS
//wxGetApp().obj_manipul()->set_dirty();
Job::finalize(); Job::finalize();
} }