Files

275 lines
6.9 KiB
C++
Raw Permalink Normal View History

2026-10-04 00:04:20 +08:00
#include "StdAfx.h"
2026-09-28 15:28:50 +08:00
#include "hlr.h"
#include "hlrcommands.h"
#ifdef ZWCAD
#pragma comment(lib, "ZwHlr.lib")
#endif
#ifdef CMAKE
#else
#ifndef ZWCAD
#if ARX ==18
#pragma comment(lib, "AsdkHlrApi18.lib")
#elif ARX == 19
#pragma comment(lib, "AsdkHlrApi19.lib")
#elif ARX == 20
#pragma comment(lib, "AsdkHlrApi20.lib")
#elif ARX == 21
#pragma comment(lib, "AsdkHlrApi21.lib")
#elif ARX == 22
#pragma comment(lib, "AsdkHlrApi22.lib")
#elif ARX == 23
#pragma comment(lib, "AsdkHlrApi23.lib")
#elif ARX == 24
#pragma comment(lib, "AsdkHlrApi24.lib")
#elif ARX == 25
#pragma comment(lib, "AsdkHlrApi25.lib")
#elif ARX == 26
#pragma comment(lib, "AsdkHlrApi26.lib")
#else
#endif
#endif
#endif
2026-10-04 00:04:20 +08:00
// 收集所有实体在某个视口的消隐线
// 实体不包含block
2026-09-28 15:28:50 +08:00
void _progress1(int percent_completed) {
acedSetStatusBarProgressMeterPos(percent_completed);
}
void _progress2(int percent_completed) {
acedSetStatusBarProgressMeterPos(100 + percent_completed);
}
void _progress3(int percent_completed) {
acedSetStatusBarProgressMeterPos(100 + percent_completed);
}
void hlrCalc(AsdkHlrCollector &collector
, AcDbViewport *pVp
, const int &control
2026-10-04 00:04:20 +08:00
, HLR::IDMapEntities &result // 结果,first-原实体 second-生成的消隐实体
, HLR::EntMapEntities &result2 // 结果,如果原实体没有id(在内存中),则保存结果到此
, HLR::EntMapInt &vbs // 每个结果实体的显示类型
, HLR::EntMapInt &hlrvbs) // 每个结果实体的hlr显示类型
2026-09-28 15:28:50 +08:00
{
typedef HLR::IDMapEntities::iterator MPIT;
typedef HLR::EntMapInt::iterator MVIT;
if (!pVp) return;
AsdkHlrEngine hlr(pVp, control);
hlr.setAcisConversionProgressCallBack(_progress1);
2026-10-04 00:04:20 +08:00
//hlr.setAhlProgressCallBack(progress2); // 崩溃,不知为何
2026-09-28 15:28:50 +08:00
hlr.setAcadConversionProgressCallBack(_progress3);
2026-10-04 00:04:20 +08:00
acedSetStatusBarProgressMeter(ACRX_T("正在分析...: "), 0, 200);
2026-09-28 15:28:50 +08:00
hlr.run(collector);
acedRestoreStatusBar();
AcDbObjectId id;
AcDbEntity *pEnt(NULL);
for (int i = 0; i < collector.mOutputData.length(); i++)
{
AsdkHlrData *pResult = collector.mOutputData[i];
if (!pResult->getResultEntity()) continue;
if (!pResult->getEntity() && pResult->getObjectIds().isEmpty()) continue;
2026-10-04 00:04:20 +08:00
// 拷贝出结果
2026-09-28 15:28:50 +08:00
pEnt = (AcDbEntity *)pResult->getResultEntity()->clone();
if (!pEnt) continue;
2026-10-04 00:04:20 +08:00
// 保存遮挡关系
2026-09-28 15:28:50 +08:00
vbs.insert(std::make_pair(pEnt, pResult->getVisibility()));
hlrvbs.insert(std::make_pair(pEnt, pResult->getHlrVisibility()));
if (pResult->getEntity())
id = pResult->getEntity()->id();
else
id = pResult->getObjectIds().first();
2026-10-04 00:04:20 +08:00
// 如果 ID 有效,
2026-09-28 15:28:50 +08:00
if (id.isValid())
{
#if ARX > 23
auto pr = result.insert(std::make_pair(id, HLR::AcDbEntityArray()));
#else
HLR::IDMapEntities::_Pairib pr = result.insert(std::make_pair(id, HLR::AcDbEntityArray()));
#endif
pr.first->second.append(pEnt);
continue;
}
else if (pResult->getEntity())
{
#if ARX > 23
auto pr = result2.insert(std::make_pair(pResult->getEntity(), HLR::AcDbEntityArray()));
#else
HLR::EntMapEntities::_Pairib pr = result2.insert(std::make_pair(pResult->getEntity(), HLR::AcDbEntityArray()));
#endif
pr.first->second.append(pEnt);
continue;
}
}
}
2026-10-04 00:04:20 +08:00
void HLR::hlr_collect_all(AcDbObjectIdArray &arIds // 原始实体
, AcDbEntityArray &arPtrs // 原始实体的指针,如果实体没有ID的情况下,用此参数传入
, const int &control // 控制参数
, AcDbViewport *pVp // 视口
, IDMapEntities &result // 结果,first-原实体 second-生成的消隐实体
, EntMapEntities &resutl2) // 结果,first-原实体 second-生成的消隐实体
2026-09-28 15:28:50 +08:00
{
if (arPtrs.isEmpty() && arIds.isEmpty()) return;
AsdkHlrCollector collector;
if (!arPtrs.isEmpty())
collector.addEntities(arPtrs);
if (!arIds.isEmpty())
collector.addEntities(arIds);
EntMapInt vbs, hlrvbs;
hlrCalc(collector, pVp, control, result, resutl2, vbs, hlrvbs);
}
2026-10-04 00:04:20 +08:00
void HLR::hlr_collect(AcDbObjectIdArray &arIds // 原始实体
, const int &control // 控制参数
, AcDbViewport *pVp // 视口
, IDMapEntities &result) // 结果,first-原实体 second-生成的消隐实体
2026-09-28 15:28:50 +08:00
{
AcDbEntityArray arPtrs;
if (arPtrs.isEmpty() && arIds.isEmpty()) return;
AsdkHlrCollector collector;
if (!arPtrs.isEmpty())
collector.addEntities(arPtrs);
if (!arIds.isEmpty())
collector.addEntities(arIds);
EntMapEntities resutl2;
EntMapInt vbs, hlrvbs;
hlrCalc(collector, pVp, control, result, resutl2, vbs, hlrvbs);
}
void HLR::hlr_lite(AcDbEntityArray &arPtrs
2026-10-04 00:04:20 +08:00
, const int &control // 控制参数
, AcDbViewport *pVp // 视口
2026-09-28 15:28:50 +08:00
, EntMapEntities &result)
{
if (arPtrs.isEmpty()) return;
AsdkHlrCollector collector;
if (!arPtrs.isEmpty())
collector.addEntities(arPtrs);
IDMapEntities result2;
EntMapInt vbs, hlrvbs;
hlrCalc(collector, pVp, control, result2, result, vbs, hlrvbs);
for (IDMapEntities::iterator it(result2.begin())
; it != result2.end()
; ++it)
{
for (int i = 0; i < it->second.length(); ++i)
delete it->second[i];
it->second.removeAll();
}
}
void HLR::hlr_lite_ids(AcDbObjectIdArray &arids
2026-10-04 00:04:20 +08:00
, const int &control // 控制参数
, AcDbViewport *pVp // 视口
2026-09-28 15:28:50 +08:00
, IDMapEntities &result)
{
if (arids.isEmpty()) return;
AsdkHlrCollector collector;
if (!arids.isEmpty())
collector.addEntities(arids);
EntMapEntities result2;
EntMapInt vbs, hlrvbs;
hlrCalc(collector, pVp, control, result, result2, vbs, hlrvbs);
for (EntMapEntities::iterator it(result2.begin())
; it != result2.end()
; ++it)
{
for (int i = 0; i < it->second.length(); ++i)
delete it->second[i];
it->second.removeAll();
}
}
void HLR::OrthoProjected3DSolidImp(AcDbEntity *pSolidClone
, const AcGePlane &plan
, AcGeMatrix3d &xformPlanToWorld
, AcDbVoidPtrArray &arEntPtrs)
{
AsdkHlrCollector collector;
AcDbEntity *pSubEnt = NULL;
if (pSolidClone != NULL)
{
collector.addEntity(pSolidClone);
}
else
{
return;
}
struct resbuf rb;
acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb);
ads_point dirPt;
acdbUcs2Wcs(rb.resval.rpoint, dirPt, Adesk::kTrue);
acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
ads_point tarPt;
acdbUcs2Wcs(rb.resval.rpoint, tarPt, Adesk::kFalse);
AcGeVector3d vtDir;
AcGePoint3d ptOrg;
AcGeVector3d vtu, vtV;
vtDir = plan.normal();
plan.get(ptOrg, vtu, vtV);
AsdkHlrEngine hlr(
ptOrg/*asPnt3d (tarPt)*/, vtDir/*asVec3d (dirPt)*/,
kEntity | kBlock | kSubentity | kProgress
| kHonorInternals
| kShowAll
| kMeshSilhouettes
| 0
);
hlr.run(collector);
AsdkHlrData *p = NULL;
int n = collector.mOutputData.logicalLength();
for (int i = 0; i < n; i++)
{
p = collector.mOutputData[i];
pSubEnt = p->getResultEntity();
AcDbCurve *pSubCrv = AcDbCurve::cast(pSubEnt);
if (pSubCrv != NULL)
{
AcDbCurve *pProjCrv = NULL;
pSubCrv->getOrthoProjectedCurve(plan, pProjCrv);
if (pProjCrv != NULL)
{
pProjCrv->transformBy(xformPlanToWorld);
arEntPtrs.append(pProjCrv);
}
}
}
}