mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-26 23:29:14 +00:00
Merge branch 'main' into feature/mcp
This commit is contained in:
commit
df459143cc
75 changed files with 2483 additions and 403 deletions
|
|
@ -771,6 +771,14 @@ required by other styles (#23575)" (`docs/changes.txt:581`). Commit eefdabcd98 a
|
|||
gtk_window_begin_move_drag(GTK_WINDOW(m_frame->m_widget), 1, p.x, p.y, gtk_get_current_event_time());
|
||||
```
|
||||
Cite: `BBLTopbar::OnMouseLeftDown`; `ResizeEdgePanel::OnLeftDown` (`MainFrame.cpp`).
|
||||
- **Rule:** On X11, never move or resize a borderless frame that is maximized or fullscreen:
|
||||
`window_pos_restore` skips `SetSize` for a maximized save, and `window_pos_sanitize` returns early.
|
||||
**Why:** a client-side resize that lands on exactly the monitor rect counts as a legacy fullscreen
|
||||
request to Mutter/Muffin (`force_fullscreen` defaults on) for an undecorated window without
|
||||
`_GTK_FRAME_EXTENTS`, so the frame came up `_NET_WM_STATE_FULLSCREEN` and an auto-hide panel became
|
||||
unreachable (#17191). It needs a work area equal to the monitor to reproduce, i.e. a panel that
|
||||
reserves no strut. Windows and macOS keep that `SetSize`: it is what gives Restore Down a saved
|
||||
normal size.
|
||||
|
||||
### macOS: a native titled window
|
||||
|
||||
|
|
|
|||
|
|
@ -463,12 +463,14 @@ ignored (observed; recorded in `GUI_App::window_pos_restore`, not documented by
|
|||
|
||||
**OrcaSlicer geometry persistence.** Orca uses `AppConfig`, not `wxPersistentTLW`:
|
||||
`GUI_App::window_pos_save` / `window_pos_restore` / `window_pos_sanitize` / `window_pos_center` (key
|
||||
`window_<name>`, a `WindowMetrics` = screen rect + maximized; restore skips `SetPosition` on Wayland), and
|
||||
`on_window_geometry(tlw, callback)` (`GUI_Utils.cpp`) to run the callback when geometry is real — MSW
|
||||
immediately (no `wxEVT_SHOW` for windows created maximized), Linux on `wxEVT_SHOW` + `CallAfter`, macOS on
|
||||
`wxEVT_SHOW`. `GUI_App::persist_window_geometry(window, default_maximized)` saves on
|
||||
`wxEVT_CLOSE_WINDOW` (then `Skip()`) but always uses the key `window_mainframe`, whatever the window's
|
||||
name — for any other window call `window_pos_save/restore` with its own name.
|
||||
`window_<name>`, a `WindowMetrics` = screen rect + maximized; restore skips `SetPosition` on Wayland and,
|
||||
on X11, skips `SetSize` when the saved state is maximized; `window_pos_sanitize` returns early for a
|
||||
maximized or fullscreen window on X11), and `on_window_geometry(tlw, callback)` (`GUI_Utils.cpp`) to run
|
||||
the callback when geometry is real — MSW immediately (no `wxEVT_SHOW` for windows created maximized),
|
||||
Linux on `wxEVT_SHOW` + `CallAfter`, macOS on `wxEVT_SHOW`.
|
||||
`GUI_App::persist_window_geometry(window, default_maximized)` saves on
|
||||
`wxEVT_CLOSE_WINDOW` (then `Skip()`) and restores under the window's own name, so the main frame
|
||||
(`"mainframe"`) and the non-modal settings dialog (`"settings_dialog"`) keep separate entries.
|
||||
|
||||
**Pitfalls.**
|
||||
- **Rule:** When restoring a top-level window (the main frame after hiding a popup or overlay frame, or a
|
||||
|
|
|
|||
57
.github/workflows/see-guide-label.yml
vendored
Normal file
57
.github/workflows/see-guide-label.yml
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
name: See guide label
|
||||
|
||||
# Adds "wait for response" so stale.yml closes the PR if nothing changes.
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [labeled]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
concurrency:
|
||||
group: see-guide-label-${{ github.event.pull_request.number }}
|
||||
|
||||
jobs:
|
||||
comment:
|
||||
if: >-
|
||||
github.repository == 'OrcaSlicer/OrcaSlicer' &&
|
||||
github.event.pull_request.state == 'open' &&
|
||||
github.event.label.name == 'see guide'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Add the wait for response label and comment
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
NUMBER: ${{ github.event.pull_request.number }}
|
||||
AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||
LABEL: ${{ github.event.label.name }}
|
||||
run: |
|
||||
gh api "repos/$GITHUB_REPOSITORY/issues/$NUMBER/labels" -f "labels[]=wait for response" --silent
|
||||
|
||||
# Posts once per PR, so removing and adding the label again doesn't repeat the comment.
|
||||
marker='<!-- see-guide-label -->'
|
||||
if [ -n "$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$NUMBER/comments" \
|
||||
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id")" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cat > body.md <<'EOF'
|
||||
<!-- see-guide-label -->
|
||||
Hi @AUTHOR, thanks for the PR. A reviewer added the `LABEL` label. It means this PR doesn't follow the [contributing guide](https://github.com/OrcaSlicer/OrcaSlicer/blob/main/CONTRIBUTING.md#prs-we-dont-review) yet. A reviewer can look at it again after it is fixed.
|
||||
|
||||
If a reviewer left a comment on this PR, that comment says what to change. If there is no comment, check this list:
|
||||
|
||||
- The PR doesn't say how you tested it. For changes you can see in the app, add screenshots.
|
||||
- The description doesn't say what the change does or why it is needed.
|
||||
- The PR has unrelated changes, or it reformats existing code.
|
||||
- It replaces working code instead of changing only what needs to change.
|
||||
- It ports code that another project has not merged, or it doesn't link and credit the source.
|
||||
- Another PR already makes the same change. Say how yours is different, or test the other PR instead.
|
||||
|
||||
To fix it, push new commits to this PR or edit the description. Please don't open a new PR. Then write a comment that says what you changed. If you think the label is a mistake, reply and say why.
|
||||
|
||||
The `wait for response` label means we are waiting for you. If nothing happens on this PR, it may be closed.
|
||||
EOF
|
||||
sed -i "s/@AUTHOR/@$AUTHOR/; s/\`LABEL\`/\`$LABEL\`/" body.md
|
||||
gh api "repos/$GITHUB_REPOSITORY/issues/$NUMBER/comments" -F body=@body.md --silent
|
||||
|
|
@ -13,7 +13,8 @@ Opening an issue? See [Opening an Issue](https://www.orcaslicer.com/wiki/develop
|
|||
- Search open PRs and issues before you start. Someone may already be working on it.
|
||||
- Keep each PR to one topic. Put changes that belong together in one PR, and unrelated changes in separate PRs. Focused PRs are reviewed and merged much faster.
|
||||
- Don't open many PRs at once. If you already have several open, wait until some are merged.
|
||||
- Explain why the change is needed, and show how you tested it. Add an automated test when the code can be tested.
|
||||
- Change the code that needs it. Don't rewrite code that already works.
|
||||
- Build and run your change before you open the PR. Explain why the change is needed, and show how you tested it. Add screenshots of anything you can see in the app, and an automated test when the code can be tested.
|
||||
- AI tools are welcome. You are still responsible for the change, so test it and make sure you understand it.
|
||||
- Keep your PR up to date and reply to review comments.
|
||||
|
||||
|
|
@ -74,10 +75,11 @@ If you are an AI agent working for a contributor, please follow these steps:
|
|||
2. Search open PRs for the same change before you start.
|
||||
3. If the contributor already has several open PRs, wait until some are merged before you open another.
|
||||
4. Before you change code, check `.claude/skills/` for a skill that matches the change, and follow it.
|
||||
5. If the code can be tested, add an automated test, and check that it fails without the change and passes with it.
|
||||
6. Ask the contributor to test the change by hand. For a bug fix, they should build the code without the change and reproduce the bug. Then they should build the branch and check that the bug is gone.
|
||||
7. Write the PR description in the [PR template](.github/pull_request_template.md). A body passed with `gh pr create --body` replaces the template, so start from the template's text.
|
||||
8. If you couldn't build or run something, say so in the PR.
|
||||
5. Change only the code that needs it. Don't replace a working file or feature with a new version.
|
||||
6. If the code can be tested, add an automated test, and check that it fails without the change and passes with it.
|
||||
7. Ask the contributor to test the change by hand. For a bug fix, they should build the code without the change and reproduce the bug. Then they should build the branch and check that the bug is gone.
|
||||
8. Write the PR description in the [PR template](.github/pull_request_template.md). A body passed with `gh pr create --body` replaces the template, so start from the template's text.
|
||||
9. If you couldn't build or run something, say so in the PR.
|
||||
|
||||
## After you open the PR
|
||||
|
||||
|
|
@ -91,9 +93,20 @@ If you are an AI agent working for a contributor, please follow these steps:
|
|||
|
||||
Reviewers are volunteers, and a first response can take a while. If you already have several PRs open, please wait until some are merged before you open more. Review comments on one PR often apply to the others too. While you wait, there are [other ways to help](https://www.orcaslicer.com/wiki/developer_reference/how_to_contribute#other-ways-to-help).
|
||||
|
||||
## PRs we don't review
|
||||
|
||||
Reviewers won't review these PRs until they are fixed:
|
||||
|
||||
- **Untested PRs.** Build and run your change before you open the PR, and say how you tested it. For anything you can see in the app, add screenshots. A PR that was never built is not ready for review.
|
||||
- **PRs that don't explain the change.** Use the PR template. Say what the change does and why it is needed.
|
||||
- **PRs that mix unrelated changes.** Keep each PR to one topic. Don't reformat existing code or make unrelated edits.
|
||||
- **Rewrites of working code.** Change the part that needs to change. A PR that replaces a working file or feature with new code brings new bugs into code that works, and it is very hard to review. If you think a rewrite is needed, open an issue first and wait until a maintainer agrees.
|
||||
- **Unmerged code from other forks.** Only port code that the other project has merged. Check that its license allows it, link the source, and credit the original author. OrcaSlicer's code may have drifted from the other project, so a ported change may no longer be right here or may cause unexpected problems. Test it in OrcaSlicer like your own change.
|
||||
- **Duplicates.** If another PR already makes the same change, test it and comment there instead.
|
||||
|
||||
## If your PR is closed
|
||||
|
||||
There are more PRs than reviewers can handle, so we may close a PR that doesn't meet this guide. For example, it may have no explanation of how it was tested, duplicate another PR, or look generated and untested. When we close a PR, we'll say why in a comment.
|
||||
There are more PRs than reviewers can handle, so we may close a PR that doesn't meet this guide. When we close a PR, we'll say why in a comment.
|
||||
|
||||
You're welcome to open a new PR once the change meets this guide. Please link the old PR in the description, so reviewers can see the earlier discussion. Thank you for the time you put into it.
|
||||
|
||||
|
|
|
|||
|
|
@ -817,9 +817,18 @@ namespace Clipper2Lib {
|
|||
std::stable_sort(minima_list_.begin(), minima_list_.end(), LocMinSorter()); //#594
|
||||
minima_list_sorted_ = true;
|
||||
}
|
||||
LocalMinimaList::const_reverse_iterator i;
|
||||
for (i = minima_list_.rbegin(); i != minima_list_.rend(); ++i)
|
||||
InsertScanline((*i)->vertex->pt.y);
|
||||
// Orca: PopScanline() returns each pending y once, however many times it was inserted, so only the
|
||||
// distinct ys of the local minima are queued. Sorted by descending y they already form a max-heap;
|
||||
// inserting them one by one in ascending order made every insertion climb to the top of the heap.
|
||||
std::vector<int64_t> minima_ys;
|
||||
minima_ys.reserve(minima_list_.size());
|
||||
for (const LocalMinima_ptr& lm : minima_list_)
|
||||
if (minima_ys.empty() || minima_ys.back() != lm->vertex->pt.y)
|
||||
minima_ys.push_back(lm->vertex->pt.y);
|
||||
if (scanline_list_.empty())
|
||||
scanline_list_ = std::priority_queue<int64_t>(std::less<int64_t>(), std::move(minima_ys));
|
||||
else
|
||||
for (int64_t y : minima_ys) InsertScanline(y);
|
||||
|
||||
current_locmin_iter_ = minima_list_.begin();
|
||||
actives_ = nullptr;
|
||||
|
|
@ -883,7 +892,9 @@ namespace Clipper2Lib {
|
|||
|
||||
void ClipperBase::InsertScanline(int64_t y)
|
||||
{
|
||||
scanline_list_.push(y);
|
||||
// Orca: a y already at the top is popped together with this one anyway.
|
||||
if (scanline_list_.empty() || scanline_list_.top() != y)
|
||||
scanline_list_.push(y);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ as for predictable geometry.
|
|||
|
||||
## Vendored Clipper2
|
||||
|
||||
`deps_src/clipper2` builds the static target `Clipper2`. It carries five
|
||||
`deps_src/clipper2` builds the static target `Clipper2`. It carries six
|
||||
changes to the upstream sources that must be carried over when Clipper2 is
|
||||
updated. The namespace switch sits at the top of every header and source, the
|
||||
other four are marked with `Orca:` comments.
|
||||
other five are marked with `Orca:` comments.
|
||||
|
||||
| Change | Files | Why |
|
||||
| --- | --- | --- |
|
||||
|
|
@ -40,6 +40,7 @@ other four are marked with `Orca:` comments.
|
|||
| Engine nodes from tbbmalloc | `clipper.engine.h`, `clipper.engine.cpp` | Vertices, active edges, output points and records, local minima and `PolyTree` nodes are allocated one by one. `CLIPPER2_NODE_ALLOCATOR` routes them through `scalable_malloc`, because the default heap does not scale when all slicing threads clip at once. |
|
||||
| Concave joins at the edge crossing | `clipper.offset.cpp` | For closed paths, a concave corner is joined at the crossing of the two offset edges when that point lies within half of both adjacent edges. The upstream 3-point loop makes inward offsets of dense curves very slow to union. |
|
||||
| Rounded arc steps | `clipper.offset.cpp` | Round joins use the rounded number of steps, not the ceiling, which keeps the vertex count of round offsets that the rest of the code is tuned for. |
|
||||
| Distinct scan lines | `clipper.engine.cpp` | `Reset()` builds the scan line heap from the distinct y of the local minima in one pass, and `InsertScanline()` skips a y already at the top. Upstream inserts the minima one by one in ascending order, so each climbs to the top of the heap. Scan lines are popped in the same order either way. |
|
||||
| No intersection sort for edges in order | `clipper.engine.h`, `clipper.engine.cpp` | `AdjustCurrXAndCopyToSEL()` reports whether the active edges kept their order at the top of the scanbeam, and `BuildIntersectList()` returns before its merge sort when they did. Most scanbeams have no crossing, and the sort was a large part of every boolean on dense support layers. |
|
||||
|
||||
## ClipperUtils semantics
|
||||
|
|
|
|||
|
|
@ -119,6 +119,12 @@ draws while an object is dragged, measure the rise from the plate and apply only
|
|||
the nozzle cone and the head body. An object away from the toolhead, which only
|
||||
the rod or the lid can reach, is left to the precise check. The ring the user
|
||||
sees touches the object's outline exactly when the pre-slice check trips.
|
||||
Arrange and Fill bed follow the rule too: they keep objects the toolhead radius
|
||||
away from the tower, or only the nozzle cone when none of the objects they place
|
||||
is taller than the nozzle height, and keep those taller than the rod clearance
|
||||
out of its Y span. They measure the height from the plate. For the rod that is
|
||||
stricter than the precise check, which only refuses an object that rises past
|
||||
the rod clearance above the compacted tower.
|
||||
|
||||
## Merging sparse layers
|
||||
|
||||
|
|
@ -209,6 +215,11 @@ read as off rather than compacting or merging in one place and not another.
|
|||
- [GLCanvas3D.cpp](../../src/slic3r/GUI/GLCanvas3D.cpp) and
|
||||
[PartPlate.cpp](../../src/slic3r/GUI/PartPlate.cpp) draw the compacted tower's
|
||||
keep-out outlines live while the user drags.
|
||||
- [ArrangeJob.cpp](../../src/slic3r/GUI/Jobs/ArrangeJob.cpp) grows the tower's
|
||||
arrange polygon by the clearance that
|
||||
[Arrange.cpp](../../src/libslic3r/Arrange.cpp) picks for the objects being
|
||||
placed, and Arrange.cpp keeps objects taller than the rod clearance out of its
|
||||
Y span.
|
||||
- [Rule tests](../../tests/libslic3r/test_wipe_tower.cpp) cover the gating of
|
||||
both settings, the per-layer predicates, the compacted z, the merge rule's run
|
||||
flushing, height conservation, the nozzle cap and the first-layer exemption,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Creality",
|
||||
"version": "02.03.02.89",
|
||||
"version": "02.03.02.90",
|
||||
"force_update": "0",
|
||||
"description": "Creality configurations",
|
||||
"machine_model_list": [
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"bed_mesh_probe_distance": "50,50",
|
||||
"before_layer_change_gcode": ";BEFORE_LAYER_CHANGE\n;[layer_z]\nG92 E0\n",
|
||||
"best_object_pos": "0.5,0.5",
|
||||
"change_filament_gcode": "G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\nG1 X0 Y245 F30000\nG1 Z{z_after_toolchange} F600",
|
||||
"change_filament_gcode": "G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\nG1 X42 Y180 F30000\nG1 Z{z_after_toolchange} F600",
|
||||
"cooling_tube_length": "0",
|
||||
"cooling_tube_retraction": "0",
|
||||
"creality_flush_time": "119",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"bed_mesh_probe_distance": "50,50",
|
||||
"before_layer_change_gcode": ";BEFORE_LAYER_CHANGE\n;[layer_z]\nG92 E0\n",
|
||||
"best_object_pos": "0.5,0.5",
|
||||
"change_filament_gcode": "G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\nG1 X0 Y245 F30000\nG1 Z{z_after_toolchange} F600",
|
||||
"change_filament_gcode": "G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\nG1 X42 Y180 F30000\nG1 Z{z_after_toolchange} F600",
|
||||
"cooling_tube_length": "0",
|
||||
"cooling_tube_retraction": "0",
|
||||
"creality_flush_time": "119",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"bed_mesh_probe_distance": "50,50",
|
||||
"before_layer_change_gcode": ";BEFORE_LAYER_CHANGE\n;[layer_z]\nG92 E0\n",
|
||||
"best_object_pos": "0.5,0.5",
|
||||
"change_filament_gcode": "G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\nG1 X0 Y245 F30000\nG1 Z{z_after_toolchange} F600",
|
||||
"change_filament_gcode": "G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\nG1 X42 Y180 F30000\nG1 Z{z_after_toolchange} F600",
|
||||
"cooling_tube_length": "0",
|
||||
"cooling_tube_retraction": "0",
|
||||
"creality_flush_time": "119",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
|
@ -397,51 +398,87 @@ namespace detail {
|
|||
return eps;
|
||||
}
|
||||
|
||||
template<typename RayIntersectorType, typename Scalar>
|
||||
static inline bool intersect_ray_recursive_first_hit(
|
||||
RayIntersectorType &ray_intersector,
|
||||
size_t node_idx,
|
||||
Scalar min_t,
|
||||
igl::Hit<float> &hit)
|
||||
// ray_box_intersect_invdir() for a ray whose direction signs are known at compile time: NegX etc. tell
|
||||
// which slabs are entered through the max face. The comparisons select the same entry and exit parameters
|
||||
// as the early returns of ray_box_intersect_invdir() and give the same answer for any input, NaN included,
|
||||
// but without the unpredictable branches.
|
||||
template<bool NegX, bool NegY, bool NegZ, typename Scalar, typename VectorType, typename BoxScalar>
|
||||
inline bool ray_box_intersect_invdir_signs(
|
||||
const VectorType &origin,
|
||||
const VectorType &inv_dir,
|
||||
const Eigen::AlignedBox<BoxScalar,3> &box,
|
||||
const Scalar t0,
|
||||
const Scalar t1)
|
||||
{
|
||||
const auto &node = ray_intersector.tree.node(node_idx);
|
||||
assert(node.is_valid());
|
||||
|
||||
if (! ray_box_intersect_invdir(ray_intersector.origin, ray_intersector.invdir, node.bbox.template cast<Scalar>(), Scalar(0), min_t))
|
||||
return false;
|
||||
const Scalar tx0 = (Scalar(NegX ? box.max().x() : box.min().x()) - origin.x()) * inv_dir.x();
|
||||
const Scalar tx1 = (Scalar(NegX ? box.min().x() : box.max().x()) - origin.x()) * inv_dir.x();
|
||||
const Scalar ty0 = (Scalar(NegY ? box.max().y() : box.min().y()) - origin.y()) * inv_dir.y();
|
||||
const Scalar ty1 = (Scalar(NegY ? box.min().y() : box.max().y()) - origin.y()) * inv_dir.y();
|
||||
const Scalar tz0 = (Scalar(NegZ ? box.max().z() : box.min().z()) - origin.z()) * inv_dir.z();
|
||||
const Scalar tz1 = (Scalar(NegZ ? box.min().z() : box.max().z()) - origin.z()) * inv_dir.z();
|
||||
const Scalar txy_min = ty0 > tx0 ? ty0 : tx0;
|
||||
const Scalar txy_max = ty1 < tx1 ? ty1 : tx1;
|
||||
const Scalar tmin = tz0 > txy_min ? tz0 : txy_min;
|
||||
const Scalar tmax = tz1 < txy_max ? tz1 : txy_max;
|
||||
return tmin <= tmax && tmin < t1 && tmax > t0;
|
||||
}
|
||||
|
||||
if (node.is_leaf()) {
|
||||
// shoot ray, record hit
|
||||
auto face = ray_intersector.faces[node.idx];
|
||||
double t, u, v;
|
||||
if (intersect_triangle(
|
||||
ray_intersector.origin, ray_intersector.dir,
|
||||
ray_intersector.vertices[face(0)], ray_intersector.vertices[face(1)], ray_intersector.vertices[face(2)],
|
||||
t, u, v, ray_intersector.eps)
|
||||
&& t > 0.) {
|
||||
hit = igl::Hit<float> { int(node.idx), -1, float(u), float(v), float(t) };
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
} else {
|
||||
// Left / right child node index.
|
||||
size_t left = node_idx * 2 + 1;
|
||||
size_t right = left + 1;
|
||||
igl::Hit<float> left_hit;
|
||||
igl::Hit<float> right_hit;
|
||||
bool left_ret = intersect_ray_recursive_first_hit(ray_intersector, left, min_t, left_hit);
|
||||
if (left_ret && left_hit.t < min_t) {
|
||||
min_t = left_hit.t;
|
||||
hit = left_hit;
|
||||
} else
|
||||
left_ret = false;
|
||||
bool right_ret = intersect_ray_recursive_first_hit(ray_intersector, right, min_t, right_hit);
|
||||
if (right_ret && right_hit.t < min_t)
|
||||
hit = right_hit;
|
||||
else
|
||||
right_ret = false;
|
||||
return left_ret || right_ret;
|
||||
}
|
||||
// The depth-first, left to right search for the first hit, the nearest hit found so far bounding the ray
|
||||
// interval tested against the boxes. Iterative, with the ray direction signs resolved at compile time.
|
||||
template<bool NegX, bool NegY, bool NegZ, typename RayIntersectorType>
|
||||
static inline bool intersect_ray_first_hit_signs(const RayIntersectorType &ray_intersector, igl::Hit<float> &hit)
|
||||
{
|
||||
using Scalar = typename RayIntersectorType::VectorType::Scalar;
|
||||
const auto &nodes = ray_intersector.tree.nodes();
|
||||
Scalar min_t = std::numeric_limits<Scalar>::infinity();
|
||||
bool found = false;
|
||||
// Nodes waiting for their left sibling's subtree: at most one per level, plus the left sibling itself.
|
||||
size_t stack[65];
|
||||
size_t stack_size = 0;
|
||||
stack[stack_size ++] = 0;
|
||||
while (stack_size > 0) {
|
||||
const size_t node_idx = stack[-- stack_size];
|
||||
const auto &node = nodes[node_idx];
|
||||
assert(node.is_valid());
|
||||
if (! ray_box_intersect_invdir_signs<NegX, NegY, NegZ>(ray_intersector.origin, ray_intersector.invdir, node.bbox, Scalar(0), min_t))
|
||||
continue;
|
||||
if (node.is_leaf()) {
|
||||
auto face = ray_intersector.faces[node.idx];
|
||||
double t, u, v;
|
||||
// A leaf at the root has no parent to reject a hit beyond min_t.
|
||||
if (intersect_triangle(
|
||||
ray_intersector.origin, ray_intersector.dir,
|
||||
ray_intersector.vertices[face(0)], ray_intersector.vertices[face(1)], ray_intersector.vertices[face(2)],
|
||||
t, u, v, ray_intersector.eps)
|
||||
&& t > 0. && (float(t) < min_t || node_idx == 0)) {
|
||||
hit = igl::Hit<float> { int(node.idx), -1, float(u), float(v), float(t) };
|
||||
min_t = hit.t;
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
assert(stack_size + 2 <= std::size(stack));
|
||||
// Push the right child first, so that the left subtree is searched first.
|
||||
stack[stack_size ++] = node_idx * 2 + 2;
|
||||
stack[stack_size ++] = node_idx * 2 + 1;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
template<typename RayIntersectorType>
|
||||
static inline bool intersect_ray_first_hit_dispatch(const RayIntersectorType &ray_intersector, igl::Hit<float> &hit)
|
||||
{
|
||||
const auto &inv_dir = ray_intersector.invdir;
|
||||
switch (int(inv_dir.x() < 0) | (int(inv_dir.y() < 0) << 1) | (int(inv_dir.z() < 0) << 2)) {
|
||||
case 0: return intersect_ray_first_hit_signs<false, false, false>(ray_intersector, hit);
|
||||
case 1: return intersect_ray_first_hit_signs<true, false, false>(ray_intersector, hit);
|
||||
case 2: return intersect_ray_first_hit_signs<false, true, false>(ray_intersector, hit);
|
||||
case 3: return intersect_ray_first_hit_signs<true, true, false>(ray_intersector, hit);
|
||||
case 4: return intersect_ray_first_hit_signs<false, false, true >(ray_intersector, hit);
|
||||
case 5: return intersect_ray_first_hit_signs<true, false, true >(ray_intersector, hit);
|
||||
case 6: return intersect_ray_first_hit_signs<false, true, true >(ray_intersector, hit);
|
||||
default: return intersect_ray_first_hit_signs<true, true, true >(ray_intersector, hit);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename RayIntersectorType>
|
||||
|
|
@ -741,14 +778,12 @@ inline bool intersect_ray_first_hit(
|
|||
// Epsilon for the ray-triangle intersection, it should be proportional to an average triangle edge length.
|
||||
const double eps = 0.000001)
|
||||
{
|
||||
using Scalar = typename VectorType::Scalar;
|
||||
auto ray_intersector = detail::RayIntersector<VertexType, IndexedFaceType, TreeType, VectorType> {
|
||||
vertices, faces, tree,
|
||||
origin, dir, VectorType(dir.cwiseInverse()),
|
||||
eps
|
||||
};
|
||||
return ! tree.empty() && detail::intersect_ray_recursive_first_hit(
|
||||
ray_intersector, size_t(0), std::numeric_limits<Scalar>::infinity(), hit);
|
||||
return ! tree.empty() && detail::intersect_ray_first_hit_dispatch(ray_intersector, hit);
|
||||
}
|
||||
|
||||
// Find all intersections of a ray with indexed triangle set.
|
||||
|
|
|
|||
|
|
@ -334,6 +334,19 @@ void update_unselected_items_inflation(ArrangePolygons& unselected, const Dynami
|
|||
: (ap.is_extrusion_cali_object ? 0 : scale_(exclusion_gap)); });
|
||||
}
|
||||
|
||||
double compacted_tower_arrange_clearance(const ArrangePolygons& placed, const ArrangeParams& params, double toolhead_radius)
|
||||
{
|
||||
// The head body sits above the nozzle cone, so an object that rises no higher than nozzle_height
|
||||
// only has to clear the cone, as compacted_wipe_tower_clearance() decides. Arrange measures the
|
||||
// height from the plate, which is never less than the rise above the tower that check measures.
|
||||
// The tower is one polygon for every object placed, so a single taller one gives them all the
|
||||
// toolhead radius, and so does an empty list, whose objects are unknown.
|
||||
const bool all_short = !placed.empty() && std::all_of(placed.begin(), placed.end(), [¶ms](const ArrangePolygon& ap) {
|
||||
return ap.height <= params.nozzle_height + EPSILON;
|
||||
});
|
||||
return all_short ? double(MAX_OUTER_NOZZLE_DIAMETER) : toolhead_radius;
|
||||
}
|
||||
|
||||
void update_selected_items_axis_align(ArrangePolygons& selected, const DynamicPrintConfig* print_cfg, const ArrangeParams& params)
|
||||
{
|
||||
// now only need to consider "Align to x axis"
|
||||
|
|
@ -900,6 +913,22 @@ protected:
|
|||
score += height_score / valid_items_cnt;
|
||||
}
|
||||
|
||||
// Orca: the nozzle keeps coming down to a prime tower compacted by "No sparse layers", and
|
||||
// the rod then sweeps the tower's Y span over the whole bed, so nothing taller than the rod
|
||||
// clearance may share that span. Same test as compacted_wipe_tower_clearance().
|
||||
if (params.compacted_tower_growth >= 0 && item.height > params.clearance_height_to_rod) {
|
||||
const auto item_bb = item.boundingBox();
|
||||
const auto iy1 = item_bb.minCorner().y() + item.inflation();
|
||||
const auto iy2 = item_bb.maxCorner().y() - item.inflation();
|
||||
for (const Item& p : m_items) {
|
||||
if (!p.is_wipe_tower) continue;
|
||||
const auto tower_bb = p.boundingBox();
|
||||
const auto grown = p.inflation() + params.compacted_tower_growth;
|
||||
if (std::max(iy1, tower_bb.minCorner().y() + grown) - std::min(iy2, tower_bb.maxCorner().y() - grown) < scaled(params.clearance_dist_to_rod))
|
||||
score += LARGE_COST_TO_REJECT * 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
std::set<int> extruder_ids;
|
||||
for (int i = 0; i < m_items.size(); i++) {
|
||||
Item& p = m_items[i];
|
||||
|
|
@ -1247,6 +1276,15 @@ void _arrange(
|
|||
//sl::offset(corrected_bin, md);
|
||||
ArrangeParams mod_params = params;
|
||||
mod_params.min_obj_distance = 0; // items are already inflated
|
||||
// Orca: aligning the finished pile would carry objects taller than the rod clearance back into
|
||||
// the Y span of a compacted prime tower, which objfunc() has just kept them out of. A
|
||||
// best_object_pos away from the bed centre makes the AutoArranger align the pile to it whatever
|
||||
// do_final_align says, so that point goes back to the centre as well.
|
||||
if (params.compacted_tower_growth >= 0 &&
|
||||
std::any_of(shapes.begin(), shapes.end(), [¶ms](const Item &itm) { return itm.height > params.clearance_height_to_rod; })) {
|
||||
mod_params.do_final_align = false;
|
||||
mod_params.align_center = Vec2d(0.5, 0.5);
|
||||
}
|
||||
|
||||
AutoArranger<BinT> arranger{corrected_bin, mod_params, progressfn, stopfn};
|
||||
|
||||
|
|
|
|||
|
|
@ -156,6 +156,13 @@ struct ArrangeParams {
|
|||
float object_skirt_offset = 0;
|
||||
float nozzle_height = 0;
|
||||
float printable_height = 256.0;
|
||||
// Orca: whether the prime tower stays low because "No sparse layers" drops its sparse layers, on a
|
||||
// plate printed by layer: the condition the slicer's clearance check applies.
|
||||
bool compacted_tower = false;
|
||||
// Orca: how far (scaled) the polygon of such a tower was grown past the tower itself, or negative
|
||||
// when no tower was grown.
|
||||
coord_t compacted_tower_growth = -1;
|
||||
float clearance_dist_to_rod = 0;
|
||||
Vec2d align_center{ 0.5,0.5 };
|
||||
// Belt printer: items print in the order they lie along the belt axis, from
|
||||
// its low end unless belt_reversed, and a part's top prints
|
||||
|
|
@ -198,6 +205,7 @@ struct ArrangeParams {
|
|||
ret += "\"clearance_height_to_rod\":" + std::to_string(clearance_height_to_rod) + ",";
|
||||
ret += "\"clearance_height_to_lid\":" + std::to_string(clearance_height_to_lid) + ",";
|
||||
ret += "\"clearance_radius\":" + std::to_string(clearance_radius) + ",";
|
||||
ret += "\"compacted_tower_growth\":" + std::to_string(compacted_tower_growth) + ",";
|
||||
ret += "\"printable_height\":" + std::to_string(printable_height) + ",";
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -214,6 +222,11 @@ void update_selected_items_inflation(ArrangePolygons& selected, const DynamicPri
|
|||
|
||||
void update_unselected_items_inflation(ArrangePolygons& unselected, const DynamicPrintConfig* print_cfg, const ArrangeParams& params);
|
||||
|
||||
// Orca: how far in mm the objects in placed have to stay from a prime tower compacted by "No sparse
|
||||
// layers": MAX_OUTER_NOZZLE_DIAMETER when none of them is taller than params.nozzle_height,
|
||||
// toolhead_radius otherwise or when placed is empty.
|
||||
double compacted_tower_arrange_clearance(const ArrangePolygons& placed, const ArrangeParams& params, double toolhead_radius);
|
||||
|
||||
void update_selected_items_axis_align(ArrangePolygons& selected, const DynamicPrintConfig* print_cfg, const ArrangeParams& params);
|
||||
|
||||
bool has_bed_exclusion_regions(const ArrangePolygons& polygons);
|
||||
|
|
|
|||
|
|
@ -396,6 +396,7 @@ set(lisbslic3r_sources
|
|||
Optimize/Optimizer.hpp
|
||||
Orient.cpp
|
||||
Orient.hpp
|
||||
ParallelForFirstError.hpp
|
||||
ParallelResolve.hpp
|
||||
ParameterUtils.cpp
|
||||
ParameterUtils.hpp
|
||||
|
|
|
|||
|
|
@ -92,6 +92,22 @@ bool ExPolygon::contains(const Polyline &polyline) const
|
|||
if (!bbox1.overlap(bbox2))
|
||||
return false;
|
||||
|
||||
// A polyline reaching further than SCALED_EPSILON out of the bounding box of all the outlines runs
|
||||
// outside of them all there, which the difference keeps: no need to compute it. This does not hold for
|
||||
// a polyline of a single point, which the difference drops.
|
||||
if (bbox2.min != bbox2.max) {
|
||||
auto reaches_out = [&bbox2](BoundingBox outlines) {
|
||||
outlines.offset(SCALED_EPSILON);
|
||||
return !outlines.contains(bbox2.min) || !outlines.contains(bbox2.max);
|
||||
};
|
||||
if (reaches_out(bbox1)) {
|
||||
for (const Polygon &hole : this->holes)
|
||||
bbox1.merge(get_extents(hole));
|
||||
if (reaches_out(bbox1))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return diff_pl(polyline, *this).empty();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ Flow Flow::with_cross_section(float area_new) const
|
|||
return this->with_width(width_new);
|
||||
} else {
|
||||
// Create a rounded extrusion.
|
||||
auto dmr = float(sqrt(area_new / M_PI));
|
||||
auto dmr = float(2. * sqrt(area_new / M_PI));
|
||||
return Flow(dmr, dmr, m_spacing, m_nozzle_diameter, false);
|
||||
}
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -2854,6 +2854,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
|
|||
|
||||
// BBS
|
||||
m_curr_print = print;
|
||||
m_overhang_layers_cache.valid = false;
|
||||
m_skirt_group_done.clear();
|
||||
m_pending_start_gcode_position.reset();
|
||||
m_exclusion_volume_travel_avoidance.init(print->config(), print->get_plate_origin());
|
||||
|
|
@ -5125,24 +5126,24 @@ struct PrecomputedLayer
|
|||
};
|
||||
} // namespace
|
||||
|
||||
// Whether process_layer() prepares the overhang estimator for `layer`.
|
||||
template<typename OverhangSpeed>
|
||||
static bool prepares_overhang_estimator(const Layer &layer, bool overhang_fan, OverhangSpeed overhang_speed)
|
||||
// Whether process_layer() prepares the overhang estimator for `layer`. Any filament may print the layer, and
|
||||
// process_layer() prepares it before the layer's tool changes, so a region's overhang speed counts if it is enabled for
|
||||
// any nozzle.
|
||||
static bool prepares_overhang_estimator(const Layer &layer, bool overhang_fan)
|
||||
{
|
||||
const LayerRegionPtrs ®ions = layer.regions();
|
||||
return std::any_of(regions.begin(), regions.end(), [overhang_fan, &overhang_speed](const LayerRegion *region) {
|
||||
return region->has_extrusions() && (overhang_fan || overhang_speed(*region));
|
||||
return std::any_of(regions.begin(), regions.end(), [overhang_fan](const LayerRegion *region) {
|
||||
return region->has_extrusions() &&
|
||||
(overhang_fan || any_enabled(region->region().config().enable_overhang_speed));
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<PrecomputedOverhangLayer> precompute_overhang_layers(const std::vector<GCode::LayerToPrint> &layers, bool overhang_fan)
|
||||
{
|
||||
// Any filament may print the layer, so a region's overhang speed counts if it is enabled for any.
|
||||
auto overhang_speed = [](const LayerRegion ®ion) { return any_enabled(region.region().config().enable_overhang_speed); };
|
||||
std::vector<PrecomputedOverhangLayer> out;
|
||||
for (const GCode::LayerToPrint &layer : layers)
|
||||
if (layer.object_layer != nullptr && layer.object_layer->lower_layer != nullptr &&
|
||||
prepares_overhang_estimator(*layer.object_layer, overhang_fan, overhang_speed)) {
|
||||
prepares_overhang_estimator(*layer.object_layer, overhang_fan)) {
|
||||
const LayerRegionPtrs ®ions = layer.object_layer->regions();
|
||||
const bool curled_lines = std::any_of(regions.begin(), regions.end(), [](const LayerRegion *region) {
|
||||
return any_enabled(region->region().config().slowdown_for_curled_perimeters);
|
||||
|
|
@ -7026,12 +7027,9 @@ LayerResult GCode::process_layer(
|
|||
return next_extruder;
|
||||
};
|
||||
|
||||
const bool overhang_fan = overhang_fan_enabled(m_config, m_enable_cooling_markers);
|
||||
auto overhang_speed = [this](const LayerRegion ®ion) {
|
||||
return bool(region.region().config().enable_overhang_speed.get_at(get_nozzle_config_index(m_writer.filament()->id())));
|
||||
};
|
||||
const bool overhang_fan = overhang_fan_enabled(m_config, m_enable_cooling_markers);
|
||||
for (const auto &layer_to_print : layers)
|
||||
if (layer_to_print.object_layer && prepares_overhang_estimator(*layer_to_print.object_layer, overhang_fan, overhang_speed))
|
||||
if (layer_to_print.object_layer && prepares_overhang_estimator(*layer_to_print.object_layer, overhang_fan))
|
||||
m_extrusion_quality_estimator.prepare_for_new_layer(layer_to_print.original_object, layer_to_print.object_layer);
|
||||
|
||||
// Group extrusions by an extruder, then by an object, an island and a region.
|
||||
|
|
@ -10854,12 +10852,22 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
|
|||
std::pair<float, float> z_range;
|
||||
z_range.second = m_layer ? m_layer->print_z : 0.f;
|
||||
z_range.first = std::max(0.f, z_range.second - protect_z);
|
||||
std::vector<LayerPtrs> layers_of_objects;
|
||||
std::vector<BoundingBox> boundingBox_for_objects;
|
||||
VecOfPoints objects_instances_shift;
|
||||
std::vector<size_t> idx_of_object_sorted = m_curr_print->layers_sorted_for_object(z_range.first, z_range.second, layers_of_objects, boundingBox_for_objects, objects_instances_shift);
|
||||
|
||||
std::vector<bool> is_layers_of_objects_sorted(layers_of_objects.size(), false);
|
||||
OverhangLayersCache &cache = m_overhang_layers_cache;
|
||||
if (!cache.valid || cache.z_min != z_range.first || cache.z_max != z_range.second) {
|
||||
cache.layers_of_objects.clear();
|
||||
cache.boundingBox_for_objects.clear();
|
||||
cache.idx_of_object_sorted = m_curr_print->layers_sorted_for_object(z_range.first, z_range.second, cache.layers_of_objects,
|
||||
cache.boundingBox_for_objects, cache.objects_instances_shift);
|
||||
for (LayerPtrs &layers : cache.layers_of_objects)
|
||||
std::sort(layers.begin(), layers.end(), [](auto left, auto right) { return left->loverhangs_bbox.area() > right->loverhangs_bbox.area();});
|
||||
cache.z_min = z_range.first;
|
||||
cache.z_max = z_range.second;
|
||||
cache.valid = true;
|
||||
}
|
||||
const std::vector<LayerPtrs> &layers_of_objects = cache.layers_of_objects;
|
||||
const std::vector<BoundingBox> &boundingBox_for_objects = cache.boundingBox_for_objects;
|
||||
const VecOfPoints &objects_instances_shift = cache.objects_instances_shift;
|
||||
const std::vector<size_t> &idx_of_object_sorted = cache.idx_of_object_sorted;
|
||||
|
||||
for (size_t idx : idx_of_object_sorted) {
|
||||
for (const Point & instance_shift : objects_instances_shift[idx]) {
|
||||
|
|
@ -10877,11 +10885,6 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
|
|||
if (intersection_pl(travel, temp).empty())
|
||||
continue;
|
||||
|
||||
if (!is_layers_of_objects_sorted[idx]) {
|
||||
std::sort(layers_of_objects[idx].begin(), layers_of_objects[idx].end(), [](auto left, auto right) { return left->loverhangs_bbox.area() > right->loverhangs_bbox.area();});
|
||||
is_layers_of_objects_sorted[idx] = true;
|
||||
}
|
||||
|
||||
for (const auto& layer : layers_of_objects[idx]) {
|
||||
for (ExPolygon overhang : layer->loverhangs) {
|
||||
overhang.translate(instance_shift);
|
||||
|
|
|
|||
|
|
@ -932,6 +932,19 @@ protected:
|
|||
|
||||
// BBS
|
||||
Print* m_curr_print = nullptr;
|
||||
// The layers of every object below the layer being exported, which needs_retraction() searches for
|
||||
// overhangs a travel crosses: collected once per z range rather than once per travel.
|
||||
struct OverhangLayersCache
|
||||
{
|
||||
bool valid = false;
|
||||
float z_min = 0.f;
|
||||
float z_max = 0.f;
|
||||
std::vector<size_t> idx_of_object_sorted;
|
||||
// Of each object, sorted by the area of their overhangs' bounding box, largest first.
|
||||
std::vector<LayerPtrs> layers_of_objects;
|
||||
std::vector<BoundingBox> boundingBox_for_objects;
|
||||
VecOfPoints objects_instances_shift;
|
||||
} m_overhang_layers_cache;
|
||||
unsigned int m_toolchange_count;
|
||||
coordf_t m_nominal_z;
|
||||
// Mixed-color sublayer state. Non-zero only while emitting a mixed slot's sub-layer:
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
#include <tbb/parallel_for.h>
|
||||
#include <tbb/concurrent_vector.h>
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <unordered_map>
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
|
@ -40,9 +41,10 @@ inline IndexPair point_map_grid_index(const Point &pt, int64_t xdist, int64_t yd
|
|||
|
||||
inline bool nearly_equal(const Point &p1, const Point &p2) { return std::abs(p1.x() - p2.x()) < SCALED_EPSILON && std::abs(p1.y() - p2.y()) < SCALED_EPSILON; }
|
||||
|
||||
inline Grids line_rasterization(const Line &line, int64_t xdist = scale_(1), int64_t ydist = scale_(1))
|
||||
// The grid cells the line passes through, in order, into res.
|
||||
inline void line_rasterization(const Line &line, Grids &res, int64_t xdist = scale_(1), int64_t ydist = scale_(1))
|
||||
{
|
||||
Grids res;
|
||||
res.clear();
|
||||
Point rayStart = line.a;
|
||||
Point rayEnd = line.b;
|
||||
IndexPair currentVoxel = point_map_grid_index(rayStart, xdist, ydist);
|
||||
|
|
@ -99,9 +101,12 @@ inline Grids line_rasterization(const Line &line, int64_t xdist = scale_(1), int
|
|||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
struct IndexPairHash
|
||||
{
|
||||
size_t operator()(const IndexPair &p) const { return std::hash<int64_t>()(p.first) ^ (std::hash<int64_t>()(p.second) * 0x9e3779b97f4a7c15ull); }
|
||||
};
|
||||
} // namespace RasterizationImpl
|
||||
|
||||
void LinesBucketQueue::emplace_back_bucket(ExtrusionLayers &&els, const void *objPtr, Point offset)
|
||||
|
|
@ -207,7 +212,7 @@ ObjectExtrusions getAllLayersExtrusionPathsFromObject(PrintObject *obj)
|
|||
|
||||
for (auto layerPtr : obj->layers()) {
|
||||
auto perimeters = getExtrusionPathsFromLayer(layerPtr->regions());
|
||||
oe.perimeters.insert(oe.perimeters.end(), perimeters.begin(), perimeters.end());
|
||||
oe.perimeters.insert(oe.perimeters.end(), std::make_move_iterator(perimeters.begin()), std::make_move_iterator(perimeters.end()));
|
||||
}
|
||||
|
||||
for (auto supportLayerPtr : obj->support_layers()) { oe.support.push_back(getExtrusionPathsFromSupportLayer(supportLayerPtr)); }
|
||||
|
|
@ -218,18 +223,20 @@ ObjectExtrusions getAllLayersExtrusionPathsFromObject(PrintObject *obj)
|
|||
ConflictComputeOpt ConflictChecker::find_inter_of_lines(const LineWithIDs &lines)
|
||||
{
|
||||
using namespace RasterizationImpl;
|
||||
std::map<IndexPair, std::vector<int>> indexToLine;
|
||||
// Only looked up, never iterated, so the order of the cells does not matter.
|
||||
std::unordered_map<IndexPair, std::vector<int>, IndexPairHash> indexToLine;
|
||||
Grids indexes;
|
||||
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
const LineWithID &l1 = lines[i];
|
||||
auto indexes = line_rasterization(l1._line);
|
||||
const LineWithID &l1 = lines[i];
|
||||
line_rasterization(l1._line, indexes);
|
||||
for (auto index : indexes) {
|
||||
const auto &possibleIntersectIdxs = indexToLine[index];
|
||||
auto &possibleIntersectIdxs = indexToLine[index];
|
||||
for (auto possibleIntersectIdx : possibleIntersectIdxs) {
|
||||
const LineWithID &l2 = lines[possibleIntersectIdx];
|
||||
if (auto interRes = line_intersect(l1, l2); interRes.has_value()) { return interRes; }
|
||||
}
|
||||
indexToLine[index].push_back(i);
|
||||
possibleIntersectIdxs.push_back(i);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public:
|
|||
Point _offset;
|
||||
|
||||
public:
|
||||
LinesBucket(ExtrusionLayers &&paths, const void* id, Point offset) : _piles(paths), _id(id), _offset(offset) {}
|
||||
LinesBucket(ExtrusionLayers &&paths, const void* id, Point offset) : _piles(std::move(paths)), _id(id), _offset(offset) {}
|
||||
LinesBucket(LinesBucket &&) = default;
|
||||
|
||||
std::pair<int, int> curRange() const
|
||||
|
|
|
|||
|
|
@ -493,9 +493,8 @@ class ExtrusionQualityEstimator
|
|||
using CurledLines = AABBTreeLines::LinesDistancer<CurledLine>;
|
||||
std::unordered_map<const PrintObject*, std::shared_ptr<const Boundaries>> prev_layer_boundaries;
|
||||
std::unordered_map<const PrintObject*, std::shared_ptr<const CurledLines>> prev_curled_extrusions;
|
||||
// The layers the trees above are built from, and the layers prepared last.
|
||||
// The layers the trees above are built from.
|
||||
std::unordered_map<const PrintObject*, const Layer*> prev_layer_sources;
|
||||
std::unordered_map<const PrintObject*, const Layer*> last_prepared_layers;
|
||||
std::vector<PrecomputedOverhangLayer> precomputed_layers;
|
||||
const PrintObject *current_object;
|
||||
|
||||
|
|
@ -518,18 +517,19 @@ public:
|
|||
// Takes the data computed ahead for the layer about to be generated, replacing the previous layer's.
|
||||
void set_precomputed_layers(std::vector<PrecomputedOverhangLayer> &&layers) { precomputed_layers = std::move(layers); }
|
||||
|
||||
// Measures the layer against the layer prepared before it.
|
||||
// Measures the layer against the layer below it. Not against the layer prepared before it: process_layer() skips
|
||||
// layers that need no overhang detection, e.g. where a height range modifier turns overhang speed off.
|
||||
void prepare_for_new_layer(const PrintObject * obj, const Layer *layer)
|
||||
{
|
||||
if (layer == nullptr) return;
|
||||
const PrintObject *object = obj;
|
||||
const Layer *prev = std::exchange(last_prepared_layers[object], layer);
|
||||
const Layer *prev = layer->lower_layer;
|
||||
prev_layer_sources[object] = prev;
|
||||
const PrecomputedOverhangLayer *precomputed = precomputed_for(object);
|
||||
if (prev == nullptr) {
|
||||
prev_layer_boundaries[object] = nullptr;
|
||||
prev_curled_extrusions[object] = nullptr;
|
||||
} else if (precomputed != nullptr && precomputed->layer == layer && layer->lower_layer == prev) {
|
||||
} else if (precomputed != nullptr && precomputed->layer == layer) {
|
||||
prev_layer_boundaries[object] = precomputed->lower_boundaries;
|
||||
prev_curled_extrusions[object] = precomputed->lower_curled_lines;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3779,6 +3779,7 @@ void GCodeProcessor::reset()
|
|||
m_travel_dist = 0.0f;
|
||||
m_fan_speed = 0.0f;
|
||||
m_z_offset = 0.0f;
|
||||
m_pressure_advance = 0.0f;
|
||||
|
||||
m_extrusion_role = erNone;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "libslic3r/PrintBase.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
#include "libslic3r/libslic3r.h"
|
||||
#include "libslic3r/ParallelForFirstError.hpp"
|
||||
#include "libslic3r/TriangleMesh.hpp"
|
||||
#include "libslic3r/TriangleSelector.hpp"
|
||||
#include "tbb/parallel_for.h"
|
||||
|
|
@ -390,20 +391,18 @@ struct GlobalModelInfo {
|
|||
}
|
||||
|
||||
float calculate_point_visibility(const Vec3f &position) const {
|
||||
std::vector<size_t> points = find_nearby_points(mesh_samples_tree, position, mesh_samples_radius);
|
||||
if (points.empty()) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
auto compute_dist_to_plane = [](const Vec3f &position, const Vec3f &plane_origin, const Vec3f &plane_normal) {
|
||||
Vec3f orig_to_point = position - plane_origin;
|
||||
return std::abs(orig_to_point.dot(plane_normal));
|
||||
};
|
||||
|
||||
// Accumulated in the order find_nearby_points() lists the samples, without collecting them first:
|
||||
// this runs for every seam candidate.
|
||||
bool any_sample = false;
|
||||
float total_weight = 0;
|
||||
float total_visibility = 0;
|
||||
for (size_t i = 0; i < points.size(); ++i) {
|
||||
size_t sample_idx = points[i];
|
||||
visit_nearby_points(mesh_samples_tree, position, mesh_samples_radius, [&](size_t sample_idx) {
|
||||
any_sample = true;
|
||||
|
||||
Vec3f sample_point = this->mesh_samples.positions[sample_idx];
|
||||
Vec3f sample_normal = this->mesh_samples.normals[sample_idx];
|
||||
|
|
@ -412,10 +411,9 @@ struct GlobalModelInfo {
|
|||
weight += (mesh_samples_radius - (position - sample_point).norm());
|
||||
total_visibility += weight * mesh_samples_visibility[sample_idx];
|
||||
total_weight += weight;
|
||||
}
|
||||
|
||||
return total_visibility / total_weight;
|
||||
});
|
||||
|
||||
return any_sample ? total_visibility / total_weight : 1.0f;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_FILES
|
||||
|
|
@ -1627,7 +1625,7 @@ Vec3f place_on_loop(const std::vector<SeamCandidate> &points, size_t index, cons
|
|||
void SeamPlacer::gather_seam_candidates(const PrintObject *po, const SeamPlacerImpl::GlobalModelInfo &global_model_info,
|
||||
PreciseSeam::PreciseSeamWarnings* warnings) {
|
||||
using namespace SeamPlacerImpl;
|
||||
PrintObjectSeamData &seam_data = m_seam_per_object.emplace(po, PrintObjectSeamData { }).first->second;
|
||||
PrintObjectSeamData &seam_data = m_seam_per_object.at(po);
|
||||
seam_data.layers.resize(po->layer_count());
|
||||
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, po->layers().size()),
|
||||
|
|
@ -1660,7 +1658,7 @@ void SeamPlacer::gather_seam_candidates(const PrintObject *po, const SeamPlacerI
|
|||
void SeamPlacer::calculate_candidates_visibility(const PrintObject *po,
|
||||
const SeamPlacerImpl::GlobalModelInfo &global_model_info) {
|
||||
|
||||
std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object[po].layers;
|
||||
std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object.at(po).layers;
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, layers.size()),
|
||||
[&layers, &global_model_info](tbb::blocked_range<size_t> r) {
|
||||
for (size_t layer_idx = r.begin(); layer_idx < r.end(); ++layer_idx) {
|
||||
|
|
@ -1676,7 +1674,7 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po)
|
|||
using namespace SeamPlacerImpl;
|
||||
using PerimeterDistancer = AABBTreeLines::LinesDistancer<Linef>;
|
||||
|
||||
std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object[po].layers;
|
||||
std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object.at(po).layers;
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, layers.size()),
|
||||
[po, &layers](tbb::blocked_range<size_t> r) {
|
||||
std::unique_ptr<PerimeterDistancer> prev_layer_distancer;
|
||||
|
|
@ -1896,7 +1894,7 @@ void SeamPlacer::align_seam_points(const PrintObject *po, const SeamPlacerImpl::
|
|||
#endif
|
||||
|
||||
//gather vector of all seams on the print_object - pair of layer_index and seam__index within that layer
|
||||
const std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object[po].layers;
|
||||
const std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object.at(po).layers;
|
||||
// Share the largest nozzle diameter between contour bounds and corner protection.
|
||||
double max_nozzle_diameter = 0.0;
|
||||
for (double diameter : po->print()->config().nozzle_diameter.values)
|
||||
|
|
@ -2112,7 +2110,33 @@ void SeamPlacer::init(const Print &print, std::function<void(void)> throw_if_can
|
|||
// Warning flags for Precise Seam processing — shared across all objects
|
||||
PreciseSeam::PreciseSeamWarnings precise_seam_warnings;
|
||||
|
||||
// The objects get their seams independently of each other, so they are processed concurrently. Their seam data
|
||||
// and the usage tracking of their Precise Seam modifiers are created first: the objects only look them up.
|
||||
struct ObjectSeams {
|
||||
const PrintObject *po;
|
||||
PrintObjectSeamData *seam_data;
|
||||
std::vector<const ModelVolume*> precise_seam_strong_volumes;
|
||||
std::vector<const ModelVolume*> precise_seam_weak_volumes;
|
||||
};
|
||||
std::vector<ObjectSeams> objects;
|
||||
objects.reserve(print.objects().size());
|
||||
for (const PrintObject *po : print.objects()) {
|
||||
ObjectSeams &object = objects.emplace_back(ObjectSeams{ po, &m_seam_per_object[po], {}, {} });
|
||||
PreciseSeam::init_precise_seam_data(
|
||||
object.precise_seam_strong_volumes,
|
||||
object.precise_seam_weak_volumes,
|
||||
object.seam_data->has_precise_seam_strong_volumes,
|
||||
po->model_object());
|
||||
// Workers only set the usage flags. Several print objects of one model object share volumes, and
|
||||
// try_emplace keeps what earlier ones recorded.
|
||||
for (const ModelVolume* vol : object.precise_seam_strong_volumes)
|
||||
precise_seam_warnings.modifier_usage.try_emplace(vol);
|
||||
for (const ModelVolume* vol : object.precise_seam_weak_volumes)
|
||||
precise_seam_warnings.modifier_usage.try_emplace(vol);
|
||||
}
|
||||
|
||||
auto place_seams = [this, &throw_if_canceled_func, &precise_seam_warnings](ObjectSeams &object) {
|
||||
const PrintObject *po = object.po;
|
||||
throw_if_canceled_func();
|
||||
SeamPosition configured_seam_preference = po->config().seam_position.value;
|
||||
SeamComparator comparator { configured_seam_preference };
|
||||
|
|
@ -2120,23 +2144,14 @@ void SeamPlacer::init(const Print &print, std::function<void(void)> throw_if_can
|
|||
{
|
||||
GlobalModelInfo global_model_info { };
|
||||
gather_enforcers_blockers(global_model_info, po);
|
||||
PreciseSeam::init_precise_seam_data(
|
||||
global_model_info.precise_seam_strong_volumes,
|
||||
global_model_info.precise_seam_weak_volumes,
|
||||
m_seam_per_object[po].has_precise_seam_strong_volumes,
|
||||
po->model_object());
|
||||
global_model_info.precise_seam_strong_volumes = std::move(object.precise_seam_strong_volumes);
|
||||
global_model_info.precise_seam_weak_volumes = std::move(object.precise_seam_weak_volumes);
|
||||
|
||||
// Slice each Precise Seam modifier once per object; both consumers read the cache.
|
||||
for (const ModelVolume* vol : global_model_info.precise_seam_strong_volumes)
|
||||
global_model_info.precise_seam_slices[vol] = PreciseSeam::prepare_modifier_slices(po->slice_single_volume_regions(vol));
|
||||
for (const ModelVolume* vol : global_model_info.precise_seam_weak_volumes)
|
||||
global_model_info.precise_seam_slices[vol] = PreciseSeam::prepare_modifier_slices(po->slice_single_volume_regions(vol));
|
||||
// Register usage tracking before the parallel phase; workers only set its flags. Several print
|
||||
// objects of one model object share volumes, and try_emplace keeps what earlier ones recorded.
|
||||
for (const ModelVolume* vol : global_model_info.precise_seam_strong_volumes)
|
||||
precise_seam_warnings.modifier_usage.try_emplace(vol);
|
||||
for (const ModelVolume* vol : global_model_info.precise_seam_weak_volumes)
|
||||
precise_seam_warnings.modifier_usage.try_emplace(vol);
|
||||
|
||||
throw_if_canceled_func();
|
||||
if (configured_seam_preference == spAligned || configured_seam_preference == spNearest || configured_seam_preference == spAlignedBack) {
|
||||
|
|
@ -2169,7 +2184,7 @@ void SeamPlacer::init(const Print &print, std::function<void(void)> throw_if_can
|
|||
BOOST_LOG_TRIVIAL(debug)
|
||||
<< "SeamPlacer: pick_seam_point : start";
|
||||
//pick seam point
|
||||
std::vector<PrintObjectSeamData::LayerSeams> &layers = m_seam_per_object[po].layers;
|
||||
std::vector<PrintObjectSeamData::LayerSeams> &layers = object.seam_data->layers;
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, layers.size()),
|
||||
[&layers, configured_seam_preference, comparator](tbb::blocked_range<size_t> r) {
|
||||
for (size_t layer_idx = r.begin(); layer_idx < r.end(); ++layer_idx) {
|
||||
|
|
@ -2195,13 +2210,24 @@ void SeamPlacer::init(const Print &print, std::function<void(void)> throw_if_can
|
|||
}
|
||||
|
||||
// Restore precise seam positions that were potentially modified
|
||||
if (m_seam_per_object[po].has_precise_seam_strong_volumes) {
|
||||
PreciseSeam::restore_precise_seam_positions(m_seam_per_object[po].layers);
|
||||
if (object.seam_data->has_precise_seam_strong_volumes) {
|
||||
PreciseSeam::restore_precise_seam_positions(object.seam_data->layers);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_FILES
|
||||
debug_export_points(m_seam_per_object[po].layers, po->bounding_box(), comparator);
|
||||
debug_export_points(object.seam_data->layers, po->bounding_box(), comparator);
|
||||
#endif
|
||||
};
|
||||
|
||||
if (objects.size() == 1)
|
||||
place_seams(objects.front());
|
||||
else if (objects.size() > 1) {
|
||||
// One object at a time, its serial steps (mesh decimation, building the search trees, aligning the seams)
|
||||
// keep most of the cores idle. A few objects at once overlap them with the others' parallel steps; no more,
|
||||
// as each holds its sampled mesh until it is done.
|
||||
constexpr size_t max_objects_at_once = 4;
|
||||
const size_t objects_per_task = (objects.size() + max_objects_at_once - 1) / max_objects_at_once;
|
||||
parallel_for_first_error(objects.size(), objects_per_task, [&objects, &place_seams](size_t i) { place_seams(objects[i]); });
|
||||
}
|
||||
|
||||
// Prepare one combined Precise Seam warning; G-code export issues it. Keep it single: separate
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <optional>
|
||||
|
|
@ -25,7 +24,6 @@
|
|||
#include "Polygon.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
#include "libslic3r/I18N.hpp"
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
|
||||
// Mark string for localization and translate.
|
||||
|
|
@ -49,29 +47,6 @@ void strip_whitespace(std::string& token)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
ConfigOptionInts effective_physical_extruder_map(const ConfigOptionInts* explicit_pem, int nozzle_count)
|
||||
{
|
||||
// One entry per logical extruder, so a profile has authored a map only when its length
|
||||
// matches. The single-element PrintConfig default does not, and is replaced rather than
|
||||
// treated as a one-extruder machine.
|
||||
if (explicit_pem && nozzle_count > 0 && (int) explicit_pem->values.size() == nozzle_count)
|
||||
return *explicit_pem;
|
||||
|
||||
ConfigOptionInts derived;
|
||||
derived.values.resize(std::max(nozzle_count, 1));
|
||||
std::iota(derived.values.begin(), derived.values.end(), 0);
|
||||
return derived;
|
||||
}
|
||||
|
||||
ConfigOptionInts effective_physical_extruder_map(const PresetBundle& pb)
|
||||
{
|
||||
const ConfigOptionInts* explicit_pem = pb.project_config.option<ConfigOptionInts>("physical_extruder_map");
|
||||
if (!explicit_pem || explicit_pem->values.size() < 2)
|
||||
explicit_pem = pb.printers.get_edited_preset().config.option<ConfigOptionInts>("physical_extruder_map");
|
||||
const auto* nozzles = pb.printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter");
|
||||
return effective_physical_extruder_map(explicit_pem, nozzles ? (int) nozzles->values.size() : 0);
|
||||
}
|
||||
|
||||
int imex_pem_tool_for(int filament_id, const std::string& parallel_mode, const ConfigOptionInts& pem)
|
||||
{
|
||||
const bool imex_parallel = !parallel_mode.empty() && parallel_mode != kImexPrimaryMode;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
class PresetBundle;
|
||||
|
||||
// Reserved sentinel name for the always-present, non-deletable Primary mode in
|
||||
// `imex_mode_names`. Comparison with this constant indicates "no parallel printing
|
||||
// in effect" — IMEX zone visualization, ghost rendering, secondary-tool PA / temp
|
||||
|
|
@ -162,19 +160,8 @@ std::vector<std::string> imex_plate_mode_choices(const ConfigBase& cfg);
|
|||
// route through one of the helpers below.
|
||||
// =============================================================================
|
||||
|
||||
// physical_extruder_map has one entry per LOGICAL extruder -- the index space of
|
||||
// nozzle_diameter -- with each value a physical extruder index. It is NOT derivable from
|
||||
// printer_extruder_id, which is indexed by variant slot (one entry per extruder+variant pair):
|
||||
// an X1 Carbon has one nozzle and printer_extruder_id {1,1}, an H2D two nozzles and {1,1,2,2,2}.
|
||||
//
|
||||
// A profile has authored a map only when its length matches nozzle_count; otherwise the identity
|
||||
// is returned, which is the same default upstream applies (see Plater.cpp's extruder_map).
|
||||
ConfigOptionInts effective_physical_extruder_map(const ConfigOptionInts* explicit_pem, int nozzle_count);
|
||||
|
||||
// GUI overload: resolves the effective pem from a live PresetBundle using the project_config
|
||||
// → printer preset fallback. Use this instead of open-coding the lookup at ghost-color,
|
||||
// tooltip, click-gate and cache-key call sites so they all agree with what the slicer sees.
|
||||
ConfigOptionInts effective_physical_extruder_map(const PresetBundle& pb);
|
||||
// effective_physical_extruder_map() lives in PrintConfig.hpp and PresetBundle.hpp: the map is a setting of
|
||||
// every multi-nozzle printer, not only IMEX ones.
|
||||
|
||||
// Returns the physical extruder index to emit as a per-tool qualifier (PA / temperature)
|
||||
// for the given filament slot, or -1 when the current IMEX state does not warrant a
|
||||
|
|
@ -189,14 +176,15 @@ int imex_pem_tool_for(int filament_id, const std::string& parallel_mode, const C
|
|||
// so it does not depend on a parallel mode being active the way imex_pem_tool_for does.
|
||||
//
|
||||
// Gated on is_imex because physical_extruder_map carries two readings in this tree: the
|
||||
// BBL paths index it by extruder id (GCode.cpp:3295, WipeTower.cpp:1353), the IMEX paths
|
||||
// BBL paths index it by extruder id (match_physical_extruder_for_each_filament in
|
||||
// GCode::_do_export, WipeTowerWriter::format_line_M104/M109), the IMEX paths
|
||||
// by filament id. Those coincide only when the filament and nozzle counts match, so an
|
||||
// ungated mapping would impose the IMEX reading on profiles that mean the other one --
|
||||
// fdm_bbl_3dp_002_common ships a non-identity [1,0] and is spared today only because
|
||||
// single_extruder_multi_material suppresses the T qualifier entirely.
|
||||
//
|
||||
// Out-of-range ids pass through unchanged, the same rule GCodeProcessor's preheat rewrite
|
||||
// uses (GCode/GCodeProcessor.cpp:1407), so a printer whose map is the registered
|
||||
// uses (GCodeProcessor::run_post_process), so a printer whose map is the registered
|
||||
// single-entry default is unaffected.
|
||||
int imex_physical_heater_for(bool is_imex, const ConfigOptionInts& pem, int logical_id);
|
||||
|
||||
|
|
@ -386,7 +374,7 @@ template<class T>
|
|||
T imex_cfg_enum(const ConfigBase& cfg, const std::string& key)
|
||||
{
|
||||
// Matched by type, not by the coEnum tag. Every ConfigOptionEnum<T> reports coEnum, so the
|
||||
// type() comparison that option<TYPE>() (Config.hpp:2656) and the int/float accessors rely on
|
||||
// type() comparison that ConfigBase::option<TYPE>() and the int/float accessors rely on
|
||||
// cannot tell one enum type from another: it would accept a ConfigOptionEnum<OtherEnum> and
|
||||
// static_cast it to this T. ConfigOptionEnum<A> and ConfigOptionEnum<B> are unrelated
|
||||
// siblings (both derive from ConfigOptionSingle<T>), so a dynamic_cast rejects the mismatch.
|
||||
|
|
|
|||
|
|
@ -444,7 +444,10 @@ void Layer::make_perimeters()
|
|||
append(clipped, diff_ex(l->raw_slices, group_slices));
|
||||
clipped = union_ex(clipped);
|
||||
if (layerms.size() == 1 && clipped.empty()) { // optimization
|
||||
// The perimeter generator appends to these, so perimeters made again (other walls) start from none, as a first
|
||||
// slice does.
|
||||
(*layerm)->fill_surfaces.surfaces.clear();
|
||||
(*layerm)->fill_no_overlap_expolygons.clear();
|
||||
(*layerm)->make_perimeters((*layerm)->slices, {*layerm}, &(*layerm)->fill_surfaces, &(*layerm)->fill_no_overlap_expolygons);
|
||||
(*layerm)->fill_expolygons = to_expolygons((*layerm)->fill_surfaces.surfaces);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
#include <map>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
|
@ -2885,11 +2886,19 @@ int ModelVolume::extruder_id() const
|
|||
|
||||
bool ModelVolume::is_splittable() const
|
||||
{
|
||||
// the call mesh.is_splittable() is expensive, so cache the value to calculate it only once
|
||||
if (m_is_splittable == -1)
|
||||
m_is_splittable = its_is_splittable(this->mesh().its);
|
||||
|
||||
return m_is_splittable == 1;
|
||||
// The call its_is_splittable() is expensive, so cache the value to calculate it only once. The PrintObjects made from
|
||||
// one ModelObject ask at the same time while they prepare their infill, so the cache is read and written under a
|
||||
// lock; the call itself runs outside it, and only callers that find the cache empty at the same time make it twice.
|
||||
static std::mutex cache_mutex;
|
||||
{
|
||||
std::scoped_lock<std::mutex> lock(cache_mutex);
|
||||
if (m_is_splittable != -1)
|
||||
return m_is_splittable == 1;
|
||||
}
|
||||
const int splittable = its_is_splittable(this->mesh().its) ? 1 : 0;
|
||||
std::scoped_lock<std::mutex> lock(cache_mutex);
|
||||
m_is_splittable = splittable;
|
||||
return splittable == 1;
|
||||
}
|
||||
|
||||
// BBS
|
||||
|
|
|
|||
46
src/libslic3r/ParallelForFirstError.hpp
Normal file
46
src/libslic3r/ParallelForFirstError.hpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/blocked_range.h>
|
||||
#include <tbb/parallel_for.h>
|
||||
#include <tbb/partitioner.h>
|
||||
#include <tbb/task_arena.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// Calls process(i) for every i in [0, count) on the TBB threads, items_per_task consecutive items in each task, and
|
||||
// throws what calling them in order would: the exception of the lowest i that threw. Items after it that have not
|
||||
// started yet are skipped, as a loop stops at its first error.
|
||||
//
|
||||
// Each task runs isolated: while it waits in the parallel loops of its own items, its thread takes no other task of
|
||||
// this loop. Otherwise it could start another item meanwhile, which holds up the waiting item until that one is
|
||||
// done, keeps more items in memory at once than there are threads, and breaks code that keeps a lock or thread-local
|
||||
// scratch across a parallel loop.
|
||||
template<class Process>
|
||||
void parallel_for_first_error(size_t count, size_t items_per_task, Process &&process)
|
||||
{
|
||||
std::vector<std::exception_ptr> errors(count);
|
||||
std::atomic<size_t> first_error { count };
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, count, items_per_task), [&](const tbb::blocked_range<size_t> &range) {
|
||||
tbb::this_task_arena::isolate([&]() {
|
||||
for (size_t i = range.begin(); i < range.end() && i < first_error.load(std::memory_order_relaxed); ++ i)
|
||||
try {
|
||||
process(i);
|
||||
} catch (...) {
|
||||
errors[i] = std::current_exception();
|
||||
size_t lowest = first_error.load(std::memory_order_relaxed);
|
||||
while (i < lowest && ! first_error.compare_exchange_weak(lowest, i, std::memory_order_relaxed))
|
||||
;
|
||||
}
|
||||
});
|
||||
}, tbb::simple_partitioner());
|
||||
for (const std::exception_ptr &error : errors)
|
||||
if (error)
|
||||
std::rethrow_exception(error);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
@ -9387,4 +9387,13 @@ bool PresetBundle::install_vendor_cache(const std::string& cache_path, const std
|
|||
}
|
||||
}
|
||||
|
||||
ConfigOptionInts effective_physical_extruder_map(const PresetBundle& pb)
|
||||
{
|
||||
const ConfigOptionInts* explicit_pem = pb.project_config.option<ConfigOptionInts>("physical_extruder_map");
|
||||
if (!explicit_pem || explicit_pem->values.size() < 2)
|
||||
explicit_pem = pb.printers.get_edited_preset().config.option<ConfigOptionInts>("physical_extruder_map");
|
||||
const auto* nozzles = pb.printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter");
|
||||
return effective_physical_extruder_map(explicit_pem, nozzles ? (int) nozzles->values.size() : 0);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -971,6 +971,12 @@ private:
|
|||
|
||||
ENABLE_ENUM_BITMASK_OPERATORS(PresetBundle::LoadConfigBundleAttribute)
|
||||
|
||||
// GUI overload of effective_physical_extruder_map() (PrintConfig.hpp): resolves the effective pem
|
||||
// from a live PresetBundle using the project_config → printer preset fallback. Use this instead of
|
||||
// open-coding the lookup at ghost-color, tooltip, click-gate and cache-key call sites so they all
|
||||
// agree with what the slicer sees.
|
||||
ConfigOptionInts effective_physical_extruder_map(const PresetBundle& pb);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif /* slic3r_PresetBundle_hpp_ */
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@
|
|||
#include "Geometry/ConvexHull.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "LifecycleEvents.hpp"
|
||||
#include "ParallelForFirstError.hpp"
|
||||
#include "ShortestPath.hpp"
|
||||
#include "Thread.hpp"
|
||||
#include "Time.hpp"
|
||||
|
|
@ -2859,10 +2860,16 @@ StringObjectException Print::validate(std::vector<StringObjectException> *warnin
|
|||
if (!validate_extrusion_width(object->config(), "support_line_width", layer_height, err_msg))
|
||||
return {err_msg, object, "support_line_width"};
|
||||
}
|
||||
for (const char *opt_key : { "inner_wall_line_width", "outer_wall_line_width", "sparse_infill_line_width", "internal_solid_infill_line_width", "top_surface_line_width","skin_infill_line_width" ,"skeleton_infill_line_width"})
|
||||
for (const char *opt_key : { "inner_wall_line_width", "outer_wall_line_width", "sparse_infill_line_width", "internal_solid_infill_line_width", "top_surface_line_width"})
|
||||
for (const PrintRegion ®ion : object->all_regions())
|
||||
if (!validate_extrusion_width(region.config(), opt_key, layer_height, err_msg))
|
||||
return {err_msg, object, opt_key};
|
||||
// Only the Locked Zag sparse infill prints skin and skeleton lines.
|
||||
for (const PrintRegion ®ion : object->all_regions())
|
||||
if (region.config().sparse_infill_pattern == ipLockedZag)
|
||||
for (const char *opt_key : { "skin_infill_line_width", "skeleton_infill_line_width" })
|
||||
if (!validate_extrusion_width(region.config(), opt_key, layer_height, err_msg))
|
||||
return {err_msg, object, opt_key};
|
||||
|
||||
const bool allow_thin_bridge_width = object->config().thick_bridges && object->config().thick_internal_bridges;
|
||||
for (const PrintRegion ®ion : object->all_regions()) {
|
||||
|
|
@ -2876,7 +2883,8 @@ StringObjectException Print::validate(std::vector<StringObjectException> *warnin
|
|||
err_msg = L("Bridge line width must not exceed nozzle diameter");
|
||||
return { err_msg, object, "bridge_line_width" };
|
||||
}
|
||||
if (!allow_thin_bridge_width && bridge_width <= layer_height) {
|
||||
// A bridge as wide as the layer is tall is a round strand, the same as a thick bridge.
|
||||
if (!allow_thin_bridge_width && bridge_width < layer_height) {
|
||||
err_msg = L("Line width too small");
|
||||
return { err_msg, object, "bridge_line_width" };
|
||||
}
|
||||
|
|
@ -3602,16 +3610,37 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
|
|||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": total object counts %1% in current print, need to slice %2%")%m_objects.size()%need_slicing_objects.size();
|
||||
BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
|
||||
// Runs a step on the objects `needs` selects and `skip` on the others. A step of an object reads that object and
|
||||
// the print's configuration only, which the support step has always relied on, so the objects run the step
|
||||
// together: one after another, each object's serial parts and slowest layers kept most of the cores idle.
|
||||
// A slicing pipeline plugin runs its hook between the objects, so with one active they keep their order.
|
||||
// Nothing enforces that rule. In particular, the PrintObjects made from one ModelObject, one per distinct instance
|
||||
// transformation, share its ModelVolumes, whose lazily filled caches are not guarded: a step must not fill them
|
||||
// (ModelVolume::is_splittable() is the exception, under a lock).
|
||||
auto for_each_object_step = [this](auto &&needs, auto &&process, auto &&skip) {
|
||||
std::vector<PrintObject*> objects;
|
||||
for (PrintObject *obj : m_objects)
|
||||
if (! needs(obj))
|
||||
skip(obj);
|
||||
else if (m_pipeline_plugin_active)
|
||||
process(obj);
|
||||
else
|
||||
objects.push_back(obj);
|
||||
if (objects.size() == 1)
|
||||
process(objects.front());
|
||||
else if (objects.size() > 1)
|
||||
parallel_for_first_error(objects.size(), 1, [&process, &objects](size_t i) { process(objects[i]); });
|
||||
};
|
||||
if (!use_cache) {
|
||||
// Fire the SlicingPipeline hook for `obj` iff it just (re)computed `pstep` this pass.
|
||||
auto hook_after = [this](PrintObject* obj, bool was_done, PrintObjectStep pstep, SlicingPipelineStepPlugin sstep) {
|
||||
if (m_pipeline_plugin_active && !was_done && obj->is_step_done(pstep))
|
||||
run_pipeline_hook(sstep, obj);
|
||||
};
|
||||
auto needs_slicing = [&need_slicing_objects](PrintObject *obj) { return need_slicing_objects.count(obj) != 0; };
|
||||
|
||||
// SlicingPipeline: dedicated slice loop so the Slice boundary is hookable before perimeters.
|
||||
for (PrintObject *obj : m_objects) {
|
||||
if (need_slicing_objects.count(obj) != 0) {
|
||||
for_each_object_step(needs_slicing, [&](PrintObject *obj) {
|
||||
const bool was_done = obj->is_step_done(posSlice);
|
||||
obj->slice();
|
||||
hook_after(obj, was_done, posSlice, SlicingPipelineStepPlugin::posSlice);
|
||||
|
|
@ -3626,32 +3655,25 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
|
|||
if (m_pipeline_plugin_active && !was_done && obj->is_step_done(posSlice))
|
||||
for (Layer *layer : obj->layers())
|
||||
layer->backup_untyped_slices();
|
||||
} else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posSlice)) obj->set_done(posSlice); // shared/duplicate — no hook
|
||||
}
|
||||
}
|
||||
for (PrintObject *obj : m_objects) {
|
||||
if (need_slicing_objects.count(obj) != 0) {
|
||||
});
|
||||
for_each_object_step(needs_slicing, [&](PrintObject *obj) {
|
||||
const bool was_done = obj->is_step_done(posPerimeters);
|
||||
obj->make_perimeters(); // slice() inside is a no-op: posSlice already DONE
|
||||
hook_after(obj, was_done, posPerimeters, SlicingPipelineStepPlugin::posPerimeters);
|
||||
} else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posPerimeters)) obj->set_done(posPerimeters);
|
||||
}
|
||||
}
|
||||
for (PrintObject *obj : m_objects) {
|
||||
if (need_slicing_objects.count(obj) != 0) {
|
||||
});
|
||||
for_each_object_step(needs_slicing, [&](PrintObject *obj) {
|
||||
const bool was_done = obj->is_step_done(posEstimateCurledExtrusions);
|
||||
obj->estimate_curled_extrusions();
|
||||
hook_after(obj, was_done, posEstimateCurledExtrusions, SlicingPipelineStepPlugin::posEstimateCurledExtrusions);
|
||||
}
|
||||
else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posEstimateCurledExtrusions))
|
||||
obj->set_done(posEstimateCurledExtrusions);
|
||||
}
|
||||
}
|
||||
for (PrintObject *obj : m_objects) {
|
||||
if (need_slicing_objects.count(obj) != 0) {
|
||||
});
|
||||
for_each_object_step(needs_slicing, [&](PrintObject *obj) {
|
||||
// split prepare_infill (fill-surface prep) from infill (make_fills) so a
|
||||
// plugin can mutate fill surfaces at the PrepareInfill seam and have make_fills
|
||||
// consume them (unlike the Infill seam, which fires after the fills are already
|
||||
|
|
@ -3663,25 +3685,20 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
|
|||
const bool was_done = obj->is_step_done(posInfill);
|
||||
obj->infill();
|
||||
hook_after(obj, was_done, posInfill, SlicingPipelineStepPlugin::posInfill);
|
||||
}
|
||||
else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posPrepareInfill))
|
||||
obj->set_done(posPrepareInfill);
|
||||
if (obj->set_started(posInfill))
|
||||
obj->set_done(posInfill);
|
||||
}
|
||||
}
|
||||
for (PrintObject *obj : m_objects) {
|
||||
if (need_slicing_objects.count(obj) != 0) {
|
||||
});
|
||||
for_each_object_step(needs_slicing, [&](PrintObject *obj) {
|
||||
const bool was_done = obj->is_step_done(posIroning);
|
||||
obj->ironing();
|
||||
hook_after(obj, was_done, posIroning, SlicingPipelineStepPlugin::posIroning);
|
||||
}
|
||||
else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posIroning))
|
||||
obj->set_done(posIroning);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Z-Contouring
|
||||
for (PrintObject *obj : m_objects) {
|
||||
|
|
@ -3729,17 +3746,14 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
|
|||
&& m_objects[i]->is_step_done(posSupportMaterial))
|
||||
run_pipeline_hook(SlicingPipelineStepPlugin::posSupportMaterial, m_objects[i]);
|
||||
|
||||
for (PrintObject* obj : m_objects) {
|
||||
if (need_slicing_objects.count(obj) != 0) {
|
||||
for_each_object_step(needs_slicing, [&](PrintObject *obj) {
|
||||
const bool was_done = obj->is_step_done(posDetectOverhangsForLift);
|
||||
obj->detect_overhangs_for_lift();
|
||||
hook_after(obj, was_done, posDetectOverhangsForLift, SlicingPipelineStepPlugin::posDetectOverhangsForLift);
|
||||
}
|
||||
else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posDetectOverhangsForLift))
|
||||
obj->set_done(posDetectOverhangsForLift);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
for (PrintObject *obj : m_objects) {
|
||||
|
|
@ -4104,9 +4118,9 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
|
|||
}
|
||||
}
|
||||
//BBS
|
||||
for (PrintObject *obj : m_objects) {
|
||||
if (((!use_cache)&&(need_slicing_objects.count(obj) != 0))
|
||||
|| (use_cache &&(re_slicing_objects.count(obj) != 0))){
|
||||
for_each_object_step([&](PrintObject *obj) {
|
||||
return (!use_cache && need_slicing_objects.count(obj) != 0) || (use_cache && re_slicing_objects.count(obj) != 0);
|
||||
}, [&](PrintObject *obj) {
|
||||
const bool was_done = obj->is_step_done(posSimplifyPath);
|
||||
obj->simplify_extrusion_path();
|
||||
// Unlike every other seam (all inside the `if (!use_cache)` block above), this loop is
|
||||
|
|
@ -4114,16 +4128,14 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
|
|||
// explicitly here to keep hooks from ever firing on cache-loaded (plugin-final) objects.
|
||||
if (!use_cache && m_pipeline_plugin_active && !was_done && obj->is_step_done(posSimplifyPath))
|
||||
run_pipeline_hook(SlicingPipelineStepPlugin::posSimplifyPath, obj);
|
||||
}
|
||||
else {
|
||||
}, [](PrintObject *obj) {
|
||||
if (obj->set_started(posSimplifyPath))
|
||||
obj->set_done(posSimplifyPath);
|
||||
if (obj->set_started(posSimplifyInfill))
|
||||
obj->set_done(posSimplifyInfill);
|
||||
if (obj->set_started(posSimplifySupportPath))
|
||||
obj->set_done(posSimplifySupportPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// BBS
|
||||
bool has_adaptive_layer_height = false;
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ std::string PrintBase::output_filepath(const std::string &path, const std::strin
|
|||
//BBS: move set_status from hpp to cpp
|
||||
void PrintBase::set_status(int percent, const std::string &message, unsigned int flags, int warning_step) const
|
||||
{
|
||||
std::scoped_lock<std::mutex> lock(m_status_callback_mutex);
|
||||
if (m_status_callback)
|
||||
m_status_callback(SlicingStatus(percent, message, flags, warning_step));
|
||||
else
|
||||
|
|
@ -132,6 +133,7 @@ void PrintBase::set_status(int percent, const std::string &message, unsigned in
|
|||
void PrintBase::status_update_warnings(int step, PrintStateBase::WarningLevel warning_level,
|
||||
const std::string &message, const PrintObjectBase* print_object, PrintStateBase::SlicingNotificationType message_id)
|
||||
{
|
||||
std::scoped_lock<std::mutex> lock(m_status_callback_mutex);
|
||||
if (this->m_status_callback) {
|
||||
auto status = print_object ? SlicingStatus(*print_object, step, message, message_id, warning_level) : SlicingStatus(*this, step, message, message_id, warning_level);
|
||||
m_status_callback(status);
|
||||
|
|
@ -145,9 +147,9 @@ void PrintBase::status_update_warnings(int step, PrintStateBase::WarningLevel wa
|
|||
const std::string& message, PrintObjectBase &object, PrintStateBase::SlicingNotificationType message_id)
|
||||
{
|
||||
//BBS: add object it into slicing status
|
||||
if (this->m_status_callback) {
|
||||
std::scoped_lock<std::mutex> lock(m_status_callback_mutex);
|
||||
if (this->m_status_callback)
|
||||
m_status_callback(SlicingStatus(object, step, message, message_id, warning_level));
|
||||
}
|
||||
else if (!message.empty())
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", PrintObject warning: %1%\n")% message.c_str();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -481,11 +481,11 @@ public:
|
|||
};
|
||||
typedef std::function<void(const SlicingStatus&)> status_callback_type;
|
||||
// Default status console print out in the form of percent => message.
|
||||
void set_status_default() { m_status_callback = nullptr; }
|
||||
void set_status_default() { set_status_callback(nullptr); }
|
||||
// No status output or callback whatsoever, useful mostly for automatic tests.
|
||||
void set_status_silent() { m_status_callback = [](const SlicingStatus&){}; }
|
||||
void set_status_silent() { set_status_callback([](const SlicingStatus&){}); }
|
||||
// Register a custom status callback.
|
||||
void set_status_callback(status_callback_type cb) { m_status_callback = cb; }
|
||||
void set_status_callback(status_callback_type cb) { std::scoped_lock<std::mutex> lock(m_status_callback_mutex); m_status_callback = std::move(cb); }
|
||||
// Calls a registered callback to update the status, or print out the default message.
|
||||
void set_status(int percent, const std::string &message, unsigned int flags = SlicingStatus::DEFAULT, int warning_step = -1) const;
|
||||
|
||||
|
|
@ -583,6 +583,9 @@ private:
|
|||
// The mutex will be used to guard the worker thread against entering a stage
|
||||
// while the data influencing the stage is modified.
|
||||
mutable std::mutex m_state_mutex;
|
||||
// Held while the status callback runs or is replaced: the objects run their steps concurrently, a callback may keep
|
||||
// state of its own, such as the warnings the command line collects, and the GUI replaces it while a slice runs.
|
||||
mutable std::mutex m_status_callback_mutex;
|
||||
|
||||
friend PrintTryCancel;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -154,6 +154,20 @@ double nozzle_diameter_for_filament(const PrintConfig& config, int filament_id,
|
|||
return config.nozzle_diameter.get_at(extruder - 1);
|
||||
}
|
||||
|
||||
ConfigOptionInts effective_physical_extruder_map(const ConfigOptionInts* explicit_pem, int nozzle_count)
|
||||
{
|
||||
// One entry per logical extruder, so a profile has authored a map only when its length
|
||||
// matches. The single-element PrintConfig default does not, and is replaced rather than
|
||||
// treated as a one-extruder machine.
|
||||
if (explicit_pem && nozzle_count > 0 && (int) explicit_pem->values.size() == nozzle_count)
|
||||
return *explicit_pem;
|
||||
|
||||
ConfigOptionInts derived;
|
||||
derived.values.resize(std::max(nozzle_count, 1));
|
||||
std::iota(derived.values.begin(), derived.values.end(), 0);
|
||||
return derived;
|
||||
}
|
||||
|
||||
|
||||
// Orca: input shaping values types by flavor
|
||||
std::vector<std::string> get_shaper_type_values_for_flavor(GCodeFlavor flavor)
|
||||
|
|
|
|||
|
|
@ -2821,6 +2821,21 @@ size_t get_extruder_index(const GCodeConfig& config, unsigned int filament_id);
|
|||
|
||||
double nozzle_diameter_for_filament(const PrintConfig& config, int filament_id, bool is_bbl_printer);
|
||||
|
||||
// physical_extruder_map has one entry per LOGICAL extruder -- the index space of
|
||||
// nozzle_diameter -- with each value a physical extruder index. It is NOT derivable from
|
||||
// printer_extruder_id, which is indexed by variant slot (one entry per extruder+variant pair):
|
||||
// an X1 Carbon has one nozzle and printer_extruder_id {1,1}, an H2D two nozzles and {1,1,2,2,2}.
|
||||
//
|
||||
// The setting belongs to every printer, not only IMEX ones: the single-element default is what
|
||||
// any multi-nozzle profile that never sets it (a Snapmaker U1, say) carries, so reading it raw by
|
||||
// logical extruder runs past its end. GUI and device-side readers go through this helper (or its
|
||||
// PresetBundle overload in PresetBundle.hpp); the non-IMEX G-code paths read the raw value on
|
||||
// purpose (see the is_imex gate in PrintApply.cpp).
|
||||
//
|
||||
// A profile has authored a map only when its length matches nozzle_count; otherwise the identity
|
||||
// is returned, the default upstream's printer sync starts from before it applies an authored map.
|
||||
ConfigOptionInts effective_physical_extruder_map(const ConfigOptionInts* explicit_pem, int nozzle_count);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
// Serialization through the Cereal library
|
||||
|
|
|
|||
|
|
@ -865,6 +865,23 @@ namespace Slic3r
|
|||
m_agent->add_subscribe(subscribe_list_cache);
|
||||
}
|
||||
|
||||
void DeviceManager::reselect_cloud_machine()
|
||||
{
|
||||
if (!m_agent)
|
||||
return;
|
||||
|
||||
// The selection is a cloud subscription, and a LAN printer has none. Selecting one makes the
|
||||
// Bambu network plugin unsubscribe the device, which drops the LAN session that connected it:
|
||||
// a connect still in flight fails, and one that already succeeded stays down with no connect
|
||||
// result to say so.
|
||||
const std::string dev_id = m_agent->get_user_selected_machine();
|
||||
const MachineObject* obj = get_my_machine(dev_id);
|
||||
if (obj && obj->is_lan_mode_printer())
|
||||
return;
|
||||
|
||||
m_agent->set_user_selected_machine(dev_id);
|
||||
}
|
||||
|
||||
std::map<std::string, MachineObject*> DeviceManager::get_my_machine_list(const std::string& agent_id)
|
||||
{
|
||||
std::map<std::string, MachineObject*> result;
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ public:
|
|||
void add_user_subscribe();
|
||||
void del_user_subscribe();
|
||||
void subscribe_device_list(std::vector<std::string> dev_list);
|
||||
// Selects the agent's selected machine again, which subscribes a cloud printer once the cloud
|
||||
// server has connected. A LAN printer is left as it is.
|
||||
void reselect_cloud_machine();
|
||||
|
||||
/* my machine*/
|
||||
MachineObject* get_my_machine(std::string dev_id);
|
||||
|
|
|
|||
|
|
@ -2345,12 +2345,14 @@ void GUI_App::init_networking_callbacks()
|
|||
if (provider != this->get_printer_cloud_provider()) {
|
||||
return;
|
||||
}
|
||||
m_agent->set_user_selected_machine(m_agent->get_user_selected_machine());
|
||||
if (m_device_manager)
|
||||
m_device_manager->reselect_cloud_machine();
|
||||
if (this->is_enable_multi_machine()) {
|
||||
auto evt = new wxCommandEvent(EVT_UPDATE_MACHINE_LIST);
|
||||
wxQueueEvent(this, evt);
|
||||
}
|
||||
m_agent->set_user_selected_machine(m_agent->get_user_selected_machine());
|
||||
if (m_device_manager)
|
||||
m_device_manager->reselect_cloud_machine();
|
||||
if (m_agent->is_user_login(provider)) {
|
||||
|
||||
/*disconnect lan*/
|
||||
|
|
@ -4558,6 +4560,11 @@ void GUI_App::select_machine(const std::string& agent_id)
|
|||
}
|
||||
}
|
||||
|
||||
// Orca: the print dialog blocks a printer whose type differs from the preset's model id, so the
|
||||
// type must be that id, not the model name. A model no vendor profile lists has no id; the
|
||||
// dialog accepts any printer then, and the name stays.
|
||||
const std::string model_id = preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle);
|
||||
|
||||
// If machine doesn't exist, create it first. The Orca agent never connects, so an entry saved
|
||||
// under it holds no binding; re-insert it for the active agent, whose machine list can't see
|
||||
// it otherwise. Entries bound by any other agent stay with that agent.
|
||||
|
|
@ -4567,7 +4574,7 @@ void GUI_App::select_machine(const std::string& agent_id)
|
|||
// We use dev_id as dev_ip to store the address (host:port)
|
||||
machine.dev_ip = dev_id;
|
||||
machine.dev_name = dev_id;
|
||||
machine.printer_type = preset.config.opt_string("printer_model");
|
||||
machine.printer_type = model_id.empty() ? preset.config.opt_string("printer_model") : model_id;
|
||||
|
||||
existing = m_device_manager->insert_local_device(
|
||||
machine, "lan", "free", "", access_code);
|
||||
|
|
@ -4581,6 +4588,11 @@ void GUI_App::select_machine(const std::string& agent_id)
|
|||
(!existing->has_access_right() || existing->get_access_code() != access_code)) {
|
||||
existing->set_access_code(access_code);
|
||||
}
|
||||
// Entries saved before held the model name; this printer's preset gives the id to repair them.
|
||||
if (!model_id.empty() && existing->printer_agent_id == agent_id && existing->printer_type != model_id) {
|
||||
existing->printer_type = model_id;
|
||||
DeviceManager::update_local_machine(*existing, app_config);
|
||||
}
|
||||
existing->local_use_ssl = boost::istarts_with(print_host, "https://");
|
||||
select_dev(dev_id);
|
||||
}
|
||||
|
|
@ -5325,12 +5337,12 @@ void GUI_App::persist_window_geometry(wxTopLevelWindow *window, bool default_max
|
|||
const std::string name = into_u8(window->GetName());
|
||||
|
||||
window->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent &event) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": received wxEVT_CLOSE_WINDOW, trigger save for window_mainframe";
|
||||
window_pos_save(window, "mainframe");
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": received wxEVT_CLOSE_WINDOW, trigger save for window_" << name;
|
||||
window_pos_save(window, name);
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
if (window_pos_restore(window, "mainframe", default_maximized)) {
|
||||
if (window_pos_restore(window, name, default_maximized)) {
|
||||
on_window_geometry(window, [=]() {
|
||||
window_pos_sanitize(window);
|
||||
});
|
||||
|
|
@ -10254,19 +10266,34 @@ bool GUI_App::window_pos_restore(wxTopLevelWindow* window, const std::string &na
|
|||
}
|
||||
|
||||
const wxRect& rect = metrics->get_rect();
|
||||
const bool maximized = metrics->get_maximized();
|
||||
#if defined(__WXGTK__)
|
||||
const bool on_x11 = !Slic3r::GUI::is_running_on_wayland();
|
||||
// On Wayland, SetPosition() is a no-op for top-level windows.
|
||||
// Only restore size and maximize state.
|
||||
if (!Slic3r::GUI::is_running_on_wayland())
|
||||
if (on_x11)
|
||||
#else
|
||||
constexpr bool on_x11 = false;
|
||||
#endif
|
||||
window->SetPosition(rect.GetPosition());
|
||||
window->SetSize(rect.GetSize());
|
||||
window->Maximize(metrics->get_maximized());
|
||||
// The rect saved for a maximized window is the maximized one. On X11 an
|
||||
// undecorated window that resizes itself to exactly the monitor rect is turned
|
||||
// into a fullscreen window by Mutter based WMs; the other ports need the resize
|
||||
// to give Restore Down the saved normal size. #17191
|
||||
if (! on_x11 || ! maximized)
|
||||
window->SetSize(rect.GetSize());
|
||||
window->Maximize(maximized);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GUI_App::window_pos_sanitize(wxTopLevelWindow* window)
|
||||
{
|
||||
#if defined(__WXGTK__)
|
||||
// On X11, moving or resizing a maximized or fullscreen window is read as a
|
||||
// fullscreen request by Mutter based WMs. #17191
|
||||
if (!Slic3r::GUI::is_running_on_wayland() && (window->IsMaximized() || window->IsFullScreen()))
|
||||
return;
|
||||
#endif
|
||||
|
||||
/*unsigned*/int display_idx = wxDisplay::GetFromWindow(window);
|
||||
wxRect display;
|
||||
if (display_idx == wxNOT_FOUND) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
#include "libslic3r/PresetBundle.hpp"
|
||||
#include "libslic3r/ModelArrange.hpp"
|
||||
#include "libslic3r/IMEXArrange.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include "libslic3r/GCode/WipeTower.hpp"
|
||||
|
||||
#include "slic3r/GUI/PartPlate.hpp"
|
||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||
|
|
@ -158,11 +161,58 @@ static WipeTower get_wipe_tower(const Plater &plater, int plate_idx)
|
|||
return WipeTower{plater.canvas3D()->get_wipe_tower_info(plate_idx)};
|
||||
}
|
||||
|
||||
arrangement::ArrangePolygon get_wipetower_arrange_poly(WipeTower* tower)
|
||||
// Orca: the gap in mm the arranger will leave around each of the objects it is about to place, which
|
||||
// is the smallest inflation update_selected_items_inflation() gives them. It is worked out on copies,
|
||||
// since the arrange jobs only inflate the objects after the tower is in place.
|
||||
static double arranged_object_gap(const arrangement::ArrangeParams& params, const ArrangePolygons& selected, const DynamicPrintConfig* print_cfg)
|
||||
{
|
||||
if (selected.empty())
|
||||
return 0.;
|
||||
arrangement::ArrangeParams params_copy = params;
|
||||
ArrangePolygons selected_copy = selected;
|
||||
update_selected_items_inflation(selected_copy, print_cfg, params_copy);
|
||||
const auto by_inflation = [](const ArrangePolygon& lhs, const ArrangePolygon& rhs) { return lhs.inflation < rhs.inflation; };
|
||||
return unscale<double>(std::min_element(selected_copy.begin(), selected_copy.end(), by_inflation)->inflation);
|
||||
}
|
||||
|
||||
// Orca: a prime tower compacted by "No sparse layers" stays low, so the toolhead comes down beside it
|
||||
// at every tool change. The objects in placed have to keep from it the clearance
|
||||
// compacted_tower_arrange_clearance() gives, as they do from one another when printing by object, so
|
||||
// the arranger is given the tower grown by that much, less the gap it keeps around those objects
|
||||
// anyway. params.compacted_tower says whether the tower is compacted at all; once grown,
|
||||
// params.compacted_tower_growth holds by how much (scaled) the polygon now reaches past the tower's
|
||||
// own zone, which the arranger needs to find the tower's Y span again.
|
||||
static void grow_compacted_wipe_tower(arrangement::ArrangePolygon& ap, arrangement::ArrangeParams& params, const ArrangePolygons& placed)
|
||||
{
|
||||
if (!params.compacted_tower || ap.poly.contour.points.empty())
|
||||
return;
|
||||
|
||||
// The config init_arrange_params() read params from.
|
||||
Plater* plater = wxGetApp().plater();
|
||||
const PrintConfig& config = plater->get_partplate_list().get_current_fff_print().config();
|
||||
// The tower's polygon holds its brim already, both the one of a tower already there and the
|
||||
// estimated one, so only the margin for the line width is left to add.
|
||||
const Polygons footprint = offset(ap.poly.contour, float(scale_(compacted_tower_footprint_padding(config, 0.))));
|
||||
if (footprint.empty())
|
||||
return;
|
||||
const CompactedTowerZone zone = compacted_wipe_tower_zone(config, footprint.front());
|
||||
if (zone.empty())
|
||||
return;
|
||||
const double clearance = compacted_tower_arrange_clearance(placed, params, zone.body_radius);
|
||||
const coord_t growth = scaled(std::max(0., clearance - arranged_object_gap(params, placed, plater->config())));
|
||||
const Polygons grown = offset(zone.hull, float(growth), jtRound, scale_(0.1));
|
||||
if (grown.empty())
|
||||
return;
|
||||
ap.poly.contour = grown.front();
|
||||
params.compacted_tower_growth = growth;
|
||||
}
|
||||
|
||||
arrangement::ArrangePolygon get_wipetower_arrange_poly(WipeTower* tower, arrangement::ArrangeParams& params, const ArrangePolygons& placed)
|
||||
{
|
||||
ArrangePolygon ap = tower->get_arrange_polygon();
|
||||
ap.bed_idx = 0;
|
||||
ap.setter = NULL; // do not move wipe tower
|
||||
grow_compacted_wipe_tower(ap, params, placed);
|
||||
return ap;
|
||||
}
|
||||
|
||||
|
|
@ -509,7 +559,7 @@ void ArrangeJob::prepare_wipe_tower()
|
|||
continue;
|
||||
if (auto wti = get_wipe_tower(*m_plater, bedid)) {
|
||||
// wipe tower is already there
|
||||
wipe_tower_ap = get_wipetower_arrange_poly(&wti);
|
||||
wipe_tower_ap = get_wipetower_arrange_poly(&wti, params, m_selected);
|
||||
wipe_tower_ap.bed_idx = bedid_unlocked;
|
||||
m_unselected.emplace_back(wipe_tower_ap);
|
||||
}
|
||||
|
|
@ -520,6 +570,7 @@ void ArrangeJob::prepare_wipe_tower()
|
|||
extruder_ids.insert(plate_extruders.begin(), plate_extruders.end());
|
||||
}
|
||||
wipe_tower_ap = estimate_wipe_tower_info(bedid, extruder_ids);
|
||||
grow_compacted_wipe_tower(wipe_tower_ap, params, m_selected);
|
||||
wipe_tower_ap.bed_idx = bedid_unlocked;
|
||||
m_unselected.emplace_back(wipe_tower_ap);
|
||||
}
|
||||
|
|
@ -585,7 +636,7 @@ void ArrangeJob::prepare_partplate() {
|
|||
|
||||
// BBS
|
||||
if (auto wti = get_wipe_tower(*m_plater, current_plate_index)) {
|
||||
ArrangePolygon&& ap = get_wipetower_arrange_poly(&wti);
|
||||
ArrangePolygon&& ap = get_wipetower_arrange_poly(&wti, params, m_selected);
|
||||
m_unselected.emplace_back(std::move(ap));
|
||||
}
|
||||
|
||||
|
|
@ -962,11 +1013,11 @@ void ArrangeJob::finalize(bool canceled, std::exception_ptr &eptr) {
|
|||
}
|
||||
|
||||
std::optional<arrangement::ArrangePolygon>
|
||||
get_wipe_tower_arrangepoly(const Plater &plater)
|
||||
get_wipe_tower_arrangepoly(const Plater &plater, arrangement::ArrangeParams ¶ms, const arrangement::ArrangePolygons &placed)
|
||||
{
|
||||
int id = plater.canvas3D()->fff_print()->get_plate_index();
|
||||
if (auto wti = get_wipe_tower(plater, id))
|
||||
return get_wipetower_arrange_poly(&wti);
|
||||
return get_wipetower_arrange_poly(&wti, params, placed);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
@ -994,6 +1045,7 @@ arrangement::ArrangeParams init_arrange_params(Plater *p)
|
|||
|
||||
params.clearance_height_to_rod = print_config.extruder_clearance_height_to_rod.value;
|
||||
params.clearance_height_to_lid = print_config.extruder_clearance_height_to_lid.value;
|
||||
params.clearance_dist_to_rod = print_config.extruder_clearance_dist_to_rod.value;
|
||||
params.clearance_radius = print_config.extruder_clearance_radius.value + object_skirt_offset * 2;
|
||||
params.object_skirt_offset = object_skirt_offset;
|
||||
params.printable_height = print_config.printable_height.value;
|
||||
|
|
@ -1034,6 +1086,11 @@ arrangement::ArrangeParams init_arrange_params(Plater *p)
|
|||
params.bed_shrink_x = BED_SHRINK_SEQ_PRINT;
|
||||
params.bed_shrink_y = BED_SHRINK_SEQ_PRINT;
|
||||
}
|
||||
|
||||
// Orca: the same condition as the slicer's clearance check for a compacted prime tower. Smooth
|
||||
// timelapse and wrapping detection keep the tower at full height, and printing by object has a
|
||||
// clearance check of its own.
|
||||
params.compacted_tower = !params.is_seq_print && wipe_tower_sparse_layers_skipped(print_config);
|
||||
return params;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,12 @@ public:
|
|||
void finalize(bool canceled, std::exception_ptr &e) override;
|
||||
};
|
||||
|
||||
std::optional<arrangement::ArrangePolygon> get_wipe_tower_arrangepoly(const Plater &);
|
||||
// The prime tower of the plate being sliced, to arrange around. A tower compacted by "No sparse
|
||||
// layers" comes grown by the clearance the objects in placed need from it, which is then recorded in
|
||||
// params; the inflation they will get counts towards it, so leave placed empty when they get none,
|
||||
// and the tower keeps the whole toolhead radius.
|
||||
std::optional<arrangement::ArrangePolygon> get_wipe_tower_arrangepoly(const Plater &, arrangement::ArrangeParams ¶ms,
|
||||
const arrangement::ArrangePolygons &placed = {});
|
||||
|
||||
// The gap between logical beds in the x axis expressed in ratio of
|
||||
// the current bed width.
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ void FillBedJob::prepare()
|
|||
|
||||
m_unselected.emplace_back(ap);
|
||||
}*/
|
||||
if (auto wt = get_wipe_tower_arrangepoly(*m_plater))
|
||||
if (auto wt = get_wipe_tower_arrangepoly(*m_plater, params, m_selected))
|
||||
m_unselected.emplace_back(std::move(*wt));
|
||||
|
||||
double sc = scaled<double>(1.) * scaled(1.);
|
||||
|
|
|
|||
|
|
@ -490,17 +490,28 @@ protected:
|
|||
page->SetSize(GetPageRect());
|
||||
}
|
||||
|
||||
virtual int DoSetSelection(size_t n, int flags = 0) override
|
||||
{
|
||||
m_target_page = GetPage(n);
|
||||
const int ret = wxBookCtrlBase::DoSetSelection(n, flags);
|
||||
m_target_page = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual void DoShowPage(wxWindow * page, bool show) override
|
||||
{
|
||||
if (show)
|
||||
page->ShowWithEffect(m_showEffect, m_showTimeout);
|
||||
else
|
||||
// Tabs may share one page window (Prepare/Preview -> m_plater). Hiding it just to re-show it
|
||||
// unmaps and remaps its GL canvases, which triggers a mutter subsurface bug on Wayland.
|
||||
else if (page != m_target_page)
|
||||
page->HideWithEffect(m_hideEffect, m_hideTimeout);
|
||||
}
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
wxWindow* m_target_page{nullptr}; // page being selected; DoShowPage must not hide it
|
||||
std::vector<wxString> m_pageNames; // index-parallel to wxBookCtrlBase::m_pages
|
||||
|
||||
wxShowEffect m_showEffect,
|
||||
|
|
|
|||
|
|
@ -3451,19 +3451,22 @@ std::vector<int> PartPlate::get_extruders_without_support(bool conside_custom_gc
|
|||
int PartPlate::get_physical_extruder_by_filament_id(const DynamicConfig& g_config, int idx) const
|
||||
{
|
||||
const std::vector<int>& filament_map = get_real_filament_maps(g_config);
|
||||
if (filament_map.size() < idx)
|
||||
if (idx <= 0 || idx > static_cast<int>(filament_map.size()))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const auto the_map = g_config.option<ConfigOptionInts>("physical_extruder_map");
|
||||
if (!the_map)
|
||||
// A multi-nozzle printer whose profile never sets physical_extruder_map carries the
|
||||
// single-element default, so the raw option cannot be indexed by logical extruder.
|
||||
const auto* nozzles = g_config.option<ConfigOptionFloats>("nozzle_diameter");
|
||||
const ConfigOptionInts pem = effective_physical_extruder_map(g_config.option<ConfigOptionInts>("physical_extruder_map"),
|
||||
nozzles ? static_cast<int>(nozzles->values.size()) : 0);
|
||||
const int zero_base_logical_idx = filament_map[idx - 1] - 1;
|
||||
if (zero_base_logical_idx < 0 || zero_base_logical_idx >= static_cast<int>(pem.values.size()))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int zero_base_logical_idx = filament_map[idx - 1] - 1;
|
||||
return the_map->values[zero_base_logical_idx];
|
||||
return pem.values[zero_base_logical_idx];
|
||||
}
|
||||
|
||||
int PartPlate::get_logical_extruder_by_filament_id(const DynamicConfig& g_config, int idx) const
|
||||
|
|
@ -6716,6 +6719,7 @@ int PartPlateList::delete_plate(int index)
|
|||
return -1;
|
||||
}
|
||||
const std::string plate_name = plate->get_plate_name();
|
||||
const std::vector<ObjectID> plate_ids_before = get_plate_ids();
|
||||
|
||||
if (m_plater) {
|
||||
// In GUI mode
|
||||
|
|
@ -6736,6 +6740,8 @@ int PartPlateList::delete_plate(int index)
|
|||
int old_cols = compute_colum_count(m_plate_list.size());
|
||||
|
||||
m_plate_list.erase(m_plate_list.begin() + index);
|
||||
// Orca: custom G-codes are keyed by plate index, so re-key them for the plates after it.
|
||||
remap_custom_gcodes(plate_ids_before);
|
||||
update_plate_cols();
|
||||
//update this plate
|
||||
//move this plate's instance to the end
|
||||
|
|
@ -7087,6 +7093,24 @@ int PartPlateList::move_plate_to_index(int old_index, int new_index)
|
|||
delta = -1;
|
||||
}
|
||||
|
||||
const std::vector<ObjectID> plate_ids_before = get_plate_ids();
|
||||
|
||||
// Orca: wipe tower positions are stored per plate index, so move them with the plate.
|
||||
if (m_plater) {
|
||||
DynamicConfig& proj_cfg = wxGetApp().preset_bundle->project_config;
|
||||
for (const char* key : { "wipe_tower_x", "wipe_tower_y" }) {
|
||||
ConfigOptionFloats* opt = proj_cfg.opt<ConfigOptionFloats>(key);
|
||||
if (opt->empty())
|
||||
continue;
|
||||
// Missing entries fall back to the first one; resize() fills them in with it.
|
||||
if (opt->size() < m_plate_list.size())
|
||||
opt->resize(m_plate_list.size());
|
||||
const double moved = opt->values[old_index];
|
||||
opt->values.erase(opt->values.begin() + old_index);
|
||||
opt->values.insert(opt->values.begin() + new_index, moved);
|
||||
}
|
||||
}
|
||||
|
||||
PartPlate* plate = m_plate_list[old_index];
|
||||
//update the plates between old_index and new_index
|
||||
for (unsigned int i = (unsigned int)old_index; i != (unsigned int)new_index; i = i + delta)
|
||||
|
|
@ -7105,9 +7129,48 @@ int PartPlateList::move_plate_to_index(int old_index, int new_index)
|
|||
//update the new plate index
|
||||
m_current_plate = new_index;
|
||||
|
||||
remap_custom_gcodes(plate_ids_before);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<ObjectID> PartPlateList::get_plate_ids() const
|
||||
{
|
||||
std::vector<ObjectID> ids;
|
||||
for (const PartPlate* plate : m_plate_list)
|
||||
ids.push_back(plate->id());
|
||||
return ids;
|
||||
}
|
||||
|
||||
void PartPlateList::remap_custom_gcodes(const std::vector<ObjectID>& plate_ids_before)
|
||||
{
|
||||
if (!m_model)
|
||||
return;
|
||||
|
||||
// Move each plate's entry into the map keyed by plate ID; entries without a plate keep their index.
|
||||
std::map<int, CustomGCode::Info> remapped;
|
||||
for (auto& [idx, info] : m_model->plates_custom_gcodes) {
|
||||
if (idx >= 0 && idx < (int)plate_ids_before.size())
|
||||
m_custom_gcodes_by_plate_id[plate_ids_before[idx]] = std::move(info);
|
||||
else
|
||||
remapped[idx] = std::move(info);
|
||||
}
|
||||
|
||||
// Put back the entries of plates that exist now.
|
||||
for (auto it = m_custom_gcodes_by_plate_id.begin(); it != m_custom_gcodes_by_plate_id.end();) {
|
||||
const ObjectID plate_id = it->first;
|
||||
auto plate = std::find_if(m_plate_list.begin(), m_plate_list.end(), [plate_id](const PartPlate* p) { return p->id() == plate_id; });
|
||||
if (plate == m_plate_list.end()) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
remapped[int(plate - m_plate_list.begin())] = std::move(it->second);
|
||||
it = m_custom_gcodes_by_plate_id.erase(it);
|
||||
}
|
||||
|
||||
m_model->plates_custom_gcodes = std::move(remapped);
|
||||
}
|
||||
|
||||
//lock plate
|
||||
int PartPlateList::lock_plate(int index, bool state)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "libslic3r/Color.hpp"
|
||||
#include "libslic3r/GCode/ThumbnailData.hpp"
|
||||
#include "libslic3r/PrintBase.hpp"
|
||||
#include "libslic3r/CustomGCode.hpp"
|
||||
#include <map>
|
||||
#include <cstddef>
|
||||
#include <cereal/access.hpp>
|
||||
|
|
@ -790,6 +791,8 @@ class PartPlateList : public ObjectBase
|
|||
PrinterTechnology printer_technology;
|
||||
|
||||
std::vector<PartPlate*> m_plate_list;
|
||||
// Orca: custom G-codes of plates removed by undo / redo, restored if the plate comes back.
|
||||
std::map<ObjectID, CustomGCode::Info> m_custom_gcodes_by_plate_id;
|
||||
std::map<int, PrintBase*> m_print_list;
|
||||
std::map<int, GCodeResult*> m_gcode_result_list;
|
||||
std::mutex m_plates_mutex;
|
||||
|
|
@ -1017,6 +1020,9 @@ public:
|
|||
|
||||
//move the plate to position index
|
||||
int move_plate_to_index(int old_index, int new_index);
|
||||
// Orca: custom G-codes are keyed by plate index; re-key them by plate ID after plates are reordered.
|
||||
std::vector<ObjectID> get_plate_ids() const;
|
||||
void remap_custom_gcodes(const std::vector<ObjectID>& plate_ids_before);
|
||||
|
||||
//lock plate
|
||||
int lock_plate(int index, bool state);
|
||||
|
|
|
|||
|
|
@ -2423,13 +2423,9 @@ bool Sidebar::priv::sync_extruder_list(bool &only_external_material, bool is_man
|
|||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " go on sync_extruder_list";
|
||||
const Preset &cur_preset = preset_bundle->printers.get_selected_preset();
|
||||
int extruder_nums = preset_bundle->get_printer_extruder_count();
|
||||
std::vector<int> extruder_map(extruder_nums);
|
||||
std::iota(extruder_map.begin(), extruder_map.end(), 0);
|
||||
const ConfigOptionInts *physical_extruder_map = cur_preset.config.option<ConfigOptionInts>("physical_extruder_map");
|
||||
if (physical_extruder_map != nullptr) {
|
||||
assert(physical_extruder_map->values.size() == extruder_nums);
|
||||
extruder_map = physical_extruder_map->values;
|
||||
}
|
||||
// A multi-nozzle profile that never sets physical_extruder_map carries the single-element default.
|
||||
const std::vector<int> extruder_map =
|
||||
effective_physical_extruder_map(cur_preset.config.option<ConfigOptionInts>("physical_extruder_map"), extruder_nums).values;
|
||||
assert(obj->GetExtderSystem()->GetTotalExtderCount() == extruder_nums);
|
||||
|
||||
// Multi-nozzle: resolve the nozzle option (pops MultiNozzleSyncDialog when is_manual). No-op for every
|
||||
|
|
@ -11420,7 +11416,9 @@ void Plater::find_new_position(const ModelInstancePtrs &instances)
|
|||
}
|
||||
}
|
||||
|
||||
if (auto wt = get_wipe_tower_arrangepoly(*this))
|
||||
// The objects placed here are not inflated, so none are passed and the tower keeps the whole
|
||||
// toolhead radius.
|
||||
if (auto wt = get_wipe_tower_arrangepoly(*this, arr_params))
|
||||
fixed.emplace_back(*wt);
|
||||
|
||||
arrangement::arrange(movable, fixed, this->build_volume().polygon(), arr_params);
|
||||
|
|
@ -16085,10 +16083,13 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator
|
|||
|
||||
// Make a copy of the snapshot, undo/redo could invalidate the iterator
|
||||
const UndoRedo::Snapshot snapshot_copy = *it_snapshot;
|
||||
// Orca: custom G-codes are not in the snapshot, so remap them by plate ID after the jump.
|
||||
const std::vector<ObjectID> plate_ids_before = this->partplate_list.get_plate_ids();
|
||||
// Do the jump in time.
|
||||
if (it_snapshot->timestamp < this->undo_redo_stack().active_snapshot_time() ?
|
||||
this->undo_redo_stack().undo(model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_selection() : this->view3D->get_canvas3d()->get_selection(), get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : this->view3D->get_canvas3d()->get_gizmos_manager(), this->partplate_list, top_snapshot_data, it_snapshot->timestamp) :
|
||||
this->undo_redo_stack().redo(model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : this->view3D->get_canvas3d()->get_gizmos_manager(), this->partplate_list, it_snapshot->timestamp)) {
|
||||
this->partplate_list.remap_custom_gcodes(plate_ids_before);
|
||||
if (printer_technology_changed) {
|
||||
// Switch to the other printer technology. Switch to the last printer active for that particular technology.
|
||||
AppConfig *app_config = wxGetApp().app_config;
|
||||
|
|
@ -16135,7 +16136,7 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator
|
|||
tower_x_opt->set_at(&tower_x_new, plate_idx, 0);
|
||||
tower_y_opt->set_at(&tower_y_new, plate_idx, 0);
|
||||
need_update = true;
|
||||
break;
|
||||
// Orca: restore every plate, moving a plate changes several positions
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -471,10 +471,14 @@ ModelObject *Selection::get_selected_single_object(int &out_object_idx) const
|
|||
|
||||
const ModelInstance *Selection::get_selected_single_intance() const
|
||||
{
|
||||
const int instance_idx = get_instance_idx();
|
||||
if (instance_idx < 0)
|
||||
return nullptr;
|
||||
|
||||
int object_idx;
|
||||
auto mo = get_selected_single_object(object_idx);
|
||||
if (mo) {
|
||||
return mo->instances[get_instance_idx()];
|
||||
return mo->instances[instance_idx];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "slic3r/Utils/NetworkAgent.hpp"
|
||||
#include "libslic3r_version.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/gdicmn.h>
|
||||
|
|
@ -31,6 +32,9 @@
|
|||
#include <wx/string.h>
|
||||
#include <wx/timer.h>
|
||||
#include <wx/toolbar.h>
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/display.h>
|
||||
#include <wx/toplevel.h>
|
||||
#include <wx/textdlg.h>
|
||||
|
||||
#include <wx/webview.h>
|
||||
|
|
@ -108,7 +112,8 @@ int ZUserLogin::ensure_loopback_port()
|
|||
}
|
||||
|
||||
ZUserLogin::ZUserLogin(std::shared_ptr<ICloudServiceAgent> cloud_agent)
|
||||
: wxDialog((wxWindow*) (wxGetApp().mainframe), wxID_ANY, "OrcaSlicer"), m_cloud_agent(cloud_agent)
|
||||
: wxDialog((wxWindow*) (wxGetApp().mainframe), wxID_ANY, "OrcaSlicer", wxDefaultPosition, wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), m_cloud_agent(cloud_agent)
|
||||
{
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
|
||||
|
|
@ -183,6 +188,13 @@ ZUserLogin::ZUserLogin(std::shared_ptr<ICloudServiceAgent> cloud_agent)
|
|||
m_browser->Hide();
|
||||
m_browser->SetSize(0, 0);
|
||||
|
||||
// The webview fills the dialog, so it follows the dialog when the user resizes it.
|
||||
// Plain SetSizer: the webview is still hidden and 0x0 here, so fitting would collapse the dialog;
|
||||
// the size is set explicitly below.
|
||||
auto* browser_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
browser_sizer->Add(m_browser, 1, wxEXPAND);
|
||||
SetSizer(browser_sizer);
|
||||
|
||||
// Connect the webview events
|
||||
Bind(wxEVT_WEBVIEW_NAVIGATING, &ZUserLogin::OnNavigationRequest, this, m_browser->GetId());
|
||||
Bind(wxEVT_WEBVIEW_NAVIGATED, &ZUserLogin::OnNavigationComplete, this, m_browser->GetId());
|
||||
|
|
@ -196,10 +208,23 @@ ZUserLogin::ZUserLogin(std::shared_ptr<ICloudServiceAgent> cloud_agent)
|
|||
// UI
|
||||
SetTitle(_L("Login"));
|
||||
// Set a more sensible size for web browsing
|
||||
wxSize pSize = FromDIP(wxSize(650, 840));
|
||||
SetSize(pSize);
|
||||
// The preferred size can exceed the work area (e.g. 840 DIP at 150% on a 1080p screen),
|
||||
// which would push the title bar off screen, so clamp it to the display the dialog is on.
|
||||
const wxRect work_area = wxDisplay(GetParent()).GetClientArea();
|
||||
const int margin = FromDIP(20);
|
||||
const wxSize max_size(std::max(1, work_area.GetWidth() - margin), std::max(1, work_area.GetHeight() - margin));
|
||||
|
||||
const wxSize pSize = FromDIP(wxSize(650, 840));
|
||||
SetMinSize(wxSize(std::min(FromDIP(400), max_size.GetWidth()), std::min(FromDIP(400), max_size.GetHeight())));
|
||||
SetSize(wxSize(std::min(pSize.GetWidth(), max_size.GetWidth()), std::min(pSize.GetHeight(), max_size.GetHeight())));
|
||||
|
||||
CentreOnParent();
|
||||
|
||||
// Keep the whole dialog, title bar included, inside the work area.
|
||||
wxRect rect = GetRect();
|
||||
rect.x = std::max(work_area.GetLeft(), std::min(rect.x, work_area.GetRight() + 1 - rect.width));
|
||||
rect.y = std::max(work_area.GetTop(), std::min(rect.y, work_area.GetBottom() + 1 - rect.height));
|
||||
Move(rect.GetPosition());
|
||||
}
|
||||
wxGetApp().UpdateDlgDarkUI(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,7 +367,9 @@ static void init_multi_extruder_params_for_cali(DynamicPrintConfig& config, cons
|
|||
nozzle_volume_types.clear();
|
||||
nozzle_volume_types.resize(extruder_count, (int)calib_info.nozzle_volume_type);
|
||||
|
||||
std::vector<int> physical_extruder_maps = dynamic_cast<ConfigOptionInts*>(config.option("physical_extruder_map", true))->values;
|
||||
// One entry per nozzle even when the profile never set the map (the single-element default).
|
||||
const std::vector<int> physical_extruder_maps =
|
||||
effective_physical_extruder_map(config.option<ConfigOptionInts>("physical_extruder_map", true), extruder_count).values;
|
||||
int extruder_id = calib_info.extruder_id;
|
||||
for (size_t index = 0; index < extruder_count; ++index) {
|
||||
if (physical_extruder_maps[index] == extruder_id)
|
||||
|
|
@ -969,7 +971,8 @@ void CalibUtils::set_for_auto_pa_model_and_config(const std::vector<CalibInfo> &
|
|||
nozzle_flush_dataset.resize(extruder_count, 0);
|
||||
|
||||
int filament_nums = calib_infos.size();
|
||||
std::vector<int> physical_extruder_maps = dynamic_cast<ConfigOptionInts *>(full_config.option("physical_extruder_map", true))->values;
|
||||
const std::vector<int> physical_extruder_maps =
|
||||
effective_physical_extruder_map(full_config.option<ConfigOptionInts>("physical_extruder_map", true), extruder_count).values;
|
||||
for (size_t filament_index = 0; filament_index < calib_infos.size(); ++filament_index) {
|
||||
CalibInfo calib_info = calib_infos[filament_index];
|
||||
int extruder_id = calib_info.extruder_id;
|
||||
|
|
@ -1055,7 +1058,10 @@ bool CalibUtils::calib_generic_auto_pa_cali(const std::vector<CalibInfo> &calib_
|
|||
std::vector<Preset> filament_presets;
|
||||
std::vector<int> filament_map;
|
||||
filament_map.resize(calib_infos.size());
|
||||
std::vector<int> physical_extruder_maps = dynamic_cast<ConfigOptionInts *>(printer_config.option("physical_extruder_map", true))->values;
|
||||
const auto* nozzle_diameters = printer_config.option<ConfigOptionFloats>("nozzle_diameter");
|
||||
const int nozzle_count = nozzle_diameters ? static_cast<int>(nozzle_diameters->values.size()) : 0;
|
||||
const std::vector<int> physical_extruder_maps =
|
||||
effective_physical_extruder_map(printer_config.option<ConfigOptionInts>("physical_extruder_map", true), nozzle_count).values;
|
||||
for (size_t i = 0; i < calib_infos.size(); ++i) {
|
||||
CalibInfo calib_info = calib_infos[i];
|
||||
calib_info.filament_prest->config.set_key_value("curr_bed_type", new ConfigOptionEnum<BedType>(calib_info.bed_type));
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
#include <boost/nowide/convert.hpp>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <wx/progdlg.h>
|
||||
|
|
@ -162,7 +164,11 @@ bool CrealityPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn,
|
|||
|
||||
auto http = Http::post(url); // std::move(url));
|
||||
set_auth(http);
|
||||
if (!supports_multi_color_print())
|
||||
// Multi-color models get no folder with the upload, so they keep it right under printer_data/gcodes.
|
||||
const bool multi_color = supports_multi_color_print();
|
||||
const auto remote_path = multi_color || upload_parent_path.empty() ? safe_upload_filename :
|
||||
(upload_parent_path / safe_upload_filename).generic_string();
|
||||
if (!multi_color)
|
||||
http.form_add("path", upload_parent_path.string());
|
||||
http.form_add_file("file", upload_data.source_path.string(), safe_upload_filename)
|
||||
|
||||
|
|
@ -171,7 +177,7 @@ bool CrealityPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn,
|
|||
|
||||
if (upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
|
||||
wxString errormsg;
|
||||
if (!start_print(errormsg, safe_upload_filename, upload_data.extended_info)) {
|
||||
if (!start_print(errormsg, remote_path, upload_data.extended_info)) {
|
||||
error_fn(std::move(errormsg));
|
||||
res = false;
|
||||
}
|
||||
|
|
@ -278,24 +284,15 @@ static int reported_cfs_connect(const std::string& msg)
|
|||
return cfs_connect == 1 ? 1 : -1;
|
||||
}
|
||||
|
||||
// Sends the CFS slot query and returns the reply, or nothing when none arrives in time.
|
||||
// The query gets slots_reply, or the later of slots_reply and cfs_reply once a status reports a CFS connected, since such a printer does answer.
|
||||
// A status reporting no CFS connected cuts the wait to no_cfs_reply from then, and sets *no_cfs if no reply follows: a SPARKX i7
|
||||
// reports no CFS connected for its CFS Lite and still sends the slots.
|
||||
static std::string ws_query_slots(net::io_context& ioc,
|
||||
websocket::stream<beast::tcp_stream>& ws,
|
||||
std::chrono::milliseconds slots_reply,
|
||||
std::chrono::milliseconds cfs_reply,
|
||||
std::chrono::milliseconds no_cfs_reply,
|
||||
bool* no_cfs)
|
||||
// Reads the printer's messages until one holds key and returns it, or returns nothing once deadline passes or on_other, which gets
|
||||
// every other message, returns false. The deadline also ends the read when the printer keeps sending heartbeats or status updates.
|
||||
template<class OnOther>
|
||||
static std::string ws_await_reply(net::io_context& ioc,
|
||||
websocket::stream<beast::tcp_stream>& ws,
|
||||
const std::chrono::steady_clock::time_point& deadline,
|
||||
const char* key,
|
||||
OnOther&& on_other)
|
||||
{
|
||||
const auto sent = std::chrono::steady_clock::now();
|
||||
auto deadline = sent + slots_reply;
|
||||
bool reported_no_cfs = false;
|
||||
beast::get_lowest_layer(ws).expires_at(deadline);
|
||||
ws_send(ioc, ws, json{{"method", "get"}, {"params", {{"boxsInfo", 1}}}});
|
||||
|
||||
// The deadline also ends the read when the printer keeps sending heartbeats or status updates.
|
||||
while (std::chrono::steady_clock::now() < deadline) {
|
||||
beast::flat_buffer buf;
|
||||
const beast::error_code ec = ws_read(ioc, ws, buf);
|
||||
|
|
@ -310,8 +307,32 @@ static std::string ws_query_slots(net::io_context& ioc,
|
|||
ws_write(ioc, ws, "ok");
|
||||
continue;
|
||||
}
|
||||
if (msg.find("boxsInfo") != std::string::npos)
|
||||
if (msg.find(key) != std::string::npos)
|
||||
return msg;
|
||||
if (!on_other(msg))
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Sends the CFS slot query and returns the reply, or nothing when none arrives in time.
|
||||
// The query gets slots_reply, or the later of slots_reply and cfs_reply once a status reports a CFS connected, since such a printer does answer.
|
||||
// A status reporting no CFS connected cuts the wait to no_cfs_reply from then, and sets *no_cfs if no reply follows: a SPARKX i7
|
||||
// reports no CFS connected for its CFS Lite and still sends the slots.
|
||||
static std::string ws_query_slots(net::io_context& ioc,
|
||||
websocket::stream<beast::tcp_stream>& ws,
|
||||
std::chrono::milliseconds slots_reply,
|
||||
std::chrono::milliseconds cfs_reply,
|
||||
std::chrono::milliseconds no_cfs_reply,
|
||||
bool* no_cfs)
|
||||
{
|
||||
const auto sent = std::chrono::steady_clock::now();
|
||||
auto deadline = sent + slots_reply;
|
||||
beast::get_lowest_layer(ws).expires_at(deadline);
|
||||
ws_send(ioc, ws, json{{"method", "get"}, {"params", {{"boxsInfo", 1}}}});
|
||||
|
||||
bool reported_no_cfs = false;
|
||||
const std::string reply = ws_await_reply(ioc, ws, deadline, "boxsInfo", [&](const std::string& msg) {
|
||||
const int cfs_connect = reported_cfs_connect(msg);
|
||||
if (cfs_connect == 0 && !reported_no_cfs) {
|
||||
reported_no_cfs = true;
|
||||
|
|
@ -323,15 +344,94 @@ static std::string ws_query_slots(net::io_context& ioc,
|
|||
deadline = sent + std::max(slots_reply, cfs_reply);
|
||||
beast::get_lowest_layer(ws).expires_at(deadline);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (!reply.empty())
|
||||
return reply;
|
||||
if (reported_no_cfs) {
|
||||
BOOST_LOG_TRIVIAL(info) << "CrealityPrint: The printer reports no CFS connected";
|
||||
if (no_cfs)
|
||||
*no_cfs = true;
|
||||
return {};
|
||||
} else
|
||||
BOOST_LOG_TRIVIAL(warning) << "CrealityPrint: Timed out waiting for a 'boxsInfo' response";
|
||||
return reply;
|
||||
}
|
||||
|
||||
// The full path a reply to reqGcodeFile lists remote_path at, an empty string when it does not list it, or nothing when the reply
|
||||
// is no list this code reads. K2-family firmware answers retGcodeFileInfo2, a list of files with their path. K1-family firmware
|
||||
// answers retGcodeFileInfo, whose fileInfo holds "folder:name:size:..." entries separated by ';'.
|
||||
static std::optional<std::string> listed_gcode_path(const std::string& reply_text, const std::string& remote_path)
|
||||
{
|
||||
const json reply = json::parse(reply_text, nullptr, false);
|
||||
if (!reply.is_object())
|
||||
return std::nullopt;
|
||||
const std::string under_gcodes = "/printer_data/gcodes/" + remote_path;
|
||||
|
||||
if (const auto files = reply.find("retGcodeFileInfo2"); files != reply.end() && files->is_array()) {
|
||||
for (const json& file : *files)
|
||||
if (file.is_object() && file.contains("path") && file.at("path").is_string() &&
|
||||
boost::algorithm::ends_with(file.at("path").get<std::string>(), under_gcodes))
|
||||
return file.at("path").get<std::string>();
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const auto info = reply.find("retGcodeFileInfo");
|
||||
if (info == reply.end() || !info->is_object() || !info->contains("fileInfo") || !info->at("fileInfo").is_string())
|
||||
return std::nullopt;
|
||||
// Finds the name between its folder and its size, so a name holding ';' or ':' is found too.
|
||||
const std::string file_info = info->at("fileInfo").get<std::string>();
|
||||
const std::string name = remote_path.substr(remote_path.rfind('/') + 1);
|
||||
const std::string field = ':' + name + ':';
|
||||
for (size_t at = file_info.find(field); at != std::string::npos; at = file_info.find(field, at + 1)) {
|
||||
const size_t entry = file_info.rfind(';', at);
|
||||
const size_t begin = entry == std::string::npos ? 0 : entry + 1;
|
||||
const std::string path = file_info.substr(begin, at - begin) + '/' + name;
|
||||
if (boost::algorithm::ends_with(path, under_gcodes))
|
||||
return path;
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
namespace {
|
||||
// What the printer's G-code file list says about an upload.
|
||||
struct GcodeListing
|
||||
{
|
||||
enum class Result { NoReply, Unreadable, NotListed, Listed } result = Result::NoReply;
|
||||
std::string path; // The full path the upload is listed at
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// Asks for the G-code file list until it lists remote_path or files_reply passes. A printer can answer before it has indexed a
|
||||
// file just uploaded, so a list without the upload is asked for again after files_retry.
|
||||
static GcodeListing ws_find_listed_gcode(net::io_context& ioc,
|
||||
websocket::stream<beast::tcp_stream>& ws,
|
||||
std::chrono::milliseconds files_reply,
|
||||
std::chrono::milliseconds files_retry,
|
||||
const std::string& remote_path)
|
||||
{
|
||||
const auto deadline = std::chrono::steady_clock::now() + files_reply;
|
||||
GcodeListing listing;
|
||||
for (;;) {
|
||||
beast::get_lowest_layer(ws).expires_at(deadline);
|
||||
ws_send(ioc, ws, json{{"method", "get"}, {"params", {{"reqGcodeFile", 1}}}});
|
||||
const std::string reply = ws_await_reply(ioc, ws, deadline, "retGcodeFileInfo", [](const std::string&) { return true; });
|
||||
if (reply.empty())
|
||||
return listing;
|
||||
const std::optional<std::string> path = listed_gcode_path(reply, remote_path);
|
||||
if (!path) {
|
||||
listing.result = GcodeListing::Result::Unreadable;
|
||||
return listing;
|
||||
}
|
||||
if (!path->empty()) {
|
||||
listing.result = GcodeListing::Result::Listed;
|
||||
listing.path = *path;
|
||||
return listing;
|
||||
}
|
||||
listing.result = GcodeListing::Result::NotListed;
|
||||
if (std::chrono::steady_clock::now() + files_retry >= deadline)
|
||||
return listing;
|
||||
std::this_thread::sleep_for(files_retry);
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(warning) << "CrealityPrint: Timed out waiting for a 'boxsInfo' response";
|
||||
return {};
|
||||
}
|
||||
|
||||
// The K1 SE closes its side after a reply and K1-family printers after a start command, so a close error is not a failure.
|
||||
|
|
@ -341,7 +441,8 @@ static void ws_close(net::io_context& ioc, websocket::stream<beast::tcp_stream>&
|
|||
run_until_done(ioc, [&](auto&& handler) { ws.async_close(websocket::close_code::normal, handler); });
|
||||
}
|
||||
|
||||
// Add a model by its /info value once its firmware is known to keep gcodes under /usr/data; every other model uses /mnt/UDISK.
|
||||
// The folder for a printer that lists no G-code file. Add a model by its /info value once its firmware is known to keep gcodes
|
||||
// under /usr/data; every other model uses /mnt/UDISK.
|
||||
static bool stores_gcode_in_usr_data(const std::string& model)
|
||||
{
|
||||
static const std::unordered_set<std::string> usr_data_models = {
|
||||
|
|
@ -351,6 +452,7 @@ static bool stores_gcode_in_usr_data(const std::string& model)
|
|||
"F004", // Ender-5 Max
|
||||
"F005", // Ender-3 V3 KE
|
||||
"F016", // K2 SE
|
||||
"Ender-3 V2 Neo", // Nebula Pad on an Ender-3 V2 Neo
|
||||
"K1",
|
||||
"K1 Max",
|
||||
"K1 Max_CFS-C",
|
||||
|
|
@ -440,6 +542,45 @@ std::string CrealityPrint::query_boxes_info(bool* no_cfs) const
|
|||
}
|
||||
}
|
||||
|
||||
// Uses a connection of its own, since the K1 SE closes its side after a reply. A failed connection is not caught: the start would
|
||||
// fail the same way, and trying again would double the wait.
|
||||
std::string CrealityPrint::query_listed_gcode(const std::string& remote_path) const
|
||||
{
|
||||
net::io_context ioc;
|
||||
websocket::stream<beast::tcp_stream> ws{ioc};
|
||||
ws_connect(ioc, ws, m_host, ws_settings.port, ws_settings.connect);
|
||||
|
||||
GcodeListing listing;
|
||||
try {
|
||||
listing = ws_find_listed_gcode(ioc, ws, ws_settings.files_reply, ws_settings.files_retry, remote_path);
|
||||
} catch (std::exception const& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "CrealityPrint: Failed to query the G-code file list: " << e.what();
|
||||
return {};
|
||||
}
|
||||
switch (listing.result) {
|
||||
case GcodeListing::Result::Listed:
|
||||
BOOST_LOG_TRIVIAL(info) << "CrealityPrint: The printer lists " << remote_path << " at " << listing.path;
|
||||
break;
|
||||
case GcodeListing::Result::NotListed:
|
||||
BOOST_LOG_TRIVIAL(warning) << "CrealityPrint: The printer's G-code file list does not include " << remote_path;
|
||||
break;
|
||||
case GcodeListing::Result::Unreadable:
|
||||
BOOST_LOG_TRIVIAL(warning) << "CrealityPrint: The printer's G-code file list has no format this host reads";
|
||||
break;
|
||||
case GcodeListing::Result::NoReply:
|
||||
BOOST_LOG_TRIVIAL(warning) << "CrealityPrint: Timed out waiting for the G-code file list";
|
||||
break;
|
||||
}
|
||||
|
||||
// A printer that sent no list may not answer a close either, so its connection is dropped without one.
|
||||
if (listing.result == GcodeListing::Result::NoReply) {
|
||||
beast::error_code ec;
|
||||
beast::get_lowest_layer(ws).socket().close(ec);
|
||||
} else
|
||||
ws_close(ioc, ws, ws_settings.close);
|
||||
return listing.path;
|
||||
}
|
||||
|
||||
CrealityPrinterInfo CrealityPrint::read_printer_info() const
|
||||
{
|
||||
CrealityPrinterInfo info;
|
||||
|
|
@ -528,14 +669,21 @@ std::vector<std::string> CrealityPrint::start_print_commands(bool
|
|||
return commands;
|
||||
}
|
||||
|
||||
bool CrealityPrint::start_print(wxString &msg, const std::string &filename, const std::map<std::string, std::string>& extended_info) const
|
||||
bool CrealityPrint::start_print(wxString &msg, const std::string &remote_path, const std::map<std::string, std::string>& extended_info) const
|
||||
{
|
||||
try {
|
||||
// Runs before the WebSocket opens and its reply deadline starts, since it can query the
|
||||
// printer over HTTP. It also fills m_model.
|
||||
const bool multi_color = supports_multi_color_print();
|
||||
const std::string data_root = stores_gcode_in_usr_data(m_model) ? "/usr/data" : "/mnt/UDISK";
|
||||
const std::string gcode_path = data_root + "/printer_data/gcodes/" + filename;
|
||||
const bool multi_color = supports_multi_color_print();
|
||||
// Starts the file at the path the printer lists it at, as Creality Print does, since the
|
||||
// folder depends on the printer's board and not on its model. The model decides only when
|
||||
// the printer does not list the upload.
|
||||
std::string gcode_path = query_listed_gcode(remote_path);
|
||||
if (gcode_path.empty()) {
|
||||
const std::string data_root = stores_gcode_in_usr_data(m_model) ? "/usr/data" : "/mnt/UDISK";
|
||||
gcode_path = data_root + "/printer_data/gcodes/" + remote_path.substr(remote_path.rfind('/') + 1);
|
||||
BOOST_LOG_TRIVIAL(info) << "CrealityPrint: Using " << data_root << " for model " << m_model;
|
||||
}
|
||||
|
||||
net::io_context ioc;
|
||||
websocket::stream<beast::tcp_stream> ws{ioc};
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ protected:
|
|||
std::chrono::milliseconds reply{std::chrono::seconds(10)}; // Commands and the replies read after them
|
||||
std::chrono::milliseconds slots_reply{std::chrono::seconds(5)}; // The CFS slot query, extended to reply once a status reports a CFS connected
|
||||
std::chrono::milliseconds no_cfs_reply{std::chrono::seconds(2)}; // The CFS slot query once a status reports no CFS connected
|
||||
std::chrono::milliseconds files_reply{std::chrono::seconds(3)}; // The G-code file list query before a start, asked again within it
|
||||
std::chrono::milliseconds files_retry{std::chrono::milliseconds(500)}; // The pause before asking again for a list without the upload
|
||||
std::chrono::milliseconds close{std::chrono::seconds(3)}; // Closing handshake
|
||||
} ws_settings;
|
||||
|
||||
|
|
@ -83,7 +85,10 @@ private:
|
|||
mutable std::string m_model;
|
||||
|
||||
std::string make_url(const std::string& path) const;
|
||||
bool start_print(wxString& msg, const std::string& filename, const std::map<std::string, std::string>& extended_info) const;
|
||||
// remote_path is where the upload went under printer_data/gcodes.
|
||||
bool start_print(wxString& msg, const std::string& remote_path, const std::map<std::string, std::string>& extended_info) const;
|
||||
// The full path the printer lists remote_path at, or nothing when it does not list it. Throws when the printer cannot be reached.
|
||||
std::string query_listed_gcode(const std::string& remote_path) const;
|
||||
std::string safe_filename(const std::string& filename) const;
|
||||
void query_model() const;
|
||||
// Reads /info and caches the model. When msg is not null, it gets a translated error, or on Windows the resolved address.
|
||||
|
|
|
|||
|
|
@ -464,8 +464,17 @@ namespace Slic3r {
|
|||
}
|
||||
bool ElegooLink::test(wxString &curl_msg) const{
|
||||
switch (classify_printer_model(m_printerModel)) {
|
||||
case ElegooPrinterType::Other:
|
||||
return OctoPrint::test(curl_msg);
|
||||
case ElegooPrinterType::Other: {
|
||||
if (OctoPrint::test(curl_msg))
|
||||
return true;
|
||||
// A custom preset can have any printer_model, so an SDCP printer may land here too.
|
||||
// If that check fails as well, keep the OctoPrint error for the user.
|
||||
wxString sdcp_msg;
|
||||
if (!elegoo_test(sdcp_msg))
|
||||
return false;
|
||||
curl_msg = sdcp_msg;
|
||||
return true;
|
||||
}
|
||||
case ElegooPrinterType::CC2:
|
||||
return elegoo_cc2_test(curl_msg);
|
||||
case ElegooPrinterType::CC:
|
||||
|
|
@ -556,19 +565,6 @@ namespace Slic3r {
|
|||
|
||||
return res;
|
||||
}
|
||||
bool ElegooLink::test_with_resolved_ip(wxString& msg) const
|
||||
{
|
||||
switch (classify_printer_model(m_printerModel)) {
|
||||
case ElegooPrinterType::Other:
|
||||
return OctoPrint::test_with_resolved_ip(msg);
|
||||
case ElegooPrinterType::CC2:
|
||||
return elegoo_cc2_test_with_resolved_ip(msg);
|
||||
case ElegooPrinterType::CC:
|
||||
return elegoo_test_with_resolved_ip(msg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ElegooLink::elegoo_cc2_test_with_resolved_ip(wxString& msg) const
|
||||
{
|
||||
const char* name = get_name();
|
||||
|
|
@ -623,11 +619,13 @@ namespace Slic3r {
|
|||
{
|
||||
const auto printer_type = classify_printer_model(m_printerModel);
|
||||
|
||||
if (printer_type == ElegooPrinterType::Other)
|
||||
return OctoPrint::upload_inner_with_resolved_ip(std::move(upload_data), prorgess_fn, error_fn, info_fn, resolved_addr);
|
||||
|
||||
info_fn(L"resolve", boost::nowide::widen(resolved_addr.to_string()));
|
||||
|
||||
// Other may be an SDCP printer: fall back to SDCP, but report the OctoPrint error if that fails too.
|
||||
wxString octoprint_msg = GUI::from_u8(resolved_addr.to_string());
|
||||
if (printer_type == ElegooPrinterType::Other && OctoPrint::test_with_resolved_ip(octoprint_msg))
|
||||
return upload_after_test_with_resolved_ip(std::move(upload_data), prorgess_fn, error_fn, info_fn, resolved_addr);
|
||||
|
||||
if (printer_type == ElegooPrinterType::CC2) {
|
||||
wxString cc2_msg = GUI::from_u8(resolved_addr.to_string());
|
||||
if (!elegoo_cc2_test_with_resolved_ip(cc2_msg)) {
|
||||
|
|
@ -642,7 +640,7 @@ namespace Slic3r {
|
|||
|
||||
wxString legacy_msg = GUI::from_u8(resolved_addr.to_string());
|
||||
if (!elegoo_test_with_resolved_ip(legacy_msg)) {
|
||||
error_fn(std::move(legacy_msg));
|
||||
error_fn(std::move(printer_type == ElegooPrinterType::Other ? octoprint_msg : legacy_msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -658,8 +656,10 @@ namespace Slic3r {
|
|||
{
|
||||
const auto printer_type = classify_printer_model(m_printerModel);
|
||||
|
||||
if (printer_type == ElegooPrinterType::Other)
|
||||
return OctoPrint::upload_inner_with_host(std::move(upload_data), prorgess_fn, error_fn, info_fn);
|
||||
// Other may be an SDCP printer: fall back to SDCP, but report the OctoPrint error if that fails too.
|
||||
wxString octoprint_msg;
|
||||
if (printer_type == ElegooPrinterType::Other && OctoPrint::test(octoprint_msg))
|
||||
return upload_after_test_with_host(std::move(upload_data), prorgess_fn, error_fn, info_fn, octoprint_msg);
|
||||
|
||||
if (printer_type == ElegooPrinterType::CC2) {
|
||||
wxString cc2_msg;
|
||||
|
|
@ -688,7 +688,7 @@ namespace Slic3r {
|
|||
|
||||
wxString legacy_msg;
|
||||
if(!elegoo_test(legacy_msg)){
|
||||
error_fn(std::move(legacy_msg));
|
||||
error_fn(std::move(printer_type == ElegooPrinterType::Other ? octoprint_msg : legacy_msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ protected:
|
|||
virtual bool upload_inner_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override;
|
||||
|
||||
#ifdef WIN32
|
||||
virtual bool test_with_resolved_ip(wxString& curl_msg) const override;
|
||||
bool elegoo_test_with_resolved_ip(wxString& curl_msg) const;
|
||||
#endif
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -348,6 +348,11 @@ bool OctoPrint::upload_inner_with_resolved_ip(PrintHostUpload upload_data, Progr
|
|||
return false;
|
||||
}
|
||||
|
||||
return upload_after_test_with_resolved_ip(std::move(upload_data), prorgess_fn, error_fn, info_fn, resolved_addr);
|
||||
}
|
||||
|
||||
bool OctoPrint::upload_after_test_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn, const boost::asio::ip::address& resolved_addr) const
|
||||
{
|
||||
const char* name = get_name();
|
||||
const auto upload_filename = upload_data.upload_path.filename();
|
||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||
|
|
@ -408,11 +413,6 @@ bool OctoPrint::upload_inner_with_resolved_ip(PrintHostUpload upload_data, Progr
|
|||
|
||||
bool OctoPrint::upload_inner_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const
|
||||
{
|
||||
const char* name = get_name();
|
||||
|
||||
const auto upload_filename = upload_data.upload_path.filename();
|
||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||
|
||||
// If test fails, test_msg_or_host_ip contains the error message.
|
||||
// Otherwise on Windows it contains the resolved IP address of the host.
|
||||
wxString test_msg_or_host_ip;
|
||||
|
|
@ -421,6 +421,16 @@ bool OctoPrint::upload_inner_with_host(PrintHostUpload upload_data, ProgressFn p
|
|||
return false;
|
||||
}
|
||||
|
||||
return upload_after_test_with_host(std::move(upload_data), prorgess_fn, error_fn, info_fn, test_msg_or_host_ip);
|
||||
}
|
||||
|
||||
bool OctoPrint::upload_after_test_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn, const wxString& test_msg_or_host_ip) const
|
||||
{
|
||||
const char* name = get_name();
|
||||
|
||||
const auto upload_filename = upload_data.upload_path.filename();
|
||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||
|
||||
std::string url;
|
||||
bool res = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,13 @@ public:
|
|||
protected:
|
||||
#ifdef WIN32
|
||||
virtual bool upload_inner_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn, const boost::asio::ip::address& resolved_addr) const;
|
||||
// Upload half of upload_inner_with_resolved_ip(), for callers that already ran the test.
|
||||
bool upload_after_test_with_resolved_ip(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn, const boost::asio::ip::address& resolved_addr) const;
|
||||
#endif
|
||||
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||
virtual bool upload_inner_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const;
|
||||
// Upload half of upload_inner_with_host(), for callers that already ran test().
|
||||
bool upload_after_test_with_host(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn, const wxString& test_msg_or_host_ip) const;
|
||||
|
||||
std::string m_host;
|
||||
std::string m_apikey;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ add_executable(${_TEST_NAME}_tests
|
|||
test_adaptive_pressure_advance.cpp
|
||||
test_bridge.cpp
|
||||
test_calib.cpp
|
||||
test_conflict_checker.cpp
|
||||
test_cooling.cpp
|
||||
test_extrusion_entity.cpp
|
||||
test_extrusion_processor.cpp
|
||||
|
|
|
|||
75
tests/fff_print/test_conflict_checker.cpp
Normal file
75
tests/fff_print/test_conflict_checker.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/GCode/GCodeProcessor.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "libslic3r/TriangleMesh.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "test_helpers.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::Test;
|
||||
|
||||
namespace {
|
||||
|
||||
// Two 10 mm cubes printed as separate objects, the second shifted along X by `offset`, at the
|
||||
// positions given (not arranged apart).
|
||||
ConflictResultOpt conflict_between_cubes(double offset)
|
||||
{
|
||||
TriangleMesh first = make_cube(10., 10., 10.);
|
||||
TriangleMesh second = make_cube(10., 10., 10.);
|
||||
first.translate(50.f, 50.f, 0.f);
|
||||
second.translate(float(50. + offset), 50.f, 0.f);
|
||||
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({ { "layer_height", "0.2" }, { "initial_layer_print_height", "0.2" } });
|
||||
|
||||
Print print;
|
||||
Model model;
|
||||
init_print({ std::move(first), std::move(second) }, print, model, config, nullptr, false);
|
||||
print.process();
|
||||
return print.get_conflict_result();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Objects whose extrusions cross are reported as a path conflict", "[ConflictChecker]")
|
||||
{
|
||||
// A 5 mm shift puts half of each cube inside the other, so their walls cross on every layer of the
|
||||
// 10 mm high cubes.
|
||||
const ConflictResultOpt conflict = conflict_between_cubes(5.);
|
||||
REQUIRE(conflict.has_value());
|
||||
CHECK(conflict->_obj1 != conflict->_obj2);
|
||||
CHECK(conflict->_height <= 10.);
|
||||
}
|
||||
|
||||
TEST_CASE("Objects apart from each other have no path conflict", "[ConflictChecker]")
|
||||
{
|
||||
// 30 mm between the cube origins leaves a 20 mm gap between the 10 mm cubes.
|
||||
CHECK_FALSE(conflict_between_cubes(30.).has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("Copies of an object printed over each other are reported as a path conflict", "[ConflictChecker]")
|
||||
{
|
||||
// Two instances of one 10 mm cube: not arranged, both stay at the origin of the object; arranged, they are
|
||||
// placed apart.
|
||||
const bool arranged = GENERATE(false, true);
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({ { "layer_height", "0.2" }, { "initial_layer_print_height", "0.2" } });
|
||||
|
||||
TriangleMesh cube = make_cube(10., 10., 10.);
|
||||
cube.translate(50.f, 50.f, 0.f);
|
||||
Print print;
|
||||
Model model;
|
||||
std::vector<TriangleMesh> meshes;
|
||||
meshes.emplace_back(std::move(cube));
|
||||
init_print(std::move(meshes), print, model, config, nullptr, arranged, 2);
|
||||
print.process();
|
||||
CHECK(print.get_conflict_result().has_value() == ! arranged);
|
||||
}
|
||||
|
|
@ -15,11 +15,13 @@
|
|||
#include "test_helpers.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include "libslic3r/Line.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include <cstddef>
|
||||
|
|
@ -30,8 +32,11 @@
|
|||
#include "libslic3r/Layer.hpp"
|
||||
#include "libslic3r/ExtrusionEntityCollection.hpp"
|
||||
#include "libslic3r/ExtrusionEntity.hpp"
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/Polygon.hpp"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
|
||||
|
|
@ -343,8 +348,10 @@ double cooled_length(const std::vector<ExtendedPoint<2>>& points, float fan_over
|
|||
return length;
|
||||
}
|
||||
|
||||
DynamicPrintConfig caged_overhang_config(const char* wall_generator){
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
// The overhang settings of these tests, on top of `config`, which gives the printer and its filaments. They set one
|
||||
// 0.4mm nozzle: a test on more nozzles sets nozzle_diameter again.
|
||||
DynamicPrintConfig caged_overhang_config(const char* wall_generator,
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config()){
|
||||
config.set_deserialize_strict({
|
||||
{"nozzle_diameter", "0.4"},
|
||||
{"initial_layer_print_height", caged_layer_height},
|
||||
|
|
@ -612,7 +619,7 @@ bool has_curled_lines(const PrintObject &object)
|
|||
return std::any_of(layers.begin(), layers.end(), [](const Layer *layer) { return !layer->curled_lines.empty(); });
|
||||
}
|
||||
|
||||
// Estimates every wall of `layer` against whatever layer `estimator` was last prepared with before it.
|
||||
// Estimates every wall of `layer` against the layer below the one `estimator` was last prepared for.
|
||||
Walls estimate_walls(ExtrusionQualityEstimator &estimator, const PrintObject *object, const Layer &layer)
|
||||
{
|
||||
const ConfigOptionPercents overlaps({90, 75, 50, 25, 13, 0});
|
||||
|
|
@ -693,26 +700,38 @@ TEST_CASE("Overhang data computed ahead of the generator gives the same wall spe
|
|||
check_identical(estimate_walls(precomputed, cage.object, *cage.layer), expected);
|
||||
}
|
||||
|
||||
TEST_CASE("Overhang distances measured against another layer than the previous one are not used", "[ExtrusionProcessor]")
|
||||
// process_layer() prepares the estimator only for the layers that need overhang detection, so the layer it was prepared
|
||||
// for before may be a lower one than the layer below, the same layer again, or none at all. Whether the distances are
|
||||
// queried or computed ahead, the walls must come out as if the estimator had been prepared for every layer.
|
||||
TEST_CASE("Walls are measured against the layer below them whichever layer was prepared before", "[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
// Nothing, the layer two below, or the same layer.
|
||||
const int prepared_before = GENERATE(0, 1, 2);
|
||||
const bool precomputed = GENERATE(false, true);
|
||||
CAPTURE(prepared_before, precomputed);
|
||||
const SlicedCage cage;
|
||||
const Layer *two_below = cage.layer->lower_layer->lower_layer;
|
||||
const Layer *one_below = cage.layer->lower_layer;
|
||||
REQUIRE(one_below != nullptr);
|
||||
const Layer *two_below = one_below->lower_layer;
|
||||
REQUIRE(two_below != nullptr);
|
||||
|
||||
ExtrusionQualityEstimator queried;
|
||||
queried.prepare_for_new_layer(cage.object, two_below);
|
||||
queried.prepare_for_new_layer(cage.object, cage.layer);
|
||||
const Walls expected = estimate_walls(queried, cage.object, *cage.layer);
|
||||
ExtrusionQualityEstimator one_below;
|
||||
one_below.prepare_for_new_layer(cage.object, cage.layer->lower_layer);
|
||||
one_below.prepare_for_new_layer(cage.object, cage.layer);
|
||||
REQUIRE(any_difference(estimate_walls(one_below, cage.object, *cage.layer), expected));
|
||||
ExtrusionQualityEstimator continuous;
|
||||
continuous.prepare_for_new_layer(cage.object, one_below);
|
||||
continuous.prepare_for_new_layer(cage.object, cage.layer);
|
||||
const Walls expected = estimate_walls(continuous, cage.object, *cage.layer);
|
||||
// Measured against the layer two below, the walls differ, so matching `expected` below is no coincidence.
|
||||
ExtrusionQualityEstimator stale;
|
||||
stale.prepare_for_new_layer(cage.object, one_below);
|
||||
REQUIRE(any_difference(estimate_walls(stale, cage.object, *cage.layer), expected));
|
||||
|
||||
ExtrusionQualityEstimator precomputed;
|
||||
precomputed.prepare_for_new_layer(cage.object, two_below);
|
||||
precomputed.set_precomputed_layers({precompute_overhang_layer(cage.object, *cage.layer)});
|
||||
precomputed.prepare_for_new_layer(cage.object, cage.layer);
|
||||
check_identical(estimate_walls(precomputed, cage.object, *cage.layer), expected);
|
||||
const Layer *const prepared_layers[] = {nullptr, two_below, cage.layer};
|
||||
ExtrusionQualityEstimator estimator;
|
||||
if (prepared_layers[prepared_before] != nullptr)
|
||||
estimator.prepare_for_new_layer(cage.object, prepared_layers[prepared_before]);
|
||||
if (precomputed)
|
||||
estimator.set_precomputed_layers({precompute_overhang_layer(cage.object, *cage.layer)});
|
||||
estimator.prepare_for_new_layer(cage.object, cage.layer);
|
||||
check_identical(estimate_walls(estimator, cage.object, *cage.layer), expected);
|
||||
}
|
||||
|
||||
TEST_CASE("Overhang data computed for another layer is not used", "[ExtrusionProcessor]")
|
||||
|
|
@ -726,9 +745,9 @@ TEST_CASE("Overhang data computed for another layer is not used", "[ExtrusionPro
|
|||
queried.prepare_for_new_layer(cage.object, one_below);
|
||||
queried.prepare_for_new_layer(cage.object, cage.layer);
|
||||
const Walls expected = estimate_walls(queried, cage.object, *cage.layer);
|
||||
// Measures the walls against the layer below one_below, the layer the data computed for one_below holds.
|
||||
ExtrusionQualityEstimator two_below;
|
||||
two_below.prepare_for_new_layer(cage.object, one_below->lower_layer);
|
||||
two_below.prepare_for_new_layer(cage.object, cage.layer);
|
||||
two_below.prepare_for_new_layer(cage.object, one_below);
|
||||
REQUIRE(any_difference(estimate_walls(two_below, cage.object, *cage.layer), expected));
|
||||
|
||||
ExtrusionQualityEstimator precomputed;
|
||||
|
|
@ -738,6 +757,52 @@ TEST_CASE("Overhang data computed for another layer is not used", "[ExtrusionPro
|
|||
check_identical(estimate_walls(precomputed, cage.object, *cage.layer), expected);
|
||||
}
|
||||
|
||||
// The curled edges that slow a wall down come from the layer below it too, not from a layer prepared before.
|
||||
TEST_CASE("Walls are slowed for the curled edges of the layer below them whichever layer was prepared before", "[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
// Nothing, a stale layer, or the stale layer and then the layer below.
|
||||
const int prepared_before = GENERATE(0, 1, 2);
|
||||
CAPTURE(prepared_before);
|
||||
Print print;
|
||||
Model model;
|
||||
init_print({cube(20.)}, print, model);
|
||||
PrintObject *object = print.get_object(0);
|
||||
Layer *stale = object->add_layer(0, 0.2, 0.2, 0.1);
|
||||
Layer *below = object->add_layer(1, 0.2, 0.4, 0.3);
|
||||
Layer *layer = object->add_layer(2, 0.2, 0.6, 0.5);
|
||||
below->lower_layer = stale;
|
||||
layer->lower_layer = below;
|
||||
// The 0.4mm wide wall runs 0.2mm inside the edge of the layer below, so it is fully supported, but along an edge
|
||||
// that curled up 1mm. The stale layer ends 0.8mm short of the wall and has no curled edges: measured against it,
|
||||
// the wall would be a full overhang.
|
||||
below->lslices = {ExPolygon(Polygon{Point::new_scale(0, 0), Point::new_scale(40, 0),
|
||||
Point::new_scale(40, 10), Point::new_scale(0, 10)})};
|
||||
below->curled_lines = {CurledLine(Point::new_scale(1, 0.2), Point::new_scale(39, 0.2), 1.f)};
|
||||
stale->lslices = {ExPolygon(Polygon{Point::new_scale(0, 1), Point::new_scale(40, 1),
|
||||
Point::new_scale(40, 10), Point::new_scale(0, 10)})};
|
||||
ExtrusionPath wall(erExternalPerimeter, 0.08, 0.4f, 0.2f);
|
||||
wall.polyline.points = {Point3::new_scale(1, 0.2, 0), Point3::new_scale(39, 0.2, 0)};
|
||||
|
||||
ExtrusionQualityEstimator estimator;
|
||||
estimator.set_current_object(object);
|
||||
if (prepared_before >= 1)
|
||||
estimator.prepare_for_new_layer(object, stale);
|
||||
if (prepared_before >= 2)
|
||||
estimator.prepare_for_new_layer(object, below);
|
||||
estimator.prepare_for_new_layer(object, layer);
|
||||
// 100mm/s when fully supported, 20mm/s when a whole width out.
|
||||
const std::vector<ProcessedPoint> points = estimator.estimate_extrusion_quality(wall,
|
||||
ConfigOptionPercents({100, 0}),
|
||||
ConfigOptionFloatsOrPercents({FloatOrPercent{100, false}, FloatOrPercent{20, false}}), 100.f, 100.f, true);
|
||||
|
||||
// A 1mm curl under a 0.2mm layer reads as half the width, 0.2mm, out: halfway between the two speeds.
|
||||
REQUIRE_FALSE(points.empty());
|
||||
for (const ProcessedPoint &point : points) {
|
||||
CHECK_THAT(point.speed, Catch::Matchers::WithinAbs(60., 0.5));
|
||||
CHECK_THAT(point.overlap, Catch::Matchers::WithinAbs(0.5, 1e-3));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Precomputed overhang data has the curled-line tree exactly when a region slows down for curled perimeters", "[ExtrusionProcessor]")
|
||||
{
|
||||
const bool slowdown = GENERATE(false, true);
|
||||
|
|
@ -844,6 +909,192 @@ TEST_CASE("Caged external overhangs are slowed when printed by object or through
|
|||
REQUIRE(*std::max_element(feed_rates.begin(), feed_rates.end()) < caged_slow_speed * MM_PER_MIN);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A 20 x 10 x 2mm wedge whose front face leans out by one layer height per layer (45 degrees), from y = 2 at the bed
|
||||
// to y = 0 at the top, while its back face at y = 12 stands vertical and fully supported.
|
||||
constexpr double wedge_height = 2.;
|
||||
constexpr double wedge_base_front_y = 2.;
|
||||
constexpr double wedge_back_y = 12.;
|
||||
|
||||
TriangleMesh wedge_mesh()
|
||||
{
|
||||
const float length = 20.f, top = float(wedge_height), front = float(wedge_base_front_y), back = float(wedge_back_y);
|
||||
return TriangleMesh(
|
||||
{
|
||||
{0.f, front, 0.f}, {length, front, 0.f}, {length, back, 0.f}, {0.f, back, 0.f},
|
||||
{0.f, 0.f, top}, {length, 0.f, top}, {length, back, top}, {0.f, back, top},
|
||||
},
|
||||
{
|
||||
{0, 2, 1}, {0, 3, 2}, {4, 5, 6}, {4, 6, 7},
|
||||
{0, 1, 5}, {0, 5, 4}, {1, 2, 6}, {1, 6, 5},
|
||||
{2, 3, 7}, {2, 7, 6}, {3, 0, 4}, {3, 4, 7},
|
||||
});
|
||||
}
|
||||
|
||||
// A height range modifier over these heights. Layers are sliced half a layer below their print_z, at 0.1, 0.3, 0.5 and
|
||||
// so on, so the bounds fall between slice planes: the layers printed at 0.6 and 0.8 take the range's settings.
|
||||
constexpr double wedge_range_min = 0.4;
|
||||
constexpr double wedge_range_max = 0.8;
|
||||
|
||||
bool in_wedge_range(double print_z)
|
||||
{
|
||||
const double slice_z = print_z - 0.5 * caged_layer_height;
|
||||
return slice_z > wedge_range_min && slice_z < wedge_range_max;
|
||||
}
|
||||
|
||||
// The wedge with overhang speed set to `object_speed`, and to `range_speed` by the height range modifier.
|
||||
std::string wedge_gcode(bool object_speed, bool range_speed)
|
||||
{
|
||||
DynamicPrintConfig config = caged_overhang_config("classic");
|
||||
config.set_deserialize_strict({
|
||||
{"enable_overhang_speed", object_speed ? "1" : "0"},
|
||||
// The overhang fan has every layer prepared for overhang detection, whether overhang speed is on or not.
|
||||
{"enable_overhang_bridge_fan", "0"},
|
||||
});
|
||||
Print print;
|
||||
Model model;
|
||||
init_print(std::vector<TriangleMesh>{wedge_mesh()}, print, model, config, nullptr, false);
|
||||
DynamicPrintConfig range_config;
|
||||
// Every layer range must carry a layer_height (see layer_height_profile_from_ranges).
|
||||
range_config.set_key_value("layer_height", new ConfigOptionFloat(caged_layer_height));
|
||||
range_config.set_deserialize_strict("enable_overhang_speed", range_speed ? "1" : "0");
|
||||
model.objects.front()->layer_config_ranges[{wedge_range_min, wedge_range_max}].assign_config(
|
||||
std::move(range_config));
|
||||
print.apply(model, config);
|
||||
return gcode(print);
|
||||
}
|
||||
|
||||
// Feed rates of the outer wall moves printed at print_z along the wedge's sloped front face, or along its back face.
|
||||
// The side walls run from one face to the other, so neither filter takes them.
|
||||
std::vector<double> wedge_wall_feed_rates(const std::string &gcode, double print_z, bool front)
|
||||
{
|
||||
return outer_wall_feed_rates(gcode, [print_z, front](const GCodeReader &self, const GCodeReader::GCodeLine &line) {
|
||||
const auto on_face = [front](double y) { return front ? y < wedge_base_front_y + 1. : y > wedge_back_y - 1.; };
|
||||
return std::abs(line.new_Z(self) - print_z) < 0.5 * caged_layer_height && on_face(self.y()) &&
|
||||
on_face(line.new_Y(self));
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Regression: the estimator measured each layer against the layer it was prepared for before. process_layer() skips the
|
||||
// layers with overhang speed off, so the first layer above a range turning it off was measured against the layer below
|
||||
// the range, and the first layer of a range turning it on against no layer at all, which slowed even supported walls.
|
||||
TEST_CASE("Walls printed with overhang speed on match a print with it always on when a height range toggles it", "[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
const bool object_speed = GENERATE(true, false);
|
||||
INFO("overhang speed " << (object_speed ? "on" : "off") << " for the object, " << (object_speed ? "off" : "on")
|
||||
<< " for the range");
|
||||
const std::string toggled = wedge_gcode(object_speed, !object_speed);
|
||||
const std::string always_on = wedge_gcode(true, true);
|
||||
|
||||
// The first layers printed with the other setting, at either end of the range.
|
||||
for (const double print_z : {wedge_range_min + caged_layer_height, wedge_range_max + caged_layer_height}) {
|
||||
INFO("back wall at z = " << print_z);
|
||||
const std::vector<double> feed_rates = wedge_wall_feed_rates(toggled, print_z, false);
|
||||
REQUIRE_FALSE(feed_rates.empty());
|
||||
for (const double feed_rate : feed_rates)
|
||||
CHECK_THAT(feed_rate / MM_PER_MIN, Catch::Matchers::WithinRel(caged_outer_wall_speed, 0.01));
|
||||
}
|
||||
|
||||
// Every layer printed with overhang speed on, above the first, which is never slowed for overhangs.
|
||||
const int layer_count = int(std::lround(wedge_height / caged_layer_height));
|
||||
for (int layer = 2; layer <= layer_count; ++layer) {
|
||||
const double print_z = layer * caged_layer_height;
|
||||
if (in_wedge_range(print_z) == object_speed)
|
||||
continue;
|
||||
INFO("slope at z = " << print_z);
|
||||
const std::vector<double> expected = wedge_wall_feed_rates(always_on, print_z, true);
|
||||
REQUIRE_FALSE(expected.empty());
|
||||
// The slope is slowed down, so matching speeds are not merely the wall speed.
|
||||
REQUIRE(*std::max_element(expected.begin(), expected.end()) < caged_slow_speed * MM_PER_MIN);
|
||||
const std::vector<double> actual = wedge_wall_feed_rates(toggled, print_z, true);
|
||||
REQUIRE(actual.size() == expected.size());
|
||||
for (size_t i = 0; i < actual.size(); ++i)
|
||||
CHECK_THAT(actual[i], Catch::Matchers::WithinAbs(expected[i], 1.));
|
||||
}
|
||||
}
|
||||
|
||||
// Regression: process_layer() prepared the estimator only when overhang speed was on for the nozzle active before the
|
||||
// layer's tool changes. Here the second nozzle prints the walls and slows down for overhangs, the first prints the
|
||||
// infill and has overhang speed off. A layer starts with the nozzle that ended the layer below, so every other layer
|
||||
// starts with the first one and was not prepared: its walls were measured against an older layer, or against none.
|
||||
TEST_CASE("Walls printed by a nozzle with overhang speed on match a print with it on for every nozzle",
|
||||
"[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
const auto two_nozzle_gcode = [](const char *overhang_speed) {
|
||||
DynamicPrintConfig config = caged_overhang_config("classic", multifilament_config(2));
|
||||
config.set_deserialize_strict({
|
||||
{"nozzle_diameter", "0.4,0.4"},
|
||||
{"printer_extruder_id", "1,2"},
|
||||
{"printer_extruder_variant", "Direct Drive Standard;Direct Drive Standard"},
|
||||
{"extruder_printable_height", "0,0"},
|
||||
{"filament_self_index", "1,2"},
|
||||
{"single_extruder_multi_material", 0},
|
||||
// Each filament on its own nozzle: left to the automatic grouping, both may share one.
|
||||
{"filament_map_mode", "Manual"},
|
||||
{"filament_map", "1,2"},
|
||||
{"enable_prime_tower", 0},
|
||||
// A process column per nozzle, or every nozzle reads the first overhang speed switch.
|
||||
{"print_extruder_id", "1,2"},
|
||||
{"print_extruder_variant", "Direct Drive Standard;Direct Drive Standard"},
|
||||
{"enable_overhang_speed", overhang_speed},
|
||||
// The overhang fan has every layer prepared for overhang detection, whether overhang speed is on or not.
|
||||
{"enable_overhang_bridge_fan", "0"},
|
||||
{"outer_wall_filament_id", 2},
|
||||
{"inner_wall_filament_id", 2},
|
||||
{"sparse_infill_filament_id", 1},
|
||||
{"internal_solid_filament_id", 1},
|
||||
{"top_surface_filament_id", 1},
|
||||
{"bottom_surface_filament_id", 1},
|
||||
{"skirt_loops", 0},
|
||||
{"brim_type", "no_brim"},
|
||||
});
|
||||
size_flush_to_nozzles(config);
|
||||
Print print;
|
||||
Model model;
|
||||
init_print(std::vector<TriangleMesh>{wedge_mesh()}, print, model, config, nullptr, false);
|
||||
return gcode(print);
|
||||
};
|
||||
const std::string mixed = two_nozzle_gcode("0,1");
|
||||
const std::string always_on = two_nozzle_gcode("1,1");
|
||||
|
||||
// The regression shows only on the layers process_layer() starts with the first filament (T0), on the first
|
||||
// nozzle. Make sure the checked layers include some: the tool order, not this test, decides which layers those are.
|
||||
int layers_starting_with_first_nozzle = 0;
|
||||
std::istringstream lines(mixed);
|
||||
int tool = -1;
|
||||
for (std::string line; std::getline(lines, line);) {
|
||||
if (line.size() > 1 && line[0] == 'T' && std::isdigit(static_cast<unsigned char>(line[1])))
|
||||
tool = std::stoi(line.substr(1));
|
||||
else if (tool == 0 && line.compare(0, 3, ";Z:") == 0 && std::stod(line.substr(3)) > 1.5 * caged_layer_height)
|
||||
++layers_starting_with_first_nozzle;
|
||||
}
|
||||
REQUIRE(layers_starting_with_first_nozzle > 0);
|
||||
|
||||
// Every layer above the first, which is never slowed for overhangs.
|
||||
const int layer_count = int(std::lround(wedge_height / caged_layer_height));
|
||||
for (int layer = 2; layer <= layer_count; ++layer) {
|
||||
const double print_z = layer * caged_layer_height;
|
||||
INFO("z = " << print_z);
|
||||
// The supported back wall keeps the wall speed, so the print with overhang speed on for every nozzle measures
|
||||
// each layer against a layer below, not against none, which would slow both prints alike.
|
||||
const std::vector<double> back_wall = wedge_wall_feed_rates(always_on, print_z, false);
|
||||
REQUIRE_FALSE(back_wall.empty());
|
||||
for (const double feed_rate : back_wall)
|
||||
CHECK_THAT(feed_rate / MM_PER_MIN, Catch::Matchers::WithinRel(caged_outer_wall_speed, 0.01));
|
||||
const std::vector<double> expected = wedge_wall_feed_rates(always_on, print_z, true);
|
||||
REQUIRE_FALSE(expected.empty());
|
||||
// The slope is slowed down, so matching speeds are not merely the wall speed.
|
||||
REQUIRE(*std::max_element(expected.begin(), expected.end()) < caged_slow_speed * MM_PER_MIN);
|
||||
const std::vector<double> actual = wedge_wall_feed_rates(mixed, print_z, true);
|
||||
REQUIRE(actual.size() == expected.size());
|
||||
for (size_t i = 0; i < actual.size(); ++i)
|
||||
CHECK_THAT(actual[i], Catch::Matchers::WithinAbs(expected[i], 1.));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Benchmark caged overhang interior sampling", "[ExtrusionProcessor][!benchmark]"){
|
||||
const char* wall_generator = GENERATE("classic", "arachne");
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include "test_helpers.hpp" // get access to init_print, etc
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
|
|
@ -93,3 +96,13 @@ SCENARIO("Flow math for bridges", "[Flow]") {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("A flow ratio scales the cross-section of a line", "[Flow][Regression]")
|
||||
{
|
||||
// At 0.2 mm layers a 0.2 mm line can't get narrower, so a ratio below 1 turns it into a round strand.
|
||||
// A 0.3 mm line narrows instead, and a ratio above 1 grows the line.
|
||||
const auto [width, ratio] = GENERATE(table<float, double>({ { 0.2f, 0.95 }, { 0.2f, 0.5 }, { 0.3f, 0.95 }, { 0.2f, 1.2 } }));
|
||||
const Flow flow(width, 0.2f, 0.2f);
|
||||
|
||||
CHECK_THAT(flow.with_flow_ratio(ratio).mm3_per_mm(), Catch::Matchers::WithinRel(ratio * flow.mm3_per_mm(), 1e-4));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -828,6 +828,36 @@ TEST_CASE("Inner walls of an exported sphere are not tagged", "[GCodeProcessor][
|
|||
CHECK(layers.size() == seams.size());
|
||||
}
|
||||
|
||||
TEST_CASE("A reset processor does not keep the previous G-code's pressure advance", "[GCodeProcessor][Regression]")
|
||||
{
|
||||
FullPrintConfig config;
|
||||
config.gcode_flavor.value = gcfMarlinFirmware;
|
||||
GCodeProcessor processor;
|
||||
// Streams G-code through the same processor, resetting it first as a reused one is.
|
||||
const auto process = [&](const std::string &gcode) {
|
||||
processor.reset();
|
||||
processor.initialize("stream.gcode");
|
||||
processor.initialize_result_moves();
|
||||
processor.apply_config(config);
|
||||
processor.process_buffer(gcode);
|
||||
processor.finalize(false);
|
||||
return processor.result().moves;
|
||||
};
|
||||
const auto is_extrusion = [](const GCodeProcessorResult::MoveVertex &move) { return move.type == EMoveType::Extrude; };
|
||||
const std::string square = "M83\nG90\nG1 X10 Y10 Z0.2 F12000\nG1 X50 Y10 E2 F3000\nG1 X50 Y50 E2\nG1 X10 Y50 E2\nG1 X10 Y10 E2\n";
|
||||
|
||||
const std::vector<GCodeProcessorResult::MoveVertex> with_pa = process("M900 K0.05\n" + square);
|
||||
REQUIRE(std::any_of(with_pa.begin(), with_pa.end(), is_extrusion));
|
||||
for (const GCodeProcessorResult::MoveVertex &move : with_pa)
|
||||
if (is_extrusion(move))
|
||||
CHECK_THAT(move.pressure_advance, Catch::Matchers::WithinAbs(0.05, 1e-6));
|
||||
|
||||
const std::vector<GCodeProcessorResult::MoveVertex> without_pa = process(square);
|
||||
REQUIRE(std::any_of(without_pa.begin(), without_pa.end(), is_extrusion));
|
||||
for (const GCodeProcessorResult::MoveVertex &move : without_pa)
|
||||
CHECK(move.pressure_advance == 0.0f);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A printer with `nozzles` nozzles over a 200 mm square bed: nozzle `filament_1_nozzle` reaches only
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@
|
|||
#include "libslic3r/Support/BeltFloorContext.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
#include "libslic3r/ExtrusionEntity.hpp"
|
||||
#include "libslic3r/ExtrusionEntityCollection.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include "libslic3r/Polyline.hpp"
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
|
@ -56,11 +58,15 @@
|
|||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <limits>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <ios>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
|
@ -69,6 +75,7 @@
|
|||
#include "libslic3r/SurfaceCollection.hpp"
|
||||
#include "libslic3r/BoundingBox.hpp"
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/Geometry.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::Test;
|
||||
|
|
@ -846,6 +853,55 @@ TEST_CASE("Print::validate ignores a flow ratio of 0 on an unused filament", "[P
|
|||
CHECK(err.string.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Print::validate checks skin and skeleton line widths only for Locked Zag infill", "[Print][validate][Regression]")
|
||||
{
|
||||
const auto [pattern, rejected] = GENERATE(table<std::string, bool>({ { "crosshatch", false }, { "lockedzag", true } }));
|
||||
|
||||
// 100% of a 0.2 mm nozzle is no wider than a 0.2 mm layer. Thick bridges keep the bridge check out of it.
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "nozzle_diameter", "0.2" },
|
||||
{ "layer_height", "0.2" },
|
||||
{ "initial_layer_print_height", "0.2" },
|
||||
{ "skin_infill_line_width", "100%" },
|
||||
{ "skeleton_infill_line_width", "100%" },
|
||||
{ "thick_bridges", "1" },
|
||||
{ "thick_internal_bridges", "1" },
|
||||
{ "sparse_infill_pattern", pattern },
|
||||
});
|
||||
|
||||
std::vector<StringObjectException> warnings;
|
||||
const StringObjectException err = validate_cubes(config, warnings);
|
||||
|
||||
if (rejected)
|
||||
CHECK(err.opt_key == "skin_infill_line_width");
|
||||
else
|
||||
CHECK(err.string.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Print::validate accepts a thin bridge as wide as the layer is tall", "[Print][validate][Regression]")
|
||||
{
|
||||
const auto [bridge_line_width, rejected] = GENERATE(table<std::string, bool>({ { "100%", false }, { "0.15", true } }));
|
||||
|
||||
// 0.2 mm layers on a 0.2 mm nozzle, without thick bridges.
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "nozzle_diameter", "0.2" },
|
||||
{ "layer_height", "0.2" },
|
||||
{ "initial_layer_print_height", "0.2" },
|
||||
{ "thick_bridges", "0" },
|
||||
{ "bridge_line_width", bridge_line_width },
|
||||
});
|
||||
|
||||
std::vector<StringObjectException> warnings;
|
||||
const StringObjectException err = validate_cubes(config, warnings);
|
||||
|
||||
if (rejected)
|
||||
CHECK(err.opt_key == "bridge_line_width");
|
||||
else
|
||||
CHECK(err.string.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Purge tower selection keeps ordinary printers on the classic path", "[Print][PurgeTower][Regression]")
|
||||
{
|
||||
DynamicPrintConfig config = multifilament_config(2, {
|
||||
|
|
@ -3517,6 +3573,128 @@ TEST_CASE("Height range settings follow a Z shrinkage change that comes with a m
|
|||
|
||||
namespace {
|
||||
|
||||
// Four distinct objects: they run each slicing step together.
|
||||
std::vector<TriangleMesh> distinct_objects()
|
||||
{
|
||||
std::vector<TriangleMesh> meshes;
|
||||
for (TestMesh m : { TestMesh::cube_with_hole, TestMesh::pyramid, TestMesh::sphere_50mm, TestMesh::overhang })
|
||||
meshes.emplace_back(Test::mesh(m));
|
||||
return meshes;
|
||||
}
|
||||
|
||||
// The moves of a G-code, without the export time in the header or the configuration block. The block also lists the
|
||||
// filament maps slicing writes back, which the GUI passes to the next apply() and these tests do not.
|
||||
std::string toolpaths(const std::string &gcode)
|
||||
{
|
||||
std::istringstream in(gcode);
|
||||
std::string out, line;
|
||||
bool config = false;
|
||||
while (std::getline(in, line)) {
|
||||
if (line.rfind("; CONFIG_BLOCK_START", 0) == 0)
|
||||
config = true;
|
||||
else if (line.rfind("; CONFIG_BLOCK_END", 0) == 0)
|
||||
config = false;
|
||||
else if (! config && line.rfind("; generated by", 0) != 0)
|
||||
out += line + '\n';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string fresh_slice_toolpaths(const DynamicPrintConfig &config)
|
||||
{
|
||||
Print print;
|
||||
Model model;
|
||||
Test::init_print(distinct_objects(), print, model, config);
|
||||
return toolpaths(Test::gcode(print));
|
||||
}
|
||||
|
||||
// Copies of a model of a cube with a hole, one at each scale, sliced together. Each scale gets a PrintObject of its
|
||||
// own, all of them made from the one ModelObject. With `only` set, the other copies stay in the model but do not
|
||||
// print, so that copy's PrintObject is the only one and keeps the coordinates it has among the others.
|
||||
void slice_copies_at_scales(const std::vector<double> &scales, const DynamicPrintConfig &config, Model &model, Print &print,
|
||||
std::optional<size_t> only = std::nullopt)
|
||||
{
|
||||
ModelObject *object = model.add_object();
|
||||
object->add_volume(Test::mesh(TestMesh::cube_with_hole));
|
||||
for (size_t i = 0; i < scales.size(); ++ i) {
|
||||
ModelInstance *instance = object->add_instance();
|
||||
instance->set_scaling_factor(Vec3d(scales[i], scales[i], scales[i]));
|
||||
instance->set_offset(Vec3d(40. + 30. * double(i), 100., 0.));
|
||||
instance->printable = ! only || *only == i;
|
||||
}
|
||||
object->ensure_on_bed();
|
||||
print.auto_assign_extruders(object);
|
||||
print.apply(model, config);
|
||||
print.set_status_silent();
|
||||
print.process();
|
||||
}
|
||||
|
||||
// The perimeters and the infill of every layer of a PrintObject, in its own coordinates.
|
||||
std::string layer_extrusions(const PrintObject &object)
|
||||
{
|
||||
std::ostringstream out;
|
||||
for (const Layer *layer : object.layers()) {
|
||||
out << "layer " << layer->print_z << '\n';
|
||||
for (const LayerRegion *layerm : layer->regions())
|
||||
for (const ExtrusionEntityCollection *extrusions : { &layerm->perimeters, &layerm->fills })
|
||||
for (const ExtrusionEntity *extrusion : extrusions->flatten().entities) {
|
||||
for (const Point &point : extrusion->as_polyline().points)
|
||||
out << point.x() << ',' << point.y() << ' ';
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
||||
// The project of an Assembly crash report: one object of a 27 mm cube and a cylinder of the same size lying along X,
|
||||
// in an instance scaled 2x along X, on the bed.
|
||||
ModelObject *add_cube_and_lying_cylinder(Model &model)
|
||||
{
|
||||
ModelObject *object = model.add_object();
|
||||
object->add_volume(cube(27.))->set_offset(Vec3d(0., 18., 0.));
|
||||
ModelVolume *cylinder = object->add_volume(make_cylinder(13.5, 27.));
|
||||
cylinder->set_rotation(Vec3d(0., 0.5 * PI, 0.));
|
||||
cylinder->set_offset(Vec3d(0., -18., 0.));
|
||||
ModelInstance *instance = object->add_instance();
|
||||
instance->set_scaling_factor(Vec3d(2., 1., 1.));
|
||||
instance->set_offset(Vec3d(100., 100., 13.5));
|
||||
return object;
|
||||
}
|
||||
|
||||
// The Assembly tool's Parallel with the cube's top face picked first and an end face of the cylinder second, which
|
||||
// GLGizmoMeasure::set_to_parallel() does by turning the cylinder until that end face points down.
|
||||
// - Turning its whole world transformation about its origin, as set_to_parallel() does now, keeps the cylinder round
|
||||
// and 54 mm long. It stands about its centre, 13.5 mm above the bed, so 13.5 mm of it goes below the bed.
|
||||
// - Setting its rotation only, as the crash build's set_to_parallel() did, lets the instance's scaling stretch it
|
||||
// along X instead: it stands 27 mm tall on the bed, an ellipse twice as wide as it is deep.
|
||||
void turn_cylinder_end_face_down(ModelObject &object, const Vec3d &end_face_normal, bool whole_transformation)
|
||||
{
|
||||
ModelVolume &cylinder = *object.volumes.back();
|
||||
const Transform3d instance = object.instances.front()->get_matrix();
|
||||
Transform3d world = instance * cylinder.get_matrix();
|
||||
Vec3d axis;
|
||||
double angle;
|
||||
Matrix3d rotation;
|
||||
Geometry::rotation_from_two_vectors(end_face_normal, -Vec3d::UnitZ(), axis, angle, &rotation);
|
||||
if (whole_transformation) {
|
||||
world.linear() = rotation * world.linear().eval();
|
||||
cylinder.set_transformation(instance.inverse() * world);
|
||||
} else {
|
||||
const Transform3d turned = Transform3d(rotation) * Geometry::Transformation(world).get_rotation_matrix();
|
||||
const Transform3d instance_rotation = object.instances.front()->get_transformation().get_rotation_matrix();
|
||||
cylinder.set_rotation(Geometry::extract_euler_angles(instance_rotation.inverse() * turned));
|
||||
}
|
||||
object.invalidate_bounding_box();
|
||||
}
|
||||
|
||||
// The area of the islands of the lowest layer at or above z, in mm².
|
||||
double island_area_at(const PrintObject &object, double z)
|
||||
{
|
||||
const auto it = std::find_if(object.layers().begin(), object.layers().end(), [z](const Layer *layer) { return layer->print_z >= z; });
|
||||
REQUIRE(it != object.layers().end());
|
||||
return area((*it)->lslices) * SCALING_FACTOR * SCALING_FACTOR;
|
||||
}
|
||||
|
||||
// One tray of the device AMS inventory, with the keys build_filament_ams_list() puts in the payload.
|
||||
DynamicPrintConfig loaded_filament_tray(const std::string &colour, const std::string &type, const std::string &tray_name)
|
||||
{
|
||||
|
|
@ -3560,6 +3738,184 @@ DynamicPrintConfig machine_inventory_config()
|
|||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Re-processing several objects after a setting change gives the toolpaths of a fresh slice", "[Print]")
|
||||
{
|
||||
// The settings invalidate the perimeters, the infill regions and everything after them, the infill, the ironing,
|
||||
// or only the G-code export.
|
||||
const auto [key, before, after] = GENERATE(table<std::string, std::string, std::string>({
|
||||
{ "wall_loops", "2", "3" },
|
||||
{ "top_shell_layers", "3", "5" },
|
||||
{ "sparse_infill_density", "15%", "40%" },
|
||||
{ "sparse_infill_pattern", "grid", "gyroid" },
|
||||
{ "ironing_type", "no ironing", "top" },
|
||||
{ "seam_position", "aligned", "nearest" },
|
||||
{ "outer_wall_speed", "60", "40" },
|
||||
}));
|
||||
INFO(key << ": " << before << " -> " << after);
|
||||
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
// init_print() turns the G-code comments on, the second apply() has to keep them.
|
||||
config.set_deserialize_strict({ { "gcode_comments", "1" }, { key, before } });
|
||||
Print print;
|
||||
Model model;
|
||||
Test::init_print(distinct_objects(), print, model, config);
|
||||
REQUIRE(print.objects().size() == 4);
|
||||
Test::gcode(print);
|
||||
|
||||
config.set_deserialize_strict(key, after);
|
||||
print.apply(model, config);
|
||||
const std::string reprocessed = toolpaths(Test::gcode(print));
|
||||
|
||||
REQUIRE(! reprocessed.empty());
|
||||
CHECK(reprocessed == fresh_slice_toolpaths(config));
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing several objects cancelled from another thread and run again gives the toolpaths of a fresh slice", "[Print]")
|
||||
{
|
||||
// As the GUI does it: the print is processed on a thread of its own, which the status updates reach from the
|
||||
// threads processing the objects, and a cancel makes process() throw before the print is processed again.
|
||||
const int cancel_at_update = GENERATE(1, 3, 6, 9);
|
||||
INFO("cancelled at status update " << cancel_at_update);
|
||||
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({ { "gcode_comments", "1" } });
|
||||
Print print;
|
||||
Model model;
|
||||
Test::init_print(distinct_objects(), print, model, config);
|
||||
REQUIRE(print.objects().size() == 4);
|
||||
|
||||
std::atomic<int> updates { 0 };
|
||||
print.set_status_callback([&print, &updates, cancel_at_update](const PrintBase::SlicingStatus &) {
|
||||
if (++ updates == cancel_at_update)
|
||||
print.cancel();
|
||||
});
|
||||
bool canceled = false;
|
||||
bool other_error = false;
|
||||
std::thread background([&print, &canceled, &other_error] {
|
||||
try {
|
||||
print.process();
|
||||
} catch (const CanceledException &) {
|
||||
canceled = true;
|
||||
} catch (...) {
|
||||
other_error = true;
|
||||
}
|
||||
});
|
||||
background.join();
|
||||
CHECK(canceled);
|
||||
CHECK_FALSE(other_error);
|
||||
|
||||
print.restart();
|
||||
const std::string resumed = toolpaths(Test::gcode(print));
|
||||
REQUIRE(! resumed.empty());
|
||||
CHECK(resumed == fresh_slice_toolpaths(config));
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing several objects calls the status callback one status at a time", "[Print]")
|
||||
{
|
||||
// The objects run their steps concurrently, while a callback such as the command line's appends the warnings
|
||||
// to a vector of its own.
|
||||
Print print;
|
||||
Model model;
|
||||
Test::init_print(distinct_objects(), print, model, DynamicPrintConfig::full_print_config());
|
||||
REQUIRE(print.objects().size() == 4);
|
||||
|
||||
std::atomic<int> calls { 0 };
|
||||
std::atomic<int> running { 0 };
|
||||
std::atomic<bool> overlapped { false };
|
||||
print.set_status_callback([&calls, &running, &overlapped](const PrintBase::SlicingStatus &) {
|
||||
++ calls;
|
||||
if (++ running > 1)
|
||||
overlapped = true;
|
||||
// Stay in the callback long enough for the other objects to report meanwhile.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2));
|
||||
-- running;
|
||||
});
|
||||
print.process();
|
||||
|
||||
REQUIRE(calls > 1);
|
||||
CHECK_FALSE(overlapped);
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing copies of one object at different scales gives each copy the layers it gets alone", "[Print]")
|
||||
{
|
||||
// The PrintObjects of the copies share the volumes of their ModelObject and run each slicing step together, while
|
||||
// a copy that is the only one printing runs its steps by itself.
|
||||
const std::vector<double> scales { 1., 0.9, 0.8, 0.7 };
|
||||
const DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
Model model;
|
||||
Print print;
|
||||
slice_copies_at_scales(scales, config, model, print);
|
||||
REQUIRE(print.objects().size() == scales.size());
|
||||
|
||||
for (size_t i = 0; i < scales.size(); ++ i) {
|
||||
const double scale = scales[i];
|
||||
INFO("scale " << scale);
|
||||
Model alone_model;
|
||||
Print alone;
|
||||
slice_copies_at_scales(scales, config, alone_model, alone, i);
|
||||
REQUIRE(alone.objects().size() == 1);
|
||||
const auto copy = std::find_if(print.objects().begin(), print.objects().end(), [scale](const PrintObject *object) {
|
||||
return std::abs(object->instances().front().model_instance->get_scaling_factor().x() - scale) < EPSILON;
|
||||
});
|
||||
REQUIRE(copy != print.objects().end());
|
||||
// The copy has walls, so the layers compare extrusions and not only their heights.
|
||||
REQUIRE(std::any_of((*copy)->layers().begin(), (*copy)->layers().end(), [](const Layer *layer) {
|
||||
return ! layer->regions().empty() && ! layer->regions().front()->perimeters.empty();
|
||||
}));
|
||||
CHECK(layer_extrusions(**copy) == layer_extrusions(*alone.objects().front()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Slicing after the Assembly tool's Parallel turns a part of a scaled object gives the toolpaths of a fresh slice", "[Print]")
|
||||
{
|
||||
// The steps of a crash report: Parallel turns the cylinder, and the GUI applies and validates the changed model.
|
||||
// The GUI processes the print only while the Preview is open, so it may have been processed before or not. The
|
||||
// crash build set the cylinder's rotation only, and either end face can be the one picked.
|
||||
const bool whole_transformation = GENERATE(false, true);
|
||||
const double end_face = GENERATE(1., -1.);
|
||||
const bool processed_before = GENERATE(false, true);
|
||||
INFO((whole_transformation ? "whole transformation" : "rotation only") << ", end face normal " << end_face << " * X, "
|
||||
<< (processed_before ? "processed" : "not processed") << " before");
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "layer_height", "0.2" },
|
||||
{ "initial_layer_print_height", "0.2" },
|
||||
// validate() wants the extruder position reset at each layer for the default relative extrusion.
|
||||
{ "layer_change_gcode", "G92 E0" },
|
||||
});
|
||||
Model model;
|
||||
ModelObject *object = add_cube_and_lying_cylinder(model);
|
||||
Print print;
|
||||
print.apply(model, config);
|
||||
REQUIRE_THAT(print.validate().string, Catch::Matchers::Equals(std::string()));
|
||||
if (processed_before)
|
||||
Test::gcode(print);
|
||||
|
||||
turn_cylinder_end_face_down(*object, end_face * Vec3d::UnitX(), whole_transformation);
|
||||
print.apply(model, config);
|
||||
CHECK_THAT(print.validate().string, Catch::Matchers::Equals(std::string()));
|
||||
const std::string sliced = toolpaths(Test::gcode(print));
|
||||
|
||||
// Only what is above the bed prints. Up to the cube's top at 27 mm, that is its 54 x 27 mm and the cylinder's
|
||||
// cross-section: the round cylinder's circle of radius 13.5 mm, alone above the cube up to 40.5 mm, or the stretched
|
||||
// cylinder's ellipse, twice as wide, which ends at 27 mm.
|
||||
REQUIRE(print.objects().size() == 1);
|
||||
const PrintObject &print_object = *print.objects().front();
|
||||
REQUIRE(! print_object.layers().empty());
|
||||
const double cylinder_area = whole_transformation ? PI * 13.5 * 13.5 : PI * 27. * 13.5;
|
||||
CHECK_THAT(print_object.layers().back()->print_z, Catch::Matchers::WithinAbs(whole_transformation ? 40.5 : 27., 0.2));
|
||||
CHECK_THAT(island_area_at(print_object, 13.5), Catch::Matchers::WithinRel(54. * 27. + cylinder_area, 0.01));
|
||||
if (whole_transformation)
|
||||
CHECK_THAT(island_area_at(print_object, 34.), Catch::Matchers::WithinRel(cylinder_area, 0.01));
|
||||
|
||||
Model fresh_model;
|
||||
turn_cylinder_end_face_down(*add_cube_and_lying_cylinder(fresh_model), end_face * Vec3d::UnitX(), whole_transformation);
|
||||
Print fresh;
|
||||
fresh.apply(fresh_model, config);
|
||||
REQUIRE(! sliced.empty());
|
||||
CHECK(sliced == toolpaths(Test::gcode(fresh)));
|
||||
}
|
||||
|
||||
// The AMS inventory is device state that only feeds filament grouping. A changed inventory has to
|
||||
// invalidate the grouping steps, while the refreshes a connected device keeps sending -- the same
|
||||
// trays, volatile metadata, or an empty payload while it reconnects -- must not.
|
||||
|
|
|
|||
|
|
@ -1538,3 +1538,37 @@ TEST_CASE("Seam extraction preserves unknown boundary roles for open extrusion p
|
|||
REQUIRE(perimeters.size() == 1);
|
||||
CHECK(perimeters.front().contour_reliable == !open);
|
||||
}
|
||||
|
||||
TEST_CASE("Seams are picked on every loop of every object when init() places several objects at once", "[SeamPlacer]")
|
||||
{
|
||||
// Random seams are picked by the workers of each object alone, and they finalize every loop. Sixteen objects make
|
||||
// four tasks of four objects each.
|
||||
const size_t object_count = 16;
|
||||
std::vector<TriangleMesh> meshes;
|
||||
for (size_t i = 0; i < object_count; ++ i)
|
||||
meshes.emplace_back(its_make_cube(10, 10, 1));
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict("seam_position", "random"); // Random needs no visibility ray tracing.
|
||||
Model model;
|
||||
Print print;
|
||||
Test::init_print(std::move(meshes), print, model, config);
|
||||
REQUIRE(print.objects().size() == object_count);
|
||||
print.process();
|
||||
|
||||
SeamPlacer placer;
|
||||
placer.init(print, [] {});
|
||||
|
||||
size_t loops = 0, picked = 0;
|
||||
for (const PrintObject *object : print.objects()) {
|
||||
const std::vector<PrintObjectSeamData::LayerSeams> &layers = placer.m_seam_per_object.at(object).layers;
|
||||
REQUIRE(layers.size() == object->layers().size());
|
||||
for (const PrintObjectSeamData::LayerSeams &layer : layers)
|
||||
for (const SeamPlacerImpl::Perimeter &perimeter : layer.perimeters) {
|
||||
++ loops;
|
||||
if (perimeter.finalized)
|
||||
++ picked;
|
||||
}
|
||||
}
|
||||
REQUIRE(loops >= object_count);
|
||||
CHECK(picked == loops);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ add_executable(${_TEST_NAME}_tests
|
|||
test_drc.cpp
|
||||
test_gcodereader.cpp
|
||||
test_toolordering_nozzle_group.cpp
|
||||
test_parallel_for_first_error.cpp
|
||||
test_parallel_resolve.cpp
|
||||
test_preset_bundle_loading.cpp
|
||||
test_preset_collection.cpp
|
||||
|
|
@ -47,6 +48,7 @@ add_executable(${_TEST_NAME}_tests
|
|||
test_preset_options.cpp
|
||||
test_edge_grid.cpp
|
||||
test_elephant_foot_compensation.cpp
|
||||
test_expolygon.cpp
|
||||
test_exclusion_volumes.cpp
|
||||
test_fill_corner_smoothing.cpp
|
||||
test_filament_mixer.cpp
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
#include <catch2/catch_all.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
#include <igl/Hit.h>
|
||||
#include <cstddef>
|
||||
#include <libslic3r/TriangleMesh.hpp>
|
||||
#include <libslic3r/AABBTreeIndirect.hpp>
|
||||
#include <limits>
|
||||
#include <random>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include "libslic3r/libslic3r.h"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
|
|
@ -63,3 +68,125 @@ TEST_CASE("Building a tree over a box, ray caster and closest query", "[AABBIndi
|
|||
REQUIRE(closest_point.y() == Catch::Approx(0.5));
|
||||
REQUIRE(closest_point.z() == Catch::Approx(1.));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// The depth-first, left to right traversal intersect_ray_first_hit() used before it visited the nearest
|
||||
// child first. The ordered traversal must return the very same hit.
|
||||
template<typename RayIntersectorType, typename Scalar>
|
||||
bool reference_first_hit(const RayIntersectorType &ray_intersector, size_t node_idx, Scalar min_t, igl::Hit<float> &hit)
|
||||
{
|
||||
const auto &node = ray_intersector.tree.node(node_idx);
|
||||
if (! AABBTreeIndirect::detail::ray_box_intersect_invdir(ray_intersector.origin, ray_intersector.invdir,
|
||||
node.bbox.template cast<Scalar>(), Scalar(0), min_t))
|
||||
return false;
|
||||
if (node.is_leaf()) {
|
||||
auto face = ray_intersector.faces[node.idx];
|
||||
double t, u, v;
|
||||
if (AABBTreeIndirect::detail::intersect_triangle(ray_intersector.origin, ray_intersector.dir,
|
||||
ray_intersector.vertices[face(0)], ray_intersector.vertices[face(1)],
|
||||
ray_intersector.vertices[face(2)], t, u, v, ray_intersector.eps) &&
|
||||
t > 0.) {
|
||||
hit = igl::Hit<float>{int(node.idx), -1, float(u), float(v), float(t)};
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
igl::Hit<float> left_hit;
|
||||
igl::Hit<float> right_hit;
|
||||
bool left_ret = reference_first_hit(ray_intersector, node_idx * 2 + 1, min_t, left_hit);
|
||||
if (left_ret && left_hit.t < min_t) {
|
||||
min_t = left_hit.t;
|
||||
hit = left_hit;
|
||||
} else
|
||||
left_ret = false;
|
||||
bool right_ret = reference_first_hit(ray_intersector, node_idx * 2 + 2, min_t, right_hit);
|
||||
if (right_ret && right_hit.t < min_t)
|
||||
hit = right_hit;
|
||||
else
|
||||
right_ret = false;
|
||||
return left_ret || right_ret;
|
||||
}
|
||||
|
||||
// Unit cube faces split into an n x n grid of triangles: many coplanar triangles sharing edges, so rays
|
||||
// through edges and vertices hit several triangles at the same distance.
|
||||
indexed_triangle_set grid_cube(int n)
|
||||
{
|
||||
indexed_triangle_set its;
|
||||
for (int axis = 0; axis < 3; ++axis)
|
||||
for (int side = 0; side < 2; ++side)
|
||||
for (int i = 0; i < n; ++i)
|
||||
for (int j = 0; j < n; ++j) {
|
||||
auto vertex = [&](int a, int b) {
|
||||
Vec3f p;
|
||||
p[axis] = float(side);
|
||||
p[(axis + 1) % 3] = float(a) / n;
|
||||
p[(axis + 2) % 3] = float(b) / n;
|
||||
its.vertices.emplace_back(p);
|
||||
return int(its.vertices.size()) - 1;
|
||||
};
|
||||
int v0 = vertex(i, j), v1 = vertex(i + 1, j), v2 = vertex(i + 1, j + 1), v3 = vertex(i, j + 1);
|
||||
its.indices.emplace_back(v0, v1, v2);
|
||||
its.indices.emplace_back(v0, v2, v3);
|
||||
}
|
||||
return its;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("First ray hit matches the depth-first search", "[AABBIndirect]")
|
||||
{
|
||||
std::mt19937 rng(42);
|
||||
std::uniform_real_distribution<double> coord(-1.5, 2.5);
|
||||
std::uniform_real_distribution<double> unit(-1., 1.);
|
||||
|
||||
indexed_triangle_set soup;
|
||||
for (int i = 0; i < 300; ++i) {
|
||||
Vec3f a(coord(rng), coord(rng), coord(rng));
|
||||
int base = int(soup.vertices.size());
|
||||
soup.vertices.emplace_back(a);
|
||||
soup.vertices.emplace_back(a + Vec3f(unit(rng), unit(rng), unit(rng)) * 0.5f);
|
||||
soup.vertices.emplace_back(a + Vec3f(unit(rng), unit(rng), unit(rng)) * 0.5f);
|
||||
soup.indices.emplace_back(base, base + 1, base + 2);
|
||||
}
|
||||
const indexed_triangle_set mesh = GENERATE_COPY(grid_cube(8), its_make_sphere(1., PI / 20.), soup);
|
||||
|
||||
const auto tree = AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(mesh.vertices, mesh.indices);
|
||||
REQUIRE(! tree.empty());
|
||||
|
||||
// Directions with zero components make the inverse direction infinite. Origins on the grid, aimed
|
||||
// along the axes or the diagonals, put the rays through shared edges and vertices.
|
||||
std::vector<std::pair<Vec3d, Vec3d>> rays;
|
||||
const Vec3d axis_dirs[] = {Vec3d::UnitX(), -Vec3d::UnitX(), Vec3d::UnitY(), -Vec3d::UnitY(), Vec3d::UnitZ(), -Vec3d::UnitZ(),
|
||||
Vec3d(1., 1., 0.).normalized(), Vec3d(1., 1., 1.).normalized(), Vec3d(-1., 0., 1.).normalized()};
|
||||
for (int i = -2; i <= 10; ++i)
|
||||
for (int j = -2; j <= 10; ++j)
|
||||
for (const Vec3d &dir : axis_dirs)
|
||||
rays.emplace_back(Vec3d(i / 8., j / 8., -1.) - dir * 2., dir);
|
||||
// Random rays aimed at random mesh vertices, so that most of them hit.
|
||||
std::uniform_int_distribution<size_t> vertex_idx(0, mesh.vertices.size() - 1);
|
||||
for (int i = 0; i < 20000; ++i) {
|
||||
const Vec3d origin(coord(rng), coord(rng), coord(rng));
|
||||
const Vec3d target = mesh.vertices[vertex_idx(rng)].cast<double>() + Vec3d(unit(rng), unit(rng), unit(rng)) * 0.01;
|
||||
if ((target - origin).squaredNorm() > 1e-6)
|
||||
rays.emplace_back(origin, (target - origin).normalized());
|
||||
}
|
||||
|
||||
size_t hits = 0;
|
||||
size_t mismatches = 0;
|
||||
for (const auto &[origin, dir] : rays) {
|
||||
igl::Hit<float> hit{-1, -1, 0.f, 0.f, 0.f};
|
||||
const bool found = AABBTreeIndirect::intersect_ray_first_hit(mesh.vertices, mesh.indices, tree, origin, dir, hit);
|
||||
|
||||
const auto ray_intersector = AABBTreeIndirect::detail::RayIntersector<stl_vertex, stl_triangle_vertex_indices, AABBTreeIndirect::Tree<3, float>, Vec3d>{
|
||||
mesh.vertices, mesh.indices, tree, origin, dir, Vec3d(dir.cwiseInverse()), 0.000001};
|
||||
igl::Hit<float> expected{-1, -1, 0.f, 0.f, 0.f};
|
||||
const bool expected_found = reference_first_hit(ray_intersector, size_t(0), std::numeric_limits<double>::infinity(), expected);
|
||||
|
||||
hits += found;
|
||||
if (found != expected_found || (found && (hit.id != expected.id || hit.t != expected.t || hit.u != expected.u || hit.v != expected.v)))
|
||||
++mismatches;
|
||||
}
|
||||
CHECK(hits > rays.size() / 2);
|
||||
CHECK(mismatches == 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1109,3 +1109,67 @@ TEST_CASE("Arrange keeps relevant objects outside conditional exclusion obstacle
|
|||
}
|
||||
require_no_overlap(items);
|
||||
}
|
||||
|
||||
TEST_CASE("Objects taller than the rod clearance stay out of the Y span of a compacted prime tower", "[Arrange]")
|
||||
{
|
||||
// A tower spanning Y 180..240 at the right edge of the bed, with no extra growth on its polygon.
|
||||
ArrangePolygon tower;
|
||||
Polygon outline;
|
||||
outline.points = {Point(scaled(180.), scaled(180.)), Point(scaled(240.), scaled(180.)), Point(scaled(240.), scaled(240.)), Point(scaled(180.), scaled(240.))};
|
||||
tower.poly = ExPolygon(outline);
|
||||
tower.bed_idx = 0;
|
||||
tower.is_virt_object = true;
|
||||
tower.is_wipe_tower = true;
|
||||
|
||||
ArrangeParams params = quiet_params(scaled(2.));
|
||||
params.clearance_height_to_rod = 24.f;
|
||||
params.clearance_dist_to_rod = 40.f;
|
||||
params.compacted_tower_growth = 0;
|
||||
|
||||
// The pile gathers around the tower, so without the rule the objects end up beside it. A
|
||||
// best_object_pos away from the bed centre, as some printer profiles set, must not carry the
|
||||
// pile back into the span either.
|
||||
for (const Vec2d &align_center : {Vec2d(0.5, 0.5), Vec2d(0.3, 0.5), Vec2d(0.7, 0.5), Vec2d(0.5, 0.7)}) {
|
||||
INFO("best_object_pos " << align_center.x() << "x" << align_center.y());
|
||||
params.align_center = align_center;
|
||||
ArrangePolygons items = squares(4, 40., 50.);
|
||||
arrange(items, {tower}, bed(250, 250), params);
|
||||
|
||||
for (const ArrangePolygon &ap : items) {
|
||||
REQUIRE(ap.bed_idx == 0);
|
||||
CHECK(ap.transformed_poly().contour.bounding_box().max.y() <= scaled(180. - 40.));
|
||||
}
|
||||
}
|
||||
|
||||
// Objects that stay under the rod may share the span.
|
||||
params.align_center = Vec2d(0.5, 0.5);
|
||||
ArrangePolygons low = squares(4, 40., 10.);
|
||||
arrange(low, {tower}, bed(250, 250), params);
|
||||
CHECK(std::any_of(low.begin(), low.end(), [](const ArrangePolygon &ap) {
|
||||
return ap.transformed_poly().contour.bounding_box().max.y() > scaled(180. - 40.);
|
||||
}));
|
||||
}
|
||||
|
||||
TEST_CASE("Objects no taller than the nozzle height only keep the nozzle cone from a compacted prime tower", "[Arrange]")
|
||||
{
|
||||
// A K2: toolhead radius 64 mm, nozzle height 4 mm.
|
||||
const double toolhead_radius = 64.;
|
||||
ArrangeParams params;
|
||||
params.nozzle_height = 4.f;
|
||||
|
||||
ArrangePolygon keychain;
|
||||
keychain.height = 3.;
|
||||
ArrangePolygon at_nozzle_height;
|
||||
at_nozzle_height.height = 4.;
|
||||
ArrangePolygon tall;
|
||||
tall.height = 30.;
|
||||
|
||||
using Catch::Matchers::WithinAbs;
|
||||
CHECK_THAT(compacted_tower_arrange_clearance({keychain, at_nozzle_height}, params, toolhead_radius), WithinAbs(MAX_OUTER_NOZZLE_DIAMETER, EPSILON));
|
||||
// The tower is one polygon for all the objects placed, so one taller object gives every one of
|
||||
// them the toolhead radius.
|
||||
CHECK_THAT(compacted_tower_arrange_clearance({keychain, tall}, params, toolhead_radius), WithinAbs(toolhead_radius, EPSILON));
|
||||
CHECK_THAT(compacted_tower_arrange_clearance({tall}, params, toolhead_radius), WithinAbs(toolhead_radius, EPSILON));
|
||||
// find_new_position() passes no objects.
|
||||
CHECK_THAT(compacted_tower_arrange_clearance({}, params, toolhead_radius), WithinAbs(toolhead_radius, EPSILON));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2042,3 +2042,50 @@ TEST_CASE("The print speed table keeps a bed outline when the extruders share no
|
|||
CHECK(outline.min == Point(0, 0));
|
||||
CHECK(outline.max == Point(scaled(350.), scaled(350.)));
|
||||
}
|
||||
|
||||
static ConfigOptionInts make_pem(std::vector<int> v) {
|
||||
ConfigOptionInts o;
|
||||
o.values = std::move(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - authored map wins", "[Config][PhysicalExtruderMap]") {
|
||||
// An AFC manifold on a 7-extruder machine: logical 0-3 all feed physical 0. Not derivable,
|
||||
// so it must be honoured verbatim.
|
||||
auto explicit_pem = make_pem({0, 0, 0, 0, 1, 2, 3});
|
||||
auto out = effective_physical_extruder_map(&explicit_pem, 7);
|
||||
REQUIRE(out.values == std::vector<int>{0, 0, 0, 0, 1, 2, 3});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - a permutation is honoured", "[Config][PhysicalExtruderMap]") {
|
||||
// Shipping BBL dual-nozzle profiles author {1,0}: a slicer/firmware numbering swap, not a
|
||||
// sharing map. Deriving over it would silently renumber both extruders.
|
||||
auto explicit_pem = make_pem({1, 0});
|
||||
auto out = effective_physical_extruder_map(&explicit_pem, 2);
|
||||
REQUIRE(out.values == std::vector<int>{1, 0});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - unauthored derives the identity", "[Config][PhysicalExtruderMap]") {
|
||||
// The PrintConfig default is a single element, which is not an authored map on a 2-extruder
|
||||
// machine. Identity is what upstream itself falls back to.
|
||||
auto default_pem = make_pem({0});
|
||||
auto out = effective_physical_extruder_map(&default_pem, 2);
|
||||
REQUIRE(out.values == std::vector<int>{0, 1});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - result is always one entry per extruder", "[Config][PhysicalExtruderMap]") {
|
||||
// The defining property: consumers index this map by logical extruder and size their own
|
||||
// arrays from nozzle_diameter, so a shorter map is an out-of-bounds read in several of them.
|
||||
for (int n : { 1, 2, 4, 7 }) {
|
||||
DYNAMIC_SECTION("nozzle count " << n) {
|
||||
REQUIRE((int) effective_physical_extruder_map(nullptr, n).values.size() == n);
|
||||
auto stale = make_pem({0}); // wrong length: must not be mistaken for authored
|
||||
REQUIRE((int) effective_physical_extruder_map(&stale, n).values.size() == n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - degenerate nozzle count still yields a usable map", "[Config][PhysicalExtruderMap]") {
|
||||
// Never hand back an empty map: several consumers index it as a raw vector.
|
||||
REQUIRE(effective_physical_extruder_map(nullptr, 0).values == std::vector<int>{0});
|
||||
}
|
||||
|
|
|
|||
65
tests/libslic3r/test_expolygon.cpp
Normal file
65
tests/libslic3r/test_expolygon.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include "libslic3r/Polygon.hpp"
|
||||
#include "libslic3r/Polyline.hpp"
|
||||
#include "libslic3r/libslic3r.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
namespace {
|
||||
|
||||
Polygon square(double x0, double y0, double size)
|
||||
{
|
||||
return Polygon{ Point::new_scale(x0, y0), Point::new_scale(x0 + size, y0), Point::new_scale(x0 + size, y0 + size),
|
||||
Point::new_scale(x0, y0 + size) };
|
||||
}
|
||||
|
||||
Polyline polyline(std::initializer_list<Vec2d> points)
|
||||
{
|
||||
Polyline out;
|
||||
for (const Vec2d &p : points)
|
||||
out.points.emplace_back(Point::new_scale(p.x(), p.y()));
|
||||
return out;
|
||||
}
|
||||
|
||||
// A 10 mm square with a 2 mm square hole at its center.
|
||||
ExPolygon square_with_hole()
|
||||
{
|
||||
ExPolygon expoly(square(0., 0., 10.));
|
||||
Polygon hole = square(4., 4., 2.);
|
||||
hole.reverse();
|
||||
expoly.holes.emplace_back(std::move(hole));
|
||||
return expoly;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("A polyline running inside an expolygon is contained in it", "[ExPolygon]")
|
||||
{
|
||||
const ExPolygon expoly = square_with_hole();
|
||||
CHECK(expoly.contains(polyline({ { 1., 1. }, { 9., 1. }, { 9., 9. } })));
|
||||
}
|
||||
|
||||
TEST_CASE("A polyline leaving an expolygon is not contained in it", "[ExPolygon]")
|
||||
{
|
||||
const ExPolygon expoly = square_with_hole();
|
||||
// Out through the contour, far beyond the bounding box and just past it.
|
||||
CHECK_FALSE(expoly.contains(polyline({ { 1., 1. }, { 20., 1. } })));
|
||||
CHECK_FALSE(expoly.contains(polyline({ { 1., 1. }, { 10.01, 1. } })));
|
||||
// Across the hole.
|
||||
CHECK_FALSE(expoly.contains(polyline({ { 1., 5. }, { 9., 5. } })));
|
||||
}
|
||||
|
||||
TEST_CASE("A polyline within the bounding box but outside of a concave expolygon is not contained in it", "[ExPolygon]")
|
||||
{
|
||||
// An L shape: the 10 mm square without its top right 5 mm quarter.
|
||||
const ExPolygon l_shape(Polygon{ Point::new_scale(0., 0.), Point::new_scale(10., 0.), Point::new_scale(10., 5.),
|
||||
Point::new_scale(5., 5.), Point::new_scale(5., 10.), Point::new_scale(0., 10.) });
|
||||
CHECK_FALSE(l_shape.contains(polyline({ { 1., 1. }, { 9., 1. }, { 9., 9. } })));
|
||||
CHECK(l_shape.contains(polyline({ { 1., 1. }, { 9., 1. }, { 4., 4. }, { 1., 9. } })));
|
||||
}
|
||||
|
|
@ -30,47 +30,6 @@ static ConfigOptionInts make_pem(std::vector<int> v) {
|
|||
return o;
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - authored map wins", "[IMEX]") {
|
||||
// An AFC manifold on a 7-extruder machine: logical 0-3 all feed physical 0. Not derivable,
|
||||
// so it must be honoured verbatim.
|
||||
auto explicit_pem = make_pem({0, 0, 0, 0, 1, 2, 3});
|
||||
auto out = effective_physical_extruder_map(&explicit_pem, 7);
|
||||
REQUIRE(out.values == std::vector<int>{0, 0, 0, 0, 1, 2, 3});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - a permutation is honoured", "[IMEX]") {
|
||||
// Shipping BBL dual-nozzle profiles author {1,0}: a slicer/firmware numbering swap, not a
|
||||
// sharing map. Deriving over it would silently renumber both extruders.
|
||||
auto explicit_pem = make_pem({1, 0});
|
||||
auto out = effective_physical_extruder_map(&explicit_pem, 2);
|
||||
REQUIRE(out.values == std::vector<int>{1, 0});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - unauthored derives the identity", "[IMEX]") {
|
||||
// The PrintConfig default is a single element, which is not an authored map on a 2-extruder
|
||||
// machine. Identity is what upstream itself falls back to.
|
||||
auto default_pem = make_pem({0});
|
||||
auto out = effective_physical_extruder_map(&default_pem, 2);
|
||||
REQUIRE(out.values == std::vector<int>{0, 1});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - result is always one entry per extruder", "[IMEX]") {
|
||||
// The defining property: consumers index this map by logical extruder and size their own
|
||||
// arrays from nozzle_diameter, so a shorter map is an out-of-bounds read in several of them.
|
||||
for (int n : { 1, 2, 4, 7 }) {
|
||||
DYNAMIC_SECTION("nozzle count " << n) {
|
||||
REQUIRE((int) effective_physical_extruder_map(nullptr, n).values.size() == n);
|
||||
auto stale = make_pem({0}); // wrong length: must not be mistaken for authored
|
||||
REQUIRE((int) effective_physical_extruder_map(&stale, n).values.size() == n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - degenerate nozzle count still yields a usable map", "[IMEX]") {
|
||||
// Never hand back an empty map: several consumers index it as a raw vector.
|
||||
REQUIRE(effective_physical_extruder_map(nullptr, 0).values == std::vector<int>{0});
|
||||
}
|
||||
|
||||
TEST_CASE("effective_physical_extruder_map - IDEX ghost-color regression guard", "[IMEX]") {
|
||||
// Dual extruder, no authored map. Before the GUI fix this produced a black ghost on T1
|
||||
// because first_filament_for_physical_head({0}, 1) == -1.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <catch2/catch_all.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "libslic3r/TriangleMesh.hpp"
|
||||
|
|
@ -135,6 +136,25 @@ TEST_CASE("Splitting a part drops pieces enclosing no volume and keeps the part
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("A part asked from several threads at once whether it can be split answers the same for all", "[Model]")
|
||||
{
|
||||
// The PrintObjects made from one ModelObject prepare their infill at the same time, and each asks the object's first
|
||||
// part whether it can be split, which fills a cache in the part. Without the lock around the cache the answers
|
||||
// still agree on most runs: ThreadSanitizer is what reports the race.
|
||||
Model model;
|
||||
ModelObject *object = model.add_object();
|
||||
const ModelVolume *volume = object->add_volume(flat_triangle_then_cubes({0., 30.}), ModelVolumeType::MODEL_PART, false);
|
||||
|
||||
std::vector<char> answers(8, 0);
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t i = 0; i < answers.size(); ++ i)
|
||||
threads.emplace_back([volume, &answers, i] { answers[i] = volume->is_splittable() ? 1 : 0; });
|
||||
for (std::thread &thread : threads)
|
||||
thread.join();
|
||||
|
||||
CHECK(std::all_of(answers.begin(), answers.end(), [](char answer) { return answer == 1; }));
|
||||
}
|
||||
|
||||
TEST_CASE("Splitting a part with a single solid piece keeps just that piece", "[Model]")
|
||||
{
|
||||
Model model;
|
||||
|
|
|
|||
64
tests/libslic3r/test_parallel_for_first_error.cpp
Normal file
64
tests/libslic3r/test_parallel_for_first_error.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/catch_message.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/blocked_range.h>
|
||||
#include <tbb/parallel_for.h>
|
||||
|
||||
#include "libslic3r/ParallelForFirstError.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
TEST_CASE("parallel_for_first_error throws the error of the lowest item that threw, after every item below it ran", "[ParallelForFirstError]")
|
||||
{
|
||||
// Items 9 and 3 throw. A loop over the items stops at item 3, so its error is the one thrown, and the items before
|
||||
// it all run. Each item is written by one task only, and read after the loop.
|
||||
const size_t items_per_task = GENERATE(size_t(1), size_t(4));
|
||||
INFO(items_per_task << " items per task");
|
||||
const size_t count = 64;
|
||||
std::vector<char> ran(count, 0);
|
||||
std::string thrown;
|
||||
try {
|
||||
parallel_for_first_error(count, items_per_task, [&ran](size_t i) {
|
||||
ran[i] = 1;
|
||||
if (i == 3 || i == 9)
|
||||
throw std::runtime_error("item " + std::to_string(i));
|
||||
});
|
||||
} catch (const std::runtime_error &error) {
|
||||
thrown = error.what();
|
||||
}
|
||||
CHECK(thrown == "item 3");
|
||||
for (size_t i = 0; i <= 3; ++ i)
|
||||
CHECK(ran[i] == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("parallel_for_first_error starts no item on a thread that waits in another item's parallel loop", "[ParallelForFirstError]")
|
||||
{
|
||||
// Each item runs a parallel loop of its own. A thread waiting for its item's loop could otherwise take another
|
||||
// item meanwhile, which would then run nested in the first one on that thread.
|
||||
static thread_local int items_on_thread = 0;
|
||||
std::atomic<bool> nested { false };
|
||||
parallel_for_first_error(64, 1, [&nested](size_t) {
|
||||
if (items_on_thread > 0)
|
||||
nested = true;
|
||||
++ items_on_thread;
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, 256), [](const tbb::blocked_range<size_t> &range) {
|
||||
double sum = 0.;
|
||||
for (size_t i = range.begin(); i < range.end(); ++ i)
|
||||
for (int k = 1; k < 2000; ++ k)
|
||||
sum += std::sqrt(double(i * size_t(k)));
|
||||
// Keeps the work from being optimized away.
|
||||
if (sum < 0.)
|
||||
throw std::logic_error("negative sum");
|
||||
});
|
||||
-- items_on_thread;
|
||||
});
|
||||
CHECK_FALSE(nested);
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ add_executable(${_TEST_NAME}_tests
|
|||
test_device_progress.cpp
|
||||
test_device_manager_integration.cpp
|
||||
test_web_media_controller.cpp
|
||||
test_part_plate.cpp
|
||||
test_scene_raycaster.cpp
|
||||
test_scene_benchmark.cpp
|
||||
test_lazy.cpp
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
|
|
@ -73,11 +74,13 @@ struct Message
|
|||
std::string payload;
|
||||
};
|
||||
|
||||
// Serves the printer's HTTP API and its websocket on one port.
|
||||
// Serves the printer's HTTP API and its websocket on one port. With file_lists, each G-code file list query gets the next one,
|
||||
// and the last one once they run out.
|
||||
class FakeCrealityPrinter
|
||||
{
|
||||
public:
|
||||
FakeCrealityPrinter(Behavior behavior, std::string model) : m_behavior(behavior), m_model(std::move(model))
|
||||
FakeCrealityPrinter(Behavior behavior, std::string model, std::vector<std::string> file_lists = {})
|
||||
: m_behavior(behavior), m_model(std::move(model)), m_file_lists(std::move(file_lists))
|
||||
{
|
||||
m_accept_thread = std::thread([this] { accept_loop(); });
|
||||
}
|
||||
|
|
@ -110,6 +113,12 @@ public:
|
|||
return m_http_requests;
|
||||
}
|
||||
|
||||
int websocket_requests()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_websocket_requests;
|
||||
}
|
||||
|
||||
// Hangs up every connection that is waiting.
|
||||
void release()
|
||||
{
|
||||
|
|
@ -144,6 +153,10 @@ private:
|
|||
serve_http(socket, request);
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
++m_websocket_requests;
|
||||
}
|
||||
if (m_behavior == Behavior::SilentBeforeHandshake) {
|
||||
wait_for_release();
|
||||
return;
|
||||
|
|
@ -171,6 +184,15 @@ private:
|
|||
m_messages.push_back({ws.got_text(), payload});
|
||||
}
|
||||
const std::string slots = R"({"boxsInfo":{"materialBoxs":[]}})";
|
||||
if (!m_file_lists.empty() && payload.find("reqGcodeFile") != std::string::npos) {
|
||||
std::string file_list;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
file_list = m_file_lists[std::min(m_file_list_replies++, m_file_lists.size() - 1)];
|
||||
}
|
||||
ws.write(net::buffer(file_list), ec);
|
||||
continue;
|
||||
}
|
||||
if (first && m_behavior == Behavior::ReportsNoCfs) {
|
||||
ws.write(net::buffer(std::string(R"({"cfsConnect":0,"nozzleTemp":"25.000000"})")), ec);
|
||||
wait_for_release();
|
||||
|
|
@ -236,6 +258,7 @@ private:
|
|||
|
||||
const Behavior m_behavior;
|
||||
const std::string m_model;
|
||||
const std::vector<std::string> m_file_lists;
|
||||
net::io_context m_accept_ioc;
|
||||
tcp::acceptor m_acceptor{m_accept_ioc, {net::ip::make_address("127.0.0.1"), 0}};
|
||||
std::atomic<bool> m_stopping{false};
|
||||
|
|
@ -245,6 +268,8 @@ private:
|
|||
std::condition_variable m_changed;
|
||||
std::vector<Message> m_messages;
|
||||
int m_http_requests = 0;
|
||||
int m_websocket_requests = 0;
|
||||
std::size_t m_file_list_replies = 0;
|
||||
bool m_released = false;
|
||||
};
|
||||
|
||||
|
|
@ -276,6 +301,7 @@ std::unique_ptr<TestHost> make_host(const FakeCrealityPrinter& printer, std::chr
|
|||
host->ws_settings.reply = deadline;
|
||||
host->ws_settings.slots_reply = deadline;
|
||||
host->ws_settings.no_cfs_reply = deadline;
|
||||
host->ws_settings.files_reply = deadline;
|
||||
host->ws_settings.close = deadline;
|
||||
return host;
|
||||
}
|
||||
|
|
@ -294,18 +320,39 @@ template<class Call> bool finishes_within(FakeCrealityPrinter& printer, std::chr
|
|||
return in_time;
|
||||
}
|
||||
|
||||
bool upload_and_print(const CrealityPrint& host, wxString& error, const std::map<std::string, std::string>& extended_info = {})
|
||||
bool upload_and_print(const CrealityPrint& host,
|
||||
wxString& error,
|
||||
const std::map<std::string, std::string>& extended_info = {},
|
||||
const std::string& upload_path = "test.gcode")
|
||||
{
|
||||
const ScopedTemporaryFile source(".gcode");
|
||||
std::ofstream(source.string()) << "G28\n";
|
||||
PrintHostUpload upload;
|
||||
upload.source_path = source.path();
|
||||
upload.upload_path = "test.gcode";
|
||||
upload.upload_path = upload_path;
|
||||
upload.post_action = PrintHostPostUploadAction::StartPrint;
|
||||
upload.extended_info = extended_info;
|
||||
return host.upload(upload, [](Http::Progress, bool&) {}, [&](wxString message) { error = message; }, [](wxString, wxString) {});
|
||||
}
|
||||
|
||||
bool is_file_list_query(const Message& message) { return message.payload.find("reqGcodeFile") != std::string::npos; }
|
||||
|
||||
int file_list_queries(FakeCrealityPrinter& printer)
|
||||
{
|
||||
const std::vector<Message> messages = printer.messages();
|
||||
return static_cast<int>(std::count_if(messages.begin(), messages.end(), is_file_list_query));
|
||||
}
|
||||
|
||||
// The start commands, without the G-code file list query and the heartbeat acknowledgement sent on its connection.
|
||||
std::vector<Message> start_messages(FakeCrealityPrinter& printer)
|
||||
{
|
||||
std::vector<Message> messages = printer.messages();
|
||||
messages.erase(std::remove_if(messages.begin(), messages.end(),
|
||||
[](const Message& message) { return is_file_list_query(message) || message.payload == "ok"; }),
|
||||
messages.end());
|
||||
return messages;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Querying the CFS slots gives a silent printer no more than its deadlines", "[CrealityPrint]")
|
||||
|
|
@ -510,11 +557,14 @@ TEST_CASE("Starting a print gives a silent printer no more than its deadlines",
|
|||
CHECK(result == started);
|
||||
CHECK(error.empty() == started);
|
||||
CHECK(error.StartsWith("Connection timed out") == !started);
|
||||
// A printer that never completes the handshake for the G-code file list query gets no second connection for the start.
|
||||
CHECK(printer.websocket_requests() == (started ? 2 : 1));
|
||||
}
|
||||
|
||||
TEST_CASE("Starting a print sends each command with the G-code path in a text frame", "[CrealityPrint]")
|
||||
{
|
||||
// F008 is a multi-color model and F018 a plain one. K1C, F005 (Ender-3 V3 KE) and F016 (K2 SE) keep their G-code under /usr/data.
|
||||
// The printer never answers the G-code file list query, so the model decides the folder. F008 is a multi-color model and F018
|
||||
// a plain one. K1C, F005 (Ender-3 V3 KE), F016 (K2 SE) and a Nebula Pad on an Ender-3 V2 Neo keep their G-code under /usr/data.
|
||||
// Only a mapping onto CFS slots starts a multi-color print; a printer that listed no slots starts plainly.
|
||||
const std::map<std::string, std::string> cfs_mapping = {{"enableSelfTest", "0"}, {"colorMatch_0", "T1A\tPLA\t#FF0000\t1\t0"}};
|
||||
const auto [model, extended_info, commands, gcode] = GENERATE_REF(table<std::string, std::map<std::string, std::string>, std::vector<std::string>, std::string>({
|
||||
|
|
@ -522,6 +572,7 @@ TEST_CASE("Starting a print sends each command with the G-code path in a text fr
|
|||
{"F008", {}, {"opGcodeFile"}, "printprt:/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
{"F018", {}, {"opGcodeFile"}, "printprt:/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
{"F005", {}, {"opGcodeFile"}, "printprt:/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"Ender-3 V2 Neo", {}, {"opGcodeFile"}, "printprt:/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"F016", cfs_mapping, {"colorMatch", "multiColorPrint"}, "/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"K1C", cfs_mapping, {"colorMatch", "multiColorPrint"}, "/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"K1C", {}, {"opGcodeFile"}, "printprt:/usr/data/printer_data/gcodes/test.gcode"},
|
||||
|
|
@ -530,11 +581,12 @@ TEST_CASE("Starting a print sends each command with the G-code path in a text fr
|
|||
|
||||
FakeCrealityPrinter printer(Behavior::Answers, model);
|
||||
const auto host = make_host(printer, 5s);
|
||||
host->ws_settings.files_reply = 200ms;
|
||||
wxString error;
|
||||
|
||||
CHECK(upload_and_print(*host, error, extended_info));
|
||||
CHECK(error.empty());
|
||||
const std::vector<Message> messages = printer.messages();
|
||||
const std::vector<Message> messages = start_messages(printer);
|
||||
REQUIRE(messages.size() == commands.size());
|
||||
for (std::size_t i = 0; i < messages.size(); ++i) {
|
||||
CAPTURE(i);
|
||||
|
|
@ -545,6 +597,89 @@ TEST_CASE("Starting a print sends each command with the G-code path in a text fr
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Starting a print uses the path the printer lists the upload at", "[CrealityPrint]")
|
||||
{
|
||||
// K1-family firmware lists "folder:name:size:..." entries, escaping its slashes, and K2-family firmware files with their path.
|
||||
// The listed path decides over the model, which would give F018 and the unlisted F099 /mnt/UDISK and K1C /usr/data. Only the
|
||||
// upload counts: another file, a list without files, or a list in a format this host does not read leave the folder to the
|
||||
// model. A name holding ';' and a file in a subfolder are still found. A name that is not UTF-8 makes the printer's text frame
|
||||
// invalid, so the whole list is lost and the model decides, but the print still starts.
|
||||
const std::string k1_upload = R"({"retGcodeFileInfo":{"totalNum":1,"fileInfo":"\/usr\/data\/printer_data\/gcodes:test.gcode:63301:0.240000:1794188820:109:\/tmp\/test.png;"}})";
|
||||
const std::string k1_other = R"({"retGcodeFileInfo":{"totalNum":1,"fileInfo":"/usr/data/printer_data/gcodes:other.gcode:63301:0.240000:1794188820:109:/tmp/other.png;"}})";
|
||||
const std::string k1_semicolon = R"({"retGcodeFileInfo":{"totalNum":2,"fileInfo":"/usr/data/printer_data/gcodes:other.gcode:63301:0.240000:1794188820:109:/tmp/other.png;)"
|
||||
R"(/usr/data/printer_data/gcodes:a;b.gcode:63301:0.240000:1794188820:109:/tmp/a;b.png;"}})";
|
||||
const std::string k1_subfolder = R"({"retGcodeFileInfo":{"totalNum":2,"fileInfo":"/usr/data/printer_data/gcodes:test.gcode:63301:0.240000:1794188820:109:/tmp/test.png;)"
|
||||
R"(/usr/data/printer_data/gcodes/parts:test.gcode:63301:0.240000:1794188820:109:/tmp/test.png;"}})";
|
||||
const std::string k2_upload = R"({"retGcodeFileInfo2":[{"name":"test.gcode","path":"/mnt/UDISK/printer_data/gcodes/test.gcode","type":8}]})";
|
||||
const std::string k2_both = R"({"retGcodeFileInfo2":[{"name":"other.gcode","path":"/usr/data/printer_data/gcodes/other.gcode","type":8},)"
|
||||
R"({"name":"test.gcode","path":"/mnt/UDISK/printer_data/gcodes/test.gcode","type":8}]})";
|
||||
const std::string k2_not_utf8 = R"({"retGcodeFileInfo2":[{"name":"x.gcode","path":"/mnt/UDISK/printer_data/gcodes/)" "\xff" R"(.gcode","type":8},)"
|
||||
R"({"name":"test.gcode","path":"/mnt/UDISK/printer_data/gcodes/test.gcode","type":8}]})";
|
||||
const std::string no_files = R"({"retGcodeFileInfo2":[]})";
|
||||
const std::string no_folders = R"({"retGcodeFileInfo3":{"fileInfo":"test.gcode:63301:1794188820;"}})";
|
||||
const auto [model, upload_path, file_list, gcode] = GENERATE_REF(table<std::string, std::string, std::string, std::string>({
|
||||
{"F099", "test.gcode", k1_upload, "/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"F018", "test.gcode", k1_other, "/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
{"F018", "a;b.gcode", k1_semicolon, "/usr/data/printer_data/gcodes/a;b.gcode"},
|
||||
{"F018", "parts/test.gcode", k1_subfolder, "/usr/data/printer_data/gcodes/parts/test.gcode"},
|
||||
{"K1C", "test.gcode", k2_upload, "/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
{"K1C", "test.gcode", k2_both, "/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
{"K1C", "test.gcode", k2_not_utf8, "/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"F005", "test.gcode", no_files, "/usr/data/printer_data/gcodes/test.gcode"},
|
||||
{"F018", "test.gcode", no_files, "/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
{"F018", "test.gcode", no_folders, "/mnt/UDISK/printer_data/gcodes/test.gcode"},
|
||||
}));
|
||||
CAPTURE(model, upload_path, file_list);
|
||||
|
||||
FakeCrealityPrinter printer(Behavior::Answers, model, {file_list});
|
||||
const auto host = make_host(printer, 5s);
|
||||
host->ws_settings.files_reply = 300ms;
|
||||
host->ws_settings.files_retry = 50ms;
|
||||
wxString error;
|
||||
|
||||
CHECK(upload_and_print(*host, error, {}, upload_path));
|
||||
CHECK(error.empty());
|
||||
const std::vector<Message> messages = printer.messages();
|
||||
REQUIRE_FALSE(messages.empty());
|
||||
CHECK(is_file_list_query(messages[0]));
|
||||
CHECK(messages[0].text);
|
||||
const std::vector<Message> start = start_messages(printer);
|
||||
REQUIRE(start.size() == 1);
|
||||
const nlohmann::json params = nlohmann::json::parse(start[0].payload).at("params");
|
||||
CHECK(params.at("opGcodeFile") == "printprt:" + gcode);
|
||||
}
|
||||
|
||||
TEST_CASE("Starting a print asks again for a file list that does not list the upload yet", "[CrealityPrint]")
|
||||
{
|
||||
// The first list comes before the printer has indexed the upload. K1C's model alone would give /usr/data.
|
||||
const std::string no_files = R"({"retGcodeFileInfo2":[]})";
|
||||
const std::string k2_upload = R"({"retGcodeFileInfo2":[{"name":"test.gcode","path":"/mnt/UDISK/printer_data/gcodes/test.gcode","type":8}]})";
|
||||
FakeCrealityPrinter printer(Behavior::Answers, "K1C", {no_files, k2_upload});
|
||||
const auto host = make_host(printer, 5s);
|
||||
host->ws_settings.files_retry = 50ms;
|
||||
wxString error;
|
||||
|
||||
CHECK(upload_and_print(*host, error));
|
||||
CHECK(error.empty());
|
||||
CHECK(file_list_queries(printer) == 2);
|
||||
const std::vector<Message> start = start_messages(printer);
|
||||
REQUIRE(start.size() == 1);
|
||||
CHECK(nlohmann::json::parse(start[0].payload).at("params").at("opGcodeFile") == "printprt:/mnt/UDISK/printer_data/gcodes/test.gcode");
|
||||
}
|
||||
|
||||
TEST_CASE("Starting a print asks once for a file list in a format this host does not read", "[CrealityPrint]")
|
||||
{
|
||||
const std::string no_folders = R"({"retGcodeFileInfo3":{"fileInfo":"test.gcode:63301:1794188820;"}})";
|
||||
FakeCrealityPrinter printer(Behavior::Answers, "F018", {no_folders});
|
||||
const auto host = make_host(printer, 5s);
|
||||
host->ws_settings.files_retry = 50ms;
|
||||
wxString error;
|
||||
|
||||
CHECK(upload_and_print(*host, error));
|
||||
CHECK(error.empty());
|
||||
CHECK(file_list_queries(printer) == 1);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
const std::string gcode_path = "/usr/data/printer_data/gcodes/part.gcode";
|
||||
|
|
|
|||
|
|
@ -88,10 +88,17 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int set_user_selected_machine(std::string dev_id) override
|
||||
{
|
||||
++selections;
|
||||
return OrcaPrinterAgent::set_user_selected_machine(std::move(dev_id));
|
||||
}
|
||||
|
||||
std::string published_device;
|
||||
json published_message;
|
||||
std::string connected_ca_file;
|
||||
int reply = 0; // what a send returns: 0 when the printer took the message
|
||||
int selections{0};
|
||||
|
||||
private:
|
||||
AgentInfo m_info;
|
||||
|
|
@ -296,6 +303,37 @@ TEST_CASE("Logging out cancels a pending last-machine restore", "[DeviceManager]
|
|||
CHECK_FALSE(manager.has_pending_last_machine_restore());
|
||||
}
|
||||
|
||||
TEST_CASE("A cloud server connection selects a cloud printer again but leaves a LAN printer alone", "[DeviceManager][integration]")
|
||||
{
|
||||
ScopedAppConfig app_config;
|
||||
auto agent = std::make_shared<TestPrinterAgent>("integration-agent");
|
||||
NetworkAgent network(nullptr, agent);
|
||||
network.set_printer_agent(agent);
|
||||
DeviceManager manager(&network, false, &app_config.config);
|
||||
|
||||
BBLocalMachine machine;
|
||||
machine.dev_id = "integration-lan-device";
|
||||
machine.dev_name = "Integration LAN device";
|
||||
machine.dev_ip = "192.0.2.10";
|
||||
machine.printer_type = "C11";
|
||||
REQUIRE(manager.insert_local_device(machine, "lan", "free", "", "access-code") != nullptr);
|
||||
manager.parse_user_print_info(machine_list_response(ORCA_CLOUD_PROVIDER, "integration-agent",
|
||||
network.get_user_machine_list_generation(), "Cloud printer"));
|
||||
REQUIRE(manager.get_user_machinelist().count("integration-device") == 1);
|
||||
|
||||
// The agent names the LAN printer once it is connected, as the Bambu network plugin does.
|
||||
agent->set_user_selected_machine(machine.dev_id);
|
||||
agent->selections = 0;
|
||||
manager.reselect_cloud_machine();
|
||||
CHECK(agent->selections == 0);
|
||||
|
||||
agent->set_user_selected_machine("integration-device");
|
||||
agent->selections = 0;
|
||||
manager.reselect_cloud_machine();
|
||||
CHECK(agent->selections == 1);
|
||||
CHECK(agent->get_user_selected_machine() == "integration-device");
|
||||
}
|
||||
|
||||
TEST_CASE("A CA file stays with the agent that saved it when a device is rebound", "[DeviceManager][integration]")
|
||||
{
|
||||
ScopedAppConfig app_config;
|
||||
|
|
|
|||
69
tests/slic3rutils/test_part_plate.cpp
Normal file
69
tests/slic3rutils/test_part_plate.cpp
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// PartPlate.hpp reaches wx/wxprec.h, which needs the Windows headers first.
|
||||
#ifdef WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
// Match the GUI precompiled header: wx/msw/wrapcctl.h needs HDITEM from CommCtrl.h.
|
||||
#include <CommCtrl.h>
|
||||
#endif
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "slic3r/GUI/PartPlate.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
namespace {
|
||||
DynamicPrintConfig nozzle_config(std::vector<double> nozzle_diameters,
|
||||
std::vector<int> filament_map,
|
||||
std::vector<int> physical_extruder_map)
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value("nozzle_diameter", new ConfigOptionFloats(std::move(nozzle_diameters)));
|
||||
config.set_key_value("filament_map", new ConfigOptionInts(std::move(filament_map)));
|
||||
config.set_key_value("physical_extruder_map", new ConfigOptionInts(std::move(physical_extruder_map)));
|
||||
return config;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("A multi-nozzle printer without its own physical extruder map puts each filament on its own nozzle", "[PartPlate]")
|
||||
{
|
||||
// Four nozzles, filament n on nozzle n, and the single-entry physical_extruder_map default.
|
||||
const DynamicPrintConfig config = nozzle_config({0.4, 0.4, 0.4, 0.4}, {1, 2, 3, 4}, {0});
|
||||
const PartPlate plate;
|
||||
|
||||
const int filament_id = GENERATE(1, 2, 3, 4);
|
||||
CHECK(plate.get_physical_extruder_by_filament_id(config, filament_id) == filament_id - 1);
|
||||
}
|
||||
|
||||
TEST_CASE("A physical extruder map the profile sets decides the physical nozzle", "[PartPlate]")
|
||||
{
|
||||
// Two nozzles whose physical order is the reverse of the logical one, as on a two-nozzle Bambu printer.
|
||||
const DynamicPrintConfig config = nozzle_config({0.4, 0.4}, {1, 2}, {1, 0});
|
||||
const PartPlate plate;
|
||||
|
||||
CHECK(plate.get_physical_extruder_by_filament_id(config, 1) == 1);
|
||||
CHECK(plate.get_physical_extruder_by_filament_id(config, 2) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("A filament with no extruder to map to has no physical nozzle", "[PartPlate]")
|
||||
{
|
||||
// Filament 2 is mapped to a fifth extruder the printer does not have; filament 0 and 3 do not exist.
|
||||
const DynamicPrintConfig config = nozzle_config({0.4, 0.4, 0.4, 0.4}, {1, 5}, {0});
|
||||
const PartPlate plate;
|
||||
|
||||
CHECK(plate.get_physical_extruder_by_filament_id(config, 2) == -1);
|
||||
CHECK(plate.get_physical_extruder_by_filament_id(config, 0) == -1);
|
||||
CHECK(plate.get_physical_extruder_by_filament_id(config, 3) == -1);
|
||||
}
|
||||
|
|
@ -2779,14 +2779,14 @@ except TypeError:
|
|||
INFO("recorded audit arguments: " << python.str("WINAPI_AUDIT_CALLS"));
|
||||
CHECK(python.eval("WINAPI_AUDIT_CALLS == [(None, COMMAND_LINE, None)]") == "True");
|
||||
|
||||
// In a plugin scope the same call is prompted and denied, and the prompt names the command
|
||||
// line exactly as the caller passed it, which an approval saves as the process grant.
|
||||
// In a plugin scope the same call is prompted and denied. The quoted executable is the
|
||||
// permission target; its arguments are not part of the grant.
|
||||
python.run_as(PLUGIN, R"PY(
|
||||
create_process_outcome = attempt(lambda: _winapi.CreateProcess(
|
||||
None, COMMAND_LINE, None, None, False, 0, None, None, subprocess.STARTUPINFO()))
|
||||
)PY");
|
||||
CHECK(python.str("create_process_outcome") == "denied");
|
||||
CHECK(describe(harness.prompts) == "_winapi.CreateProcess: " + python.str("COMMAND_LINE") + "\n");
|
||||
CHECK(describe(harness.prompts) == "_winapi.CreateProcess: " + python.str("DENIED_EXECUTABLE") + "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue