Esempio n. 1
0
    def write_edge(points_edge, topo_edge):
        """
        Method to recreate an Edge associated to a geometric curve
        after the modification of its points.
        :param points_edge: the deformed points array.
        :param topo_edge: the Edge to be modified
        :return: Edge (Shape)

        :rtype: TopoDS_Edge

        """
        # convert Edge to Geom B-spline Curve
        nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_edge)
        nurbs_converter.Perform(topo_edge)
        nurbs_curve = nurbs_converter.Shape()
        topo_curve = topods_Edge(nurbs_curve)
        h_geomcurve = BRep_Tool.Curve(topo_curve)[0]
        h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
        bspline_edge_curve = h_bcurve.GetObject()

        # Edge geometric properties
        nb_cpt = bspline_edge_curve.NbPoles()
        # check consistency
        if points_edge.shape[0] != nb_cpt:
            raise ValueError("Input control points do not have not have the "
                             "same number as the geometric edge!")

        else:
            for i in range(1, nb_cpt + 1):
                cpt = points_edge[i - 1]
                bspline_edge_curve.SetPole(i, gp_Pnt(cpt[0], cpt[1], cpt[2]))

        new_edge = BRepBuilderAPI_MakeEdge(bspline_edge_curve.GetHandle())

        return new_edge.Edge()
Esempio n. 2
0
 def project_curve(self, other):
     # this way Geom_Circle and alike are valid too
     if (isinstance(other, TopoDS_Edge) or isinstance(other, Geom_Curve)
             or issubclass(other, Geom_Curve)):
         # convert edge to curve
         first, last = topexp.FirstVertex(other), topexp.LastVertex(other)
         lbound, ubound = BRep_Tool().Parameter(
             first, other), BRep_Tool().Parameter(last, other)
         other = BRep_Tool.Curve(other, lbound, ubound).GetObject()
         return geomprojlib.Project(other, self.surface_handle)
Esempio n. 3
0
def intersection(a, b):

    if set([a.ShapeType(), b.ShapeType()]) <= set([TopAbs.TopAbs_WIRE, TopAbs.TopAbs_EDGE]):
        # TODO: check if the computed point is within the bounded part of
        # the curves
        l = []
        for c0 in subshapes(a, TopAbs.TopAbs_EDGE):
            c0_ = BRep_Tool.Curve(c0)[0]
            for c1 in subshapes(b, TopAbs.TopAbs_EDGE):
                c1_ = BRep_Tool.Curve(c1)[0]
                # TODO: use IntTools_EdgeEdge
                #  or IntTools_BeanBeanIntersector
                u = GeomAPI_ExtremaCurveCurve(c0_, c1_)
                par = u.LowerDistanceParameters()[0]
                pnt = c0_.GetObject().Value(par)
                l.append(BRepBuilderAPI_MakeVertex(pnt).Vertex())
        return l

    c = BRepAlgoAPI.BRepAlgoAPI_Common(a, b).Shape()
    comp = TopoDS.topods_Compound(c)
    # get the subshape of the compound:
    types = set([a.ShapeType(), b.ShapeType()])
    # compound = 0
    # compsolid = 1
    # solid = 2
    # shell = 3
    # face = 4
    # wire = 5
    # edge = 6
    # vertex = 7
    # shape = 8
    if types == set([TopAbs.TopAbs_FACE]):
        return [subshapes(comp, TopAbs.TopAbs_FACE)[0]]
    elif types == set([TopAbs.TopAbs_FACE, TopAbs.TopAbs_SOLID]):
        return [subshapes(comp, TopAbs.TopAbs_SHELL)[0]]
    elif types == set([TopAbs.TopAbs_SOLID]):
        return [subshapes(comp, TopAbs.TopAbs_SOLID)[0]]
    elif types == set([TopAbs.TopAbs_SHELL]):
        return [subshapes(comp, TopAbs.TopAbs_EDGE)[0]]
    else:
        raise ConstructionError()
Esempio n. 4
0
    def project_curve(self, other):
        # this way Geom_Circle and alike are valid too
        if isinstance(other, TopoDS_Edge) or\
             isinstance(other, Geom_Curve)  or\
             issubclass(other, Geom_Curve):
                if isinstance(other, TopoDS_Edge):
                    # convert edge to curve
                    first, last = TopExp.FirstVertex(other), TopExp.LastVertex(other)
                    lbound, ubound  = BRep_Tool().Parameter(first, other), BRep_Tool().Parameter(first, other)
                    other = BRep_Tool.Curve(other, lbound, ubound).GetObject()

                from OCC.GeomProjLib import GeomProjLib
                return GeomProjLib().Project(other, self.surface_handle)
 def get_curve(self):
     return BRep_Tool.Curve(self)