|
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS 采用RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CBreakLineApp : public AcRxArxApp {
public:
CBreakLineApp() : AcRxArxApp() {}
virtual AcRx::AppRetCode On采用kInitAppMsg(void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On采用kInitAppMsg(pkt);
return (retCode);
}
virtual AcRx::AppRetCode On采用kUnloadAppMsg(void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On采用kUnloadAppMsg(pkt);
return (retCode);
}
virtual void RegisterServerComponents() { }
//////////////////////////////////////////////////////////////////////////
// Adding entity to Database
//////////////////////////////////////////////////////////////////////////
static Acad::ErrorStatus postToDwg(AcDbEntity *pEnt, AcDbDatabase *pDb = NULL, ACHAR *requiredSpace = NULL)
{
// if the default database is to be used
if (pDb == NULL)
{
pDb = acdbHostApplicationServices()->workingDatabase();
}
AcDbBlockTable *blockTable = NULL;
// get a pointer to the block table
Acad::ErrorStatus es = pDb->getBlockTable(blockTable, AcDb::kForRead);
// if it failed then abort
if (es != Acad::eOk)
return (es);
AcDbBlockTableRecord *blockTableRecord = NULL;
// now get a pointer to the model space entity records
if (requiredSpace)
{
es = blockTable->getAt(requiredSpace, blockTableRecord, AcDb::kForWrite);
}
else
{
es = acdbOpenObject(blockTableRecord, pDb->currentSpaceId(), AcDb::kForWrite);
}
// can close the block table itself as we don't need it anymore
blockTable->close();
// if it failed then abort
if (es != Acad::eOk)
return (es);
// otherwise put the entity into the model space
es = blockTableRecord->appendAcDbEntity(pEnt);
// now close it up
blockTableRecord->close();
// close entity
return (es);
}
static void RivilisBreakLine()
{
ads采用name en;
AcGePoint3d p;
Acad::ErrorStatus es = Acad::eOk;
//////////////////////////////////////////////////////////////////////////
// Calculation gap length
//////////////////////////////////////////////////////////////////////////
resbuf rb;
acedGetVar(采用ACRX采用T("PDSIZE"), &rb);
double radius = rb.resval.rreal * 0.5;
if (radius < 1e-12 && radius > -1e-12)
radius = -5.0;
if (radius <= 1e-12)
{
acedGetVar(采用ACRX采用T("VIEWSIZE"), &rb);
radius = -radius * rb.resval.rreal / 100.0;
}
//////////////////////////////////////////////////////////////////////////
if (acedEntSel(L"\nSelect curve: ", en, asDblArray(p)) == RTNORM)
{
AcDbObjectId idCurve; acdbGetObjectId(idCurve, en);
AcDbObjectPointer<AcDbCurve> pCurve(idCurve, AcDb::kForRead);
if ((es = pCurve.openStatus()) != Acad::eOk)
{
acutPrintf(L"\nError open curve: %s", acadErrorStatusText(es));
return;
}
AcGeDoubleArray pts;
AcGePoint3d pNear = p; pCurve->getClosestPointTo(p, pNear);
AcDbPoint *pDbPoint = new AcDbPoint(pNear);
pDbPoint->setDatabaseDefaults();
postToDwg(pDbPoint);
pDbPoint->close();
if (es == Acad::eOk)
{
AcDbCircle *pCircle = new AcDbCircle(p, AcGeVector3d::kZAxis, radius);
AcGePlane plane(p, AcGeVector3d::kZAxis);
AcGePoint3dArray ptsInts;
pCurve->intersectWith(pCircle, AcDb::kOnBothOperands, plane, ptsInts);
delete pCircle;
if (ptsInts.length() >= 2)
{
AcGePoint3d ptFirst = ptsInts[0], ptLast = ptsInts[ptsInts.length() - 1];
pCurve->getClosestPointTo(ptsInts[0], ptFirst);
pCurve->getClosestPointTo(ptsInts[ptsInts.length() - 1], ptLast);
double paramFirst = 0, paramLast = 0;
pCurve->getParamAtPoint(ptFirst, paramFirst);
pCurve->getParamAtPoint(ptLast, paramLast);
if (paramFirst > paramLast)
{
pts.append(paramLast);
pts.append(paramFirst);
}
else
{
pts.append(paramFirst);
pts.append(paramLast);
}
}
else
{
double param = 0;
pCurve->getParamAtPoint(pNear, param);
pts.append(param);
}
}
else
{
double param = 0;
pCurve->getParamAtPoint(pNear, param);
pts.append(param);
}
AcDbVoidPtrArray aSegs;
if ((es = pCurve->getSplitCurves(pts, aSegs)) != Acad::eOk)
{
acutPrintf(L"\npCurve->getSplitCurves: %s", acadErrorStatusText(es));
return;
}
if (aSegs.length() > 1)
{
AcDbEntity *pEnt = reinterpret采用cast<AcDbEntity *>(aSegs[0]);
if (postToDwg(pEnt) == Acad::eOk) pEnt->close();
else delete pEnt;
pEnt = reinterpret采用cast<AcDbEntity *>(aSegs[aSegs.length() - 1]);
if (postToDwg(pEnt) == Acad::eOk) pEnt->close();
else delete pEnt;
if (pCurve->upgradeOpen() == Acad::eOk) pCurve->erase();
}
}
}
};
//-----------------------------------------------------------------------------
IMPLEMENT采用ARX采用ENTRYPOINT(CBreakLineApp)
ACED采用ARXCOMMAND采用ENTRY采用AUTO(CBreakLineApp, Rivilis, BreakLine, BreakLine, ACRX采用CMD采用MODAL, NULL) |
|