コード例 #1
0
    def __init__(self, shapes):
        results = []
        for shape in shapes:
            shape = Shape.to_shape(shape)
            ls = LinearProps(shape).length
            results.append((ls, shape))

        results.sort(key=lambda tup: tup[0])
        self._lengths = [data[0] for data in results]
        self._shapes = [data[1] for data in results]
コード例 #2
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.
        """
        if not self._on_shape:
            raise AttributeError("Group is not associated to a shape.")
        return Shape.wrap(self._ds.GetShape())
コード例 #3
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))
コード例 #4
0
ファイル: utils.py プロジェクト: gitter-badger/AFEM
    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
コード例 #5
0
ファイル: utils.py プロジェクト: gitter-badger/AFEM
    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))
コード例 #6
0
    def __init__(self, spine, profile):
        if isinstance(spine, Curve):
            spine = Wire.by_curve(spine)
        elif spine.is_edge:
            spine = Wire.by_edge(spine)

        if not spine.is_wire:
            raise TypeError('Spine is not a wire.')

        profile = Shape.to_shape(profile)
        self._tool = BRepOffsetAPI_MakePipe(spine.object, profile.object)

        self._tool.Build()
コード例 #7
0
    def trim_u2(self, entity):
        """
        Trim the last parameter of the reference curve by interesting it with
        the entity.

        :param entity: The entity.
        :type entity: afem.geometry.entities.Geometry or
            afem.topology.entities.Shape

        :return: None.

        :raise RuntimeError: If an intersection with the reference curve cannot
            be found.
        """
        shape1 = Shape.to_shape(self.cref)
        shape2 = Shape.to_shape(entity)
        bop = IntersectShapes(shape1, shape2)
        if not bop.is_done:
            raise RuntimeError('Failed to intersect reference curve.')

        pnts = [v.point for v in bop.vertices]
        p = CheckGeom.nearest_point(self.cref.p2, pnts)
        self.set_p2(p)
コード例 #8
0
ファイル: brep.py プロジェクト: gitter-badger/AFEM
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)
コード例 #9
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())
コード例 #10
0
ファイル: modify.py プロジェクト: sanderboer/AFEM
    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))
コード例 #11
0
 def section_edges(self):
     """
     :return: A list of section edges as a result of intersection between
         the shapes.
     :rtype: list(afem.topology.entities.Edge)
     """
     if isinstance(self._bop, (BRepAlgoAPI_Splitter, BOPAlgo_MakerVolume,
                               BRepFeat_MakeCylindricalHole)):
         n = self._bop.__class__.__name__
         msg = ('Getting section edges not available for {}. '
                'Returning an empty list.'.format(n))
         logger.warn(msg)
         return []
     else:
         return Shape.from_topods_list(self._bop.SectionEdges())
コード例 #12
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())
コード例 #13
0
ファイル: utils.py プロジェクト: gitter-badger/AFEM
    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
コード例 #14
0
ファイル: transform.py プロジェクト: jasoncorman/AFEM
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())
コード例 #15
0
ファイル: transform.py プロジェクト: jasoncorman/AFEM
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())
コード例 #16
0
ファイル: utils.py プロジェクト: sanderboer/AFEM
def shape_of_entity(entity):
    """
    Get the shape of the entity. This method is useful if method inputs can
    either be a part or a shape. If the entity is already a shape it will be
    returned. If the entity is part the shape of the part will be returned. If
    the entity is a curve or surface then it will be converted to a shape.

    :param entity: The entity.
    :type entity: afem.geometry.entities.Geometry or
        afem.topology.entities.Shape or afem.base.entities.ShapeHolder

    :return: The shape.
    :rtype: afem.topology.entities.Shape
    """
    if isinstance(entity, ShapeHolder):
        return entity.shape
    else:
        return Shape.to_shape(entity)
コード例 #17
0
ファイル: step.py プロジェクト: tnakaicode/AFEM-OCC
    def transfer(self, *shapes):
        """
        Transfer and add the shapes to the exported entities.

        :param afem.topology.entities.Shape shapes: The shape(s).

        :return: *True* if shape was transferred, *False* if not.
        :rtype: bool
        """
        added_shape = False
        for shape in shapes:
            shape = Shape.to_shape(shape)
            if not shape:
                continue
            status = self._writer.Transfer(shape.object, STEPControl_AsIs)
            if int(status) < int(IFSelect_RetError):
                added_shape = True
        return added_shape
コード例 #18
0
ファイル: entities.py プロジェクト: sanderboer/AFEM
    def discard_by_dmin(self, entity, dmin):
        """
        Discard shapes of the part using a shape and a distance. If the
        distance between a shape of the part and the given shape is less
        than *dmin*, then the shape is removed. Edges are checked
        for curve parts and faces are checked for surface parts.

        :param entity: The shape.
        :type entity: afem.topology.entities.Shape or
            afem.geometry.entities.Geometry
        :param float dmin: The minimum distance.

        :return: *True* if shapes were discarded, *False* if not.
        :rtype: bool

        :raise TypeError: If this part is not a curve or surface part.
        """
        entity = Shape.to_shape(entity)

        if isinstance(self, CurvePart):
            shapes = self.shape.edges
        elif isinstance(self, SurfacePart):
            shapes = self.shape.faces
        else:
            msg = 'Invalid part type in discard operation.'
            raise TypeError(msg)

        rebuild = RebuildShapeWithShapes(self._shape)

        modified = False
        for part_shape in shapes:
            dmin_ = DistanceShapeToShape(entity, part_shape).dmin
            if dmin > dmin_:
                rebuild.remove(part_shape)
                modified = True

        if not modified:
            return False

        new_shape = rebuild.apply()
        self.set_shape(new_shape)
        return True
コード例 #19
0
ファイル: xde.py プロジェクト: 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)
コード例 #20
0
ファイル: modify.py プロジェクト: sanderboer/AFEM
    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)
コード例 #21
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
コード例 #22
0
ファイル: modify.py プロジェクト: sanderboer/AFEM
 def __init__(self, shape):
     tool = ShapeUpgrade_ShapeDivideClosed(shape.object)
     tool.Perform()
     self._shape = Shape.wrap(tool.Result())
コード例 #23
0
ファイル: modify.py プロジェクト: sanderboer/AFEM
 def __init__(self, shape, edges=True, faces=True, bsplines=False):
     tool = ShapeUpgrade_UnifySameDomain(shape.object, edges, faces,
                                         bsplines)
     tool.Build()
     self._shape = Shape.wrap(tool.Shape())
     self._history = tool.History()
コード例 #24
0
 def shape(self):
     """
     :return: The shape to mesh.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._mesh.GetShapeToMesh())
コード例 #25
0
 def last_vertex(self):
     """
     :return: Last vertex of side.
     :rtype: afem.topology.entities.Vertex
     """
     return Shape.wrap(self._fside.LastVertex())
コード例 #26
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()]
コード例 #27
0
 def shape(self):
     """
     :return: The resulting shape.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._bop.Shape())
コード例 #28
0
ファイル: fix.py プロジェクト: gitter-badger/AFEM
 def shape(self):
     """
     :return: The fixed shape.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._tool.Shape())
コード例 #29
0
ファイル: distance.py プロジェクト: tnakaicode/AFEM-OCC
 def __init__(self, shape1, shape2, deflection=1.0e-7):
     shape1 = Shape.to_shape(shape1)
     shape2 = Shape.to_shape(shape2)
     self._tool = BRepExtrema_DistShapeShape(shape1.object, shape2.object,
                                             deflection,
                                             Extrema_ExtFlag_MIN)
コード例 #30
0
 def shape(self):
     """
     :return: The sub-shape.
     :rtype: afem.topology.entities.Shape
     """
     return Shape.wrap(self._mesh.GetSubShape())