Wed, 12/02/2020 - 16:09
Forums:
I had wrote the code by referring the sample code of occt7.5. However, I met a problem. When I run the program, the view of occt cannt show on the QWidget. When I open anthoer window on the view, the view will not display. I have to input an occt command to display the view when I meet the same problem, such as rotation, zoom , display an object. Here is my code:
OCCView::OCCView(QWidget * widget)
{
initViewer();
initView(widget);
initContext();
}
void OCCView::initViewer()
{
static Handle(OpenGl_GraphicDriver) aGraphicDriver;
if (aGraphicDriver.IsNull())
{
Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
aGraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
}
aViewer = new V3d_Viewer(aGraphicDriver);
aViewer->InitActiveLights();
aViewer->SetDefaultViewSize(1000.);
aViewer->SetDefaultViewProj(V3d_XposYnegZpos);
aViewer->SetComputedMode(Standard_True);
aViewer->SetDefaultComputedMode(Standard_True);
aViewer->SetDefaultLights();
aViewer->SetLightOn();
aViewer->ActivateGrid(Aspect_GridType::Aspect_GT_Rectangular, Aspect_GridDrawMode::Aspect_GDM_Lines);
}
void OCCView::initView(QWidget * widget)
{
wind = new WNT_Window((Aspect_Handle)widget->winId());
aView = aViewer->CreateView();
aView->MustBeResized();
aView->SetWindow(wind);
if (!wind->IsMapped())
{
wind->Map();
//widget->update();
}
aView->SetBgGradientColors(Quantity_Color(1., 1., 1., Quantity_TypeOfColor::Quantity_TOC_RGB),
Quantity_Color(0.4, 0.6, 0.8, Quantity_TypeOfColor::Quantity_TOC_RGB),
Aspect_GradientFillMethod::Aspect_GFM_DIAG1, Standard_True);
/*aView->ZBufferTriedronSetup(Quantity_NOC_RED, Quantity_NOC_BLUE1, Quantity_NOC_GREEN, 1, 0.05, 12);
aView->TriedronDisplay(Aspect_TOTP_LEFT_UPPER, Quantity_NOC_RED,
0.08, V3d_ZBUFFER);*/
aView->SetImmediateUpdate(Standard_True);
aView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
aView->FitAll();
aView->AutoZFit();
}
void OCCView::initContext()
{
aContext = new AIS_InteractiveContext(aViewer);
aContext->SetDisplayMode(AIS_DisplayMode::AIS_Shaded, Standard_True);
aContext->UpdateCurrentViewer();
}
Also I had rewrite the the function of Qwidget:
void OCCWidget::paintEvent(QPaintEvent* e)
{
occView->view()->Redraw();
occView->view()->InvalidateImmediate();
FlushViewEvents(occView->context(), occView->view(), true);
}
void OCCWidget::resizeEvent(QResizeEvent* event)
{
if (!occView->view().IsNull())
{
occView->view()->MustBeResized();
}
}
QPaintEngine* OCCWidget::paintEngine()
{
return 0;
}
How can I solve this problem?