0% found this document useful (0 votes)
40 views

OCCT源码学习

Uploaded by

网不行自己
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

OCCT源码学习

Uploaded by

网不行自己
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

源码学习

OCCT 源码学习

姜豪
2023 年 6 月
目录

1. 编译记录................................................................................................. 1

1.1 概况.................................................................................................................. 1
1.2 基本情况.............................................................................................................. 1
1.3 第三方库编译........................................................................................................... 1
1.3.1 TCL 8.6.13【OCC 的 DRAW 模块依赖】...............................................................1
1.3.2 TK 8.6.13【OCC 的 DRAW 模块依赖】.................................................................4
1.3.3 FreeType 2.13.1......................................................................................6
1.3.4 oneTBB 2021.9.0....................................................................................6
1.3.5 FreeImage 3.18.0....................................................................................6
1.3.6 VTK-9.2.6................................................................................................ 7
1.4 编译 OCCT......................................................................................................... 7

2. 代码学习...............................................................................................15
1. 编译记录

1.1 概况

在 VS 2017 环境下,从第三方依赖开始,编译 64 位 OCCT。

1.2 基本情况

 本次编译的版本是 7.7.0;
 支持的编译平台有:

OS Compiler

Microsoft Visual Studio: 2015 Update 3, 2017 1,


Windows 2019, 2022
, LLVM (ClangCL), GCC 4.3+ (Mingw-w64)

GNU gcc 4.3+


Linux
LLVM CLang 3.6+

OS X /
XCode 6 or newer
macOS

Android NDK r12, GNU gcc 4.9 or newer

Web Emscripten SDK 1.39 or newer (CLang)

VC++ 141 64-bit【本次编译也在该配置下进行】是推荐的编译环境,OCCT 的常规测试和官方发布的二


进制包都是在此编译环境下进行的。
 参考官方文档:“Open CASCADE Technology”-“Build, Debug and Upgrade”

1.3 第三方库编译

1.3.1 TCL 8.6.13【OCC 的 DRAW 模块依赖】

官方指南对 TCL\TK 原有编译管理脚本有一些破坏!!


1) 从 https://www.tcl.tk/software/tcltk/download.html 下载源码
2) 在目录“tcl8.6.13\win”下存在文件批处理脚本 buildall.vc.bat
改脚本配置实际上是对 namke 命令调用的一个封装,namke 命令本质上是将一个 buildall.vc.bat 同目录下的

makefile.vc 作为编译参数。但要进入 vs 命令提示环境需要调用 vcvarsXXX.bat 脚本,这个脚本在不同的编

1
译器版本里是不同的。比如,原有的 buildall.vc.bat 脚本指定的路径是

直接运行该脚本会报路径错误。

直接运行原有脚本会报错

我的电脑上 Visual Studio 2017 的 Visual Studio Tools 路径

我的电脑上 Visual Studio 2015-2022 的 Visual Studio Tools 路径

另一方面,buildall.vc.bat 脚本中指定了编译后结果的安装路径,我们也需要对其进行调整。

3) 做如下几处修改:
a) 指定系统的开发者环境

b) 指定编译结果安装路径

c) 为第一次调用 nmake 添加安装路径

2
d) 删除第二个 nmake

e) 修改 rules.vc

f) 将动态运行时库改为静态运行时库
/MT 是 "multithread, static version ” 意思是多线程静态的版本,定义了它后,编译
器把 LIBCMT.lib 安置到 OBJ 文件中,让链接器使用 LIBCMT.lib 处理外部符号。
/MD 是 "multithread- and DLL-specific version” ,意思是多线程 DLL 版
本,定义了它后,编译器把 MSVCRT.lib 安置到 OBJ 文件中,它连接到 DLL 的方式是静态链接,
实际上工作的库是 MSVCR80.DLL。
即:
静态运行时库:LIBCMT.lib
动态运行时库:MSVCRT.lib + MSVCR80.DLL

这是修改的 makefile.vc
实际应该修改 rules.vc:
3
Mode LastWriteTime Length Name

---- ------------- ------ ----

-a---- 2023/6/25 16:12 1679360 tcl86.dll

-a---- 2023/6/25 16:12 78336 tclsh86.exe

-a---- 2022/10/27 19:52 134656 zlib1.dll

仅修改 makefile.vc:
Mode LastWriteTime Length Name

---- ------------- ------ ----

-a---- 2023/6/25 15:44 1670144 tcl86.dll

-a---- 2023/6/25 15:44 70144 tclsh86.exe

-a---- 2022/10/27 19:52 134656 zlib1.dll

g) 注释掉 generic\tclMain.c 的 isatty()函数的前置声明

4) 运行两次 buildall.vc.bat
5) 拷贝 tclsh76.exe,重命名为 tclsh.exe

1.3.2 TK 8.6.13【OCC 的 DRAW 模块依赖】

对 TCL 的操作对 TK 再来一遍。


1) 做如下几处修改:
a) 指定系统的开发者环境

b) 指定编译结果安装路径

c) 指定 tcl 源码路径

4
d) 为第一次调用 nmake 添加安装路径
e) 删除第二个 nmake

f) 修改 rules.vc

g) 将动态运行时库改为静态运行时库

h) 注释掉 generic\tkMain.c 的 isatty()函数的前置声明【实际上应该不需要注释】

5
2) 运行一次 buildall.vc.bat
3) 拷贝 wish86.exe,重命名为 wish.exe

1.3.3 FreeType 2.13.1

直接从官网下载源文件,在路径 freetype-2.13.1\builds\windows\vc2010 下有配置好的 sln,可直接


编译。将不同的编译结果放置在设定好的路径下。【编译为动态库】

1.3.4 oneTBB 2021.9.0

在 github 的 Release 页面下载编译好的 win 平台的二进制文件。


【不再从源码编译了,可能会很麻烦】

1.3.5 FreeImage 3.18.0

内有配置好的 sln,直接编译即可。

1.3.6 VTK-9.2.6

从官网下载源码,使用 CMake 配置【VTK 和 CMake 都是 Kitware 出的,一家产品,用 CMake 还是


比较丝滑】。

6
1.4 编译 OCCT

1) 设置目录

Source:源目录

Build:构建目录

Installation:安装目录

2) 一些 CMake 编译选项的设置

Variable Type Purpose 说明

Specifies the build type 没找到


on single-configuration
generators (such as
CMAKE_BUILD_TYPE String
make). Possible values
are Debug, Release and
RelWithDebInfo

Indicates whether 是
FreeType product should
USE_FREETYPE Boolean
be used in OCCT for text
rendering

Indicates whether 是
FreeImage product
should be used in OCCT
USE_FREEIMAGE Boolean visualization module for
support of popular
graphics image formats
(PNG, BMP, etc.)

Indicates whether 否
OpenVR product should
USE_OPENVR Boolean be used in OCCT
visualization module for
support of Virtual Reality

USE_OPENGL Boolean Indicates whether 是

7
TKOpenGl graphic driver
using OpenGL library
(desktop) should be
built within OCCT
visualization module

Indicates whether 否
TKOpenGles graphic
driver using OpenGL ES
USE_GLES2 Boolean library (embedded
OpenGL) should be built
within OCCT
visualization module

Indicates whether 否
RapidJSON product
should be used in OCCT
USE_RAPIDJSON Boolean
Data Exchange module
for support of glTF mesh
file format

Indicates whether Draco 否


product should be used
in OCCT Data Exchange
USE_DRACO Boolean
module for support of
Draco compression in
glTF mesh file format

Indicates whether Tcl/Tk 是


product should be used
in OCCT Draw Harness
USE_TK Boolean module for user
interface (in addition to
Tcl, which is mandatory
for Draw Harness)

Indicates whether TBB 是


(Threading Building
Blocks) 3rd party is used
USE_TBB Boolean
or not. Note that OCCT
remains parallel even
without TBB product

USE_VTK Boolean Indicates whether VTK 是


3rd party is used or not.

8
OCCT comes with a
bridge between CAD
data representation and
VTK by means of its
dedicated VIS
component (VTK
Integration Services).
You may skip this 3rd
party unless you are
planning to use VTK
visualization for OCCT
geometry. See the
official
documentation VTK
Integration Services
(VIS) for the details on
VIS

Defines the root E:/OCCT-


directory where all 7.7.0/3rdparty
required 3rd party
products will be
searched. Once you
3RDPARTY_DIR Path define this path it is
very convenient to click
"Configure" button in
order to let CMake
automatically detect all
necessary products

3RDPARTY_FREETYPE Path to FreeType Done


Path
_* binaries

3RDPARTY_TCL_* Done
Path Path to Tcl/Tk binaries
3RDPARTY_TK_*

3RDPARTY_FREEIMAG Path to FreeImage Done


Path
E* binaries

3RDPARTY_TBB* Path Path to TBB binaries

3RDPARTY_VTK_* Path Path to VTK binaries Done

BUILD_MODULE_<MO Boolean Indicates whether the All


DULE> corresponding OCCT

9
module should be built
or not. It should be
noted that some toolkits
of a module can be built
even if this module is
not checked (this
happens if some other
modules depend on
these toolkits). The main
modules and their
descriptions can be
found in User Guides

Specifies the type of Shared


library to be created.
"Shared" libraries are
linked dynamically and
loaded at runtime.
"Static" libraries are
archives of object files
BUILD_LIBRARY_TYPE String
used when linking other
targets. Note that Draw
Harness plugin system
is incompatible with
"Static" builds, and
therefore it is disabled
for these builds.

Semicolon-separated None
individual toolkits to
include into build
process. If you want to
build some particular
libraries (toolkits) only,
then you may uncheck
BUILD_ADDITIONAL_T
String all modules in the
OOLKITS
corresponding BUILD_M
ODUE_<MODULE> optio
ns and provide the list of
necessary libraries here.
Of course, all
dependencies will be
resolved automatically

10
Enables Flex/Bison No
lexical analyzers. OCCT
source files relating to
STEP reader and
ExprIntrp functionality
are generated
BUILD_YACCLEX Boolean automatically with
Flex/Bison. Checking
this option leads to
automatic search of
Flex/Bison binaries and
regeneration of the
mentioned files

Indicates whether MFC No


samples should be built 设 置 此 选 项 会 通 不 过
BUILD_SAMPLES_MFC Boolean together with OCCT. This CMake
option is only relevant to
Windows platforms

Indicates whether QT Yes


BUILD_SAMPLES_QT Boolean samples should be built
together with OCCT.

Indicates whether Yes


BUILD_Inspector Boolean Inspector should be built
together with OCCT.

Indicates whether OCCT Yes


overview documentation
project should be
created together with
OCCT. It is not built
together with OCCT.
Checking this option
BUILD_DOC_Overview Boolean
leads to automatic
search of Doxygen
binaries. Its building
calls Doxygen command
to generate the
documentation in HTML
format

BUILD_PATCH Path Points to the directory None


recognized as a "patch"

11
for OCCT. If specified,
the files from this
directory take
precedence over the
corresponding native
OCCT sources. This way
you are able to
introduce patches to
Open CASCADE
Technology not affecting
the original source
distribution

Enables extended Yes


messages of many
OCCT algorithms,
usually printed to cout.
BUILD_WITH_DEBUG Boolean These include messages
on internal errors and
special cases
encountered, timing,
etc.

Enable/Disable the No
floating point exceptions
(FPE) during DRAW
execution only.
Corresponding
BUILD_ENABLE_FPE_S
Boolean environment variable
IGNAL_HANDLER
(CSF_FPE) can be
changed manually in
custom.bat/sh scripts
without regeneration by
CMake.

Employ corresponding C++11


BUILD_CPP_STANDAR c++ standard (C++11,
String
D C++14, ..C++23) for
building OCCT

CMAKE_CONFIGURATI Semicolon-separated
String
ON_TYPES CMake configurations

INSTALL_DIR Path Points to the installation E:/OCCT-7.7.0/


directory. INSTALL_DIR is opencascade-

12
a synonym 7.7.0-install
of CMAKE_INSTALL_PREF
IX. The user can specify
both INSTALL_DIR or CM
AKE_INSTALL_PREFIX

Relative path to the


binaries installation
INSTALL_DIR_BIN Path directory (absolute path
is ${INSTALL_DIR}/$
{INSTALL_DIR_BIN})

Relative path to the


scripts installation
INSTALL_DIR_SCRIPT Path directory (absolute path
is ${INSTALL_DIR}/$
{INSTALL_DIR_SCRIPT})

Relative path to the


libraries installation
INSTALL_DIR_LIB Path directory (absolute path
is ${INSTALL_DIR}/$
{INSTALL_DIR_LIB})

Relative path to the


includes installation
INSTALL_DIR_INCLUD directory (absolute path
Path
E is ${INSTALL_DIR}/$
{INSTALL_DIR_INCLUDE}
)

Relative path to the


resources installation
INSTALL_DIR_RESOUR directory (absolute path
Path
CE is ${INSTALL_DIR}/$
{INSTALL_DIR_RESOURC
E})

INSTALL_DIR_LAYOUT String Defines the structure of


OCCT files (binaries,
resources, headers, etc.)
for the install directory.
Two variants are
predefined: for Windows
(standard OCCT layout)

13
and for Unix operating
systems (standard Linux
layout). If needed, the
layout can be
customized with
INSTALL_DIR_* variables

Relative path to the data


files installation
INSTALL_DIR_DATA Path directory (absolute path
is ${INSTALL_DIR}/$
{INSTALL_DIR_DATA})

Relative path to the


samples installation
directory. Note that only
"samples/tcl" folder will
INSTALL_DIR_SAMPLE
Path be installed. (absolute
S
path is $
{INSTALL_DIR}/$
{INSTALL_DIR_SAMPLES
})

Relative path to the


tests installation
INSTALL_DIR_TESTS Path directory (absolute path
is ${INSTALL_DIR}/$
{INSTALL_DIR_TESTS})

Relative path to the


documentation
installation directory
INSTALL_DIR_DOC Path
(absolute path is $
{INSTALL_DIR}/$
{INSTALL_DIR_DOC})

Indicates whether Yes


FreeType binaries should
INSTALL_FREETYPE Boolean
be installed into the
installation directory

Indicates whether Yes


FreeImage binaries
INSTALL_FREEIMAGE Boolean
should be installed into
the installation directory

14
Indicates whether TBB Yes
binaries should be
INSTALL_TBB Boolean
installed into the
installation directory

Indicates whether VTK Yes


binaries should be
INSTALL_VTK Boolean
installed into the
installation directory

Indicates whether TCL Yes


binaries should be
INSTALL_TCL Boolean
installed into the
installation directory

Indicates whether non- Yes


regression OCCT test
INSTALL_TEST_CASES Boolean scripts should be
installed into the
installation directory

Indicates whether OCCT Yes


INSTALL_DOC_Overvi overview documentation
Boolean
ew should be installed into
the installation directory

3) 设置好之后即可生成 sln,然后通过编译。可以使用管理员模式打开 VS,这样可以通过项目 INSTALL 的编


译【即完成编译结果的安装】。
4) 示例程序的调试需要添加 dll 文件的目录,考虑到 INSTALL 时,已经统一将第三方库的 dll 移动到了安装目
录下,可以直接将 Samples 程序的调试环境添加一个安装目录。

15
2. Quaoar Workshop

16
17
18

You might also like