|
[code]
void CArcBlockJigEntity::DrawOrAddSubEnts(AcGiWorldDraw* mode)
{
//绘制圆弧
AcDbCurve *pCurve = NULL; //计算等分点的曲线
AcGePoint2d startPoint2d = ToPoint2d(m_startPoint);
AcGePoint2d thirdPoint2d = ToPoint2d(m_thirdPoint);
AcGePoint2d endPoint2d = ToPoint2d(m_endPoint);
if (ThreePointIsCollinear(startPoint2d, thirdPoint2d, endPoint2d))
{
AcGePoint3d verts[2];
verts[0] = m_startPoint;
verts[1] = m_endPoint;
if (mode != NULL)
{
mode->geometry().polyline(2, verts);
}
pCurve = new AcDbLine(m_startPoint, m_endPoint);//创建直线段
}
else
{
if (mode != NULL)
{
mode->geometry().circularArc(m_startPoint, m_thirdPoint, m_endPoint);
}
AcGeCircArc2d geArc(startPoint2d, thirdPoint2d, endPoint2d);
//geArc的起始角度始终是0,因此单独计算起始角度和终止角度
AcGeVector2d vecStart = startPoint2d - geArc.center();
AcGeVector2d vecEnd = endPoint2d - geArc.center();
//AcGeArc必须是逆时针,因此需要根据三点的旋转方向,确定正确的起始
//角度
double startAngle = 0;
if (PtInLeftOfLine(startPoint2d, thirdPoint2d, endPoint2d) > 0)
//逆时针
{
startAngle = vecStart.angle();
}
else
{
startAngle = vecEnd.angle();
}
double endAngle = startAngle + (geArc.endAng() - geArc.startAng());
pCurve = new AcDbArc(ToPoint3d(geArc.center()), geArc.radius(),
startAngle, endAngle);
//计算等分点,获得块参照插入的位置
double startParam = 0, endParam = 0; //曲线的起点和终点参数
pCurve->getStartParam(startParam);
pCurve->getEndParam(endParam);
int intervalCount = m_blockCount + 1; //等分间距份数比块参照数量大1
double paramInterval = (endParam - startParam) / intervalCount;
AcGePoint3dArray blkRefPoints; //块参照插入点的集合
for (int i = 1; i < intervalCount; i++) //曲线的起点和终点不需要放置图块
{
double param = startParam + i * paramInterval;
AcGePoint3d pt;
pCurve->getPointAtParam(param, pt);
blkRefPoints.append(pt);
}
if (mode != NULL) //显示子实体
{
delete pCurve; //动态分配的实体,不加入模型空间,使用完毕之后需要释放
}
else //添加子实体的方式
{
PostToModelSpace(pCurve);
}
//绘制几个图块
m_blkRefIds.setLogicalLength(0);
for (int i = 0; i < blkRefPoints.length(); i++)
{
AcDbBlockReference *pBlkRef = new AcDbBlockReference(blkRefPoints[i], m_blkDefId);
if (mode != NULL)
{
pBlkRef->worldDraw(mode);
delete pBlkRef;
}
else
{
m_blkRefIds.append(PostToModelSpace(pBlkRef));
}
}
}
}[/code] |
|