天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 4|回复: 0

【转载】曲线打断、求交点

[复制链接]
  • TA的每日心情
    开心
    昨天 15:23
  • 签到天数: 69 天

    [LV.6]常住居民II

    410

    主题

    167

    回帖

    2704

    积分

    管理员

    积分
    2704
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    [code]void drawEntity(AcDbEntity* pEntity);
     bool breakCurve(AcDbCurve* curve, AcGePoint3d pt);
     bool breakCurve(AcDbCurve* curve, AcGePoint3d p1, AcGePoint3d p2);


     static void Mybreak2008_Mybreak(void)
     {
         // Add your code for command Mybreak2008._Mybreak here
         ads_point pt1,pt2;
         ads_name entName;
         Acad::ErrorStatus es;
         int ret;
         ACHAR kWord[100];


         if (acedEntSel(_T("\n选择所要打断的曲线:"), entName, pt1) !=RTNORM)
         {
             return;
         }
         AcDbObjectId entId;
         AcDbCurve *pCurve=NULL;
         AcDbEntity *pEnt = NULL;
         es = acdbGetObjectId(entId, entName);
         if (es != Acad::eOk)
         {
            return;
         }
         acdbOpenObject(pEnt, entId, AcDb::kForWrite);
         if (pEnt->isKindOf(AcDbCurve::desc()))
         {
            pCurve = AcDbCurve::cast(pEnt);
            if (pCurve != NULL)
            {
               acedInitGet (NULL, _T("F"));
               ret=acedGetPoint(NULL,_T("\n指定第二个打断点或[第一点(F)]:"),pt2);
               switch (ret)
               {
                   case RTKWORD:
                       ret=acedGetInput(kWord);
                       if ( ret!= RTNORM )
                           break ;
                       acedInitGet(RSG_NONULL, _T(""));
                       ret=acedGetPoint(NULL,_T("\n指定第一个打断点:"),pt1);
                       if (ret!=RTNORM)
                           break;
                       acedInitGet(RSG_NONULL, _T(""));
                       ret=acedGetPoint(NULL,_T("\n指定第二个打断点:"),pt2);
                       if (ret!=RTNORM)
                          break;
                       breakCurve(pCurve,asPnt3d(pt1), asPnt3d(pt2));
                       break;
                   case RTNONE:
                       breakCurve(pCurve,asPnt3d(pt1));
                       break;
                    case RTNORM:
                       breakCurve(pCurve,asPnt3d(pt1), asPnt3d(pt2));
                        break;
                  default:
                       break;
               }
            }
         }
         pEnt->close();
     }


     //以下为函数
     //打断于点
     bool breakCurve(AcDbCurve* curve,AcGePoint3d pt)
     {
         AcGePoint3d p1;
         curve->getClosestPointTo(pt,p1);
         double param;
         curve->getParamAtPoint(p1,param);
         AcGeDoubleArray params;
         params.append(param);
         AcDbVoidPtrArray curveSegments;
         curve->getSplitCurves(params, curveSegments);
         AcDbEntity* ent =NULL;
         if (curveSegments.length()==2)
         {
             ent=(AcDbEntity*)curveSegments[0];
             drawEntity(ent);
             ent->close();
             ent=(AcDbEntity*)curveSegments[1];
             drawEntity(ent);
             ent->close();
             curve->erase();
         }
         else
         {
             curve->close();
         }   
         return true ;
     }
     //两点打断
     bool breakCurve(AcDbCurve* curve, AcGePoint3d p1, AcGePoint3d p2)
     {
         AcGePoint3d p11;
         curve->getClosestPointTo(p1,p11);
         double param1;
         curve->getParamAtPoint(p11,param1);
         AcGePoint3d p21;
         curve->getClosestPointTo(p2,p21);
         double param2;
         curve->getParamAtPoint(p21,param2);
         AcGeDoubleArray params;
    &#160;&#160;&#160;&#160;&#160;if&#160;(param1<param2)
    &#160;&#160;&#160;&#160;&#160;{
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;params.append(param1);
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;params.append(param2);
    &#160;&#160;&#160;&#160;&#160;}
    &#160;&#160;&#160;&#160;&#160;else
    &#160;&#160;&#160;&#160;&#160;{
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;params.append(param2);
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;params.append(param1);
    &#160;&#160;&#160;&#160;&#160;}
    &#160;&#160;&#160;&#160;&#160;AcDbVoidPtrArray&#160;curveSegments;
    &#160;&#160;&#160;&#160;&#160;curve->getSplitCurves(params,&#160;curveSegments);
    &#160;&#160;&#160;&#160;&#160;AcDbEntity*&#160;ent&#160;=NULL;
    &#160;&#160;&#160;&#160;&#160;if&#160;(curveSegments.length()==2)
    &#160;&#160;&#160;&#160;&#160;{
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ent=(AcDbEntity*)curveSegments[1];
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;drawEntity(ent);
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ent->close();
    &#160;&#160;&#160;&#160;&#160;}
    &#160;&#160;&#160;&#160;&#160;else&#160;if&#160;(curveSegments.length()==3)
    &#160;&#160;&#160;&#160;&#160;{
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ent=(AcDbEntity*)curveSegments[0];
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;drawEntity(ent);
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ent->close();
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ent=(AcDbEntity*)curveSegments[2];
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;drawEntity(ent);
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ent->close();
    &#160;&#160;&#160;&#160;&#160;}
    &#160;&#160;&#160;&#160;&#160;curve->erase();
    &#160;&#160;&#160;&#160;&#160;return&#160;true&#160;;
    &#160;}
    &#160;//绘制打断的曲线
    &#160;void&#160;drawEntity(AcDbEntity*&#160;pEntity)
    &#160;{
    &#160;&#160;&#160;&#160;&#160;AcDbBlockTable&#160;*pBlockTable;
    &#160;&#160;&#160;&#160;&#160;acdbHostApplicationServices()->workingDatabase()
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;->getSymbolTable(pBlockTable,&#160;AcDb::kForRead);
    &#160;&#160;&#160;&#160;&#160;AcDbBlockTableRecord&#160;*brec;
    &#160;&#160;&#160;&#160;&#160;resbuf&#160;tilemode;
    &#160;&#160;&#160;&#160;&#160;acedGetVar(_T("TILEMODE"),&tilemode);
    &#160;&#160;&#160;&#160;&#160;int&#160;tile=tilemode.resval.rint;
    &#160;&#160;&#160;&#160;&#160;if&#160;(tile)
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pBlockTable->getAt(ACDB_MODEL_SPACE,&#160;brec,AcDb::kForWrite);
    &#160;&#160;&#160;&#160;&#160;else
    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pBlockTable->getAt(ACDB_PAPER_SPACE,&#160;brec,AcDb::kForWrite);
    &#160;&#160;&#160;&#160;&#160;pBlockTable->close();
    &#160;&#160;&#160;&#160;&#160;AcDbObjectId&#160;entid;
    &#160;&#160;&#160;&#160;&#160;brec->appendAcDbEntity(entid,&#160;pEntity);
    &#160;&#160;&#160;&#160;&#160;&#160;brec->close();&#160;&#160;&#160;&#160;&#160;
    &#160;&#160;}[/code]

     

     

     

     

    【转载】曲线打断、求交点
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|

    GMT+8, 2024-7-1 05:45 , Processed in 0.057214 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表