天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 115|回复: 0

圆打断曲线

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-5-25 11:13:48 | 显示全部楼层 |阅读模式
//-----------------------------------------------------------------------------
//----- 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)

 

 

 

 

圆打断曲线
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-5 12:27 , Processed in 0.140201 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表