模拟画多段线的函数 - 精华帖集合
www.dimcax.com
模拟画多段线的函数
//自定义的画多段线函数
//返回值: 成功则返回true,失败则返回false
bool addpline(
acdbobjectid &id //生成的多段线的objectid
, const char* code //编码
, const char* layername //图层名
, const char* linetypename //线型名
, double constwidth //全局线宽
, adesk::uint16 colorindex //索引色, 默认为 bylayer
, double initialx //第一点的x坐标
, double initialy //第一点的y坐标
, acdbdatabase* pdb //目标数据库
)
{
ads_point apt; //前一个点
ads_point act; //当前点
ads_point att; //临时点
double dtmp1, dtmp2;
acgepoint2d gpt, gtt, gct; //
acgepoint3d pt1, pt2, pt3;
if ((initialx == 0) && (initialy == 0)) {
if (acedgetpoint(null, "\n第一点: ", apt) != rtnorm) return false;
}
else {
apt[x] = initialx;
apt[y] = initialy;
}
int irc;
acdbpolyline* ppl;
char kword[100];
setdatabase(pdb);
//输入多段线的第一段
acedinitget(null, "a");
irc = acedgetpoint(apt, "\n圆弧a/<指定下一点>", act);
//指定下一点
if (irc == rtnorm) {
ppl = new acdbpolyline(2);
ppl->addvertexat(0, acgepoint2d(apt[x], apt[y]));
ppl->addvertexat(1, acgepoint2d(act[x], act[y]));
if (code != null) setxdata(ppl, appname, code, pdb);
setentitylayer(ppl, layername, true, pdb);
setentitylinetype(ppl, linetypename, pdb);
ppl->setconstantwidth(constwidth);
ppl->setcolorindex(colorindex);
ppl->setplinegen(adesk::ktrue);
id = addtomodelspace(ppl, pdb);
ppl->close();
apt[x] = act[x];
apt[y] = act[y];
}
//输入关键词"a"
else if (irc == rtkword) {
if (acedgetinput(kword) != rtnorm) return false;
else if (strcmp(kword, "a") == 0) {
if (acedgetpoint(null, "\n圆弧第二点: ", att) != rtnorm) return false;
if (acedgetpoint(null, "\n圆弧终点: ", act) != rtnorm) return false;
ppl = new acdbpolyline(2);
ppl->addvertexat(0, aspnt2d(apt), getbulgeof3pt(apt, att, act));
ppl->addvertexat(1, aspnt2d(act));
if (code != null) setxdata(ppl, appname, code, pdb);
setentitylayer(ppl, layername, true, pdb);
setentitylinetype(ppl, linetypename, pdb);
ppl->setconstantwidth(constwidth);
ppl->setcolorindex(colorindex);
ppl->setplinegen(adesk::ktrue);
id = addtomodelspace(ppl, pdb);
ppl->close();
apt[x] = act[x];
apt[y] = act[y];
}
}
else {
return false;
}
//输入多段线的第2,3,4,…段
for ( ; ; ) {
acedinitget(null, "a c g j u h");
irc = acedgetpoint(apt, "\n圆弧a/闭合c/隔一点闭合g/隔一点j/回退u/换向h<下一点>", act);
//下一点
if (irc == rtnorm) {
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
ppl->addvertexat(ppl->numverts(), aspnt2d(act));
ppl->close();
apt[x] = act[x];
apt[y] = act[y];
}
//输入关键词
else if (irc == rtkword) {
if (acedgetinput(kword) != rtnorm) return true;
else if (strcmp(kword, "a") == 0) {
if (acedgetpoint(null, "\n圆弧第二点: ", att) != rtnorm) return false;
if (acedgetpoint(null, "\n圆弧终点: ", act) != rtnorm) return false;
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
ppl->getpointat(ppl->numverts() - 1, gpt);
apt[x] = gpt.x;
apt[y] = gpt.y;
ppl->setbulgeat(ppl->numverts() - 1, getbulgeof3pt(apt, att, act));
ppl->addvertexat(ppl->numverts(), aspnt2d(act));
ppl->close();
apt[x] = act[x];
apt[y] = act[y];
}
else if (strcmp(kword, "c") == 0) {
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
if (ppl->numverts() < 3) {
acutprintf("\n点数少于3, 不得闭合, 重新选择: \n");
ppl->close();
continue;
}
else {
ppl->setclosed(adesk::ktrue);
ppl->close();
return true;
}
}
else if (strcmp(kword, "g") == 0) {
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
if (ppl->numverts() == 2) {
acutprintf("\n点数少于3, 不满足隔一点闭合条件, 重新选择:\n");
ppl->close();
continue;
}
else {
ppl->getpointat(ppl->numverts() - 1, gpt);
ppl->getpointat(ppl->numverts() - 2, gtt);
ppl->getpointat(0, gct);
acgeline2d gl2d(gpt, acgevector2d(gpt.x - gtt.x, gtt.y - gpt.y));
gtt = gl2d.closestpointto(gct);
ppl->addvertexat(ppl->numverts(), gtt);
ppl->setclosed(adesk::ktrue);
ppl->close();
return true;
}
}
else if (strcmp(kword, "j") == 0) {
if (acedgetpoint(null, "\n指定点:", act) != rtnorm) {
ppl->close();
continue;
}
else {
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
ppl->getpointat(ppl->numverts() - 1, gpt);
ppl->getpointat(ppl->numverts() - 2, gtt);
gct.set(act[x], act[y]);
acgeline2d gl2d(gpt, acgevector2d(gpt.x - gtt.x, gtt.y - gpt.y));
gtt = gl2d.closestpointto(gct);
ppl->addvertexat(ppl->numverts(), gtt);
ppl->addvertexat(ppl->numverts(), gct);
ppl->close();
apt[x] = act[x];
apt[y] = act[y];
}
}
else if (strcmp(kword, "u") == 0) {
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
if (ppl->numverts() == 2) {
ppl->getpointat(0, gpt);
ppl->erase();
ppl->close();
addpline(id, code, layername, continuous, constwidth, colorindex, gpt.x, gpt.y, pdb);
}
else {
ppl->removevertexat(ppl->numverts() - 1);
ppl->setbulgeat(ppl->numverts() - 1, 0);
ppl->getpointat(ppl->numverts() - 1, gpt);
ppl->close();
apt[x] = gpt.x;
apt[y] = gpt.y;
}
}
else if (strcmp(kword, "h") == 0) {
if (acdbopenobject(ppl, id, acdb::kforwrite) != acad::eok) return false;
invertpolyline(ppl);
ppl->getpointat(ppl->numverts() - 1, gpt);
ppl->close();
apt[x] = gpt.x;
apt[y] = gpt.y;
}
}
else {
return true;
}
}
return true;
}
[ ]
加精收藏