FIX: unassigned initial extruder ignored

from BambuStudio
This commit is contained in:
SoftFever 2024-06-15 20:14:48 +08:00
parent 50e8e90dc8
commit 85d88e68be

View file

@ -25,14 +25,20 @@ const static bool g_wipe_into_objects = false;
// Shortest hamilton path problem // Shortest hamilton path problem
static std::vector<unsigned int> solve_extruder_order(const std::vector<std::vector<float>>& wipe_volumes, std::vector<unsigned int> all_extruders, unsigned int start_extruder_id) static std::vector<unsigned int> solve_extruder_order(const std::vector<std::vector<float>>& wipe_volumes, std::vector<unsigned int> all_extruders, std::optional<unsigned int> start_extruder_id)
{ {
auto start_iter = std::find(all_extruders.begin(), all_extruders.end(), start_extruder_id);
bool add_start_extruder_flag = false; bool add_start_extruder_flag = false;
if (start_extruder_id) {
auto start_iter = std::find(all_extruders.begin(), all_extruders.end(), start_extruder_id);
if (start_iter == all_extruders.end()) if (start_iter == all_extruders.end())
all_extruders.insert(all_extruders.begin(), start_extruder_id), add_start_extruder_flag = true; all_extruders.insert(all_extruders.begin(), *start_extruder_id), add_start_extruder_flag = true;
else else
std::swap(*all_extruders.begin(), *start_iter); std::swap(*all_extruders.begin(), *start_iter);
}
else {
*start_extruder_id = all_extruders.front();
}
unsigned int iterations = (1 << all_extruders.size()); unsigned int iterations = (1 << all_extruders.size());
unsigned int final_state = iterations - 1; unsigned int final_state = iterations - 1;
@ -84,7 +90,7 @@ static std::vector<unsigned int> solve_extruder_order(const std::vector<std::vec
return path; return path;
} }
std::vector<unsigned int> get_extruders_order(const std::vector<std::vector<float>> &wipe_volumes, std::vector<unsigned int> all_extruders, unsigned int start_extruder_id) std::vector<unsigned int> get_extruders_order(const std::vector<std::vector<float>> &wipe_volumes, std::vector<unsigned int> all_extruders, std::optional<unsigned int>start_extruder_id)
{ {
#define USE_DP_OPTIMIZE #define USE_DP_OPTIMIZE
#ifdef USE_DP_OPTIMIZE #ifdef USE_DP_OPTIMIZE
@ -123,7 +129,6 @@ if (all_extruders.size() > 1) {
#endif // OPTIMIZE #endif // OPTIMIZE
} }
// Returns true in case that extruder a comes before b (b does not have to be present). False otherwise. // Returns true in case that extruder a comes before b (b does not have to be present). False otherwise.
bool LayerTools::is_extruder_order(unsigned int a, unsigned int b) const bool LayerTools::is_extruder_order(unsigned int a, unsigned int b) const
{ {
@ -838,10 +843,12 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume()
wipe_volumes.push_back(std::vector<float>(number_of_extruders, print_config->prime_volume)); wipe_volumes.push_back(std::vector<float>(number_of_extruders, print_config->prime_volume));
} }
auto extruders_to_hash_key = [](const std::vector<unsigned int>& extruders, unsigned int initial_extruder_id)->uint32_t { auto extruders_to_hash_key = [](const std::vector<unsigned int>& extruders,
std::optional<unsigned int> initial_extruder_id) -> uint32_t {
uint32_t hash_key = 0; uint32_t hash_key = 0;
// high 16 bit define initial extruder ,low 16 bit define extruder set // high 16 bit define initial extruder ,low 16 bit define extruder set
hash_key |= (1 << (16 + initial_extruder_id)); if (initial_extruder_id)
hash_key |= (1 << (16 + *initial_extruder_id));
for (auto item : extruders) for (auto item : extruders)
hash_key |= (1 << item); hash_key |= (1 << item);
return hash_key; return hash_key;
@ -868,7 +875,7 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume()
return false; return false;
}; };
unsigned int current_extruder_id = -1; std::optional<unsigned int>current_extruder_id;
for (int i = 0; i < m_layer_tools.size(); ++i) { for (int i = 0; i < m_layer_tools.size(); ++i) {
LayerTools& lt = m_layer_tools[i]; LayerTools& lt = m_layer_tools[i];
if (lt.extruders.empty()) if (lt.extruders.empty())