487 lines
12 KiB
C++
487 lines
12 KiB
C++
#include "stdafx.h"
|
|
#include "HlrCutOption.h"
|
|
#include "AecDbEntityBase.h"
|
|
#include "AecDbCurveBase.h"
|
|
#include "EarThwormDef.h"
|
|
#include "coretools.h"
|
|
#include "acgiviewdraw.h"
|
|
#include "aecdbwall.h"
|
|
#include "aecdbbeam.h"
|
|
#include "aecdbslab.h"
|
|
#include "aecdbcolumn.h"
|
|
|
|
#define HLR_CUT_OPTION_XDATA _T("HLR_CUT_OPTION_XDATA")
|
|
|
|
#define IMPL_VALUE_FUNC(func, name, type)\
|
|
BOOL HlrCutOption::getHlr##func##_##name(type &dW)\
|
|
{\
|
|
AecDbObjXDataMap xdata;\
|
|
if (KTModelLayoutXData::ReadModelXData(HLR_CUT_OPTION_XDATA, xdata))\
|
|
return xdata.GetAt(CString(_T("_")) + _T(#func) + _T("_") + _T(#name), dW);\
|
|
return false;\
|
|
}\
|
|
\
|
|
void HlrCutOption::setHlr##func##_##name(const type &dW)\
|
|
{\
|
|
AecDbObjXDataMap xdata;\
|
|
if (KTModelLayoutXData::ReadModelXData(HLR_CUT_OPTION_XDATA, xdata))\
|
|
{\
|
|
xdata.SetAt(CString(_T("_")) + _T(#func) + _T("_") + _T(#name), dW);\
|
|
KTModelLayoutXData::WriteModelXData(HLR_CUT_OPTION_XDATA, xdata);\
|
|
}\
|
|
}\
|
|
\
|
|
void HlrCutOption::removeHlr##func##_##name()\
|
|
{\
|
|
AecDbObjXDataMap xdata;\
|
|
if (KTModelLayoutXData::ReadModelXData(HLR_CUT_OPTION_XDATA, xdata))\
|
|
{\
|
|
xdata.RemoveAt(CString(_T("_")) + _T(#func) + _T("_") + _T(#name));\
|
|
KTModelLayoutXData::WriteModelXData(HLR_CUT_OPTION_XDATA, xdata);\
|
|
}\
|
|
}
|
|
|
|
#define IMPL_CHECK_FUNC(func, name)\
|
|
BOOL HlrCutOption::getHlr##func##_##name()\
|
|
{\
|
|
BOOL bRel(FALSE);\
|
|
AecDbObjXDataMap xdata;\
|
|
if (KTModelLayoutXData::ReadModelXData(HLR_CUT_OPTION_XDATA, xdata))\
|
|
xdata.GetAt(CString(_T("_")) + _T(#func) + _T("_") + _T(#name), bRel);\
|
|
return bRel;\
|
|
}\
|
|
\
|
|
void HlrCutOption::setHlr##func##_##name(const BOOL &v)\
|
|
{\
|
|
AecDbObjXDataMap xdata;\
|
|
if (KTModelLayoutXData::ReadModelXData(HLR_CUT_OPTION_XDATA, xdata))\
|
|
{\
|
|
xdata.SetAt(CString(_T("_")) + _T(#func) + _T("_") + _T(#name), v);\
|
|
KTModelLayoutXData::WriteModelXData(HLR_CUT_OPTION_XDATA, xdata);\
|
|
}\
|
|
}\
|
|
|
|
IMPL_VALUE_FUNC(LW, Wall, double)
|
|
IMPL_VALUE_FUNC(LW, Beam, double)
|
|
IMPL_VALUE_FUNC(LW, Slab, double)
|
|
IMPL_VALUE_FUNC(LW, Column, double)
|
|
IMPL_VALUE_FUNC(LW, PipeSys, double)
|
|
IMPL_VALUE_FUNC(LW, HvacSys, double)
|
|
IMPL_VALUE_FUNC(LW, ElecSys, double)
|
|
IMPL_VALUE_FUNC(LW, EnvCut, double)
|
|
|
|
IMPL_CHECK_FUNC(BLK, OPEN)
|
|
IMPL_CHECK_FUNC(BLK, FITTING)
|
|
IMPL_CHECK_FUNC(BLK, EQU)
|
|
IMPL_CHECK_FUNC(BLK, PARAEQU)
|
|
IMPL_CHECK_FUNC(BLK, YGDT)
|
|
IMPL_CHECK_FUNC(BLK, STAIR)
|
|
|
|
IMPL_CHECK_FUNC(STYLE2D, VALVE)
|
|
IMPL_CHECK_FUNC(STYLE2D, OPEN)
|
|
IMPL_CHECK_FUNC(STYLE2D, HOLE)
|
|
|
|
IMPL_CHECK_FUNC(MERGE, Wall)
|
|
IMPL_CHECK_FUNC(MERGE, Beam)
|
|
IMPL_CHECK_FUNC(MERGE, Slab)
|
|
IMPL_CHECK_FUNC(MERGE, Column)
|
|
|
|
IMPL_CHECK_FUNC(ZX, SameDir)
|
|
IMPL_CHECK_FUNC(ZX, Parallel)
|
|
|
|
IMPL_VALUE_FUNC(LW, Envelope, double)
|
|
IMPL_VALUE_FUNC(LY, Envelope, AcDbObjectId)
|
|
IMPL_VALUE_FUNC(LT, Envelope, AcDbObjectId)
|
|
IMPL_VALUE_FUNC(CL, Envelope, int)
|
|
|
|
#define SET_AT_BLK(func, name, v) xData.SetAt(CString(_T("_")) + _T(#func) + _T("_") + _T(#name), v)
|
|
|
|
int HlrCutOption::init()
|
|
{
|
|
AecDbObjXDataMap xData;
|
|
SET_AT_BLK(BLK, OPEN, TRUE);
|
|
SET_AT_BLK(BLK, FITTING, TRUE);
|
|
SET_AT_BLK(BLK, EQU, TRUE);
|
|
SET_AT_BLK(BLK, YGDT, TRUE);
|
|
SET_AT_BLK(BLK, STAIR, TRUE);
|
|
SET_AT_BLK(BLK, PARAEQU, TRUE);
|
|
SET_AT_BLK(STYLE2D, VALVE, TRUE);
|
|
SET_AT_BLK(STYLE2D, OPEN, TRUE);
|
|
SET_AT_BLK(STYLE2D, HOLE, TRUE);
|
|
|
|
SET_AT_BLK(MERGE, Wall, TRUE);
|
|
SET_AT_BLK(MERGE, Beam, TRUE);
|
|
SET_AT_BLK(MERGE, Slab, TRUE);
|
|
SET_AT_BLK(MERGE, Column, FALSE);
|
|
|
|
SET_AT_BLK(ZX, SameDir, FALSE);
|
|
SET_AT_BLK(ZX, Parallel, FALSE);
|
|
|
|
if (!KTModelLayoutXData::ReadModelXData(HLR_CUT_OPTION_XDATA, xData))
|
|
KTModelLayoutXData::WriteModelXData(HLR_CUT_OPTION_XDATA, xData);
|
|
|
|
return 1;
|
|
}
|
|
|
|
bool HlrCutOption::getHlrMERGE_Envelope()
|
|
{
|
|
int count(0);
|
|
|
|
if (getHlrMERGE_Wall())
|
|
++count;
|
|
if (getHlrMERGE_Beam())
|
|
++count;
|
|
if (getHlrMERGE_Slab())
|
|
++count;
|
|
if (getHlrMERGE_Column())
|
|
++count;
|
|
|
|
return count >= 2;
|
|
}
|
|
|
|
resbuf* HlrCutOption::getEnvelopeFilter()
|
|
{
|
|
if (!getHlrMERGE_Envelope()) return NULL;
|
|
|
|
resbuf *pStart = acutBuildList(-4, _T("<or"), 0);
|
|
|
|
resbuf *pLast(pStart);
|
|
while (pLast->rbnext)
|
|
pLast = pLast->rbnext;
|
|
|
|
if (getHlrMERGE_Wall())
|
|
{
|
|
resbuf *pWall = acutBuildList(-4, _T("<and"), RTDXF0, _T("AEC_DBWALL"), -4, _T("and>"), 0);
|
|
pLast->rbnext = pWall;
|
|
while (pLast->rbnext)
|
|
pLast = pLast->rbnext;
|
|
}
|
|
|
|
if (getHlrMERGE_Beam())
|
|
{
|
|
resbuf *pBeam = acutBuildList(-4, _T("<and"), RTDXF0, _T("AEC_DBBEAM"), -4, _T("and>"), 0);
|
|
pLast->rbnext = pBeam;
|
|
while (pLast->rbnext)
|
|
pLast = pLast->rbnext;
|
|
}
|
|
|
|
if (getHlrMERGE_Slab())
|
|
{
|
|
resbuf *pSlab = acutBuildList(-4, _T("<and"), RTDXF0, _T("AEC_DBSLAB"), -4, _T("and>"), 0);
|
|
pLast->rbnext = pSlab;
|
|
while (pLast->rbnext)
|
|
pLast = pLast->rbnext;
|
|
}
|
|
|
|
if (getHlrMERGE_Column())
|
|
{
|
|
resbuf *pColumn = acutBuildList(-4, _T("<and"), RTDXF0, _T("AEC_DBCOLMN"), -4, _T("and>"), 0);
|
|
pLast->rbnext = pColumn;
|
|
while (pLast->rbnext)
|
|
pLast = pLast->rbnext;
|
|
}
|
|
|
|
pLast->rbnext = acutBuildList(-4, _T("or>"), 0);
|
|
|
|
return pStart;
|
|
}
|
|
|
|
bool HlrCutOption::isEnvelopeEntity(LPCTSTR dxf)
|
|
{
|
|
if (!dxf) return false;
|
|
if (!getHlrMERGE_Envelope())
|
|
return false;
|
|
|
|
if (getHlrMERGE_Wall() && CString(dxf) == _T("AEC_DBWALL"))
|
|
return true;
|
|
|
|
if (getHlrMERGE_Beam() && CString(dxf) == _T("AEC_DBBEAM"))
|
|
return true;
|
|
|
|
if (getHlrMERGE_Slab() && CString(dxf) == _T("AEC_DBSLAB"))
|
|
return true;
|
|
|
|
if (getHlrMERGE_Column() && CString(dxf) == _T("AEC_DBCOLMN"))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
DLLIMPEXP bool MakeBlockRefSet(AcDbVoidPtrArray &arEntPtrs, const AcDbObjectId &idLay,Adesk::Boolean bDoSubent, LPCTSTR pszName, AcDbDatabase *pDb = NULL);
|
|
void HlrCutOption::ProcessHlrResult(const AcDbEntity *pE
|
|
, const BOOL &bBlod
|
|
, const double &dW
|
|
, const BOOL &bBlock
|
|
, const AcArray<AcDbEntity *> &ar
|
|
, const std::map<AcDbEntity *, AcArray<AcDbEntity *>> &preAr
|
|
, AcArray<AcDbEntity *> &output
|
|
, const AecDbObjXDataMap *_pXData)
|
|
{
|
|
int clr(pE->colorIndex());
|
|
AcDbObjectId idLy(pE->layerId()), idLt(pE->linetypeId());
|
|
|
|
const AecDbEntityBase *pEntBase(AecDbEntityBase::cast(pE));
|
|
const AecDbCurveBase *pCrvBase(AecDbCurveBase::cast(pE));
|
|
|
|
const AecDbObjXDataMap *pXData(_pXData);
|
|
if (!pXData)
|
|
{
|
|
if (pEntBase)
|
|
pXData = pEntBase->GetSpecialtyData();
|
|
else if (pCrvBase)
|
|
pXData = pCrvBase->GetSpecialtyData();
|
|
}
|
|
|
|
AecDbObjXDataMap testData;
|
|
testData.CopyFrom(pXData);
|
|
|
|
// 遍历,删掉二进制类型,如果有的话
|
|
std::vector<CString> strs;
|
|
for (AecDbObjXDataMap::It it = testData.Begin(); it != testData.End(); ++it)
|
|
{
|
|
if (it->second.nVt == (VT_BYREF | VT_R8 + 5))
|
|
strs.push_back(it->first);
|
|
}
|
|
for (size_t i(0); i < strs.size(); ++i)
|
|
testData.RemoveAt(strs[i]);
|
|
|
|
AcArray<AcDbEntity *> arpts(ar);
|
|
std::map<AcDbEntity *, AcArray<AcDbEntity *>>::const_iterator it(preAr.begin());
|
|
for (; it != preAr.end(); ++it)
|
|
arpts.append(it->second);
|
|
|
|
for (int i(0); i < arpts.length(); ++i)
|
|
{
|
|
// 不是 AcDbCurve 无法加粗
|
|
if (!AcDbCurve::cast(arpts[i])) continue;
|
|
|
|
AcDbEntity *pEnt((AcDbEntity *)arpts[i]->clone()), *p(NULL);
|
|
if (!pEnt) continue;
|
|
|
|
|
|
if (bBlod)
|
|
{
|
|
AcDbPolyline *pL(CoreTools::MakePolyline((AcDbCurve *)pEnt));
|
|
if (pL)
|
|
{
|
|
p = pL;
|
|
pL->setConstantWidth(dW);
|
|
DELETE_PTR(pEnt);
|
|
}
|
|
else
|
|
{
|
|
p = pEnt;
|
|
}
|
|
}
|
|
else
|
|
p = pEnt;
|
|
|
|
//if (pXData)
|
|
// pXData->Write(p, BIMDATA_APP);
|
|
testData.Write(p, BIMDATA_APP);
|
|
|
|
p->setColorIndex(clr);
|
|
p->setLayer(idLy);
|
|
p->setLinetype(idLt);
|
|
|
|
output.append(p);
|
|
}
|
|
|
|
if (bBlock)
|
|
{
|
|
AcDbEntity *pBlk = makeBlock(pE, output);
|
|
if (pBlk)
|
|
{
|
|
deleteContainerOfArx<AcDbEntity>(output);
|
|
output.append(pBlk);
|
|
}
|
|
}
|
|
}
|
|
|
|
AcDbEntity *HlrCutOption::makeBlock(const AcDbEntity *pEnt
|
|
, const AcArray<AcDbEntity*> &output
|
|
, const AecDbObjXDataMap *_pXData)
|
|
{
|
|
const AecDbEntityBase *pEntBase(AecDbEntityBase::cast(pEnt));
|
|
const AecDbCurveBase *pCrvBase(AecDbCurveBase::cast(pEnt));
|
|
|
|
const AecDbObjXDataMap *pXData(_pXData);
|
|
if (!pXData)
|
|
{
|
|
if (pEntBase)
|
|
pXData = pEntBase->GetSpecialtyData();
|
|
else if (pCrvBase)
|
|
pXData = pCrvBase->GetSpecialtyData();
|
|
}
|
|
|
|
AcDbVoidPtrArray blkPtrs;
|
|
for (int i(0); i < output.length(); ++i)
|
|
blkPtrs.append((AcDbEntity*)output[i]->clone());
|
|
|
|
CString sName(pEnt->isA()->dxfName());
|
|
if (pXData)
|
|
pXData->GetAt(KEY_NAME, sName);
|
|
|
|
MakeBlockRefSet(blkPtrs, pEnt->layerId(), Adesk::kFalse, sName);
|
|
if (!blkPtrs.isEmpty())
|
|
{
|
|
AcDbEntity *pBlk((AcDbEntity *)blkPtrs.first());
|
|
if (pXData)
|
|
pXData->Write(pBlk, BIMDATA_APP);
|
|
return pBlk;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
bool HlrCutOption::isWithinHorizSection(const AcDbEntity *pEnt
|
|
, const AcGePoint3d &ptPlnO
|
|
, const AcGeVector3d &vtPlnN)
|
|
{
|
|
AcDbExtents ext;
|
|
pEnt->getGeomExtents(ext);
|
|
return isWithinHorizSection(ext.maxPoint().z, ext.minPoint().z, ptPlnO, vtPlnN);
|
|
}
|
|
|
|
bool HlrCutOption::isWithinHorizSection(const double &dMax
|
|
, const double &dMin
|
|
, const AcGePoint3d &ptPlnO
|
|
, const AcGeVector3d &vtPlnN)
|
|
{
|
|
if (vtPlnN.isParallelTo(AcGeVector3d::kZAxis))
|
|
{
|
|
AcGePoint3d ptEye(ptPlnO);
|
|
AcGePoint3d ptDeep(ptEye + vtPlnN);
|
|
|
|
double dEyeTop(ptEye.z), dEyeBot(ptDeep.z);
|
|
double dEntMax(dMax), dEntMin(dMin);
|
|
|
|
if (dEyeBot > dEntMax) return false;
|
|
if (dEyeTop < dEntMin) return false;
|
|
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
void setFlag(const AcDbEntity *pEnt, LPCTSTR pszFlag, const int &flag)
|
|
{
|
|
const AecDbCurveBase *pBaseCrv(AecDbCurveBase::cast(pEnt));
|
|
const AecDbEntityBase *pBaseEnt(AecDbEntityBase::cast(pEnt));
|
|
|
|
if (pBaseCrv)
|
|
const_cast<AecDbCurveBase *>(pBaseCrv)->SetAt(pszFlag, flag);
|
|
else if (pBaseEnt)
|
|
const_cast<AecDbEntityBase *>(pBaseEnt)->SetAt(pszFlag, flag);
|
|
}
|
|
|
|
int getFlag(const AcDbEntity *pEnt, LPCTSTR pszFlag)
|
|
{
|
|
AecDbCurveBase *pBaseCrv(AecDbCurveBase::cast(pEnt));
|
|
AecDbEntityBase *pBaseEnt(AecDbEntityBase::cast(pEnt));
|
|
|
|
int bRel(FALSE);
|
|
|
|
if (pBaseCrv)
|
|
pBaseCrv->GetAt(pszFlag, bRel);
|
|
else if (pBaseEnt)
|
|
pBaseEnt->GetAt(pszFlag, bRel);
|
|
|
|
return bRel;
|
|
}
|
|
|
|
const AcDbVoidPtrArray* get3DBuffer(const AcDbEntity *pEnt)
|
|
{
|
|
const AcDbVoidPtrArray *pAr(NULL);
|
|
|
|
pAr = HlrCutOption::get3dBuffer<AecDbXWall>(pEnt);
|
|
if (pAr)
|
|
return pAr;
|
|
|
|
pAr = HlrCutOption::get3dBuffer<AecDbBeam>(pEnt);
|
|
if (pAr)
|
|
return pAr;
|
|
|
|
pAr = HlrCutOption::get3dBuffer<AecDbXSlab>(pEnt);
|
|
if (pAr)
|
|
return pAr;
|
|
|
|
pAr = HlrCutOption::get3dBuffer<AecDbColumn>(pEnt);
|
|
if (pAr)
|
|
return pAr;
|
|
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
BOOL HlrCutOption::isHlrCalc(const AcDbEntity *pEnt)
|
|
{
|
|
return getFlag(pEnt, HLR_CALC);
|
|
}
|
|
|
|
void HlrCutOption::setHlrCalc(const AcDbEntity *pEnt, const BOOL &bValue)
|
|
{
|
|
setFlag(pEnt, HLR_CALC, bValue);
|
|
}
|
|
|
|
bool HlrCutOption::isIntersectWithSection(const AcDbEntity *pEnt)
|
|
{
|
|
return getFlag(pEnt, _T("HLR_PLAN_ENVE_INSTERSECT")) == FALSE ? false : true;
|
|
}
|
|
|
|
void HlrCutOption::setIntersectWithSection(const AcDbEntity *pEnt, const AcGePlane &plnSection)
|
|
{
|
|
const AcDbVoidPtrArray *pAr(get3DBuffer(pEnt));
|
|
if (!pAr) return;
|
|
|
|
setFlag(pEnt, _T("HLR_PLAN_ENVE_INSTERSECT"), FALSE);
|
|
for (int i(0); i < pAr->length(); ++i)
|
|
{
|
|
const AcDb3dSolid *pSolid(AcDb3dSolid::cast((AcDbEntity*)pAr->at(i)));
|
|
if (!pSolid) continue;
|
|
|
|
AcDbRegion *pReg(NULL);
|
|
if (pSolid->getSection(plnSection, pReg) == Acad::eOk && pReg)
|
|
{
|
|
DELETE_PTR(pReg);
|
|
setFlag(pEnt, _T("HLR_PLAN_ENVE_INSTERSECT"), TRUE);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
BOOL HlrCutOption::getEnvCutLW(const AcDbEntity *pEnt, double &dW)
|
|
{
|
|
double dW1, dW2;
|
|
|
|
BOOL bWallBlod(FALSE);
|
|
if (CEntityProperty::isThisClass<AecDbXWall>(pEnt))
|
|
bWallBlod = HlrCutOption::getHlrLW_Wall(dW1);
|
|
else if (CEntityProperty::isThisClass<AecDbXSlab>(pEnt))
|
|
bWallBlod = HlrCutOption::getHlrLW_Slab(dW1);
|
|
else if (CEntityProperty::isThisClass<AecDbColumn>(pEnt))
|
|
bWallBlod = HlrCutOption::getHlrLW_Column(dW1);
|
|
else if (CEntityProperty::isThisClass<AecDbBeam>(pEnt))
|
|
bWallBlod = HlrCutOption::getHlrLW_Beam(dW1);
|
|
|
|
BOOL bCutBlod(HlrCutOption::isIntersectWithSection(pEnt)
|
|
&& HlrCutOption::getHlrLW_EnvCut(dW2));
|
|
|
|
// 剖切面相切加粗优先级最高
|
|
BOOL bBold(FALSE);
|
|
dW = .0;
|
|
if (bCutBlod)
|
|
{
|
|
bBold = TRUE;
|
|
dW = dW2;
|
|
}
|
|
else if (bWallBlod)
|
|
{
|
|
bBold = TRUE;
|
|
dW = dW1;
|
|
}
|
|
return bBold;
|
|
}
|