pythonocc_放样改写,坐标自动跟进

在这里插入图片描述
在这里插入图片描述

# 放样改写
from OCC.Core.AIS import AIS_Shape
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections
from OCC.Core.gp import gp_Pnt
from OCC.Display.SimpleGui import init_display
from OCC.Display.OCCViewer import rgb_color
from OCC.Core.GC import GC_MakeSegment, GC_MakeCircle, GC_MakeArcOfCircle, GC_MakeEllipse

def build_auto_wire():
    # 做第一条封闭曲线(四边形)
    gp_n = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    gp_x = [40, 82.5, 42.5, 0, 8, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32, 36, 40, 44, 48]
    gp_y = [0, 25, 93, 68, 19, 23, 28, 28, 28, 31, 31, 34, 37, 37, 40, 43, 49, 49, 56, 56, 62, 62, 70, 70]
    gp_z = [0, 0, 0, 0, 160, 190, 220, 250, 310, 370, 430, 490, 550, 660, 770, 875, 990, 1090, 1210,
            1420, 1640, 1860, 2070, 2300]
    dict_gp_x = dict(zip(gp_n, gp_x))
    dict_gp_y = dict(zip(gp_n, gp_y))
    dict_gp_z = dict(zip(gp_n, gp_z))

    dict_select_num = 3

    aWire = BRepBuilderAPI_MakeWire()  # Create a wire out of the edges
    for i in range(0, dict_select_num):
        if i < dict_select_num - 1:
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z[i]),
                                      gp_Pnt(dict_gp_x[i + 1], dict_gp_y[i + 1], dict_gp_z[i + 1]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            aWire.Add(anEdge.Edge())
        else:
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z[i]),
                                      gp_Pnt(dict_gp_x[0], dict_gp_y[0], dict_gp_z[0]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            aWire.Add(anEdge.Edge())
    display.DisplayShape(aWire.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))  #

def build_auto_MakeEdge():
    # 做第一条封闭曲线(四边形)
    gp_n = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    gp_x = [40, 82.5, 42.5, 0, 8, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32, 36, 40, 44, 48]
    gp_y = [0, 25, 93, 68, 19, 23, 28, 28, 28, 31, 31, 34, 37, 37, 40, 43, 49, 49, 56, 56, 62, 62, 70, 70]
    gp_z = [0, 0, 0, 0, 160, 190, 220, 250, 310, 370, 430, 490, 550, 660, 770, 875, 990, 1090, 1210,
            1420, 1640, 1860, 2070, 2300]
    dict_gp_x = dict(zip(gp_n, gp_x))
    dict_gp_y = dict(zip(gp_n, gp_y))
    dict_gp_z = dict(zip(gp_n, gp_z))

    dict_select_num = 3

    aWire = BRepBuilderAPI_MakeEdge()  # Create a wire out of the edges
    for i in range(0, dict_select_num):
        if i < dict_select_num - 1:
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z[i]),
                                      gp_Pnt(dict_gp_x[i + 1], dict_gp_y[i + 1], dict_gp_z[i + 1]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            aWire.Add(anEdge.Edge())
        else:
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z[i]),
                                      gp_Pnt(dict_gp_x[0], dict_gp_y[0], dict_gp_z[0]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            aWire.Add(anEdge.Edge())
    display.DisplayShape(aWire.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))  #


def fangyang():
    # 做第一条封闭曲线(四边形)
    gp_n = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    gp_x = [40, 50, 60, 30, 8, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32, 36, 40, 44, 48]
    gp_y = [0, 25, 93, 68, 50, 23, 28, 28, 28, 31, 31, 34, 37, 37, 40, 43, 49, 49, 56, 56, 62, 62, 70, 70]
    gp_z = [0, 0, 0, 0, 0, 0, 220, 250, 310, 370, 430, 490, 550, 660, 770, 875, 990, 1090, 1210,
            1420, 1640, 1860, 2070, 2300]
    dict_gp_x = dict(zip(gp_n, gp_x ))
    dict_gp_y = dict(zip(gp_n, gp_y ))
    dict_gp_z = dict(zip(gp_n, gp_z ))

    dict_select_num=5

    BRep_Wire_down = BRepBuilderAPI_MakeWire()  # Create a wire out of the edges
    for i in range(0, dict_select_num):

        if i<dict_select_num-1: #因为最后一个数不取
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i],dict_gp_y[i],dict_gp_z[i]),
                                      gp_Pnt(dict_gp_x[i+1],dict_gp_y[i+1],dict_gp_z[i+1]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            BRep_Wire_down.Add(anEdge.Edge())
            # print(i)
        else:
            # print(' ssss',i)
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z[i]),
                                      gp_Pnt(dict_gp_x[0], dict_gp_y[0], dict_gp_z[0]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            BRep_Wire_down.Add(anEdge.Edge())
    display.EraseAll()
    display.DisplayShape(BRep_Wire_down.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))  #

    #高度变化
    gp_z1 = [5, 5, 5, 5, 5, 190, 220, 250, 310, 370, 430, 490, 550, 660, 770, 875, 990, 1090, 1210,
                       1420, 1640, 1860, 2070, 2300]
    dict_gp_z_up = dict(zip(gp_n, gp_z1))
    dict_select_num_up = 4

    BRep_Wire_up = BRepBuilderAPI_MakeWire()  # Create a wire out of the edges
    for i in range(0, dict_select_num_up):
        if i < dict_select_num_up - 1:
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z_up[i]),
                                      gp_Pnt(dict_gp_x[i + 1], dict_gp_y[i + 1], dict_gp_z_up[i + 1]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            BRep_Wire_up.Add(anEdge.Edge())
        else:
            aSegment = GC_MakeSegment(gp_Pnt(dict_gp_x[i], dict_gp_y[i], dict_gp_z_up[i]),
                                      gp_Pnt(dict_gp_x[0], dict_gp_y[0], dict_gp_z_up[0]))

            anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
            BRep_Wire_up.Add(anEdge.Edge())
    display.DisplayShape(BRep_Wire_up.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))  #

    # 做第2条封闭曲线(三角形)#只取3个数

    # 高度放样
    generator=BRepOffsetAPI_ThruSections(True)#类初始化
    generator.AddWire(BRep_Wire_up.Wire()) #增加参数:上部线
    generator.AddWire(BRep_Wire_down.Wire())#增加参数:下部线
    ais_shpe=AIS_Shape(generator.Shape())#参数转AIS_shape
    generator.Build()#完成放样
    display.DisplayShape(generator.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))
    # display.DisplayShape(ais_shpe.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))  #
    return ais_shpe,generator



def exit(event=None):
    import  sys
    sys.exit()


if __name__ == '__main__':
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.display_triedron()  # 坐標顯示
    display.set_bg_gradient_color([206, 215, 222], [0, 128, 0])  # 设置背景渐变色
    add_menu('放样曲线')
    add_function_to_menu('放样曲线',  build_auto_wire)
    add_function_to_menu('放样曲线', fangyang)
    start_display()
    # display.DisplayShape(generator.Shape(),update=True)
    # ais_shpe,generator=fangyang()
    build_auto_wire()
    # display.DisplayShape(ais_shpe.Shape(),update=True)
    # display.DisplayShape(ais_shpe.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))#
    # display.DisplayShape(generator.Shape(), update=True, color=rgb_color(0.1, 0.2, 1))#
    start_display()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值