1. 程式人生 > >散線轉化成多段線

散線轉化成多段線

dal ack acad get str tor open rtp dstar

std::vector<entStruct> vecInfo;
AcDbObjectIdArray idarr=CDwgDatabaseUtil::GetAllEntityIds();
int iLen = idarr.length();
for (int i = 0; i < iLen;i++)
{
entStruct eTemp;
AcDbObjectId idTemp = idarr[i];
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es;
es = acdbOpenAcDbEntity(pEnt, idTemp, AcDb::kForWrite);
if (es!=eOk)
{
continue;
}
if (pEnt->isKindOf(AcDbLine::desc()))
{
AcDbLine *pLine = static_cast<AcDbLine*>(pEnt);
eTemp.id = idTemp;
eTemp.rx = AcDbLine::desc();
eTemp.ptStr = pLine->startPoint();
eTemp.ptEnd = pLine->endPoint();
eTemp.dBulge = 0;
vecInfo.push_back(eTemp);
pEnt->close();
}
else if (pEnt->isKindOf(AcDbArc::desc()))
{
AcDbArc *pArc = static_cast<AcDbArc*>(pEnt);
eTemp.id = idTemp;
eTemp.rx = AcDbArc::desc();
AcGePoint3d pts, pte;
pArc->getStartPoint(pts);
pArc->getEndPoint(pte);
eTemp.ptStr = pts;
eTemp.ptEnd = pte;
double dStart = pArc->startAngle();
double dEnd = pArc->endAngle();
double dAlfa = dEnd - dStart;
if (dAlfa<0)
{
dAlfa += CMathUtil::PI()*2;
}
double dBu = tan((dAlfa) / 4.0);
eTemp.dBulge = dBu;
vecInfo.push_back(eTemp);
pEnt->close();
}
else
{
pEnt->close();
}
}

size_t iS = vecInfo.size();
entStruct entTemp = vecInfo[0];
AcGePoint3d pPolyStr=entTemp.ptEnd;
AcGePoint3d pPolyEnt = entTemp.ptStr;
AcDbObjectId idTemp = entTemp.id;

AcDbPolyline *pPoly = new AcDbPolyline;
pPoly->addVertexAt(0, CConvertUtil::ToPoint2d(pPolyStr));
int iMark = 1;
for (int j = 0; j < iS;j++)
{
for (int i = 0; i < iS; i++)
{
entStruct eT = vecInfo[i];
if (idTemp==eT.id)
{
continue;
}
if (eT.ptStr == pPolyStr)
{
if (eT.rx == AcDbLine::desc())
{
pPoly->addVertexAt(iMark, CConvertUtil::ToPoint2d(eT.ptEnd));
pPolyStr = eT.ptEnd;
iMark++;
idTemp = eT.id;
break;
}
if (eT.rx==AcDbArc::desc())
{
pPoly->setBulgeAt(iMark - 1,eT.dBulge);
pPoly->addVertexAt(iMark, CConvertUtil::ToPoint2d(eT.ptEnd));
pPolyStr = eT.ptEnd;
iMark++;
idTemp = eT.id;
break;
}
}
else if (eT.ptEnd == pPolyStr)
{
if (eT.rx == AcDbLine::desc())
{
pPoly->addVertexAt(iMark, CConvertUtil::ToPoint2d(eT.ptStr));
pPolyStr = eT.ptStr;
iMark++;
idTemp = eT.id;
break;
}
if (eT.rx == AcDbArc::desc())
{
pPoly->setBulgeAt(iMark - 1, eT.dBulge);
pPoly->addVertexAt(iMark, CConvertUtil::ToPoint2d(eT.ptEnd));
pPolyStr = eT.ptStr;
iMark++;
idTemp = eT.id;
break;
}
}
else
{
continue;
}
}
}
if (entTemp.rx==AcDbArc::desc())
{
pPoly->setBulgeAt(iMark-1, entTemp.dBulge);
}

CDwgDatabaseUtil::PostToModelSpace(pPoly);

散線轉化成多段線