mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-15 15:20:37 -08:00
Another Split refactor - maintain last operation
This commit is contained in:
parent
e08cc7173d
commit
73945ed27c
2 changed files with 11 additions and 23 deletions
|
|
@ -1,18 +1,8 @@
|
|||
"""
|
||||
OK, fwiw, the reason translate() creates a copy is because the use of copy=True in Shape._apply_transform(): https://github.com/CadQuery/cadquery/blob/c9d3f1e693d8d3b59054c8f10027c46a55342b22/cadquery/occ_impl/shapes.py#L846. I tried setting it to False and my original example passes.
|
||||
Thanks. Playing around a bit more, it seems like translate() makes the underlying TShapes unequal, but Shape.moved() preserves TShape. This returns true, which could be useful:
|
||||
|
||||
x1 = cq.Workplane().box(3,4,5)
|
||||
x2 = cq.Workplane(x1.findSolid().moved(cq.Location(cq.Vector(1,2,3),cq.Vector(4,5,6),7)))
|
||||
|
||||
f1 = x1.faces(">Z").val()
|
||||
f2 = x2.faces(">Z").val()
|
||||
|
||||
f1.wrapped.TShape() == f2.wrapped.TShape() <=== TRUE
|
||||
|
||||
@fpq473 - cadquery newbie
|
||||
Thanks. Playing around a bit more, it seems like translate() makes the underlying TShapes unequal, but Shape.moved() preserves TShape. This returns true, which could be useful: x1 = cq.Workplane().box(3,4,5) x2 = cq.Workplane(x1.findSolid().moved(cq.Location(cq.Vector(1,2,3),cq.Vector(4,5,6),7))) f1 = x1.faces(">Z").val() f2 = x2.faces(">Z").val() f1.wrapped.TShape() == f2.wrapped.TShape() <=== TRUE
|
||||
|
||||
TODO:
|
||||
- Update Vector so it can be initialized with a Vertex or Location
|
||||
- Update VectorLike to include a Vertex and Location
|
||||
"""
|
||||
from math import radians
|
||||
from typing import Union
|
||||
|
|
|
|||
|
|
@ -714,29 +714,27 @@ class Split(Compound):
|
|||
def __init__(self, bisect_by: Plane = Plane.named("XZ"), keep: Keep = Keep.TOP):
|
||||
max_size = BuildPart.get_context().BoundingBox().DiagonalLength
|
||||
|
||||
def split_part(part: Compound, keep: Keep) -> Compound:
|
||||
def build_cutter(keep: Keep) -> Solid:
|
||||
cutter_center = (
|
||||
Vector(-max_size, -max_size, 0)
|
||||
if keep == Keep.TOP
|
||||
else Vector(-max_size, -max_size, -2 * max_size)
|
||||
)
|
||||
cutter = bisect_by.fromLocalCoords(
|
||||
return bisect_by.fromLocalCoords(
|
||||
Solid.makeBox(2 * max_size, 2 * max_size, 2 * max_size).moved(
|
||||
Location(cutter_center)
|
||||
)
|
||||
)
|
||||
return self.intersect(cutter)
|
||||
|
||||
new_solids = []
|
||||
cutters = []
|
||||
if keep == Keep.BOTH:
|
||||
new_solids.append(split_part(BuildPart.get_context().part, Keep.TOP))
|
||||
new_solids.append(split_part(BuildPart.get_context().part, Keep.BOTTOM))
|
||||
cutters.append(build_cutter(Keep.TOP))
|
||||
cutters.append(build_cutter(Keep.BOTTOM))
|
||||
else:
|
||||
new_solids.append(split_part(BuildPart.get_context().part, keep))
|
||||
cutters.append(build_cutter(keep))
|
||||
|
||||
new_part = Compound.makeCompound(new_solids)
|
||||
BuildPart.get_context().part = new_part
|
||||
super().__init__(new_part.wrapped)
|
||||
BuildPart.get_context().add_to_context(*cutters, mode=Mode.INTERSECTION)
|
||||
super().__init__(BuildPart.get_context().part.wrapped)
|
||||
|
||||
|
||||
class Sweep(Compound):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue