feat: X3dPart 几何块存盘/恢复(env 开关,默认关)+ 中望放开 modeler filer
按"3dbuffer 非空才存、空就不存、读不到就重建"的语义实现第一版: - 块写在 AecDbX3dPartEntity::dwgOutFields **末尾**,读在 dwgInFields 末尾探测 magic 'A3DP'。不写在 AecDbX3dPart 里:part 是嵌在实体流中间的子流 (它后面还有 m_drawable2d),老版本会把块的字节当成后续字段读。 - 读不到 magic / 块不完整 / modeler 恢复失败 → 一律保持 m_bNeedCreate 走重建, 不刷日志、不动 kCurrentVersionNumber(老版本读新图 = 照旧重建)。 - 内存 filer(clone / copyFrom / 剪贴板)不参与,避免拷贝出来的实体夹带用不上的缓存。 - 探测块会让 filer 状态变成 eEndOfFile,所以 dwgInFields 末尾显式 return eOk, 不再 return pFiler->filerStatus()(否则整个实体会被判读取失败)。 - AecDbX3dPart 加两个存盘用访问器:GetDwgCacheSolid()(脏/没建过返回 NULL)、 SetDwgCacheSolid()(接管恢复出来的 solid,顺带丢掉 m_pSolidDraw 让绘制副本重建)。 - cmakelists.txt:AEC_HAS_MODELER_FILER 对中望也放开(ZRX/Z20xx/arxport/inc/dbacis.h 把 acdbModeler* 映射到 zcdbModeler*,ZwDatabase.lib 有这些符号)。 - 开关 AEC_3D_DWG_CACHE:默认关(确认收益前不改存盘结果),=1 打开; AEC_3D_CACHE_TRACE=1 时把每次 read/write 写 %TEMP%\aec_x3d_cache.log。 实测(big1.dwg,R230 Debug): - 开图期探测到 220 个 part 实体,全部 miss(老图,正常回退重建); - 存盘(MOVE+REGEN+QSAVE)后跟踪日志 **0 条 write**,DWG 只多 128 KB: 这 220 个 part 实体在存盘时不是脏的,增量存盘按字节整块拷贝,dwgOutFields 没被调用; - 而 X3dPart::Rebuild 是 1138 次 —— 说明 1248 个 part 里只有 220 个是入库实体, 其余 ~918 个是 AecDbBDPipeBase/AecDbSlab/AecDbWeir/AecDbWell 等绘制期 new 出来的临时 part。 结论(已写进 3d-cache-dwg-verdict.md §8):这一版覆盖面上限 220/1248 ≈ 18%, 而且是"part 自己的流里带缓存"这个方案的天生缺陷;下一步要么挂到**所有者实体** (它们存盘时确实是脏的,写得出去),要么做**图级中央缓存**。等决策后再动。
This commit is contained in:
1 parent
caafe7c2b5
commit
010d91af04
4 files changed
+242
-1
No files matched your search
@@ -12,6 +12,10 @@
|
||||
#include "AcGiExplodeDraw.h"
|
||||
#include "AecDbSlab.h"
|
||||
#include "AecDbXDrawPointer.h"
|
||||
#include "SectionPerfCounter.h"
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
#include "dbacis.h"
|
||||
#endif
|
||||
|
||||
extern CString IDCreate();
|
||||
extern double PixelToWcs(int nPixel);
|
||||
@@ -45,6 +49,183 @@ static const Adesk::UInt16 kColorByLayer = 256;
|
||||
|
||||
Adesk::UInt32 AecDbX3dPartEntity::kCurrentVersionNumber = 2;
|
||||
|
||||
// ===========================================================================
|
||||
// 3D 几何缓存随存盘(modeler filer 通道)
|
||||
//
|
||||
// 为什么挂在 AecDbX3dPartEntity 这一层:
|
||||
// - 3D 几何(AecDbX3dPart::m_pSolid)是布尔运算的结果,重建一次 15 ms 量级;
|
||||
// 而把它当 ASM body 存取只要不到 1 ms(实测见 3d-cache-dwg-verdict.md §7)。
|
||||
// - AecDbX3dPart 是嵌在实体流**中间**的子流(它后面还有 m_drawable2d),
|
||||
// 往里加块会让老版本插件把块的字节当成它后面的字段读(管道那次就这样把 XWall 读崩了)。
|
||||
// 而 AecDbX3dPartEntity 的 dwgOutFields 末尾就是本实体流的结尾,老版本读到自己
|
||||
// 需要的字段就停,尾部多出来的字节会被忽略(AutoCAD 流按对象定长)。
|
||||
// - 不升 kCurrentVersionNumber:老版本读新图 = 读不到块 = 照旧重建。
|
||||
//
|
||||
// 语义:
|
||||
// - 存:part 的几何有效(没被置脏、且建过)才写;没有就写 count=0,等于没存;
|
||||
// - 读:读不到 magic(老图/开关关掉)或任何一步失败 → 静默回退重建。
|
||||
// ===========================================================================
|
||||
namespace
|
||||
{
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
|
||||
// 开关:AEC_3D_DWG_CACHE=0 时既不再写块、也不读块(A/B 对照用)
|
||||
bool IsX3dDwgCacheEnabled()
|
||||
{
|
||||
static int s_nOn = -1;
|
||||
if (s_nOn < 0)
|
||||
{
|
||||
const char* psz = ::getenv("AEC_3D_DWG_CACHE");
|
||||
s_nOn = (psz != NULL && psz[0] != '0') ? 1 : 0; // default off until the win is proven
|
||||
}
|
||||
return s_nOn == 1;
|
||||
}
|
||||
|
||||
// 试点跟踪(AEC_3D_CACHE_TRACE=1):确认存盘/开图时这个块的调用情况
|
||||
void Trace3DCache(const char* pszFmt, ...)
|
||||
{
|
||||
static int s_nOn = -1;
|
||||
if (s_nOn < 0)
|
||||
{
|
||||
const char* psz = ::getenv("AEC_3D_CACHE_TRACE");
|
||||
s_nOn = (psz != NULL && psz[0] != '0') ? 1 : 0;
|
||||
}
|
||||
if (s_nOn != 1) return;
|
||||
|
||||
TCHAR szTmp[MAX_PATH + 1];
|
||||
::memset(szTmp, 0, sizeof(szTmp));
|
||||
if (::GetTempPath(MAX_PATH, szTmp) == 0) return;
|
||||
TCHAR szFile[MAX_PATH + 1];
|
||||
::_stprintf_s(szFile, MAX_PATH, _T("%saec_x3d_cache.log"), szTmp);
|
||||
FILE* fp = NULL;
|
||||
if (_tfopen_s(&fp, szFile, _T("a")) != 0 || fp == NULL) return;
|
||||
va_list args;
|
||||
va_start(args, pszFmt);
|
||||
vfprintf(fp, pszFmt, args);
|
||||
va_end(args);
|
||||
fputc(10, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
const Adesk::UInt32 kX3dMagic = 0x50443341; // 'A3DP'
|
||||
const Adesk::UInt32 kX3dMagicEnd = 0x50443341 ^ 0xFFFFFFFF;
|
||||
const Adesk::UInt16 kX3dBlkVer = 1;
|
||||
|
||||
// 内存 filer(clone / copyFrom / 剪贴板)不参与:它的读取语义与 DWG 流不同,
|
||||
// 写进去也只会让拷贝出来的实体带着一份用不上的缓存
|
||||
bool IsMemoryFiler(AcDbDwgFiler* pFiler)
|
||||
{
|
||||
return (pFiler != NULL) && pFiler->isKindOf(CMFCDbDwgFiler::desc());
|
||||
}
|
||||
|
||||
void WriteX3dGeomBlock(AcDbDwgFiler* pFiler, const AecDbX3dPart* pPart)
|
||||
{
|
||||
if (pFiler == NULL || pPart == NULL)
|
||||
return;
|
||||
if (IsMemoryFiler(pFiler) || !IsX3dDwgCacheEnabled())
|
||||
return;
|
||||
|
||||
AcDb3dSolid* pSolid = pPart->GetDwgCacheSolid();
|
||||
const bool bHasSolid = (pSolid != NULL);
|
||||
Trace3DCache("write hasSolid=%d", bHasSolid ? 1 : 0);
|
||||
|
||||
// 没有几何也写头(count=0):读端才知道"这次真的没缓存",而不是老数据
|
||||
pFiler->writeUInt32(kX3dMagic);
|
||||
pFiler->writeUInt16(kX3dBlkVer);
|
||||
pFiler->writeUInt16(0); // flags 预留
|
||||
pFiler->writeUInt32(bHasSolid ? 1 : 0);
|
||||
|
||||
if (!bHasSolid)
|
||||
{
|
||||
pFiler->writeUInt32(kX3dMagicEnd);
|
||||
return;
|
||||
}
|
||||
|
||||
SectionPerf::Scope perfScope("X3dGeom.write");
|
||||
|
||||
ENTITY* pAsm = (ENTITY*)pSolid->getLockedASMBody();
|
||||
if (pAsm == NULL)
|
||||
{
|
||||
// 拿不到 body:块已经写了一半,补 0 让读端当"没有缓存"
|
||||
pFiler->writeUInt32(0);
|
||||
return;
|
||||
}
|
||||
|
||||
AcDbDatabase* pDb = pSolid->database();
|
||||
if (pDb == NULL)
|
||||
pDb = acdbHostApplicationServices()->workingDatabase();
|
||||
|
||||
// modelerVersion = -1:跟随 filer 的 DWG 版本,不硬编码
|
||||
Acad::ErrorStatus es = acdbModelerSaveEntityToDwgFiler(pFiler, pAsm, pDb, -1);
|
||||
pSolid->unlockASMBody();
|
||||
|
||||
if (es != Acad::eOk)
|
||||
{
|
||||
pFiler->writeUInt32(0); // 同上:让读端回退
|
||||
return;
|
||||
}
|
||||
|
||||
pFiler->writeUInt32(kX3dMagicEnd);
|
||||
}
|
||||
|
||||
// 返回 true = 成功用块里的几何接管了 part
|
||||
bool ReadX3dGeomBlock(AcDbDwgFiler* pFiler, AecDbX3dPart* pPart)
|
||||
{
|
||||
if (pFiler == NULL || pPart == NULL)
|
||||
return false;
|
||||
if (IsMemoryFiler(pFiler))
|
||||
return false;
|
||||
|
||||
// 老图 / 写端关掉:读到的不是 magic,直接回退(不刷日志)
|
||||
Adesk::UInt32 nMagic = 0;
|
||||
if (pFiler->readUInt32(&nMagic) != Acad::eOk || nMagic != kX3dMagic)
|
||||
{
|
||||
SectionPerf::Scope missScope("X3dGeom.miss");
|
||||
Trace3DCache("read nomagic");
|
||||
return false;
|
||||
}
|
||||
|
||||
Adesk::UInt16 nBlkVer = 0;
|
||||
Adesk::UInt16 nFlags = 0;
|
||||
Adesk::UInt32 nCount = 0;
|
||||
if (pFiler->readUInt16(&nBlkVer) != Acad::eOk || nBlkVer != kX3dBlkVer)
|
||||
return false;
|
||||
if (pFiler->readUInt16(&nFlags) != Acad::eOk)
|
||||
return false;
|
||||
if (pFiler->readUInt32(&nCount) != Acad::eOk)
|
||||
return false;
|
||||
|
||||
Trace3DCache("read magic=ok count=%u", (unsigned)nCount);
|
||||
if (nCount == 0 || nCount > 4)
|
||||
return false; // 没缓存 / 数据不可信
|
||||
|
||||
ENTITY* pAsm = NULL;
|
||||
int nModelerVer = -1;
|
||||
if (acdbModelerRestoreEntityFromDwgFiler(pFiler, pAsm, &nModelerVer, kReadStrangerEntityDefault) != Acad::eOk)
|
||||
return false;
|
||||
|
||||
Adesk::UInt32 nEnd = 0;
|
||||
if (pFiler->readUInt32(&nEnd) != Acad::eOk || nEnd != kX3dMagicEnd)
|
||||
return false; // 半成品块:回退重建
|
||||
|
||||
if (pAsm == NULL)
|
||||
return false;
|
||||
|
||||
AcDb3dSolid* pSolid = new AcDb3dSolid();
|
||||
if (pSolid->setASMBody(pAsm) != Acad::eOk)
|
||||
{
|
||||
delete pSolid;
|
||||
return false;
|
||||
}
|
||||
|
||||
pPart->SetDwgCacheSolid(pSolid);
|
||||
|
||||
SectionPerf::Scope hitScope("X3dGeom.read.ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // AEC_HAS_MODELER_FILER
|
||||
}
|
||||
|
||||
ACRX_DXF_DEFINE_MEMBERS (AecDbX3dPartEntity, AecDbEntityBase,
|
||||
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||||
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
|
||||
@@ -1824,8 +2005,17 @@ Acad::ErrorStatus AecDbX3dPartEntity::dwgInFields (AcDbDwgFiler* pFiler)
|
||||
//开图时不建布尔结果:dwgInFields 里已置脏,首次绘制或取几何时由 EnsureCreated 重建
|
||||
|
||||
m_drawable2d.dwgInFields(pFiler, version);
|
||||
if (pFiler->filerStatus() != Acad::eOk)
|
||||
return (pFiler->filerStatus ());
|
||||
|
||||
return (pFiler->filerStatus ());
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
// 末尾探测 3D 几何块;读不到就是老图(或开关关掉),part 保持"待重建"
|
||||
ReadX3dGeomBlock(pFiler, m_pPart);
|
||||
#endif
|
||||
|
||||
// 注意:不能用 return pFiler->filerStatus()。探测块时 readUInt32 在老图上会
|
||||
// 把状态置成 eEndOfFile,那样整个实体都会被判成读取失败。
|
||||
return Acad::eOk;
|
||||
}
|
||||
|
||||
Acad::ErrorStatus AecDbX3dPartEntity::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||||
@@ -1848,6 +2038,11 @@ Acad::ErrorStatus AecDbX3dPartEntity::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||||
m_pPart->dwgOutFields(pFiler);
|
||||
m_drawable2d.dwgOutFields(pFiler, AecDbX3dPartEntity::kCurrentVersionNumber);
|
||||
|
||||
#ifdef AEC_HAS_MODELER_FILER
|
||||
// 3D 几何块:只能在**本实体流末尾**追加(见文件顶部那段说明)
|
||||
WriteX3dGeomBlock(pFiler, m_pPart);
|
||||
#endif
|
||||
|
||||
return (pFiler->filerStatus ());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user