Location>code7788 >text

Qt + OpenCascade development notes (II): windows development environment (II): Qt to introduce occ library, build the basic project template Demo and release Demo

Popularity:865 ℃/2024-07-29 10:41:05

preamble

  Open CASCADE is an open source software development platform developed and supported by Open Cascade SAS, Inc. designed for rapid development of programs for specific domains. It is an object-oriented C++ class library that provides rich functionality for geometric modeling, data exchange and visualization, and has become a core component of many CAD software.
  This article describes the process of setting up a Qt development occ environment.

 

Demo

  Note: The internal QWidgets used are promoted to OccWidgets, and the borders are all 9px by default.
  在这里插入图片描述

 

Compiler version issues

  Since 7.7, which uses deocc, is itself a msvc2015x64 version, Qt uses the msvc2015x64 version of 5.9.3 (the previous post was written as msvc2017x64).
  在这里插入图片描述

 

Build Qt development environment

Step 1: New demo, modularization ideas

   在这里插入图片描述

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

Step 2: Modularize the occ sdk

  Here was going to put all the tripartite libraries into a bin, lib and include under the mix, so that the pro inside to write xcopy script, and then found out that it is not very good, had to keep it alone as is.
  The following start copying, all the folders inside the bin inside the copy to the module under the bin, lib and include to do this operation, here under a single folder have bin, lib and include, only occ does not.

draco-1.4.1-vc14-64: copying bin, include, libs

  在这里插入图片描述

ffmpeg-3.3.4-64: copy bin, include, lib

  在这里插入图片描述

freeimage-3.17.0-vc14-64: copying bin, include, libs

  在这里插入图片描述

freetype-2.5.5-vc14-64: copying bin, include, libs

  在这里插入图片描述

opencascade-7.7.0: copy inc and win64

  header files in inc, bin and lib in win64, keep the relative paths to prevent subsequent tracking of directory consistency.
  在这里插入图片描述

  在这里插入图片描述

openvr-1.14.15-64: copy bin, include, lib

  在这里插入图片描述

qt5.11.2-vc14-64: no copy, we are Qt5.9.3 msvc2017x64 (that's vc14-64)

rapidjson-1.1.0: copy include

  This one is special in that the source files are inside the header file, not generating a library.
  在这里插入图片描述

tbb_2021.5-vc14-64: copy bin, include, lib

  在这里插入图片描述

tcltk-86-64: copy bin, include, lib

  在这里插入图片描述

vtk-6.1.0-vc14-64: copy bin, include, lib

  在这里插入图片描述

Step 3: Configure the pri introduction library

  Header file paths, library file paths and library files are introduced here:

INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

HEADERS += \
    $$PWD/OccManager.h

SOURCES += \
    $$PWD/OccManager.cpp

# occ-7.7.0-msvc2015x64(openCascade-7.7.0-vc14-64)
INCLUDEPATH += $$PWD/occ-7.7.0-msvc2015x64/opencascade-7.7.0/inc
LIBS += -L$$PWD/occ-7.7.0-msvc2015x64/opencascade-7.7.0/win64/vc14/lib
LIBS += -lTKBin
LIBS += -lTKBinL
LIBS += -lTKBinTObj
LIBS += -lTKBinXCAF
LIBS += -lTKBO
LIBS += -lTKBool
LIBS += -lTKBRep
LIBS += -lTKCAF
LIBS += -lTKCDF
LIBS += -lTKD3DHost
LIBS += -lTKD3DHostTest
LIBS += -lTKDCAF
LIBS += -lTKDFBrowser
LIBS += -lTKDraw
LIBS += -lTKernel
LIBS += -lTKExpress
LIBS += -lTKFeat
LIBS += -lTKFillet
LIBS += -lTKG2d
LIBS += -lTKG3d
LIBS += -lTKGeomAlgo
LIBS += -lTKGeomBase
LIBS += -lTKHLR
LIBS += -lTKIGES
LIBS += -lTKIVtk
LIBS += -lTKIVtkDraw
LIBS += -lTKLCAF
LIBS += -lTKMath
LIBS += -lTKMesh
LIBS += -lTKMeshVS
LIBS += -lTKMessageModel
LIBS += -lTKMessageView
LIBS += -lTKOffset
LIBS += -lTKOpenGl
LIBS += -lTKOpenGles
LIBS += -lTKOpenGlesTest
LIBS += -lTKOpenGlTest
LIBS += -lTKPrim
LIBS += -lTKQADraw
LIBS += -lTKRWMesh
LIBS += -lTKService
LIBS += -lTKShapeView
LIBS += -lTKShHealing
LIBS += -lTKStd
LIBS += -lTKStdL
LIBS += -lTKSTEP
LIBS += -lTKSTEP209
LIBS += -lTKSTEPAttr
LIBS += -lTKSTEPBase
LIBS += -lTKSTL
LIBS += -lTKTInspector
LIBS += -lTKTInspectorAPI
LIBS += -lTKTObj
LIBS += -lTKTObjDRAW
LIBS += -lTKToolsDraw
LIBS += -lTKTopAlgo
LIBS += -lTKTopTest
LIBS += -lTKTreeModel
LIBS += -lTKV3d
LIBS += -lTKVCAF
LIBS += -lTKView
LIBS += -lTKViewerTest
LIBS += -lTKVInspector
LIBS += -lTKVRML
LIBS += -lTKXCAF
LIBS += -lTKXDE
LIBS += -lTKXDECascade
LIBS += -lTKXDEDRAW
LIBS += -lTKXDEIGES
LIBS += -lTKXDESTEP
LIBS += -lTKXMesh
LIBS += -lTKXml
LIBS += -lTKXmlL
LIBS += -lTKXmlTObj
LIBS += -lTKXmlXCAF
LIBS += -lTKXSBase
LIBS += -lTKXSDRAW

Step 4: Compilation

  Common errors occur:
  在这里插入图片描述

  Check out the article "About fatal error LNK1158: can't run "" solution" to solve it. (Note: Direct assignment of rc related files to qt's msvc2015_64 version bin folder is the best).
  在这里插入图片描述

  So far, the introduction of the occ library is good, but we still need calls to detect it.

Step 5: Compile and run the test using the demo

  在这里插入图片描述
  It's not enough to just include the opencascade bin (as we expected, but the compilation doesn't bring in the other library libs, so I don't know):
  在这里插入图片描述

  The dlls under the bin of all the previous libraries are needed to get it up and running correctly, but it really doesn't need libs outside of opencascade when compiling.
  The resultant run, with nothing much in the program, releases the deployment package (Qt5.9.3 msvc2017x64 opencascade-7.7.0) with about 220MB, as shown below:
  在这里插入图片描述

  A total of 303 items:
  在这里插入图片描述

 

Demo key source code

protected slots:            // Once displayed, you need to refresh the size of the occ window to make it the same size.
void slot_resize();

protected:                  // Three functions of the parent class need to be overridden
    QPaintEngine* paintEngine() const;
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);

private:        // Occ's proprietary variables
    opencascade::handle<V3d_Viewer> _pV3dViewer;
    opencascade::handle<V3d_View> _pV3dView;
    opencascade::handle<Aspect_DisplayConnection> _pAspectDisplayConnection;
    opencascade::handle<OpenGl_GraphicDriver> _pOpenGLGraphicDriver;
    opencascade::handle<AIS_InteractiveContext> _pAisInteractiveContext;
    WId _wid;
    opencascade::handle<WNT_Window> _pWntWindow;
};
…

void OccWidget::initControl()
{
    // Initialize occ
{
        // Display to screen
setAttribute(Qt::WA_PaintOnScreen);
        // Create a connection to the display device
        _pAspectDisplayConnection= new Aspect_DisplayConnection();
        // Create a 3D interface to define the graphics driver
        _pOpenGLGraphicDriver= new OpenGl_GraphicDriver(_pAspectDisplayConnection);
        // Create the 3D viewer object and specify the graphics driver
        _pV3dViewer= new V3d_Viewer(_pOpenGLGraphicDriver);
        // Create an interactive context object to associate with the 3D viewer
        _pAisInteractiveContext= new AIS_InteractiveContext(_pV3dViewer);
        // Create the view and associate it to the 3D viewer
        _pV3dView= _pV3dViewer->CreateView();
        // Get the window handle and create WNT_Window.
        _wid= winId();
        _pWntWindow= new WNT_Window((Aspect_Handle)_wid);
        // Setting up the view window
        _pV3dView->SetWindow(_pWntWindow);
        if(!_pWntWindow->IsMapped())
        {
            _pWntWindow->Map();
            _pV3dView->Redraw();
        }
        QTimer::singleShot(10, this, SLOT(slot_resize()));
    }
}

void OccWidget::slot_resize()
{
    _pV3dView->MustBeResized();
}

QPaintEngine *OccWidget::paintEngine() const
{
    return 0;
}

void OccWidget::paintEvent(QPaintEvent *event)
{
    if(!_pV3dView.IsNull())
    {
        _pV3dView->Redraw();
    }
    QWidget::paintEvent(event);
}

void OccWidget::resizeEvent(QResizeEvent *event)
{
    if(!_pV3dView.IsNull())
    {
        _pV3dView->MustBeResized();
    }
    QWidget::resizeEvent(event);
}
…
 

fig. make a career out of it

Pitfall 1: Window stretching appears to be a window re-flashing problem

concern

  The stretching is shown below:
  在这里插入图片描述

rationale

  The judgment was swiped but it seemed to be overwritten, then I found out the reason was a code problem when hand coding
  在这里插入图片描述

settle (a dispute)

  在这里插入图片描述

Pitfall 2: Display window will redraw incorrectly the first time

concern

  Show that the problem occurs
  在这里插入图片描述

  Stretching down then refreshes no problem:
  在这里插入图片描述

rationale

  It should be a refreshing problem, the window is refreshed according to some value (indeterminate) before it is fully displayed, which is the same as dynamic layout getting inconsistent size in the construction.

settle (a dispute)

  This one just needs to pick up another slot function in the construct (this one will make sure that it is re-called once after startup).
  在这里插入图片描述

  在这里插入图片描述