Implemented constraint translation to the POD format
This commit is contained in:
@ -4,9 +4,14 @@ from typing_extensions import Literal
|
||||
from uuid import uuid1 as uuid
|
||||
|
||||
from .cq import Workplane
|
||||
from .occ_impl.shapes import Shape
|
||||
from .occ_impl.geom import Location
|
||||
from .occ_impl.shapes import Shape, Face, Edge, Wire
|
||||
from .occ_impl.geom import Location, Vector
|
||||
from .occ_impl.assembly import Color
|
||||
from .occ_impl.solver import (
|
||||
ConstraintSolver,
|
||||
ConstraintMarker,
|
||||
Constraint as ConstraintPOD,
|
||||
)
|
||||
from .occ_impl.exporters.assembly import exportAssembly, exportCAF
|
||||
|
||||
|
||||
@ -50,6 +55,41 @@ class Constraint(object):
|
||||
self.kind = kind
|
||||
self.param = param
|
||||
|
||||
def _getAxis(self, arg: Shape) -> Vector:
|
||||
|
||||
if isinstance(arg, Face):
|
||||
rv = arg.normalAt()
|
||||
elif isinstance(arg, Edge) and arg.geomType() != "CIRCLE":
|
||||
rv = arg.tangentAt()
|
||||
elif isinstance(arg, Edge) and arg.geomType() == "CIRCLE":
|
||||
rv = arg.normal()
|
||||
else:
|
||||
raise ValueError(f"Cannot construct Axis for {arg}")
|
||||
|
||||
return rv
|
||||
|
||||
def toPOD(self) -> ConstraintPOD:
|
||||
"""
|
||||
Convert the constraint to a representation used by the solver.
|
||||
"""
|
||||
|
||||
rv: List[Tuple[ConstraintMarker, ...]] = []
|
||||
|
||||
for arg, loc in zip(self.args, self.locs):
|
||||
|
||||
arg = arg.moved(loc)
|
||||
|
||||
if self.kind == "Axis":
|
||||
rv.append((self._getAxis(arg).toDir(),))
|
||||
elif self.kind == "Point":
|
||||
rv.append((arg.Center().toPnt(),))
|
||||
elif self.kind == "Plane":
|
||||
rv.append((self._getAxis(arg).toDir(), arg.Center().toPnt()))
|
||||
else:
|
||||
raise ValueError(f"Unknown constraint kind {self.kind}")
|
||||
|
||||
return cast(ConstraintPOD, tuple(rv))
|
||||
|
||||
|
||||
class Assembly(object):
|
||||
"""Nested assembly of Workplane and Shape objects defining their relative positions.
|
||||
|
||||
@ -977,6 +977,28 @@ class Edge(Shape, Mixin1D):
|
||||
|
||||
return rv
|
||||
|
||||
def normal(self) -> Vector:
|
||||
"""
|
||||
Calculate normal Vector. Only possible for CIRCLE or ELLIPSE
|
||||
|
||||
:param locationParam: location to use in [0,1]
|
||||
:return: tangent vector
|
||||
"""
|
||||
|
||||
curve = self._geomAdaptor()
|
||||
gtype = self.geomType()
|
||||
|
||||
if gtype == "CIRCLE":
|
||||
circ = curve.Circle()
|
||||
rv = Vector(circ.Axis().Direction())
|
||||
elif gtype == "ELLIPSE":
|
||||
ell = curve.Ellipse()
|
||||
rv = Vector(ell.Axis().Direction())
|
||||
else:
|
||||
raise ValueError(f"{gtype} has no normal")
|
||||
|
||||
return rv
|
||||
|
||||
def Center(self) -> Vector:
|
||||
|
||||
Properties = GProp_GProps()
|
||||
|
||||
Reference in New Issue
Block a user