Open CASCADE(简称OCC)平台是是一个开源的C++类库,OCC主要用于开发二维和三维几何建模应用程序,包括通用的或专业的计算机辅助设计CAD系统、制造或分析领域的应用程序、仿真应用程序或图形演示工具。
PythonOCC是对Open CASCADE的封装。PythonOCC按照官方描述:3D CAD/CAE/PLM DEVELOPMENT FRAMEWORK FOR THE PYTHON PROGRAMMING LANGUAGE. 即用于开发CAD/CAE/CAM程序的一个Python框架。PythonOCC的下载地址为:http://www.pythonocc.org/download/
学习一个框架先从最简单的"Hello world"程序开始,下面用PythonOCC创建一个最简单的立方体并显示出来。
'''
This examples creates and displays a simple box.
''' # The first line loads the init_display function, necessary to
# enable the builtin simple gui provided with pythonocc
from OCC.Display.SimpleGui import init_display # Then we import the class that instanciates a box
# Here the BRepPrimAPI module means Boundary Representation Primitive API.
# It provides an API for creation of basic geometries like spheres,cones etc
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox # Following line initializes the display
# By default, the init_display function looks for a Qt based Gui (PyQt, PySide)
display, start_display, add_menu, add_function_to_menu = init_display() # The BRepPrimAPI_MakeBox class is initialized with the 3 parameters of the box: widht, height, depth
my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() # Then the box shape is sent to the renderer
display.DisplayShape(my_box, update=True) # At last, we enter the gui mainloop
start_display()
显示结果如下,按键盘上的W,S,H键可以在线框模型,面模型和消隐线模型之间切换。按住左键移动鼠标可以旋转物体,鼠标中键用于缩放,按住鼠标中键可以平移物体
参考: