//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CSplitSplineApp : public AcRxArxApp {
public:
CSplitSplineApp() : 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() { }
static void RivilisSplitSpline() {
ads_name en; ads_point pt;
if (acedEntSel(L"\nВыберите самопересекающийся сплайн: ", en, pt) != RTNORM)
return;
AcDbObjectId id; acdbGetObjectId(id, en);
AcDbObjectPointer<AcDbSpline> pSpline(id, AcDb::kForRead);
Acad::ErrorStatus es = pSpline.openStatus();
if (es == Acad::eNotThatKindOfClass)
{
acutPrintf(L"\nЭто не сплайн!");
return;
}
else if (es != Acad::eOk)
{
acutPrintf(L"\nОшибка pSpline.openStatus() = %s", acadErrorStatusText(es));
return;
}
AcGeCurve3d *pgSpline = nullptr;
if ((es = pSpline->getAcGeCurve(pgSpline)) != Acad::eOk)
{
acutPrintf(L"\nОшибка pSpline->getAcGeCurve(pgSpline) = %s", acadErrorStatusText(es));
return;
}
AcGeCurveCurveInt3d cci3d;
cci3d.set(*pgSpline, *pgSpline);
int nInt = cci3d.numIntPoints();
if (nInt > 0)
{
std::set<double> parms;
double param = 0;
pSpline->getStartParam(param);
parms.insert(param);
for (int i = 0; i < nInt; i++)
{
if (cci3d.isTangential(i)) continue;
AcGePoint3d p = cci3d.intPoint(i);
double par1 = 0, par2 = 0;
cci3d.getIntParams(i, par1, par2);
acutPrintf(L"\nInt(%d)=(%g %g %g), par1=%g par2=%g", i, p.x, p.y, p.z, par1, par2);
parms.insert(par1); parms.insert(par2);
}
pSpline->getEndParam(param);
parms.insert(param);
AcGeDoubleArray parmsa;
parmsa.setPhysicalLength((int)parms.size());
for (std::set<double>::iterator it = parms.begin(); it != parms.end(); ++it)
{
parmsa.append(*it);
}
AcDbVoidPtrArray ents;
if (pSpline->getSplitCurves(parmsa, ents) == Acad::eOk)
{
AcDbBlockTableRecordPointer pCurrSpace(acdbCurDwg()->currentSpaceId(), AcDb::kForWrite);
if (pCurrSpace.openStatus() == Acad::eOk)
{
for (int i = 0; i < ents.length(); i++)
{
AcDbEntity *pEnt = static_cast<AcDbEntity *>(ents[i]);
pCurrSpace->appendAcDbEntity(pEnt);
pEnt->close();
}
}
}
}
else
{
acutPrintf(L"\nЭто не самопересекающийся сплайн!");
}
}
};
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CSplitSplineApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CSplitSplineApp, Rivilis, SplitSpline, SplitSpline, ACRX_CMD_MODAL, NULL)