OCCT7.6安装后,得到以下几个文件夹
两个灰色文件夹是我自己建的,一个放occt的工程,一个是第三方库的DLL文件
添加一个QT工程
在vs环境下,老三样:
1 包含目录:D:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc
2 库目录 :D:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\win64\vc14\libd
tips:这里是用的调试环境,所有用libd ,d表示调试版静态库文件
3 链接器依赖项:
DRAWEXE.lib
TKBin.lib
TKBinL.lib
TKBinTObj.lib
TKBinXCAF.lib
TKBO.lib
TKBool.lib
TKBRep.lib
TKCAF.lib
TKCDF.lib
TKD3DHost.lib
TKD3DHostTest.lib
TKDCAF.lib
TKDraw.lib
TKernel.lib
TKFeat.lib
TKFillet.lib
TKG2d.lib
TKG3d.lib
TKGeomAlgo.lib
TKGeomBase.lib
TKHLR.lib
TKIGES.lib
TKIVtk.lib
TKIVtkDraw.lib
TKLCAF.lib
TKMath.lib
TKMesh.lib
TKMeshVS.lib
TKOffset.lib
TKOpenGl.lib
TKOpenGlTest.lib
TKPrim.lib
TKQADraw.lib
TKRWMesh.lib
TKService.lib
TKShHealing.lib
TKStd.lib
TKStdL.lib
TKSTEP.lib
TKSTEP209.lib
TKSTEPAttr.lib
TKSTEPBase.lib
TKSTL.lib
TKTObj.lib
TKTObjDRAW.lib
TKTopAlgo.lib
TKTopTest.lib
TKV3d.lib
TKVCAF.lib
TKViewerTest.lib
TKVRML.lib
TKXCAF.lib
TKXDEDRAW.lib
TKXDEIGES.lib
TKXDESTEP.lib
TKXMesh.lib
TKXml.lib
TKXmlL.lib
TKXmlTObj.lib
TKXmlXCAF.lib
TKXSBase.lib
TKXSDRAW.lib
还有就是动态链接库(DLL)
在项目右键属性,找到调试,这里设置DLL位置,我是将所有第三方库的DLL囊括一块儿了
当然还有OCC的DLL
编译通过就可以看见小窗口了。
以下是所有的文件
occview.h:
#pragma once
#include<QWidget>
#include<QEvent>
#include<QMouseEvent>
#include<QPaintEngine>
#include<AIS_InteractiveContext.hxx>
#include<OpenGl_GraphicDriver.hxx>
#include<V3d_View.hxx>
#include<V3d_Viewer.hxx>
#include"ui_occview.h"
class OccView : public QWidget
{
Q_OBJECT
public:
OccView(QWidget *parent);
~OccView();
private:
Ui::Form *ui;
Handle(AIS_InteractiveContext) m_context;
Handle(V3d_Viewer) m_viewer;
Handle(V3d_View) m_view;
Handle(Graphic3d_GraphicDriver) m_graphic_driver;
public:
QPaintEngine* paintEngine() const;
Handle(AIS_InteractiveContext) GetInteractiveContext();
Handle(V3d_View) GetView();
protected:
void paintEvent(QPaintEvent* event);
void resizeEvent(QResizeEvent* event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
protected:
enum CurrentAction
{
CurrentAction_Nothing,
CurrentAction_Panning,
CurrentAction_Zooming,
CurrentAction_Rotation
};
private:
Standard_Integer m_x;
Standard_Integer m_y;
CurrentAction m_current_mode;
};
occview.cpp
#include<windows.h>
#include"occview.h"
#include"ui_occview.h"
#include"WNT_Window.hxx"
#include<Quantity_NameOfColor.hxx>
OccView::OccView(QWidget *parent)
: QWidget(parent)
{
ui->setupUi(this);
if (m_context.IsNull()) {
Handle(Aspect_DisplayConnection) m_display_connection = new Aspect_DisplayConnection();
if (m_graphic_driver.IsNull())
{
m_graphic_driver = new OpenGl_GraphicDriver(m_display_connection);
}
WId window_handle = (WId)winId();
Handle(WNT_Window) wind = new WNT_Window((Aspect_Handle)window_handle);
m_viewer = new V3d_Viewer(m_graphic_driver);
m_view = m_viewer->CreateView();
m_view->SetWindow(wind);
if (!wind->IsMapped()) {
wind->Map();
}
m_context = new AIS_InteractiveContext(m_viewer);
m_viewer->SetDefaultLights();
m_viewer->SetLightOn();
m_view->SetBackgroundColor(Quantity_NOC_GRAY60);
m_view->MustBeResized();
m_view->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_GOLD,0.08,V3d_ZBUFFER);
m_context->SetDisplayMode(AIS_Shaded,Standard_True);
}
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setBackgroundRole(QPalette::NoRole);
setFocusPolicy(Qt::StrongFocus);
setMouseTracking(TRUE);
}
OccView::~OccView()
{}
QPaintEngine * OccView::paintEngine() const
{
return nullptr;
}
Handle(AIS_InteractiveContext) OccView::GetInteractiveContext()
{
return m_context;
}
Handle(V3d_View) OccView::GetView()
{
return m_view;
}
void OccView::paintEvent(QPaintEvent * event)
{
m_view->Redraw();
}
void OccView::resizeEvent(QResizeEvent * event)
{
if (!m_view.IsNull())
{
m_view->MustBeResized();
}
}
void OccView::mousePressEvent(QMouseEvent * event)
{
// 左键拖动
if (event->buttons() & Qt::LeftButton)
{
m_current_mode = CurrentAction_Panning;
m_x = event->pos().x();
m_y = event->pos().y();
}
else if (event->buttons() & Qt::RightButton)
{
//按住中键进行旋转
m_current_mode = CurrentAction_Rotation;
m_view->StartRotation(event->pos().x(), event->pos().y());
}
}
void OccView::mouseReleaseEvent(QMouseEvent * event)
{
m_current_mode = CurrentAction_Nothing;
}
void OccView::wheelEvent(QWheelEvent * event)
{
m_view->StartZoomAtPoint(event->pos().x(), event->pos().y());
m_view->ZoomAtPoint(0, 0, event->angleDelta().y(), 0);
}
void OccView::mouseMoveEvent(QMouseEvent * event)
{
switch (m_current_mode)
{
case CurrentAction_Panning:
m_view->Pan(event->pos().x() - m_x, m_y - event->pos().y());
m_x = event->pos().x();
m_y = event->pos().y();
break;
case CurrentAction_Rotation:
m_view->Rotation(event->pos().x(), event->pos().y());
break;
default:
break;
}
}
occ_demo2.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_occ_demo2.h"
#include "occview.h"
#include "QMenu"
#include <QMenuBar>
#include <QAction>
#include <QMessageBox>
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include "AIS_Shape.hxx"
class OCC_DEMO2 : public QMainWindow
{
Q_OBJECT
public:
OCC_DEMO2(QWidget *parent = nullptr);
~OCC_DEMO2();
private:
Ui::OCC_DEMO2Class* ui;
OccView* occView;
private:
void InitMenu();
TopoDS_Shape createBox();
TopoDS_Shape createSphere();
private slots:
void trigerMenu(QAction* action);
};
occ_demo2.cpp
#include "occ_demo2.h"
OCC_DEMO2::OCC_DEMO2(QWidget *parent)
: QMainWindow(parent)
{
ui->setupUi(this);
occView = new OccView(this);
setCentralWidget(occView);
InitMenu();
}
OCC_DEMO2::~OCC_DEMO2()
{}
void OCC_DEMO2::InitMenu()
{
QMenuBar* menuBar = ui->menuBar;
QMenu* menuCreate = menuBar->addMenu(tr("&Create"));
menuCreate->addAction(tr("&Box"));
menuCreate->addAction(tr("&Sphere"));
connect(menuBar,SIGNAL(triggered(QAction*)),this,SLOT(trigerMenu(QAction*)));
}
TopoDS_Shape OCC_DEMO2::createBox()
{
return BRepPrimAPI_MakeBox(10.0, 10.0, 10.0).Shape();
}
TopoDS_Shape OCC_DEMO2::createSphere()
{
return BRepPrimAPI_MakeSphere(10.0).Shape();
}
void OCC_DEMO2::trigerMenu(QAction* action)
{
if (action->text()=="&Box")
{
TopoDS_Shape box = createBox();
Handle(AIS_Shape) aisBox = new AIS_Shape(box);
occView->GetInteractiveContext()->Display(aisBox,Standard_True);
occView->GetView()->FitAll();
}
else if (action->text()=="&Sphere")
{
TopoDS_Shape sphere = createSphere();
Handle(AIS_Shape) aisSphere = new AIS_Shape(sphere);
occView->GetInteractiveContext()->Display(aisSphere, Standard_True);
occView->GetView()->FitAll();
}else
{
QMessageBox::warning(this, tr("Warning"), action->text());
}
}
main.cpp
#include "occ_demo2.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
OCC_DEMO2 w;
w.show();
return a.exec();
}
编译成功,运行->