|
[code]void drawEntity(AcDbEntity* pEntity);app
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];spa
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();
}.net
//如下为函数
//打断于点
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();
}[/code] |
|