コード例 #1
0
ファイル: calculate.py プロジェクト: CES-MDE/py4design
def project_face_on_faceplane(occface2projon, occface2proj):
    """
    This function projects the OCCface onto another OCCface plane. The plane stretches through infinity.
 
    Parameters
    ----------
    occface2projon : OCCface
        The OCCface to be projected on.
        
    occface2proj : OCCface
        The OCCface to be projected.
        
    Returns
    -------
    list of points : pyptlist
        The list of projected points.
    """

    wire_list = list(Topology.Topo(occface2proj).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)
    proj_ptlist = []
    for occpt in occpt_list:
        occ_pnt = BRep_Tool.Pnt(occpt)
        pypt = (occ_pnt.X(), occ_pnt.Y(), occ_pnt.Z())
        projected_pt = project_point_on_faceplane(pypt, occface2projon)
        proj_ptlist.append(projected_pt)

    return proj_ptlist
コード例 #2
0
def buildFaceBotUp():
    """Following procedure in Roman Lygen's blog
    """
    origin = gp_Pnt(0, 0, 0)
    wDir = gp_Dir(0, 0, 1)
    uDir = gp_Dir(1, 0, 0)
    vDir = gp_Dir(0, 1, 0)
    xyzAx3 = gp_Ax3(origin, wDir, uDir)
    gpPlane = gp_Pln(xyzAx3)  # type OCC.gp.gp_Pln
    # gpPlane = gp_XOY()  # type gp_Ax2
    plane = Geom_Plane(gpPlane)  # type: OCC.Geom.Geom_Plane
    aSurf = Handle_Geom_Surface(plane)  # type: Handle_Geom_Surface
    anExtC = Geom_Circle(gp_XOY(), 10.0)  # type: OCC.Geom.Geom_Circle
    anIntC = Geom_Circle(gp_XOY(), 5.0)  # type: OCC.Geom.Geom_Circle
    anExtE = BRepBuilderAPI_MakeEdge(anExtC.GetHandle())
    anIntE = BRepBuilderAPI_MakeEdge(anIntC.GetHandle())
    anExtWire = BRepBuilderAPI_MakeWire(anExtE.Edge())
    anIntWire = BRepBuilderAPI_MakeWire(anIntE.Edge())
    aFace = BRepBuilderAPI_MakeFace(anExtWire.Wire())
    aFace.Add(anIntWire.Wire())  # adds wire to the face as a hole
    display.DisplayShape(aFace.Face())
    edgeList = []
    anEdgeExplorer = TopExp_Explorer(aFace.Face(), TopAbs_EDGE)
    while anEdgeExplorer.More():
        anEdge = topods.Edge(anEdgeExplorer.Current())
        anEdgeExplorer.Next()
        edgeList.append(anEdge)
    print 'Number of edges: ', len(edgeList)
    Topology.dumpTopology(aFace.Face())
    topo = Topology.Topo(aFace.Face())
    print 'Number of wires: ', topo.number_of_wires_from_face(aFace.Face())
    wires = topo.wires_from_face(aFace.Face())
    for wire in wires:
        display.DisplayShape(wire)
コード例 #3
0
ファイル: calculate.py プロジェクト: Linwal/pyliburo
def srf_nrml_facing_solid_inward(occ_face, occ_solid):
    #move the face in the direction of the normal
    #first offset the face so that vert will be within the solid
    o_wire = Construct.make_offset(occ_face, 0.0001)
    o_face = BRepBuilderAPI_MakeFace(o_wire).Face()

    wire_list = list(Topology.Topo(o_face).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)

    pt = BRep_Tool.Pnt(occpt_list[0])  #a point that is on the edge of the face
    normal = face_normal(occ_face)

    gp_direction2move = gp_Vec(normal[0], normal[1], normal[2])
    gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001))
    mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z())

    in_solid = point_in_solid(occ_solid, mv_pt)

    if in_solid:
        return True
    else:
        return False
コード例 #4
0
ファイル: calculate.py プロジェクト: Linwal/pyliburo
def project_face_on_faceplane(occface2projon, occface2proj):
    wire_list = list(Topology.Topo(occface2proj).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)
    proj_ptlist = []
    for occpt in occpt_list:
        occ_pnt = BRep_Tool.Pnt(occpt)
        pypt = (occ_pnt.X(), occ_pnt.Y(), occ_pnt.Z())
        projected_pt = project_point_on_faceplane(occface2projon, pypt)
        proj_ptlist.append(projected_pt)

    return proj_ptlist
コード例 #5
0
def points_frm_wire(occ_wire):
    '''
    vertex_list = geom_explorer(occ_wire, TopAbs_VERTEX)
    point_list = vertex_list_2_point_list(vertex_list)
    
    n_pt_list = []
    for pt in point_list:
        if n_pt_list:
            p_vert = (n_pt_list[-1].X(), n_pt_list[-1].Y(), n_pt_list[-1].Z())
            c_vert = (pt.X(), pt.Y(), pt.Z())
            if c_vert != p_vert:
                n_pt_list.append(pt)
        else:
            n_pt_list.append(pt)
    
    return n_pt_list
    '''
    #TODO: WHEN DEALING WITH OPEN WIRE IT WILL NOT RETURN THE LAST VERTEX
    verts = Topology.WireExplorer(occ_wire).ordered_vertices()
    point_list = []
    for vert in verts:
        pt = BRep_Tool.Pnt(vert)
        point_list.append(pt)

    #this always returns points in order that is opposite of the input
    #e.g. if the inputs are clockwise it will ouput anticlockwise
    #e.g. if the inputs are anticlockwise it will ouput clockwise
    #thus the point list needs to be reversed to reflect the true order
    #point_list = list(reversed(point_list))

    return point_list
コード例 #6
0
def points_frm_solid(occ_solid):
    verts = Topology.Topo(occ_solid).vertices()
    point_list = []
    for vert in verts:
        pt = BRep_Tool.Pnt(vert)
        point_list.append(pt)

    return point_list
コード例 #7
0
ファイル: calculate.py プロジェクト: CES-MDE/py4design
def srf_nrml_facing_solid_inward(occface, occsolid):
    """
    This function checks if the OCCface is facing the inside of the OCCsolid.
 
    Parameters
    ----------
    occface : OCCface
        The OCCface to be checked.
        
    occsolid : OCCsolid
        The OCCsolid.
        
    Returns
    -------
    True or False : bool
        If True the face is facing the inside of the solid, if False the face is not facing inwards.
    """
    #move the face in the direction of the normal
    #first offset the face so that vert will be within the solid
    o_wire = Construct.make_offset(occface, 0.0001)
    o_face = BRepBuilderAPI_MakeFace(o_wire).Face()

    wire_list = list(Topology.Topo(o_face).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)

    pt = BRep_Tool.Pnt(occpt_list[0])  #a point that is on the edge of the face
    normal = face_normal(occface)

    gp_direction2move = gp_Vec(normal[0], normal[1], normal[2])
    gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001))
    mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z())

    in_solid = point_in_solid(occsolid, mv_pt)

    if in_solid:
        return True
    else:
        return False
コード例 #8
0
def solids_frm_compsolid(occcompsolid):
    """
    This function fetches a list of OCCsolids from the OCCcompsolid.
 
    Parameters
    ----------
    occcompsolid : OCCcompsolid
        The OCCcompsolid to be examined.
        
    Returns
    -------
    list of solids : list of OCCsolids
        The list of OCCsolids extracted from the occcompsolid.
    """
    solid_list = Topology.Topo(occcompsolid).solids()
    return list(solid_list)
コード例 #9
0
def shells_frm_solid(occsolid):
    """
    This function fetches a list of OCCshells from the OCCsolid. The solid is constructed based on the list of shells.
 
    Parameters
    ----------
    occsolid : OCCsolid
        The OCCsolid to be examined.
        
    Returns
    -------
    list of shells : list of OCCshells
        The list of OCCshells extracted from the OCCsolid.
    """
    shell_list = Topology.Topo(occsolid).shells()
    return list(shell_list)
コード例 #10
0
def wires_frm_face(occface):
    """
    This function fetches a list of OCCwires from the OCCface. The face is constructed based on the list of wires.
 
    Parameters
    ----------
    occface : OCCface
        The OCCface to be examined.
        
    Returns
    -------
    list of wires : list of OCCwires
        The list of OCCwires extracted from the OCCface.
    """
    wire_list =  Topology.Topo(occface).wires()
    return list(wire_list)
コード例 #11
0
def faces_frm_shell(occshell):
    """
    This function fetches a list of OCCfaces from the OCCshell. The shell is constructed based on the list of faces.
 
    Parameters
    ----------
    occshell : OCCshell
        The OCCshell to be examined.
        
    Returns
    -------
    list of faces : list of OCCfaces
        The list of OCCfaces extracted from the OCCshell.
    """
    face_list = Topology.Topo(occshell).faces()
    return list(face_list) 
コード例 #12
0
def edges_frm_wire(occwire):
    """
    This function fetches a list of OCCedges from the OCCwire. The wire is constructed based on the list of edges.
 
    Parameters
    ----------
    occwire : OCCwire
        The OCCwire to be examined.
        
    Returns
    -------
    list of edges : list of OCCedges
        The list of OCCedges extracted from the OCCwire.
    """
    edge_list = Topology.WireExplorer(occwire).ordered_edges()
    return list(edge_list)
コード例 #13
0
def getPolygonesFromShape(shape):
    from Geometry.Geom3D import Pnt3D,Poly3D

    exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_WIRE)  # .TopAbs_FACE)
    polygons = []
    while exp.More():
        wire = TopoDS.topods.Wire(TopoDS.topods.Wire(exp.Current()))
        exp.Next()
        points = []
        from OCCUtils import Topology
        explorer = Topology.WireExplorer(wire)
        vertices = explorer.ordered_vertices()
        for vertex in vertices:
            pnt = BRep.BRep_Tool_Pnt(vertex)
            points.append(Pnt3D(pnt.X(),pnt.Y(),pnt.Z()))
        polygons.append(Poly3D(points))

    return polygons
コード例 #14
0
def points_frm_solid(occsolid):
    """
    This function fetches a list of points from the OCCsolid.
 
    Parameters
    ----------
    occsolid : OCCsolid
        The OCCsolid to be examined.
        
    Returns
    -------
    list of points : pyptlist
        The list of points extracted from the OCCsolid.
    """
    verts = list(Topology.Topo(occsolid).vertices())
    ptlist = modify.occvertex_list_2_occpt_list(verts)
    pyptlist = modify.occpt_list_2_pyptlist(ptlist)        
    return pyptlist
コード例 #15
0
def points_frm_edge(occedge):
    """
    This function fetches a list of points from the OCCedge. The list of points consist of the starting and ending point of the edge.
 
    Parameters
    ----------
    occedge : OCCedge
        The OCCedge to be examined.
        
    Returns
    -------
    list of points : pyptlist
        The list of points extracted from the OCCedge.
    """
    vertex_list = list(Topology.Topo(occedge).vertices())
    point_list = modify.occvertex_list_2_occpt_list(vertex_list)
    pyptlist = modify.occpt_list_2_pyptlist(point_list)
    return pyptlist
コード例 #16
0
def points_frm_wire(occwire):
    """
    This function fetches a list of points from the OCCwire. The wire is constructed based on the list of points.
    TODO: WHEN DEALING WITH OPEN WIRE IT WILL NOT RETURN THE LAST VERTEX
 
    Parameters
    ----------
    occwire : OCCwire
        The OCCwire to be examined.
        
    Returns
    -------
    list of points : pyptlist
        The list of points extracted from the OCCwire.
    """
    verts = list(Topology.WireExplorer(occwire).ordered_vertices())
    point_list = modify.occvertex_list_2_occpt_list(verts)
    pyptlist = modify.occpt_list_2_pyptlist(point_list)
    return pyptlist
コード例 #17
0
def fillet(event=None):
    """Fillet (blend) edges of active part"""
    if win.lineEditStack and win.edgeStack:
        topo = Topology.Topo(win.activePart)
        text = win.lineEditStack.pop()
        filletR = float(text) * win.unitscale
        edges = []
        # Test if edge(s) selected are in active part
        for edge in win.edgeStack:
            try:
                if edge in topo.edges():
                    edges.append(edge)
                else:
                    print("Selected edge(s) must be in Active Part.")
                    win.clearCallback()
                    return
            except ValueError:
                print("You must first set the Active Part.")
                win.clearCallback()
                return
        win.edgeStack = []
        workPart = win.activePart
        uid = win.activePartUID
        mkFillet = BRepFilletAPI_MakeFillet(workPart)
        for edge in edges:
            mkFillet.Add(filletR, edge)
        try:
            newPart = mkFillet.Shape()
            win.erase_shape(uid)
            doc.replaceShape(uid, newPart)
            win.draw_shape(uid)
            win.statusBar().showMessage("Fillet operation complete")
        except RuntimeError as e:
            print(f"Unable to make Fillet. {e}")
        win.setActivePart(uid)
        win.clearCallback()
    else:
        win.registerCallback(filletC)
        display.SetSelectionModeEdge()
        statusText = "Select edge(s) to fillet then specify fillet radius."
        win.statusBar().showMessage(statusText)
コード例 #18
0
def visualise_falsecolour_topo(occtopo_list,
                               results,
                               other_occtopo_2dlist=None,
                               other_colour_list=None,
                               minval=None,
                               maxval=None,
                               backend="qt-pyqt5",
                               inverse=False):
    """
    This function visualise a falsecolour 3D model using the PythonOCC viewer.
 
    Parameters
    ----------
    occtopo_list : list of OCCtopologies
        The geometries to be visualised with the results. The list of geometries must correspond to the list of results.
        OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex 
        
    results : list of floats
        The results to be visualised. The list of results must correspond to the occtopo_list.
        
    other_occtopo_2dlist : 2d list of OCCtopologies, optional
        Other geometries to be visualised together with the results, Default = None.
        
    other_colour_list : list of str, optional
        The colours of the other_topo2dlist, Default = None. The colour strings include: "WHITE", "BLUE", "RED", "GREEN", "YELLOW", "CYAN",
        "BLACK", "ORANGE". The number of colours must correspond to the number of list in the other_topo2dlist. 
        
    minval : float, optional
        The minimum value of the falsecolour rgb, Default = None. If None the maximum value is equal to the maximum value from the results.
        
    maxval : float, optional
        The maximum value of the falsecolour rgb, Default = None. If None the maximum value is equal to the minimum value from the results.
        
    backend : str, optional
        The graphic interface to use for visualisation, Default = qt-pyqt5. Other options include:"qt-pyqt4", "qt-pyside", "wx"
        
    inverse : bool
        False for red being max, True for blue being maximum.
        
    Returns
    -------
    None : None
        A qt window pops up displaying the geometries.
    """
    display, start_display, add_menu, add_function_to_menu = init_display(
        backend_str=backend)

    if minval == None:
        minval1 = min(results)
    elif minval != None:
        minval1 = minval

    if maxval == None:
        maxval1 = max(results)
    elif maxval != None:
        maxval1 = maxval

    res_colours = falsecolour(results, minval1, maxval1, inverse=inverse)

    colour_list = []
    c_srf_list = []
    for r_cnt in range(len(res_colours)):
        fcolour = res_colours[r_cnt]
        rf = occtopo_list[r_cnt]
        if fcolour not in colour_list:
            colour_list.append(fcolour)
            c_srf_list.append([rf])

        elif fcolour in colour_list:
            c_index = colour_list.index(fcolour)
            c_srf_list[c_index].append(rf)

    for c_cnt in range(len(c_srf_list)):
        c_srfs = c_srf_list[c_cnt]
        colour = colour_list[c_cnt]
        from OCC.Quantity import Quantity_TOC_RGB, Quantity_Color
        compound = construct.make_compound(c_srfs)
        display.DisplayColoredShape(compound,
                                    color=Quantity_Color(
                                        colour[0], colour[1], colour[2],
                                        Quantity_TOC_RGB),
                                    update=True)

    #display the edges of the grid
    tedges = []
    for t in occtopo_list:
        edge = list(Topology.Topo(t).edges())
        tedges.extend(edge)

    edgecompound = construct.make_compound(tedges)
    display.DisplayColoredShape(edgecompound, color="BLACK", update=True)

    if other_occtopo_2dlist != None:
        tc_cnt = 0
        for other_topolist in other_occtopo_2dlist:
            other_compound = construct.make_compound(other_topolist)
            other_colour = other_colour_list[tc_cnt]
            display.DisplayColoredShape(other_compound,
                                        color=other_colour,
                                        update=True)
            tc_cnt += 1

    display.set_bg_gradient_color(0, 0, 0, 0, 0, 0)
    display.View_Iso()
    display.FitAll()
    start_display()
コード例 #19
0
def points_from_edge(occ_edge):
    vertex_list = list(Topology.Topo(occ_edge).vertices())
    point_list = vertex_list_2_point_list(vertex_list)
    return point_list
コード例 #20
0
def edges_frm_wire(occ_wire):
    edge_list = Topology.WireExplorer(occ_wire).ordered_edges()
    return list(edge_list)
コード例 #21
0
def wires_frm_face(occ_face):
    wire_list = Topology.Topo(occ_face).wires()
    return list(wire_list)
コード例 #22
0
def faces_frm_shell(occ_shell):
    face_list = Topology.Topo(occ_shell).faces()
    return list(face_list)
コード例 #23
0
def shells_frm_solid(occ_solid):
    shell_list = Topology.Topo(occ_solid).shells()
    return list(shell_list)
コード例 #24
0
def solids_frm_compsolid(occ_compsolid):
    solid_list = Topology.Topo(occ_compsolid).solids()
    return list(solid_list)
コード例 #25
0
def topoDumpAP():
    if win.activePart:
        Topology.dumpTopology(win.activePart)
コード例 #26
0
ファイル: construct.py プロジェクト: Linwal/pyliburo
def visualise_falsecolour_topo(results,
                               occtopo_list,
                               other_topo2dlist=None,
                               other_colourlist=None,
                               minval_range=None,
                               maxval_range=None,
                               backend="qt-pyqt5"):

    display, start_display, add_menu, add_function_to_menu = init_display(
        backend_str=backend)

    if minval_range == None:
        minval = min(results)
    elif minval_range != None:
        minval = minval_range

    if maxval_range == None:
        maxval = max(results)
    elif maxval_range != None:
        maxval = maxval_range

    res_colours = falsecolour(results, minval, maxval)

    colour_list = []
    c_srf_list = []
    for r_cnt in range(len(res_colours)):
        fcolour = res_colours[r_cnt]
        rf = occtopo_list[r_cnt]
        if fcolour not in colour_list:
            colour_list.append(fcolour)
            c_srf_list.append([rf])

        elif fcolour in colour_list:
            c_index = colour_list.index(fcolour)
            c_srf_list[c_index].append(rf)

    for c_cnt in range(len(c_srf_list)):
        c_srfs = c_srf_list[c_cnt]
        colour = colour_list[c_cnt]
        compound = make_compound(c_srfs)
        display.DisplayColoredShape(compound, color=colour, update=True)

    #display the edges of the grid
    tedges = []
    for t in occtopo_list:
        edge = list(Topology.Topo(t).edges())
        tedges.extend(edge)

    edgecompound = make_compound(tedges)
    display.DisplayColoredShape(edgecompound, color="BLACK", update=True)

    if other_topo2dlist != None:
        tc_cnt = 0
        for other_topolist in other_topo2dlist:
            other_compound = make_compound(other_topolist)
            other_colour = other_colourlist[tc_cnt]
            display.DisplayColoredShape(other_compound,
                                        color=other_colour,
                                        update=True)
            tc_cnt += 1

    display.set_bg_gradient_color(0, 0, 0, 0, 0, 0)
    display.View_Iso()
    display.FitAll()
    start_display()