Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

286 lines
6.3 KiB
C++

#include "stdafx.h"
#include "HVACFittingToolkit.h"
#include "AecDbHvacFitting.h"
#include "AecDbHvacDuct.h"
// 表示数据库中弯头信息字段
#define ELBOW_STARTWIDTH _T("WidthA")
#define ELBOW_ENDWIDTH _T("WidthB")
#define ELBOW_DIAMETER _T("Dia")
#define ELBOW_SEGMENT _T("Segm")
#define ELBOW_RADRATIO _T("CR")
#define ELBOW_THICK _T("ThickA")
#define ELBOW_ENDTHICK _T("ThickB")
#define ELBOW_ANGEL _T("Angel")
CHVACFittingToolkit::CHVACFittingToolkit(void)
{
}
CHVACFittingToolkit::~CHVACFittingToolkit(void)
{
}
//弯头替换
void CHVACFittingToolkit::EblowReplace(CMapFitaram& mapElbow,int nFitCode,int nFitSect,AcDbObjectId& idFit)
{
}
// 变径替换
void CHVACFittingToolkit::ReducerReplace(CMapFitaram& mapFitParam,int nFitCode,int nFitSect,AcDbObjectId& idToEdit)
{
}
#define DXF_PIPE_ONLY _T("AEC_DBDUCT")
static bool GetDuctFitInf(AecInterface& infBra, AecInterface& infFit,AcDbObjectId& idDuct)
{
ads_name ss,ent;
struct resbuf *pRb = acutBuildList(RTDXF0, DXF_PIPE_ONLY, 0);
int nRes = acedSSGet(_T("A"), NULL, NULL, pRb, ss);
if (nRes == RTNORM)
{
Adesk::Int32 nLen;
acedSSLength(ss, &nLen);
AcDbObjectId id;
AcDbEntity *pEnt = NULL;
for (int i = 0;i < nLen;i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(id, ent);
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead))
{
AecDbHvacDuct *pWpipe = AecDbHvacDuct::cast(pEnt);
if (pWpipe != NULL)
{
AcArray<AecInterface> arInf;
pWpipe->GetInterface(arInf);
for (int ii = 0;ii < arInf.length();ii++)
{
//找到 误差 1.e-2
if ( infBra.ptPos.distanceTo(arInf.at(ii).ptPos) < 1.e-2)
{
infFit = arInf.at(ii);
idDuct = id;
acedSSFree(ss);
pEnt->close();
acutRelRb(pRb);
return true;
}
}
}
pEnt->close();
}
}
}
acedSSFree(ss);
acutRelRb(pRb);
return false;
}
static bool GetDuctFitInf(AecInterface &infBra, AecInterface &infFit, AcDbObjectId &idDuct,const AcDbObjectIdArray& arDuctIDs)
{
Adesk::Int32 nLen = arDuctIDs.length();
AcDbObjectId id;
AcDbEntity *pEnt = NULL;
for (int i = 0; i < nLen; i++)
{
id = arDuctIDs.at(i);
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead))
{
AecDbHvacDuct *pWpipe = AecDbHvacDuct::cast(pEnt);
if (pWpipe != NULL)
{
AcArray<AecInterface> arInf;
pWpipe->GetInterface(arInf);
for (int ii = 0; ii < arInf.length(); ii++)
{
//找到 误差 1.e-2
if (infBra.ptPos.distanceTo(arInf.at(ii).ptPos) < 1.e-2)
{
infFit = arInf.at(ii);
idDuct = id;
pEnt->close();
return true;
}
}
}
pEnt->close();
}
}
return false;
}
//三通替换
void CHVACFittingToolkit::TeeReplace(CMapFitaram& mapFitParam,int nFitCode,int nFitSect,AcDbObjectId& idToEdit)
{
}
static void MoveDuctInfPosTo(AcDbObjectId& idDuct, AecInterface& infFit, AcGePoint3d& ptNewPos)
{
AcDbEntity *pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, idDuct, AcDb::kForWrite))
{
AecDbHvacDuct *pWpipe = AecDbHvacDuct::cast(pEnt);
if (pWpipe != NULL)
{
AcGePoint3d ptS = pWpipe->StartPoint();
if (ptS.distanceTo(infFit.ptPos) < 1.e-2)
{
pWpipe->SetStartPoint(ptNewPos);
pEnt->close();
return;
}
AcGePoint3d ptE = pWpipe->EndPoint();
if (ptE.distanceTo(infFit.ptPos) < 1.e-2)
{
pWpipe->SetEndPoint(ptNewPos);
pEnt->close();
return;
}
}
pEnt->close();
}
}
//三通接口关联更新
void CHVACFittingToolkit::UpdateTeeInfAssoc(AecDbHvacFitting * pFit, AcArray<AecInterface>& arTInfLast, AcArray<AecInterface>& arTInfThis,AecHvac::HvacTeeType eTeeTypeLast, AecHvac::HvacTeeType eTeeTypeThis,BOOL bFloorDir)
{
if (arTInfLast.length() != 3 && arTInfThis.length() != 3)
{
return;
}
bool bFitNeed = false;
//新的结构方式 承插 或 斜接 , 支管的位置发生变化, 产生联动
if (eTeeTypeThis == AecHvac::eInsertBranch || eTeeTypeThis == AecHvac::eInsertIntubBranch)//承插
{
if (eTeeTypeLast != eTeeTypeThis)//不同
{
bFitNeed = true;
}
}
else if (eTeeTypeThis == AecHvac::eInclineBranch)//斜接
{
//原来的结构方式
if (eTeeTypeLast != eTeeTypeThis)//不同
{
bFitNeed = true;
}
}
//
//原来是 承插 或 斜接 变动为其他. 产生按照支管变动
if (eTeeTypeLast == AecHvac::eInsertBranch || eTeeTypeLast == AecHvac::eInsertIntubBranch)//承插
{
if (eTeeTypeLast != eTeeTypeThis)//不同
{
bFitNeed = true;
}
}
else if (eTeeTypeLast == AecHvac::eInclineBranch)//斜接
{
//原来的结构方式
if (eTeeTypeLast != eTeeTypeThis)//不同
{
bFitNeed = true;
}
}
if (!bFitNeed)
{
if (bFloorDir)//换向
{
if (eTeeTypeLast == AecHvac::eInclineBranch ||
eTeeTypeLast == AecHvac::eInsertBranch ||
eTeeTypeLast == AecHvac::eInsertIntubBranch)// 承插 斜接
{
//更新
}
else
{
return;
}
}
else
{
return;
}
}
//首先按分支接口调整
AecInterface& infBraL = arTInfLast.at(2);
AecInterface &infBraT = arTInfThis.at(2);
AcGeVector3d vtM = infBraL.ptPos - infBraT.ptPos;
//vtSta 方向上的位移
if (!vtM.isParallelTo(arTInfThis.first().vtDir))
{
AcGeVector3d vtBraV = vtM.orthoProject(arTInfThis.first().vtDir);
vtM = vtM.orthoProject(vtBraV);//和主向平行的位移
}
//按管子的位置 调整Fit.
AcGeMatrix3d xM;
xM.setToTranslation(vtM);
pFit->TransformBy(xM);
//新的接口位置
arTInfThis.removeAll();
pFit->GetInterface(arTInfThis);
AcDbObjectIdArray arDuctIds;
AcDbObjectId id;
ads_name ss, ent;
struct resbuf *pRb = acutBuildList(RTDXF0, DXF_PIPE_ONLY, 0);
int nRes = acedSSGet(_T("A"), NULL, NULL, pRb, ss);
if (nRes == RTNORM)
{
Adesk::Int32 nLen;
acedSSLength(ss, &nLen);
for (int i = 0; i < nLen; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(id, ent);
arDuctIds.append(id);
}
acedSSFree(ss);
}
acutRelRb(pRb);
AcDbObjectId idDuct;
AecInterface infFit;
for (int i = 0;i < arTInfLast.length();i++)
{
AecInterface &infOld = arTInfLast.at(i);
if (GetDuctFitInf(infOld, infFit, idDuct, arDuctIds))
{
MoveDuctInfPosTo(idDuct, infFit, arTInfThis.at(i).ptPos);
}
}
}
//四通替换
void CHVACFittingToolkit::CrossReplace(CMapFitaram& mapFitParam,int nFitCode,int nFitSect,AcDbObjectId& idToEdit)
{
}
//乙子弯
void CHVACFittingToolkit::OffsetReplace(CMapFitaram& mapFitParam,int nFitCode,int nFitSect,AcDbObjectId& idToEdit)
{
}