ENH: support delete any filament id

Change-Id: I71bcd54985b3f9e19a19d04327d00b402ec22380
(cherry picked from commit f3d67a98ac770e6f045a76bed4531139763b33cf)
This commit is contained in:
zhimin.zeng
2024-06-20 13:09:51 +08:00
committed by Noisyfox
parent 84dc2d8835
commit fe09c20725
13 changed files with 287 additions and 43 deletions

View File

@@ -38,7 +38,7 @@ namespace Slic3r {
// Forward declarations.
class GCode;
namespace { struct Item; }
namespace CustomGCode{ struct Item; }
struct PrintInstance;
class ConstPrintObjectPtrsAdaptor;

View File

@@ -2481,6 +2481,17 @@ void ModelVolume::update_extruder_count(size_t extruder_count)
}
}
void ModelVolume::update_extruder_count_when_delete_filament(size_t extruder_count, size_t filament_id)
{
std::vector<int> used_extruders = get_extruders();
for (int extruder_id : used_extruders) {
if (extruder_id == filament_id) {
mmu_segmentation_facets.set_enforcer_block_type_limit(*this, (EnforcerBlockerType)(extruder_count + 1), (EnforcerBlockerType) filament_id);
break;
}
}
}
void ModelVolume::center_geometry_after_creation(bool update_source_offset)
{
Vec3d shift = this->mesh().bounding_box().center();
@@ -3375,10 +3386,10 @@ void FacetsAnnotation::get_facets(const ModelVolume& mv, std::vector<indexed_tri
selector.get_facets(facets_per_type);
}
void FacetsAnnotation::set_enforcer_block_type_limit(const ModelVolume& mv, EnforcerBlockerType max_type)
void FacetsAnnotation::set_enforcer_block_type_limit(const ModelVolume &mv, EnforcerBlockerType max_type, EnforcerBlockerType to_delete_filament)
{
TriangleSelector selector(mv.mesh());
selector.deserialize(m_data, false, max_type);
selector.deserialize(m_data, false, max_type, to_delete_filament);
this->set(selector);
}

View File

@@ -734,7 +734,7 @@ public:
indexed_triangle_set get_facets(const ModelVolume& mv, EnforcerBlockerType type) const;
// BBS
void get_facets(const ModelVolume& mv, std::vector<indexed_triangle_set>& facets_per_type) const;
void set_enforcer_block_type_limit(const ModelVolume& mv, EnforcerBlockerType max_type);
void set_enforcer_block_type_limit(const ModelVolume& mv, EnforcerBlockerType max_type, EnforcerBlockerType to_delete_filament = EnforcerBlockerType::NONE);
indexed_triangle_set get_facets_strict(const ModelVolume& mv, EnforcerBlockerType type) const;
bool has_facets(const ModelVolume& mv, EnforcerBlockerType type) const;
bool empty() const { return m_data.triangles_to_split.empty(); }
@@ -915,6 +915,7 @@ public:
// BBS
std::vector<int> get_extruders() const;
void update_extruder_count(size_t extruder_count);
void update_extruder_count_when_delete_filament(size_t extruder_count, size_t filament_id);
// Split this volume, append the result to the object owning this volume.
// Return the number of volumes created from this one.

View File

@@ -1881,6 +1881,30 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
update_multi_material_filament_presets();
}
void PresetBundle::update_num_filaments(unsigned int to_del_flament_id)
{
int old_filament_count = this->filament_presets.size();
assert(to_del_flament_id < old_filament_count);
filament_presets.erase(filament_presets.begin() + to_del_flament_id);
ConfigOptionStrings *filament_color = project_config.option<ConfigOptionStrings>("filament_colour");
if (filament_color->values.size() > to_del_flament_id) {
filament_color->values.erase(filament_color->values.begin() + to_del_flament_id);
}
else {
filament_color->values.resize(to_del_flament_id);
}
if (ams_multi_color_filment.size() > to_del_flament_id){
ams_multi_color_filment.erase(ams_multi_color_filment.begin() + to_del_flament_id);
}
else {
ams_multi_color_filment.resize(to_del_flament_id);
}
update_multi_material_filament_presets(to_del_flament_id);
}
unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
{
std::vector<std::string> filament_presets;
@@ -3182,7 +3206,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
return std::make_pair(std::move(substitutions), presets_loaded);
}
void PresetBundle::update_multi_material_filament_presets()
void PresetBundle::update_multi_material_filament_presets(size_t to_delete_filament_id)
{
if (printers.get_edited_preset().printer_technology() != ptFFF)
return;
@@ -3200,6 +3224,8 @@ void PresetBundle::update_multi_material_filament_presets()
#else
size_t num_filaments = this->filament_presets.size();
#endif
if (to_delete_filament_id == -1)
to_delete_filament_id = num_filaments;
// Now verify if flush_volumes_matrix has proper size (it is used to deduce number of extruders in wipe tower generator):
std::vector<double> old_matrix = this->project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values;
@@ -3218,38 +3244,24 @@ void PresetBundle::update_multi_material_filament_presets()
filaments.pop_back();
}
if (nozzle_nums > 1) {
size_t old_matrix_size = old_number_of_filaments * old_number_of_filaments;
size_t new_matrix_size = num_filaments * num_filaments;
std::vector<double> new_matrix(new_matrix_size * nozzle_nums, 0);
for (unsigned int i = 0; i < num_filaments; ++i)
for (unsigned int j = 0; j < num_filaments; ++j) {
if (i < old_number_of_filaments && j < old_number_of_filaments) {
for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) {
new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = old_matrix[i * old_number_of_filaments + j + old_matrix_size * nozzle_id];
}
size_t old_matrix_size = old_number_of_filaments * old_number_of_filaments;
size_t new_matrix_size = num_filaments * num_filaments;
std::vector<double> new_matrix(new_matrix_size * nozzle_nums, 0);
for (unsigned int i = 0; i < num_filaments; ++i)
for (unsigned int j = 0; j < num_filaments; ++j) {
if (i < old_number_of_filaments && j < old_number_of_filaments) {
unsigned int old_i = i >= to_delete_filament_id ? i + 1 : i;
unsigned int old_j = j >= to_delete_filament_id ? j + 1 : j;
for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) {
new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = old_matrix[old_i * old_number_of_filaments + old_j + old_matrix_size * nozzle_id];
}
else {
for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) {
new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = (i == j ? 0. : filaments[2 * i] + filaments[2 * j + 1]);
}
} else {
for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) {
new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = (i == j ? 0. : filaments[2 * i] + filaments[2 * j + 1]);
}
}
this->project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values = new_matrix;
}
else {
std::vector<double> new_matrix;
for (unsigned int i = 0; i < num_filaments; ++i)
for (unsigned int j = 0; j < num_filaments; ++j) {
// append the value for this pair from the old matrix (if it's there):
if (i < old_number_of_filaments && j < old_number_of_filaments)
new_matrix.push_back(old_matrix[i * old_number_of_filaments + j]);
else
new_matrix.push_back(i == j ? 0. : filaments[2 * i] + filaments[2 * j + 1]); // so it matches new extruder volumes
}
this->project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values = new_matrix;
}
}
this->project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values = new_matrix;
}
}

View File

@@ -115,6 +115,7 @@ public:
// BBS
void set_num_filaments(unsigned int n, std::vector<std::string> new_colors);
void set_num_filaments(unsigned int n, std::string new_col = "");
void update_num_filaments(unsigned int to_del_flament_id);
unsigned int sync_ams_list(unsigned int & unknowns);
//BBS: check whether this is the only edited filament
bool is_the_only_edited_filament(unsigned int filament_index);
@@ -244,7 +245,7 @@ public:
// Read out the number of extruders from an active printer preset,
// update size and content of filament_presets.
void update_multi_material_filament_presets();
void update_multi_material_filament_presets(size_t to_delete_filament_id = size_t(-1));
// Update the is_compatible flag of all print and filament presets depending on whether they are marked
// as compatible with the currently selected printer (and print in case of filament presets).

View File

@@ -1720,7 +1720,7 @@ TriangleSelector::TriangleSplittingData TriangleSelector::serialize() const {
return out.data;
}
void TriangleSelector::deserialize(const TriangleSplittingData& data, bool needs_reset, EnforcerBlockerType max_ebt)
void TriangleSelector::deserialize(const TriangleSplittingData& data, bool needs_reset, EnforcerBlockerType max_ebt, EnforcerBlockerType to_delete_filament)
{
if (needs_reset)
reset(); // dump any current state
@@ -1772,6 +1772,10 @@ void TriangleSelector::deserialize(const TriangleSplittingData& data, bool needs
if (state > max_ebt)
state = EnforcerBlockerType::NONE;
if (to_delete_filament != EnforcerBlockerType::NONE && state != EnforcerBlockerType::NONE) {
state = state > to_delete_filament ? EnforcerBlockerType((int)state - 1) : state;
}
// Only valid if is_split.
int special_side = code >> 2;

View File

@@ -358,7 +358,8 @@ public:
// Load serialized data. Assumes that correct mesh is loaded.
void deserialize(const TriangleSplittingData& data,
bool needs_reset = true,
EnforcerBlockerType max_ebt = EnforcerBlockerType::ExtruderMax);
EnforcerBlockerType max_ebt = EnforcerBlockerType::ExtruderMax,
EnforcerBlockerType to_delete_filament = EnforcerBlockerType::NONE);
// Extract all used facet states from the given TriangleSplittingData.
static std::vector<EnforcerBlockerType> extract_used_facet_states(const TriangleSplittingData &data);