* FIX: the logic of buried points that were not buried JIRA: none Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: Id95174659c5fce7feba409eb5e14916608745fa4 * ci: update network module based on commit bc7ca98 Change-Id: I923526f0bf9ce5a288144fa1f9b0f2fc640f41b7 * Fix Firefox Co-authored-by: hadess <hadess@hadess.net> * FIX: cali: custom created filament from AMS displayed as incompatible jira: new remove the condition: is_system Change-Id: Ib1366966bbdbe01bc9e2483d9914d270ebefa976 * FIX: duplicated items in comboBox at calibration completed page jira: new Change-Id: I4749a2206df16c438e0d3098e36274b2a20f313e * ENH:update support for P1S plus jira:[for p1s plus] Change-Id: Id577d4e94e2162cb0045d261dfaa5f396ecded2f * ENH: CLI: add mk information support JIRA: no jira Change-Id: Idd89b143d439de50d9f52eb8aec95b262d66875d * ENH:calibration support p1p plus jira:[plus] Change-Id: Ia290d3a8a8b9adaac7a6ee26d9a8b5ea0c1b3aee * FIX: add log for base_id and filament_id github: #3087 Change-Id: Iebfbd0f224fce49f33fc81c71e6108f6e3abb5ff * FIX: sync whole preset vendor directory Change-Id: I191dbe979a87ff35d38cab1149b7975664344838 Jira: STUDIO-5534 (cherry picked from commit 628866608116336453804aa1217dd55db04d47ad) * FIX: use t_utc for debug only Change-Id: Ia05d8969d4de3dd38908980d6e17a3ebb11ca279 Github 3045 Change-Id: I77935df53bbf2772b1146e5c330c537165a3a2e6 * FIX:make sort_volumes right Jira: STUDIO-5645 Change-Id: If324c9115bfaaf0c1b7b4be7c7ee96ba6b8ac890 * ENH:keep an unload logic jira:[for unload] Change-Id: Id30ec71ffa5b2dac89346ea47ca48a62479e3ab1 * FIX: several problems with mesh boolean 1. Cut with multiple volumes are OK now. 2. Close mesh boolean fail error with new object or open object 3. Fix wrong name and config of boolean resulting object github: #3118 jira: none Change-Id: If2c9dbfb36cbdfe4917a2371217923891bb7909c (cherry picked from commit 982c0ecb92cf7c2b5ae5972ab900a6b10e7dda50) * NEW:limit the length of project name jira:[project name] Change-Id: I955620f7073b3b7fda280d1118524f561d047751 * ENH:adjusting the warning level of timelpase jira:[STUDIO-5662] Change-Id: I4902b22d316f5e09a97a62c88b8a98e55c405434 * FIX: 3mf specification: change namespace form slic3rpe to BambuStudio Jira: XXXX Change-Id: Id705affc875ef23fdf2ac6d79f0cb0aafc4f7050 * NEW: Open MakerWorld With BambuStudio GetParam JIRA: none Change-Id: I0d65b364f1cd2d634a88882ab072c3e61ea89167 (cherry picked from commit 8eaf45e5359439a7c796fd79876c86775abcf48e) * FIX: Filament issue generated when creating a printer Jira: XXXX Change-Id: I976770b69b47641bd54aa7a9c56fba7f58d1ab68 (cherry picked from commit ba42188b93c58b3954234d72acdd9769a68e3d3c) * FIX: Blank page appears when editing presets Jira: 5563 Change-Id: I4c49e05515b1beff55991e92f8079c4499c27eab (cherry picked from commit e86517d290f4cd0765a230d811b0ddf2c9f34c17) * FIX: context menu didn't update UI jira: STUDIO-5691 Change-Id: Ia66b8623d832eba805aff5320941233a68ff258b * FIX: crash of "filling bed" "get_arrange_settings() const" gets trapped in infinite recursive calling. Now we delete this function. jira: STUDIO-5688 Change-Id: Ia39974734bb37b2a2f06b5bf78185f01be726872 * FIX: boolean hangs in the middle of color painting Can't do splits in combine_mesh_fff, as do_boolean of mcut will split meshes. jira: STUDIO-5693 Change-Id: Idddb7d20dd7ca386c39ddd3d87d9defc3136aa5d (cherry picked from commit 6c67d015941458e37faaf0015b6509b5a0eadc0e) * Fix: Fix a number of compilation problems issues found when using gcc version 13.2.0 (GCC) in a Flatpak sandbox github : https://github.com/bambulab/BambuStudio/issues/3074 github pull request: https://github.com/bambulab/BambuStudio/pull/3096 Change-Id: I08aeac593eb1ce7675894df72e8489200bae713d (cherry picked from commit 069d133d66bfa682de4a860e379d5dc16b3d907c) * fix: macos icns issue when icon was not attached github pull request:https://github.com/bambulab/BambuStudio/pull/3116 Change-Id: I49072ad49f3af7669a6d307c791594ade210da50 (cherry picked from commit c977e5582e3a30ad16dd267810037423aad9a53c) * FIX: Add flush_length for change_filament_gcode Change-Id: I30f4b97d3d61c2a57f0e92f157cbd31c38aa7265 Jira: XXXX (cherry picked from commit 92eb2bac977a0c4095b316cbbc6580fb5228b710) * FIX: edit preset dialog can't close on mac Jira: 5696 Change-Id: Ib33dfd07cc588ddd3805e3490a4d8c36dcd890ac * ENH: add dev_ota_version in ssdp JIRA: STUDIO-5740 Change-Id: Ic80e6d4b9bf82813fdc4a76604a3d36213d12b03 Signed-off-by: Stone Li <stone.li@bambulab.com> * NEW:Adapt to multicolour and gradient colour JIRA:xxxx Change-Id: I8084cab603d5681cbcaf2d6f5e0d7ad5419cb2af * NEW:Adaptation of semi transparent materials JIRA: XXXX Change-Id: Ie32d8ce67c37b85eb6d7d6594cb514a696307e68 * FIX: disable flush options if prime tower is unchecked jira: STUDIO-5639 Change-Id: I25081584d430bc7d062e14bcc2cdbf7522cf9d99 * ENH: refine GetVersion for HMS query JIRA: STUDIO-5763 Change-Id: Ia3ccc07d79cc0736eb12e9782da50211abb74772 Signed-off-by: Stone Li <stone.li@bambulab.com> * FIX: Prefer old selection when sync AMS not compatible Change-Id: I6b18db51887132a997cf78d70fff9a92e23bc44a Jira: STUDIO-5416 (cherry picked from commit 077fae29823cf4f3071d408b1b40f55ee0cb33c6) * FIX: The flushing was not auto-calc when sync ams list JIRA: STUDIO-5551 1. flushing volume auto-calc when sync ams list 2. flushing volume takes the larger calculation value when filament has multi-colors Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: I72e6f9780ea56103a44c2da6068440a4615c254d * FIX:fixed invalid links jira:[fixed link] Change-Id: I036a38b6e8e94da762f93805bd7be706538771fe * FIX: Prompt to delete problematic presets Jira: XXXX Change-Id: Ic43f7bb782794d7ab0b6acbffbb5d73e94f6ed73 * FIX:fixed incorrect HMS content jira:[STUDIO-5818] Change-Id: Ia2896d6f0ab1ffedbc850e54168acece8e47bdbb * FIX:external transparent material display error JIRA: STUDIO-5845 Change-Id: I0a4f05ac5d5c0ac49d85a704ee65a7221c5f1e1d * FIX: [5846] Custom Filament Page show System Filament Simultaneously solve: When downloading Preset from the cloud, the filament_id of the preset in m_preset is null. Jira: 5846 Change-Id: I6ba1b46fe92e345614b6a4af3fffa87d81fa2456 * FIX:A1 and p1 series do not support custom materials JIRA:XXXX Change-Id: Ib0459273d1f9a7152a5563757204634a8d0cd6f5 * FIX: exception when comparing profiles jira:[NEW] Signed-off-by: XunZhangBambu <xun.zhang@bambulab.com> Change-Id: I946b5fcd35f779d271df2b3de731fdcada5aab29 (cherry picked from commit 00e739570812e5c4be3e0f7702ce8c72c0f9e72b) * FIX: hide_id_middle_string Change-Id: I28f32ec526b443d31d7992971b80ab1cb737deb6 Github: STUDIO-5825 * ENH: modify some logs level JIRA: STUDIO-5958 Change-Id: I5a8592dfb8ffa9a81952535cb30944f867aa0e22 Signed-off-by: Stone Li <stone.li@bambulab.com> * NEW:build plate marker detect Change-Id: I70f03efea688bb6ce71c3f5990bb3c50605ab184 * FIX: Studio UI Freeze when saving user preset github: #3335 Change-Id: Idaf53f673a3e46408826c06bdde2c592395d358b * update bbl plugin version * fix build errors * update bbl profiles * update color --------- Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Signed-off-by: Stone Li <stone.li@bambulab.com> Co-authored-by: Kunlong Ma <kunlong.ma@bambulab.com> Co-authored-by: gerrit <gerrit@bambulab.com> Co-authored-by: liz.li <liz.li@bambulab.com> Co-authored-by: tao wang <tao.wang@bambulab.com> Co-authored-by: lane.wei <lane.wei@bambulab.com> Co-authored-by: maosheng.wei <maosheng.wei@bambulab.com> Co-authored-by: chunmao.guo <chunmao.guo@bambulab.com> Co-authored-by: zhou.xu <zhou.xu@bambulab.com> Co-authored-by: Arthur <arthur.tang@bambulab.com> Co-authored-by: Bastien Nocera <hadess@hadess.net> Co-authored-by: zhimin.zeng <zhimin.zeng@bambulab.com> Co-authored-by: hu.wang <hu.wang@bambulab.com> Co-authored-by: Stone Li <stone.li@bambulab.com> Co-authored-by: XunZhangBambu <xun.zhang@bambulab.com>
791 lines
31 KiB
C++
791 lines
31 KiB
C++
///|/ Copyright (c) Prusa Research 2020 - 2023 Tomáš Mészáros @tamasmeszaros, Enrico Turri @enricoturri1966, Vojtěch Bubník @bubnikv, David Kocík @kocikdav, Filip Sykala @Jony01, Lukáš Matěna @lukasmatena
|
||
///|/
|
||
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
||
///|/
|
||
#include "ArrangeJob.hpp"
|
||
|
||
#include "libslic3r/BuildVolume.hpp"
|
||
#include "libslic3r/SVG.hpp"
|
||
#include "libslic3r/MTUtils.hpp"
|
||
#include "libslic3r/PresetBundle.hpp"
|
||
#include "libslic3r/ModelArrange.hpp"
|
||
|
||
#include "slic3r/GUI/PartPlate.hpp"
|
||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||
#include "slic3r/GUI/GUI.hpp"
|
||
#include "slic3r/GUI/GUI_App.hpp"
|
||
#include "slic3r/GUI/NotificationManager.hpp"
|
||
#include "slic3r/GUI/format.hpp"
|
||
#include "slic3r/GUI/GUI_ObjectList.hpp"
|
||
|
||
#include "libnest2d/common.hpp"
|
||
|
||
#define SAVE_ARRANGE_POLY 0
|
||
|
||
namespace Slic3r { namespace GUI {
|
||
using ArrangePolygon = arrangement::ArrangePolygon;
|
||
|
||
// Cache the wti info
|
||
class WipeTower: public GLCanvas3D::WipeTowerInfo {
|
||
public:
|
||
explicit WipeTower(const GLCanvas3D::WipeTowerInfo &wti)
|
||
: GLCanvas3D::WipeTowerInfo(wti)
|
||
{}
|
||
|
||
explicit WipeTower(GLCanvas3D::WipeTowerInfo &&wti)
|
||
: GLCanvas3D::WipeTowerInfo(std::move(wti))
|
||
{}
|
||
|
||
void apply_arrange_result(const Vec2d& tr, double rotation, int item_id)
|
||
{
|
||
m_pos = unscaled(tr); m_rotation = rotation;
|
||
apply_wipe_tower();
|
||
}
|
||
|
||
ArrangePolygon get_arrange_polygon() const
|
||
{
|
||
Polygon ap({
|
||
{scaled(m_bb.min)},
|
||
{scaled(m_bb.max.x()), scaled(m_bb.min.y())},
|
||
{scaled(m_bb.max)},
|
||
{scaled(m_bb.min.x()), scaled(m_bb.max.y())}
|
||
});
|
||
|
||
ArrangePolygon ret;
|
||
ret.poly.contour = std::move(ap);
|
||
ret.translation = scaled(m_pos);
|
||
ret.rotation = m_rotation;
|
||
//BBS
|
||
ret.name = "WipeTower";
|
||
ret.is_virt_object = true;
|
||
ret.is_wipe_tower = true;
|
||
++ret.priority;
|
||
|
||
BOOST_LOG_TRIVIAL(debug) << " arrange: wipe tower info:" << m_bb << ", m_pos: " << m_pos.transpose();
|
||
|
||
return ret;
|
||
}
|
||
};
|
||
|
||
// BBS: add partplate logic
|
||
static WipeTower get_wipe_tower(const Plater &plater, int plate_idx)
|
||
{
|
||
return WipeTower{plater.canvas3D()->get_wipe_tower_info(plate_idx)};
|
||
}
|
||
|
||
arrangement::ArrangePolygon get_wipetower_arrange_poly(WipeTower* tower)
|
||
{
|
||
ArrangePolygon ap = tower->get_arrange_polygon();
|
||
ap.bed_idx = 0;
|
||
ap.setter = NULL; // do not move wipe tower
|
||
return ap;
|
||
}
|
||
|
||
void ArrangeJob::clear_input()
|
||
{
|
||
const Model &model = m_plater->model();
|
||
|
||
size_t count = 0, cunprint = 0; // To know how much space to reserve
|
||
for (auto obj : model.objects)
|
||
for (auto mi : obj->instances)
|
||
mi->printable ? count++ : cunprint++;
|
||
|
||
params.nonprefered_regions.clear();
|
||
m_selected.clear();
|
||
m_unselected.clear();
|
||
m_unprintable.clear();
|
||
m_locked.clear();
|
||
m_unarranged.clear();
|
||
m_selected.reserve(count + 1 /* for optional wti */);
|
||
m_unselected.reserve(count + 1 /* for optional wti */);
|
||
m_unprintable.reserve(cunprint /* for optional wti */);
|
||
m_locked.reserve(count + 1 /* for optional wti */);
|
||
current_plate_index = 0;
|
||
}
|
||
|
||
ArrangePolygon ArrangeJob::prepare_arrange_polygon(void* model_instance)
|
||
{
|
||
ModelInstance* instance = (ModelInstance*)model_instance;
|
||
const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
|
||
return get_instance_arrange_poly(instance, config);
|
||
}
|
||
|
||
void ArrangeJob::prepare_selected() {
|
||
PartPlateList& plate_list = m_plater->get_partplate_list();
|
||
|
||
clear_input();
|
||
|
||
Model& model = m_plater->model();
|
||
bool selected_is_locked = false;
|
||
//BBS: remove logic for unselected object
|
||
//double stride = bed_stride_x(m_plater);
|
||
|
||
std::vector<const Selection::InstanceIdxsList*>
|
||
obj_sel(model.objects.size(), nullptr);
|
||
|
||
for (auto& s : m_plater->get_selection().get_content())
|
||
if (s.first < int(obj_sel.size()))
|
||
obj_sel[size_t(s.first)] = &s.second;
|
||
|
||
// Go through the objects and check if inside the selection
|
||
for (size_t oidx = 0; oidx < model.objects.size(); ++oidx) {
|
||
const Selection::InstanceIdxsList* instlist = obj_sel[oidx];
|
||
ModelObject* mo = model.objects[oidx];
|
||
|
||
std::vector<bool> inst_sel(mo->instances.size(), false);
|
||
|
||
if (instlist)
|
||
for (auto inst_id : *instlist)
|
||
inst_sel[size_t(inst_id)] = true;
|
||
|
||
for (size_t i = 0; i < inst_sel.size(); ++i) {
|
||
ModelInstance* mi = mo->instances[i];
|
||
ArrangePolygon&& ap = prepare_arrange_polygon(mo->instances[i]);
|
||
//BBS: partplate_list preprocess
|
||
//remove the locked plate's instances, neither in selected, nor in un-selected
|
||
bool locked = plate_list.preprocess_arrange_polygon(oidx, i, ap, inst_sel[i]);
|
||
if (!locked)
|
||
{
|
||
ArrangePolygons& cont = mo->instances[i]->printable ?
|
||
(inst_sel[i] ? m_selected :
|
||
m_unselected) :
|
||
m_unprintable;
|
||
|
||
ap.itemid = cont.size();
|
||
cont.emplace_back(std::move(ap));
|
||
}
|
||
else
|
||
{
|
||
//skip this object due to be locked in plate
|
||
ap.itemid = m_locked.size();
|
||
m_locked.emplace_back(std::move(ap));
|
||
if (inst_sel[i])
|
||
selected_is_locked = true;
|
||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": skip locked instance, obj_id %1%, instance_id %2%, name %3%") % oidx % i % mo->name;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// If the selection was empty arrange everything
|
||
//if (m_selected.empty()) m_selected.swap(m_unselected);
|
||
if (m_selected.empty()) {
|
||
if (!selected_is_locked)
|
||
m_selected.swap(m_unselected);
|
||
else {
|
||
m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
|
||
NotificationManager::NotificationLevel::WarningNotificationLevel, into_u8(_L("All the selected objects are on the locked plate,\nWe can not do auto-arrange on these objects.")));
|
||
}
|
||
}
|
||
|
||
prepare_wipe_tower();
|
||
|
||
|
||
// The strides have to be removed from the fixed items. For the
|
||
// arrangeable (selected) items bed_idx is ignored and the
|
||
// translation is irrelevant.
|
||
//BBS: remove logic for unselected object
|
||
//for (auto &p : m_unselected) p.translation(X) -= p.bed_idx * stride;
|
||
}
|
||
|
||
void ArrangeJob::prepare_all() {
|
||
PartPlateList& plate_list = m_plater->get_partplate_list();
|
||
|
||
clear_input();
|
||
|
||
Model &model = m_plater->model();
|
||
bool selected_is_locked = false;
|
||
|
||
// Go through the objects and check if inside the selection
|
||
for (size_t oidx = 0; oidx < model.objects.size(); ++oidx) {
|
||
ModelObject *mo = model.objects[oidx];
|
||
|
||
for (size_t i = 0; i < mo->instances.size(); ++i) {
|
||
ModelInstance * mi = mo->instances[i];
|
||
ArrangePolygon&& ap = prepare_arrange_polygon(mo->instances[i]);
|
||
//BBS: partplate_list preprocess
|
||
//remove the locked plate's instances, neither in selected, nor in un-selected
|
||
bool locked = plate_list.preprocess_arrange_polygon(oidx, i, ap, true);
|
||
if (!locked)
|
||
{
|
||
ArrangePolygons& cont = mo->instances[i]->printable ? m_selected :m_unprintable;
|
||
|
||
ap.itemid = cont.size();
|
||
cont.emplace_back(std::move(ap));
|
||
}
|
||
else
|
||
{
|
||
//skip this object due to be locked in plate
|
||
ap.itemid = m_locked.size();
|
||
m_locked.emplace_back(std::move(ap));
|
||
selected_is_locked = true;
|
||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": skip locked instance, obj_id %1%, instance_id %2%") % oidx % i;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// If the selection was empty arrange everything
|
||
//if (m_selected.empty()) m_selected.swap(m_unselected);
|
||
if (m_selected.empty()) {
|
||
if (!selected_is_locked) {
|
||
m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
|
||
NotificationManager::NotificationLevel::WarningNotificationLevel, into_u8(_L("No arrangable objects are selected.")));
|
||
}
|
||
else {
|
||
m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
|
||
NotificationManager::NotificationLevel::WarningNotificationLevel, into_u8(_L("All the selected objects are on the locked plate,\nWe can not do auto-arrange on these objects.")));
|
||
}
|
||
}
|
||
|
||
prepare_wipe_tower();
|
||
|
||
// add the virtual object into unselect list if has
|
||
plate_list.preprocess_exclude_areas(m_unselected, MAX_NUM_PLATES);
|
||
}
|
||
|
||
arrangement::ArrangePolygon estimate_wipe_tower_info(int plate_index, std::set<int>& extruder_ids)
|
||
{
|
||
PartPlateList& ppl = wxGetApp().plater()->get_partplate_list();
|
||
const auto& full_config = wxGetApp().preset_bundle->full_config();
|
||
int plate_count = ppl.get_plate_count();
|
||
int plate_index_valid = std::min(plate_index, plate_count - 1);
|
||
|
||
// we have to estimate the depth using the extruder number of all plates
|
||
int extruder_size = extruder_ids.size();
|
||
|
||
auto arrange_poly = ppl.get_plate(plate_index_valid)->estimate_wipe_tower_polygon(full_config, plate_index, extruder_size);
|
||
arrange_poly.bed_idx = plate_index;
|
||
return arrange_poly;
|
||
}
|
||
|
||
// 准备料塔。逻辑如下:
|
||
// 1. 以下几种情况不需要料塔:
|
||
// 1)料塔被禁用,
|
||
// 2)逐件打印,
|
||
// 3)不允许不同材料落在相同盘,且没有多色对象
|
||
// 2. 以下情况需要料塔:
|
||
// 1)某对象是多色对象;
|
||
// 2)打开了支撑,且支撑体与接触面使用的是不同材料
|
||
// 3)允许不同材料落在相同盘,且所有选定对象中使用了多种热床温度相同的材料
|
||
// (所有对象都是单色的,但不同对象的材料不同,例如:对象A使用红色PLA,对象B使用白色PLA)
|
||
void ArrangeJob::prepare_wipe_tower()
|
||
{
|
||
bool need_wipe_tower = false;
|
||
|
||
// if wipe tower is explicitly disabled, no need to estimate
|
||
DynamicPrintConfig& current_config = wxGetApp().preset_bundle->prints.get_edited_preset().config;
|
||
auto op = current_config.option("enable_prime_tower");
|
||
bool enable_prime_tower = op && op->getBool();
|
||
if (!enable_prime_tower || params.is_seq_print) return;
|
||
|
||
bool smooth_timelapse = false;
|
||
auto sop = current_config.option("timelapse_type");
|
||
if (sop) { smooth_timelapse = sop->getInt() == TimelapseType::tlSmooth; }
|
||
if (smooth_timelapse) { need_wipe_tower = true; }
|
||
|
||
// estimate if we need wipe tower for all plates:
|
||
// need wipe tower if some object has multiple extruders (has paint-on colors or support material)
|
||
for (const auto& item : m_selected) {
|
||
std::set<int> obj_extruders;
|
||
obj_extruders.insert(item.extrude_ids.begin(), item.extrude_ids.end());
|
||
if (obj_extruders.size() > 1) {
|
||
need_wipe_tower = true;
|
||
BOOST_LOG_TRIVIAL(info) << "arrange: need wipe tower because object " << item.name << " has multiple extruders (has paint-on colors)";
|
||
break;
|
||
}
|
||
}
|
||
|
||
// if multile extruders have same bed temp, we need wipe tower
|
||
// 允许不同材料落在相同盘,且所有选定对象中使用了多种热床温度相同的材料
|
||
if (params.allow_multi_materials_on_same_plate) {
|
||
std::map<int, std::set<int>> bedTemp2extruderIds;
|
||
for (const auto& item : m_selected)
|
||
for (auto id : item.extrude_ids) { bedTemp2extruderIds[item.bed_temp].insert(id); }
|
||
for (const auto& be : bedTemp2extruderIds) {
|
||
if (be.second.size() > 1) {
|
||
need_wipe_tower = true;
|
||
BOOST_LOG_TRIVIAL(info) << "arrange: need wipe tower because allow_multi_materials_on_same_plate=true and we have multiple extruders of same type";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
BOOST_LOG_TRIVIAL(info) << "arrange: need_wipe_tower=" << need_wipe_tower;
|
||
|
||
|
||
ArrangePolygon wipe_tower_ap;
|
||
wipe_tower_ap.name = "WipeTower";
|
||
wipe_tower_ap.is_virt_object = true;
|
||
wipe_tower_ap.is_wipe_tower = true;
|
||
const GLCanvas3D* canvas3D = static_cast<const GLCanvas3D*>(m_plater->canvas3D());
|
||
|
||
std::set<int> extruder_ids;
|
||
PartPlateList& ppl = wxGetApp().plater()->get_partplate_list();
|
||
int plate_count = ppl.get_plate_count();
|
||
if (!only_on_partplate) {
|
||
extruder_ids = ppl.get_extruders(true);
|
||
}
|
||
|
||
int bedid_unlocked = 0;
|
||
for (int bedid = 0; bedid < MAX_NUM_PLATES; bedid++) {
|
||
int plate_index_valid = std::min(bedid, plate_count - 1);
|
||
PartPlate* pl = ppl.get_plate(plate_index_valid);
|
||
if(bedid<plate_count && pl->is_locked())
|
||
continue;
|
||
if (auto wti = get_wipe_tower(*m_plater, bedid)) {
|
||
// wipe tower is already there
|
||
wipe_tower_ap = get_wipetower_arrange_poly(&wti);
|
||
wipe_tower_ap.bed_idx = bedid_unlocked;
|
||
m_unselected.emplace_back(wipe_tower_ap);
|
||
}
|
||
else if (need_wipe_tower) {
|
||
if (only_on_partplate) {
|
||
auto plate_extruders = pl->get_extruders(true);
|
||
extruder_ids.clear();
|
||
extruder_ids.insert(plate_extruders.begin(), plate_extruders.end());
|
||
}
|
||
wipe_tower_ap = estimate_wipe_tower_info(bedid, extruder_ids);
|
||
wipe_tower_ap.bed_idx = bedid_unlocked;
|
||
m_unselected.emplace_back(wipe_tower_ap);
|
||
}
|
||
bedid_unlocked++;
|
||
}
|
||
}
|
||
|
||
|
||
//BBS: prepare current part plate for arranging
|
||
void ArrangeJob::prepare_partplate() {
|
||
clear_input();
|
||
|
||
PartPlateList& plate_list = m_plater->get_partplate_list();
|
||
PartPlate* plate = plate_list.get_curr_plate();
|
||
current_plate_index = plate_list.get_curr_plate_index();
|
||
assert(plate != nullptr);
|
||
|
||
if (plate->empty())
|
||
{
|
||
//no instances on this plate
|
||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": no instances in current plate!");
|
||
|
||
return;
|
||
}
|
||
|
||
if (plate->is_locked()) {
|
||
m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
|
||
NotificationManager::NotificationLevel::WarningNotificationLevel, into_u8(_L("This plate is locked,\nWe can not do auto-arrange on this plate.")));
|
||
return;
|
||
}
|
||
|
||
Model& model = m_plater->model();
|
||
|
||
// Go through the objects and check if inside the selection
|
||
for (size_t oidx = 0; oidx < model.objects.size(); ++oidx)
|
||
{
|
||
ModelObject* mo = model.objects[oidx];
|
||
for (size_t inst_idx = 0; inst_idx < mo->instances.size(); ++inst_idx)
|
||
{
|
||
bool in_plate = plate->contain_instance(oidx, inst_idx) || plate->intersect_instance(oidx, inst_idx);
|
||
ArrangePolygon&& ap = prepare_arrange_polygon(mo->instances[inst_idx]);
|
||
|
||
ArrangePolygons& cont = mo->instances[inst_idx]->printable ?
|
||
(in_plate ? m_selected : m_unselected) :
|
||
m_unprintable;
|
||
bool locked = plate_list.preprocess_arrange_polygon_other_locked(oidx, inst_idx, ap, in_plate);
|
||
if (!locked)
|
||
{
|
||
ap.itemid = cont.size();
|
||
cont.emplace_back(std::move(ap));
|
||
}
|
||
else
|
||
{
|
||
//skip this object due to be not in current plate, treated as locked
|
||
ap.itemid = m_locked.size();
|
||
m_locked.emplace_back(std::move(ap));
|
||
//BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": skip locked instance, obj_id %1%, name %2%") % oidx % mo->name;
|
||
}
|
||
}
|
||
}
|
||
|
||
// BBS
|
||
if (auto wti = get_wipe_tower(*m_plater, current_plate_index)) {
|
||
ArrangePolygon&& ap = get_wipetower_arrange_poly(&wti);
|
||
m_unselected.emplace_back(std::move(ap));
|
||
}
|
||
|
||
// add the virtual object into unselect list if has
|
||
plate_list.preprocess_exclude_areas(m_unselected, current_plate_index + 1);
|
||
}
|
||
|
||
//BBS: add partplate logic
|
||
void ArrangeJob::prepare()
|
||
{
|
||
m_plater->get_notification_manager()->push_notification(NotificationType::ArrangeOngoing,
|
||
NotificationManager::NotificationLevel::RegularNotificationLevel, _u8L("Arranging..."));
|
||
m_plater->get_notification_manager()->bbl_close_plateinfo_notification();
|
||
|
||
params = init_arrange_params(m_plater);
|
||
|
||
//BBS update extruder params and speed table before arranging
|
||
const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
|
||
auto& print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
|
||
auto print_config = print.config();
|
||
int numExtruders = wxGetApp().preset_bundle->filament_presets.size();
|
||
|
||
Model::setExtruderParams(config, numExtruders);
|
||
Model::setPrintSpeedTable(config, print_config);
|
||
|
||
int state = m_plater->get_prepare_state();
|
||
if (state == Job::JobPrepareState::PREPARE_STATE_DEFAULT) {
|
||
only_on_partplate = false;
|
||
prepare_all();
|
||
}
|
||
else if (state == Job::JobPrepareState::PREPARE_STATE_MENU) {
|
||
only_on_partplate = true; // only arrange items on current plate
|
||
prepare_partplate();
|
||
}
|
||
|
||
|
||
#if SAVE_ARRANGE_POLY
|
||
if (1)
|
||
{ // subtract excluded region and get a polygon bed
|
||
auto& print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
|
||
auto print_config = print.config();
|
||
bed_poly.points = get_bed_shape(*m_plater->config());
|
||
Pointfs excluse_area_points = print_config.bed_exclude_area.values;
|
||
Polygons exclude_polys;
|
||
Polygon exclude_poly;
|
||
for (int i = 0; i < excluse_area_points.size(); i++) {
|
||
auto pt = excluse_area_points[i];
|
||
exclude_poly.points.emplace_back(scale_(pt.x()), scale_(pt.y()));
|
||
if (i % 4 == 3) { // exclude areas are always rectangle
|
||
exclude_polys.push_back(exclude_poly);
|
||
exclude_poly.points.clear();
|
||
}
|
||
}
|
||
bed_poly = diff({ bed_poly }, exclude_polys)[0];
|
||
}
|
||
|
||
BoundingBox bbox = bed_poly.bounding_box();
|
||
Point center = bbox.center();
|
||
auto polys_to_draw = m_selected;
|
||
for (auto it = polys_to_draw.begin(); it != polys_to_draw.end(); it++) {
|
||
it->poly.translate(center);
|
||
bbox.merge(it->poly);
|
||
}
|
||
SVG svg("SVG/arrange_poly.svg", bbox);
|
||
if (svg.is_opened()) {
|
||
svg.draw_outline(bed_poly);
|
||
//svg.draw_grid(bbox, "gray", scale_(0.05));
|
||
std::vector<std::string> color_array = { "red","black","yellow","gree","blue" };
|
||
for (auto it = polys_to_draw.begin(); it != polys_to_draw.end(); it++) {
|
||
std::string color = color_array[(it - polys_to_draw.begin()) % color_array.size()];
|
||
svg.add_comment(it->name);
|
||
svg.draw_text(get_extents(it->poly).min, it->name.c_str(), color.c_str());
|
||
svg.draw_outline(it->poly, color);
|
||
}
|
||
}
|
||
#endif
|
||
|
||
check_unprintable();
|
||
}
|
||
|
||
void ArrangeJob::check_unprintable()
|
||
{
|
||
for (auto it = m_selected.begin(); it != m_selected.end();) {
|
||
if (it->poly.area() < 0.001)
|
||
{
|
||
#if SAVE_ARRANGE_POLY
|
||
SVG svg("SVG/arrange_unprintable_"+it->name+".svg", get_extents(it->poly));
|
||
if (svg.is_opened())
|
||
svg.draw_outline(it->poly);
|
||
#endif
|
||
|
||
m_unprintable.push_back(*it);
|
||
auto msg = (boost::format(
|
||
_utf8("Object %s has zero size and can't be arranged."))
|
||
% _utf8(it->name)).str();
|
||
m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
|
||
NotificationManager::NotificationLevel::WarningNotificationLevel, msg);
|
||
it = m_selected.erase(it);
|
||
}
|
||
else
|
||
it++;
|
||
}
|
||
}
|
||
|
||
void ArrangeJob::process(Ctl &ctl)
|
||
{
|
||
static const auto arrangestr = _u8L("Arranging");
|
||
ctl.update_status(0, arrangestr);
|
||
ctl.call_on_main_thread([this]{ prepare(); }).wait();;
|
||
|
||
auto & partplate_list = m_plater->get_partplate_list();
|
||
|
||
const Slic3r::DynamicPrintConfig& global_config = wxGetApp().preset_bundle->full_config();
|
||
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
|
||
const bool is_bbl = wxGetApp().preset_bundle->is_bbl_vendor();
|
||
if (is_bbl && params.avoid_extrusion_cali_region && global_config.opt_bool("scan_first_layer"))
|
||
partplate_list.preprocess_nonprefered_areas(m_unselected, MAX_NUM_PLATES);
|
||
|
||
update_arrange_params(params, m_plater->config(), m_selected);
|
||
update_selected_items_inflation(m_selected, m_plater->config(), params);
|
||
update_unselected_items_inflation(m_unselected, m_plater->config(), params);
|
||
update_selected_items_axis_align(m_selected, m_plater->config(), params);
|
||
|
||
Points bedpts = get_shrink_bedpts(m_plater->config(),params);
|
||
|
||
partplate_list.preprocess_exclude_areas(params.excluded_regions, 1, scale_(1));
|
||
|
||
BOOST_LOG_TRIVIAL(debug) << "arrange bedpts:" << bedpts[0].transpose() << ", " << bedpts[1].transpose() << ", " << bedpts[2].transpose() << ", " << bedpts[3].transpose();
|
||
|
||
params.stopcondition = [&ctl]() { return ctl.was_canceled(); };
|
||
|
||
params.progressind = [this, &ctl](unsigned num_finished, std::string str = "") {
|
||
ctl.update_status(num_finished * 100 / status_range(), _u8L("Arranging") + str);
|
||
};
|
||
|
||
{
|
||
BOOST_LOG_TRIVIAL(warning)<< "Arrange full params: "<< params.to_json();
|
||
BOOST_LOG_TRIVIAL(info) << boost::format("arrange: items selected before arranging: %1%") % m_selected.size();
|
||
for (auto selected : m_selected) {
|
||
BOOST_LOG_TRIVIAL(debug) << selected.name << ", extruder: " << selected.extrude_ids.back() << ", bed: " << selected.bed_idx << ", filemant_type:" << selected.filament_temp_type
|
||
<< ", trans: " << selected.translation.transpose();
|
||
}
|
||
BOOST_LOG_TRIVIAL(debug) << "arrange: items unselected before arrange: " << m_unselected.size();
|
||
for (auto item : m_unselected)
|
||
BOOST_LOG_TRIVIAL(debug) << item.name << ", bed: " << item.bed_idx << ", trans: " << item.translation.transpose()
|
||
<<", bbox:"<<get_extents(item.poly).min.transpose()<<","<<get_extents(item.poly).max.transpose();
|
||
}
|
||
|
||
arrangement::arrange(m_selected, m_unselected, bedpts, params);
|
||
|
||
// sort by item id
|
||
std::sort(m_selected.begin(), m_selected.end(), [](auto a, auto b) {return a.itemid < b.itemid; });
|
||
{
|
||
BOOST_LOG_TRIVIAL(info) << boost::format("arrange: items selected after arranging: %1%") % m_selected.size();
|
||
for (auto selected : m_selected)
|
||
BOOST_LOG_TRIVIAL(debug) << selected.name << ", extruder: " << selected.extrude_ids.back() << ", bed: " << selected.bed_idx
|
||
<< ", bed_temp: " << selected.first_bed_temp << ", print_temp: " << selected.print_temp
|
||
<< ", trans: " << unscale<double>(selected.translation(X)) << ","<< unscale<double>(selected.translation(Y));
|
||
BOOST_LOG_TRIVIAL(debug) << "arrange: items unselected after arrange: "<< m_unselected.size();
|
||
for (auto item : m_unselected)
|
||
BOOST_LOG_TRIVIAL(debug) << item.name << ", bed: " << item.bed_idx << ", trans: " << item.translation.transpose();
|
||
}
|
||
|
||
arrangement::arrange(m_unprintable, {}, bedpts, params);
|
||
|
||
// put unpackable items to m_unprintable so they goes outside
|
||
bool we_have_unpackable_items = false;
|
||
for (auto item : m_selected) {
|
||
if (item.bed_idx < 0) {
|
||
//BBS: already processed in m_selected
|
||
//m_unprintable.push_back(std::move(item));
|
||
we_have_unpackable_items = true;
|
||
}
|
||
}
|
||
|
||
// finalize just here.
|
||
ctl.update_status(100,
|
||
ctl.was_canceled() ? _u8L("Arranging canceled.") :
|
||
we_have_unpackable_items ? _u8L("Arranging is done but there are unpacked items. Reduce spacing and try again.") : _u8L("Arranging done."));
|
||
}
|
||
|
||
ArrangeJob::ArrangeJob() : m_plater{wxGetApp().plater()} { }
|
||
|
||
static std::string concat_strings(const std::set<std::string> &strings,
|
||
const std::string &delim = "\n")
|
||
{
|
||
return std::accumulate(
|
||
strings.begin(), strings.end(), std::string(""),
|
||
[delim](const std::string &s, const std::string &name) {
|
||
return s + name + delim;
|
||
});
|
||
}
|
||
|
||
void ArrangeJob::finalize(bool canceled, std::exception_ptr &eptr) {
|
||
try {
|
||
if (eptr)
|
||
std::rethrow_exception(eptr);
|
||
} catch (libnest2d::GeometryException &) {
|
||
show_error(m_plater, _(L("Arrange failed. "
|
||
"Found some exceptions when processing object geometries.")));
|
||
eptr = nullptr;
|
||
} catch (...) {
|
||
eptr = std::current_exception();
|
||
}
|
||
|
||
if (canceled || eptr)
|
||
return;
|
||
|
||
// Unprintable items go to the last virtual bed
|
||
int beds = 0;
|
||
|
||
//BBS: partplate
|
||
PartPlateList& plate_list = m_plater->get_partplate_list();
|
||
//clear all the relations before apply the arrangement results
|
||
if (only_on_partplate) {
|
||
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
|
||
plate_list.postprocess_bed_index_for_selected(ap);
|
||
|
||
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;
|
||
}
|
||
|
||
//BBS: adjust the bed_index, create new plates, get the max bed_index
|
||
for (ArrangePolygon& ap : m_unselected)
|
||
{
|
||
if (ap.is_virt_object)
|
||
continue;
|
||
|
||
//BBS: partplate postprocess
|
||
if (!only_on_partplate)
|
||
plate_list.postprocess_bed_index_for_unselected(ap);
|
||
|
||
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;
|
||
}
|
||
|
||
for (ArrangePolygon& ap : m_locked) {
|
||
beds = std::max(ap.bed_idx, beds);
|
||
|
||
plate_list.postprocess_arrange_polygon(ap, false);
|
||
|
||
ap.apply();
|
||
}
|
||
|
||
// Apply the arrange result to all selected objects
|
||
for (ArrangePolygon& ap : m_selected) {
|
||
//BBS: partplate postprocess
|
||
plate_list.postprocess_arrange_polygon(ap, true);
|
||
|
||
ap.apply();
|
||
}
|
||
|
||
// 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)
|
||
{
|
||
if (ap.is_virt_object)
|
||
continue;
|
||
|
||
//BBS: partplate postprocess
|
||
plate_list.postprocess_arrange_polygon(ap, false);
|
||
|
||
ap.apply();
|
||
}
|
||
|
||
// 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
|
||
for (ArrangePolygon& ap : m_unprintable) {
|
||
ap.bed_idx = beds + 1;
|
||
plate_list.postprocess_arrange_polygon(ap, true);
|
||
|
||
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;
|
||
}
|
||
|
||
m_plater->update();
|
||
// BBS
|
||
//wxGetApp().obj_manipul()->set_dirty();
|
||
|
||
if (!m_unarranged.empty()) {
|
||
std::set<std::string> names;
|
||
for (ModelInstance *mi : m_unarranged)
|
||
names.insert(mi->get_object()->name);
|
||
|
||
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"),
|
||
concat_strings(names, "\n")));
|
||
}
|
||
m_plater->get_notification_manager()->close_notification_of_type(NotificationType::ArrangeOngoing);
|
||
|
||
//BBS: reload all objects due to arrange
|
||
if (only_on_partplate) {
|
||
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->m_arrange_running.store(false);
|
||
}
|
||
|
||
std::optional<arrangement::ArrangePolygon>
|
||
get_wipe_tower_arrangepoly(const Plater &plater)
|
||
{
|
||
int id = plater.canvas3D()->fff_print()->get_plate_index();
|
||
if (auto wti = get_wipe_tower(plater, id))
|
||
return get_wipetower_arrange_poly(&wti);
|
||
|
||
return {};
|
||
}
|
||
|
||
//BBS: add sudoku-style stride
|
||
double bed_stride_x(const Plater* plater) {
|
||
double bedwidth = plater->build_volume().bounding_box().size().x();
|
||
return (1. + LOGICAL_BED_GAP) * bedwidth;
|
||
}
|
||
|
||
double bed_stride_y(const Plater* plater) {
|
||
double beddepth = plater->build_volume().bounding_box().size().y();
|
||
return (1. + LOGICAL_BED_GAP) * beddepth;
|
||
}
|
||
|
||
// call before get selected and unselected
|
||
arrangement::ArrangeParams init_arrange_params(Plater *p)
|
||
{
|
||
arrangement::ArrangeParams params;
|
||
GLCanvas3D::ArrangeSettings &settings = p->canvas3D()->get_arrange_settings();
|
||
auto &print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
|
||
const PrintConfig &print_config = print.config();
|
||
|
||
params.clearance_height_to_rod = print_config.extruder_clearance_height_to_rod.value;
|
||
params.clearance_height_to_lid = print_config.extruder_clearance_height_to_lid.value;
|
||
params.cleareance_radius = print_config.extruder_clearance_radius.value;
|
||
params.printable_height = print_config.printable_height.value;
|
||
params.allow_rotations = settings.enable_rotation;
|
||
params.align_center = print_config.best_object_pos.value;
|
||
params.allow_multi_materials_on_same_plate = settings.allow_multi_materials_on_same_plate;
|
||
params.avoid_extrusion_cali_region = settings.avoid_extrusion_cali_region;
|
||
params.is_seq_print = settings.is_seq_print;
|
||
params.min_obj_distance = scaled(settings.distance);
|
||
params.align_to_y_axis = settings.align_to_y_axis;
|
||
|
||
int state = p->get_prepare_state();
|
||
if (state == Job::JobPrepareState::PREPARE_STATE_MENU) {
|
||
PartPlateList &plate_list = p->get_partplate_list();
|
||
PartPlate * plate = plate_list.get_curr_plate();
|
||
bool plate_same_as_global = true;
|
||
params.is_seq_print = plate->get_real_print_seq(&plate_same_as_global) == PrintSequence::ByObject;
|
||
// if plate's print sequence is not the same as global, the settings.distance is no longer valid, we set it to auto
|
||
if (!plate_same_as_global)
|
||
params.min_obj_distance = 0;
|
||
}
|
||
|
||
if (params.is_seq_print) {
|
||
params.min_obj_distance = std::max(params.min_obj_distance, scaled(params.cleareance_radius + 0.001)); // +0.001mm to avoid clearance check fail due to rounding error
|
||
params.bed_shrink_x = BED_SHRINK_SEQ_PRINT;
|
||
params.bed_shrink_y = BED_SHRINK_SEQ_PRINT;
|
||
}
|
||
return params;
|
||
}
|
||
|
||
}} // namespace Slic3r::GUI
|