Example #1
0
    def update_shape(self, change):
        from .occ_draw import OccVertex, OccWire

        d = self.declaration

        shape = BRepOffsetAPI_ThruSections(d.solid, d.ruled, d.precision)

        #: TODO: Support Smoothing, Max degree, par type, etc...

        for child in self.children():
            if isinstance(child, OccVertex):
                shape.AddVertex(child.shape.Vertex())
            elif isinstance(child, OccWire):
                shape.AddWire(child.shape.Wire())
            #: TODO: Handle transform???

        #: Set the shape
        self.shape = shape
Example #2
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
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()