//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
Acad::ErrorStatus postToDatabase (/*[in]*/AcDbDatabase *pDb /*=NULL*/, AcDbEntity *pEnt, AcDbObjectId &idObj);
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CTest3dsolidApp : public AcRxArxApp {
public:
CTest3dsolidApp () : AcRxArxApp () {}
AcString AsdkHlrApi;
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg (pkt) ;
// Загружаем нужную версию HlrApi
int ver = acdbHostApplicationServices()->releaseMajorVersion();
AsdkHlrApi.format(_T("AsdkHlrApi%d.dbx"),ver);
acedArxLoad(AsdkHlrApi);
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
acedArxUnload(AsdkHlrApi);
return (retCode) ;
}
virtual void RegisterServerComponents () { }
static void RivilisTestConv () {
int nPoints = 8 ;
int nTriangles = 12 ;
int nIndices = 3 * nTriangles ;
double p [] = {
0, 0, 0,
1, 0, 0,
1, 1, 0,
0, 1, 0,
0, 0, 1,
1, 0, 1,
1, 1, 1,
0, 1, 1
} ;
int i [] = {
0, 1, 5, 0, 5, 4,
1, 6, 5, 1, 2, 6,
4, 5, 6, 4, 6, 7,
7, 0, 4, 7, 3, 0,
2, 0, 3, 2, 1, 0,
7, 6, 3, 6, 2, 3
} ;
AcGeIntArray indices (nIndices) ;
indices.setLogicalLength (nIndices) ;
indices.setPhysicalLength (nIndices) ;
memcpy (indices.asArrayPtr (), i, nIndices * sizeof (int)) ;
AcGePoint3dArray gePts (nPoints) ;
gePts.setLogicalLength (nPoints) ;
gePts.setPhysicalLength (nPoints) ;
memcpy (gePts.asArrayPtr(), p, nPoints * sizeof (AcGePoint3d)) ;
void *acisBody = createBodyFromTriangles (gePts, indices) ;
AcDbObjectId id ;
// Получаем из треугольников AcDbBody, так как напрямую
// AcDb3dSolid получить не удаётся.
AcDbBody *pBody = new AcDbBody();
Acad::ErrorStatus es = pBody->setASMBody(acisBody);
// Преобразуем AcDbBody в поверхность AcDbSurface
AcBrBrep *pBrep = new AcBrBrep();
AcBr::ErrorStatus ebs = pBrep->set(*pBody);
AcDbSurface *pSurf = new AcDbSurface() ;
ebs = pBrep->get(pSurf);
// Получаем из AcDbSurface AcDb3dSolid
AcDb3dSolid *pSolid = new AcDb3dSolid();
es = pSolid->createFrom(pSurf);
// Добавляем в чертеж.
es = postToDatabase (NULL, pSolid, id) ;
delete pBrep; delete pSurf; delete pBody;
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CTest3dsolidApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CTest3dsolidApp, Rivilis, TestConv, TestConv, ACRX_CMD_MODAL, NULL)
Acad::ErrorStatus postToDatabase (/*[in]*/AcDbDatabase *pDb /*=NULL*/, AcDbEntity *pEnt, AcDbObjectId &idObj) {
assert ( pEnt != NULL ) ;
if ( pDb == NULL )
pDb =acdbHostApplicationServices ()->workingDatabase () ;
Acad::ErrorStatus es ;
AcDbBlockTable *pBlockTable ;
if ( (es =pDb->getBlockTable (pBlockTable, AcDb::kForRead)) == Acad::eOk ) {
AcDbBlockTableRecord *pSpaceRecord ;
if ( (es =pBlockTable->getAt (ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite)) == Acad::eOk ) {
if ( (es =pSpaceRecord->appendAcDbEntity (idObj, pEnt)) == Acad::eOk )
pEnt->close () ;
pSpaceRecord->close () ;
}
pBlockTable->close () ;
}
return (es) ;
}