//-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#define _USE_MATH_DEFINES
#include <math.h>
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
Acad::ErrorStatus postToDwg (AcDbEntity *pEnt, AcDbDatabase *pDb, ACHAR *requiredSpace);
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CCircleInAngleApp : public AcRxArxApp {
public:
CCircleInAngleApp () : 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 () { }
public:
// - CircleInAngle.CreateCircle command (do not rename)
static void CircleInAngleCreateCircle(void)
{
AcGePoint3d p1, p2, p3;
if (acedGetPoint(NULL, L"\nP1: ", asDblArray(p1)) != RTNORM) return;
if (acedGetPoint(asDblArray(p1), L"\nP2: ", asDblArray(p2)) != RTNORM) return;
if (acedGetPoint(asDblArray(p2), L"\nP3: ", asDblArray(p3)) != RTNORM) return;
double r = 0;
acedInitGet(7, NULL);
if (acedGetDist(asDblArray(p2), L"\nR: ", &r) != RTNORM) return;
// Первый отрезок
AcDbLine *pLine1 = new AcDbLine(p1, p2);
pLine1->setDatabaseDefaults(acdbCurDwg());
postToDwg(pLine1, NULL, NULL);
pLine1->close();
// Второй отрезок
AcDbLine *pLine2 = new AcDbLine(p2, p3);
pLine2->setDatabaseDefaults(acdbCurDwg());
postToDwg(pLine2, NULL, NULL);
pLine2->close();
AcGeVector3d v1 = p1 - p2;
AcGeVector3d v2 = p3 - p2;
double ang = v1.angleTo(v2);
// Расстояние до центра окружности из вершины угла
double l = r / sin (ang * 0.5);
// Строим биссектрису угла
AcGePoint3d p11 = p2 + AcGeVector3d(p1 - p2).normalize() * l;
AcGePoint3d p33 = p2 + AcGeVector3d(p3 - p2).normalize() * l;
AcGePoint3d pMid = p11 + AcGeVector3d(p33 - p11) * 0.5;
// Вектор биссиктрисы
AcGeVector3d vb = AcGeVector3d(pMid - p2).normalize();
// Точка центра вписанной окружности
AcGePoint3d pc = p2 + vb * l;
AcDbCircle *pCircle = new AcDbCircle(pc, AcGeVector3d::kZAxis, r);
pCircle->setDatabaseDefaults(acdbCurDwg());
postToDwg(pCircle, NULL, NULL);
pCircle->close();
}
} ;
Acad::ErrorStatus postToDwg (AcDbEntity *pEnt, AcDbDatabase *pDb, ACHAR *requiredSpace)
{
// 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);
}
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CCircleInAngleApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CCircleInAngleApp, CircleInAngle, CreateCircle, CC, ACRX_CMD_TRANSPARENT, NULL)