【OCC学习22】如何在c++程序中集成OCC Draw的所有命令

写了一段最短的集成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;
}
  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值