Added optional constraint param
This commit is contained in:
@ -15,12 +15,16 @@ ExportLiterals = Literal["STEP", "XML"]
|
|||||||
|
|
||||||
|
|
||||||
class Constraint(object):
|
class Constraint(object):
|
||||||
|
"""
|
||||||
|
Geometrical constraint between two shapes of an assembly.
|
||||||
|
"""
|
||||||
|
|
||||||
objects: Tuple[str, ...]
|
objects: Tuple[str, ...]
|
||||||
args: Tuple[Shape, ...]
|
args: Tuple[Shape, ...]
|
||||||
kind: ConstraintKinds
|
kind: ConstraintKinds
|
||||||
|
param: Any
|
||||||
|
|
||||||
def __init__(self, objects: Tuple[str, ...], args: Tuple[Shape, ...], kind: ConstraintKinds):
|
def __init__(self, objects: Tuple[str, ...], args: Tuple[Shape, ...], kind: ConstraintKinds, param: Any = None):
|
||||||
"""
|
"""
|
||||||
Construct a constraint.
|
Construct a constraint.
|
||||||
"""
|
"""
|
||||||
@ -28,6 +32,7 @@ class Constraint(object):
|
|||||||
self.objects = objects
|
self.objects = objects
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
|
self.param = param
|
||||||
|
|
||||||
|
|
||||||
class Assembly(object):
|
class Assembly(object):
|
||||||
@ -81,6 +86,7 @@ class Assembly(object):
|
|||||||
self.parent = None
|
self.parent = None
|
||||||
|
|
||||||
self.children = []
|
self.children = []
|
||||||
|
self.constraints = []
|
||||||
self.objects = {self.name: self.obj}
|
self.objects = {self.name: self.obj}
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
@ -177,12 +183,12 @@ class Assembly(object):
|
|||||||
return name, res.val() if isinstance(res.val(), Shape) else None
|
return name, res.val() if isinstance(res.val(), Shape) else None
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def constrain(self, q1: str, q2: str, kind: ConstraintKinds) -> "Assembly":
|
def constrain(self, q1: str, q2: str, kind: ConstraintKinds, param: Any=None) -> "Assembly":
|
||||||
...
|
...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def constrain(
|
def constrain(
|
||||||
self, id1: str, s1: Shape, id2: str, s2: Shape, kind: ConstraintKinds
|
self, id1: str, s1: Shape, id2: str, s2: Shape, kind: ConstraintKinds, param: Any=None
|
||||||
) -> "Assembly":
|
) -> "Assembly":
|
||||||
...
|
...
|
||||||
|
|
||||||
@ -191,16 +197,16 @@ class Assembly(object):
|
|||||||
Define a new constraint.
|
Define a new constraint.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if len(args) == 3:
|
if len(args) == 4:
|
||||||
q1, q2, kind = args
|
q1, q2, kind, param = args
|
||||||
id1, s1 = self._query(q1)
|
id1, s1 = self._query(q1)
|
||||||
id2, s2 = self._query(q2)
|
id2, s2 = self._query(q2)
|
||||||
elif len(args) == 5:
|
elif len(args) == 6:
|
||||||
id1, s1, id2, s2, kind = args
|
id1, s1, id2, s2, kind, param = args
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Incompatibile arguments: {args}')
|
raise ValueError(f'Incompatibile arguments: {args}')
|
||||||
|
|
||||||
self.constraints.append(Constraint((id1, id2), (s1, s2), kind))
|
self.constraints.append(Constraint((id1, id2), (s1, s2), kind, param))
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user