OpenCascade Draw Test Harness
eryar@163.com
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的建模算法??捎脕斫换サ膭?chuàng)建、顯示和修改曲線、曲面及拓樸形狀。你也可以自己寫Tcl腳本來自定義Draw或使用腳本來實現(xiàn)自動化測試。也可以為Draw添加新的自定義的命令。
因為Draw是基于Tcl/Tk腳本的,所以可以根據(jù)OpenCascade自定義的命令名稱來找到相關(guān)的實現(xiàn),這個實現(xiàn)應(yīng)該是使用OpenCascade最有效的方式,也是官方使用OpenCascade的方式,具有很好的參考價值。
還可在Draw 中使用Tcl腳本來實現(xiàn)概念建模,如果結(jié)果和預(yù)期一致,可再把Tcl命令相對應(yīng)的C++代碼寫到程序中,提高編程效率。
本文主要介紹如何根據(jù)OpenCascade中實現(xiàn)的命令找到相關(guān)的實現(xiàn)代碼,作為編程時的參考,避免了用C++代碼來實現(xiàn)一些功能時自己來摸索,從而浪費不必要的時間。
2. Using Tcl/Tk
先給出Draw中使用腳本出來的效果的例子,再介紹找出命令實現(xiàn)代碼的方法。如下圖所示為用腳本在Draw中產(chǎn)生的效果:
Figure 2.1 A blend test in Draw Test Harness
其實現(xiàn)的腳本如下所示:
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
Figure 2.2 Tcl script
將上述腳本代碼保存到samples/tcl文件夾下,文件名為init.tcl,再啟動Draw,輸入命令:
Figure 2.3 Use the Tcl file
3. Find code from Draw Test
因為Draw是基于Tcl/Tk實現(xiàn)的解釋器,所以根據(jù)Tcl中自定義命令的方法,可以找出OpenCascade中這些命令的實現(xiàn)代碼。更方便的做法是直接輸入命令名稱,再在所有的源代碼中搜索相關(guān)文件即可。如上述腳本中的vgrid命令,是打開、關(guān)閉柵格,可以直接搜索vgrid,得到結(jié)果如下所示:
Figure 3.1 Find command in Files
Figure 3.2 Find Result of the Command
得到相關(guān)的代碼使用方法如下圖所示:
Figure 3.3 The Command function code
依此類推,其他Draw中的命令都可以找到相關(guān)的實現(xiàn)代碼,這些代碼都可作為編程的依據(jù),有助于OpenCascade的正確、高效使用。
4. Conclusion
從上可知,如果需要OpenCascade的什么功能,可以先在Draw Test Harness中試試看,如果在Draw Test Harness中可以實現(xiàn),再找出其實現(xiàn)那個命令的代碼,再參考代碼實現(xiàn)所需要功能即可。這樣編程使用OpenCascade應(yīng)該是輕松和高效的,因為Tcl是解釋執(zhí)行,不像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
5. http://sourceforge.net/projects/tcl/
5. http://www.tcl.tk/