ENH: dual_extruder: add logic to process extruder_printable_area

JIRA: STUDIO-7498
Change-Id: I1cf53db93acf41b06cb1b9569a0679487c9f1e41
(cherry picked from commit e5be69dedd1ba6dc289a14b89598c9a6101dacb3)
This commit is contained in:
lane.wei 2024-08-30 21:13:16 +08:00 committed by Noisyfox
parent e433e49e2f
commit f702ad9fd2
20 changed files with 339 additions and 76 deletions

View file

@ -2645,7 +2645,7 @@ void PartPlate::generate_exclude_polygon(ExPolygon &exclude_polygon)
exclude_polygon.contour.make_counter_clockwise();
}
bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Vec2d position, float height_to_lid, float height_to_rod)
bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, const std::vector<Pointfs>& extruder_areas, Vec2d position, float height_to_lid, float height_to_rod)
{
Pointfs new_shape, new_exclude_areas;
for (const Vec2d& p : shape) {
@ -2655,6 +2655,18 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Ve
for (const Vec2d& p : exclude_areas) {
new_exclude_areas.push_back(Vec2d(p.x() + position.x(), p.y() + position.y()));
}
std::vector<Pointfs> new_extruder_areas;
for (const Pointfs& shape : extruder_areas) {
Pointfs new_extruder_area;
for (const Vec2d& p : shape) {
Vec2d point(p(0) + position.x(), p(1) + position.y());
new_extruder_area.push_back(point);
}
new_extruder_areas.push_back(new_extruder_area);
}
m_extruder_areas = std::move(new_extruder_areas);
if ((m_shape == new_shape)&&(m_exclude_area == new_exclude_areas)
&&(m_height_to_lid == height_to_lid)&&(m_height_to_rod == height_to_rod)) {
BOOST_LOG_TRIVIAL(info) << "PartPlate same shape, skip directly";
@ -3629,7 +3641,7 @@ void PartPlateList::reset_size(int width, int depth, int height, bool reload_obj
m_plate_height = height;
update_all_plates_pos_and_size(false, false, true);
if (update_shapes) {
set_shapes(m_shape, m_exclude_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
set_shapes(m_shape, m_exclude_areas, m_extruder_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
}
if (reload_objects)
reload_all_objects();
@ -3714,7 +3726,7 @@ void PartPlateList::reinit()
//reset plate 0's position
Vec2d pos = compute_shape_position(0, m_plate_cols);
m_plate_list[0]->set_shape(m_shape, m_exclude_areas, pos, m_height_to_lid, m_height_to_rod);
m_plate_list[0]->set_shape(m_shape, m_exclude_areas, m_extruder_areas, pos, m_height_to_lid, m_height_to_rod);
//reset unprintable plate's position
Vec3d origin2 = compute_origin_for_unprintable();
unprintable_plate.set_pos_and_size(origin2, m_plate_width, m_plate_depth, m_plate_height, false);
@ -3764,7 +3776,7 @@ int PartPlateList::create_plate(bool adjust_position)
plate->set_index(new_index);
Vec2d pos = compute_shape_position(new_index, cols);
plate->set_shape(m_shape, m_exclude_areas, pos, m_height_to_lid, m_height_to_rod);
plate->set_shape(m_shape, m_exclude_areas, m_extruder_areas, pos, m_height_to_lid, m_height_to_rod);
m_plate_list.emplace_back(plate);
update_plate_cols();
if (old_cols != cols)
@ -3772,7 +3784,7 @@ int PartPlateList::create_plate(bool adjust_position)
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":old_cols %1% -> new_cols %2%") % old_cols % cols;
//update the origin of each plate
update_all_plates_pos_and_size(adjust_position, false);
set_shapes(m_shape, m_exclude_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
set_shapes(m_shape, m_exclude_areas, m_extruder_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
if (m_plater) {
Vec2d pos = compute_shape_position(m_current_plate, cols);
@ -3943,7 +3955,7 @@ int PartPlateList::delete_plate(int index)
//update render shapes
Vec2d pos = compute_shape_position(i, m_plate_cols);
plate->set_shape(m_shape, m_exclude_areas, pos, m_height_to_lid, m_height_to_rod);
plate->set_shape(m_shape, m_exclude_areas, m_extruder_areas, pos, m_height_to_lid, m_height_to_rod);
}
//update current_plate if delete current
@ -3966,7 +3978,7 @@ int PartPlateList::delete_plate(int index)
{
//update the origin of each plate
update_all_plates_pos_and_size();
set_shapes(m_shape, m_exclude_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
set_shapes(m_shape, m_exclude_areas, m_extruder_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
}
else
{
@ -5063,11 +5075,12 @@ void PartPlateList::select_plate_view()
m_plater->get_camera().select_view("topfront");
}
bool PartPlateList::set_shapes(const Pointfs& shape, const Pointfs& exclude_areas, const std::string& texture_filename, float height_to_lid, float height_to_rod)
bool PartPlateList::set_shapes(const Pointfs& shape, const Pointfs& exclude_areas, const std::vector<Pointfs>& extruder_areas, const std::string& texture_filename, float height_to_lid, float height_to_rod)
{
const std::lock_guard<std::mutex> local_lock(m_plates_mutex);
m_shape = shape;
m_exclude_areas = exclude_areas;
m_extruder_areas = extruder_areas;
m_height_to_lid = height_to_lid;
m_height_to_rod = height_to_rod;
@ -5081,7 +5094,7 @@ bool PartPlateList::set_shapes(const Pointfs& shape, const Pointfs& exclude_area
Vec2d pos;
pos = compute_shape_position(i, m_plate_cols);
plate->set_shape(shape, exclude_areas, pos, height_to_lid, height_to_rod);
plate->set_shape(shape, exclude_areas, extruder_areas, pos, height_to_lid, height_to_rod);
}
is_load_bedtype_textures = false; //reload textures
calc_bounding_boxes();
@ -5260,7 +5273,7 @@ int PartPlateList::rebuild_plates_after_deserialize(std::vector<bool>& previous_
}
update_plate_cols();
update_all_plates_pos_and_size(false, false, false, false);
set_shapes(m_shape, m_exclude_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
set_shapes(m_shape, m_exclude_areas, m_extruder_areas, m_logo_texture_filename, m_height_to_lid, m_height_to_rod);
for (unsigned int i = 0; i < (unsigned int)m_plate_list.size(); ++i)
{
bool need_reset_print = false;
@ -5592,7 +5605,7 @@ int PartPlateList::load_gcode_files()
//BoundingBoxf3 print_volume = m_plate_list[i]->get_bounding_box(false);
//print_volume.max(2) = this->m_plate_height;
//print_volume.min(2) = -1e10;
m_model->update_print_volume_state({m_plate_list[i]->get_shape(), (double)this->m_plate_height });
m_model->update_print_volume_state({m_plate_list[i]->get_shape(), (double)this->m_plate_height, m_plate_list[i]->get_extruder_areas() });
if (!m_plate_list[i]->load_gcode_from_file(m_plate_list[i]->m_gcode_path_from_3mf))
ret ++;