ENH: disable arranging selected items

0. disable arranging selected
1. fix bug where brim is not correct.
2. fix bug where big circle objects are not arranged properly
3. disable default enable_rotation

Change-Id: Ifc69f35d900ff63ec1e9ec8bf8638afc6ea7d54b
(cherry picked from commit 2ed1b0dd8573a1e10aaf77f0d9f8896cef304427)
This commit is contained in:
Arthur 2022-08-02 14:18:20 +08:00 committed by Lane.Wei
parent 74e92ac51d
commit 07ae246e5f
9 changed files with 77 additions and 31 deletions

View file

@ -203,6 +203,20 @@ public:
inline Unit area() const BP2D_NOEXCEPT { inline Unit area() const BP2D_NOEXCEPT {
return Unit(width())*height(); return Unit(width())*height();
} }
_Box intersection(_Box other) {
_Box inter;
inter.p1.x() = std::max(p1.x(), other.p1.x());
inter.p1.y() = std::max(p1.y(), other.p1.y());
inter.p2.x() = std::min(p2.x(), other.p2.x());
inter.p2.y() = std::min(p2.y(), other.p2.y());
inter.defined = true;
if (inter.p2.y() < inter.p1.y() || inter.p2.x() < inter.p1.x()) {
inter.p2 = inter.p1;
inter.defined = false;
}
return inter;
}
static inline _Box infinite(const P &center = {TCoord<P>(0), TCoord<P>(0)}); static inline _Box infinite(const P &center = {TCoord<P>(0), TCoord<P>(0)});
}; };

View file

@ -1083,9 +1083,13 @@ private:
auto d = cb - ci; auto d = cb - ci;
// BBS TODO we assume the exclude region contains bottom left corner. If not, change the code below // BBS TODO we assume the exclude region contains bottom left corner. If not, change the code below
if (!config_.m_excluded_regions.empty()) { if (!config_.m_excluded_regions.empty()) { // do not move to left to much to avoid clash with excluded regions
d.x() = d.x() < 0 ? 0 : d.x(); if (d.x() < 0) {
d.y() = d.y() < 0 ? 0 : d.y(); d.x() = 0;// std::max(long(d.x()), long(bbin.maxCorner().x() - bb.maxCorner().x()));
}
if (d.y() < 0) {
d.y() = 0;// std::max(long(d.y()), long(bbin.maxCorner().y() - bb.maxCorner().y()));
}
} }
for(Item& item : items_) for(Item& item : items_)
if (!item.is_virt_object) if (!item.is_virt_object)

View file

@ -136,6 +136,25 @@ static double fixed_overfit(const std::tuple<double, Box>& result, const Box &bi
return score; return score;
} }
// useful for arranging big circle objects
static double fixed_overfit_topright_sliding(const std::tuple<double, Box>& result, const Box& binbb)
{
double score = std::get<0>(result);
Box pilebb = std::get<1>(result);
auto shift = binbb.maxCorner() - pilebb.maxCorner();
shift.x() = std::max(0, shift.x()); // do not allow left shift
shift.y() = std::max(0, shift.y()); // do not allow bottom shift
pilebb.minCorner() += shift;
pilebb.maxCorner() += shift;
Box fullbb = sl::boundingBox(pilebb, binbb);
auto diff = double(fullbb.area()) - binbb.area();
if (diff > 0) score += diff;
return score;
}
// A class encapsulating the libnest2d Nester class and extending it with other // A class encapsulating the libnest2d Nester class and extending it with other
// management and spatial index structures for acceleration. // management and spatial index structures for acceleration.
template<class TBin> template<class TBin>
@ -503,8 +522,9 @@ public:
break; break;
} }
} }
cfg.object_function = [this, bb, starting_point](const Item& item) { cfg.object_function = [this, bb, starting_point](const Item& item) {
return fixed_overfit(objfunc(item, starting_point), bb); return fixed_overfit_topright_sliding(objfunc(item, starting_point), bb);
}; };
}; };

View file

@ -65,8 +65,7 @@ struct ArrangePolygon {
int itemid{ 0 }; // item id in the vector, used for accessing all possible params like extrude_id int itemid{ 0 }; // item id in the vector, used for accessing all possible params like extrude_id
int is_applied{ 0 }; // transform has been applied int is_applied{ 0 }; // transform has been applied
double height{ 0 }; // item height double height{ 0 }; // item height
double auto_brim_width{ 0 }; // auto brim width double brim_width{ 0 }; // brim width
double user_brim_width{ 0 }; // user defined brim width
std::string name; std::string name;
// If empty, any rotation is allowed (currently unsupported) // If empty, any rotation is allowed (currently unsupported)

View file

@ -2885,6 +2885,14 @@ double getTemperatureFromExtruder(const ModelVolumePtrs objectVolumes) {
#endif #endif
} }
double ModelInstance::get_auto_brim_width() const
{
double adhcoeff = getadhesionCoeff(object->volumes);
double DeltaT = getTemperatureFromExtruder(object->volumes);
// get auto brim width (Note even if the global brim_type=btOuterBrim, we can still go into this branch)
return get_auto_brim_width(DeltaT, adhcoeff);
}
void ModelInstance::get_arrange_polygon(void* ap) const void ModelInstance::get_arrange_polygon(void* ap) const
{ {
// static const double SIMPLIFY_TOLERANCE_MM = 0.1; // static const double SIMPLIFY_TOLERANCE_MM = 0.1;
@ -2924,18 +2932,6 @@ void ModelInstance::get_arrange_polygon(void* ap) const
ret.extrude_ids = volume->get_extruders(); ret.extrude_ids = volume->get_extruders();
if (ret.extrude_ids.empty()) //the default extruder if (ret.extrude_ids.empty()) //the default extruder
ret.extrude_ids.push_back(1); ret.extrude_ids.push_back(1);
// get user specified brim width per object
// Note: if global brim_type=btNoBrim or brAutoBrim, user can't set individual brim_width
if (object->config.has("brim_width"))
ret.user_brim_width = object->config.opt_float("brim_width");
else {
// BBS: get DeltaT, adhcoeff before calculating brim width
double adhcoeff = getadhesionCoeff(object->volumes);
double DeltaT = getTemperatureFromExtruder(object->volumes);
// get auto brim width (Note even if the global brim_type=btOuterBrim, we can still go into this branch)
ret.auto_brim_width = get_auto_brim_width(DeltaT, adhcoeff);
}
} }
indexed_triangle_set FacetsAnnotation::get_facets(const ModelVolume& mv, EnforcerBlockerType type) const indexed_triangle_set FacetsAnnotation::get_facets(const ModelVolume& mv, EnforcerBlockerType type) const

View file

@ -297,6 +297,12 @@ public:
const Model* get_model() const { return m_model; } const Model* get_model() const { return m_model; }
// BBS: production extension // BBS: production extension
int get_backup_id() const; int get_backup_id() const;
template<typename T> const T* get_config_value(const DynamicPrintConfig& global_config, const std::string& config_option) {
if (config.has(config_option))
return static_cast<const T*>(config.option(config_option));
else
return global_config.option<T>(config_option);
}
ModelVolume* add_volume(const TriangleMesh &mesh); ModelVolume* add_volume(const TriangleMesh &mesh);
ModelVolume* add_volume(TriangleMesh &&mesh, ModelVolumeType type = ModelVolumeType::MODEL_PART); ModelVolume* add_volume(TriangleMesh &&mesh, ModelVolumeType type = ModelVolumeType::MODEL_PART);
@ -1083,6 +1089,7 @@ public:
//BBS //BBS
double get_auto_brim_width(double deltaT, double adhension) const; double get_auto_brim_width(double deltaT, double adhension) const;
double get_auto_brim_width() const;
// BBS // BBS
Polygon convex_hull_2d(); Polygon convex_hull_2d();
void invalidate_convex_hull_2d(); void invalidate_convex_hull_2d();

View file

@ -144,8 +144,22 @@ ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const Slic3r::
for (int i = 0; i < BedType::btCount; i++) for (int i = 0; i < BedType::btCount; i++)
ap.vitrify_temp += tmp * pow(100, BedType::btCount - i - 1); ap.vitrify_temp += tmp * pow(100, BedType::btCount - i - 1);
} }
ap.height = instance->get_object()->bounding_box().size().z();
ap.name = instance->get_object()->name; // get brim width
auto obj = instance->get_object();
ap.brim_width = instance->get_auto_brim_width();
auto brim_type_ptr = obj->get_config_value<ConfigOptionEnum<BrimType>>(config, "brim_type");
if (brim_type_ptr) {
auto brim_type = brim_type_ptr->getInt();
if (brim_type == btOuterOnly)
ap.brim_width = obj->get_config_value<ConfigOptionFloat>(config, "brim_width")->getFloat();
else if (brim_type == btNoBrim)
ap.brim_width = 0;
}
ap.height = obj->bounding_box().size().z();
ap.name = obj->name;
return ap; return ap;
} }

View file

@ -361,7 +361,7 @@ public:
// float distance_seq_print = 6.; // Used when sequential print is ON // float distance_seq_print = 6.; // Used when sequential print is ON
// float distance_sla = 6.; // float distance_sla = 6.;
float accuracy = 0.65f; // Unused currently float accuracy = 0.65f; // Unused currently
bool enable_rotation = true; bool enable_rotation = false;
bool allow_multi_materials_on_same_plate = true; bool allow_multi_materials_on_same_plate = true;
bool avoid_extrusion_cali_region = true; bool avoid_extrusion_cali_region = true;
//BBS: add more arrangeSettings //BBS: add more arrangeSettings

View file

@ -403,7 +403,7 @@ void ArrangeJob::prepare()
int state = m_plater->get_prepare_state(); int state = m_plater->get_prepare_state();
if (state == Job::JobPrepareState::PREPARE_STATE_DEFAULT) { if (state == Job::JobPrepareState::PREPARE_STATE_DEFAULT) {
only_on_partplate = false; only_on_partplate = false;
prepare_selected(); prepare_all();
} }
else if (state == Job::JobPrepareState::PREPARE_STATE_MENU) { else if (state == Job::JobPrepareState::PREPARE_STATE_MENU) {
only_on_partplate = true; // only arrange items on current plate only_on_partplate = true; // only arrange items on current plate
@ -508,16 +508,8 @@ void ArrangeJob::process()
double skirt_distance = print.has_skirt() ? print.config().skirt_distance.value : 0; double skirt_distance = print.has_skirt() ? print.config().skirt_distance.value : 0;
bool is_auto_brim = print.has_auto_brim();
double brim_max = 0; double brim_max = 0;
if (is_auto_brim) { std::for_each(m_selected.begin(), m_selected.end(), [&](ArrangePolygon ap) { brim_max = std::max(brim_max, ap.brim_width); });
brim_max = 0;
std::for_each(m_selected.begin(), m_selected.end(), [&](ArrangePolygon ap) { brim_max = std::max(brim_max, ap.auto_brim_width); });
}
else {
brim_max = print.has_brim() ? print.default_object_config().brim_width : 0;
std::for_each(m_selected.begin(), m_selected.end(), [&](ArrangePolygon ap) { brim_max = std::max(brim_max, ap.user_brim_width); });
}
// Note: skirt_distance is now defined between outermost brim and skirt, not the object and skirt. // Note: skirt_distance is now defined between outermost brim and skirt, not the object and skirt.
// So we can't do max but do adding instead. // So we can't do max but do adding instead.