|
众所周知自定义实体需要重写一些函数,其中关于自定义实体数据存储的两个:
将自定义实体对象写入到DWG文件时调用的函数。
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
从DWG文件中读取自定义实体对象时需要访问的函数。
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
如果自定义实体对象还要保存或读取DXF文件,则还需要重写:
virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler* pFiler);
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* pFiler) const;
创建三角形的自定义实体的数据存储的实现如下:
实现dwgOut函数,向导生成了一些代码,我们要做的仅仅是把成员变量写入到外部:
Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const
{
assertReadEnabled () ;
//—– Save parent class information first.
Acad::ErrorStatus es =AcDbEntity::dwgOutFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//—– Object version number needs to be saved first
if ( (es =pFiler->writeUInt32 (kCurrentVersionNumber)) != Acad::eOk )
return (es) ;
//—– Output params
for (int i = 0; i < 3; i++)
{
pFiler->writeItem(m_verts[i]);
}
return (pFiler->filerStatus ()) ;
1
}
实现dwgIn函数,我们要做的仅仅是从外部读取成员变量的值:
Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) {
assertWriteEnabled () ;
//—– Read parent class information first.
Acad::ErrorStatus es =AcDbEntity::dwgInFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//—– Object version number needs to be read first
Adesk::UInt32 version =0 ;
if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )
return (es) ;
if ( version > kCurrentVersionNumber )
return (Acad::eMakeMeProxy) ;
//- Uncomment the 2 following lines if your current object implementation cannot
//- support previous version of that object.
//if ( version < kCurrentVersionNumber )
// return (Acad::eMakeMeProxy) ;
//—– Read params
for (int i = 0; i < 3; i++)
{
pFiler->readItem(&m_verts[i]);
}
return (pFiler->filerStatus ()) ;
}
[code]原文链接:https://blog.csdn.net/csdn_wuwt/article/details/81945988[/code] |
|