bluemira.codes._freecadapi

Supporting functions for the bluemira geometry module.

Attributes

apiVertex

apiVector

apiEdge

apiWire

apiFace

apiShell

apiSolid

apiShape

apiSurface

apiPlacement

apiPlane

apiCompound

WORKING_PRECISION

MIN_PRECISION

MAX_PRECISION

ONE_PERIOD

Classes

JoinType

See Part/PartEnums.py, its not importable

Document

Context manager to wrap freecad document creation

_CADType

CAD file type definition

CADFileType

FreeCAD standard export filetypes

ExporterProtocol

Typing for CAD exporter

ImporterProtocol

Typing for CAD importer

DefaultDisplayOptions

Freecad default display options

Functions

catch_caderr(new_error_type)

Catch CAD errors with given error

arrange_edges(→ apiWire)

A helper to try and fix some topological naming issues.

check_data_type(data_type)

Decorator to check the data type of the first parameter input (args[0]) of a

vector_to_list(→ list[list[float]])

Converts a FreeCAD Base.Vector or list(Base.Vector) into a list

point_to_list(→ list[list[float]])

Converts a FreeCAD Part.Point or list(Part.Point) into a list

vertex_to_list(→ list[list[float]])

Converts a FreeCAD Part.Vertex or list(Part.Vertex) into a list

vector_to_numpy(→ numpy.ndarray)

Converts a FreeCAD Base.Vector or list(Base.Vector) into a numpy array

point_to_numpy(→ numpy.ndarray)

Converts a FreeCAD Part.Point or list(Part.Point) into a numpy array

vertex_to_numpy(→ numpy.ndarray)

Converts a FreeCAD Part.Vertex or list(Part.Vertex) into a numpy array

make_solid(→ apiSolid)

Make a solid from a shell.

make_shell(→ apiShell)

Make a shell from faces.

make_compound(→ apiCompound)

Make an FreeCAD compound object out of many shapes

make_polygon(→ apiWire)

Make a polygon from a set of points.

make_bezier(→ apiWire)

Make a bezier curve from a set of points.

make_bspline(→ apiWire)

Builds a B-Spline by a lists of Poles, Mults, Knots

make_bsplinesurface(→ apiSurface)

Builds a B-SplineSurface by a lists of Poles, Mults, Knots

interpolate_bspline(→ apiWire)

Make a B-Spline curve by interpolating a set of points.

make_bspline_g1_blend(→ apiWire)

Create a G1-continuous B-spline blend between two edges.

make_circle_curve(→ Part.Circle)

Make a Part.Circle with a consistent .Rotation property, by initializing a circle of

make_circle(→ apiWire)

Create a circle or arc of circle object with given parameters.

make_circle_arc_3P(→ apiWire)

Create an arc of circle object given three points.

make_ellipse(→ apiWire)

Creates an ellipse or arc of ellipse object with given parameters.

offset_wire(→ apiWire)

Make an offset from a wire.

make_face(→ apiFace)

Make a face given a wire boundary.

_get_api_attr(obj, prop)

length(→ float)

Object's length

area(→ float)

Object's Area

volume(→ float)

Object's volume

center_of_mass(→ numpy.ndarray)

Object's center of mass

is_null(→ bool)

True if obj is null

is_closed(→ bool)

True if obj is closed

is_valid(→ bool)

True if obj is valid

is_same(→ bool)

True if obj1 and obj2 have the same shape.

bounding_box(→ tuple[float, float, float, float, ...)

Object's bounding box

optimal_bounding_box(→ tuple[float, float, float, ...)

Object's optimal bounding box

tessellate(→ tuple[numpy.ndarray, numpy.ndarray])

Tessellate a geometry object.

start_point(→ numpy.ndarray)

The start point of the object

end_point(→ numpy.ndarray)

The end point of the object

ordered_vertexes(→ numpy.ndarray)

Ordered vertexes of the object

vertexes(→ numpy.ndarray)

Wires of the object

orientation(→ bool)

True if obj is valid

edges(→ list[apiWire])

Edges of the object

ordered_edges(→ numpy.ndarray)

Ordered edges of the object

wires(→ list[apiWire])

Wires of the object

faces(→ list[apiFace])

Faces of the object

shells(→ list[apiShell])

Shells of the object

solids(→ list[apiSolid])

Solids of the object

normal_at(→ numpy.ndarray)

wire_closure(→ apiWire)

Create a line segment wire that closes an open wire

close_wire(→ apiWire)

Closes a wire with a line segment, if not already closed.

discretise(→ numpy.ndarray)

Discretise a wire.

discretise_by_edges(→ numpy.ndarray)

Discretise a wire taking into account the edges of which it consists of.

dist_to_shape(→ tuple[float, list[tuple[numpy.ndarray, ...)

Find the minimum distance between two shapes

wire_value_at(→ numpy.ndarray)

Get a point a given distance along a wire.

wire_parameter_at(→ float)

Get the parameter value at a vertex along a wire.

split_wire(→ tuple[apiWire | None, apiWire | None])

Split a wire at a given vertex.

_split_edge(edge, parameter)

_get_closest_edge_idx(wire, vertex)

slice_shape(shape, plane_origin, plane_axis)

Slice a shape along a given plane

_slice_wire(wire, normal_plane, shift, *[, BIG_NUMBER])

Get the plane intersection points of any wire (possibly anything, needs testing)

_slice_solid(obj, normal_plane, shift)

Get the plane intersection wires of a face or solid

import_cad(→ list[tuple[apiShape, str]])

Import CAD objects from file

webgl_export(→ ExporterProtocol)

Webgl exporter for offscreen rendering

stepz_import(→ ImporterProtocol)

Step z importer "needs" more FreeCADGui so we're patching it out

meshed_exporter(→ ExporterProtocol)

Meshing and then exporting CAD in certain formats.

save_as_STP(shapes[, filename])

Saves a series of Shape objects as a STEP assembly

_scale_obj(objs[, scale])

Scale objects

save_cad(shapes, filename[, cad_format, labels, doc_name])

Save CAD in a given file format

scale_shape(→ apiShape)

Apply scaling with factor to the shape

translate_shape(→ apiShape)

Apply scaling with factor to the shape

rotate_shape(, direction, float, float] =, degree)

Apply the rotation (base, dir, degree) to this shape

mirror_shape(→ apiShape)

Mirror a shape about a plane.

revolve_shape(, direction, float, float] =, degree)

Apply the revolve (base, dir, degree) to this shape

extrude_shape(→ apiShape)

Apply the extrusion along vec to this shape

_split_wire(wire)

Split a wire into two parts at mid point or middle edge.

sweep_shape(→ apiShell | apiSolid)

Sweep a a set of profiles along a path.

loft(→ apiShell | apiSolid)

Loft between a set of profiles.

fillet_wire_2D(→ apiWire)

Fillet or chamfer a two-dimensional wire, returning a new wire

join_connect(→ apiShape)

Connects the interiors of two walled objects (e.g. pipes).

boolean_fuse(→ apiShape)

Fuse two or more shapes together. Internal splitter are removed.

boolean_cut(→ list[apiShape])

Difference of shape and a given (list of) topo shape cut(tools)

boolean_fragments(→ tuple[apiCompound, list[apiSolid]])

Split a list of shapes into their Boolean fragments.

point_inside_shape(→ bool)

Whether or not a point is inside a shape.

_edges_tangent(→ bool)

Check if two adjacent edges are tangent to one another.

_wire_edges_tangent(→ bool)

Check that all consecutive edges in a wire are tangent

_wire_is_planar(→ bool)

Check if a wire is planar.

_wire_is_straight(→ bool)

Check if a wire is a straight line.

_is_wire_or_face(shape_type)

_check_shapes_same_type(shapes)

Check that all the shapes are of the same type.

_check_shapes_coplanar(shapes)

_shapes_are_coplanar(→ bool)

Check if a list of shapes are all coplanar. First shape is taken as the reference.

_shapes_are_coaxis(→ bool)

Check if a list of shapes are all co-axis. First shape is taken as the reference.

_make_shapes_coaxis(shapes)

Make a list of shapes co-axis by reversing. First shape is taken as the reference.

fix_shape(shape[, precision, min_length])

Fix a shape by removing any small edges and joining the remaining edges.

make_placement(→ apiPlacement)

Make a FreeCAD Placement

make_placement_from_matrix(→ apiPlacement)

Make a FreeCAD Placement from a 4 x 4 matrix.

move_placement(placement, vector)

Moves the FreeCAD Placement along the given vector

make_placement_from_vectors(→ apiPlacement)

Create a placement from three directional vectors

change_placement(geo, placement)

Change the placement of a FreeCAD object

make_plane(, axis, float, float] = ) → apiPlane)

Creates a FreeCAD plane with a given location and normal

make_plane_from_3_points(, point2, float, float] =, ...)

Creates a FreeCAD plane defined by three non-linear points

face_from_plane(→ apiFace)

Creates a FreeCAD face from a Plane with specified height and width.

plane_from_shape(→ apiPlane)

placement_from_plane(→ apiPlacement)

_colourise(node, options)

collect_verts_faces(→ tuple[numpy.ndarray | None, ...)

Collects vertices and faces of parts and tessellates them

collect_wires(→ tuple[numpy.ndarray, numpy.ndarray])

Collects vertices and edges of parts and discretises them

show_cad(parts[, options, labels, camera_rotation])

The implementation of the display API for FreeCAD parts.

rotate_into_position(scene, x_ang, y_ang, z_ang)

Rotate camera around object

embedLight(→ pivy.coin.SoSeparator)

Embeds a given coin node

extract_attribute(func)

Decorator for serialise_shape. Convert the function output attributes string

serialise_shape(shape)

Serialise a FreeCAD topological data object.

deserialise_shape(buffer)

Deserialise a FreeCAD topological data object obtained from serialise_shape.

_convert_edge_to_curve(...)

Convert a Freecad Edge to the respective curve.

Module Contents

bluemira.codes._freecadapi.apiVertex
bluemira.codes._freecadapi.apiVector
bluemira.codes._freecadapi.apiEdge
bluemira.codes._freecadapi.apiWire
bluemira.codes._freecadapi.apiFace
bluemira.codes._freecadapi.apiShell
bluemira.codes._freecadapi.apiSolid
bluemira.codes._freecadapi.apiShape
bluemira.codes._freecadapi.apiSurface
bluemira.codes._freecadapi.apiPlacement
bluemira.codes._freecadapi.apiPlane
bluemira.codes._freecadapi.apiCompound
bluemira.codes._freecadapi.WORKING_PRECISION = 1e-05
bluemira.codes._freecadapi.MIN_PRECISION = 1e-05
bluemira.codes._freecadapi.MAX_PRECISION = 1e-05
bluemira.codes._freecadapi.ONE_PERIOD
bluemira.codes._freecadapi.catch_caderr(new_error_type)

Catch CAD errors with given error

Returns:

the wrapped function

bluemira.codes._freecadapi.arrange_edges(old_wire: apiWire, new_wire: apiWire) apiWire

A helper to try and fix some topological naming issues. Tries to arrange edges as they were in the old wire

Parameters:
  • old_wire (apiWire) – old wire to emulate edges from

  • new_wire (apiWire) – new wire to change edge arrangement

Returns:

Wire with arranged edges

Return type:

apiWire

bluemira.codes._freecadapi.check_data_type(data_type)

Decorator to check the data type of the first parameter input (args[0]) of a function.

Returns:

Decorator enforcing a certain datatype

Raises:

TypeError – If args[0] objects are not instances of data_type

bluemira.codes._freecadapi.vector_to_list(vectors: list[apiVector]) list[list[float]]

Converts a FreeCAD Base.Vector or list(Base.Vector) into a list

Parameters:

vectors (list[apiVector])

Return type:

list[list[float]]

bluemira.codes._freecadapi.point_to_list(points: list[Part.Point]) list[list[float]]

Converts a FreeCAD Part.Point or list(Part.Point) into a list

Parameters:

points (list[Part.Point])

Return type:

list[list[float]]

bluemira.codes._freecadapi.vertex_to_list(vertexes: list[apiVertex]) list[list[float]]

Converts a FreeCAD Part.Vertex or list(Part.Vertex) into a list

Parameters:

vertexes (list[apiVertex])

Return type:

list[list[float]]

bluemira.codes._freecadapi.vector_to_numpy(vectors: list[apiVector]) numpy.ndarray

Converts a FreeCAD Base.Vector or list(Base.Vector) into a numpy array

Parameters:

vectors (list[apiVector])

Return type:

numpy.ndarray

bluemira.codes._freecadapi.point_to_numpy(points: list[Part.Point]) numpy.ndarray

Converts a FreeCAD Part.Point or list(Part.Point) into a numpy array

Parameters:

points (list[Part.Point])

Return type:

numpy.ndarray

bluemira.codes._freecadapi.vertex_to_numpy(vertexes: list[apiVertex]) numpy.ndarray

Converts a FreeCAD Part.Vertex or list(Part.Vertex) into a numpy array

Parameters:

vertexes (list[apiVertex])

Return type:

numpy.ndarray

bluemira.codes._freecadapi.make_solid(shell: apiShell) apiSolid

Make a solid from a shell.

Parameters:

shell (apiShell)

Return type:

apiSolid

bluemira.codes._freecadapi.make_shell(faces: list[apiFace]) apiShell

Make a shell from faces.

Parameters:

faces (list[apiFace])

Return type:

apiShell

bluemira.codes._freecadapi.make_compound(shapes: list[apiShape]) apiCompound

Make an FreeCAD compound object out of many shapes

Parameters:

shapes (list[apiShape]) – A set of objects to be compounded

Return type:

A compounded set of shapes

bluemira.codes._freecadapi.make_polygon(points: list | numpy.ndarray) apiWire

Make a polygon from a set of points.

Parameters:

points (list | numpy.ndarray) – list of points. It can be given as a list of 3D tuples, a 3D numpy array, or similar.

Returns:

A FreeCAD wire that contains the polygon

Return type:

apiWire

bluemira.codes._freecadapi.make_bezier(points: list | numpy.ndarray) apiWire

Make a bezier curve from a set of points.

Parameters:

points (list | numpy.ndarray) – list of points. It can be given as a list of 3D tuples, a 3D numpy array, or similar.

Returns:

A FreeCAD wire that contains the bezier curve

Return type:

apiWire

bluemira.codes._freecadapi.make_bspline(poles: numpy.typing.ArrayLike, mults: numpy.typing.ArrayLike, knots: numpy.typing.ArrayLike, *, periodic: bool, degree: int, weights: numpy.typing.ArrayLike, check_rational: bool) apiWire

Builds a B-Spline by a lists of Poles, Mults, Knots

Parameters:
  • poles (numpy.typing.ArrayLike) – list of poles.

  • mults (numpy.typing.ArrayLike) – list of integers for the multiplicity

  • knots (numpy.typing.ArrayLike) – list of knots

  • periodic (bool) – Whether or not the spline is periodic (same curvature at start and end points)

  • degree (int) – bspline degree

  • weights (numpy.typing.ArrayLike) – sequence of float

  • check_rational (bool) – Whether or not to check if the BSpline is rational (not sure)

Returns:

A FreeCAD wire that contains the bspline curve

Return type:

apiWire

Notes

This function wraps the FreeCAD function of bsplines buildFromPolesMultsKnots

bluemira.codes._freecadapi.make_bsplinesurface(poles: numpy.typing.ArrayLike, mults_u: numpy.typing.ArrayLike, mults_v: numpy.typing.ArrayLike, knot_vector_u: numpy.typing.ArrayLike, knot_vector_v: numpy.typing.ArrayLike, degree_u: int, degree_v: int, weights: numpy.typing.ArrayLike, *, periodic: bool = False, check_rational: bool = False) apiSurface

Builds a B-SplineSurface by a lists of Poles, Mults, Knots

Parameters:
  • poles (numpy.typing.ArrayLike) – poles (sequence of Base.Vector).

  • mults_u (numpy.typing.ArrayLike) – list of integers for the u-multiplicity

  • mults_v (numpy.typing.ArrayLike) – list of integers for the u-multiplicity

  • knot_vector_u (numpy.typing.ArrayLike) – list of u-knots

  • knot_vector_v (numpy.typing.ArrayLike) – list of v-knots

  • degree_u (int) – degree of NURBS in u-direction

  • degree_v (int) – degree of NURBS in v-direction

  • weights (numpy.typing.ArrayLike) – pole weights (sequence of float).

  • periodic (bool) – Whether or not the spline is periodic (same curvature at start and end points)

  • check_rational (bool) – Whether or not to check if the BSpline is rational (not sure)

Returns:

A FreeCAD object that contours the bsplinesurface

Return type:

apiSurface

Notes

This function wraps the FreeCAD function of bsplinesurface buildFromPolesMultsKnots

bluemira.codes._freecadapi.interpolate_bspline(points: list | numpy.ndarray, *, closed: bool = False, start_tangent: collections.abc.Iterable | None = None, end_tangent: collections.abc.Iterable | None = None) apiWire

Make a B-Spline curve by interpolating a set of points.

Parameters:
  • points (list | numpy.ndarray) – list of points. It can be given as a list of 3D tuples, a 3D numpy array, or similar.

  • closed (bool) – if True, the first and last points will be connected in order to form a closed shape.

  • start_tangent (collections.abc.Iterable | None) – Tangency of the BSpline at the first pole. Must be specified with end_tangent

  • end_tangent (collections.abc.Iterable | None) – Tangency of the BSpline at the last pole. Must be specified with start_tangent

Returns:

A FreeCAD wire that contains the bspline curve

Raises:
  • InvalidCADInputsError – Not enough points to interpolate

  • FreeCADError – Unable to make spline

Return type:

apiWire

bluemira.codes._freecadapi.make_bspline_g1_blend(edge1: apiEdge, edge2: apiEdge, scale=0.2) apiWire

Create a G1-continuous B-spline blend between two edges.

This function generates a B-spline curve that connects edge1 and edge2 while attempting to enforce G1 (tangent) continuity. The curve is constructed by blending the tangents of the edges at their connection points.

Parameters:
  • edge1 (apiEdge) – The first edge to connect. The blend will attach to either its start or end, depending on at_end1.

  • edge2 (apiEdge) – The second edge to connect. The blend will attach to either its start or end, depending on at_start2.

  • scale (float, optional) – Scale factor for the tangent vector length used in the blend (default is 0.1).

Returns:

A B-spline wire representing the blend curve between edge1 and edge2.

Return type:

apiWire

Raises:

FreeCADError – If the edges are coincident

Notes

This is hot garbage. Tangency is not reliable.

bluemira.codes._freecadapi.make_circle_curve(radius: float, center: apiVector, axis: apiVector) Part.Circle

Make a Part.Circle with a consistent .Rotation property, by initializing a circle of the default size, position and orientation at first.

Parameters:
  • radius (float) – radius of the circle [m]

  • center (apiVector) – center of the circle [m]

  • axis (apiVector) – Normalised vector around which the circle spins counter-clockwise.

Returns:

Part.Circle created by FreeCAD.

Return type:

circle

bluemira.codes._freecadapi.make_circle(radius: float = 1.0, center: collections.abc.Iterable[float] = [0.0, 0.0, 0.0], start_angle: float = 0.0, end_angle: float = 360.0, axis: collections.abc.Iterable[float] = [0.0, 0.0, 1.0]) apiWire

Create a circle or arc of circle object with given parameters.

Parameters:
  • radius (float) – Radius of the circle

  • center (collections.abc.Iterable[float]) – Center of the circle

  • start_angle (float) – Start angle of the arc [degrees]

  • end_angle (float) – End angle of the arc [degrees]. If start_angle == end_angle, a circle is created, otherwise a circle arc is created

  • axis (collections.abc.Iterable[float]) – Normal vector to the circle plane. It defines the clockwise/anticlockwise circle orientation according to the right hand rule. Default [0., 0., 1.].

Returns:

FreeCAD wire that contains the arc or circle

Return type:

apiWire

bluemira.codes._freecadapi.make_circle_arc_3P(p1: collections.abc.Iterable[float], p2: collections.abc.Iterable[float], p3: collections.abc.Iterable[float], axis: collections.abc.Iterable[float] | None = None) apiWire

Create an arc of circle object given three points.

Parameters:
  • p1 (collections.abc.Iterable[float]) – Starting point of the circle arc

  • p2 (collections.abc.Iterable[float]) – Middle point of the circle arc

  • p3 (collections.abc.Iterable[float]) – End point of the circle arc

  • axis (collections.abc.Iterable[float] | None)

Returns:

FreeCAD wire that contains the arc of circle

Raises:

FreeCADError – Raised if the three points are collinear.

Return type:

apiWire

bluemira.codes._freecadapi.make_ellipse(center: collections.abc.Iterable[float] = [0.0, 0.0, 0.0], major_radius: float = 2.0, minor_radius: float = 1.0, major_axis: collections.abc.Iterable[float] = [1, 0, 0], minor_axis: collections.abc.Iterable[float] = [0, 1, 0], start_angle: float = 0.0, end_angle: float = 360.0) apiWire

Creates an ellipse or arc of ellipse object with given parameters.

Parameters:
  • center (collections.abc.Iterable[float]) – Center of the ellipse

  • major_radius (float) – the major radius of the ellipse

  • minor_radius (float) – the minor radius of the ellipse

  • major_axis (collections.abc.Iterable[float]) – major axis direction

  • minor_axis (collections.abc.Iterable[float]) – minor axis direction

  • start_angle (float) – Start angle of the arc [degrees]

  • end_angle (float) – End angle of the arc [degrees]. If start_angle == end_angle, an ellipse is created, otherwise an arc of ellipse is created

Returns:

FreeCAD wire that contains the ellipse or arc of ellipse

Return type:

apiWire

class bluemira.codes._freecadapi.JoinType

Bases: enum.IntEnum

Inheritance diagram of bluemira.codes._freecadapi.JoinType

See Part/PartEnums.py, its not importable

Arc = 0
Tangent = 1
Intersect = 2
bluemira.codes._freecadapi.offset_wire(wire: apiWire, thickness: float, join: str = 'intersect', *, open_wire: bool = True) apiWire

Make an offset from a wire.

Parameters:
  • wire (apiWire) – Wire to offset from

  • thickness (float) – Offset distance. Positive values outwards, negative values inwards

  • join (str) – Offset method. “arc” gives rounded corners, and “intersect” gives sharp corners

  • open_wire (bool) – For open wires (counter-clockwise default) whether or not to make an open offset wire, or a closed offset wire that encompasses the original wire. This is disabled for closed wires.

Returns:

Offset wire

Raises:
  • InvalidCADInputsError – Wire must be planar and cannot be straight

  • FreeCADError – offset failed

Return type:

apiWire

bluemira.codes._freecadapi.make_face(wire: apiWire) apiFace

Make a face given a wire boundary.

Parameters:

wire (apiWire) – Wire boundary from which to make a face

Returns:

Face created from the wire boundary

Raises:

FreeCADError – If the created face is invalid

Return type:

apiFace

bluemira.codes._freecadapi._get_api_attr(obj: apiShape, prop: str)
Parameters:
  • obj (apiShape)

  • prop (str)

bluemira.codes._freecadapi.length(obj: apiShape) float

Object’s length

Parameters:

obj (apiShape)

Return type:

float

bluemira.codes._freecadapi.area(obj: apiShape) float

Object’s Area

Parameters:

obj (apiShape)

Return type:

float

bluemira.codes._freecadapi.volume(obj: apiShape) float

Object’s volume

Parameters:

obj (apiShape)

Return type:

float

bluemira.codes._freecadapi.center_of_mass(obj: apiShape) numpy.ndarray

Object’s center of mass

Parameters:

obj (apiShape)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.is_null(obj: apiShape) bool

True if obj is null

Parameters:

obj (apiShape)

Return type:

bool

bluemira.codes._freecadapi.is_closed(obj: apiShape) bool

True if obj is closed

Parameters:

obj (apiShape)

Return type:

bool

bluemira.codes._freecadapi.is_valid(obj) bool

True if obj is valid

Return type:

bool

bluemira.codes._freecadapi.is_same(obj1: apiShape, obj2: apiShape) bool

True if obj1 and obj2 have the same shape.

Parameters:
  • obj1 (apiShape)

  • obj2 (apiShape)

Return type:

bool

bluemira.codes._freecadapi.bounding_box(obj: apiShape) tuple[float, float, float, float, float, float]

Object’s bounding box

Parameters:

obj (apiShape)

Return type:

tuple[float, float, float, float, float, float]

bluemira.codes._freecadapi.optimal_bounding_box(obj: apiShape) tuple[float, float, float, float, float, float]

Object’s optimal bounding box

Parameters:

obj (apiShape)

Return type:

tuple[float, float, float, float, float, float]

bluemira.codes._freecadapi.tessellate(obj: apiShape, tolerance: float) tuple[numpy.ndarray, numpy.ndarray]

Tessellate a geometry object.

Parameters:
  • obj (apiShape) – Shape to tessellate

  • tolerance (float) – Tolerance with which to perform the operation

Returns:

  • vertices – Array of the vertices (N, 3, dtype=float) from the tesselation operation

  • indices – Array of the indices (M, 3, dtype=int) from the tesselation operation

Raises:

ValueError – If the tolerance is <= 0.0

Return type:

tuple[numpy.ndarray, numpy.ndarray]

Notes

Once tesselated an object’s properties may change. Tesselation cannot be reverted to a previous lower value, but can be increased (irreversibly).

bluemira.codes._freecadapi.start_point(obj: apiShape) numpy.ndarray

The start point of the object

Parameters:

obj (apiShape)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.end_point(obj: apiShape) numpy.ndarray

The end point of the object

Parameters:

obj (apiShape)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.ordered_vertexes(obj: apiShape) numpy.ndarray

Ordered vertexes of the object

Parameters:

obj (apiShape)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.vertexes(obj: apiShape) numpy.ndarray

Wires of the object

Parameters:

obj (apiShape)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.orientation(obj: apiShape) bool

True if obj is valid

Parameters:

obj (apiShape)

Return type:

bool

bluemira.codes._freecadapi.edges(obj: apiShape) list[apiWire]

Edges of the object

Parameters:

obj (apiShape)

Return type:

list[apiWire]

bluemira.codes._freecadapi.ordered_edges(obj: apiShape) numpy.ndarray

Ordered edges of the object

Parameters:

obj (apiShape)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.wires(obj: apiShape) list[apiWire]

Wires of the object

Parameters:

obj (apiShape)

Return type:

list[apiWire]

bluemira.codes._freecadapi.faces(obj: apiShape) list[apiFace]

Faces of the object

Parameters:

obj (apiShape)

Return type:

list[apiFace]

bluemira.codes._freecadapi.shells(obj: apiShape) list[apiShell]

Shells of the object

Parameters:

obj (apiShape)

Return type:

list[apiShell]

bluemira.codes._freecadapi.solids(obj: apiShape) list[apiSolid]

Solids of the object

Parameters:

obj (apiShape)

Return type:

list[apiSolid]

bluemira.codes._freecadapi.normal_at(face: apiFace, alpha_1: float = 0.0, alpha_2: float = 0.0) numpy.ndarray
Returns:

The normal vector of the face at a parameterised point in space. For planar faces, the normal is the same everywhere.

Parameters:
  • face (apiFace)

  • alpha_1 (float)

  • alpha_2 (float)

Return type:

numpy.ndarray

bluemira.codes._freecadapi.wire_closure(wire: apiWire) apiWire

Create a line segment wire that closes an open wire

Returns:

The closure segment

Parameters:

wire (apiWire)

Return type:

apiWire

bluemira.codes._freecadapi.close_wire(wire: apiWire) apiWire

Closes a wire with a line segment, if not already closed.

Returns:

A new closed wire.

Parameters:

wire (apiWire)

Return type:

apiWire

bluemira.codes._freecadapi.discretise(w: apiWire, ndiscr: int = 10, dl: float | None = None) numpy.ndarray

Discretise a wire.

Parameters:
  • w (apiWire) – wire to be discretised.

  • ndiscr (int) – number of points for the whole wire discretisation.

  • dl (float | None) – target discretisation length (default None). If dl is defined, ndiscr is not considered.

Returns:

Array of points

Raises:

ValueError – If ndiscr < 2 If dl <= 0.0

Return type:

numpy.ndarray

bluemira.codes._freecadapi.discretise_by_edges(w: apiWire, ndiscr: int = 10, dl: float | None = None) numpy.ndarray

Discretise a wire taking into account the edges of which it consists of.

Parameters:
  • w (apiWire) – Wire to be discretised.

  • ndiscr (int) – Number of points for the whole wire discretisation.

  • dl (float | None) – Target discretisation length (default None). If dl is defined, ndiscr is not considered.

Returns:

Array of points

Raises:

ValueError – dl <= 0

Return type:

numpy.ndarray

Notes

Final number of points can be slightly different due to edge discretisation routine.

bluemira.codes._freecadapi.dist_to_shape(shape1: apiShape, shape2: apiShape) tuple[float, list[tuple[numpy.ndarray, numpy.ndarray]]]

Find the minimum distance between two shapes

Parameters:
  • shape1 (apiShape) – reference shape.

  • shape2 (apiShape) – target shape.

Returns:

  • dist – Minimum distance

  • vectors – List of tuples corresponding to the nearest points (numpy.ndarray) between shape1 and shape2. The distance between those points is the minimum distance given by dist.

Return type:

tuple[float, list[tuple[numpy.ndarray, numpy.ndarray]]]

bluemira.codes._freecadapi.wire_value_at(wire: apiWire, distance: float) numpy.ndarray

Get a point a given distance along a wire.

Parameters:
  • wire (apiWire) – Wire along which to get a point

  • distance (float) – Distance

Returns:

Wire point value at distance

Return type:

numpy.ndarray

bluemira.codes._freecadapi.wire_parameter_at(wire: apiWire, vertex: collections.abc.Iterable[float], tolerance: float = EPS_FREECAD) float

Get the parameter value at a vertex along a wire.

Parameters:
  • wire (apiWire) – Wire along which to get the parameter

  • vertex (collections.abc.Iterable[float]) – Vertex for which to get the parameter

  • tolerance (float) – Tolerance within which to get the parameter

Returns:

Parameter value along the wire at the vertex

Raises:

FreeCADError: – If the vertex is further away to the wire than the specified tolerance

Return type:

float

bluemira.codes._freecadapi.split_wire(wire: apiWire, vertex: collections.abc.Iterable[float], tolerance: float) tuple[apiWire | None, apiWire | None]

Split a wire at a given vertex.

Parameters:
  • wire (apiWire) – Wire to be split

  • vertex (collections.abc.Iterable[float]) – Vertex at which to split the wire

  • tolerance (float) – Tolerance within which to find the closest vertex on the wire

Returns:

  • wire_1 – First half of the wire. Will be None if the vertex is the start point of the wire

  • wire_2 – Last half of the wire. Will be None if the vertex is the start point of the wire

Raises:

FreeCADError – If the vertex is further away to the wire than the specified tolerance

Return type:

tuple[apiWire | None, apiWire | None]

bluemira.codes._freecadapi._split_edge(edge, parameter)
Parameters:
  • edge – The Part.Edge to be splitted

  • parameter – the parameter

Returns:

  • edge_1 – The edge from its minimum parameter up to the user-provided parameter. If length=0, then return None.

  • edge_2 – The edge from the user-provided parameter up to its maximum parameter. If length=0, then return None.

Raises:

FreeCADError – Thrown if the provided parameter is outside of the edge’s valid parameter range.

bluemira.codes._freecadapi._get_closest_edge_idx(wire, vertex)
bluemira.codes._freecadapi.slice_shape(shape: apiShape, plane_origin: collections.abc.Iterable[float], plane_axis: collections.abc.Iterable[float])

Slice a shape along a given plane

Parameters:
  • shape (apiShape) – shape to slice

  • plane_origin (collections.abc.Iterable[float]) – plane origin

  • plane_axis (collections.abc.Iterable[float]) – normal plane axis

Notes

Degenerate cases such as tangents to solid or faces do not return intersections if the shape and plane are acting at the Plane base. Further investigation needed.

bluemira.codes._freecadapi._slice_wire(wire, normal_plane, shift, *, BIG_NUMBER=100000.0)

Get the plane intersection points of any wire (possibly anything, needs testing)

bluemira.codes._freecadapi._slice_solid(obj, normal_plane, shift)

Get the plane intersection wires of a face or solid

class bluemira.codes._freecadapi.Document(shapes: collections.abc.Iterable[apiShape] | None = None, labels: collections.abc.Iterable[str] | None = None, doc_name: str = 'Bluemira_FreeCAD_wrapper')

Context manager to wrap freecad document creation

Parameters:
  • shapes (collections.abc.Iterable[apiShape] | None)

  • labels (collections.abc.Iterable[str] | None)

  • doc_name (str)

shapes = None
labels = None
doc_name = 'Bluemira_FreeCAD_wrapper'
__enter__()
parts() collections.abc.Iterator[Part.Feature]

Get FreeCAD parts.

Converts shapes to FreeCAD Part.Features to enable saving and viewing

Yields:

Each object in document

Raises:

ValueError – Number of objects not equal to number of labels

Return type:

collections.abc.Iterator[Part.Feature]

__exit__(exc_type, exc_value, exc_tb)
class bluemira.codes._freecadapi._CADType

CAD file type definition

file_extensions: str | tuple[str, Ellipsis]
export_module: str | None = None
import_module: str | None = None
__post_init__()
__contains__(value: str) bool
Parameters:

value (str)

Return type:

bool

__eq__(value: str | _CADType) bool
Parameters:

value (str | _CADType)

Return type:

bool

__hash__()
property ext
exporter() ExporterProtocol
Return type:

ExporterProtocol

importer() ImporterProtocol
Return type:

ImporterProtocol

class bluemira.codes._freecadapi.CADFileType(*args, **kwds)

Bases: enum.Enum

Inheritance diagram of bluemira.codes._freecadapi.CADFileType

FreeCAD standard export filetypes

Notes

Some filetypes my require additional dependencies see: https://wiki.freecad.org/Import_Export

ASCII_STEREO_MESH
ADDITIVE_MANUFACTURING
ASC
AUTOCAD
AUTOCAD_DXF
BDF
BINMESH
BREP
CSG
DAE
DAT
FREECAD
FENICS_FEM
FENICS_FEM_XML
GLTRANSMISSION
IFC_BIM
IFC_BIM_JSON
IGES
INP
INVENTOR_V2_1
JSON
JSON_MESH
MED
MESHJSON
MESHPY
MESHYAML
OBJ
OBJ_WAVE
OFF
OPENSCAD
PCD
PLY
PLY_STANFORD
SIMPLE_MODEL
STEP
STEP_ZIP
STL
SVG_FLAT
TETGEN_FEM
UNV
VTK
VTU
WEBGL
YAML
Z88_FEM_MESH
Z88_FEM_MESH_2
classmethod _missing_(value: str) CADFileType
Parameters:

value (str)

Return type:

CADFileType

classmethod unitless_formats() tuple[CADFileType, Ellipsis]
Returns:

CAD formats that don’t need to be converted because they are unitless

Return type:

tuple[CADFileType, Ellipsis]

classmethod manual_mesh_formats() tuple[CADFileType, Ellipsis]

CAD formats that need to have meshed objects.

Return type:

tuple[CADFileType, Ellipsis]

classmethod not_importable_formats() tuple[CADFileType, Ellipsis]
Return type:

tuple[CADFileType, Ellipsis]

classmethod mesh_import_formats() tuple[CADFileType, Ellipsis]
Return type:

tuple[CADFileType, Ellipsis]

ext() str
Return type:

str

exporter() ExporterProtocol

Get exporter module for each filetype

Raises:

FreeCADError – Unable to save file type

Return type:

ExporterProtocol

importer() ImporterProtocol

Get importer module for each filetype

Raises:

FreeCADError – Unable to import file type

Return type:

ImporterProtocol

class bluemira.codes._freecadapi.ExporterProtocol

Bases: Protocol

Inheritance diagram of bluemira.codes._freecadapi.ExporterProtocol

Typing for CAD exporter

__call__(objs: list[Part.Feature], filename: str, **kwargs)

Export CAD protocol

Parameters:
  • objs (list[Part.Feature])

  • filename (str)

class bluemira.codes._freecadapi.ImporterProtocol

Bases: Protocol

Inheritance diagram of bluemira.codes._freecadapi.ImporterProtocol

Typing for CAD importer

__call__(filename: str, document: str, **kwargs)

Import CAD protocol

Parameters:
  • filename (str)

  • document (str)

bluemira.codes._freecadapi.import_cad(file: str | pathlib.Path, filetype: CADFileType | str | None = None, unit_scale: str = 'm', **kwargs) list[tuple[apiShape, str]]

Import CAD objects from file

Returns:

The imported shapes

Parameters:
  • file (str | pathlib.Path)

  • filetype (CADFileType | str | None)

  • unit_scale (str)

Return type:

list[tuple[apiShape, str]]

bluemira.codes._freecadapi.webgl_export(export_func: ExporterProtocol) ExporterProtocol

Webgl exporter for offscreen rendering

Parameters:

export_func (ExporterProtocol)

Return type:

ExporterProtocol

bluemira.codes._freecadapi.stepz_import(import_func: ImporterProtocol) ImporterProtocol

Step z importer “needs” more FreeCADGui so we’re patching it out

Parameters:

import_func (ImporterProtocol)

Return type:

ImporterProtocol

bluemira.codes._freecadapi.meshed_exporter(cad_format: CADFileType, export_func: ExporterProtocol) ExporterProtocol

Meshing and then exporting CAD in certain formats.

Parameters:
Return type:

ExporterProtocol

bluemira.codes._freecadapi.save_as_STP(shapes: list[apiShape], filename: str = 'test')

Saves a series of Shape objects as a STEP assembly

Parameters:
  • shapes (list[apiShape]) – Iterable of shape objects to be saved

  • filename (str) – Full path filename of the STP assembly

Raises:

FreeCADError – Shape is null

Notes

This uses the legacy method to save to STP files. It doesn’t require freecad documents but also doesn’t allow much customisation. Part builds in millimetres therefore we need to scale to metres to be consistent with our units.

bluemira.codes._freecadapi._scale_obj(objs, scale: float = 1000)

Scale objects

Notes

Since the scale function modifies directly the shape, a copy of the shape is made to avoid modification of the original shapes. The scale of Part is in mm by default therefore we scale by 1000 to convert to metres.

Parameters:

scale (float)

bluemira.codes._freecadapi.save_cad(shapes: collections.abc.Iterable[apiShape], filename: str, cad_format: str | CADFileType = 'stp', labels: collections.abc.Iterable[str] | None = None, doc_name: str = 'Bluemira_FreeCAD_wrapper', **kwargs)

Save CAD in a given file format

Parameters:
  • shapes (collections.abc.Iterable[apiShape]) – CAD shape objects to save

  • filename (str) – filename (file extension will be forced base on cad_format)

  • cad_format (str | CADFileType) – file cad_format

  • labels (collections.abc.Iterable[str] | None) – shape labels

  • kwargs – passed to freecad preferences configuration

  • doc_name (str)

Raises:

FreeCADError – Unable to save to format

Notes

Part builds in millimetres therefore we need to scale to metres to be consistent with our units

bluemira.codes._freecadapi.scale_shape(shape: apiShape, factor: float) apiShape

Apply scaling with factor to the shape

Parameters:
  • shape (apiShape) – The shape to be scaled

  • factor (float) – The scaling factor

Returns:

The scaled shape

Return type:

apiShape

bluemira.codes._freecadapi.translate_shape(shape: apiShape, vector: tuple[float, float, float]) apiShape

Apply scaling with factor to the shape

Parameters:
  • shape (apiShape) – The shape to be scaled

  • vector (tuple[float, float, float]) – The translation vector

Returns:

The translated shape

Return type:

apiShape

bluemira.codes._freecadapi.rotate_shape(shape: apiShape, base: tuple[float, float, float] = (0.0, 0.0, 0.0), direction: tuple[float, float, float] = (0.0, 0.0, 1.0), degree: float = 180) apiShape

Apply the rotation (base, dir, degree) to this shape

Parameters:
  • shape (apiShape) – The shape to be rotated

  • base (tuple[float, float, float]) – Origin location of the rotation

  • direction (tuple[float, float, float]) – The direction vector

  • degree (float) – rotation angle

Returns:

The rotated shape

Return type:

apiShape

bluemira.codes._freecadapi.mirror_shape(shape: apiShape, base: tuple[float, float, float], direction: tuple[float, float, float]) apiShape

Mirror a shape about a plane.

Parameters:
  • shape (apiShape) – Shape to mirror

  • base (tuple[float, float, float]) – Mirror plane base point

  • direction (tuple[float, float, float]) – Mirror plane direction

Returns:

The mirrored shape

Return type:

apiShape

bluemira.codes._freecadapi.revolve_shape(shape: apiShape, base: tuple[float, float, float] = (0.0, 0.0, 0.0), direction: tuple[float, float, float] = (0.0, 0.0, 1.0), degree: float = 180.0) apiShape

Apply the revolve (base, dir, degree) to this shape

Parameters:
  • shape (apiShape) – The shape to be revolved

  • base (tuple[float, float, float]) – Origin location of the revolution

  • direction (tuple[float, float, float]) – The direction vector

  • degree (float) – revolution angle

Returns:

The revolved shape.

Return type:

apiShape

bluemira.codes._freecadapi.extrude_shape(shape: apiShape, vec: tuple[float, float, float]) apiShape

Apply the extrusion along vec to this shape

Parameters:
  • shape (apiShape) – The shape to be extruded

  • vec (tuple[float, float, float]) – The vector along which to extrude

Returns:

The extruded shape.

Return type:

apiShape

bluemira.codes._freecadapi._split_wire(wire)

Split a wire into two parts at mid point or middle edge.

Returns:

  • The first split

  • The second split

bluemira.codes._freecadapi.sweep_shape(profiles: collections.abc.Iterable[apiWire], path: apiWire, *, solid: bool = True, frenet: bool = True, transition: int = 0) apiShell | apiSolid

Sweep a a set of profiles along a path.

Parameters:
  • profiles (collections.abc.Iterable[apiWire]) – Set of profiles to sweep

  • path (apiWire) – Path along which to sweep the profiles

  • solid (bool) – Whether or not to create a Solid

  • frenet (bool) – If true, the orientation of the profile(s) is calculated based on local curvature and tangency. For planar paths, should not make a difference.

  • transition (int)

Returns:

Swept geometry object

Raises:

FreeCADError – Wires must be all open or all closed and edges must be consecutively tangent

Return type:

apiShell | apiSolid

bluemira.codes._freecadapi.loft(profiles: collections.abc.Iterable[apiWire], *, solid: bool = False, ruled: bool = False, closed: bool = False) apiShell | apiSolid

Loft between a set of profiles.

Parameters:
  • profiles (collections.abc.Iterable[apiWire]) – Profile(s) to loft between

  • solid (bool) – Whether or not to create a Solid

  • ruled (bool) – Create a ruled shape

  • closed (bool)

Return type:

Lofted geometry object

bluemira.codes._freecadapi.fillet_wire_2D(wire: apiWire, radius: float, *, chamfer: bool = False) apiWire

Fillet or chamfer a two-dimensional wire, returning a new wire

Parameters:
  • wire (apiWire) – Wire to be filleted or chamfered

  • radius (float) – Radius of the fillet or chamfer operation

  • chamfer (bool (default=False)) – Whether to chamfer or not

Return type:

Resulting filleted or chamfered wire

bluemira.codes._freecadapi.join_connect(shapes: collections.abc.Iterable[apiShape], dist_tolerance: float) apiShape

Connects the interiors of two walled objects (e.g. pipes). It can also join shells and wires.

Returns:

Result of the join connect operation.

Raises:
  • FreeCADError – In case the boolean operation fails.

  • TypeError – Shapes must be in a list

  • ValueError – At least 2 shapes must be given

Parameters:
  • shapes (collections.abc.Iterable[apiShape])

  • dist_tolerance (float)

Return type:

apiShape

Notes

See https://wiki.freecad.org/Part_JoinConnect

bluemira.codes._freecadapi.boolean_fuse(shapes: collections.abc.Iterable[apiShape], *, remove_splitter: bool = True) apiShape

Fuse two or more shapes together. Internal splitter are removed.

Parameters:
  • shapes (collections.abc.Iterable[apiShape]) – List of FreeCAD shape objects to be fused together. All the objects in the list must be of the same type.

  • remove_splitter (bool) – if True, shape is refined removing extra edges. See(https://wiki.freecadweb.org/Part_RefineShape)

Return type:

Result of the boolean operation.

Raises:
  • FreeCADError – In case the boolean operation fails.

  • TypeError – Shapes must be in a list

  • ValueError – At least 2 shapes must be given

bluemira.codes._freecadapi.boolean_cut(shape: apiShape, tools: list[apiShape], *, split: bool = True) list[apiShape]

Difference of shape and a given (list of) topo shape cut(tools)

Parameters:
  • shape (apiShape) – the reference object

  • tools (list[apiShape]) – List of FreeCAD shape objects to be used as tools.

  • split (bool) – If True, shape is split into pieces based on intersections with tools.

Return type:

Result of the boolean operation.

bluemira.codes._freecadapi.boolean_fragments(shapes: list[apiSolid], tolerance: float = 0.0) tuple[apiCompound, list[apiSolid]]

Split a list of shapes into their Boolean fragments.

Parameters:
  • shapes (list[apiSolid]) – List of BluemiraSolids to be split into Boolean fragments

  • tolerance (float) – Tolerance with which to perform the operation

Returns:

  • compound – A compound of the unique fragments

  • fragment_map – An ordered list of groups of solid Boolean fragments (ordered in terms of input ordering)

Raises:

FreeCADError – Boolean operation failed

Return type:

tuple[apiCompound, list[apiSolid]]

bluemira.codes._freecadapi.point_inside_shape(point: collections.abc.Iterable[float], shape: apiShape) bool

Whether or not a point is inside a shape.

Parameters:
  • point (collections.abc.Iterable[float]) – Coordinates of the point

  • shape (apiShape) – Geometry to check with

Returns:

Whether or not the point is inside the shape

Return type:

bool

bluemira.codes._freecadapi._edges_tangent(edge_1, edge_2) bool

Check if two adjacent edges are tangent to one another.

Return type:

bool

bluemira.codes._freecadapi._wire_edges_tangent(wire) bool

Check that all consecutive edges in a wire are tangent

Return type:

bool

bluemira.codes._freecadapi._wire_is_planar(wire) bool

Check if a wire is planar.

Return type:

bool

bluemira.codes._freecadapi._wire_is_straight(wire) bool

Check if a wire is a straight line.

Return type:

bool

bluemira.codes._freecadapi._is_wire_or_face(shape_type)
bluemira.codes._freecadapi._check_shapes_same_type(shapes)

Check that all the shapes are of the same type.

Raises:

ValueError – shapes must all be the same type

bluemira.codes._freecadapi._check_shapes_coplanar(shapes)
bluemira.codes._freecadapi._shapes_are_coplanar(shapes) bool

Check if a list of shapes are all coplanar. First shape is taken as the reference.

Return type:

bool

bluemira.codes._freecadapi._shapes_are_coaxis(shapes) bool

Check if a list of shapes are all co-axis. First shape is taken as the reference.

Return type:

bool

bluemira.codes._freecadapi._make_shapes_coaxis(shapes)

Make a list of shapes co-axis by reversing. First shape is taken as the reference.

bluemira.codes._freecadapi.fix_shape(shape: apiShape, precision: float = EPS_FREECAD, min_length: float = MINIMUM_LENGTH)

Fix a shape by removing any small edges and joining the remaining edges.

Parameters:
  • shape (apiShape) – Shape to fix

  • precision (float) – General precision with which to work

  • min_length (float) – Minimum edge length

bluemira.codes._freecadapi.make_placement(base: collections.abc.Iterable[float], axis: collections.abc.Iterable[float], angle: float) apiPlacement

Make a FreeCAD Placement

Parameters:
  • base (Iterable) – a vector representing the Placement local origin

  • axis (Iterable) – axis of rotation

  • angle (float) – rotation angle in degree

Return type:

apiPlacement

bluemira.codes._freecadapi.make_placement_from_matrix(matrix: numpy.ndarray) apiPlacement

Make a FreeCAD Placement from a 4 x 4 matrix.

Parameters:

matrix (numpy.ndarray) – 4 x 4 matrix from which to make the placement

Raises:

FreeCADError – Must be 4x4 matrix

Return type:

apiPlacement

Notes

Matrix should be of the form:

[cos_11, cos_12, cos_13, dx] [cos_21, cos_22, cos_23, dy] [cos_31, cos_32, cos_33, dz] [ 0, 0, 0, 1]

bluemira.codes._freecadapi.move_placement(placement: apiPlacement, vector: collections.abc.Iterable[float])

Moves the FreeCAD Placement along the given vector

Parameters:
  • placement (apiPlacement) – the FreeCAD placement to be modified

  • vector (collections.abc.Iterable[float]) – direction along which the placement is moved

bluemira.codes._freecadapi.make_placement_from_vectors(base: collections.abc.Iterable[float] = [0, 0, 0], vx: collections.abc.Iterable[float] = [1, 0, 0], vy: collections.abc.Iterable[float] = [0, 1, 0], vz: collections.abc.Iterable[float] = [0, 0, 1], order: str = 'ZXY') apiPlacement

Create a placement from three directional vectors

Parameters:
  • base (collections.abc.Iterable[float])

  • vx (collections.abc.Iterable[float])

  • vy (collections.abc.Iterable[float])

  • vz (collections.abc.Iterable[float])

  • order (str)

Return type:

apiPlacement

bluemira.codes._freecadapi.change_placement(geo: apiShape, placement: apiPlacement)

Change the placement of a FreeCAD object

Parameters:
  • geo (apiShape) – the object to be modified

  • placement (apiPlacement) – the FreeCAD placement to be modified

bluemira.codes._freecadapi.make_plane(base: tuple[float, float, float] = (0.0, 0.0, 0.0), axis: tuple[float, float, float] = (0.0, 0.0, 1.0)) apiPlane

Creates a FreeCAD plane with a given location and normal

Parameters:
  • base (tuple[float, float, float]) – a reference point in the plane

  • axis (tuple[float, float, float]) – normal vector to the plane

Return type:

Plane from base and axis

bluemira.codes._freecadapi.make_plane_from_3_points(point1: tuple[float, float, float] = (0.0, 0.0, 0.0), point2: tuple[float, float, float] = (1.0, 0.0, 0.0), point3: tuple[float, float, float] = (0.0, 1.0, 0.0)) apiPlane

Creates a FreeCAD plane defined by three non-linear points

Parameters:
  • point1 (tuple[float, float, float]) – a reference point in the plane

  • point2 (tuple[float, float, float]) – a reference point in the plane

  • point3 (tuple[float, float, float]) – a reference point in the plane

Return type:

Plane from three points

bluemira.codes._freecadapi.face_from_plane(plane: apiPlane, width: float, height: float) apiFace

Creates a FreeCAD face from a Plane with specified height and width.

Note

Face is centred on the Plane Position. With respect to the global coordinate system, the face placement is given by a simple rotation of the z axis.

Parameters:
  • plane (apiPlane) – the reference plane

  • width (float) – output face width

  • height (float) – output face height

Returns:

Face from plane

Return type:

apiFace

bluemira.codes._freecadapi.plane_from_shape(shape: apiShape) apiPlane
Returns:

A plane if the shape is planar

Parameters:

shape (apiShape)

Return type:

apiPlane

bluemira.codes._freecadapi.placement_from_plane(plane: apiPlane) apiPlacement
Returns:

A placement from a plane with the origin on the plane base and the z-axis directed as the plane normal.

Parameters:

plane (apiPlane)

Return type:

apiPlacement

bluemira.codes._freecadapi._colourise(node: pivy.coin.SoNode, options: dict)
Parameters:
  • node (pivy.coin.SoNode)

  • options (dict)

bluemira.codes._freecadapi.collect_verts_faces(solid: apiShape, tesselation: float = 0.1) tuple[numpy.ndarray | None, Ellipsis]

Collects vertices and faces of parts and tessellates them for the CAD viewer

Parameters:
  • solid (apiShape) – FreeCAD Part

  • tesselation (float) – amount of tessellation for the mesh

Returns:

  • vertices – Vertices

  • faces – Faces

Return type:

tuple[numpy.ndarray | None, Ellipsis]

bluemira.codes._freecadapi.collect_wires(solid: apiShape, **kwds) tuple[numpy.ndarray, numpy.ndarray]

Collects vertices and edges of parts and discretises them for the CAD viewer

Parameters:

solid (apiShape) – FreeCAD Part

Returns:

  • vertices – Vertices

  • edges – Edges

Return type:

tuple[numpy.ndarray, numpy.ndarray]

class bluemira.codes._freecadapi.DefaultDisplayOptions

Freecad default display options

colour: bluemira.utilities.tools.ColourDescriptor
transparency: float = 0.0
property color: str

See colour

Return type:

str

bluemira.codes._freecadapi.show_cad(parts: apiShape | list[apiShape], options: dict | list[dict | None] | None = None, labels: list[str] | None = None, camera_rotation: collections.abc.Iterable[float] = (90, 0, 0), **kwargs)

The implementation of the display API for FreeCAD parts.

Parameters:
  • parts (apiShape | list[apiShape]) – The parts to display.

  • options (dict | list[dict | None] | None) – The options to use to display the parts.

  • labels (list[str] | None) – labels to use for each part object

  • camera_rotation (collections.abc.Iterable[float]) – rotation in degrees of camera around object, Default looks at the bluemira xz plane.

Raises:

FreeCADError – Number of parts and options must be equal

bluemira.codes._freecadapi.rotate_into_position(scene: pivy.quarter.QuarterWidget, x_ang: float, y_ang: float, z_ang: float)

Rotate camera around object

Parameters:
  • scene (pivy.quarter.QuarterWidget)

  • x_ang (float)

  • y_ang (float)

  • z_ang (float)

bluemira.codes._freecadapi.embedLight(scene, lightdir: tuple[float], intensity: float) pivy.coin.SoSeparator

Embeds a given coin node inside a shadow group with directional light with the given direction (x,y,z) tuple.

Returns:

the final coin node

Parameters:
  • lightdir (tuple[float])

  • intensity (float)

Return type:

pivy.coin.SoSeparator

Notes

Modified from BIM.OfflineRendingerUtils::embedLight

bluemira.codes._freecadapi.extract_attribute(func)

Decorator for serialise_shape. Convert the function output attributes string list to the corresponding object attributes.

The first argument of func is the reference object.

Returns:

If an output is callable, the output result is returned.

bluemira.codes._freecadapi.serialise_shape(shape)

Serialise a FreeCAD topological data object.

Returns:

The json-ified shape

bluemira.codes._freecadapi.deserialise_shape(buffer)

Deserialise a FreeCAD topological data object obtained from serialise_shape.

Parameters:

buffer – Object serialisation as stored by serialise_shape

Returns:

The deserialised FreeCAD object

Raises:

FreeCADError – Wrapping the OCCError: BRep not done in a more understandable message.

bluemira.codes._freecadapi._convert_edge_to_curve(edge: apiEdge) Part.LineSegment | Part.Circle | Part.ArcOfCircle | Part.Ellipse | Part.ArcOfEllipse | Part.BezierCurve | Part.BSplineCurve

Convert a Freecad Edge to the respective curve.

Parameters:

edge (apiEdge) – FreeCAD Edge, where type(edge.Curve) is one of the following: 1. Part.Line 2. Part.Circle 3. Part.Ellipse 4. Part.BezierCurve 5. Part.BSplineCurve 6. Part.OffsetCurve

Returns:

FreeCAD Part curve object, corresponding to the input type: 1. Part.Line -> Part.LineSegment 2. Part.Circle -> Part.ArcOfCircle 3. Part.ellipse -> Part.ArcOfEllipse 4. Part.BezierCurve -> Part.BezierCurve 5. Part.BSplineCurve-> Part.BSplineCurve 6. Part.OffsetCurve -> Part.BSplineCurve

Return type:

Part.LineSegment | Part.Circle | Part.ArcOfCircle | Part.Ellipse | Part.ArcOfEllipse | Part.BezierCurve | Part.BSplineCurve