多段线
AcDbObjectId FymPolyline::Add(const AcGePoint2dArray& points, double width, Adesk::Boolean isClosed){
int numVerts = points.length();//计算输入点数组的长度
AcDbPolyline* pPline = new AcDbPolyline(numVerts);
for (int i = 0; i < points.length(); i++)
{
pPline->addVertexAt(i, points.at(i), 0, width, width, 0); //将每个点添加到多段线中
}
pPline->setClosed(isClosed);//为真,则多线段将被设置为闭合
return FymDatabase::PostToModelSpace(pPline);
}
AcDbObjectId FymPolyline::Add(const AcGePoint2d& ptStart, const AcGePoint2d& ptEnd, double width)
{
AcGePoint2dArray points;
points.append(ptStart);
points.append(ptEnd);
return Add(points, width);
}
//2d多段线
AcDbObjectId FymPolyline::Add2dPolyline(const AcGePoint3dArray& points, double startWidth, double endWidth, Adesk::Boolean isClosed)
{
AcGePoint3dArray verPoints = points;
AcDb2dPolyline* pPline = new AcDb2dPolyline(AcDb::k2dSimplePoly, verPoints, 0, isClosed, startWidth, endWidth);
return FymDatabase::PostToModelSpace(pPline);
}
//3d多段线
AcDbObjectId FymPolyline::Add3dPolyline(const AcGePoint3dArray& points)
{
AcGePoint3dArray verPts = points;
AcDb3dPolyline* pPline = new AcDb3dPolyline(AcDb::k3dSimplePoly, verPts);
return FymDatabase::PostToModelSpace(pPline);
}
//正多边形,(rotation)为旋转角度
AcDbObjectId FymPolyline::Add3dPolyGon(const AcGePoint2d& ptCenter, int number, double radius, double rotation, double width)
{
double angle = 2 * FymMathUtil::PI() / (double)number;//计算每个顶点与中心的夹角
AcGePoint2dArray points;//存储多段线的所有顶点
for (int i = 0; i < number; i++)
{
AcGePoint2d pt;
pt.x = ptCenter.x + radius * cos(i * angle);
pt.y = ptCenter.y + radius * sin(i * angle);
points.append(pt);
}
AcDbObjectId polyId = Add(points, width, Adesk::kTrue);
FymEditor::Rotate(polyId, ptCenter, rotation);
return polyId;
}
//对角线矩形
AcDbObjectId FymPolyline::AddRectang(const AcGePoint2d& pt1, const AcGePoint2d& pt2, double width)
{
double x1 = pt1.x, x2 = pt2.x;
double y1 = pt1.y, y2 = pt2.y;
AcGePoint2d ptLeftBottom(min(x1, x2), min(y1, y2));
AcGePoint2d ptRightBottom(max(x1, x2), min(y1, y2));
AcGePoint2d ptRightTop(max(x1, x2), max(y1, y2));
AcGePoint2d ptLeftTop(min(x1, x2), max(y1, y2));
AcGePoint2dArray points;
points.append(ptLeftBottom);
points.append(ptRightBottom);
points.append(ptRightTop);
points.append(ptLeftTop);
return Add(points, width, Adesk::kTrue);
}
//测试:小爱心,bulge0.5为四分之一圆
AcDbObjectId FymPolyline::AddPolyCircle(const AcGePoint2d& ptCenter, double radius, double width)
{
AcGePoint2d pt1, pt2, pt3, pt4;
pt1.x = ptCenter.x + radius;
pt1.y = ptCenter.y;
pt2.x = ptCenter.x - radius;
pt2.y = ptCenter.y;
pt3.x = ptCenter.x ;
pt3.y = ptCenter.y + radius;
pt4.x = ptCenter.x;
pt4.y = ptCenter.y - radius;
AcDbPolyline* pPloy = new AcDbPolyline(4);
pPloy->addVertexAt(0, pt1, 1, width, width);
pPloy->addVertexAt(1, pt3, 1, width, width);
pPloy->addVertexAt(2, pt2, 0.1, width, width);
pPloy->addVertexAt(3, pt4, 0.1, width, width);
pPloy->setClosed(Adesk::kTrue);
return FymDatabase::PostToModelSpace(pPloy);
}
AcDbObjectId FymPolyline::SetWidth(const AcDbObjectId& polyId, ads采用real width)
{
AcDbPolyline* pPline = NULL;
if (acdbOpenObject(pPline,polyId,AcDb::kForWrite)==Acad::eOk)
{
pPline->setConstantWidth(width);
pPline->close();
}
return FymDatabase::PostToModelSpace(pPline);
}
页:
[1]