Hello World of OpenCascade
eryar@163.com
摘要Abstract:以一個(gè)經(jīng)典的Hello World程序?yàn)槔_始對開源幾何造型內(nèi)核OpenCascade的學(xué)習(xí)。
關(guān)鍵字Key Words:OpenCascade、Qt、Hello World
一、引言 Introduction
OpenCascade編譯成功后,看著大量的代碼,無從下手。本文以Hello World程序?yàn)槔敿?xì)說明使用OpenCascade進(jìn)行編程需要注意的事項(xiàng),以便對OpenCascade做進(jìn)一步學(xué)習(xí)。
選擇的編程工具為Qt Creator,因?yàn)槠湟彩情_源的,其版本信息如下圖所示:
Figure 1.1 About Qt Creator
二、Hello World of OpenCascade
1. 新建工程:在Qt Creator中創(chuàng)建一個(gè)新的工程,選擇Non-Qt Project -> Plain C++ Project,如下圖所示:
Figure 2.1 Create a Plain C++ project in Qt Creator
2. 在工程文件中添加頭文件路徑及所需要用到的庫文件,如下圖所示:
Figure 2.2 Set header file path and library
3. 程序的源代碼如下所示:
1 /*
2 * Copyright (c) 2013 eryar All Rights Reserved.
3 *
4 * File : Main.cpp
5 * Author : eryar@163.com
6 * Date : 2013-08-22 18:52
7 * Version : 1.0v
8 *
9 * Description : Hello World program of OpenCascade.
10 *
11 */
12
13 #include <iostream>
14
15 // OpenCascade library.
16 //#define WNT
17 #include <Standard_CString.hxx>
18
19 int main(void)
20 {
21 Standard_CString strHelloWorld("Hello World!");
22 Standard_CString strHelloOcct("Hello OpenCascade!");
23
24 std::cout << strHelloWorld << std::endl;
25 std::cout << strHelloOcct << std::endl;
26
27 return 0;
28 }
29
4. 程序輸出結(jié)果如下圖所示:
Figure 2.3 Program output
5. 程序代碼說明:
l #include <iostream>:使用了C++的標(biāo)準(zhǔn)輸入輸出,如:std::cout;
l #define WNT:告知OpenCascade程序運(yùn)行在Windows平臺上。若不設(shè)置,當(dāng)編譯器為MSVC時(shí),會出現(xiàn)如下編譯錯誤:
1 // check if WNT macro is not defined but compiler is MSVC
2 #if defined(_MSC_VER) && !defined(WNT)
3 #error "Wrong compiler options has been detected. Add /DWNT option for proper compilation!!!!!"
4 #endif
5
l #include <Standard_CString.hxx>:使用OpenCascade中的字符串;
l 使用了兩個(gè)字符串變量分別輸出“Hello World!”和“Hello OpenCascade!”;
三、結(jié)論 Conclusion
在Qt Creator中以一個(gè)簡單的示例程序,詳細(xì)說明了在Windows平臺使用OpenCascade開發(fā)需要注意的事項(xiàng),為進(jìn)一步研究、學(xué)習(xí)、使用OpenCascade奠定基礎(chǔ)。