天气与日历 切换到窄版

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

用AcedGrRead()函数实现一拖多

[复制链接]
  • TA的每日心情
    开心
    7 小时前
  • 签到天数: 20 天

    [LV.4]偶尔看看III

    115

    主题

    11

    回帖

    1393

    积分

    管理员

    积分
    1393
    QQ
    发表于 2024-5-4 18:41:33 | 显示全部楼层 |阅读模式
    1. 实现代码:
    2. #include "StdAfx.h"
    3. #include "StdArx.h"
    4. #include "..\..\Common\我的类\Arc.h"
    5. #include <acedads.h>
    6. #include "..\..\Common\Entity\LineUtil.h"
    7. #include <geassign.h>
    8. #include <dbents.h>
    9. #include "..\..\Common\Others\ConvertUtil.h"
    10. #include <gearc2d.h>
    11. #include <dbcurve.h>
    12. #include "..\..\Common\Interaction\SelectUtil.h"
    13. #include "..\..\Common\Document\DwgDatabaseUtil.h"
    14. void ZffMyProjectdrwarc()
    15. {
    16.   AcDbEntity *pEntRef=NULL;
    17.   AcGePoint3d pickPoint;
    18.   AcDbBlockReference *pBlkRef=NULL;
    19.   AcDbObjectId blkDefId;
    20.   AcDbObjectIdArray blkRefIds;
    21.   int i,n=5;
    22.   int track=1,type;
    23.   ads采用point pnt;
    24.   AcGePoint3d pt;
    25.   if (CSelectUtil::PromptSelectEntity(TEXT("\n选择块:"),AcDbBlockReference::desc(),pEntRef,pickPoint))
    26.   {
    27.     pBlkRef=AcDbBlockReference::cast(pEntRef);
    28.     blkDefId=pBlkRef->blockTableRecord();
    29.     pEntRef->close();
    30.     pBlkRef->close();
    31.   }
    32.   acedGetPoint(NULL,"\n请输入一点:",pnt);
    33.   pt.x=pnt[X];
    34.   pt.y=pnt[Y];
    35.   pt.z=pnt[Z];
    36.   AcGePoint2d pt12d=CConvertUtil::ToPoint2d(asPnt3d(pnt));
    37.   AcGePoint2d pt22d=CConvertUtil::ToPoint2d(pt);
    38.   AcDbObjectId lineId=CLineUtil::Add(asPnt3d(pnt),pt);
    39.   AcGeVector2d vec=pt22d-pt12d;
    40.   for (i=1;i<n+1;i++)
    41.   {
    42.     pBlkRef=new AcDbBlockReference(CConvertUtil::ToPoint3d(pt12d+i*vec/(n+1)),blkDefId);
    43.     blkRefIds.append(CDwgDatabaseUtil::PostToModelSpace(pBlkRef));
    44.   }
    45.   pBlkRef->close();
    46.   AcDbLine *pLine=NULL;
    47.   struct resbuf result;
    48.   while(track>0)
    49.   {
    50.     acedGrRead(track,&type,&result);
    51.     pt.x=result.resval.rpoint[X];
    52.     pt.y=result.resval.rpoint[Y];
    53.     pt.z=result.resval.rpoint[Z];
    54.     pt12d=CConvertUtil::ToPoint2d(asPnt3d(pnt));
    55.     pt22d=CConvertUtil::ToPoint2d(pt);
    56.     acdbOpenObject(pLine,lineId,AcDb::kForWrite);
    57.     pLine->setEndPoint(pt);
    58.     for (i=0;i<blkRefIds.length();i++)
    59.     {
    60.       acdbOpenObject(pBlkRef,blkRefIds[i],AcDb::kForWrite);
    61.       pBlkRef->setPosition(CConvertUtil::ToPoint3d(pt12d+(i+1)*(pt22d-pt12d)/(n+1)));
    62.       pBlkRef->close();
    63.     }
    64.     if (type==3)
    65.     {
    66.       track=0;
    67.     }
    68.     pLine->close();
    69.   }
    70.   AcGePoint2d ptOnArc;
    71.   AcDbObjectId arcId;
    72.   double startParam=0,endParam=0,paramInterval;
    73.   track=1;
    74.   while (track>0)
    75.   {
    76.     acedGrRead(track,&type,&result);
    77.     ptOnArc.x=result.resval.rpoint[X];
    78.     ptOnArc.y=result.resval.rpoint[Y];
    79.     if (ptOnArc.x!=pt.x||ptOnArc.y!=pt.y)
    80.     {
    81.       if (arcId.isNull())
    82.       {
    83.         acdbOpenObject(pLine,lineId,AcDb::kForWrite);
    84.         pLine->erase();
    85.         pLine->close();
    86.         arcId=CArc::Add(pt12d,pt22d,pt22d);
    87.       }
    88.       AcGeCircArc2d geArc(pt12d, ptOnArc, pt22d);
    89.       AcGePoint2d ptCenter = geArc.center();
    90.       double radius = geArc.radius();
    91.       AcGeVector2d vecStart(pt12d.x - ptCenter.x, pt12d.y - ptCenter.y);
    92.       AcGeVector2d vecEnd(pt22d.x - ptCenter.x, pt22d.y - ptCenter.y);
    93.       double startAngle = vecStart.angle();
    94.       double endAngle = vecEnd.angle();
    95.       AcDbArc *pArc2=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter),radius,startAngle,endAngle);
    96.       AcGePoint3d ptclose;
    97.       pArc2->getClosestPointTo(CConvertUtil::ToPoint3d(ptOnArc),ptclose);
    98.       pArc2->close();
    99.       AcDbArc *pArc=NULL;
    100.       acdbOpenObject(pArc,arcId,AcDb::kForWrite);
    101.       if (CConvertUtil::ToPoint2d(ptclose).distanceTo(ptOnArc)<0.01)
    102.       {
    103.         pArc->setCenter(CConvertUtil::ToPoint3d(ptCenter));
    104.         pArc->setRadius(radius);
    105.         pArc->setStartAngle(startAngle);
    106.         pArc->setEndAngle(endAngle);
    107.       }
    108.       else
    109.       {
    110.         pArc->setCenter(CConvertUtil::ToPoint3d(ptCenter));
    111.         pArc->setRadius(radius);
    112.         pArc->setStartAngle(endAngle);
    113.         pArc->setEndAngle(startAngle);
    114.       }
    115.       AcDbCurve *pCurve=AcDbCurve::cast(pArc);
    116.       pCurve->getStartParam(startParam);
    117.       pCurve->getEndParam(endParam);
    118.       paramInterval=(endParam-startParam)/(n+1);
    119.       for (i=1;i<n+1;i++)
    120.       {
    121.         double param=startParam+i*paramInterval;
    122.         pCurve->getPointAtParam(param,pt);
    123.         acdbOpenObject(pBlkRef,blkRefIds[i-1],AcDb::kForWrite);
    124.         pBlkRef->setPosition(pt);
    125.         pBlkRef->close();
    126.       }
    127.       pCurve->close();
    128.       pArc->close();
    129.       if (type==3)
    130.       {
    131.         track=0;
    132.       }
    133.     }
    134.   }
    135. }
    136. AcDbObjectId CArc::Add(const AcGePoint2d &ptStart,const AcGePoint2d &ptOnArc,const AcGePoint2d &ptEnd)
    137. {
    138. AcGePoint3d ptOnArc1;
    139. AcGeCircArc2d geArc(ptStart, ptOnArc, ptEnd);
    140. AcGePoint2d ptCenter = geArc.center();
    141. double radius = geArc.radius();
    142. double tol=0.01;
    143. // 计算起始和终止角度
    144. AcGeVector2d vecStart(ptStart.x - ptCenter.x, ptStart.y - ptCenter.y);
    145. AcGeVector2d vecEnd(ptEnd.x - ptCenter.x, ptEnd.y - ptCenter.y);
    146. double startAngle = vecStart.angle();
    147. double endAngle = vecEnd.angle();
    148. AcDbArc *pArc=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter), radius, startAngle, endAngle);
    149. pArc->getClosestPointTo(CConvertUtil::ToPoint3d(ptOnArc),ptOnArc1);
    150. if (CConvertUtil::ToPoint2d(ptOnArc1).distanceTo(ptOnArc)<tol)
    151. {
    152. return CDwgDatabaseUtil::PostToModelSpace(pArc);
    153. }
    154. else
    155. {
    156. AcDbArc *pArc2=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter),radius,endAngle,startAngle);
    157. delete pArc;
    158. return CDwgDatabaseUtil::PostToModelSpace(pArc2);
    159. }
    160. }
    复制代码

     

     

     

     

    用AcedGrRead()函数实现一拖多
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-11-5 12:26 , Processed in 0.135667 second(s), 24 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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