写了一段最短的集成OCC Draw命令的Demo,C++程序中可自由地运行Tcl/Tk脚本了。里面的代码都参考OCC Draw中的核心逻辑。
#include "Draw.hxx"
#include "DBRep.hxx"
#include "DrawTrSurf.hxx"
#include "TopExp_Explorer.hxx"
#include "TopoDS_Face.hxx"
#include "TopoDS_Vertex.hxx"
#include "TopoDS.hxx"
#include "Bnd_Box.hxx"
#include "BRep_Builder.hxx"
#include <tcl.h>
#include "BRepTools.hxx"
int runCmd(const char* cmd) {
const Draw_PInterp inter = Draw::GetInterpretor().Interp();
int ret = Tcl_RecordAndEval(inter, cmd, false);
if (*Tcl_GetStringResult(inter)) {
std::cout << Tcl_GetStringResult(inter) << std::endl;
}
std::cout << "cmd ret:" << ret << std::endl;
return ret;
}
int main() {
// 初始化TK解析器
Draw_Interpretor& aCommands = Draw::GetInterpretor();
aCommands.Init();
Tcl_Interp* interp = aCommands.Interp();
Tcl_Init(interp);
// 注册Draw的命令, 并运行pload ALL
Draw::Commands(aCommands);
DBRep::BasicCommands(aCommands);
DrawTrSurf::BasicCommands(aCommands);
runCmd("pload ALL");
// 执行命令
runCmd("box cc 1 2 3");
//runCmd("dump cc");
// 获取命令创建的TopoDS_Shape
const char* na = "cc";
TopoDS_Shape aS1 = DBRep::Get(na);
return 0;
}