Example #1
0
File: join.py Project: trelau/AFEM
    def __init__(self, groups, fuzzy_val=None, include_subgroup=True):
        if len(groups) < 2:
            raise ValueError('Not enough groups to fuse. Need at least '
                             'two.')

        bop = FuseShapes(fuzzy_val=fuzzy_val)

        groups = list(groups)
        parts1 = groups[0].get_parts(include_subgroup)
        shapes1 = [part.shape for part in parts1]
        shape1 = CompoundByShapes(shapes1).compound
        bop.set_args([shape1])

        tools = []
        other_parts = []
        for group in groups[1:]:
            parts = group.get_parts(include_subgroup)
            other_parts += parts
            shapes = [part.shape for part in parts]
            shape = CompoundByShapes(shapes).compound
            tools.append(shape)
        bop.set_tools(tools)

        bop.build()

        all_parts = parts1 + other_parts
        all_shapes = [part.shape for part in all_parts]
        rebuild = RebuildShapesByTool(all_shapes, bop)
        for part in all_parts:
            new_shape = rebuild.new_shape(part.shape)
            part.set_shape(new_shape)

        self._bop = bop
Example #2
0
    def fuse(self, *other_parts):
        """
        Fuse with other surface parts and rebuild both.

        :param afem.structure.entities.SurfacePart other_parts: The other
            part(s).

        :return: *True* if fused, *False* if not.
        :rtype: bool
        """
        # Putting the other parts in a compound avoids fusing them to each
        # other
        other_shapes = [part.shape for part in other_parts]
        other_compound = CompoundByShapes(other_shapes).compound

        fuse = FuseShapes(self._shape, other_compound)
        if not fuse.is_done:
            return False

        # Rebuild the part shapes
        parts = [self] + list(other_parts)
        shapes = [part.shape for part in parts]
        rebuild = RebuildShapesByTool(shapes, fuse)
        for part in parts:
            new_shape = rebuild.new_shape(part.shape)
            part.set_shape(new_shape)

        return True
Example #3
0
    def build(self, pln=None, scale=None, rotate=None):
        """
        Build a shape in 3-D using the 2-D cross section curves. This method
        collects the 2-D curves, converts them into 3-D edges on the plane,
        fuses them together, and attempts to build wires and a face if
        applicable.

        :param pln: The plane to build on. If *None*, then the default plane
            is used.
        :param float scale: Scale the 3-D curve after construction on the
            plane. The reference point is the plane origin.
        :param float rotate: Rotate the 3-D curve after construction on the
            plane. The reference point is the plane origin.

        :return: *True* if successful, *False* otherwise.
        :rtype: bool
        """
        if pln is None:
            pln = self._pln
        if pln is None:
            raise RuntimeError('No plane is defined.')
        origin = pln.origin
        axis = pln.axis

        edges = []
        for c2d in self._crvs:
            c3d = c2d.to_3d(pln)
            if scale is not None:
                c3d.scale(origin, scale)
            if rotate is not None:
                c3d.rotate(axis, rotate)
            e = Edge.by_curve(c3d)
            edges.append(e)

        if len(edges) == 0:
            return False

        if len(edges) == 1:
            self._shape = edges[0]
        else:
            # Fuse the shape
            fuse = FuseShapes()
            fuse.set_args(edges[:-1])
            fuse.set_tools(edges[-1:])
            fuse.build()
            self._shape = fuse.shape
            edges = fuse.edges

        # Try and make wire(s)
        self._wire_tool = WiresByConnectedEdges(edges)

        # Try to make a face if one wire was created
        if self.nwires == 1:
            self._face = FaceByPlanarWire(self.wires[0]).face

        return True
Example #4
0
File: join.py Project: trelau/AFEM
    def __init__(self, parts, tools, fuzzy_val=None):
        bop = FuseShapes(fuzzy_val=fuzzy_val)

        parts = list(parts)
        other_parts = list(tools)
        args = [part.shape for part in parts]
        bop.set_args(args)
        tools = [part.shape for part in tools]
        bop.set_tools(tools)
        bop.build()

        rebuild = RebuildShapesByTool(args + tools, bop)
        for part in parts + other_parts:
            new_shape = rebuild.new_shape(part.shape)
            part.set_shape(new_shape)

        self._is_done = bop.is_done
        self._fused_shape = bop.shape
Example #5
0
    def merge(self, other, unify=False):
        """
        Merge other surface part or shape with this one.

        :param other: The other part or shape.
        :type other: afem.structure.entities.SurfacePart or
            afem.topology.entities.Shape
        :param bool unify: Option to attempt to unify same domains.

        :return: *True* if merged, *False* if not.
        :rtype: bool
        """
        # Fuse the parts
        fuse = FuseShapes(self._shape, other)
        if not fuse.is_done:
            return False

        # Reset the shape
        self.set_shape(fuse.shape)

        # Unify if possible
        if not unify:
            return True
        return self.unify()