明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 956|回复: 2

Jig定义的实体做成块

[复制链接]
发表于 2015-10-16 09:16 | 显示全部楼层 |阅读模式

  1. CMultiCircleJigEntity::CMultiCircleJigEntity(const AcGePoint3d & centerPoint, const unsigned int &iNum)
  2. {
  3.   AcDbCircle *pCirc;
  4.   for (int i = 0; i < iNum; i++)
  5.   {
  6.     pCirc = new AcDbCircle(centerPoint, AcGeVector3d::kZAxis, 1.0);
  7.     m_CircArr.append(pCirc);
  8.   }  
  9. }
  10. CMultiCircleJigEntity::~CMultiCircleJigEntity()
  11. {
  12.   for (int i = 0; i < m_CircArr.length(); i++)
  13.   {
  14.     delete m_CircArr[i];
  15.   }
  16. }
  17. Adesk::Boolean CMultiCircleJigEntity::worldDraw(AcGiWorldDraw *mode)
  18. {
  19.   for (int i = 0; i < m_CircArr.length(); i++)
  20.   {
  21.     mode ->geometry().draw(m_CircArr[i]);
  22.   }
  23.   return (AcDbEntity::worldDraw (mode)) ;
  24. }
  25. void CMultiCircleJigEntity::setRadius(double dRadius)
  26. {
  27.   if (m_CircArr.length() <= 0)
  28.     return;
  29.   double dCurRadius = dRadius;
  30.   double dRadiusStep = dRadius / m_CircArr.length();

  31.   for (int i = 0; i < m_CircArr.length(); i++)
  32.   {
  33.     m_CircArr[i] ->setRadius(dCurRadius);
  34.     dCurRadius -= dRadiusStep;
  35.   }
  36. }
  37. void CMultiCircleJigEntity::appendToCurrentSpace()
  38. {
  39.   AcDbDatabase * pDb = acdbCurDwg();
  40.   AcDbBlockTable *pBlockTable;
  41.   pDb ->getBlockTable(pBlockTable, AcDb::kForWrite);
  42.   AcDbBlockTableRecord *pBlkRec;

  43.   pBlkRec = new AcDbBlockTableRecord();

  44.   CString blkName = _T("ss");
  45.   
  46.   pBlkRec->setName(blkName);

  47.   AcDbObjectId blkDefId;
  48.   pBlockTable->add(blkDefId, pBlkRec);
  49.   
  50. ////////////////////////////////////////////////////////////////////////////

  51.   if (pDb ->tilemode())
  52.   {
  53.     pBlockTable ->getAt(ACDB_MODEL_SPACE, pBlkRec, AcDb::kForWrite);
  54.   }
  55.   else
  56.   {
  57.     pBlockTable ->getAt(ACDB_PAPER_SPACE, pBlkRec, AcDb::kForWrite);
  58.   }
  59.   pBlockTable ->close();
  60.   for (int i = 0; i < m_CircArr.length(); i++)
  61.   {
  62.     AcDbCircle *& pCirc = m_CircArr.at(i);
  63.     AcDbObjectId entId;
  64.     if (Acad::eOk == pBlkRec ->appendAcDbEntity(entId,pCirc))
  65.     {
  66.       pCirc ->setDatabaseDefaults();
  67.       pCirc ->close();
  68.     }
  69.     else
  70.     {
  71.       delete pCirc;
  72.     }
  73.   }
  74.   pBlkRec ->close();
  75.   m_CircArr.removeAll();
  76. }
复制代码
帮忙指点下,为什么不能生成块?
发表于 2015-11-9 09:32 | 显示全部楼层
本帖最后由 星辰20130920 于 2015-11-9 09:38 编辑

new出来的AcDbCircle对象都已经加到了块表记录中去了,为何还要在析构中delete掉?
When you create an instance of an AcDbObject object with the intent of appending it to the database, use the AcDbObject::new() function. When an object is first created and has not yet been added to the database, you can delete it. However, once an object has been added to the database, you cannot delete it; AutoCAD manages the deletion of all database-resident objects.


 楼主| 发表于 2015-11-24 11:35 | 显示全部楼层
多谢,已解决
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 02:12 , Processed in 0.161058 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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