Exemple #1
0
def make_loft(elements,
              ruled=False,
              tolerance=TOLERANCE,
              continuity=GeomAbs_C2,
              check_compatibility=True):
    sections = BRepOffsetAPI_ThruSections(False, ruled, tolerance)
    for i in elements:
        if isinstance(i, TopoDS_Wire):
            sections.AddWire(i)
        elif isinstance(i, TopoDS_Vertex):
            sections.AddVertex(i)
        else:
            raise TypeError(
                'elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool'
                % i.__class__)

    sections.CheckCompatibility(check_compatibility)
    sections.SetContinuity(continuity)
    sections.Build()
    with assert_isdone(sections, 'failed lofting'):
        te = ShapeToTopology()
        loft = te(sections.Shape())
        return loft
anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(),
                                         Handle_Geom_Surface(aCyl2))

threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(),
                                         anEdge2OnSurf1.Edge())
threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(),
                                         anEdge2OnSurf2.Edge())

# Compute the 3D representations of the edges/wires
breplib.BuildCurves3d(threadingWire1.Shape())
breplib.BuildCurves3d(threadingWire2.Shape())

# Create the surfaces of the threading
aTool = BRepOffsetAPI_ThruSections(True)
aTool.AddWire(threadingWire1.Wire())
aTool.AddWire(threadingWire2.Wire())
aTool.CheckCompatibility(False)
myThreading = aTool.Shape()

# Build the resulting compound
aRes = TopoDS_Compound()
aBuilder = BRep_Builder()
aBuilder.MakeCompound(aRes)
aBuilder.Add(aRes, myBody.Shape())
aBuilder.Add(aRes, myThreading)

display, start_display, add_menu, add_function_to_menu = init_display('wx')
display.DisplayColoredShape(aRes)

start_display()
def AddSurfaceLoft(objs, continuity=GeomAbs_C2, check_compatibility=True,
                   solid=True, first_vertex=None, last_vertex=None,
                   max_degree=8, close_sections=True):
    """Create a lift surface through curve objects
    Parameters
    ----------
    objs : list of python classes
        Each obj is expected to have an obj.Curve attribute :
        see airconics.primitives.airfoil class

    continuity : OCC.GeomAbs.GeomAbs_XX type (default C2)
        The order of continuity (C^0, C^1, C^2, G^0, ....)

    check_compatibility : bool (default=True)
        Adds a surface compatibility check to the builder
    solid : bool (default=True)
        Creates a solid object from the loft if True

    first_vertex : TopoDS_Vertex (optional, default=None)
        The starting vertex of the surface to add to the 'ThruSections'
        algorithm
    last_vertex : TopoDS_Vertex (optional, default=None)
        The end vertex of the surface to add to the 'ThruSections'
        algorithm
    max_degree : int (default=8)
        The order of the fitted NURBS surface
    close_sections : bool (default=True):
        Connects the start and end point of the loft rib curves if true. This
        has the same effect as adding an airfoil trailing edge.
    Returns
    -------
    shape : TopoDS_Shape
        The generated loft surface

    Notes
    -----
    Uses OCC.BRepOffsetAPI.BRepOffsetAPI_ThruSections. This function is
    ORDER DEPENDANT, i.e. add elements in the order through which they should
    be lofted
    """
    assert (len(objs) >= 2), 'Loft Failed: Less than two input curves'
    # Note: This is to give a smooth loft.
    ruled = False
    pres3d = 1e-6
    args = [solid, ruled, pres3d]  # args (in order) for ThruSections
    generator = BRepOffsetAPI_ThruSections(*args)
    generator.SetMaxDegree(max_degree)
    #    from OCC.GeomAbs import GeomAbs_G1
    generator.SetParType(Approx_ChordLength)
    if first_vertex:
        generator.AddVertex(first_vertex)
    for obj in objs:
        try:
            # Check if this is an airconics object with a GeomBspline handle
            # as its 'Curve' attribute
            obj = obj.Curve
        #            edge = [make_edge(obj)]
        except:
            # Assume the object is already a geombspline handle
            pass
        #            try:
        #                # If working with an airconics object, the OCC curve is stored
        #                # in obj.Curve:
        edges = [make_edge(obj)]

        if close_sections:
            crv = obj.GetObject()
            if crv.IsClosed() is False:
                # Add Finite TE edge
                TE = make_edge(crv.Value(1), crv.Value(0))
                edges.append(TE)

        generator.AddWire(BRepBuilderAPI_MakeWire(*edges).Wire())
    #        else:
    #            generator
    if last_vertex:
        generator.AddVertex(last_vertex)

    generator.CheckCompatibility(check_compatibility)
    generator.SetContinuity(continuity)
    generator.Build()
    with assert_isdone(generator, 'failed lofting'):
        return generator.Shape()