用OCC+VS+Qt创建并显示一个几何
OCC+VS+QT相关配置详细见
OCC+ QT+VS、OCC+QtCreator 环境配置
创建视图并显示几何
OCC中显示过程如下:
获取OpenGl_GraphicDriverr
图形驱动
基于图形驱动初始化一个V3d_Viewer
通过Viewer创建一个视图View,并设置显示窗口
通过Viewer初始化一个AIS_Context交互环境,并设置其显示方式(shaded或者wire)
将几何模型转换为拓扑类型
经拓扑模型转换为AIS类型(交互对象类型)
在context中显示交互对象
.h文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #pragma once
#include <QtWidgets/QMainWindow> #include <Standard_Handle.hxx> #include <V3d_Viewer.hxx> #include <OpenGl_GraphicDriver.hxx> #include <WNT_Window.hxx> #include <V3d_View.hxx> #include <AIS_InteractiveContext.hxx> #include <BRepPrimAPI_MakeBox.hxx> #include <TopoDs_Shape.hxx> #include <AIS_Shape.hxx>
class QtWidgetsApplication1 : public QMainWindow { Q_OBJECT
public: QtWidgetsApplication1(QWidget *parent = nullptr); ~QtWidgetsApplication1(); protected: void paintEvent(QPaintEvent *event) override; QPaintEngine *paintEngine() const;
private: Ui::QtWidgetsApplication1Class ui; Handle(V3d_Viewer) viewer; Handle(V3d_View) view; Handle(AIS_InteractiveContext) context; Handle(WNT_Window) window;
};
|
cpp文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include "QtWidgetsApplication1.h"
QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent) : QMainWindow(parent) { Handle(Aspect_DisplayConnection) hAspect_DisplayConnect = new Aspect_DisplayConnection; Handle(OpenGl_GraphicDriver) driver = new OpenGl_GraphicDriver(hAspect_DisplayConnect);
viewer = new V3d_Viewer(driver); view = viewer->CreateView();
WId win_handle = winId(); window = new WNT_Window((Aspect_Handle)win_handle); view->SetWindow(window); if (!window->IsMapped()) { window->Map(); } view->SetBackgroundColor(Quantity_NOC_BLACK); view->MustBeResized(); viewer->SetDefaultLights(); setAttribute(Qt::WA_PaintOnScreen); context = new AIS_InteractiveContext(viewer); context->SetDisplayMode(AIS_Shaded, Standard_True);
TopoDS_Shape box = BRepPrimAPI_MakeBox(10, 10, 10); Handle(AIS_Shape) abox = new AIS_Shape(box); context->Display(abox, Standard_True); view->FitAll();
}
QtWidgetsApplication1::~QtWidgetsApplication1() {}
void QtWidgetsApplication1::paintEvent(QPaintEvent * event) { view->Redraw(); }
QPaintEngine * QtWidgetsApplication1::paintEngine() const { return 0; }
|
