Jig定义的实体做成块
CMultiCircleJigEntity::CMultiCircleJigEntity(const AcGePoint3d & centerPoint, const unsigned int &iNum)
{
AcDbCircle *pCirc;
for (int i = 0; i < iNum; i++)
{
pCirc = new AcDbCircle(centerPoint, AcGeVector3d::kZAxis, 1.0);
m_CircArr.append(pCirc);
}
}
CMultiCircleJigEntity::~CMultiCircleJigEntity()
{
for (int i = 0; i < m_CircArr.length(); i++)
{
delete m_CircArr;
}
}
Adesk::Boolean CMultiCircleJigEntity::worldDraw(AcGiWorldDraw *mode)
{
for (int i = 0; i < m_CircArr.length(); i++)
{
mode ->geometry().draw(m_CircArr);
}
return (AcDbEntity::worldDraw (mode)) ;
}
void CMultiCircleJigEntity::setRadius(double dRadius)
{
if (m_CircArr.length() <= 0)
return;
double dCurRadius = dRadius;
double dRadiusStep = dRadius / m_CircArr.length();
for (int i = 0; i < m_CircArr.length(); i++)
{
m_CircArr ->setRadius(dCurRadius);
dCurRadius -= dRadiusStep;
}
}
void CMultiCircleJigEntity::appendToCurrentSpace()
{
AcDbDatabase * pDb = acdbCurDwg();
AcDbBlockTable *pBlockTable;
pDb ->getBlockTable(pBlockTable, AcDb::kForWrite);
AcDbBlockTableRecord *pBlkRec;
pBlkRec = new AcDbBlockTableRecord();
CString blkName = _T("ss");
pBlkRec->setName(blkName);
AcDbObjectId blkDefId;
pBlockTable->add(blkDefId, pBlkRec);
////////////////////////////////////////////////////////////////////////////
if (pDb ->tilemode())
{
pBlockTable ->getAt(ACDB_MODEL_SPACE, pBlkRec, AcDb::kForWrite);
}
else
{
pBlockTable ->getAt(ACDB_PAPER_SPACE, pBlkRec, AcDb::kForWrite);
}
pBlockTable ->close();
for (int i = 0; i < m_CircArr.length(); i++)
{
AcDbCircle *& pCirc = m_CircArr.at(i);
AcDbObjectId entId;
if (Acad::eOk == pBlkRec ->appendAcDbEntity(entId,pCirc))
{
pCirc ->setDatabaseDefaults();
pCirc ->close();
}
else
{
delete pCirc;
}
}
pBlkRec ->close();
m_CircArr.removeAll();
}帮忙指点下,为什么不能生成块?
本帖最后由 星辰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.
多谢,已解决
页:
[1]