Fixed typing and linting issues
Some checks are pending
benchmarks / benchmarks (macos-14, 3.12) (push) Waiting to run
benchmarks / benchmarks (macos-15-intel, 3.12) (push) Waiting to run
benchmarks / benchmarks (ubuntu-latest, 3.12) (push) Waiting to run
benchmarks / benchmarks (windows-latest, 3.12) (push) Waiting to run
Upload coverage reports to Codecov / run (push) Waiting to run
pylint / lint (3.10) (push) Waiting to run
Run type checker / typecheck (3.10) (push) Waiting to run
Run type checker / typecheck (3.13) (push) Waiting to run
Wheel building and publishing / Build wheel on ubuntu-latest (push) Waiting to run
Wheel building and publishing / upload_pypi (push) Blocked by required conditions
tests / tests (macos-14, 3.10) (push) Waiting to run
tests / tests (macos-14, 3.13) (push) Waiting to run
tests / tests (macos-15-intel, 3.10) (push) Waiting to run
tests / tests (macos-15-intel, 3.13) (push) Waiting to run
tests / tests (ubuntu-latest, 3.10) (push) Waiting to run
tests / tests (ubuntu-latest, 3.13) (push) Waiting to run
tests / tests (windows-latest, 3.10) (push) Waiting to run
tests / tests (windows-latest, 3.13) (push) Waiting to run

This commit is contained in:
gumyr 2025-12-02 11:04:08 -05:00
parent 8985220c79
commit 5adf296fd8
2 changed files with 31 additions and 16 deletions

View file

@ -56,8 +56,7 @@ from __future__ import annotations
from collections.abc import Iterable, Sequence from collections.abc import Iterable, Sequence
from math import radians, cos, tan from math import radians, cos, tan
from typing import TYPE_CHECKING, Literal, overload from typing import TYPE_CHECKING, Literal
from typing import cast as tcast
from typing_extensions import Self from typing_extensions import Self
import OCP.TopAbs as ta import OCP.TopAbs as ta
@ -118,7 +117,6 @@ from .shape_core import (
Shape, Shape,
ShapeList, ShapeList,
Joint, Joint,
TrimmingTool,
downcast, downcast,
shapetype, shapetype,
_sew_topods_faces, _sew_topods_faces,
@ -137,7 +135,7 @@ from .zero_d import Vertex
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from .composite import Compound, Curve, Sketch, Part # pylint: disable=R0801 from .composite import Compound # pylint: disable=R0801
class Mixin3D(Shape[TOPODS]): class Mixin3D(Shape[TOPODS]):

View file

@ -62,6 +62,7 @@ from abc import ABC, abstractmethod
from collections.abc import Iterable, Sequence from collections.abc import Iterable, Sequence
from math import degrees from math import degrees
from typing import TYPE_CHECKING, Any, TypeVar, overload from typing import TYPE_CHECKING, Any, TypeVar, overload
from typing import cast as tcast
import OCP.TopAbs as ta import OCP.TopAbs as ta
from OCP.BRep import BRep_Builder, BRep_Tool from OCP.BRep import BRep_Builder, BRep_Tool
@ -104,6 +105,7 @@ from OCP.Standard import (
Standard_ConstructionError, Standard_ConstructionError,
Standard_Failure, Standard_Failure,
Standard_NoSuchObject, Standard_NoSuchObject,
Standard_TypeMismatch,
) )
from OCP.StdFail import StdFail_NotDone from OCP.StdFail import StdFail_NotDone
from OCP.TColgp import TColgp_Array1OfPnt, TColgp_HArray2OfPnt from OCP.TColgp import TColgp_Array1OfPnt, TColgp_HArray2OfPnt
@ -217,7 +219,7 @@ class Mixin2D(ABC, Shape[TOPODS]):
if self._wrapped is None: if self._wrapped is None:
raise ValueError("Invalid Shape") raise ValueError("Invalid Shape")
new_surface = copy.deepcopy(self) new_surface = copy.deepcopy(self)
new_surface.wrapped = downcast(self.wrapped.Complemented()) new_surface.wrapped = tcast(TOPODS, downcast(self.wrapped.Complemented()))
# As the surface has been modified, the parent is no longer valid # As the surface has been modified, the parent is no longer valid
new_surface.topo_parent = None new_surface.topo_parent = None
@ -366,7 +368,9 @@ class Mixin2D(ABC, Shape[TOPODS]):
for obj in common_set: for obj in common_set:
match (obj, target): match (obj, target):
case (_, Vertex() | Edge() | Wire() | Face() | Shell()): case (_, Vertex() | Edge() | Wire() | Face() | Shell()):
operation = BRepAlgoAPI_Section() operation: BRepAlgoAPI_Section | BRepAlgoAPI_Common = (
BRepAlgoAPI_Section()
)
result = bool_op((obj,), (target,), operation) result = bool_op((obj,), (target,), operation)
if not isinstance(obj, Edge | Wire) and not isinstance( if not isinstance(obj, Edge | Wire) and not isinstance(
target, (Edge | Wire) target, (Edge | Wire)
@ -604,6 +608,7 @@ class Face(Mixin2D[TopoDS_Face]):
""" """
def __init__(self, *args: Any, **kwargs: Any): def __init__(self, *args: Any, **kwargs: Any):
obj: TopoDS_Face | Plane | None
outer_wire, inner_wires, obj, label, color, parent = (None,) * 6 outer_wire, inner_wires, obj, label, color, parent = (None,) * 6
if args: if args:
@ -1463,7 +1468,7 @@ class Face(Mixin2D[TopoDS_Face]):
try: try:
patch.Build() patch.Build()
result = cls(patch.Shape()) result = cls(TopoDS.Face_s(patch.Shape()))
except ( except (
Standard_Failure, Standard_Failure,
StdFail_NotDone, StdFail_NotDone,
@ -1579,8 +1584,12 @@ class Face(Mixin2D[TopoDS_Face]):
if len(profile.edges()) != 1 or len(path.edges()) != 1: if len(profile.edges()) != 1 or len(path.edges()) != 1:
raise ValueError("Use Shell.sweep for multi Edge objects") raise ValueError("Use Shell.sweep for multi Edge objects")
profile = Wire([profile.edge()]) profile_edge = profile.edge()
path = Wire([path.edge()]) path_edge = path.edge()
assert profile_edge is not None
assert path_edge is not None
profile = Wire([profile_edge])
path = Wire([path_edge])
builder = BRepOffsetAPI_MakePipeShell(path.wrapped) builder = BRepOffsetAPI_MakePipeShell(path.wrapped)
builder.Add(profile.wrapped, False, False) builder.Add(profile.wrapped, False, False)
builder.SetTransitionMode(Shape._transModeDict[transition]) builder.SetTransitionMode(Shape._transModeDict[transition])
@ -1604,6 +1613,7 @@ class Face(Mixin2D[TopoDS_Face]):
Returns: Returns:
Vector: center Vector: center
""" """
center_point: Vector | gp_Pnt
if (center_of == CenterOf.MASS) or ( if (center_of == CenterOf.MASS) or (
center_of == CenterOf.GEOMETRY and self.is_planar center_of == CenterOf.GEOMETRY and self.is_planar
): ):
@ -1663,7 +1673,10 @@ class Face(Mixin2D[TopoDS_Face]):
# Index or iterator access to OCP.TopTools.TopTools_ListOfShape is slow on M1 macs # Index or iterator access to OCP.TopTools.TopTools_ListOfShape is slow on M1 macs
# Using First() and Last() to omit # Using First() and Last() to omit
edges = (Edge(edge_list.First()), Edge(edge_list.Last())) edges = (
Edge(TopoDS.Edge_s(edge_list.First())),
Edge(TopoDS.Edge_s(edge_list.Last())),
)
edge1, edge2 = Wire.order_chamfer_edges(reference_edge, edges) edge1, edge2 = Wire.order_chamfer_edges(reference_edge, edges)
@ -2053,7 +2066,7 @@ class Face(Mixin2D[TopoDS_Face]):
BRepAlgoAPI_Common(), BRepAlgoAPI_Common(),
) )
for topods_shell in get_top_level_topods_shapes(topods_shape): for topods_shell in get_top_level_topods_shapes(topods_shape):
intersected_shapes.append(Shell(topods_shell)) intersected_shapes.append(Shell(TopoDS.Shell_s(topods_shell)))
intersected_shapes = intersected_shapes.sort_by(Axis(self.center(), direction)) intersected_shapes = intersected_shapes.sort_by(Axis(self.center(), direction))
projected_shapes: ShapeList[Face | Shell] = ShapeList() projected_shapes: ShapeList[Face | Shell] = ShapeList()
@ -2110,7 +2123,7 @@ class Face(Mixin2D[TopoDS_Face]):
for hole_wire in inner_wires: for hole_wire in inner_wires:
reshaper.Remove(hole_wire.wrapped) reshaper.Remove(hole_wire.wrapped)
modified_shape = downcast(reshaper.Apply(self.wrapped)) modified_shape = downcast(reshaper.Apply(self.wrapped))
holeless.wrapped = modified_shape holeless.wrapped = TopoDS.Face_s(modified_shape)
return holeless return holeless
def wire(self) -> Wire: def wire(self) -> Wire:
@ -2513,7 +2526,10 @@ class Shell(Mixin2D[TopoDS_Shell]):
builder.Add(shell, obj.wrapped) builder.Add(shell, obj.wrapped)
obj = shell obj = shell
elif isinstance(obj, Iterable): elif isinstance(obj, Iterable):
obj = _sew_topods_faces([f.wrapped for f in obj]) try:
obj = TopoDS.Shell_s(_sew_topods_faces([f.wrapped for f in obj]))
except Standard_TypeMismatch:
raise TypeError("Unable to create Shell, invalid input type")
super().__init__( super().__init__(
obj=obj, obj=obj,
@ -2531,6 +2547,7 @@ class Shell(Mixin2D[TopoDS_Shell]):
solid_shell = ShapeFix_Solid().SolidFromShell(self.wrapped) solid_shell = ShapeFix_Solid().SolidFromShell(self.wrapped)
properties = GProp_GProps() properties = GProp_GProps()
calc_function = Shape.shape_properties_LUT[shapetype(solid_shell)] calc_function = Shape.shape_properties_LUT[shapetype(solid_shell)]
assert calc_function is not None
calc_function(solid_shell, properties) calc_function(solid_shell, properties)
return properties.Mass() return properties.Mass()
return 0.0 return 0.0
@ -2573,7 +2590,7 @@ class Shell(Mixin2D[TopoDS_Shell]):
Returns: Returns:
Shell: Lofted object Shell: Lofted object
""" """
return cls(_make_loft(objs, False, ruled)) return cls(TopoDS.Shell_s(_make_loft(objs, False, ruled)))
@classmethod @classmethod
def revolve( def revolve(
@ -2599,7 +2616,7 @@ class Shell(Mixin2D[TopoDS_Shell]):
profile.wrapped, axis.wrapped, angle * DEG2RAD, True profile.wrapped, axis.wrapped, angle * DEG2RAD, True
) )
return cls(revol_builder.Shape()) return cls(TopoDS.Shell_s(revol_builder.Shape()))
@classmethod @classmethod
def sweep( def sweep(
@ -2627,7 +2644,7 @@ class Shell(Mixin2D[TopoDS_Shell]):
builder.Add(profile.wrapped, False, False) builder.Add(profile.wrapped, False, False)
builder.SetTransitionMode(Shape._transModeDict[transition]) builder.SetTransitionMode(Shape._transModeDict[transition])
builder.Build() builder.Build()
result = Shell(builder.Shape()) result = Shell(TopoDS.Shell_s(builder.Shape()))
if SkipClean.clean: if SkipClean.clean:
result = result.clean() result = result.clean()