Example #1
0
 def __init__(self, shape, edges=True, faces=True, bsplines=False):
     from OCC.Core.ShapeUpgrade import ShapeUpgrade_UnifySameDomain
     tool = ShapeUpgrade_UnifySameDomain(shape.object, edges, faces,
                                         bsplines)
     tool.Build()
     self._shape = Shape.wrap(tool.Shape())
     self._history = tool.History()
Example #2
0
 def sewed_shape(self):
     """
     :return: The sewed shape. May be a null shape if nothing is
         constructed.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._tool.SewedShape())
Example #3
0
    def __init__(self,
                 shape,
                 to_project,
                 tol3d=1.0e-4,
                 tol2d=None,
                 continuity=Geometry.C2,
                 max_degree=14,
                 max_seg=16,
                 max_dist=None,
                 limit=True):
        tool = BRepOffsetAPI_NormalProjection(shape.object)

        if tol2d is None:
            tol2d = sqrt(tol3d)

        tool.SetParams(tol3d, tol2d, continuity, max_degree, max_seg)

        if max_dist is not None:
            tool.SetMaxDistance(max_dist)

        if limit:
            tool.SetLimit(True)

        for item in to_project:
            tool.Add(item.object)

        tool.Build()
        self._tool = tool
        self._projection = Shape.wrap(self._tool.Projection())
        self._wires = self._projection.wires
        self._edges = self._projection.edges
Example #4
0
 def first_shape(self):
     """
     :return: The first/bottom shape of the loft if a solid was
         constructed.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._tool.FirstShape())
Example #5
0
    def __init__(self,
                 faces,
                 tol=None,
                 cut_free_edges=False,
                 non_manifold=False):
        if tol is None:
            tol = max([f.tol_max for f in faces])

        builder = BRepBuilderAPI_Sewing(tol, True, True, cut_free_edges,
                                        non_manifold)
        for f in faces:
            builder.Add(f.object)
        builder.Perform()

        shape = Shape.wrap(builder.SewedShape())
        self._shells = []
        self._shell = None
        self._nshells = 0
        if shape.is_compound:
            self._shells = shape.shells
            self._nshells = len(self._shells)
        elif shape.is_face:
            self._shell = shape.to_shell()
            self._nshells = 1
        elif shape.is_shell:
            self._shell = shape
            self._nshells = 1
        else:
            raise RuntimeError('Invalid shape type in ShellBySewing.')
Example #6
0
 def __init__(self, shape, tol=0.001, continuity=Geometry.C1):
     tool = ShapeUpgrade_ShapeDivideContinuity(shape.object)
     tool.SetTolerance(tol)
     tool.SetBoundaryCriterion(continuity)
     tool.SetPCurveCriterion(continuity)
     tool.SetSurfaceCriterion(continuity)
     tool.Perform()
     self._shape = Shape.wrap(tool.Result())
Example #7
0
    def apply(self):
        """
        Apply the substitutions to the original old shape and return a new
        shape.

        :return: The new shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.Apply(self._old_shape.object))
Example #8
0
    def shape(self):
        """
        :Getter: The shape of the group.
        :Setter: Set the group shape.
        :type: afem.topology.entities.Shape

        :raise AttributeError: If the group is not associated with a shape.
        """
        return Shape.wrap(self._ds.GetShape())
Example #9
0
    def support_on_shape2(self, n=1):
        """
        Get the shape where the *n-th* solution is on the second shape.

        :param int n: The index.

        :return: The support shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.SupportOnShape2(n))
Example #10
0
    def modified_subshape(self, subshape):
        """
        Get a modified sub-shape.

        :param afem.topology.entities.Shape subshape: The sub-shape.

        :return: The modified sub-shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.ModifiedSubShape(subshape.object))
Example #11
0
    def modified_shape(self, shape):
        """
        Return the modified shape corresponding to the given shape.

        :param afem.topology.entities.Shape shape: A shape.

        :return: The modified shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._modifier.ModifiedShape(shape))
Example #12
0
File: xde.py Project: trelau/AFEM
 def shape(self):
     """
     :return: The label shape.
     :rtype: afem.topology.entities.Shape or None
     """
     shape = TNaming_NamedShape()
     status, shape = self._label.FindAttribute(shape.GetID_(), shape)
     if status:
         return Shape.wrap(shape.Get())
     return None
Example #13
0
    def index_to_shape(self, indx):
        """
        Get the shape from an index.

        :param int indx: The index.

        :return: The shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._ds.IndexToShape(indx))
Example #14
0
    def apply(self, shape):
        """
        Apply substitutions to the shape (or sub-shape) and get the result.

        :param afem.topology.entities.Shape shape: The shape.

        :return: The new shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self.context.Apply(shape.object))
Example #15
0
    def generated_face(self, edge):
        """
        Get a face(s) generated by the edge. If the ruled option was used,
        then this returns each face generated by the edge. If the smoothing
        option was used, then this returns the face generated by the edge.

        :param afem.topology.entities.Edge edge: The edge.

        :return: The face(s) generated by the edge.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.GeneratedFace(edge.object))
Example #16
0
    def shape_by_hypothesis(hyp, shape, mesh):
        """
        Get a shape the hypothesis is applied to.

        :param afem.smesh.hypotheses.Hypothesis hyp: The hypothesis.
        :param afem.topology.entities.Shape shape: The shape.
        :param afem.smesh.meshes.Mesh mesh: The mesh.

        :return: The shape that the hypothesis is applied to.
        :rtype: afem.topology.entities.Shape
        """
        h, s, m = hyp.object, shape.object, mesh.object
        return Shape.wrap(SMESH_MesherHelper.GetShapeOfHypothesis_(h, s, m))
Example #17
0
    def subshape_by_node(node, mesh_ds):
        """
        Get the support shape of a node.

        :param afem.smesh.entities.Node node: The node.
        :param afem.smesh.meshes.MeshDS mesh_ds: The mesh data structure.

        :return: The support shape.
        :rtype: afem.topology.entities.Shape
        """
        n, m = node.object, mesh_ds.object
        shape = Shape.wrap(SMESH_MesherHelper.GetSubShapeByNode_(n, m))
        return shape
Example #18
0
    def __init__(self, shape, offset, tol=None, join_mode=Geometry.ARC,
                 remove_internal_edges=False, perform_simple=False):
        if tol is None:
            tol = shape.tol_avg

        self._tool = BRepOffsetAPI_MakeOffsetShape()
        if perform_simple:
            self._tool.PerformBySimple(shape.object, offset)
        else:
            self._tool.PerformByJoin(shape.object, offset, tol,
                                     BRepOffset_Skin, False, False, join_mode,
                                     remove_internal_edges)

        self._shape = Shape.wrap(self._tool.Shape())
Example #19
0
def read_brep(fn):
    """
    Read a BREP file and return the shape.

    :param str fn: The filename.

    :return: The shape.
    :rtype: afem.topology.entities.Shape
    """
    shape = TopoDS_Shape()
    builder = BRep_Builder()
    BRepTools.Read_(shape, fn, builder)

    return Shape.wrap(shape)
Example #20
0
    def new_shape(self, old_shape):
        """
        Get the new shape from the old shape.

        :param afem.topology.entities.Shape old_shape: The old shape provided
            in the initial inputs.

        :return: The new shape after substitutions.
        :rtype: afem.topology.entities.Shape

        :raises RuntimeError: If the old shape is not a key in the final
            results.
        """
        return Shape.wrap(self._new_shapes.Find(old_shape.object))
Example #21
0
    def __init__(self, fn):
        self._reader = IGESControl_Reader()

        # Read file
        status = self._reader.ReadFile(fn)
        if status != IFSelect_RetDone:
            raise RuntimeError("Error reading IGES file.")

        # Convert to desired units
        Interface_Static.SetCVal("xstep.cascade.unit", Settings.units)

        # Transfer
        nroots = self._reader.TransferRoots()
        if nroots > 0:
            self._shape = Shape.wrap(self._reader.OneShape())
Example #22
0
    def common_ancestor(shape1, shape2, mesh, ancestor_type=Shape.EDGE):
        """
        Get a common ancestor between the two shapes.

        :param afem.topology.entities.Shape shape1: The first shape.
        :param afem.topology.entities.Shape shape2: The second shape.
        :param afem.smesh.meshes.Mesh mesh: The mesh.
        :param OCCT.TopAbs.TopAbs_ShapeEnum ancestor_type: The shape type.

        :return: The common ancestor.
        :rtype: afem.topology.entities.Edge
        """
        s1, s2, m = shape1.object, shape2.object, mesh.object
        e = Shape.wrap(SMESH_MesherHelper.GetCommonAncestor_(s1, s2, m,
                                                             ancestor_type))
        return e
Example #23
0
def translate_shape(shape, vec):
    """
    Translate a shape along a vector.

    :param afem.topology.entities.Shape shape: The shape.
    :param Union[afem.geometry.entitites.Vector, Sequence] vec: The vector.

    :return: The translated shape.
    :rtype: afem.topology.entities.Shape

    :raise RuntimeError: If the translation fails or is not done.
    """
    trsf = gce_MakeTranslation(vec.gp_vec).Value()
    builder = BRepBuilderAPI_Transform(shape.object, trsf, True)
    if not builder.IsDone():
        raise RuntimeError('Failed to mirror the shape.')
    return Shape.wrap(builder.Shape())
Example #24
0
def mirror_shape(shape, pln):
    """
    Mirror a shape about a plane.

    :param afem.topology.entities.Shape shape: The shape.
    :param afem.geometry.entities.Plane pln: The plane.

    :return: The mirrored shape.
    :rtype: afem.topology.entities.Shape

    :raise RuntimeError: If the transformation fails or is not done.
    """
    trsf = gce_MakeMirror(pln.gp_pln).Value()
    builder = BRepBuilderAPI_Transform(shape.object, trsf, True)
    if not builder.IsDone():
        raise RuntimeError('Failed to mirror the shape.')
    return Shape.wrap(builder.Shape())
Example #25
0
File: xde.py Project: trelau/AFEM
    def read_step(self, fn):
        """
        Read and translate a STEP file.

        :param str fn: The filename.

        :return: The shapes label.
        :rtype: afem.exchange.xde.Label.

        :raise RuntimeError: If the file cannot be read.
        """
        reader = STEPCAFControl_Reader()
        reader.SetNameMode(True)
        reader.SetColorMode(True)
        status = reader.Perform(fn, self._doc)
        if not status:
            raise RuntimeError("Error reading STEP file.")

        self._shape = Shape.wrap(reader.Reader().OneShape())
        label = XCAFDoc_DocumentTool.ShapesLabel_(self._doc.Main())
        return XdeLabel(label)
Example #26
0
    def __init__(self, old_shapes, tool):
        reshape = ShapeBuild_ReShape()

        self._new_shapes = TopTools_DataMapOfShapeShape()
        index_map = TopTools_IndexedMapOfShape()

        for old_shape in old_shapes:
            # Old shapes
            shapes = old_shape.faces
            if not shapes:
                shapes = old_shape.edges
            if not shapes:
                shapes = old_shape.vertices
            if not shapes:
                continue

            # Delete and replace
            for shape in shapes:
                # Deleted
                if tool.is_deleted(shape):
                    reshape.Remove(shape.object)
                    continue

                # Modified considering shapes already used
                mod_shapes = tool.modified(shape)
                replace_shapes = []
                for mod_shape in mod_shapes:
                    if index_map.Contains(mod_shape.object):
                        continue
                    replace_shapes.append(mod_shape)
                    index_map.Add(mod_shape.object)

                if replace_shapes:
                    new_shape = Compound.by_shapes(replace_shapes)
                    reshape.Replace(shape.object, new_shape.object)

            new_shape = Shape.wrap(reshape.Apply(old_shape.object))
            self._new_shapes.Bind(old_shape.object, new_shape.object)
Example #27
0
 def last_vertex(self):
     """
     :return: Last vertex of side.
     :rtype: afem.topology.entities.Vertex
     """
     return Shape.wrap(self._fside.LastVertex())
Example #28
0
 def edges(self):
     """
     :return: List of side edges.
     :rtype: list(afem.topology.entities.Edge)
     """
     return [Shape.wrap(e) for e in self._fside.Edges()]
Example #29
0
 def shape(self):
     """
     :return: The shape to mesh.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._mesh.GetShapeToMesh())
Example #30
0
 def __init__(self, shape):
     tool = ShapeUpgrade_ShapeDivideClosed(shape.object)
     tool.Perform()
     self._shape = Shape.wrap(tool.Result())