// (C) Copyright 2002-2012 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
static AcGePoint3dArray IntersectRoutine(AcDbSurface *pSurface, AcGeLineSeg3d &line)
{
AcGeContext::gTol.setEqualPoint(1.0e-8);
AcGeContext::gTol.setEqualVector(1.0e-6);
AcGePoint3dArray returnPtArray;
AcDbBody* pBody = new AcDbBody();
Acad::ErrorStatus es = pBody->setASMBody(pSurface->ASMBodyCopy(true));
// build AcBrBrep
AcBrBrep* pBrep = new AcBrBrep();
//
if(AcBr::eOk == pBrep->set(*pBody))
{
AcBrBrepFaceTraverser* pFaceTrav = new AcBrBrepFaceTraverser;
if(AcBr::eOk == pFaceTrav->setBrep(*pBrep))
{
for(pFaceTrav->restart();!pFaceTrav->done();pFaceTrav->next())
{
AcBrFace face;
if(AcBr::eOk == pFaceTrav->getFace(face))
{
double area = 0.0f;
face.getSurfaceArea(area);
acutPrintf(L"\nSurface Area: %f", area);
//****real surface of the original AcDbSurface
AcGeExternalBoundedSurface** nurbs = NULL;
Adesk::UInt32 numNurbs = 0;
face.getSurfaceAsTrimmedNurbs(numNurbs,nurbs);
//*****
for (Adesk::UInt32 i = 0; i < numNurbs; i++)
{
// AcGeCurveSurfInt curveSI(line, *nurbs[i]);
AcGeCurveSurfInt curveSI;
AcGeIntersectError err_1 = AcGe::kXXOk;
//input the curve and line
curveSI.set(line,*nurbs[i]);
//get the count of intersect points
int count = curveSI.numIntPoints(err_1); // <- Always err_1 == kXXUnknown if line is AcGeLine3d
if(err_1 == AcGe::kXXOk && count > 0 )
{
AcGeIntersectError err_2 = AcGe::kXXOk;
for(int index = 0; index < count; index ++)
{
AcGePoint3d pt = curveSI.intPoint(index,err_2);
if (err_2 == AcGe::kXXOk) {
returnPtArray.append(pt);
}
}
}
delete nurbs[i];
}
// your responsibility to delete the
// array of surfaces
delete[] nurbs;
}
}
}
delete pFaceTrav;
}
delete pBrep;
delete pBody;
return returnPtArray;
}
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CCurveIntSurfApp : public AcRxArxApp {
public:
CCurveIntSurfApp () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here
// You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
static void CurvIntCurveIntSurf () {
// Put your command code here
ads_name ename;
ads_point pickpt;
AcDbObjectId objId;
int rc;
// select a surface
rc = acedEntSel(L"\nSelect Surface: ", ename, pickpt);
if(rc != RTNORM)
{
if (rc != RTCAN) acutPrintf(L"\nError selecting entity ");
return;
}
ads_point p1,p2;
if (acedGetPoint(NULL,L"\nPoint 1: ", p1) != RTNORM ||
acedGetPoint(p1 ,L"\nPoint 2: ", p2) != RTNORM) return;
acdbGetObjectId(objId, ename);
AcDbEntityPointer pObj(objId, AcDb::kForRead);
if (pObj.openStatus() == Acad::eOk) {
AcDbSurface* pEntity1 = AcDbSurface::cast(pObj);
if (!pEntity1) {
acutPrintf(L"\nSelection Invalid...");
return;
}
// call Intersect
AcGePoint3dArray points = IntersectRoutine( pEntity1, AcGeLineSeg3d(asPnt3d(p1), asPnt3d(p2)));
if(points.length() > 0)
{
for (int i = 0; i < points.length(); i++) {
acutPrintf(L"\nPoint(%d) (%g %g %g)", i, points[i].x, points[i].y, points[i].z);
}
}
}
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CCurveIntSurfApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CCurveIntSurfApp, CurvInt, CurveIntSurf, CurveIntSurf, ACRX_CMD_MODAL, NULL)