OpenCascade

Hello World of OpenCascade

 

Hello World of OpenCascade

eryar@163.com

 

摘要Abstract:以一个经典的Hello World程序为例开始对开源几何造型内核OpenCascade的学习。

关键字Key WordsOpenCascadeQtHello World

 

一、引言 Introduction

OpenCascade编译成功后,看着大量的代码,无从下手。本文以Hello World程序为例,详细说明使用OpenCascade进行编程需要注意的事项,以便对OpenCascade做进一步学习。

选择的编程工具为Qt Creator,因为其也是开源的,其版本信息如下图所示:

Figure 1.1 About Qt Creator

 

 

二、Hello World of OpenCascade

1. 新建工程:在Qt Creator中创建一个新的工程,选择Non-Qt Project -> Plain C++ Project,如下图所示:

wps_clip_image-12094

Figure 2.1 Create a Plain C++ project in Qt Creator

 

2. 在工程文件中添加头文件路径及所需要用到的库文件,如下图所示:

wps_clip_image-1389

Figure 2.2 Set header file path and library

 

3. 程序的源代码如下所示:

/*

*    Copyright (c) 2013 eryar All Rights Reserved.

*

*        File    : Main.cpp

*        Author  : eryar@163.com

*        Date    : 2013-08-22 18:52

*        Version : 1.0v

*

*    Description : Hello World program of OpenCascade.

*

*/

 

#include <iostream>

 

// OpenCascade library.

#define WNT

#include <Standard_CString.hxx>

 

int main(void)

{

   Standard_CString strHelloWorld("Hello World!");

   Standard_CString strHelloOcct("Hello OpenCascade!");

 

   std::cout << strHelloWorld << std::endl;

   std::cout << strHelloOcct << std::endl;

 

   return 0;

}

 

4. 程序输出结果如下图所示:

wps_clip_image-27256

Figure 2.3 Program output

 

5. 程序代码说明:

#include <iostream>:使用了C++的标准输入输出,如:std::cout

#define WNT:告知OpenCascade程序运行在Windows平台上。若不设置,当编译器为MSVC时,会出现如下编译错误:

// check if WNT macro is not defined but compiler is MSVC

#if defined(_MSC_VER) && !defined(WNT)

#error "Wrong compiler options has been detected. Add /DWNT option for proper compilation!!!!!"

#endif

 

#include <Standard_CString.hxx>:使用OpenCascade中的字符串;

使用了两个字符串变量分别输出“Hello World!”和“Hello OpenCascade!”;

 

 

三、结论 Conclusion

Qt Creator中以一个简单的示例程序,详细说明了在Windows平台使用OpenCascade开发需要注意的事项,为进一步研究、学习、使用OpenCascade奠定基础。

 

PDF Version: Hello World of OpenCascade

 
 
原文地址:https://www.cnblogs.com/Leo_wl/p/3276445.html