天天看點

OpenCascade Draw Test Harness

Abstract. Draw is a command interpreter based on Tcl/Tk and a graphical system used to test and demonstrate OpenCascade modeling libraries. It provides a flexible and easy to use means of testing and demonstrating the OCCT modeling libraries. By a given command of Tcl, you can find the implentation code for that command by OpenCascade, the code could be as a demo to use of OCC modeling libraries. So this is the most effectively way of use OpenCascade. Key words. OpenCascade, Tcl/Tk, Testing,

OpenCascade Draw Test Harness

[email protected]

Abstract. Draw is a command interpreter based on Tcl/Tk and a graphical system used to test and demonstrate OpenCascade modeling libraries. It provides a flexible and easy to use means of testing and demonstrating the OCCT modeling libraries. By a given command of Tcl, you can find the implentation code for that command by OpenCascade, the code could be as a demo to use of OCC modeling libraries. So this is the most effectively way of use OpenCascade. 

Key words. OpenCascade, Tcl/Tk, Testing, Scripts

1. Introduction

Draw Test Harness提供了靈活和易于使用的方式來測試、示範OpenCascade的模組化算法。可用來互動的建立、顯示和修改曲線、曲面及拓樸形狀。你也可以自己寫Tcl腳本來自定義Draw或使用腳本來實作自動化測試。也可以為Draw添加新的自定義的指令。 

因為Draw是基于Tcl/Tk腳本的,是以可以根據OpenCascade自定義的指令名稱來找到相關的實作,這個實作應該是使用OpenCascade最有效的方式,也是官方使用OpenCascade的方式,具有很好的參考價值。 

還可在Draw 中使用Tcl腳本來實作概念模組化,如果結果和預期一緻,可再把Tcl指令相對應的C++代碼寫到程式中,提高程式設計效率。 

本文主要介紹如何根據OpenCascade中實作的指令找到相關的實作代碼,作為程式設計時的參考,避免了用C++代碼來實作一些功能時自己來摸索,進而浪費不必要的時間。 

2. Using Tcl/Tk

先給出Draw中使用腳本出來的效果的例子,再介紹找出指令實作代碼的方法。如下圖所示為用腳本在Draw中産生的效果: 

OpenCascade Draw Test Harness

Figure 2.1 A blend test in Draw Test Harness 

其實作的腳本如下所示:

pload ALL

vinit
vgrid

vsetgradientbg 0 0 180 255 255 255 2

vzbufftrihedron

# run a test
source tests/blend/begin
source tests/blend/buildevol/a2

vsetdispmode 1
vdisplay result
vfit      
OpenCascade Draw Test Harness

Figure 2.2 Tcl script 

将上述腳本代碼儲存到samples/tcl檔案夾下,檔案名為init.tcl,再啟動Draw,輸入指令: 

OpenCascade Draw Test Harness

Figure 2.3 Use the Tcl file 

3. Find code from Draw Test

因為Draw是基于Tcl/Tk實作的解釋器,是以根據Tcl中自定義指令的方法,可以找出OpenCascade中這些指令的實作代碼。更友善的做法是直接輸入指令名稱,再在所有的源代碼中搜尋相關檔案即可。如上述腳本中的vgrid指令,是打開、關閉栅格,可以直接搜尋vgrid,得到結果如下所示: 

OpenCascade Draw Test Harness

Figure 3.1 Find command in Files 

OpenCascade Draw Test Harness

Figure 3.2 Find Result of the Command 

得到相關的代碼使用方法如下圖所示: 

OpenCascade Draw Test Harness

Figure 3.3 The Command function code 

依此類推,其他Draw中的指令都可以找到相關的實作代碼,這些代碼都可作為程式設計的依據,有助于OpenCascade的正确、高效使用。 

4. Conclusion

從上可知,如果需要OpenCascade的什麼功能,可以先在Draw Test Harness中試試看,如果在Draw Test Harness中可以實作,再找出其實作那個指令的代碼,再參考代碼實作所需要功能即可。這樣程式設計使用OpenCascade應該是輕松和高效的,因為Tcl是解釋執行,不像C++那樣需要編譯時間。 

5. References

1. Tcl and the Tk Toolkit 

2. Practical Programming in Tcl and Tk 

3. Tcl/Tk A Developer’s Guide 

4. OpenCascade Test Harness User’s Guide  

繼續閱讀