From f65bc75976f2acb213a9ac44767dd9110eb13da6 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Wed, 22 Mar 2023 08:45:18 +0100 Subject: [PATCH] fixed examples to work with build1223d --- examples/boxes_on_faces_algebra.py | 2 - .../build123d_customizable_logo_algebra.py | 3 +- examples/clock_algebra.py | 7 +- examples/din_rail_algebra.py | 5 +- examples/handle_algebra.py | 3 +- examples/holes_algebra.py | 15 ++-- examples/intersecting_chamfers_algebra.py | 5 +- examples/intersecting_pipes_algebra.py | 2 +- examples/lego_algebra.py | 7 +- examples/loft_algebra.py | 5 +- examples/pillow_block_algebra.py | 13 ++- examples/vase_algebra.py | 11 ++- src/build123d/alg_compat.py | 89 ------------------- 13 files changed, 32 insertions(+), 135 deletions(-) delete mode 100644 src/build123d/alg_compat.py diff --git a/examples/boxes_on_faces_algebra.py b/examples/boxes_on_faces_algebra.py index 8cab0aa..842194c 100644 --- a/examples/boxes_on_faces_algebra.py +++ b/examples/boxes_on_faces_algebra.py @@ -1,7 +1,5 @@ from build123d import * -# from build123d.part_operations import * - b = Box(3, 3, 3) b2 = Rot(0, 0, 45) * extrude(Rectangle(1, 2), 0.2) for plane in [Plane(f) for f in b.faces()]: diff --git a/examples/build123d_customizable_logo_algebra.py b/examples/build123d_customizable_logo_algebra.py index 4df8e60..0b04d9e 100644 --- a/examples/build123d_customizable_logo_algebra.py +++ b/examples/build123d_customizable_logo_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT logo_text = Text("123d", font_size=10, align=(Align.MIN, Align.MIN)) font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y @@ -27,7 +26,7 @@ three_d = Pos(font_height * 1.1, 0) * extrude(three_d, amount=font_height * 0.3) logo_width = three_d.vertices().sort_by(Axis.X)[-1].X t1 = TangentArc((0, 0), (1, 0.75), tangent=(1, 0)) -arrow_left = t1 + COMPAT.mirror(t1, about=Plane.XZ) +arrow_left = t1 + mirror(t1, about=Plane.XZ) ext_line_length = font_height * 0.5 dim_line_length = (logo_width - build_width - 2 * font_height * 0.05) / 2 diff --git a/examples/clock_algebra.py b/examples/clock_algebra.py index 6c8d470..4780805 100644 --- a/examples/clock_algebra.py +++ b/examples/clock_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT clock_radius = 10 @@ -7,9 +6,9 @@ l1 = CenterArc((0, 0), clock_radius * 0.975, 0.75, 4.5) l2 = CenterArc((0, 0), clock_radius * 0.925, 0.75, 4.5) l3 = Line(l1 @ 0, l2 @ 0) l4 = Line(l1 @ 1, l2 @ 1) -minute_indicator = COMPAT.make_face([l1, l3, l2, l4]) -minute_indicator = COMPAT.fillet( - minute_indicator, minute_indicator.vertices(), radius=clock_radius * 0.01 +minute_indicator = make_face(l1, l3, l2, l4) +minute_indicator = fillet( + *minute_indicator.vertices(), radius=clock_radius * 0.01, target=minute_indicator ) clock_face = Circle(clock_radius) diff --git a/examples/din_rail_algebra.py b/examples/din_rail_algebra.py index 989ab57..36f9df2 100644 --- a/examples/din_rail_algebra.py +++ b/examples/din_rail_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT # 35x7.5mm DIN Rail Dimensions overall_width, top_width, height, thickness, fillet_radius = 35, 27, 7.5, 1, 0.8 @@ -25,14 +24,14 @@ inside_vertices = ( ) ) -din = COMPAT.fillet(din, inside_vertices, radius=fillet_radius) +din = fillet(*inside_vertices, radius=fillet_radius, target=din) outside_vertices = filter( lambda v: (v.Y == 0.0 or v.Y == height) and -overall_width / 2 < v.X < overall_width / 2, din.vertices(), ) -din = COMPAT.fillet(din, outside_vertices, radius=fillet_radius + thickness) +din = fillet(*outside_vertices, radius=fillet_radius + thickness, target=din) rail = extrude(din, rail_length) diff --git a/examples/handle_algebra.py b/examples/handle_algebra.py index 4333c5c..66f0448 100644 --- a/examples/handle_algebra.py +++ b/examples/handle_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT segment_count = 6 @@ -27,7 +26,7 @@ for i in range(segment_count + 1): section = plane * Circle(1) else: section = plane * Rectangle(1.25, 3) - section = COMPAT.fillet(section, section.vertices(), radius=0.2) + section = fillet(*section.vertices(), radius=0.2, target=section) sections += section # Create the handle by sweeping along the path diff --git a/examples/holes_algebra.py b/examples/holes_algebra.py index 0d325d5..6610fc0 100644 --- a/examples/holes_algebra.py +++ b/examples/holes_algebra.py @@ -1,26 +1,23 @@ from build123d import * -import build123d.alg_compat as COMPAT thru_hole = Cylinder(radius=3, height=2) -thru_hole -= COMPAT.Bore(thru_hole, radius=1) +thru_hole -= Hole(radius=1, depth=2) # Recessed counter bore hole (hole location = (0,0,0)) recessed_counter_bore = Cylinder(radius=3, height=2) -recessed_counter_bore -= COMPAT.CounterBore( - recessed_counter_bore, radius=1, counter_bore_radius=1.5, counter_bore_depth=0.5 +recessed_counter_bore -= CounterBoreHole( + radius=1, depth=2, counter_bore_radius=1.5, counter_bore_depth=0.5 ) # Recessed counter sink hole (hole location = (0,0,0)) recessed_counter_sink = Cylinder(radius=3, height=2) -recessed_counter_sink -= COMPAT.CounterSink( - recessed_counter_sink, radius=1, counter_sink_radius=1.5 -) +recessed_counter_sink -= CounterSinkHole(radius=1, depth=2, counter_sink_radius=1.5) # Flush counter sink hole (hole location = (0,0,2)) flush_counter_sink = Cylinder(radius=3, height=2) plane = Plane(flush_counter_sink.faces().sort_by().last) -flush_counter_sink -= plane * COMPAT.CounterSink( - flush_counter_sink, radius=1, counter_sink_radius=1.5 +flush_counter_sink -= plane * CounterSinkHole( + radius=1, depth=2, counter_sink_radius=1.5 ) if "show_object" in locals(): diff --git a/examples/intersecting_chamfers_algebra.py b/examples/intersecting_chamfers_algebra.py index e589cad..5631688 100644 --- a/examples/intersecting_chamfers_algebra.py +++ b/examples/intersecting_chamfers_algebra.py @@ -1,15 +1,14 @@ from build123d import * -import build123d.alg_compat as COMPAT blocks = Pos(-1, -1, 0) * Box(1, 2, 1, align=(Align.CENTER, Align.MIN, Align.MIN)) blocks += Box(1, 1, 2, align=(Align.CENTER, Align.MIN, Align.MIN)) blocks += Pos(1, -1, 0) * Box(1, 2, 1, align=(Align.CENTER, Align.MIN, Align.MIN)) bottom_edges = blocks.edges().filter_by_position(Axis.Z, 0, 1, inclusive=(True, False)) -blocks2 = COMPAT.chamfer(blocks, bottom_edges, length=0.1) +blocks2 = chamfer(*bottom_edges, length=0.1, target=blocks) top_edges = blocks2.edges().filter_by_position(Axis.Z, 1, 2, inclusive=(False, True)) -blocks2 = COMPAT.chamfer(blocks2, top_edges, length=0.1) +blocks2 = chamfer(*top_edges, length=0.1, target=blocks2) if "show_object" in locals(): diff --git a/examples/intersecting_pipes_algebra.py b/examples/intersecting_pipes_algebra.py index 1c1ea53..e37eac9 100644 --- a/examples/intersecting_pipes_algebra.py +++ b/examples/intersecting_pipes_algebra.py @@ -10,7 +10,7 @@ for plane in [Plane(f) for f in pipes.faces()]: last = pipes.edges() pipes += extrude(pipe, amount=10) - pipes = fillet(pipes, pipes.edges() - last, radius=0.2) + pipes = fillet(*pipes.edges() - last, radius=0.2, target=pipes) if "show_object" in locals(): show_object(pipes, name="intersecting pipes") diff --git a/examples/lego_algebra.py b/examples/lego_algebra.py index d987deb..f4bf6a7 100644 --- a/examples/lego_algebra.py +++ b/examples/lego_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT pip_count = 6 @@ -23,7 +22,7 @@ wall_thickness = 1.2 plan = Rectangle(width=block_length, height=block_width) # Subtract an offset to create the block walls -plan -= COMPAT.offset( +plan -= offset( plan, amount=-wall_thickness, kind=Kind.INTERSECTION, @@ -51,7 +50,7 @@ for loc in GridLocations( lego = extrude(plan, amount=base_height - wall_thickness) # Create a box on the top of the walls -for loc in Locations((0, 0, lego.vertices().max().Z)): +for loc in Locations((0, 0, lego.vertices().sort_by().last.Z)): # Create the top of the block lego += loc * Box( length=block_length, @@ -61,7 +60,7 @@ for loc in Locations((0, 0, lego.vertices().max().Z)): ) # Create a workplane on the top of the block -plane = Plane(lego.faces().max()) +plane = Plane(lego.faces().sort_by().last) # Create a grid of pips for loc in GridLocations(lego_unit_size, lego_unit_size, pip_count, 2): diff --git a/examples/loft_algebra.py b/examples/loft_algebra.py index b0cd336..416e2a4 100644 --- a/examples/loft_algebra.py +++ b/examples/loft_algebra.py @@ -1,6 +1,5 @@ from math import pi, sin from build123d import * -import build123d.alg_compat as COMPAT slice_count = 10 @@ -10,8 +9,8 @@ for i in range(slice_count + 1): art += plane * Circle(10 * sin(i * pi / slice_count) + 5) art = loft(art) -top_bottom = art.faces(GeomType.PLANE) -art = COMPAT.shell(art, openings=top_bottom, amount=0.5) +top_bottom = art.faces().filter_by(GeomType.PLANE) +art = offset(art, openings=top_bottom, amount=0.5) if "show_object" in locals(): show_object(art, name="art") diff --git a/examples/pillow_block_algebra.py b/examples/pillow_block_algebra.py index 287610b..c0d6c00 100644 --- a/examples/pillow_block_algebra.py +++ b/examples/pillow_block_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT height, width, thickness, padding = 60, 80, 10, 12 screw_shaft_radius, screw_head_radius, screw_head_height = 1.5, 3, 3 @@ -7,20 +6,20 @@ bearing_axle_radius, bearing_radius, bearing_thickness = 4, 11, 7 # Build pillow block as an extruded sketch with counter bore holes plan = Rectangle(width, height) -plan = COMPAT.fillet(plan, plan.vertices(), 5) +plan = fillet(*plan.vertices(), radius=5, target=plan) pillow_block = extrude(plan, thickness) -plane = Plane(pillow_block.faces().max()) +plane = Plane(pillow_block.faces().sort_by().last) -pillow_block -= plane * COMPAT.CounterBore( - pillow_block, bearing_axle_radius, bearing_radius, bearing_thickness +pillow_block -= plane * CounterBoreHole( + bearing_axle_radius, bearing_radius, bearing_thickness, height ) for loc in GridLocations(width - 2 * padding, height - 2 * padding, 2, 2): pillow_block -= ( plane * loc - * COMPAT.CounterBore( - pillow_block, screw_shaft_radius, screw_head_radius, screw_head_height + * CounterBoreHole( + screw_shaft_radius, screw_head_radius, screw_head_height, height ) ) diff --git a/examples/vase_algebra.py b/examples/vase_algebra.py index 02e033e..a7994a2 100644 --- a/examples/vase_algebra.py +++ b/examples/vase_algebra.py @@ -1,5 +1,4 @@ from build123d import * -import build123d.alg_compat as COMPAT l1 = Line((0, 0), (12, 0)) l2 = RadiusArc(l1 @ 1, (15, 20), 50) @@ -18,14 +17,14 @@ outline += Polyline( (0, (l5 @ 1).Y + 1), l1 @ 0, ) -profile = COMPAT.make_face(outline) +profile = make_face(*outline.edges()) vase = revolve(profile, axis=Axis.Y) -vase = COMPAT.shell(vase, openings=vase.faces().max(Axis.Y), amount=-1) +vase = offset(vase, openings=vase.faces().sort_by(Axis.Y).last, amount=-1) -top_edges = vase.edges(GeomType.CIRCLE).filter_by_position(Axis.Y, 60, 62) -vase = fillet(vase, top_edges, radius=0.25) +top_edges = vase.edges().filter_by(GeomType.CIRCLE).filter_by_position(Axis.Y, 60, 62) +vase = fillet(*top_edges, radius=0.25, target=vase) -vase = fillet(vase, vase.edges().sort_by(Axis.Y)[0], radius=0.5) +vase = fillet(vase.edges().sort_by(Axis.Y).first, radius=0.5, target=vase) if "show_object" in locals(): show_object(vase, name="vase") diff --git a/src/build123d/alg_compat.py b/src/build123d/alg_compat.py deleted file mode 100644 index a7774fe..0000000 --- a/src/build123d/alg_compat.py +++ /dev/null @@ -1,89 +0,0 @@ -# -# TEMPORARY FOR MIGRATION ONLY -# -import copy -from build123d import * -from build123d.topology import class_LUT - -from typing import Union, List - - -class Hole: - def __init__(self): - raise NotImplemented - - -class CounterSinkHole: - def __init__(self): - raise NotImplemented - - -class CounterBoreHole: - def __init__(self): - raise NotImplemented - - -def chamfer( - obj: Union[Part, Sketch], - objects: Union[List[Union[Edge, Vertex]], Edge, Vertex], - length: float, - length2: float = None, -): - if isinstance(obj, Part): - compound = Compound.make_compound( - [obj.solids()[0].chamfer(length, length2, list(objects))] - ) - else: - new_faces = [] - for face in obj.faces(): - vertices_in_face = [v for v in face.vertices() if v in objects] - if vertices_in_face: - new_faces.append(face.chamfer_2d(length, vertices_in_face)) - else: - new_faces.append(face) - compound = Compound.make_compound(new_faces) - compound._dim = obj._dim - return compound - - -def fillet( - obj: Union[Part, Sketch], - objects: Union[List[Union[Edge, Vertex]], Edge, Vertex], - radius: float, -): - if isinstance(obj, Part): - compound = Compound.make_compound( - [obj.solids()[0].fillet(radius, list(objects))] - ) - else: - new_faces = [] - for face in obj.faces(): - vertices_in_face = [v for v in face.vertices() if v in objects] - if vertices_in_face: - new_faces.append(face.fillet_2d(radius, vertices_in_face)) - else: - new_faces.append(face) - compound = Compound.make_compound(new_faces) - compound._dim = obj._dim - return compound - - -def mirror( - *objects: Union[Part, Sketch, Curve], - about: Plane = Plane.XZ, -): - mirrored = [copy.deepcopy(o).mirror(about) for o in objects] - compound = Compound.make_compound(mirrored) - dim = objects[0]._dim if isinstance(objects, (list, tuple)) else objects._dim - return class_LUT[dim](compound.wrapped) - - -def make_face(objs: Union[Sketch, List[Edge]]): - if isinstance(objs, Sketch) and objs._dim == 1: - edges = objs.edges() - elif isinstance(objs, (tuple, list)): - edges = objs - else: - edges = [objs] - - return Sketch.make_compound([Face.make_from_wires(*Wire.combine(edges))])