mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
Working on Compound changes
This commit is contained in:
parent
b3bf628584
commit
956fcd7438
3 changed files with 57 additions and 42 deletions
|
|
@ -35,6 +35,7 @@ from build123d.build_enums import Align, Mode
|
||||||
from build123d.build_part import BuildPart
|
from build123d.build_part import BuildPart
|
||||||
from build123d.geometry import Location, Plane, Rotation, RotationLike
|
from build123d.geometry import Location, Plane, Rotation, RotationLike
|
||||||
from build123d.topology import Compound, Part, ShapeList, Solid, tuplify
|
from build123d.topology import Compound, Part, ShapeList, Solid, tuplify
|
||||||
|
from build123d.topology.utils import _make_topods_compound_from_shapes
|
||||||
|
|
||||||
|
|
||||||
class BasePartObject(Part):
|
class BasePartObject(Part):
|
||||||
|
|
@ -83,11 +84,15 @@ class BasePartObject(Part):
|
||||||
context._add_to_context(*new_solids, mode=mode)
|
context._add_to_context(*new_solids, mode=mode)
|
||||||
|
|
||||||
if len(new_solids) > 1:
|
if len(new_solids) > 1:
|
||||||
new_part = Compound(new_solids).wrapped
|
# new_part = Compound(new_solids).wrapped
|
||||||
|
new_part = _make_topods_compound_from_shapes(
|
||||||
|
[s.wrapped for s in new_solids]
|
||||||
|
)
|
||||||
elif isinstance(new_solids[0], Compound): # Don't add extra layers
|
elif isinstance(new_solids[0], Compound): # Don't add extra layers
|
||||||
new_part = new_solids[0].wrapped
|
new_part = new_solids[0].wrapped
|
||||||
else:
|
else:
|
||||||
new_part = Compound(new_solids).wrapped
|
# new_part = Compound(new_solids).wrapped
|
||||||
|
new_part = _make_topods_compound_from_shapes([new_solids[0].wrapped])
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
obj=new_part,
|
obj=new_part,
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,9 @@ from .zero_d import Vertex
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
|
|
||||||
def where_am_i_called_from():
|
def where_am_i_called_from(stack_levels: int = 2):
|
||||||
# inspect.stack()[0] is this frame; [2] is the caller
|
# inspect.stack()[0] is this frame; [2] is the caller
|
||||||
caller_frame_info = inspect.stack()[2]
|
caller_frame_info = inspect.stack()[stack_levels]
|
||||||
filename = caller_frame_info.filename
|
filename = caller_frame_info.filename
|
||||||
lineno = caller_frame_info.lineno
|
lineno = caller_frame_info.lineno
|
||||||
code_line = caller_frame_info.code_context[0].strip()
|
code_line = caller_frame_info.code_context[0].strip()
|
||||||
|
|
@ -197,7 +197,7 @@ class MixinComposite(NodeMixin):
|
||||||
if hasattr(node, "_base_wrapped") and node._base_wrapped is not None:
|
if hasattr(node, "_base_wrapped") and node._base_wrapped is not None:
|
||||||
shapes.append(node._base_wrapped)
|
shapes.append(node._base_wrapped)
|
||||||
|
|
||||||
# then union in every child’s current shape
|
# then add in every child’s current shape
|
||||||
shapes.extend(child.wrapped for child in node.children)
|
shapes.extend(child.wrapped for child in node.children)
|
||||||
if len(shapes) == 1:
|
if len(shapes) == 1:
|
||||||
node.wrapped = shapes[0]
|
node.wrapped = shapes[0]
|
||||||
|
|
@ -801,16 +801,16 @@ class Compound(Mixin3D, MixinComposite, Shape[TopoDS_Compound]):
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, TopoDS_Shape):
|
if isinstance(obj, TopoDS_Shape):
|
||||||
print("Making a Compound 1")
|
print("Making a Compound 1")
|
||||||
# self._base_wrapped = downcast(obj)
|
where_am_i_called_from(3)
|
||||||
self._base_wrapped = obj
|
self._base_wrapped = downcast(obj)
|
||||||
elif isinstance(obj, Iterable):
|
elif isinstance(obj, Iterable):
|
||||||
print("Making a Compound 2")
|
print("Making a Compound 2")
|
||||||
|
where_am_i_called_from(3)
|
||||||
self._base_wrapped = _make_topods_compound_from_shapes(
|
self._base_wrapped = _make_topods_compound_from_shapes(
|
||||||
[s.wrapped for s in obj]
|
[s.wrapped for s in obj]
|
||||||
)
|
)
|
||||||
elif obj is None:
|
elif obj is None:
|
||||||
print("Making a Compound 3")
|
print("Making a Compound 3")
|
||||||
# self._base_wrapped = _make_topods_compound_from_shapes([])
|
|
||||||
self._base_wrapped = None
|
self._base_wrapped = None
|
||||||
elif isinstance(obj, Assembly):
|
elif isinstance(obj, Assembly):
|
||||||
print("Making a Compound 4")
|
print("Making a Compound 4")
|
||||||
|
|
@ -818,6 +818,16 @@ class Compound(Mixin3D, MixinComposite, Shape[TopoDS_Compound]):
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid obj of type {type(obj)}")
|
raise ValueError(f"Invalid obj of type {type(obj)}")
|
||||||
|
|
||||||
|
# if isinstance(obj, Iterable):
|
||||||
|
# print("Making a Compound 1")
|
||||||
|
# topods_compound = _make_topods_compound_from_shapes(
|
||||||
|
# [s.wrapped for s in obj]
|
||||||
|
# )
|
||||||
|
# else:
|
||||||
|
# print("Making a Compound 2")
|
||||||
|
# topods_compound = obj
|
||||||
|
# self._base_wrapped = topods_compound
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
obj=self._base_wrapped,
|
obj=self._base_wrapped,
|
||||||
label=label,
|
label=label,
|
||||||
|
|
|
||||||
|
|
@ -617,26 +617,26 @@ class AlgebraTests(unittest.TestCase):
|
||||||
self.assertAlmostEqual(b.volume, r.volume, 5)
|
self.assertAlmostEqual(b.volume, r.volume, 5)
|
||||||
self.assertEqual(r._dim, 3)
|
self.assertEqual(r._dim, 3)
|
||||||
|
|
||||||
# def test_empty_minus_part(self):
|
def test_empty_minus_part(self):
|
||||||
# b = Box(1, 2, 3)
|
b = Box(1, 2, 3)
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# r = Part() - b
|
r = Part() - b
|
||||||
|
|
||||||
# def test_part_minus_empty(self):
|
def test_part_minus_empty(self):
|
||||||
# b = Box(1, 2, 3)
|
b = Box(1, 2, 3)
|
||||||
# r = b - Part()
|
r = b - Part()
|
||||||
# self.assertAlmostEqual(b.volume, r.volume, 5)
|
self.assertAlmostEqual(b.volume, r.volume, 5)
|
||||||
# self.assertEqual(r._dim, 3)
|
self.assertEqual(r._dim, 3)
|
||||||
|
|
||||||
# def test_empty_and_part(self):
|
def test_empty_and_part(self):
|
||||||
# b = Box(1, 2, 3)
|
b = Box(1, 2, 3)
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# r = Part() & b
|
r = Part() & b
|
||||||
|
|
||||||
# def test_part_and_empty(self):
|
def test_part_and_empty(self):
|
||||||
# b = Box(1, 2, 3)
|
b = Box(1, 2, 3)
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# r = b & Part()
|
r = b & Part()
|
||||||
|
|
||||||
# Sketch + - & Empty
|
# Sketch + - & Empty
|
||||||
|
|
||||||
|
|
@ -652,26 +652,26 @@ class AlgebraTests(unittest.TestCase):
|
||||||
self.assertAlmostEqual(b.area, r.area, 5)
|
self.assertAlmostEqual(b.area, r.area, 5)
|
||||||
self.assertEqual(r._dim, 2)
|
self.assertEqual(r._dim, 2)
|
||||||
|
|
||||||
# def test_empty_minus_sketch(self):
|
def test_empty_minus_sketch(self):
|
||||||
# b = Rectangle(1, 2)
|
b = Rectangle(1, 2)
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# r = Sketch() - b
|
r = Sketch() - b
|
||||||
|
|
||||||
# def test_sketch_minus_empty(self):
|
def test_sketch_minus_empty(self):
|
||||||
# b = Rectangle(1, 2)
|
b = Rectangle(1, 2)
|
||||||
# r = b - Sketch()
|
r = b - Sketch()
|
||||||
# self.assertAlmostEqual(b.area, r.area, 5)
|
self.assertAlmostEqual(b.area, r.area, 5)
|
||||||
# self.assertEqual(r._dim, 2)
|
self.assertEqual(r._dim, 2)
|
||||||
|
|
||||||
# def test_empty_and_sketch(self):
|
def test_empty_and_sketch(self):
|
||||||
# b = Rectangle(1, 3)
|
b = Rectangle(1, 3)
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# r = Sketch() & b
|
r = Sketch() & b
|
||||||
|
|
||||||
# def test_sketch_and_empty(self):
|
def test_sketch_and_empty(self):
|
||||||
# b = Rectangle(1, 2)
|
b = Rectangle(1, 2)
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# r = b & Sketch()
|
r = b & Sketch()
|
||||||
|
|
||||||
def test_1d_2d_minus(self):
|
def test_1d_2d_minus(self):
|
||||||
line = Line((0, 0), (1, 1))
|
line = Line((0, 0), (1, 1))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue