|
看到书上关于long transaction(长事务)方面的例子的时候出现了不懂
得地方
说得简单一点是对acapLongTransactionManagerPtr()->checkOut()和checkIn()函数如何用不是很理解
说得复杂点,就是对long transaction的不理解了,请各位老师看看下
面的这个例子吧:
下面的这个简单的例子演示的是如何从另一个数据库检出实体,在当前数据
库中修改它们,然后将它们返回到原来的数据库。
void
refEditApiExample()
{
AcDbObjectId transId;
AcDbDatabase* pDb;
char *fname;
struct resbuf *rb;
//从用户获得dwg文件
rb = acutNewRb(RTSTR);
acedGetFileD("ick a drawing", NULL, "dwg", 0, rb);
fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
strcpy(fname, rb->resval.rstring);
acutRelRb(rb);
//打开dwg文件
pDb = new AcDbDatabase(Adesk::kFalse);
pDb->readDwgFile(fname);
//获得块表和模型空间btr记录
AcDbBlockTable *pBlockTable;
pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pOtherMsBtr;
pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr,
AcDb::kForRead);
pBlockTable->close();
//建立遍历器
AcDbBlockTableRecordIterator *pIter;
pOtherMsBtr->newIterator(pIter);
//建立对象id阵列
AcDbObjectIdArray objIdArray;
//遍历模型空间,查找的定的线,将其对象id加入阵列
for (pIter->start(); !pIter->done(); pIter->step()) {
AcDbEntity *pEntity;
pIter->getEntity(pEntity, AcDb::kForRead);
//只查找AcDbLine对象并将它们加入objIdArray阵列中;
if (pEntity->isKindOf(AcDbLine::desc())) {
objIdArray.append(pEntity->objectId());
}
pEntity->close();
}
delete pIter;
pOtherMsBtr->close();
//下面获得当前数据库和当前数据库的模型空间btr的对象id
AcDbBlockTable *pThisBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pThisBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pThisMsBtr;
pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr,
AcDb::kForWrite);
pThisBlockTable->close();
AcDbObjectId id = pThisMsBtr->objectId();
pThisMsBtr->close();
//创建长事务,从外部数据库检出所有实体
acapLongTransactionManagerPtr()->checkOut(transId,
objIdArray, id);//----这一句编译通过不了----(一)
// 修改这些实体的颜色
int colorIndex;
acedGetInt("\请输入颜色号码: ",&colorIndex);
AcDbObject* pObj;
if (acdbOpenObject(pObj, transId, AcDb::kForRead) ==
Acad::eOk)
{
// 获得事务指针
AcDbLongTransaction* pLongTrans =
AcDbLongTransaction::cast(pObj);
if (pLongTrans != NULL) {
// 得到workset的遍历器-------(二)
//
AcDbLongTransWorkSetIterator* pWorkSetIter =
pLongTrans->newWorkSetIterator();
//遍历workset中的实体并改变其颜色
for (pWorkSetIter->start(); !pWorkSetIter->done();
pWorkSetIter->step()) {
AcDbEntity *pEntity;
acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(),
AcDb::kForWrite);
pEntity->setColorIndex(colorIndex);
pEntity->close();
}
delete pWorkSetIter;
}
pObj->close();
}
//观看颜色的变化
char str[132];//
acedGetString(0, "\nNote the new colors. Press return to \
check the objects back in to the original database", str);
// 返回对象到原数据库
acapLongTransactionManagerPtr()->checkIn(transId);//(三)
// 保存数据库
pDb->saveAs(fname);
// 关闭并删除数据库.
delete pDb;
pDb = NULL;
acad_free(fname);
}
(一)处我查了帮助checkout()函数的定义,看了半天不明白
(二)处workset是个什么东东,遍历它和遍历其它的诸如block之类
有何不同
(三)checkin()是和checkout()相对的吧,编译时这两个地方都显示参数
不对
(四)希望了解longTransaction 的具体意义 |
|