www.mxdraw.com
内容索引主面
前一个向上下一个
McDbCurve 类

曲线类型,实现了曲线的相关操作,如求曲线的长度,最近点,面积,曲线上任一点在曲线上的长度 切向方向,曲线交点,坐标变换,打断,偏移,离散等功能

C++
class McDbCurve : public McDbEntity;

McDbCurve.h

例如:偏移曲线代码

    void CTestCommands::OffsetPolyline()
    {
        ads_name entName;
        ads_point pt;
        if(acedEntSel(_T("需要偏移的PL线:"),entName,pt) != RTNORM)
        {
            return;
        }

        AcDbObjectId objId;
        if(acdbGetObjectId(objId,entName) != Acad::eOk)
            return;

        McDbObjectPointer<McDbPolyline> spPolyline(objId,AcDb::kForRead);
        if(spPolyline.openStatus() != Acad::eOk)
        {
            acutPrintf(_T("n 请选择Polyline"));
            return;
        }


        ads_point tmpPt1;
        if(acedGetPoint(NULL,_T("n 点取偏移点:"),tmpPt1) != RTNORM)
        {
            return;
        }

        ads_point tmpPt2;
        if(acedGetPoint(tmpPt1,_T("n 点取偏移距离:"),tmpPt2) != RTNORM)
        {
            return;
        }

        McGePoint3d pt1 = asPnt3d(tmpPt1);
        McGePoint3d pt2 = asPnt3d(tmpPt2);

        double dDis = pt1.distanceTo(pt2);
        if(fabs(dDis) < 0.01)
        {
            acutPrintf(_T("n 偏移距离为太小"));
            return;
        }

        McGePoint3d ptRef = pt1;
        McDbVoidPtrArray offsetCurves;

        if(spPolyline->getOffsetCurvesEx(dDis,offsetCurves,ptRef) != Mcad::eOk)
        {
            acutPrintf(_T("n 未知原因,偏移失败"));
            return;
        }

        // 对偏移后的PL线,按偏移距离,把突出的角导圆角。
        McGePoint3d startPt;
        spPolyline->getStartPoint(startPt);

        for(int i = 0 ; i < offsetCurves.length();i++)
        {
            McDbEntity* pEnt = (McDbEntity*)(offsetCurves[i]);
            ASSERT(pEnt != NULL);

            if(McDbPolyline::cast(pEnt) != NULL)
            {
                McDbPolyline* pNewPolyline = GetNewPolyline(startPt,McDbPolyline::cast(pEnt),dDis );
                if(pNewPolyline != NULL)
                {
                    MrxDbgUtils::addToCurrentSpace(pNewPolyline);
                    pNewPolyline->close();
                    delete pEnt;
                    pEnt = NULL;
                }

            }

            if(pEnt != NULL)
            {
                MrxDbgUtils::addToCurrentSpaceAndClose(pEnt);
            }
        }
    }

求曲线的长度

    void GetCurveLenght()
    {
        ads_name entName;
        ads_point pt;
        if(acedEntSel(_T("选择曲线:"),entName,pt) != RTNORM)
        {
            return;
        }

        AcDbObjectId objId;
        if(acdbGetObjectId(objId,entName) != Acad::eOk)
            return;

        McDbObjectPointer<McDbCurve> spCurve(objId,AcDb::kForRead);
        if(spCurve.openStatus() != Acad::eOk)
        {
            acutPrintf(_T("n 请选择曲线"));
            return;
        }

        double dEndParam = 0.0;
        spCurve->getEndParam(dEndParam);

        double dist = 0.0;
        spCurve->getDistAtParam(dEndParam,dist);

        CString sT;
        sT.Format(_T("曲线的上度:%lf"),dist);
        AfxMessageBox(sT);
    }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!