|
[code]static void HHAddPoly(void)
{
int nColorIndex = 0; // 颜色索引值
ads_real width = 0; // 多段线的线宽
int nIndex = 2; // 当前输入点的次数
ads_point ptStart; // 起点
ads_point ptPrevious;// 前一个参考点
ads_point ptCurrent; //当前拾取的点
AcDbObjectId polyId; //多段线ID
// 提示用户输入起点
if (RTNORM != acedGetPoint(NULL, _T("\n输入第一点:"), ptStart))
{
return ;
}
// 输入第二点
acedInitGet(NULL, _T("W C B F"));
int rc = acedGetPoint(ptStart,_T("\n输入下一点 [宽度(W)/颜色(C)/闭合(B)]<完成(F)>:"), ptCurrent);
while (RTNORM == rc || RTKWORD == rc)
{
if (RTKWORD == rc) // 如果用户输入了关键字
{
ACHAR keyWord[20];// 关键字
//获取输入的关键字
if (RTNORM != acedGetInput(keyWord))
{
return;
}
if (0 == _tcscmp(keyWord, _T("W")))
{
width = CAuxiliary::GetWidth();
AcDbPolyline *pPoly = CAuxiliary::GetPolyLine(polyId);
if (NULL == pPoly)
{
return;
}
pPoly->setConstantWidth(width);
pPoly->close();
}
else if (0 == _tcscmp(keyWord, _T("C")))
{
nColorIndex = CAuxiliary::GetColorIndex();
AcDbPolyline *pPoly = CAuxiliary::GetPolyLine(polyId);
if (NULL == pPoly)
{
return;
}
pPoly->setColorIndex(nColorIndex);
pPoly->close();
}
else if (0 == _tcscmp(keyWord, _T("B")))
{
if (nIndex < 3)
{
acutPrintf(_T("\n输入点个数不足,不能执行闭合操作"));
return;
}
AcDbPolyline *pPoly = CAuxiliary::GetPolyLine(polyId);
if (NULL == pPoly)
{
return;
}
pPoly->setClosed(Adesk::kTrue);
pPoly->close();
return;
}
else if (0 == _tcscmp(keyWord, _T("F")))
{
return;
}
else
{
acutPrintf(_T("\n无效的关键字."));
}
}
else if (RTNORM == rc) // 用户输入了点
{
acutPrintf(_T("\n输入点的坐标是(%.2f, %.2f, %.2f)"), ptCurrent[X], ptCurrent[Y], ptCurrent[Z]);
if (2 == nIndex)
{
// 创建多段线
polyId = CAuxiliary::CreatePolyline(ptStart, ptCurrent, width, nColorIndex);
}
else if (nIndex > 2)
{
//修改多段线
CAuxiliary::AddPolyline(polyId, ptCurrent,nIndex, width, nColorIndex);
}
++nIndex;
acdbPointSet(ptCurrent, ptPrevious);//acdbPointSet宏: ads_point 变量值的复制
}
// 提示用户输入新的节点
acedInitGet(NULL, _T("W C B F"));
rc = acedGetPoint(ptPrevious, _T("\n输入下一点 [宽度(W)/颜色(C)/闭合(B)]<完成(F)>:"), ptCurrent);
}
}[/code] |
|