I have an app where a user can create features, using the GeometryEditor class.
I also want to adjust/modify/apply constraints to the geometry as the user is drawing. I can use
for await geom in geometryEditor.$geometry {
// alter geom if needed, apply constraints etc.
if let altered = applyContraints(to: geom) {
geometryEditor.replaceGeomtry(with: altered)
}
}
This works, and the user experience is acceptable. However, this messes with the undo manager.
Is there a way to either fiddle with the undo stack, use a different method to apply a transform the geometry as the user is drawing?
Hi Svein, can you describe how the undo manager is messed up or showing unexpected behavior?
I assume that with your code, the behavior would be…
- When a user interactively change a geometry A, it will show the changed geometry B for a glimpse, then show the constraint applied geometry C immediately after.
- When a user tap redo once, it will revert from the constrained geometry C to the interactively edited geometry B; tapping the redo for another time will revert to the initial state A.
Is that what you are seeing or expecting?
---
Edit: I see the problem - when an edit is undone, it will trigger the async stream… thus the constraints are applied again. Let me see what can be done
There are 2 ideas that we came up with so far…
1. When you have the altered geometry in a local variable, call undo on the geometry editor so it reverts the last interactive step, then call replace geometry so that the altered geometry is on the undo stack. Although it still needs you to omit the geometry change that will cause the constraints being applied when undo is called - which may require an additional boolean flag.
2. Having 2 geometry editors, one for interactive changes and one for programmatic changes. Pretty alike the first solution, just using a separate stack to manage the operations.