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

样条线类型

C++
class McDbSpline : public McDbCurve;

McDbSpline.h

例如:创建一个样条线代码

    CDrawSplineJig::CDrawSplineJig(void)
    {
        m_pSpline       = NULL;
        m_degree        = 3;
        m_fitTolerance  = AcGeContext::gTol.equalVector(); 
        m_periodic      = Adesk::kFalse;
    }

    CDrawSplineJig::~CDrawSplineJig(void)
    {
        ASSERT(m_pSpline == NULL);
    }


    AcEdJig::DragStatus 
    CDrawSplineJig::sampler()
    {

        AcGePoint3d point;
        AcEdJig::DragStatus ret = acquirePoint(point);
        if(ret == AcEdJig::kNormal)
        {
            McGePoint3dArray tmpFitPoint;
            tmpFitPoint = m_aryFitPoint;
            tmpFitPoint.append(point);


            m_getPt = point;
            if(tmpFitPoint.length() > 1 && m_pSpline != NULL)
            {
                m_pSpline->setFitData(tmpFitPoint,m_degree,m_fitTolerance,
                    m_startTangent,m_endTangent,m_periodic);
            }
        }
        return ret;
    }

    Adesk::Boolean CDrawSplineJig::update()
    {
        return Adesk::kTrue;
    }

    AcDbEntity* CDrawSplineJig::entity() const
    {
        return m_pSpline;
    }

    bool    CDrawSplineJig::DoIt()
    {


        ads_point pt;
        if(acedGetPoint(NULL,_T("n 指定第一个点:"),pt) != RTNORM)
        {
            return false;
        }

        m_aryFitPoint.append(McGePoint3d(pt[X],pt[Y],pt[Z]) );

        m_pSpline = new AcDbSpline;

        // 取每一个点。
        bool isSuc = false;
        while(true)
        {
            acutPrintf(_T("n 指定下一个点 <回车退出>:") );
            if(drag() != AcEdJig::kNormal)
            {
                break;
            }
            m_aryFitPoint.append(m_getPt);
            isSuc = true;
        }
        delete m_pSpline;
        m_pSpline = NULL;

        if(isSuc)
        {
            AcDbSpline* m_pAddSpline = new AcDbSpline;
            m_pAddSpline->setFitData(m_aryFitPoint,m_degree,m_fitTolerance,
                m_startTangent,m_endTangent,m_periodic);

            MrxDbgUtils::addToCurrentSpaceAndClose(m_pAddSpline);
        }


        return isSuc;
    }

离散曲线的代码

    void CSampleCurveJig::DoIt()
    {
        ads_name entName;
        ads_point pt;
        if(acedEntSel(_T("n 选择需要离散的实体:"),entName,pt) != RTNORM)
        {
            return;
        }
        AcDbObjectId objId;
        if(acdbGetObjectId(objId,entName) != Acad::eOk)
            return;

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

        if(AcDbSpline::cast(spCurve.object() ) != NULL
            || AcDbArc::cast(spCurve.object() ) != NULL
            || AcDbCircle::cast(spCurve.object() ) != NULL 
            || AcDbEllipse::cast(spCurve.object() ) != NULL 
            || AcDbPolyline::cast(spCurve.object() ) != NULL 
            )
        {
            double approxEps    = 0.1;          // 离散后的最小弧的弧高。

            AcGePoint3dArray pointArray;        // 返离后的点数组。
            AcGeDoubleArray  paramArray;

            spCurve->InnerGetSamplePoints(approxEps,pointArray,paramArray);

            if(pointArray.isEmpty() )
            {
                acutPrintf(_T("n 离散失败"));
            }
            else
            {
                AcGePoint3d tmpBt(pt[0],pt[1],pt[2]);
                // 报离散后的点,开始拖放,定位。

                m_pEnt = new CSampleCurveEnt(pointArray,tmpBt);

                if(drag() == AcEdJig::kNormal)
                {
                    AcGePoint3dArray aryPt;
                    m_pEnt->GetNewPosAryPt(aryPt);

                    for(int i = 1; i < aryPt.length();i++)
                    {
                        AcDbLine* pLine = new AcDbLine(aryPt[i -1],aryPt[i]);
                        CTestCommands::AddToModelSpace(pLine,acdbCurDwg() );
                        pLine->close();

                    }

                }

                delete m_pEnt;
                m_pEnt = NULL;

            }
        }
        else
        {
            acutPrintf(_T("n 请选择样条线实体"));
        }

    }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!