Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jan 8, 2024
2 parents dcada9f + 1b4d227 commit 05af3be
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 105 deletions.
10 changes: 5 additions & 5 deletions resources/data/hints.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Settings highlight (like search feature)
# hypertext_type = settings
# hypertext_settings_opt = name_of_settings (hover over settings value and copy last line of hover text)
# hypertext_settings_type = 1 (1 - 5 according to settings tab - to be channged to name of tabs instead of numbers)
# hypertext_settings_type = print ( {print, filament, sla_print, sla_material, printer} according to settings tab)
# hypertext_settings_category = Infill (name of panel - written on left in settings)
#
# Plater top toolbar highlight
Expand Down Expand Up @@ -67,7 +67,7 @@
text = Fuzzy skin\nDid you know that you can create rough fibre-like texture on the sides of your models using the<a>Fuzzy skin</a>feature? You can also use modifiers to apply fuzzy-skin only to a portion of your model.
hypertext_type = settings
hypertext_settings_opt = fuzzy_skin
hypertext_settings_type = 1
hypertext_settings_type = print
hypertext_settings_category = Layers and perimeters
disabled_tags = SLA

Expand Down Expand Up @@ -118,7 +118,7 @@ text = Set number of instances\nDid you know that you can right-click a model an
text = Combine infill\nDid you know that you can print the infill with a higher layer height compared to perimeters to save print time using the setting<a>Combine infill every</a>.
hypertext_type = settings
hypertext_settings_opt = infill_every_layers
hypertext_settings_type = 1
hypertext_settings_type = print
hypertext_settings_category = Infill
disabled_tags = SLA; simple

Expand All @@ -142,7 +142,7 @@ disabled_tags = SLA
text = Solid infill threshold area\nDid you know that you can make parts of your model with a small cross-section be filled with solid infill automatically? Set the<a>Solid infill threshold area</a>. (Expert mode only.)
hypertext_type = settings
hypertext_settings_opt = solid_infill_below_area
hypertext_settings_type = 1
hypertext_settings_type = print
hypertext_settings_category = Infill
enabled_tags = FFF; expert

Expand Down Expand Up @@ -207,7 +207,7 @@ hypertext_menubar_item_name = &Configuration Snapshots
text = Minimum shell thickness\nDid you know that instead of the number of top and bottom layers, you can define the<a>Minimum shell thickness</a>in millimeters? This feature is especially useful when using the variable layer height function.
hypertext_type = settings
hypertext_settings_opt = top_solid_min_thickness
hypertext_settings_type = 1
hypertext_settings_type = print
hypertext_settings_category = Layers and perimeters
disabled_tags = SLA

Expand Down
2 changes: 1 addition & 1 deletion resources/ui_layout/default/print.ui
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ group:sidetext_width$5:Infill angle
end_line
line:Modifiers
setting:label_width$6:width$5:label$increment:fill_angle_increment
setting:label_width$6:width$5:label$increment:fill_angle_cross
setting:width$5:fill_angle_cross
vector_line:fill_angle_template
# setting:fill_angle_template
group:sidetext_width$5:Advanced
Expand Down
5 changes: 5 additions & 0 deletions src/libslic3r/ExtrusionEntityCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class ExtrusionEntityCollection : public ExtrusionEntity
return *this;
}
~ExtrusionEntityCollection() override { clear(); }
// move all entitites from src into this
void append_move_from(ExtrusionEntityCollection &src) {
m_entities.insert(m_entities.end(), src.m_entities.begin(), src.m_entities.end());
src.m_entities.clear();
}

/// Operator to convert and flatten this collection to a single vector of ExtrusionPaths.
explicit operator ExtrusionPaths() const;
Expand Down
6 changes: 3 additions & 3 deletions src/libslic3r/Format/3mf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2934,7 +2934,7 @@ namespace Slic3r {
}
} else {
std::string value = config.opt_serialize(opt_key);
if (!value.empty()) {
if (!value.empty() || opt_key.find("_pattern") == std::string::npos) {
pt::ptree& opt_tree = range_tree.add("option", value);
opt_tree.put("<xmlattr>.opt_key", opt_key);
} else {
Expand Down Expand Up @@ -3160,7 +3160,7 @@ namespace Slic3r {
} else {
for (const std::string& key : obj->config.keys()) {
std::string value = obj->config.opt_serialize(key);
if (!value.empty()) {
if (!value.empty() || key.find("_pattern") == std::string::npos) {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << OBJECT_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n";
} else {
std::ofstream log("ERROR_FILE_TO_SEND_TO_MERILL_PLZZZZ.txt", std::ios_base::app);
Expand Down Expand Up @@ -3268,7 +3268,7 @@ namespace Slic3r {
for (const std::string& key : volume->config.keys()) {
//stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << volume->config.opt_serialize(key) << "\"/>\n";
std::string value = volume->config.opt_serialize(key);
if (!value.empty() && key.find("pattern") == std::string::npos) {
if (!value.empty() || key.find("_pattern") == std::string::npos) {
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n";
} else {
std::ofstream log("ERROR_FILE_TO_SEND_TO_MERILL_PLZZZZ.txt", std::ios_base::app);
Expand Down
129 changes: 54 additions & 75 deletions src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
#endif

namespace Slic3r {

//struct CollectionSimplifyVisitor : public ExtrusionVisitor
//{
// ExtrusionEntityCollection *previous = nullptr;
// virtual void default_use(ExtrusionEntity& entity) override {};
// virtual void use(ExtrusionEntityCollection &coll) override
// {
// if (previous && coll.entities().size() == 1) {
// previous->append_move_from(coll);
// } else {
// ExtrusionEntityCollection *old_previous = previous;
// previous = &coll;
// for (size_t i = 0; i < coll.entities().size(); ++i) { coll.set_entities()[i]->visit(*this); }
// previous = old_previous;
// }
// }
//};


PerimeterGeneratorLoops get_all_Childs(PerimeterGeneratorLoop loop) {
PerimeterGeneratorLoops ret;
for (PerimeterGeneratorLoop &child : loop.children) {
Expand Down Expand Up @@ -348,8 +367,10 @@ ProcessSurfaceResult PerimeterGenerator::process_arachne(int& loop_number, const
std::unordered_map<const Arachne::ExtrusionLine*, size_t> map_extrusion_to_idx;
for (size_t idx = 0; idx < all_extrusions.size(); idx++)
map_extrusion_to_idx.emplace(all_extrusions[idx], idx);

auto extrusions_constrains = Arachne::WallToolPaths::getRegionOrder(all_extrusions, this->config->external_perimeters_first);

//TODO: order extrusion for contour/hole separatly
bool reverse_order = this->config->external_perimeters_first || this->object_config->brim_width.value > 0 || this->object_config->brim_width_interior.value > 0;
auto extrusions_constrains = Arachne::WallToolPaths::getRegionOrder(all_extrusions, reverse_order);
for (auto [before, after] : extrusions_constrains) {
auto after_it = map_extrusion_to_idx.find(after);
++blocked[after_it->second];
Expand All @@ -360,7 +381,7 @@ ProcessSurfaceResult PerimeterGenerator::process_arachne(int& loop_number, const
Point current_position = all_extrusions.empty() ? Point::Zero() : all_extrusions.front()->junctions.front().p; // Some starting position.
std::vector<PerimeterGeneratorArachneExtrusion> ordered_extrusions; // To store our result in. At the end we'll std::swap.
ordered_extrusions.reserve(all_extrusions.size());

while (ordered_extrusions.size() < all_extrusions.size()) {
size_t best_candidate = 0;
double best_distance_sqr = std::numeric_limits<double>::max();
Expand Down Expand Up @@ -1598,6 +1619,19 @@ ProcessSurfaceResult PerimeterGenerator::process_classic(int& loop_number, const
#if _DEBUG
peri_entities.visit(LoopAssertVisitor{});
#endif
// remove the un-needed top collection if only one child.
//peri_entities.visit(CollectionSimplifyVisitor{});
if (peri_entities.entities().size() == 1) {
if (ExtrusionEntityCollection *coll_child = dynamic_cast<ExtrusionEntityCollection *>(
peri_entities.set_entities().front());
coll_child != nullptr) {
peri_entities.set_can_sort_reverse(coll_child->can_sort(), coll_child->can_reverse());
peri_entities.append_move_from(*coll_child);
peri_entities.remove(0);
}
}


//{
// static int aodfjiaqsdz = 0;
// std::stringstream stri;
Expand All @@ -1613,69 +1647,6 @@ ProcessSurfaceResult PerimeterGenerator::process_classic(int& loop_number, const
// svg.Close();
//}


// if brim will be printed, reverse the order of perimeters so that
// we continue inwards after having finished the brim
// be careful to not print thin walls before perimeters (gapfill will be added after so don't worry for them)
// TODO: add test for perimeter order
const bool brim_first_layer = this->layer->id() == 0 && (this->object_config->brim_width.value > 0 || this->object_config->brim_width_interior.value > 0);
if (this->config->external_perimeters_first || brim_first_layer) {
if (this->config->external_perimeters_nothole.value || brim_first_layer) {
if (this->config->external_perimeters_hole.value || brim_first_layer) {
//reverse only not-thin wall
ExtrusionEntityCollection coll2;
for (const ExtrusionEntity* loop : peri_entities.entities()) {
if ( (loop->is_loop() && loop->role() != erThinWall)) {
coll2.append(*loop);
}
}
coll2.reverse();
for (const ExtrusionEntity* loop : peri_entities.entities()) {
if (!((loop->is_loop() && loop->role() != erThinWall))) {
coll2.append(*loop);
}
}
//note: this hacky thing is possible because coll2.entities contains in fact peri_entities's entities
//if you does peri_entities = coll2, you'll delete peri_entities's entities() and then you have nothing.
peri_entities = std::move(coll2);
} else {
//reverse only not-hole perimeters
ExtrusionEntityCollection coll2;
for (const ExtrusionEntity* loop : peri_entities.entities()) {
if ((loop->is_loop() && loop->role() != erThinWall) && !(((ExtrusionLoop*)loop)->loop_role() & ExtrusionLoopRole::elrHole) != 0) {
coll2.append(*loop);
}
}
coll2.reverse();
for (const ExtrusionEntity* loop : peri_entities.entities()) {
if (!((loop->is_loop() && loop->role() != erThinWall) && !(((ExtrusionLoop*)loop)->loop_role() & ExtrusionLoopRole::elrHole) != 0)) {
coll2.append(*loop);
}
}
//note: this hacky thing is possible because coll2.entities contains in fact entities's entities
//if you does peri_entities = coll2, you'll delete peri_entities's entities and then you have nothing.
peri_entities = std::move(coll2);
}
} else if (this->config->external_perimeters_hole.value) {
//reverse the hole, and put them in first place.
ExtrusionEntityCollection coll2;
for (const ExtrusionEntity* loop : peri_entities.entities()) {
if ((loop->is_loop() && loop->role() != erThinWall) && (((ExtrusionLoop*)loop)->loop_role() & ExtrusionLoopRole::elrHole) != 0) {
coll2.append(*loop);
}
}
coll2.reverse();
for (const ExtrusionEntity* loop : peri_entities.entities()) {
if (!((loop->is_loop() && loop->role() != erThinWall) && (((ExtrusionLoop*)loop)->loop_role() & ExtrusionLoopRole::elrHole) != 0)) {
coll2.append(*loop);
}
}
//note: this hacky thing is possible because coll2.entities contains in fact peri_entities's entities
//if you does peri_entities = coll2, you'll delete peri_entities's entities and then you have nothing.
peri_entities = std::move(coll2);
}

}
// append perimeters for this slice as a collection
if (!peri_entities.empty()) {
//move it, to avoid to clone evrything and then delete it
Expand Down Expand Up @@ -2651,6 +2622,13 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(
if (idx.first >= loops.size())
better_chain.push_back(idx);
}

// if brim will be printed, reverse the order of perimeters so that
// we continue inwards after having finished the brim
const bool reverse_contour = (this->layer->id() == 0 && this->object_config->brim_width.value > 0) ||
(this->config->external_perimeters_first.value && this->config->external_perimeters_nothole.value);
const bool reverse_hole = (this->layer->id() == 0 && this->object_config->brim_width_interior.value > 0) ||
(this->config->external_perimeters_first.value && this->config->external_perimeters_hole.value);

//move from coll to coll_out and getting children of each in the same time. (deep first)
for (const std::pair<size_t, bool> &idx : better_chain) {
Expand Down Expand Up @@ -2691,28 +2669,30 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(
assert(thin_walls.empty());
ExtrusionEntityCollection children = this->_traverse_loops(loop.children, thin_walls, has_overhang ? 1 : count_since_overhang < 0 ? -1 : (count_since_overhang+1));
coll[idx.first] = nullptr;
if (loop.is_contour) {
if ((loop.is_contour && !reverse_contour) || (!loop.is_contour && reverse_hole)) {
//note: this->layer->id() % 2 == 1 already taken into account in the is_steep_overhang compute (to save time).
if (loop.is_steep_overhang && this->layer->id() % 2 == 1)
// if contour: reverse if steep_overhang & odd. if hole: the opposite
if ((loop.is_steep_overhang && this->layer->id() % 2 == 1) == loop.is_contour)
eloop->make_clockwise();
else
eloop->make_counter_clockwise();
//ensure that our children are printed before us
if (!children.empty()) {
ExtrusionEntityCollection print_child_beforeplz;
print_child_beforeplz.set_can_sort_reverse(false, false);
if (children.entities().size() > 1) {
if (children.entities().size() > 1 && (children.can_reverse() || children.can_sort())) {
print_child_beforeplz.append(children);
} else {
print_child_beforeplz.append(std::move(children.entities()));
print_child_beforeplz.append_move_from(children);
}
print_child_beforeplz.append(*eloop);
coll_out.append(std::move(print_child_beforeplz));
} else {
coll_out.append(*eloop);
}
} else {
if (loop.is_steep_overhang && this->layer->id() % 2 == 1)
// if hole: reverse if steep_overhang & odd. if contour: the opposite
if ((loop.is_steep_overhang && this->layer->id() % 2 == 1) != loop.is_contour)
eloop->make_counter_clockwise();
else
eloop->make_clockwise();
Expand All @@ -2721,10 +2701,10 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(
ExtrusionEntityCollection print_child_beforeplz;
print_child_beforeplz.set_can_sort_reverse(false, false);
print_child_beforeplz.append(*eloop);
if (children.entities().size() > 1) {
if (children.entities().size() > 1 && (children.can_reverse() || children.can_sort())) {
print_child_beforeplz.append(children);
} else {
print_child_beforeplz.append(std::move(children.entities()));
print_child_beforeplz.append_move_from(children);
}
coll_out.append(std::move(print_child_beforeplz));
} else {
Expand Down Expand Up @@ -2778,7 +2758,7 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_extrusions(std::vector<P
ClipperLib_Z::Path extrusion_path;
extrusion_path.reserve(extrusion->size());
for (const Arachne::ExtrusionJunction& ej : extrusion->junctions) {
//remove duplicate poitns from arachne
//remove duplicate points from arachne
if(extrusion_path.empty() ||
(ej.p.x() != extrusion_path.back().x() || ej.p.y() != extrusion_path.back().y()))
extrusion_path.emplace_back(ej.p.x(), ej.p.y(), ej.w);
Expand Down Expand Up @@ -3016,7 +2996,6 @@ void PerimeterGenerator::_merge_thin_walls(ExtrusionEntityCollection &extrusions
current_loop = last_loop;
}
virtual void use(ExtrusionEntityCollection &collection) override {
collection.set_can_sort_reverse(true, true);
//for each loop? (or other collections)
for (ExtrusionEntity *entity : collection.entities())
entity->visit(*this);
Expand Down
14 changes: 14 additions & 0 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,20 @@ std::string Preset::type_name(Type t) {
}
}

Preset::Type Preset::type_from_name(std::string name) {
if ("print" == name)
return Preset::TYPE_FFF_PRINT;
if ("filament" == name)
return Preset::TYPE_FFF_FILAMENT;
if ("sla_print" == name)
return Preset::TYPE_SLA_PRINT;
if ("sla_material" == name)
return Preset::TYPE_SLA_MATERIAL;
if ("printer" == name)
return Preset::TYPE_PRINTER;
return Preset::TYPE_INVALID;
}

std::string PresetCollection::section_name() const
{
return Preset::type_name(this->type());
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/Preset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Preset
return PrinterTechnology::ptUnknown;
}
static std::string type_name(Type t);
static Type type_from_name(std::string name);

Type type = TYPE_INVALID;

Expand Down
Loading

0 comments on commit 05af3be

Please sign in to comment.