资源简介
C++读取DXF,然后用OpenCV绘制出来,实现了插入块坐标修正,知道坐标在哪里,里面包含了OpenCV的一个库,看起来有点大
代码片段和文件信息
#define _CRT_SECURE_NO_WARNINGS //防止新编译器老函数使用报错
#include “DXFRead.h“
using namespace std;
IMPLEMENT_DYNCREATE(LINEPoint Cobject)
IMPLEMENT_DYNCREATE(BLOCKPoint Cobject)
#define FILENAME “2.dxf“
#define SAVENAME “2.png“
LINEPoint::LINEPoint(CADLINE &line)
{
m_line = line;
}
BLOCKPoint::BLOCKPoint(CADBLOCK &block)
{
m_block = block;
}
void DXFRead::ReadLine(CADDATA &data)
{
FILE *fp = fopen(FILENAME “r“);
if (!fp)
{
cout << “读取“ << FILENAME << “失败,任意键退出“ << endl;
getchar();
exit(0);
}
else
{
cout << “打开“ << FILENAME << “成功,正在读取LINE...“ << endl;
}
while (!feof(fp) && !ferror(fp))
{
fscanf(fp “%s“ &str);
//扫描块中线
if (strcmp(str “BLOCK“) == 0)
{
fscanf(fp “%s“ &str);
while (strcmp(str “2“) != 0)
{
fscanf(fp “%s“ &str);
}
//获得块名字
fscanf(fp “%s“ &name);
//如果不是这两个块,做记录
if (strcmp(name“$MODEL_SPACE“) != 0
&& strcmp(name “$PAPER_SPACE“) != 0)
{
while (strcmp(str “ENDBLK“) != 0)
{
fscanf(fp “%s“ &str);
//扫描块中线
if (strcmp(str “LINE“) == 0)
{
//归属块
strcpy(tempLine.name name);
//x1
while (strcmp(str “10“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.x1 = atof(str);
//y1
while (strcmp(str “20“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.y1 = atof(str);
//z1
while (strcmp(str “30“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.z1 = atof(str);
//x2
while (strcmp(str “11“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.x2 = atof(str);
//y2
while (strcmp(str “21“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.y2 = atof(str);
//z2
while (strcmp(str “31“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.z2 = atof(str);
data.LINE.Add(new LINEPoint(tempLine));
}
}
}
}
//扫描主坐标系线
else if (strcmp(str “LINE“) == 0)
{
//归属块
strcpy(tempLine.name “ReferenceBlock“);
//x1
while (strcmp(str “10“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.x1 = atof(str);
//y1
while (strcmp(str “20“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.y1 = atof(str);
//z1
while (strcmp(str “30“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.z1 = atof(str);
//x2
while (strcmp(str “11“) != 0)
{
fscanf(fp “%s“ &str);
}
fscanf(fp “%s“ &str);
tempLine.x2 = atof(str);
//y2
while (strcmp(str “21“) != 0)
{
fscanf(fp “%s“ &st
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 29696 2016-12-07 16:35 DXFRead\.vs\DXFRead\v14\.suo
文件 118272 2016-12-07 16:35 DXFRead\Debug\DXFRead.exe
文件 823296 2016-12-07 16:35 DXFRead\Debug\DXFRead.ilk
文件 2002944 2016-12-07 16:35 DXFRead\Debug\DXFRead.pdb
文件 27639296 2015-06-04 02:24 DXFRead\Debug\opencv_world300.dll
文件 6280 2016-12-06 15:03 DXFRead\DXFRead\1.dxf
文件 7211 2016-12-06 15:07 DXFRead\DXFRead\2.dxf
文件 6838 2016-12-07 16:35 DXFRead\DXFRead\DXFRead.cpp
文件 1380 2016-12-07 16:06 DXFRead\DXFRead\DXFRead.h
文件 6295 2016-12-07 14:50 DXFRead\DXFRead\DXFRead.vcxproj
文件 1068 2016-12-07 10:41 DXFRead\DXFRead\DXFRead.vcxproj.filters
文件 165 2016-12-07 10:28 DXFRead\DXFRead\DXFRead.vcxproj.user
文件 1303 2016-12-07 09:43 DXFRead\DXFRead.sln
目录 0 2016-12-07 09:43 DXFRead\.vs\DXFRead\v14
目录 0 2016-12-07 09:43 DXFRead\.vs\DXFRead
...D.H. 0 2016-12-07 09:43 DXFRead\.vs
目录 0 2016-12-07 16:05 DXFRead\Debug
目录 0 2016-12-07 16:36 DXFRead\DXFRead
目录 0 2016-12-07 16:35 DXFRead
----------- --------- ---------- ----- ----
30644044 19
- 上一篇:使用MFC绘制中国地图
- 下一篇:C++语言程序设计习题集
评论
共有 条评论