open CasCade下载
1、进入网点
OCCT3D Open Source - OCCT3D
join the OCCT3D
也可以直接进入Download - Open CASCADE Technology
界面如下
点击进入download、界面如下
我选择的previous release 7.8.0
下载 源码
往下滑进入
进入github、界面如下、往下走
下载你需要的第三方包
接下来就可以解压、然后cmake了
我使用的是cmake4.0.0版本、可能是太新了会出现错误
把cmakelists的第一行改成指定的版本号就可以了
然后再进行
又会出现错误、没有找到第三方包
找到以下name、把值改为你的第三方解压包的路径就可以了
先configure再generate最后就可以open Project了
用vs打开会出现
只需要先生成ALL_BUILD\、没有错误、然后再生成INSTALL就可以了
当后续写项目时配置环境、需要添加lib库、不需要一个一个复制名字
打开命令提示符(Win + R,输入 cmd)。
切换到你的 .lib 文件所在的目录:
Cmd
深色版本
cd C:\path\to\your\lib\folder
使用以下命令列出所有 .lib 文件并保存到一个文本文件中:
深色版本
dir /b *.lib > lib_list.txt
打开生成的 lib_list.txt 文件,里面会列出所有的 .lib 文件名。
打开命令提示符(Win + R,输入 cmd)。
使用以下命令将指定目录中的所有 .dll 文件复制到目标文件夹:
Cmd
深色版本
copy "C:\source_folder\*.dll" "C:\target_folder\"
附上可用源码
// OpenCasCade.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <STEPControl_Reader.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <BRepTools.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include<TopoDS.hxx>
int main()
{
// 创建 STEP 文件读取器
//STEPControl_Reader reader;
读取 STEP 文件
//IFSelect_ReturnStatus status = reader.ReadFile("example.STEP");
//if (status != IFSelect_RetDone) {
// std::cerr << "Error: Failed to read STEP file." << std::endl;
// return 1;
//}
STEPControl_Reader reader;
//IFSelect_ReturnStatus status = reader.ReadFile("D:\\zou\\vsProject\\CPLusProject\\OpenCasCade\\x64\\Debug\\example.STEP");
IFSelect_ReturnStatus status = reader.ReadFile("D:\\zou\\vsProject\\CPLusProject\\OpenCasCade\\x64\\Debug\\example.STEP");
if (status == IFSelect_RetDone) {
reader.TransferRoots(); // 转换模型
TopoDS_Shape shape = reader.OneShape(); // 获取几何体
}
else
{
std::cerr << "Error: Failed to read STEP file." << std::endl;
return 1;
}
// 转换文件中的形状
reader.TransferRoots();
// 获取第一个形状
TopoDS_Shape shape = reader.OneShape();
// 遍历所有边
std::cout << "Edges in the shape:" << std::endl;
TopExp_Explorer edgeExplorer(shape, TopAbs_EDGE);
int edgeCount = 0;
for (; edgeExplorer.More(); edgeExplorer.Next()) {
TopoDS_Edge edge = TopoDS::Edge(edgeExplorer.Current());
std::cout << "Edge " << ++edgeCount << ": ";
// 获取边的几何曲线
Standard_Real first, last;
Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, first, last);
if (!curve.IsNull()) {
std::cout << "Curve type: " << curve->DynamicType()->Name() << ", ";
std::cout << "Parameter range: [" << first << ", " << last << "]" << std::endl;
}
else {
std::cout << "No curve associated with this edge." << std::endl;
}
}
// 遍历所有面
std::cout << "\nFaces in the shape:" << std::endl;
TopExp_Explorer faceExplorer(shape, TopAbs_FACE);
int faceCount = 0;
for (; faceExplorer.More(); faceExplorer.Next()) {
TopoDS_Face face = TopoDS::Face(faceExplorer.Current());
std::cout << "Face " << ++faceCount << ": ";
// 获取面的几何表面
TopLoc_Location location;
Handle(Geom_Surface) surface = BRep_Tool::Surface(face, location);
if (!surface.IsNull()) {
std::cout << "Surface type: " << surface->DynamicType()->Name() << std::endl;
}
else {
std::cout << "No surface associated with this face." << std::endl;
}
}
// 输出形状信息
BRepTools::Write(shape, "output.brep");
std::cout << "STEP file successfully loaded and converted!" << std::endl;
return 0;
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件