ENH: wipe_tower: use uniform wipe tower logic for cli and gui

jira: no-jira
Change-Id: I179212585871071cd17bd37c2756444a2d7aba1f
(cherry picked from commit 1f3dde94980d3685bb4d1266e8a5448b8f231b9f)
This commit is contained in:
lane.wei
2025-03-08 16:29:58 +08:00
committed by Noisyfox
parent c8484d99d6
commit 6f2f8c584e
5 changed files with 156 additions and 117 deletions

View File

@@ -1790,7 +1790,7 @@ bool PartPlate::check_mixture_of_pla_and_petg(const DynamicPrintConfig &config)
return true;
}
Vec3d PartPlate::calculate_wipe_tower_size(const DynamicPrintConfig &config, const double w, const double wipe_volume, int plate_extruder_size, bool use_global_objects) const
/*Vec3d PartPlate::calculate_wipe_tower_size(const DynamicPrintConfig &config, const double w, const double wipe_volume, int plate_extruder_size, bool use_global_objects) const
{
Vec3d wipe_tower_size;
double layer_height = 0.08f; // hard code layer height
@@ -1810,7 +1810,7 @@ Vec3d PartPlate::calculate_wipe_tower_size(const DynamicPrintConfig &config, con
if (!use_global_objects && !contain_instance_totally(obj_idx, 0))
continue;
BoundingBoxf3 bbox = m_model->objects[obj_idx]->bounding_box_exact();
BoundingBoxf3 bbox = m_model->objects[obj_idx]->bounding_box();
max_height = std::max(bbox.size().z(), max_height);
}
wipe_tower_size(2) = max_height;
@@ -1827,53 +1827,66 @@ Vec3d PartPlate::calculate_wipe_tower_size(const DynamicPrintConfig &config, con
}
return wipe_tower_size;
}
}*/
Vec3d PartPlate::estimate_wipe_tower_size(const DynamicPrintConfig & config, const double w, const double d, int plate_extruder_size, bool use_global_objects) const
Vec3d PartPlate::estimate_wipe_tower_size(const DynamicPrintConfig & config, const double w, const double d, int extruder_count, int plate_extruder_size, bool use_global_objects) const
{
Vec3d wipe_tower_size;
Vec3d wipe_tower_size;
double layer_height = 0.08f; // hard code layer height
double max_height = 0.f;
wipe_tower_size.setZero();
double layer_height = 0.08f; // hard code layer height
double max_height = 0.f;
wipe_tower_size.setZero();
wipe_tower_size(0) = w;
const ConfigOption* layer_height_opt = config.option("layer_height");
if (layer_height_opt)
layer_height = layer_height_opt->getFloat();
const ConfigOption* layer_height_opt = config.option("layer_height");
if (layer_height_opt)
layer_height = layer_height_opt->getFloat();
// empty plate
if (plate_extruder_size == 0)
// empty plate
if (plate_extruder_size == 0)
{
std::vector<int> plate_extruders = get_extruders(true);
plate_extruder_size = plate_extruders.size();
}
if (plate_extruder_size == 0)
return wipe_tower_size;
if (plate_extruder_size == 0)
return wipe_tower_size;
for (int obj_idx = 0; obj_idx < m_model->objects.size(); obj_idx++) {
if (!use_global_objects && !contain_instance_totally(obj_idx, 0))
continue;
for (int obj_idx = 0; obj_idx < m_model->objects.size(); obj_idx++) {
if (!use_global_objects && !contain_instance_totally(obj_idx, 0))
continue;
BoundingBoxf3 bbox = m_model->objects[obj_idx]->bounding_box_exact();
max_height = std::max(bbox.size().z(), max_height);
}
wipe_tower_size(2) = max_height;
max_height = std::max(bbox.size().z(), max_height);
}
wipe_tower_size(2) = max_height;
//const DynamicPrintConfig &dconfig = wxGetApp().preset_bundle->prints.get_edited_preset().config;
//const DynamicPrintConfig &dconfig = wxGetApp().preset_bundle->prints.get_edited_preset().config;
auto timelapse_type = config.option<ConfigOptionEnum<TimelapseType>>("timelapse_type");
bool timelapse_enabled = timelapse_type ? (timelapse_type->value == TimelapseType::tlSmooth) : false;
double extra_spacing = config.option("prime_tower_infill_gap")->getFloat() / 100.;
double depth = plate_extruder_size == 1 ? 0 : d*extra_spacing;
if (timelapse_enabled || depth > EPSILON) {
float min_wipe_tower_depth = WipeTower::get_limit_depth_by_height(max_height);
depth = std::max((double)min_wipe_tower_depth, depth);
}
wipe_tower_size(1) = depth;
return wipe_tower_size;
const ConfigOptionBool* use_rib_wall_opt = config.option<ConfigOptionBool>("prime_tower_rib_wall");
bool use_rib_wall = use_rib_wall_opt ? use_rib_wall_opt->value: true;
double depth;
if (use_rib_wall) {
depth = std::sqrt(d * w * (extruder_count == 2 ? plate_extruder_size : (plate_extruder_size - 1)) * extra_spacing);
if (timelapse_enabled || plate_extruder_size > 1) {
float min_wipe_tower_depth = WipeTower::get_limit_depth_by_height(max_height);
depth = std::max((double) min_wipe_tower_depth, depth);
wipe_tower_size(0) = wipe_tower_size(1) = depth;
}
}
else {
depth = plate_extruder_size == 1 ? 0 : d*extra_spacing;
if (timelapse_enabled || depth > EPSILON) {
float min_wipe_tower_depth = WipeTower::get_limit_depth_by_height(max_height);
depth = std::max((double)min_wipe_tower_depth, depth);
}
wipe_tower_size(0) = w;
wipe_tower_size(1) = depth;
}
return wipe_tower_size;
}
arrangement::ArrangePolygon PartPlate::estimate_wipe_tower_polygon(const DynamicPrintConfig& config, int plate_index, int plate_extruder_size, bool use_global_objects) const
arrangement::ArrangePolygon PartPlate::estimate_wipe_tower_polygon(const DynamicPrintConfig& config, int plate_index, Vec3d& wt_pos, Vec3d& wt_size, int extruder_count, int plate_extruder_size, bool use_global_objects) const
{
float x = dynamic_cast<const ConfigOptionFloats*>(config.option("wipe_tower_x"))->get_at(plate_index);
float y = dynamic_cast<const ConfigOptionFloats*>(config.option("wipe_tower_y"))->get_at(plate_index);
@@ -1881,19 +1894,22 @@ arrangement::ArrangePolygon PartPlate::estimate_wipe_tower_polygon(const Dynamic
//float a = dynamic_cast<const ConfigOptionFloat*>(config.option("wipe_tower_rotation_angle"))->value;
std::vector<double> v = dynamic_cast<const ConfigOptionFloats*>(config.option("filament_prime_volume"))->values;
float tower_brim_width = dynamic_cast<const ConfigOptionFloat*>(config.option("prime_tower_brim_width"))->value;
Vec3d wipe_tower_size = estimate_wipe_tower_size(config, w, get_max_element(v), plate_extruder_size, use_global_objects);
wt_size = estimate_wipe_tower_size(config, w, get_max_element(v), extruder_count, plate_extruder_size, use_global_objects);
int plate_width=m_width, plate_depth=m_depth;
float depth = wipe_tower_size(1);
float depth = wt_size(1);
float margin = WIPE_TOWER_MARGIN + tower_brim_width, wp_brim_width = 0.f;
const ConfigOption* wipe_tower_brim_width_opt = config.option("prime_tower_brim_width");
if (wipe_tower_brim_width_opt) {
wp_brim_width = wipe_tower_brim_width_opt->getFloat();
if (wp_brim_width < 0) wp_brim_width = WipeTower::get_auto_brim_by_height((float) wipe_tower_size.z());
if (wp_brim_width < 0) wp_brim_width = WipeTower::get_auto_brim_by_height((float) wt_size.z());
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("arrange wipe_tower: wp_brim_width %1%") % wp_brim_width;
}
x = std::clamp(x, margin, (float)plate_width - w - margin - wp_brim_width);
y = std::clamp(y, margin, (float)plate_depth - depth - margin - wp_brim_width);
wt_pos(0) = x;
wt_pos(1) = y;
wt_pos(2) = 0.f;
arrangement::ArrangePolygon wipe_tower_ap;
Polygon ap({