php读取dxf,分享个DXF转G代码的实例
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469;acceptfiles=1)
winform.add(
button={cls="button";text='\u2460获取有效数据';left=609;top=363;right=757;bottom=466;font=LOGFONT(h=-21);z=2};
button2={cls="button";text='\u2461生成ARC';left=5;top=363;right=138;bottom=466;font=LOGFONT(h=-21);z=3};
button3={cls="button";text='\u2464生成正序G';left=304;top=363;right=436;bottom=466;font=LOGFONT(h=-21);z=6};
button4={cls="button";text='\u2462排序';left=139;top=363;right=221;bottom=466;font=LOGFONT(h=-21);z=4};
button5={cls="button";text='\u2463结果';left=225;top=363;right=300;bottom=466;font=LOGFONT(h=-21);z=5};
button6={cls="button";text="生成反序G";left=442;top=363;right=579;bottom=466;font=LOGFONT(h=-21);z=7};
edit={cls="edit";left=0;top=0;right=760;bottom=362;edge=1;multiline=1;vscroll=1;z=1}
)
/*}}*/
var filePath,fileContents;
import console;
console.open()
winform.wndproc = function(hwnd,message,wParam,lParam){
select( message ) {
//拖拽文件到窗体里
case 0x233/*_WM_DROPFILES*/{
filePath = win.getDropFile(wParam )[1];
}
else{
}
}
}
class entitiesClass{
line = {};
arc = {};
}
class line{
//线段的第一个点
float x1 = 0.0;
float y1 = 0.0;
float z1 = 0.0;
//线段的第二个点
float x2 = 0.0;
float y2 = 0.0;
float z2 = 0.0;
};
class arc{
//弧形的第一个点
float x1 = 0.0;
float y1 = 0.0;
float z1 = 0.0;
//弧形第二个点
float x2 = 0.0;
float y2 = 0.0;
float z2 = 0.0;
//弧形半径
float R = 0.0;
//弧形圆心点
float xx = 0.0;
float yy = 0.0;
float zz = 0.0;
//弧形起始角度和终止角度
float startN = 0.0;
float endN = 0.0;
};
var G_line = line();
var G_arc = arc();
var entitiesTab = entitiesClass();
var entitiesStart = false;
winform.button.oncommand = function(id,event){
winform.edit.text = "";
fileContents = io.open(filePath,"r+");
fileContents.seek("set");
do{
//读取文件的一行
var stringLine = tostring(fileContents.read());
//去除该行的首尾空白字符之后进行判断
select( string.trim( stringLine ) ) {
case "ENTITIES" {
console.log("找到实体文件! 开始解析:");
entitiesStart = true;
}
case "LINE" {
//只有找到实体线条模块之后,线条类型解析才有效
if(entitiesStart == true){
//循环读取直到找到线属性这行
while( fileContents.read() != "AcDbLine" ){ };
//LINE线属性共有6组,其中每组第一行是特定属性名,第二行是属性值
for(i=1;6;1){
select( string.trim(tostring( fileContents.read() )) ) {
case "10" {
var pos = fileContents.read();
G_line.x1 = tonumber( string.format("%.3f",pos ) );
}
case "20" {
var pos = fileContents.read();
G_line.y1 = tonumber( string.format("%.3f",pos ) );
}
case "30" {
var pos = fileContents.read();
G_line.z1 = tonumber( string.format("%.3f",pos ) );
}
case "11" {
var pos = fileContents.read();
G_line.x2 = tonumber( string.format("%.3f",pos ) );
}
case "21" {
var pos = fileContents.read();
G_line.y2 = tonumber( string.format("%.3f",pos ) );
}
case "31" {
var pos = fileContents.read();
G_line.z2 = tonumber( string.format("%.3f",pos ) );;
}
else {
}
}
}
//每块LINE类型属性读取完毕,放入LINE表中,等待下一步操作
table.push(entitiesTab.line,table.clone(G_line));
}
}
case "ARC" {
if(entitiesStart == true){
//循环读取直到找到线属性这行
while( fileContents.read() != "AcDbCircle" ){ };
//ARC弧线属性共有6组,其中每组第一行是特定属性名,第二行是属性值
for(i=1;6;1){
select( string.trim(tostring( fileContents.read() )) ) {
case "10" {
var pos = fileContents.read();
G_arc.xx = tonumber( string.format("%.3f",pos ) );
}
case "20" {
var pos = fileContents.read();
G_arc.yy = tonumber( string.format("%.3f",pos ) );
}
case "30" {
var pos = fileContents.read();
G_arc.zz = tonumber( string.format("%.3f",pos ) );
}
case "40" {
var pos = fileContents.read();
G_arc.R = tonumber( string.format("%.3f",pos ) );
while( fileContents.read() != "AcDbArc" ){ };
}
case "50" {
var pos = fileContents.read();
G_arc.startN = tonumber( string.format("%.3f",pos ) );
}
case "51" {
var pos = fileContents.read();
G_arc.endN = tonumber( string.format("%.3f",pos ) );
}
else {
}
}
}
//每块ARC类型属性读取完毕,放入ARC表中,等待下一步操作
table.push(entitiesTab.arc,table.clone(G_arc));
}
}
//其他模块暂时不使用,检测到此模块即结束此次解析
case "CIRCLE","ELLIPSE","POLYLINE","VERTEX","SPLINE","INDERT","TEXT","DIMENSION" {
if(entitiesStart == true){
entitiesStart = false;
}
}
//文件末尾
case "EOF" {
console.dump(entitiesTab);
}
else {
}
}
}while( fileContents.read(0)/**是否是最后一行**/ )
}
//解析获得的ARC数据,求出弧线的起始点坐标和终止点坐标
winform.button2.oncommand = function(id,event){
for(i=1;#entitiesTab.arc;1){
if( (entitiesTab.arc[ i ].startN >= 0) && (entitiesTab.arc[ i ].startN <= 90) ){
//起始点在第一象限
entitiesTab.arc[ i ].x1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].R * math.cos(math.rad(entitiesTab.arc[ i ].startN)) + entitiesTab.arc[ i ].xx) );
entitiesTab.arc[ i ].y1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].R * math.sin(math.rad(entitiesTab.arc[ i ].startN)) + entitiesTab.arc[ i ].yy) );
}elseif( (entitiesTab.arc[ i ].startN > 90) && (entitiesTab.arc[ i ].startN <= 180) ){
//起始点在第二象限
entitiesTab.arc[ i ].x1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].xx - entitiesTab.arc[ i ].R * math.cos(math.rad(180 - entitiesTab.arc[ i ].startN))) );
entitiesTab.arc[ i ].y1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].R * math.sin(math.rad(180 - entitiesTab.arc[ i ].startN)) + entitiesTab.arc[ i ].yy) );
}elseif( (entitiesTab.arc[ i ].startN > 180) && (entitiesTab.arc[ i ].startN <= 270) ){
//起始点在第三象限
entitiesTab.arc[ i ].x1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].xx - entitiesTab.arc[ i ].R * math.cos(math.rad(entitiesTab.arc[ i ].startN - 180))) );
entitiesTab.arc[ i ].y1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].yy - entitiesTab.arc[ i ].R * math.sin(math.rad(entitiesTab.arc[ i ].startN - 180))) );
}elseif( (entitiesTab.arc[ i ].startN > 270) && (entitiesTab.arc[ i ].startN <=360) ){
//起始点在第四象限
entitiesTab.arc[ i ].x1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].xx + entitiesTab.arc[ i ].R * math.cos(math.rad(360 - entitiesTab.arc[ i ].startN))) );
entitiesTab.arc[ i ].y1 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].yy - entitiesTab.arc[ i ].R * math.sin(math.rad(360 - entitiesTab.arc[ i ].startN))) );
}
if( (entitiesTab.arc[ i ].endN >= 0) && (entitiesTab.arc[ i ].endN <= 90) ){
//终止点在第一象限
entitiesTab.arc[ i ].x2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].R * math.cos(math.rad(entitiesTab.arc[ i ].endN)) + entitiesTab.arc[ i ].xx) );
entitiesTab.arc[ i ].y2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].R * math.sin(math.rad(entitiesTab.arc[ i ].endN)) + entitiesTab.arc[ i ].yy) );
}elseif( (entitiesTab.arc[ i ].endN > 90) && (entitiesTab.arc[ i ].endN <= 180) ){
//终止点在第二象限
entitiesTab.arc[ i ].x2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].xx - entitiesTab.arc[ i ].R * math.cos(math.rad(180 - entitiesTab.arc[ i ].endN))) );
entitiesTab.arc[ i ].y2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].R * math.sin(math.rad(180 - entitiesTab.arc[ i ].endN)) + entitiesTab.arc[ i ].yy) );
}elseif( (entitiesTab.arc[ i ].endN > 180) && (entitiesTab.arc[ i ].endN <= 270) ){
//终止点在第三象限
entitiesTab.arc[ i ].x2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].xx - entitiesTab.arc[ i ].R * math.cos(math.rad(entitiesTab.arc[ i ].endN - 180))) );
entitiesTab.arc[ i ].y2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].yy - entitiesTab.arc[ i ].R * math.sin(math.rad(entitiesTab.arc[ i ].endN - 180))) );
}elseif( (entitiesTab.arc[ i ].endN > 270) && (entitiesTab.arc[ i ].endN <=360) ){
//终止点在第四象限
entitiesTab.arc[ i ].x2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].xx + entitiesTab.arc[ i ].R * math.cos(math.rad(360 - entitiesTab.arc[ i ].endN))) );
entitiesTab.arc[ i ].y2 = tonumber( string.format("%.3f", entitiesTab.arc[ i ].yy - entitiesTab.arc[ i ].R * math.sin(math.rad(360 - entitiesTab.arc[ i ].endN))) );
}
}
}
//定义排序列表
class retClass{
str G_type; //类型
point G_content; //内容
}
class lineClass{
float startX1;
float startY1;
float endX1;
float endY1;
}
class arcClass{
float R;
float startX1;
float startY1;
float endX1;
float endY1;
float centerX;
float centerY;
}
var retTable = {};
var retType = retClass();
var lineType = lineClass();
var arcType = arcClass();
var 正常顺序 = function( tab , flag ){
if(flag == "line"){
retType.G_type = "line";
lineType.startX1 = tab.x1;
lineType.startY1 = tab.y1;
lineType.endX1 = tab.x2;
lineType.endY1 = tab.y2;
retType.G_content = table.clone( lineType );
}elseif( flag == "arc" ){
retType.G_type = "逆时针";
arcType.startX1 = tab.x1;
arcType.startY1 = tab.y1;
arcType.endX1 = tab.x2;
arcType.endY1 = tab.y2;
arcType.centerX = tab.xx;
arcType.centerY = tab.yy;
arcType.R = tab.R;
retType.G_content = table.clone( arcType );
}
return retType;
}
var 颠倒顺序 = function( tab , flag ){
if(flag == "line"){
retType.G_type = "line";
lineType.startX1 = tab.x2;
lineType.startY1 = tab.y2;
lineType.endX1 = tab.x1;
lineType.endY1 = tab.y1;
retType.G_content = table.clone( lineType );
}elseif( flag == "arc" ){
retType.G_type = "顺时针";
arcType.startX1 = tab.x2;
arcType.startY1 = tab.y2;
arcType.endX1 = tab.x1;
arcType.endY1 = tab.y1;
arcType.centerX = tab.xx;
arcType.centerY = tab.yy;
arcType.R = tab.R;
retType.G_content = table.clone( arcType );
}
return retType;
}
winform.button4.oncommand = function(id,event){
/*
取出排好序的表的第一元素的头点坐标,和最后一个元素的尾坐标,
拿其他没有对比过的线条的头坐标和尾坐标分别比较,然后就可以插入到相应的排序表的头和尾部
这样就形成一个连续的队列
难点在对比并放入排序列表的线条,应该放入后从原表中删除,防止多次重复对比,因为每根线条只有唯一的序号,无需再次判断
table貌似没有删除哪一条的指令
*/
//首先把第一个线条作为第一序列
//console.dump(entitiesTab.line[1])
var tempTab = 正常顺序(entitiesTab.line[1],"line");
table.push(retTable, table.clone(tempTab) );
table.remove(entitiesTab.line,1);
while( (#entitiesTab.arc + #entitiesTab.line) ){
for(k=1;#entitiesTab.arc;1){
if((retTable[1].G_content.startX1 == entitiesTab.arc[k].x1) && (retTable[1].G_content.startY1 == entitiesTab.arc[k].y1)){
var tempTab = 颠倒顺序(entitiesTab.arc[k],"arc");
table.insert(retTable,table.clone(tempTab));//插到前面
table.remove(entitiesTab.arc,k);
break 1;
}
if((retTable[1].G_content.startX1 == entitiesTab.arc[k].x2) && (retTable[1].G_content.startY1 == entitiesTab.arc[k].y2)){
var tempTab = 正常顺序(entitiesTab.arc[k],"arc");
table.insert(retTable,table.clone(tempTab));//插到前面
table.remove(entitiesTab.arc,k);
break 1;
}
if((retTable[#retTable].G_content.endX1 == entitiesTab.arc[k].x1) && (retTable[#retTable].G_content.endY1 == entitiesTab.arc[k].y1)){
var tempTab = 正常顺序(entitiesTab.arc[k],"arc");
table.push(retTable,table.clone(tempTab));//插到后面
table.remove(entitiesTab.arc,k);
break 1;
}
if((retTable[#retTable].G_content.endX1 == entitiesTab.arc[k].x2) && (retTable[#retTable].G_content.endY1 == entitiesTab.arc[k].y2)){
var tempTab = 颠倒顺序(entitiesTab.arc[k],"arc");
table.push(retTable,table.clone(tempTab));//插到后面
table.remove(entitiesTab.arc,k);
break 1;
}
}
//-----------------------------------------------------
for(j=1;#entitiesTab.line;1){
//起始点有没重合
if((retTable[1].G_content.startX1 == entitiesTab.line[j].x1) && (retTable[1].G_content.startY1 == entitiesTab.line[j].y1)){
var tempTab = 颠倒顺序(entitiesTab.line[j],"line");
table.insert(retTable,table.clone(tempTab));//插到前面
table.remove(entitiesTab.line,j);
break 1;
}
if((retTable[1].G_content.startX1 == entitiesTab.line[j].x2) && (retTable[1].G_content.startY1 == entitiesTab.line[j].y2)){
var tempTab = 正常顺序(entitiesTab.line[j],"line");
table.insert(retTable,table.clone(tempTab));//插到前面
table.remove(entitiesTab.line,j);
break 1;
}
if((retTable[#retTable].G_content.endX1 == entitiesTab.line[j].x1) && (retTable[#retTable].G_content.endY1 == entitiesTab.line[j].y1)){
var tempTab = 正常顺序(entitiesTab.line[j],"line");
table.push(retTable,table.clone(tempTab));//插到后面
table.remove(entitiesTab.line,j);
break 1;
}
if((retTable[#retTable].G_content.endX1 == entitiesTab.line[j].x2) && (retTable[#retTable].G_content.endY1 == entitiesTab.line[j].y2)){
var tempTab = 颠倒顺序(entitiesTab.line[j],"line");
table.push(retTable,table.clone(tempTab));//插到后面
table.remove(entitiesTab.line,j);
break 1;
}
}
}
console.log("转换完成!");
}
winform.button5.oncommand = function(id,event){
console.dump(retTable)
}
winform.button3.oncommand = function(id,event){
var GcodeStr;
for(k,v in retTable){
if(GcodeStr == null){
GcodeStr = string.concat(GcodeStr,"G00 ","X",v.G_content.startX1," Y",v.G_content.startY1,'\r\n');
}
select(v.G_type) {
case "line" {
GcodeStr = string.concat(GcodeStr,"G01 ","X",v.G_content.endX1," Y",v.G_content.endY1,'\r\n');
}
case "顺时针" {
GcodeStr = string.concat(GcodeStr,"G02 ","X",v.G_content.endX1," Y",v.G_content.endY1," R",v.G_content.R,'\r\n');
}
case "逆时针" {
GcodeStr = string.concat(GcodeStr,"G03 ","X",v.G_content.endX1," Y",v.G_content.endY1," R",v.G_content.R,'\r\n');
}
else {
console.log("rrrrrrrrrrrrr")
}
}
}
console.log( GcodeStr );
string.save("/cnctest.nc",GcodeStr)
}
winform.button6.oncommand = function(id,event){
var GcodeStr;
table.reverse(retTable);
for(k,v in retTable){
if(GcodeStr == null){
GcodeStr = string.concat(GcodeStr,"G00 ","X",v.G_content.endX1," Y",v.G_content.endY1,'\r\n');
}
select(v.G_type) {
case "line" {
GcodeStr = string.concat(GcodeStr,"G01 ","X",v.G_content.startX1," Y",v.G_content.startY1,'\r\n');
}
case "顺时针" {
GcodeStr = string.concat(GcodeStr,"G03 ","X",v.G_content.startX1," Y",v.G_content.startY1," R",v.G_content.R,'\r\n');
}
case "逆时针" {
GcodeStr = string.concat(GcodeStr,"G02 ","X",v.G_content.startX1," Y",v.G_content.startY1," R",v.G_content.R,'\r\n');
}
else {
console.log("rrrrrrrrrrrrr")
}
}
}
console.log( GcodeStr );
string.save("/cnctestFFFF.nc",GcodeStr)
}
winform.show()
win.loopMessage();
php读取dxf,分享个DXF转G代码的实例相关推荐
- php验证码大全(实例分享),php文件上传代码大全(实例分...-php验证码大全(实例分享)-php打印倒三角的实例代码_169IT.COM...
本节主要内容: php中的文件上传代码 在我们平时的php编程中,涉及文件上传的内容很多,无论是简单的留言本程序,还是复杂的新闻系统,甚至是功能完备的cms系统中,都少不了文件上传的功能与代码. 本文 ...
- matlab找不到bma_g代码,基于矢量图形的G代码自动生成软件路径优化算法的研究
在数控雕刻技术中,数控编程是设计人员与执行人员联系的桥梁.传统的方法是由技术员从图纸中提取零件信息,结合加工工艺要求,根据数控加工程序的标准手工编制加工程序,速度较慢且精度较低.随着数控技术的发展,市 ...
- 编程 ul 不能一行显示 跳到下行_史上最全的数控G代码编程详解
一.G代码功能简述 G00------快速定位 G01------直线插补 G02------顺时针方向圆弧插补 G03------逆时针方向圆弧插补 G04------定时暂停 G05------通 ...
- ObjectARX2010二次开发之 --- DXF转G代码(1)
近期计划用ObjectARX2010开发一个DXF转G代码插件,计划已开始.在此记录每天编程用到的关键函数.今日用到的函数如下: 以下英文解释默认是参考ObjectARX for AutoCAD201 ...
- dxf文件解析,g代码解析,图片解析C#工程文件
dxf文件解析,g代码解析,图片解析C#工程文件 1.解析完成的图形坐标自动保存,通过通信接口直接下发即可 2.可用于激光切割机,打印机,打码机,巡边机,点胶机等运动控制系统 ID:693000659 ...
- dxf文件解析,g代码解析,图片解析C#工程文件 可用于激光切割机,打印机,打码机,巡边机,点胶机等运动控制系统
dxf文件解析,g代码解析,图片解析C#工程文件 1.解析完成的图形坐标自动保存,通过通信接口直接下发即可 2.可用于激光切割机,打印机,打码机,巡边机,点胶机等运动控制系统 ID:483000659 ...
- Codesys的文件读取功能---G代码文件读取及运行
1.序言 前文已经介绍过Codesys软件可以将dxg格式的CAD文件直接读取出来转换成G代码,导入到软件可以使用的CNC程序,通过对该CNC程序的编程,可以实现将CAD图纸转成CNC指令并运行,参考 ...
- DXF文件格式——ASCII DXF 文件
ASCII DXF 文件 本节介绍 ASCII DXF 文件的格式.只有自行编写程序处理 DXF 文件,或者使用由 AutoLISP® 和 ObjectARX® 应用程序获得的图元信息时,才需要使用本 ...
- dxf素材和dxf、plt、dst看图软件
dxf.plt.dst看图软件:软件主要应用于激光.雕刻等通过二维矢量.位图输出控制的设备上.支持二次开发嵌入AutoCAD.CorelDRAW等绘图软件.软件提供强大的与AutoCAD一致的偏移功能 ...
最新文章
- Failed to initialize NSS library
- 【luogu P1343 地震逃生】 题解
- 有n个人围成一圈,按顺序从1到n编号。从第一个人开始报数
- C++ STL : 模拟实现STL中的关联式容器map和set
- MATLAB-矩阵基本语法知识
- java 并发锁_Java并发教程–重入锁
- 为什么我要选择erlang+go进行server架构(2)
- python怎么设置回文数_python如何写一个函数判断回文数?
- 【elasticsearch】 Elasticsearch集群规模和容量规划的底层逻辑
- 【报告分享】2020年中国快消品行业KOL内容营销报告.pdf(附下载链接)
- 多线程设计模式(二):Future模式
- 自助bi工具如何搭建数据可视化
- 肯定存在无摩擦力的材料
- 【学生信息管理系统】-优化篇1
- 阿里巴巴 Java面经
- 最新字节跳动面试题之堆排序
- RAM Type——Register file(寄存器堆)
- Ruoyi 整合Flowable UI Modeler 6.7.2
- 2022制冷与空调设备运行操作培训试题及答案
- Unity面试经验(两天面六家,四个offer,济南)
热门文章
- SAP Spartacus 服务器端渲染编程规范
- SAP Spartacus Spinner控件显示原理
- 如何在postman里为类型为Edm.DateTime的OData参数指定正确格式的值
- 将S/4HANA的自定义BO功能以Web Service的方式暴露给第三方
- SAP CRM WebClient UI如何将后台存储的timestamp时间戳转换成本地时间
- 如何使用Prometheus采集SAP ABAP Netweaver的应用日志数据
- role cache - set data user parameter - /UI2/CACHE_DISABLE
- SAP UI5 new sap.ui.commons.Button trigger component load
- how is navigation list item click event handled - actually no logic done
- SAP Kyma上mqtt前缀的endpoint