|
void CreateLine()//创建直线命令
{
ads_point startPoint, endPoint;
//用户交互,获取点
int nReturn;
nReturn = acedGetPoint(NULL, _RXST("指定第一个点:"), startPoint);
if (nReturn != RTNORM){
AfxMessageBox(_RXST("点选失败."));
return;
}
//记录坐标点的数目
int PotNumber = 1;
ads_point temp_point;
temp_point[X] = startPoint[X], temp_point[Y] = startPoint[Y];
while (true){
acedInitGet(NULL, _T("U C"));
if (PotNumber >= 3){
nReturn = acedGetPoint(temp_point, _RXST("\n指定下一点或闭合(C)或放弃(U):"), endPoint);
}
else {
nReturn = acedGetPoint(temp_point, _RXST("\n指定下一点或放弃(U):"), endPoint);
}
//判断时关键字or按下一点or其他
if (nReturn == RTKWORD)//关键字
{
ACHAR kword[20];
if (acedGetInput(kword) != RTNORM){
return;
}
if (_tcscmp(kword, _T("U")) == 0){
acutPrintf(_RXST("放弃 创建直线."));
return;
}
else if (_tcscmp(kword, _T("C")) == 0){
if (PotNumber < 3)
continue;
AcGePoint3d AcGeStartPot = asPnt3d(temp_point);
AcGePoint3d AcGeEndPot = asPnt3d(startPoint);
AcDbLine *pLine = new AcDbLine(AcGeStartPot, AcGeEndPot);
HysuEditor::PostToModelSpace(pLine);
acutPrintf(_RXST("闭合直线."));
return;
}
else
AfxMessageBox(_RXST("关键字无效."));
}
else if (nReturn == RTNORM)//按下一点
{
PotNumber++;
AcGePoint3d AcGeStartPot = asPnt3d(temp_point);
AcGePoint3d AcGeEndPot = asPnt3d(endPoint);
AcDbLine *pLine = new AcDbLine(AcGeStartPot, AcGeEndPot);
HysuEditor::PostToModelSpace(pLine);
//将下一点坐标转换成下一直线的起始点
temp_point[X] = endPoint[X], temp_point[Y] = endPoint[Y];
}
else//其他
{
acutPrintf(_RXST("\n已退出 创建直线."));
return;
}
}
}
AcDbObjectId HysuEditor::PostToModelSpace(AcDbEntity *pEnt, AcDbDatabase *pDb)
{
AcDbBlockTable *pBlkTbl = NULL;
Acad::ErrorStatus es;
es = pDb->getBlockTable(pBlkTbl, AcDb::kForRead);
if (es != Acad::eOk)
{
acutPrintf(_T("\n块表打开失败,错误代码:%s"), acadErrorStatusText(es));
return AcDbObjectId::kNull;
}
AcDbBlockTableRecord *pBlkTblRcd = NULL;
es = pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
if (es != Acad::eOk)
{
acutPrintf(_T("\n模型空间块表记录打开失败,错误代码:%s"), acadErrorStatusText(es));
pBlkTbl->close();
return AcDbObjectId::kNull;
}
pBlkTbl->close();
AcDbObjectId outId;
es = pBlkTblRcd->appendAcDbEntity(outId, pEnt);
if (es != Acad::eOk)
{
acutPrintf(_T("\n无法添加实体到模型空间,错误代码:%s"), acadErrorStatusText(es));
pBlkTblRcd->close();
return AcDbObjectId::kNull;
}
pEnt->close();
pBlkTblRcd->close();
return outId;
} |
|