diff --git a/src/libnest2d/include/libnest2d/nester.hpp b/src/libnest2d/include/libnest2d/nester.hpp index 7529444ad..68141c9b4 100644 --- a/src/libnest2d/include/libnest2d/nester.hpp +++ b/src/libnest2d/include/libnest2d/nester.hpp @@ -76,7 +76,8 @@ class _Item { public: int itemid_{ 0 }; std::vector extrude_ids; - int filament_temp_type = -1; // -1 means unset. otherwise should be {0,1,2} + std::vector filament_types{}; /// filament type for different material judge + int filament_temp_type = -1; // -1 means unset. otherwise should be one of FilamentTempType ie {0,1,2} double height{ 0 }; double print_temp{ 0 }; double bed_temp{ 0 }; diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 8480cbbc5..301f38b08 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -549,14 +549,23 @@ protected: } std::set extruder_ids; + std::set tpu_extruder_ids; for (int i = 0; i < m_items.size(); i++) { Item& p = m_items[i]; if (p.is_virt_object) continue; extruder_ids.insert(p.extrude_ids.begin(),p.extrude_ids.end()); + for (int j = 0; j < p.extrude_ids.size(); j++) { + if (p.filament_types[j] == "TPU") tpu_extruder_ids.insert(p.extrude_ids[j]); + } + } + for (int j = 0; j < item.extrude_ids.size(); j++) { + if (item.filament_types[j] == "TPU") tpu_extruder_ids.insert(item.extrude_ids[j]); } + // do not allow more than 1 TPU extruder on same plate + if (tpu_extruder_ids.size() > 1) score += LARGE_COST_TO_REJECT; // add a large cost if not multi materials on same plate is not allowed - if (!params.allow_multi_materials_on_same_plate) { + else if (!params.allow_multi_materials_on_same_plate) { // it's the first object, which can be multi-color bool first_object = extruder_ids.empty(); // the two objects (previously packed items and the current item) are considered having same color if either one's colors are a subset of the other @@ -984,6 +993,7 @@ static void process_arrangeable(const ArrangePolygon &arrpoly, item.priority(arrpoly.priority); item.itemId(arrpoly.itemid); item.extrude_ids = arrpoly.extrude_ids; + item.filament_types = arrpoly.filament_types; item.height = arrpoly.height; item.name = arrpoly.name; //BBS: add virtual object logic diff --git a/src/libslic3r/Arrange.hpp b/src/libslic3r/Arrange.hpp index 98f938341..741d3b41d 100644 --- a/src/libslic3r/Arrange.hpp +++ b/src/libslic3r/Arrange.hpp @@ -62,6 +62,7 @@ struct ArrangePolygon { int row{0}; int col{0}; std::vector extrude_ids{}; /// extruder_id for least extruder switch + std::vector filament_types{}; /// filament type for different material judge int filament_temp_type{ -1 }; int bed_temp{0}; ///bed temperature for different material judge int print_temp{0}; ///print temperature for different material judge diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 84b376629..c215a9ff2 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -3952,6 +3952,11 @@ void ModelInstance::get_arrange_polygon(void *ap, const Slic3r::DynamicPrintConf // static const double SIMPLIFY_TOLERANCE_MM = 0.1; Geometry::Transformation trafo_instance = get_transformation(); + + //BOOST_LOG_TRIVIAL(debug) << "get_arrange_polygon: " << object->name << " instance trans:\n" + // << trafo_instance.get_matrix().matrix() << "\n object trans:\n" + // << object->volumes.front()->get_transformation().get_matrix().matrix(); + trafo_instance.set_offset(Vec3d(0, 0, get_offset(Z))); Polygon p = get_object()->convex_hull_2d(trafo_instance.get_matrix()); diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 4dbd43c3d..013446b48 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -668,6 +668,25 @@ inline std::string filter_characters(const std::string& str, const std::string& return filteredStr; } +// custom vector wrapper for outputting to log +template struct VectorFormatter +{ + const std::vector &vec; + + explicit VectorFormatter(const std::vector &v) : vec(v) {} + + friend std::ostream &operator<<(std::ostream &os, const VectorFormatter &vf) + { + os << "["; + for (size_t i = 0; i < vf.vec.size(); ++i) { + os << vf.vec[i]; + if (i != vf.vec.size() - 1) { os << ", "; } + } + os << "]"; + return os; + } +}; + } // namespace Slic3r #if WIN32 diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index a85331612..c59885827 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -100,8 +100,30 @@ void ArrangeJob::clear_input() ArrangePolygon ArrangeJob::prepare_arrange_polygon(void* model_instance) { ModelInstance* instance = (ModelInstance*)model_instance; - const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config(); - return get_instance_arrange_poly(instance, config); + auto preset_bundle = wxGetApp().preset_bundle; + const Slic3r::DynamicPrintConfig& config = preset_bundle->full_config(); + ArrangePolygon ap = get_instance_arrange_poly(instance, config); + + // get filament types such as PLA, ABS, etc. + ap.filament_types.clear(); + for (size_t i = 0; i < preset_bundle->filament_presets.size(); ++i) { + auto iter = std::find(ap.extrude_ids.begin(), ap.extrude_ids.end(), i + 1); + if (iter == ap.extrude_ids.end()) continue; + + std::string filament_name = preset_bundle->filament_presets[i]; + for (int f_index = 0; f_index < preset_bundle->filaments.size(); f_index++) { + PresetCollection *filament_presets = &preset_bundle->filaments; + Preset *preset = &filament_presets->preset(f_index); + int size = preset_bundle->filaments.size(); + if (preset && filament_name.compare(preset->name) == 0) { + std::string display_filament_type; + std::string filament_type = preset->config.get_filament_type(display_filament_type); + ap.filament_types.push_back(filament_type); + } + } + } + + return ap; } void ArrangeJob::prepare_selected() { @@ -633,7 +655,8 @@ void ArrangeJob::process() BOOST_LOG_TRIVIAL(warning)<< "Arrange full params: "<< params.to_json(); BOOST_LOG_TRIVIAL(info) << boost::format("arrange: items selected before arranging: %1%") % m_selected.size(); for (auto selected : m_selected) { - BOOST_LOG_TRIVIAL(debug) << selected.name << ", extruder: " << selected.extrude_ids.back() << ", bed: " << selected.bed_idx + BOOST_LOG_TRIVIAL(debug) << selected.name << ", extruder: " << VectorFormatter( selected.extrude_ids) + << ", filament types: " << VectorFormatter(selected.filament_types) << ", bed: " << selected.bed_idx << ", filemant_type:" << selected.filament_temp_type << ", trans: " << selected.translation.transpose() << ", rotation: " << selected.rotation; }