打斷曲線

原文地址:http://www.objectarx.net/bbs/viewthread.php?tid=1655&extra=page%3D1%26amp%3Bfilter%3Ddigest

 

找出了幾個重要的函數,分別是打斷曲線的getSplitCurves、求兩曲線交點的intersectwith。感謝ObjectARX編程站,讓我找到很多ObjectARX方面我需要的東西,以下就是我轉載的文章:

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;
  if (param1<param2)
  {
   params.append(param1);
   params.append(param2);
  }
  else
  {
   params.append(param2);
   params.append(param1);
  }
  AcDbVoidPtrArray curveSegments;
  curve->getSplitCurves(params, curveSegments);
  AcDbEntity* ent =NULL;
  if (curveSegments.length()==2)
  {
   ent=(AcDbEntity*)curveSegments[1];
   drawEntity(ent);
   ent->close();
  }
  else if (curveSegments.length()==3)
  {
   ent=(AcDbEntity*)curveSegments[0];
   drawEntity(ent);
   ent->close();
   ent=(AcDbEntity*)curveSegments[2];
   drawEntity(ent);
   ent->close();
  }
  curve->erase();
  return true ;
 }
 //繪製打斷的曲線
 void drawEntity(AcDbEntity* pEntity)
 {
  AcDbBlockTable *pBlockTable;
  acdbHostApplicationServices()->workingDatabase()
   ->getSymbolTable(pBlockTable, AcDb::kForRead);
  AcDbBlockTableRecord *brec;
  resbuf tilemode;
  acedGetVar(_T("TILEMODE"),&tilemode);
  int tile=tilemode.resval.rint;
  if (tile)
   pBlockTable->getAt(ACDB_MODEL_SPACE, brec,AcDb::kForWrite);
  else
   pBlockTable->getAt(ACDB_PAPER_SPACE, brec,AcDb::kForWrite);
  pBlockTable->close();
  AcDbObjectId entid;
  brec->appendAcDbEntity(entid, pEntity);
  brec->close();    
 }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章