几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-29, 05:37 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】模拟南方软件下polyline线的输入(并进行修改),不敢独享 - 精华帖集合

模拟南方软件下polyline线的输入(并进行修改),不敢独享 - 精华帖集合
www.dimcax.com
模拟南方软件下polyline线的输入(并进行修改),不敢独享
在大家的帮助下学习c#开发cad,现已实现了模拟南方软件下polyline线的编辑,不敢共享,拿出来和大家共同探讨,希望大家能指点!程序只是初步的写了一下,还有很多代码没有精简,希望哪位高手精简后能与大家共享一下。我是圆圈
using system;
using system.collections.generic;
using system.text;
using autodesk.autocad.applicationservices;
using autodesk.autocad.databaseservices;
using autodesk.autocad.editorinput;
using autodesk.autocad.runtime;
using autodesk.autocad.geometry;
using autodesk.autocad.colors;
namespace scpfmapmain
{
public class mypoly
{
[commandmethod("mypoly")]
static public void mypoly()
{
database db = hostapplicationservices.workingdatabase;
editor ed = application.documentmanager.mdiactivedocument.editor;
double width = 0;
int index = 2;
polyline polyent = new polyline();

objectid polyentid = objectid.null;
promptpointoptions optpoint = new promptpointoptions("\n第一点");
optpoint.allownone = true;
promptpointresult respoint = ed.getpoint(optpoint);
if (respoint.status == promptstatus.cancel)
return;
point3d ptstart;
if (respoint.status == promptstatus.none)
{
return;
}
else
{
ptstart = respoint.value;
}
point3d ptprevious = ptstart;
bool isarc = false, isbcjh = false, isadx = false, isisertpnt = false, isundo = false, isys = false, isczhi = false, isczu = false, ispyi = false,isj=false, ishx = false;
int inumfx = 1;
nextpoint:
promptpointoptions optptkey = new promptpointoptions("\n下一点或[曲线(q)/边长交会(b)/微导线(a)/插入点(s)/延伸(e)/垂直点(i)/垂足点(n)/偏移点(p)/隔一点(j)/隔点闭合(g)/闭合(c)/换向(h)/回退(u)]",
"q b a s e i n p j g c h u");
optptkey.allownone = true;

point3d ptnext, endpnt;
if (isarc == true || isbcjh == true || isadx==true || isundo==true || isisertpnt ==true || isys==true || isczhi==true || isczu==true || ispyi==true || isj==true || ishx==true)//基点改变
{
optptkey.usebasepoint = true;
optptkey.basepoint = ptnext;
}
else
{
optptkey.usebasepoint = true;
optptkey.basepoint = ptprevious;
}
promptpointresult reskey = ed.getpoint(optptkey);
if (reskey.status == promptstatus.cancel)
return;
if (reskey.status == promptstatus.keyword)//输入了关键字
{
switch (reskey.stringresult)
{
case "q"://****************************************************************************************************绘制曲线
ptnext = polyent.endpoint;
promptpointoptions optarc = new promptpointoptions("\n第一点");
promptpointresult resoptarc = ed.getpoint(optarc);
if (resoptarc.status == promptstatus.ok)
{
point3d pntonarc;
pntonarc = resoptarc.value;
promptpointoptions optarc1 = new promptpointoptions("\n第二点");
resoptarc = ed.getpoint(optarc1);
if (resoptarc.status == promptstatus.ok)
{
endpnt = resoptarc.value;
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = true;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
double td = bulgeof3d(ptnext, pntonarc, endpnt);
polyent.setbulgeat(index - 2, td);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
else if (resoptarc.status == promptstatus.none || resoptarc.status == promptstatus.cancel)
{
break;
}
}
else if (resoptarc.status == promptstatus.none || resoptarc.status == promptstatus.cancel)
{
break;
}
index++;
break;
复制代码
case "b"://**************************************************************************************************边长交会
promptpointoptions startpnt = new promptpointoptions("\n第一点");
promptpointresult resstartpnt = ed.getpoint(startpnt);
if (resstartpnt.status == promptstatus.ok)
{
promptdoubleresult disa = ed.getdouble("\n输入从第一点延伸距离");
if (disa.equals(0))
{
ed.writemessage("\n距离不能为零,边长交会退出!");
break;
}
else
{
promptpointoptions secondpnt = new promptpointoptions("\n第二点");
promptpointresult ressecondpnt = ed.getpoint(secondpnt);
if (ressecondpnt.status == promptstatus.ok)
{
promptdoubleresult disb = ed.getdouble("\n输入从第二点延伸到距离");
if (disb.equals(0))
{
ed.writemessage("\n距离不能为零,边长交会退出!");
break;
}
else
{
double disab = disa.value + disb.value;
double disyzb = ressecondpnt.value.distanceto(resstartpnt.value);
if (disab <= disyzb)
{
ed.writemessage("\n没有交点,边长交会退出!");
break;
}
else
{
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = true;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = bcjh(resstartpnt.value, ressecondpnt.value, disyzb, disa.value, disb.value);
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
}
}
if (ressecondpnt.status == promptstatus.cancel)
break;
}
}
if (resstartpnt.status == promptstatus.cancel)
break;
index++;
break;
case "a"://**************************************************************************************************************微导线
promptdoubleoptions angle = new promptdoubleoptions("\n输入角度");
promptdoubleresult resangle = ed.getdouble(angle);
if (resangle.status == promptstatus.cancel || resangle.value==0)
{
ed.writemessage("\n微导线退出!");
break;
}
if (resangle.status==promptstatus.ok)
{
promptdoubleoptions adis = new promptdoubleoptions("\n输入距离");
promptdoubleresult resdis = ed.getdouble(adis);
if (resdis.status == promptstatus.cancel || resdis.value == 0)
{
ed.writemessage("\n微导线退出!");
break;
}
if (resdis.status == promptstatus.ok)
{
int plnum = polyent.numberofvertices;
point3d endpnt1 = polyent.getpoint3dat(plnum-1);
point3d prvpnt = polyent.getpoint3dat(plnum - 2);
double x = prvpnt.x-endpnt1.x;
double y = prvpnt.y-endpnt1.y;
double a = commfunction.zbfwj(y, x) + commfunction.gw(resangle.value);
x = endpnt1.x + resdis.value * math.sin(a);
y = endpnt1.y + resdis.value * math.cos(a);
point3d ptxy = new point3d(x, y,0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = true;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
}
index ++;
break;
复制代码
case "s"://***********************************************************************************************************************插入点
promptpointoptions spnt = new promptpointoptions("\n请在线本条线上拾取一点");
spnt.allownone = true;
promptpointresult resspnt = ed.getpoint(spnt);
if (resspnt.status == promptstatus.cancel || resspnt.status == promptstatus.none)
{
ed.writemessage("\n插入点退出!");
break;
}
if (resspnt.status == promptstatus.ok)
{
int inum = 0,i=0;
for (i = 0; i < polyent.numberofvertices - 1; i++)
{
double xx1, xx2, yy1, yy2;
xx1 = math.min(polyent.getpoint3dat(i).x, polyent.getpoint3dat(i + 1).x);
xx2 = math.max(polyent.getpoint3dat(i).x, polyent.getpoint3dat(i + 1).x);
yy1 = math.min(polyent.getpoint3dat(i).y, polyent.getpoint3dat(i + 1).y);
yy2 = math.max(polyent.getpoint3dat(i).y, polyent.getpoint3dat(i + 1).y);
if ((xx1 <= resspnt.value.x && resspnt.value.x <= xx2) && (yy1 <= resspnt.value.y && resspnt.value.y <= yy2))
{
inum = i;
break;
}
}
promptpointoptions insertpnt = new promptpointoptions("\n拾取插入点位置");
insertpnt.allownone = true;
promptpointresult resinsertpnt = ed.getpoint(insertpnt);
if (resinsertpnt.status == promptstatus.none || resinsertpnt.status == promptstatus.cancel)
{
ed.writemessage("\n插入点退出!");
break;
}
if (resinsertpnt.status == promptstatus.ok)
{
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = true;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx =false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = resinsertpnt.value;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(inum+1, ptcurrent, 0, width, width);
ptnext = polyent.getpoint3dat(polyent.numberofvertices-1);
trans.commit();
}
index++;
}
else
{
break;//应该不会发生
}
}
else
{
break;//应该不会发生
}
break;
case "e"://************************************************************************************************************************延伸点
promptdoubleoptions ysdis = new promptdoubleoptions("\n延伸距离");
ysdis.allownone = false;
promptdoubleresult resysdis = ed.getdouble(ysdis);
if (resysdis.status == promptstatus.cancel || resysdis.value == 0)
{
ed.writemessage("\n延伸退出!");
break;
}
if (resysdis.status==promptstatus.ok)
{
int plnum = polyent.numberofvertices;
point3d endpnt1 = polyent.getpoint3dat(plnum-1);
point3d prvpnt = polyent.getpoint3dat(plnum - 2);
double x = prvpnt.x-endpnt1.x;
double y = prvpnt.y-endpnt1.y;
double a = commfunction.zbfwj(y, x) + math.pi;
x = endpnt1.x + resysdis.value * math.sin(a);
y = endpnt1.y + resysdis.value * math.cos(a);
point3d ptxy = new point3d(x, y,0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = true;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
index ++;
break;
复制代码
case "i"://************************************************************************************************************************垂直点
promptpointoptions pntstar = new promptpointoptions("\n拾取起始点");
promptpointresult respntstar = ed.getpoint(pntstar);
if (respntstar.status == promptstatus.cancel)
{
ed.writemessage("\n垂直点退出!");
break;
}
if (respntstar.status == promptstatus.ok)
{
promptpointoptions pntcz = new promptpointoptions("\n拾取垂足点");
promptpointresult respntcz = ed.getpoint(pntcz);
if (respntcz.status == promptstatus.cancel)
{
ed.writemessage("\n垂直点退出!");
break;
}
if (respntcz.status == promptstatus.ok)
{
promptdoubleoptions czdis = new promptdoubleoptions("\n输入垂直距离(+左/-右)");
promptdoubleresult resczdis = ed.getdouble(czdis);
if (resczdis.status == promptstatus.cancel || resczdis.value == 0)
{
ed.writemessage("\n垂直点退出!");
break;
}
if (resczdis.status == promptstatus.ok)
{
double czangle = 0;
if (resczdis.value > 0)
{
czangle = commfunction.gw(90.0);
}
if (resczdis.value<0)
{
czangle = commfunction.gw(270.0);
}
int plnum = polyent.numberofvertices;
point3d endpnt1 = respntcz.value;
point3d prvpnt = respntstar.value;
double x = prvpnt.x - endpnt1.x;
double y = prvpnt.y - endpnt1.y;
double a = commfunction.zbfwj(y, x) + czangle;
x = endpnt1.x + math.abs(resczdis.value) * math.sin(a);
y = endpnt1.y + math.abs(resczdis.value) * math.cos(a);
point3d ptxy = new point3d(x, y, 0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = true;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
}
}
index++;
break;
case "n"://*************************************************************************************************************************垂足点
promptpointoptions pntstar1 = new promptpointoptions("\n第一点");
promptpointresult respntstar1 = ed.getpoint(pntstar1);
if (respntstar1.status == promptstatus.cancel)
{
break;
}
if (respntstar1.status == promptstatus.ok)
{
promptpointoptions pntsec=new promptpointoptions("\n第二点");
promptpointresult respntsec=ed.getpoint(pntsec);
if (respntsec.status==promptstatus.cancel)
{
break;
}
if (respntsec.status==promptstatus.ok)
{
promptpointoptions pntczx=new promptpointoptions("\n拾取垂足线上一点");
promptpointresult respntczx=ed.getpoint(pntczx);
if (respntczx.status==promptstatus.cancel)
{
break;
}
if (respntczx.status == promptstatus.ok)
{
double disab, disa, disb,g,l,czangle;
disab = respntstar1.value.distanceto(respntsec.value);
disa = respntstar1.value.distanceto(respntczx.value);
disb = respntsec.value.distanceto(respntczx.value);
g = (disa * disa + disab * disab - disb * disb) / (2 * disab);
l = (disb * disb + disab * disab - disa * disa) / (2 * disab);
if (l <= disab)
{
czangle = 0;
}
else
{
czangle = math.pi;
}
int plnum = polyent.numberofvertices;
point3d endpnt1 =respntstar1.value;
point3d prvpnt = respntsec.value;
double x = prvpnt.x - endpnt1.x;
double y = prvpnt.y - endpnt1.y;
double a = commfunction.zbfwj(y, x) + czangle;
x = endpnt1.x + math.abs(g) * math.sin(a);
y = endpnt1.y + math.abs(g) * math.cos(a);
point3d ptxy = new point3d(x, y, 0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false; ;
isczu = true;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
}
}
index++;
break;
复制代码
case "p"://*************************************************************************************************************************偏移点
promptpointoptions pntbase = new promptpointoptions("\n拾取基准点");
promptpointresult respntbase = ed.getpoint(pntbase);
if (respntbase.status == promptstatus.cancel)
{
break;
}
if (respntbase.status == promptstatus.ok)
{
promptpointoptions pntpy = new promptpointoptions("\n拾取偏移方向上一点");
promptpointresult respntpy = ed.getpoint(pntpy);
if (respntpy.status == promptstatus.cancel)
{
break;
}
if (respntpy.status == promptstatus.ok)
{
promptdoubleoptions pydis = new promptdoubleoptions("\n输入偏移距离");
promptdoubleresult respydis = ed.getdouble(pydis);
if (respydis.status == promptstatus.cancel || respydis.value == 0.0)
{
break;
}
if (respntpy.status == promptstatus.ok)
{
int plnum = polyent.numberofvertices;
point3d endpnt1 = respntpy.value;
point3d prvpnt = respntbase.value;
double x = prvpnt.x - endpnt1.x;
double y = prvpnt.y - endpnt1.y;
double a = commfunction.zbfwj(y, x);
x = endpnt1.x + math.abs(respydis.value) * math.sin(a);
y = endpnt1.y + math.abs(respydis.value) * math.cos(a);
point3d ptxy = new point3d(x, y, 0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false; ;
isczu = true;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptnext = endpnt;
trans.commit();
}
}
}
}
index++;
break;
case "j"://*************************************************************************************************************************隔一点
promptpointoptions jpnt = new promptpointoptions("\n拾取点");
promptpointresult resjpnt = ed.getpoint(jpnt);
if (resjpnt.status==promptstatus.cancel)
{
ed.writemessage("\n隔一点退出!");
break;
}
if (resjpnt.status == promptstatus.ok)
{
double fx = m_ptside(resjpnt.value, polyent.getpoint3dat(polyent.numberofvertices - 2), polyent.getpoint3dat(polyent.numberofvertices -1));
double gangle = 0;
if (fx > 0)
{
gangle = 3 * math.pi / 2;
}
if (fx < 0)
{
gangle = math.pi / 2;
}
double disab, disa, disb,g,h;
disab = polyent.getpoint3dat(polyent.numberofvertices - 2).distanceto(polyent.getpoint3dat(polyent.numberofvertices - 1));
disa = polyent.getpoint3dat(polyent.numberofvertices - 2).distanceto(resjpnt.value);
disb = polyent.getpoint3dat(polyent.numberofvertices - 1).distanceto(resjpnt.value);
g=(disa*disa+disab*disab-disb*disb)/(2*disab);
h=math.sqrt(disa*disa-g*g);
int plnum = polyent.numberofvertices;
point3d endpnt1 = polyent.getpoint3dat(plnum - 1);
point3d prvpnt = polyent.getpoint3dat(plnum - 2);
double x = prvpnt.x - endpnt1.x;
double y = prvpnt.y - endpnt1.y;
double a = commfunction.zbfwj(y, x) +gangle;
x = endpnt1.x + h * math.sin(a);
y = endpnt1.y + h * math.cos(a);
point3d ptxy = new point3d(x, y, 0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = true;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptcurrent =new point2d(resjpnt.value.x, resjpnt.value.y);
index++;
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
endpnt = resjpnt.value;
ptnext = endpnt;
trans.commit();
}
}
index++;
break;
复制代码
case "g"://*************************************************************************************************************************隔点闭合
point3d resgpnt = polyent.getpoint3dat(0);
double fxx = m_ptside(resgpnt, polyent.getpoint3dat(polyent.numberofvertices - 2), polyent.getpoint3dat(polyent.numberofvertices - 1));
double dgangle = 0;
if (fxx > 0)
{
dgangle = 3 * math.pi / 2;
}
if (fxx < 0)
{
dgangle = math.pi / 2;
}
double disab1, disa1, disb1, g1, h1;
disab1 = polyent.getpoint3dat(polyent.numberofvertices - 2).distanceto(polyent.getpoint3dat(polyent.numberofvertices - 1));
disa1 = polyent.getpoint3dat(polyent.numberofvertices - 2).distanceto(resgpnt);
disb1 = polyent.getpoint3dat(polyent.numberofvertices - 1).distanceto(resgpnt);
g1 = (disa1 * disa1 + disab1 * disab1 - disb1 * disb1) / (2 * disab1);
h1 = math.sqrt(disa1 * disa1 - g1 * g1);
int plnum1 = polyent.numberofvertices;
point3d endpnt11 = polyent.getpoint3dat(plnum1 - 1);
point3d prvpnt1 = polyent.getpoint3dat(plnum1 - 2);
double x1 = prvpnt1.x - endpnt11.x;
double y1 = prvpnt1.y - endpnt11.y;
double a1 = commfunction.zbfwj(y1, x1) + dgangle;
x1 = endpnt11.x + h1 * math.sin(a1);
y1 = endpnt11.y + h1 * math.cos(a1);
point3d ptxy1 = new point3d(x1, y1, 0.0);
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
endpnt = ptxy1;
point2d ptcurrent = new point2d(endpnt[0], endpnt[1]);
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
ptcurrent = new point2d(resgpnt.x, resgpnt.y);
polyent.closed = true;
trans.commit();
}

return;
case "c"://*************************************************************************************************************************闭合
using (transaction trans = db.transactionmanager.starttransaction())
{
trans.getobject(polyentid, openmode.forwrite);
polyent.closed = true;
trans.commit();
}
return;
case "h"://*************************************************************************************************************************换向
if (inumfx == 0)
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt =false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx =true;
ptnext = polyent.getpoint3dat(polyent.numberofvertices - 1);

inumfx=1;
break;
}
if (inumfx == 1)
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = false;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = true;
ptnext = polyent.getpoint3dat(0);
inumfx = 0;
break;
}
break;
case "u"://*************************************************************************************************************************回退
if (polyent.numberofvertices <= 2)
{
ed.writemessage("\n不能再回退了!");
break;
}
else
{
using (transaction trans = db.transactionmanager.starttransaction())
{
isarc = false;
isbcjh = false;
isadx = false;
isundo = true;
isisertpnt = false;
isys = false;
isczhi = false;
isczu = false;
ispyi = false;
isj = false;
ishx = false;
trans.getobject(polyentid, openmode.forwrite);
polyent.removevertexat(polyent.numberofvertices - 1);
index = index - 1;
if (polyent.getbulgeat(index-2) !=0)
{
polyent.setbulgeat(index - 2, 0);
}
ptnext = polyent.getpoint3dat(polyent.numberofvertices - 1);

trans.commit();
break;
}
}
}//***************************************************************设置关键字结束
goto nextpoint;
}
else if (reskey.status == promptstatus.none)//没有输入任何内容或键入了回车键、空格键,输入pl线完成
{
复制代码
return;
}
else if (reskey.status == promptstatus.cancel)
{
return;
}
else//直接输入了点
{
isarc = false;
isbcjh = false;
ptnext = reskey.value;
if (index == 2)
{
//polyent.layer =layername;
//polyent.thickness = bianma;
//polyent.linetype = linetype;
polyent.elevation = ptprevious[2];//设置pl线的标高
point2d pt1 = new point2d(ptprevious[0], ptprevious[1]);
point2d pt2 = new point2d(ptnext[0], ptnext[1]);
polyent.addvertexat(0, pt1, 0, width, width);
polyent.addvertexat(1, pt2, 0, width, width);

polyentid = appendentity(polyent);
}
else
{
using (transaction trans = db.transactionmanager.starttransaction())
{
trans.getobject(polyentid, openmode.forwrite);
point2d ptcurrent = new point2d(ptnext[0], ptnext[1]);
//为换向输入pl线设置条件
if (inumfx==0)
{
polyent.addvertexat(0, ptcurrent, 0, width, width);
}
else
{
polyent.addvertexat(index - 1, ptcurrent, 0, width, width);
}
trans.commit();
}
}
index++;
}
ptprevious = ptnext;
goto nextpoint;
}
// 将图形对象加入到模型空间的函数.
private static objectid appendentity(entity ent)
{
database db = hostapplicationservices.workingdatabase;
objectid entid;
using (transaction trans = db.transactionmanager.starttransaction())
{
blocktable bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread);
blocktablerecord btr = (blocktablerecord)trans.getobject(bt[blocktablerecord.modelspace], openmode.forwrite);
entid = btr.appendentity(ent);
trans.addnewlycreateddbobject(ent, true);
trans.commit();
}
return entid;
}
//********************************************************************************
private static double bulgeof3d(point3d startpnt, point3d pntonarc, point3d endpnt)//计算凸度函数
{
circulararc3d arc = new circulararc3d(startpnt, pntonarc, endpnt);
vector3d vec = pntonarc - startpnt;
double h, d, td;
h = arc.radius - math.cos(math.abs(arc.startangle - arc.endangle) / 2) * arc.radius;
vec = startpnt.getvectorto(endpnt);
d = vec.length;
td = 2 * h / d;//凸度,没有方向
//判断方向
vector3d vec1 = startpnt.getvectorto(pntonarc);
vector3d vec2 = startpnt.getvectorto(endpnt);
double psid = vec2.x * vec1.y - vec1.x * vec2.y;
return (psid < 0) ? td : -td;
}
//*********************************************************************
private static point3d bcjh(point3d a, point3d b, double yzbc, double bca, double bcb)//边长交会
{
double g, l, h;
g = (bca * bca + yzbc * yzbc - bcb * bcb) / (2 * yzbc);
l = (bcb * bcb + yzbc * yzbc - bca * bca) / (2 * yzbc);
h = math.sqrt(bca * bca - g * g);
double x, y;
x = a.x + l * (b.x - a.x) / yzbc + h * (b.y - a.y) / yzbc;
y = a.y + l * (b.y - a.y) / yzbc + h * (a.x - b.x) / yzbc;
point3d ptxy = new point3d(x, y, 0.0);
return ptxy;
}
//判断点pt1在直线pt2->t3的哪一侧?返回值:>0,右侧;=0,三点共线;<0,左侧
private static double m_ptside(point3d pt1, point3d pt2, point3d pt3)
{
vector3d vect1 = pt1.getvectorto(pt2);//向量pt1->pt2
vector3d vect2 = pt1.getvectorto(pt3);//向量pt1->pt3
return vect2.x * vect1.y - vect1.x * vect2.y;
}
复制代码
//******************************************************************************************************************
static public double zbfwj(double xx, double yy)//坐标方位角计算
{
double aa;
aa = 0;
if (xx > 0)
{
if (yy >= 0)
{
aa = math.atan(yy / xx);
}
if (yy < 0)
{
aa = math.atan(yy / xx) + 2 * math.pi;
}
}
if (xx == 0)
{
if (yy > 0)
{
aa = math.pi / 2;
}
if (yy < 0)
{
aa = 3 * math.pi / 2;
}
}
if (xx < 0)
{
aa = math.atan(yy / xx) + math.pi;
}
return aa;
}
//********************************************************************************************
static public double wg(double aa)//弧度转度分秒
{
double dd, ff, mm,dfm;
dfm = 0;
aa = aa*180/math.pi;
dd = math.truncate(aa);
ff =math.truncate((aa - dd) * 60);
mm = ((aa - dd) * 60 - ff) * 60;
dfm = dd + ff / 100 + mm / 10000;
return dfm;
}
//*********************************************************************************************度分秒转弧度
static public double gw(double aa)
{
double dd, ff, mm, hd;
hd = 0;
dd = math.truncate(aa);
ff =math.truncate((aa - dd) * 100);
mm = (aa - dd) * 100 - ff;
hd = (dd + ff / 100 + mm / 10000) * math.pi / 180;
return hd;
}
复制代码
}
}
复制代码
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 09:35 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多