Skip to content

Commit

Permalink
Merge pull request #783 from erooke/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
gumyr authored Nov 14, 2024
2 parents 47814ad + af60811 commit 4c43b22
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 69 deletions.
29 changes: 22 additions & 7 deletions src/build123d/build_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def _add_to_context(
x_dir=(1, 0, 0),
z_dir=new_face.normal_at(),
)
except:
except Exception:
plane = Plane(origin=(0, 0, 0), z_dir=new_face.normal_at())

new_face = plane.to_local_coords(new_face)
Expand Down Expand Up @@ -521,7 +521,10 @@ def vertex(self, select: Select = Select.ALL) -> Vertex:
all_vertices = self.vertices(select)
vertex_count = len(all_vertices)
if vertex_count != 1:
warnings.warn(f"Found {vertex_count} vertices, returning first")
warnings.warn(
f"Found {vertex_count} vertices, returning first",
stacklevel=2,
)
return all_vertices[0]

def edges(self, select: Select = Select.ALL) -> ShapeList[Edge]:
Expand Down Expand Up @@ -561,7 +564,10 @@ def edge(self, select: Select = Select.ALL) -> Edge:
all_edges = self.edges(select)
edge_count = len(all_edges)
if edge_count != 1:
warnings.warn(f"Found {edge_count} edges, returning first")
warnings.warn(
f"Found {edge_count} edges, returning first",
stacklevel=2,
)
return all_edges[0]

def wires(self, select: Select = Select.ALL) -> ShapeList[Wire]:
Expand Down Expand Up @@ -601,7 +607,10 @@ def wire(self, select: Select = Select.ALL) -> Wire:
all_wires = self.wires(select)
wire_count = len(all_wires)
if wire_count != 1:
warnings.warn(f"Found {wire_count} wires, returning first")
warnings.warn(
f"Found {wire_count} wires, returning first",
stacklevel=2,
)
return all_wires[0]

def faces(self, select: Select = Select.ALL) -> ShapeList[Face]:
Expand Down Expand Up @@ -641,7 +650,10 @@ def face(self, select: Select = Select.ALL) -> Face:
all_faces = self.faces(select)
face_count = len(all_faces)
if face_count != 1:
warnings.warn(f"Found {face_count} faces, returning first")
warnings.warn(
f"Found {face_count} faces, returning first",
stacklevel=2,
)
return all_faces[0]

def solids(self, select: Select = Select.ALL) -> ShapeList[Solid]:
Expand Down Expand Up @@ -681,7 +693,10 @@ def solid(self, select: Select = Select.ALL) -> Solid:
all_solids = self.solids(select)
solid_count = len(all_solids)
if solid_count != 1:
warnings.warn(f"Found {solid_count} solids, returning first")
warnings.warn(
f"Found {solid_count} solids, returning first",
stacklevel=2,
)
return all_solids[0]

def _shapes(self, obj_type: Union[Vertex, Edge, Face, Solid] = None) -> ShapeList:
Expand Down Expand Up @@ -1291,7 +1306,7 @@ def localize(cls, *points: VectorLike) -> Union[list[Vector], Vector]:


def __gen_context_component_getter(
func: Callable[Concatenate[Builder, P], T2]
func: Callable[Concatenate[Builder, P], T2],
) -> Callable[P, T2]:
@functools.wraps(func)
def getter(select: Select = Select.ALL):
Expand Down
4 changes: 2 additions & 2 deletions src/build123d/build_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

from typing import Union

from build123d.build_common import Builder, WorkplaneList, logger
from build123d.build_common import Builder, WorkplaneList
from build123d.build_enums import Mode
from build123d.geometry import Location, Plane
from build123d.topology import Compound, Edge, Face, ShapeList, Sketch, Wire, Vertex
from build123d.topology import Compound, Edge, Face, ShapeList, Sketch, Wire


class BuildSketch(Builder):
Expand Down
5 changes: 4 additions & 1 deletion src/build123d/drafting.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ class TechnicalDrawing(BaseSketchObject):
def __init__(
self,
designed_by: str = "build123d",
design_date: date = date.today(),
design_date: Optional[date] = None,
page_size: PageSize = PageSize.A4,
title: str = "Title",
sub_title: str = "Sub Title",
Expand All @@ -633,6 +633,9 @@ def __init__(
):
# pylint: disable=too-many-locals

if design_date is None:
design_date = date.today()

page_dim = TechnicalDrawing.page_sizes[page_size]
# Frame
frame_width = page_dim[0] - 2 * TechnicalDrawing.margin - 2 * nominal_text_size
Expand Down
2 changes: 1 addition & 1 deletion src/build123d/exporters3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _create_xde(to_export: Shape, unit: Unit = Unit.MM) -> TDocStd_Document:
elif isinstance(node, Curve):
explorer = TopExp_Explorer(node.wrapped, ta.TopAbs_EDGE)
else:
warnings.warn("Unknown Compound type, color not set")
warnings.warn("Unknown Compound type, color not set", stacklevel=2)
explorer = TopExp_Explorer() # don't know what to look for

while explorer.More():
Expand Down
2 changes: 0 additions & 2 deletions src/build123d/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@
overload,
TypeVar,
)
from typing_extensions import deprecated

from OCP.Bnd import Bnd_Box, Bnd_OBB
from OCP.BRep import BRep_Tool
from OCP.BRepBndLib import BRepBndLib
from OCP.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from OCP.BRepGProp import BRepGProp, BRepGProp_Face # used for mass calculation
from OCP.BRepMesh import BRepMesh_IncrementalMesh
from OCP.BRepTools import BRepTools
from OCP.Geom import Geom_BoundedSurface, Geom_Line, Geom_Plane
from OCP.GeomAPI import GeomAPI_ProjectPointOnSurf, GeomAPI_IntCS, GeomAPI_IntSS
Expand Down
2 changes: 0 additions & 2 deletions src/build123d/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@
from pathlib import Path
from typing import TextIO, Union, Optional

import OCP.IFSelect
from OCP.BRep import BRep_Builder
from OCP.BRepGProp import BRepGProp
from OCP.BRepTools import BRepTools
from OCP.GProp import GProp_GProps
from OCP.Quantity import Quantity_ColorRGBA
from OCP.RWStl import RWStl
from OCP.STEPCAFControl import STEPCAFControl_Reader
from OCP.STEPControl import STEPControl_Reader
from OCP.TCollection import TCollection_AsciiString, TCollection_ExtendedString
from OCP.TDataStd import TDataStd_Name
from OCP.TDF import TDF_Label, TDF_LabelSequence
Expand Down
16 changes: 11 additions & 5 deletions src/build123d/joints.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from __future__ import annotations

from math import inf
from typing import Union, overload
from typing import Optional, Union, overload

from build123d.build_common import validate_inputs
from build123d.build_enums import Align
Expand Down Expand Up @@ -75,8 +75,8 @@ def symbol(self) -> Compound:
def __init__(
self,
label: str,
to_part: Union[Solid, Compound] = None,
joint_location: Location = Location(),
to_part: Optional[Union[Solid, Compound]] = None,
joint_location: Union[Location, None] = None,
):
context: BuildPart = BuildPart._get_context(self)
validate_inputs(context, self)
Expand All @@ -86,6 +86,9 @@ def __init__(
else:
raise ValueError("Either specify to_part or place in BuildPart scope")

if joint_location is None:
joint_location = Location()

self.relative_location = to_part.location.inverse() * joint_location
to_part.joints[label] = self
super().__init__(label, to_part)
Expand Down Expand Up @@ -677,8 +680,8 @@ def symbol(self) -> Compound:
def __init__(
self,
label: str,
to_part: Union[Solid, Compound] = None,
joint_location: Location = Location(),
to_part: Optional[Union[Solid, Compound]] = None,
joint_location: Optional[Location] = None,
angular_range: tuple[
tuple[float, float], tuple[float, float], tuple[float, float]
] = ((0, 360), (0, 360), (0, 360)),
Expand All @@ -692,6 +695,9 @@ def __init__(
else:
raise ValueError("Either specify to_part or place in BuildPart scope")

if joint_location is None:
joint_location = Location()

self.relative_location = to_part.location.inverse() * joint_location
to_part.joints[label] = self
self.angular_range = angular_range
Expand Down
13 changes: 7 additions & 6 deletions src/build123d/mesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
# pylint: disable=no-name-in-module, import-error
import copy
import ctypes
import itertools
import math
import os
import sys
Expand All @@ -103,16 +102,15 @@
from OCP.gp import gp_Pnt
import OCP.TopAbs as ta
from OCP.GProp import GProp_GProps
from OCP.ShapeFix import ShapeFix_Shape
from OCP.TopAbs import TopAbs_ShapeEnum
from OCP.TopExp import TopExp_Explorer
from OCP.TopoDS import TopoDS_Compound
from OCP.TopLoc import TopLoc_Location

from py_lib3mf import Lib3MF
from build123d.build_enums import MeshType, Unit
from build123d.geometry import Color, TOLERANCE, Vector
from build123d.topology import Compound, Face, Shape, Shell, Solid, downcast
from build123d.geometry import Color, TOLERANCE
from build123d.topology import Compound, Shape, Shell, Solid, downcast


class Mesher:
Expand Down Expand Up @@ -400,7 +398,10 @@ def add_shape(

# Skip invalid meshes
if len(ocp_mesh_vertices) < 3 or not triangles:
warnings.warn(f"Degenerate shape {b3d_shape} - skipped")
warnings.warn(
f"Degenerate shape {b3d_shape} - skipped",
stacklevel=2,
)
continue

# Create 3mf mesh inputs
Expand Down Expand Up @@ -429,7 +430,7 @@ def add_shape(
if not mesh_3mf.IsValid():
raise RuntimeError("3mf mesh is invalid")
if not mesh_3mf.IsManifoldAndOriented():
warnings.warn("3mf mesh is not manifold")
warnings.warn("3mf mesh is not manifold", stacklevel=2)

# Add mesh to model
self.meshes.append(mesh_3mf)
Expand Down
1 change: 0 additions & 1 deletion src/build123d/objects_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from __future__ import annotations

import copy
import warnings
from math import copysign, cos, radians, sin, sqrt
from scipy.optimize import minimize
from typing import Iterable, Union
Expand Down
2 changes: 1 addition & 1 deletion src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def offset(
)
else:
inner_wires.append(offset_wire)
except:
except Exception:
pass
# inner wires may go beyond the outer wire so subtract faces
new_face = Face(outer_wire)
Expand Down
2 changes: 1 addition & 1 deletion src/build123d/operations_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def make_brake_formed(
line = line.wires()[0]
elif not isinstance(line, (Edge, Wire)):
raise ValueError("line must be either a Curve, Edge or Wire")
elif context is not None and not context.pending_edges_as_wire is None:
elif context is not None and context.pending_edges_as_wire is not None:
line = context.pending_edges_as_wire
else:
raise ValueError("A line must be provided")
Expand Down
1 change: 0 additions & 1 deletion src/build123d/operations_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from build123d.geometry import Vector
from build123d.build_common import flatten_sequence, validate_inputs
from build123d.build_sketch import BuildSketch
from build123d.objects_curve import ThreePointArc
from scipy.spatial import Voronoi


Expand Down
Loading

0 comments on commit 4c43b22

Please sign in to comment.