#ifndef MutableItemTraits_HPP #define MutableItemTraits_HPP #include #include #include namespace Slic3r { namespace arr2 { template struct IsMutableItem_ : public std::false_type {}; // Using this interface to set up any arrange item. Provides default // implementation but it needs to be explicitly switched on with // IsMutableItem_ or completely reimplement a specialization. template struct MutableItemTraits_ { static_assert(IsMutableItem_::value, "Not a Writable item type!"); static void set_priority(Itm &itm, int p) { itm.set_priority(p); } static void set_convex_shape(Itm &itm, const Polygon &shape) { itm.set_convex_shape(shape); } static void set_shape(Itm &itm, const ExPolygons &shape) { itm.set_shape(shape); } static void set_convex_envelope(Itm &itm, const Polygon &envelope) { itm.set_convex_envelope(envelope); } static void set_envelope(Itm &itm, const ExPolygons &envelope) { itm.set_envelope(envelope); } template static void set_arbitrary_data(Itm &itm, const std::string &key, T &&data) { if constexpr (IsWritableDataStore) set_data(itm, key, std::forward(data)); } static void set_allowed_rotations(Itm &itm, const std::vector &rotations) { itm.set_allowed_rotations(rotations); } }; template using MutableItemTraits = MutableItemTraits_>; template constexpr bool IsMutableItem = IsMutableItem_::value; template using MutableItemOnly = std::enable_if_t, TT>; template void set_priority(Itm &itm, int p) { MutableItemTraits::set_priority(itm, p); } template void set_convex_shape(Itm &itm, const Polygon &shape) { MutableItemTraits::set_convex_shape(itm, shape); } template void set_shape(Itm &itm, const ExPolygons &shape) { MutableItemTraits::set_shape(itm, shape); } template void set_convex_envelope(Itm &itm, const Polygon &envelope) { MutableItemTraits::set_convex_envelope(itm, envelope); } template void set_envelope(Itm &itm, const ExPolygons &envelope) { MutableItemTraits::set_envelope(itm, envelope); } template void set_arbitrary_data(Itm &itm, const std::string &key, T &&data) { MutableItemTraits::set_arbitrary_data(itm, key, std::forward(data)); } template void set_allowed_rotations(Itm &itm, const std::vector &rotations) { MutableItemTraits::set_allowed_rotations(itm, rotations); } template int raise_priority(ArrItem &itm) { int ret = get_priority(itm) + 1; set_priority(itm, ret); return ret; } template int reduce_priority(ArrItem &itm) { int ret = get_priority(itm) - 1; set_priority(itm, ret); return ret; } template int lowest_priority(const Range &item_range) { auto minp_it = std::min_element(item_range.begin(), item_range.end(), [](auto &itm1, auto &itm2) { return get_priority(itm1) < get_priority(itm2); }); int min_priority = 0; if (minp_it != item_range.end()) min_priority = get_priority(*minp_it); return min_priority; } }} // namespace Slic3r::arr2 #endif // MutableItemTraits_HPP