cqparts.constraint package

Submodules

cqparts.constraint.base module

class cqparts.constraint.base.Constraint

Bases: object

A means to limit the relative position &/or motion of 1 or more components.

Constraints are combined and solved to set world coordinates of the components within an assembly.

cqparts.constraint.constraints module

class cqparts.constraint.constraints.Coincident(mate, to_mate)

Bases: cqparts.constraint.base.Constraint

Set a component’s world coordinates of mate.component so that mate.world_coords == to_mate.world_coords.

To successfully determine the component’s location, the relative component must be solvable.

Note

An Assembly cannot solely rely on relative locks to place its components. This is because every component will be waiting for another component to be placed, a circular problem.

At least one of them must use the Fixed

__init__(mate, to_mate)
Parameters:
  • mate (Mate) – mate to lock
  • to_mate (Mate) – mate to lock mate to
class cqparts.constraint.constraints.Fixed(mate, world_coords=None)

Bases: cqparts.constraint.base.Constraint

Sets a component’s world coordinates so the given mate is positioned and orientated to the given world_coords.

There is only 1 possible solution.

__init__(mate, world_coords=None)
Parameters:
  • mate (Mate) – mate to lock
  • world_coords (CoordSystem) – world coordinates to lock mate to
Raises:

TypeError – if an invalid parameter type is passed

If the world_coords parameter is set as a Mate instance, the mate’s .world_coords is used.

If world_coords is None, the object is locked to the origin.

cqparts.constraint.mate module

class cqparts.constraint.mate.Mate(component, local_coords=None)

Bases: object

A mate is a coordinate system relative to a component’s origin.

__add__(other)
Parameters:other – the object being added

Behaviour based on type being added:

Mate + CoordSystem:

Return a copy of self with other added to .local_coords

Raises:TypeError – if type of other is not supported
__init__(component, local_coords=None)
Parameters:
  • component (Component) – component the mate is relative to
  • local_coords (CoordSystem) – coordinate system of mate relative to component’s origin

If component is explicitly set to None, the mate’s world_coords() == local_coords.

If local_coords is not set, the component’s origin is used (ie: coords at 0,0,0, with no rotation)

world_coords
Returns:world coordinates of mate.
Return type:CoordSystem
Raises:ValueError – if .component does not have valid world coordinates.

If .component is None, then the .local_coords are returned.

cqparts.constraint.solver module

cqparts.constraint.solver.solver(constraints, coord_sys=None)

Solve constraints. Solutions pair Constraint instances with their suitable CoordSystem world coordinates.

Parameters:
  • constraints (iterable of Constraint) – constraints to solve
  • coord_sys (CoordSystem) – coordinate system to offset solutions (default: no offset)
Returns:

generator of (Component, CoordSystem) tuples.

Module contents

class cqparts.constraint.Mate(component, local_coords=None)

Bases: object

A mate is a coordinate system relative to a component’s origin.

__add__(other)
Parameters:other – the object being added

Behaviour based on type being added:

Mate + CoordSystem:

Return a copy of self with other added to .local_coords

Raises:TypeError – if type of other is not supported
__init__(component, local_coords=None)
Parameters:
  • component (Component) – component the mate is relative to
  • local_coords (CoordSystem) – coordinate system of mate relative to component’s origin

If component is explicitly set to None, the mate’s world_coords() == local_coords.

If local_coords is not set, the component’s origin is used (ie: coords at 0,0,0, with no rotation)

world_coords
Returns:world coordinates of mate.
Return type:CoordSystem
Raises:ValueError – if .component does not have valid world coordinates.

If .component is None, then the .local_coords are returned.

class cqparts.constraint.Constraint

Bases: object

A means to limit the relative position &/or motion of 1 or more components.

Constraints are combined and solved to set world coordinates of the components within an assembly.

class cqparts.constraint.Fixed(mate, world_coords=None)

Bases: cqparts.constraint.base.Constraint

Sets a component’s world coordinates so the given mate is positioned and orientated to the given world_coords.

There is only 1 possible solution.

__init__(mate, world_coords=None)
Parameters:
  • mate (Mate) – mate to lock
  • world_coords (CoordSystem) – world coordinates to lock mate to
Raises:

TypeError – if an invalid parameter type is passed

If the world_coords parameter is set as a Mate instance, the mate’s .world_coords is used.

If world_coords is None, the object is locked to the origin.

class cqparts.constraint.Coincident(mate, to_mate)

Bases: cqparts.constraint.base.Constraint

Set a component’s world coordinates of mate.component so that mate.world_coords == to_mate.world_coords.

To successfully determine the component’s location, the relative component must be solvable.

Note

An Assembly cannot solely rely on relative locks to place its components. This is because every component will be waiting for another component to be placed, a circular problem.

At least one of them must use the Fixed

__init__(mate, to_mate)
Parameters:
  • mate (Mate) – mate to lock
  • to_mate (Mate) – mate to lock mate to