Files
envi-code/SourceCode/Code2026/tg_shs/shs_pipebase/THImpHvacVRVBrPipe.cpp
T
2026-09-28 15:28:50 +08:00

1709 lines
45 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdafx.h"
#include "StdArx.h"
#include "THImpHvacVRVBrPipe.h"
#include "TDbInterfaceRecord.h"
#include "TDbXDataMap.h"
#include "TDbInterfaceMsgWrite.h"
#include "math.h"
#include "dbxutil.h"
#include <dbelipse.h>
using namespace TDb;
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
THImpHvacVRVBrPipe::THImpHvacVRVBrPipe()
{
}
THImpHvacVRVBrPipe::~THImpHvacVRVBrPipe()
{
}
BOOL THImpHvacVRVBrPipe::GetInterfaceSizeData(int nIndex, TInterface& pipeInterface) const
{
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
// 获取各点位置
AcGePoint3d ptStart = arpts[0], ptEnd = arpts[4], ptBran = arpts[6];
// 求各端方向
AcGeVector3d vtStart = GetVtMain(), vtEnd, vtBran;
vtEnd = vtBran = -vtStart;
CString sDesc = _T("冷媒出口");
switch(nIndex)
{
case 0:
{
pipeInterface.SetOutDir(vtStart);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptStart);
sDesc = _T("冷媒进口");
sDesc += GetMediaPipeDn();
pipeInterface.SetDescr(sDesc);
pipeInterface.SetType(4);
return TRUE;
}
case 1:
{
pipeInterface.SetOutDir(vtEnd);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptEnd);
sDesc += GetMediaPipeDn();
pipeInterface.SetDescr(sDesc);
pipeInterface.SetType(4);
return TRUE;
}
case 2:
{
pipeInterface.SetOutDir(vtBran);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptBran);
sDesc += GetMediaPipeDn();
pipeInterface.SetDescr(sDesc);
pipeInterface.SetType(4);
return TRUE;
}
}
return FALSE;
}
BOOL THImpHvacVRVBrPipe::GetInterface(int nIndex,TInterface& pipeInterface) const
{
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
// 获取各点位置
AcGePoint3d ptStart = arpts[0], ptEnd = arpts[4], ptBran = arpts[6];
// 求各端方向
AcGeVector3d vtStart = GetVtMain(), vtEnd, vtBran;
vtEnd = vtBran = -vtStart;
AcDbObjectId id;
switch(nIndex)
{
case 0:
// 如果起始接口和第一个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptStart, vtStart, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 如果起始接口和第二个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT2, id) && MakesureInterfaceValidate(id, ptStart, vtStart, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 如果起始接口和第三个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT3, id) && MakesureInterfaceValidate(id, ptStart, vtStart, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 没有管件连接
pipeInterface.SetOutDir(vtStart);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptStart);
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
case 1:
// 如果末尾接口和第一个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptEnd, vtEnd, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 如果末尾接口和第二个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT2, id) && MakesureInterfaceValidate(id, ptEnd, vtEnd, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 如果末尾接口和第三个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT3, id) && MakesureInterfaceValidate(id, ptEnd, vtEnd, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 没有管件连接
pipeInterface.SetOutDir(vtEnd);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptEnd);
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
case 2:
// 如果支管接口和第一支管连接
if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptBran, vtBran, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 如果支管接口和第二个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT2, id) && MakesureInterfaceValidate(id, ptBran, vtBran, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 如果支管接口和第三个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT3, id) && MakesureInterfaceValidate(id, ptBran, vtBran, pipeInterface))
{
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
// 没有管件连接
pipeInterface.SetOutDir(vtBran);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptBran);
GetInterfaceSizeData(nIndex, pipeInterface);
return TRUE;
}
return FALSE;
}
BOOL THImpHvacVRVBrPipe::GetInterface(const AcGePoint3d& ptCon,TInterface& pipeInterface) const
{
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
// 获取各点位置
AcGePoint3d ptStart = arpts[0], ptEnd = arpts[4], ptBran = arpts[6];
// 求各端方向
AcGeVector3d vtStart = GetVtMain(), vtEnd, vtBran;
vtEnd = vtBran = -vtStart;
// 计算测试点到始末点的距离
double dDist1 = ptCon.distanceTo(ptStart);
double dDist2 = ptCon.distanceTo(ptEnd);
double dDist3 = ptCon.distanceTo(ptBran);
AcDbObjectId id;
// 位于起始点
if (dDist1 < 1e-3)
{
// 如果起始接口和第一个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptStart, vtStart, pipeInterface))
{
GetInterfaceSizeData(0, pipeInterface);
return TRUE;
}
// 如果起始接口和第二个管件连接
if (m_pXDataMap->GetAt(KEY_IDCNT2, id) && MakesureInterfaceValidate(id, ptStart, vtStart, pipeInterface))
{
GetInterfaceSizeData(0, pipeInterface);
return TRUE;
}
// 如果起始接口和第三个管件连接
if (m_pXDataMap->GetAt(KEY_IDCNT3, id) && MakesureInterfaceValidate(id, ptStart, vtStart, pipeInterface))
{
GetInterfaceSizeData(0, pipeInterface);
return TRUE;
}
// 没有管件连接
pipeInterface.SetOutDir(vtStart);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptStart);
GetInterfaceSizeData(0, pipeInterface);
return TRUE;
}
else if (dDist2 < 1e-3) // 位于末尾点
{
// 如果末尾接口和第一个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptEnd, vtEnd, pipeInterface))
{
GetInterfaceSizeData(1, pipeInterface);
return TRUE;
}
// 如果末尾接口和第二个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT2, id) && MakesureInterfaceValidate(id, ptEnd, vtEnd, pipeInterface))
{
GetInterfaceSizeData(1, pipeInterface);
return TRUE;
}
// 如果末尾接口和第三个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT3, id) && MakesureInterfaceValidate(id, ptEnd, vtEnd, pipeInterface))
{
GetInterfaceSizeData(1, pipeInterface);
return TRUE;
}
// 没有管件连接
pipeInterface.SetOutDir(vtEnd);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptEnd);
GetInterfaceSizeData(1, pipeInterface);
return TRUE;
}
else if (dDist3 < 1e-3) // 位于支管点
{
// 如果末尾接口和第一个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptBran, vtBran, pipeInterface))
{
GetInterfaceSizeData(2, pipeInterface);
return TRUE;
}
// 如果末尾接口和第二个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT2, id) && MakesureInterfaceValidate(id, ptBran, vtBran, pipeInterface))
{
GetInterfaceSizeData(2, pipeInterface);
return TRUE;
}
// 如果末尾接口和第三个管连接
if (m_pXDataMap->GetAt(KEY_IDCNT3, id) && MakesureInterfaceValidate(id, ptBran, vtBran, pipeInterface))
{
GetInterfaceSizeData(2, pipeInterface);
return TRUE;
}
// 没有管件连接
pipeInterface.SetOutDir(vtBran);
pipeInterface.SetOwnerId(m_pOwnerEnt->objectId());
pipeInterface.SetPosition(ptBran);
GetInterfaceSizeData(2, pipeInterface);
return TRUE;
}
return FALSE;
}
BOOL THImpHvacVRVBrPipe::HasInterface(const AcGePoint3d& ptCon,const AcGeVector3d& vtDir)
{
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
// 获取各点位置
AcGePoint3d ptStart = arpts[0], ptEnd = arpts[4], ptBran = arpts[6];
// 求各端方向
AcGeVector3d vtStart = GetVtMain(), vtEnd, vtBran;
vtEnd = vtBran = -vtStart;
// 计算测试点到始末点的距离
double dDist1 = ptCon.distanceTo(ptStart);
double dDist2 = ptCon.distanceTo(ptEnd);
double dDist3 = ptCon.distanceTo(ptBran);
// 位于起始点
if (dDist1 < 1e-3)
return (vtDir.isParallelTo(vtStart));
// 位于末尾点
if (dDist2 < 1.e-3)
return (vtDir.isParallelTo(vtEnd));
// 位于支管点
if (dDist3 < 1.e-3)
return (vtDir.isParallelTo(vtBran));
return TRUE;
}
int THImpHvacVRVBrPipe::GetInterfaceCount() const
{
return 3;
}
BOOL THImpHvacVRVBrPipe::SetInterfaceRelation(const AcGePoint3d& ptConnect,const AcDbObjectId& idConnect)
{
if (NULL == m_pXDataMap)
return FALSE;
if ( !idConnect.isValid() )
return FALSE;
// 打开对象
AcDbEntity* pEnt;
if (Acad::eOk != acdbOpenObject(pEnt, idConnect, AcDb::kForRead))
return FALSE;
// 检查对象类型,是否是暖通管件
if (!(pEnt->isKindOf(TDbHvacDuct::desc()) || pEnt->isKindOf(TDbHvacFitting::desc())
|| pEnt->isKindOf(TDbHvacEquipment::desc())))
{
pEnt->close();
return FALSE;
}
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
// 获取各点位置
AcGePoint3d ptStart = arpts[0], ptEnd = arpts[4], ptBran = arpts[6];
// 求各端方向
AcGeVector3d vtStart = GetVtMain(), vtEnd, vtBran;
vtEnd = vtBran = -vtStart;
// 计算测试点到各点的距离
double dDist1 = ptConnect.distanceTo(ptStart);
double dDist2 = ptConnect.distanceTo(ptEnd);
double dDist3 = ptConnect.distanceTo(ptBran);
// 基类指针
TDbInterfacesObj* pInterfaceObj = TDbInterfacesObj::cast(pEnt);
ASSERT(NULL != pInterfaceObj);
// 位于起始点
if (dDist1 < 1e-3 && pInterfaceObj->HasInterface(ptStart, vtStart))
{
m_pXDataMap->SetAt(KEY_IDCNT1, idConnect);
pEnt->close();
return TRUE;
}
// 位于末尾点
if (dDist2 < 1.e-3 && pInterfaceObj->HasInterface(ptEnd, vtEnd))
{
m_pXDataMap->SetAt(KEY_IDCNT2, idConnect);
pEnt->close();
return TRUE;
}
// 位于支管点
if (dDist3 < 1e-3 && pInterfaceObj->HasInterface(ptBran, vtBran))
{
m_pXDataMap->SetAt(KEY_IDCNT3, idConnect);
pEnt->close();
return TRUE;
}
pEnt->close();
return FALSE;
}
BOOL THImpHvacVRVBrPipe::RemoveInterfaceRelation(const AcGePoint3d& ptConnect,const AcDbObjectId& idConnect)
{
if (NULL == m_pXDataMap)
return FALSE;
// 浅层次删除; 命名字典中的关系,需要外面移除关系,只移除内部关系
AcDbObjectId id;
m_pXDataMap->GetAt(KEY_IDCNT1, id);
if (id == idConnect)
{
m_pXDataMap->SetAt(KEY_IDCNT1, AcDbObjectId::kNull);
return TRUE;
}
m_pXDataMap->GetAt(KEY_IDCNT2, id);
if (id == idConnect)
{
m_pXDataMap->SetAt(KEY_IDCNT2, AcDbObjectId::kNull);
return TRUE;
}
m_pXDataMap->GetAt(KEY_IDCNT3, id);
if (id == idConnect)
{
m_pXDataMap->SetAt(KEY_IDCNT2, AcDbObjectId::kNull);
return TRUE;
}
return FALSE;
}
BOOL THImpHvacVRVBrPipe::NotifyInterfaceToModify(const TInterfaceModifyMsg& iModiMsg,TInterfaceModifyMsgs& iModiMsgs)
{
return FALSE;
}
BOOL THImpHvacVRVBrPipe::MakeCurves(TComplexCurve& cplCurve) const
{
//绘制两条out接口线
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return FALSE;
TDb::TCurveElement el;
memset(&el,0,sizeof(TDb::TCurveElement));
el.dWidth = GetEndLineWidth();
el.idSubLay = GetEndLayer();
if (IsSysMode())
{
el.ptGe[0] = arpts[0];
el.ptGe[1] = arpts[2];
el.ptGe[2] = arpts[2];
cplCurve.append(el);
el.ptGe[0] = arpts[0];
el.ptGe[1] = arpts[3];
el.ptGe[2] = arpts[3];
cplCurve.append(el);
el.ptGe[0] = arpts[3];
el.ptGe[1] = arpts[2];
el.ptGe[2] = arpts[2];
cplCurve.append(el);
el.ptGe[0] = arpts[1];
el.ptGe[1] = arpts[4];
el.ptGe[2] = arpts[4];
cplCurve.append(el);
el.ptGe[0] = arpts[5];
el.ptGe[1] = arpts[6];
el.ptGe[2] = arpts[6];
cplCurve.append(el);
}
else
{
el.ptGe[0] = arpts[1];
el.ptGe[1] = arpts[4];
el.ptGe[2] = arpts[4];
cplCurve.append(el);
el.ptGe[0] = arpts[5];
el.ptGe[1] = arpts[6];
el.ptGe[2] = arpts[6];
cplCurve.append(el);
}
return TRUE;
}
AcDbPolyline* THImpHvacVRVBrPipe::MakePolyCurve() const
{
return NULL;
}
BOOL THImpHvacVRVBrPipe::MakePolyCurveFaces(AcDbVoidPtrArray& arFaces)
{
return FALSE;
}
void THImpHvacVRVBrPipe::GetKindName(CString& sName)
{
sName = _T("ATS_DBHEQUIPMENT");
}
//////////////////////////////////////////////////////////////////////////
// 2
// ╱│
// ╱ │1 4
// 7 0╱ │______
// ╲ 8 │
// ╲ │______
// ╲│5 6
// 3
//得到分歧管的各个端点7是命令夹点
//点8 用于三维绘制
//
BOOL THImpHvacVRVBrPipe::GetPts(AcGePoint3dArray& arpts) const
{
AcGePoint3d pt;
int nType(0);
int nIsConverse(0);
AcGeVector3d vtMain(AcGeVector3d::kXAxis), vtMainv(AcGeVector3d::kYAxis), vtNor(AcGeVector3d::kZAxis);
double dLength(300.0), dH(200.0), dBrLen(100);
m_pXDataMap->GetAt(HVRV_CenterPoint, pt);
m_pXDataMap->GetAt(HVRV_MainDir, vtMain);
m_pXDataMap->GetAt(HVRV_Length, dLength);
m_pXDataMap->GetAt(HVRV_Width, dBrLen);
m_pXDataMap->GetAt(HVRV_IsConverse, nIsConverse);
vtNor = GetNormal();
vtMainv = vtMain;
if (nIsConverse)
{
vtMainv = -vtMain;
}
vtMainv.rotateBy(PI * 0.5, vtNor);
vtMain.normalize();
vtMainv.normalize();
//等边三角形的高
dH = dLength * sqrt(3.0) * 0.5;
m_pXDataMap->GetAt(KEY_SectType, nType);
if (nType == 1)
{
pt += vtMain * (dH + dBrLen);
}
else if (nType == 2)
{
pt += vtMain * (dH + dBrLen);
pt += vtMainv * dLength * 0.25;
}
if (IsSysMode())
{
CString sAngle = _T("");
m_pXDataMap->GetAt(HVRV_SPicPipe, sAngle);
TransformVecor(sAngle, vtMainv);
TransformVecor(sAngle, vtMain);
}
arpts.append(pt);//0
pt = arpts[0] - vtMain * dH;
arpts.append(pt);//1
pt = arpts[1] + vtMainv * dLength * 0.5;
arpts.append(pt);//2
pt = arpts[1] - vtMainv * dLength * 0.5;
arpts.append(pt);//3
pt = arpts[1] - vtMain * dBrLen;
arpts.append(pt);//4
pt = arpts[1] - vtMainv * dLength * 0.25;
arpts.append(pt);//5
pt = arpts[4] - vtMainv * dLength * 0.25;
arpts.append(pt);//6
pt = arpts[0] + vtMain * g_dCmdOff;
arpts.append(pt);//7
pt = arpts[1] + vtMain * dLength * 0.25;
arpts.append(pt);//8
if (nIsConverse)
{
pt = arpts[8] - vtMainv * dLength * 0.25;
}
else
pt = arpts[8] + vtMainv * dLength * 0.25;
arpts.append(pt);//9
return arpts.length() == 10;
}
// 获取外壳的8个顶点
BOOL THImpHvacVRVBrPipe::GetBoxPts(AcGePoint3dArray& arpts) const
{
AcGePoint3dArray arTmpPts;
if (!GetPts(arTmpPts))
return FALSE;
AcGeVector3d vtMain(AcGeVector3d::kXAxis), vtMainv(AcGeVector3d::kYAxis), vtNor(AcGeVector3d::kZAxis);
double dLength(300);
int nIsConverse(0);
m_pXDataMap->GetAt(HVRV_MainDir, vtMain);
m_pXDataMap->GetAt(HVRV_Length, dLength);
m_pXDataMap->GetAt(HVRV_IsConverse, nIsConverse);
vtNor = GetNormal();
vtMainv = vtMain;
if (nIsConverse)
{
vtMainv = -vtMain;
}
vtMainv.rotateBy(PI * 0.5, vtNor);
vtMain.normalize();
vtMainv.normalize();
AcGePoint3d pt;
pt = arTmpPts[0] + vtMainv * dLength * 0.5 - vtNor * 25;
arpts.append(pt);
pt = arTmpPts[4] + vtMainv * dLength * 0.5 - vtNor * 25;
arpts.append(pt);
pt = arTmpPts[4] - vtMainv * dLength * 0.5 - vtNor * 25;
arpts.append(pt);
pt = arTmpPts[0] - vtMainv * dLength * 0.5 - vtNor * 25;
arpts.append(pt);
pt = arTmpPts[0] + vtMainv * dLength * 0.5 + vtNor * 25;
arpts.append(pt);
pt = arTmpPts[4] + vtMainv * dLength * 0.5 + vtNor * 25;
arpts.append(pt);
pt = arTmpPts[4] - vtMainv * dLength * 0.5 + vtNor * 25;
arpts.append(pt);
pt = arTmpPts[0] - vtMainv * dLength * 0.5 + vtNor * 25;
arpts.append(pt);
return arpts.length() == 8;
}
int THImpHvacVRVBrPipe::GetBodyBox( AcDbExtents& ext ) const
{
if (m_pXDataMap == NULL)
return 0;
AcGePoint3dArray arpt;
if (!GetBoxPts(arpt))
return 0;
// 构造最小包含体
TAuxTools::BuildMinRectangle(arpt, ext);
return 1;
}
int THImpHvacVRVBrPipe::GetXBaseShell(TXShell& xShell)
{
if (m_pXDataMap == NULL)
return 0;
AcGePoint3dArray arpt;
if (!GetPts(arpt))
return 0;
//BEGIN================================================================================
//AcGePoint3d ptCent;
//Midpoint(arpt[0], arpt[4], ptCent);
//AcGePoint3d ptS, ptE;
AcGeVector3d vtNor = GetNormal();
//ptS = ptCent - vtNor * 25;
//ptE = ptCent + vtNor * 25;
double dWidth = 0.0;
double dThick = VRVPIPEDIA;
//m_pXDataMap->GetAt(HVRV_Width, dThick);
m_pXDataMap->GetAt(HVRV_Length, dWidth);
// 构造碰撞实体
TAuxTools::BuildRectDuct(arpt[0], arpt[4], vtNor, dWidth, dThick, dWidth, dThick, xShell);
//修改时间:2010-06-01
//修改人 :王亚东
//修改原因:支持分歧管的碰撞检测包围壳正确返回
//END===================================================================================
return 1;
}
TDb::Position THImpHvacVRVBrPipe::ExplainGripIndex(int nIndex) const
{
if(nIndex == 0)
{
return TDb::eMid;
}
else
{
return TDb::eCommand0;
}
}
Acad::ErrorStatus THImpHvacVRVBrPipe::GetGripText(int i, CString &cs) const
{
if (i == 0)
{
cs = _T("改变位置");
}
else if( i == 1)
{
cs = _T("输入口");;
}
else
{
cs = _T("输出口");;
}
return Acad::eOk;
}
void THImpHvacVRVBrPipe::GetTips(CMapStringToString& mapLable2Tip) const
{
}
BOOL THImpHvacVRVBrPipe::GetPtOnArcExt(AcGePoint3d &ptStartArc, const AcGePoint3d &ptCorStart, AcGePoint3d &ptEndArc, const AcGePoint3d &ptCorEnd, AcGePoint3d &ptOnArcOut, double &dPlusEdge) const
{
AcGeVector3d vtStr,vtEnd,vtCor,vtNor;
AcGeVector3d vtStartArc;
AcGeVector3d vtEndArc;
AcGePoint3d ptGeCen;
AcGePoint3d ptCorner;
AcGeVector3d vtCorStartCom = ptCorStart.asVector();
AcGeVector3d vtCorEndCom = ptCorEnd.asVector();
AcGeVector3d vtCornerCom = (vtCorStartCom + vtCorEndCom) / 2;
ptCorner = AcGePoint3d::kOrigin + vtCornerCom;
vtStr = ptStartArc - ptCorStart;
vtEnd = ptEndArc - ptCorEnd;
vtStr.normalize();
vtEnd.normalize();
ptStartArc = ptStartArc - vtStr * dPlusEdge;
ptEndArc = ptEndArc - vtEnd * dPlusEdge;
vtStartArc = ptStartArc - ptCorner;
vtEndArc = ptEndArc - ptCorner;
vtNor = vtStartArc.crossProduct(vtEndArc);
vtStartArc.rotateBy(PI * 0.5, vtNor);
vtEndArc.rotateBy(PI * 0.5, vtNor);
if(!GetIntersectWith(ptStartArc,ptEndArc,vtStartArc,vtEndArc,ptGeCen))
return FALSE;
vtCor = ptCorner - ptGeCen;
vtCor.normalize();
ptOnArcOut = ptGeCen + vtCor * (ptStartArc.distanceTo(ptGeCen));
return TRUE;
}
BOOL THImpHvacVRVBrPipe::GetIntersectWith(AcGePoint3d &pt1,AcGePoint3d &pt2,AcGeVector3d &vt1,AcGeVector3d &vt2,AcGePoint3d &ptIntersect) const
{
AcGeLine3d line1,line2;
line1.set(pt1,vt1);
line2.set(pt2,vt2);
return line1.intersectWith(line2, ptIntersect);
}
void THImpHvacVRVBrPipe::DrawElbow(XExplodeDraw &mode) const
{
AcGePoint3dArray arPts;
if (!GetPts(arPts))
return;
double dDiameter = 50.0,dPlusEdge = 0.1;
//int nSectType = 2;
AcDbObjectId idLayer;
//int nBaseLine = 1;
//int nSingleLine = 0;
int nSegments = 6;
AcGePoint3d ptStart, ptCorner, ptEnd;
//m_pXDataMap->GetAt(HELB_Segments, nSegments);
//m_pXDataMap->GetAt(HVAC_SectType,nSectType);
//BEGIN===================================================
//m_pXDataMap->GetAt(HELB_Diameter, dDiameter);
double dDiameterStart = 50.0;
double dDiameterEnd = 50.0;
ptStart = arPts[8];
ptEnd = arPts[5];
ptCorner = arPts[9];
//m_pXDataMap->GetAt(HELB_StartPoint,ptStart);
//m_pXDataMap->GetAt(HELB_CornerPoint,ptCorner);
//m_pXDataMap->GetAt(HELB_EndPoint,ptEnd);
//m_pXDataMap->GetAt(HVAC_HasBaseLine,nBaseLine);
//m_pXDataMap->GetAt(HVAC_IsSingleLine,nSingleLine);
// m_pXDataMap->GetAt(HELB_Diameter, dDiameterStart);
// if (!m_pXDataMap->GetAt(HELB_EndDiameter, dDiameterEnd))
// {
// dDiameterEnd = dDiameterStart;
// }
// double dMaxWidth = dDiameterStart > dDiameterEnd ? dDiameterStart : dDiameterEnd;
//
// if ((ptStart.distanceTo(ptCorner) - 50.0) - dMaxWidth / 2 < -1e-6)
// {
// dPlusEdge = 0.1;
// }
dDiameterStart *= 0.5;
dDiameterEnd *= 0.5;
double dMinDiffAng = TAuxTools::GetMinDiffAngle();
int nColumns = (int)(PI * 2 / dMinDiffAng);
//计算半径偏移量
double dDiameterOffset = dDiameterEnd - dDiameterStart;
AcGePoint3d ptOnArc = ptCorner;
AcGePoint3d ptStartArc = ptStart;
AcGePoint3d ptEndArc = ptEnd;
GetPtOnArcExt(ptStartArc, ptCorner, ptEndArc, ptCorner, ptOnArc, dPlusEdge);
AcGeCircArc3d circleArc;
circleArc.set(ptStartArc, ptOnArc, ptEndArc);
AcGePoint3d ptCenterArc = circleArc.center();
AcGeVector3d vtStartArc = ptStartArc - ptCenterArc;
AcGeVector3d vtEndArc = ptEndArc - ptCenterArc;
AcGeVector3d vtNormalArc = vtEndArc.crossProduct(vtStartArc);
vtStartArc.normalize();
vtEndArc.normalize();
vtNormalArc.normalize();
double dAngle = vtStartArc.angleTo(vtEndArc);
double dSegAngle = dAngle / nSegments;
//关键节点数组
AcGePoint3dArray arptKeys;
AcGePoint3d ptTemp; //临时点值,用于插入关键节点数组时使用
double dDiameterTemp = 50.0; //临时半径值,用于临时存储环节半径
//起始段
AcGeVector3d vtAxisStart = ptStart - ptStartArc;
//起始段前端
for (int iStart = 0; iStart < nColumns; iStart++)
{
ptTemp = ptStart + dDiameterStart * vtStartArc;
ptTemp.rotateBy(dMinDiffAng * iStart, vtAxisStart, ptStart);
arptKeys.append(ptTemp);
}
ptTemp = ptStart + dDiameterStart * vtStartArc;
arptKeys.append(ptTemp);
//起始段后端
for (int iStartArc = 0; iStartArc < nColumns; iStartArc++)
{
ptTemp = ptStartArc + dDiameterStart * vtStartArc;
ptTemp.rotateBy(dMinDiffAng * iStartArc, vtAxisStart, ptStartArc);
arptKeys.append(ptTemp);
}
ptTemp = ptStartArc + dDiameterStart * vtStartArc;
arptKeys.append(ptTemp);
//中间圆弧段
for (int iArc = 1; iArc < nSegments; iArc++)
{
dDiameterTemp = dDiameterStart + dDiameterOffset * iArc / nSegments;
AcGePoint3d ptStartArcTemp = ptStartArc;
AcGePoint3d ptOnArcTemp = ptStartArcTemp.rotateBy(-dSegAngle * iArc, vtNormalArc, ptCenterArc);
AcGeVector3d vtOnArcTemp = ptOnArcTemp - ptCenterArc;
AcGeVector3d vtOnArcAxis = vtOnArcTemp;
vtOnArcAxis.rotateBy(PI / 2, vtNormalArc);
vtOnArcTemp.normalize();
for (int i = 0; i < nColumns; i++)
{
ptTemp = ptOnArcTemp + dDiameterTemp * vtOnArcTemp;
ptTemp.rotateBy(dMinDiffAng * i, vtOnArcAxis, ptOnArcTemp);
arptKeys.append(ptTemp);
}
ptTemp = ptOnArcTemp + dDiameterTemp * vtOnArcTemp;
arptKeys.append(ptTemp);
}
//末尾段
AcGeVector3d vtAxisEnd = ptEndArc - ptEnd;
//末尾段前端
for (int iEndArc = 0; iEndArc < nColumns; iEndArc++)
{
ptTemp = ptEndArc + dDiameterEnd * vtEndArc;
ptTemp.rotateBy(dMinDiffAng * iEndArc, vtAxisEnd, ptEndArc);
arptKeys.append(ptTemp);
}
ptTemp = ptEndArc + dDiameterEnd * vtEndArc;
arptKeys.append(ptTemp);
//末尾段后端
for (int iEnd = 0; iEnd < nColumns; iEnd++)
{
ptTemp = ptEnd + dDiameterEnd * vtEndArc;
ptTemp.rotateBy(dMinDiffAng * iEnd, vtAxisEnd, ptEnd);
arptKeys.append(ptTemp);
}
ptTemp = ptEnd + dDiameterEnd * vtEndArc;
arptKeys.append(ptTemp);
//生成三维网格
mode.DrawMesh(nSegments + 3, nColumns + 1, arptKeys.asArrayPtr());
}
Acad::ErrorStatus THImpHvacVRVBrPipe::ExplodeOrDraw3d(XExplodeDraw &mode) const
{
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
// XPoint p1 = arpts[1],p2 = arpts[4];
// XLine l1(p1,p2);
// mode.DrawLine(l1);
// p1 = arpts[5];
// p2 = arpts[6];
// l1.SetPoints(p1,p2);
// mode.DrawLine(l1);
DrawElbow(mode);
AcGePoint3d ptS = arpts[0];
AcGePoint3d ptE = arpts[4];
AcGeVector3d vtNormal = normal();
AcGeVector3d vtDirect = ptE - ptS;
vtDirect.normalize();
double dMinAngle(TAuxTools::GetMinDiffAngle());
int nPartNum = int(PI * 2 / dMinAngle);
dMinAngle = PI * 2 / nPartNum;
double dDiaMet(50.0);
AcGePoint3dArray ptArr;
// 修改为,三维最外轮廓跟返回Polylinje一致
// AcGeVector3d vtNow = vtNormal * -1; // 每组顶点法向
AcGeVector3d vtNow = vtNormal.crossProduct(vtDirect); // 每组顶点法向
int i(0);
for (i = 0; i < nPartNum * 2; i += 2)
{
ptArr.append(ptS + dDiaMet * 0.5 * vtNow);
ptArr.append(ptE + dDiaMet * 0.5 * vtNow);
vtNow.rotateBy(dMinAngle, vtDirect);
}
// 单独设置末点,防止误差
ptArr.append(ptArr.at(0));
ptArr.append(ptArr.at(1));
mode.DrawMesh(nPartNum + 1, 2, ptArr.asArrayPtr());
ptArr.setLogicalLength(0);
ptS = arpts[5];
ptE = arpts[6];
vtDirect = ptE - ptS;
vtDirect.normalize();
ptS = ptS - vtDirect * 25.0;
ptE = ptE + vtDirect * 25.0;
vtNow = vtNormal.crossProduct(vtDirect);
for (i = 0; i < nPartNum * 2; i += 2)
{
ptArr.append(ptS + dDiaMet * 0.5 * vtNow);
ptArr.append(ptE + dDiaMet * 0.5 * vtNow);
vtNow.rotateBy(dMinAngle, vtDirect);
}
// 单独设置末点,防止误差
ptArr.append(ptArr.at(0));
ptArr.append(ptArr.at(1));
mode.DrawMesh(nPartNum + 1, 2, ptArr.asArrayPtr());
return Acad::eOk;
}
AcGeVector3d THImpHvacVRVBrPipe::GetNormal() const
{
ASSERT(NULL != m_pXDataMap);
AcGeVector3d vtNor;
m_pXDataMap->GetAt(HVAC_Normal, vtNor);
return vtNor.normalize();
}
AcGeVector3d THImpHvacVRVBrPipe::GetVtMain() const
{
ASSERT(NULL != m_pXDataMap);
AcGeVector3d vtMain;
m_pXDataMap->GetAt(HVRV_MainDir, vtMain);
return vtMain.normalize();
}
double THImpHvacVRVBrPipe::GetLength() const
{
ASSERT(NULL != m_pXDataMap);
double dLength(300.0);
m_pXDataMap->GetAt(HVRV_Length, dLength);
return dLength;
}
CString THImpHvacVRVBrPipe::GetMediaPipeDn() const
{
ASSERT(NULL != m_pXDataMap);
CString sDn;
m_pXDataMap->GetAt(HVRV_SMediaPipe, sDn);
return sDn;
}
double THImpHvacVRVBrPipe::GetEndLineWidth() const
{
BOOL bShow(FALSE);
GetGlobalContext(HVAC_SHOWWIDTH, bShow);
// add by hh 2011-01-05 从图纸中读取加粗标识 避免全局参数对不同的图纸间的影响
TAuxTools::GetTHvacDataFromDwg(HVAC_SHOWWIDTH, bShow);
if (!bShow)
return 0.0;
ASSERT(NULL != m_pXDataMap);
double dWidth(0.0);
m_pXDataMap->GetAt(HVAC_EndWidth, dWidth);
return dWidth;
}
AcDbObjectId THImpHvacVRVBrPipe::GetEndLayer() const
{
ASSERT(NULL != m_pXDataMap);
AcDbObjectId idSideLayer(AcDbObjectId::kNull);
m_pXDataMap->GetAt(HVAC_EndLayer, idSideLayer);
return idSideLayer;
}
int THImpHvacVRVBrPipe::GetDrawType() const
{
ASSERT(NULL != m_pXDataMap);
int nDrawType(0);
m_pXDataMap->GetAt(KEY_DrawType, nDrawType);//是否画实心
return nDrawType;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::ExplodeOrDraw2d(XExplodeDraw &mode) const
{
AcGePoint3dArray arpts;
if(!GetPts(arpts))
return Acad::eNotApplicable;
if (!IsSysMode())
{
AcGePlane plan(arpts[0], arpts[1], arpts[2]);
AcGePoint3d ptOrth = AcGePoint3d::kOrigin.orthoProject(plan);
plan.set(ptOrth, GetNormal());
double dEl = ptOrth.asVector().length();
if (ptOrth.asVector().angleTo(plan.normal()) > PI*0.5)
dEl *= -1.0;
AcDbPolyline pArrow;
//画实心
if (GetDrawType())
{
pArrow.addVertexAt(0, arpts[0].convert2d(plan));
pArrow.addVertexAt(1, arpts[1].convert2d(plan));
pArrow.setWidthsAt(0, 0, GetLength());
}
else
{
pArrow.addVertexAt(0, arpts[0].convert2d(plan));
pArrow.addVertexAt(1, arpts[2].convert2d(plan));
pArrow.addVertexAt(2, arpts[3].convert2d(plan));
pArrow.setClosed(Adesk::kTrue);
// 需求变更,三角形保持原样,两个引出管加粗Lixl add 2012/5/16
// pArrow.addVertexAt(3, arpts[0].convert2d(plan));
// TGGiWorldViewportDraw绘制PLINE线的时候,线宽需要考虑打印比例Lixl add 2012/5/3
// double dEndLineWidth = GetEndLineWidth();
// double dPScale = ((TDbInterfacesObj*)m_pOwnerEnt)->GetPrintScale();
// if (dPScale < 1.e-3)
// dPScale = 1.0;
// pArrow.setWidthsAt(0, dEndLineWidth*dPScale, dEndLineWidth*dPScale);
// pArrow.setWidthsAt(1, dEndLineWidth*dPScale, dEndLineWidth*dPScale);
// pArrow.setWidthsAt(2, dEndLineWidth*dPScale, dEndLineWidth*dPScale);
}
pArrow.setElevation(dEl);
mode.Polyline(pArrow);
}
else // 系统图绘制
{
// TDbExtentsEdge edage;
// edage.SetEdage(cplCurve);
//
// AcDbObjectId idReal = ((TDbInterfacesObj*)m_pOwnerEnt)->layerId();
// AcDbObjectId idDash = ((TDbInterfacesObj*)m_pOwnerEnt)->DashLayer();
// AcDbObjectId idCent = ((TDbInterfacesObj*)m_pOwnerEnt)->CenterLayer();
//
// edage.ExplodeOrDraw2d(mode,idReal,idDash,idCent,NULL,FALSE,FALSE);
}
return Acad::eOk;
}
XPoint THImpHvacVRVBrPipe::TransformPoint(const XPoint& point, double angle, const XPoint& basePoint) const
{
XPoint pt = point- basePoint;//
XPoint ptN(pt.x + cos(angle) * pt.y, pt.z + sin(angle) * pt.y, point.z);
return ptN;
}
void THImpHvacVRVBrPipe::TransformVecor(CString sAngle, AcGeVector3d& vt) const
{
double dAngle = _tstof(sAngle) * PI / 180;
vt.set(vt.x + cos(dAngle) * vt.y, vt.z + sin(dAngle) * vt.y, 0);
//vt.normalize();
}
void THImpHvacVRVBrPipe::list() const
{
if (m_pXDataMap != NULL)
{
AcGePoint3d ptCenter;
AcGeVector3d vtMain;
CString sType,sName,sParma;
double dLength(50.0), dThick(50.0), dWidth(50.0), dPlusEdge(50.0);
double daircap(0),drefri(0),dheatcap(0),dwtrRes(0);
TDbXDataMap mapparam;
// m_pXDataMap->GetAt(HVRV_SFactory, sType);
// m_pXDataMap->GetAt(HVRV_SEquipName, sName);
m_pXDataMap->GetAt(HVRV_CenterPoint, ptCenter);
m_pXDataMap->GetAt(HVRV_MainDir, vtMain);
m_pXDataMap->GetAt(HVRV_Length, dLength);
m_pXDataMap->GetAt(HVRV_Width, dWidth);
m_pXDataMap->GetAt(HVRV_Thick, dThick);
acutPrintf(_T("\t\t\t\t\t\t\t\t%s"),sType);
acutPrintf(_T("\n\t\t\t\t\t型号: %s"),sName);
//读出所有参数信息
m_pXDataMap->GetAt(HVRV_Parameter,0,mapparam);
TDbXDataMap::It it;
TXData xdata;
for(it = mapparam.Begin();it != mapparam.End();)
{
m_pXDataMap->GetAt(it->first, sParma);
mapparam.GetNext(it,xdata);
acutPrintf(_T("\n\t\t\t\t\t%s%s"),xdata.pszVal,sParma);
}
//几何参数信息
acutPrintf(_T("\n\t\t\t\t\t长度: %.0fmm"),fabs(dLength));
acutPrintf(_T("\n\t\t\t\t\t宽度: %.0fmm"),fabs(dWidth));
acutPrintf(_T("\n\t\t\t\t\t高度: %.0fmm"),fabs(dThick));
acutPrintf(_T("\n\t\t\t\t\t标高: %.0fm"),ptCenter.z * 0.001);
int icount(0);
m_pXDataMap->GetAt(HVRV_InterfaceNum, icount);
if (icount < 1)
{
acutPrintf(_T("\n\t\t\t\t\t接口:无"));
}
}
}
BOOL THImpHvacVRVBrPipe::IsSysMode() const
{
if (m_pXDataMap == NULL)
return FALSE;
HvacModelType eType = eModel;
m_pXDataMap->GetAt(HVAC_ModeType, (int&)eType);
if (eType != eSystem)
return FALSE;
return TRUE;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::transformBy(const AcGeMatrix3d& xform)
{
if (NULL == m_pXDataMap)
return Acad::eNotApplicable;
// 取得位置点
AcGePoint3d ptCenter;
AcGeVector3d vtMain,vtNor;
double dL(1.0),dW(1.0),dT(1.0);
m_pXDataMap->GetAt(HVRV_CenterPoint, ptCenter);
m_pXDataMap->GetAt(HVRV_MainDir, vtMain);
m_pXDataMap->GetAt(HVRV_Length, dL);
m_pXDataMap->GetAt(HVRV_Width, dW);
m_pXDataMap->GetAt(HVRV_Thick, dT);
m_pXDataMap->GetAt(HVAC_Normal, vtNor);
AcGeVector3d vtPrep(vtNor.crossProduct(vtMain));
// 变换位置
vtNor.transformBy(xform);
ptCenter.transformBy(xform);
vtMain.transformBy(xform);
vtPrep.transformBy(xform);
// 同向是旋转,不变号,反向是镜像,变号。
int iSign = ((vtPrep.isCodirectionalTo(vtNor.crossProduct(vtMain))) ? 1 : -1);
// 更新点
m_pXDataMap->SetAt(HVAC_Normal, vtNor);
m_pXDataMap->SetAt(HVRV_CenterPoint, ptCenter);
m_pXDataMap->SetAt(HVRV_MainDir, vtMain);
int nIsConverse(0);
m_pXDataMap->GetAt(HVRV_IsConverse, nIsConverse);
if (iSign < 0)
{
if (nIsConverse)
{
m_pXDataMap->SetAt(HVRV_IsConverse, 0);
}
else
m_pXDataMap->SetAt(HVRV_IsConverse, 1);
}
// 传递消息
if (m_pOwnerEnt != NULL && m_pOwnerEnt->objectId().isValid())
{
// 如果实体不是在当前模型空间中,不做写消息,更新接口处理
AcDbDatabase* pDb = m_pOwnerEnt->database();
if (pDb == NULL) pDb = acdbCurDwg();
AcDbObjectId idModel;
AcDbBlockTable* pTable = NULL;
pDb->getBlockTable(pTable, AcDb::kForRead);
if (pTable != NULL)
{
pTable->getAt(ACDB_MODEL_SPACE, idModel);
pTable->close();
}
// 如果实体不是在当前模型空间中,不做写消息,更新接口处理
if (idModel == m_pOwnerEnt->blockId())
{
TInterfaceModifyMsg iMsg;
iMsg.SetInterfaceOper(TDb::eTransformBy);
iMsg.SetMsgValidate(TRUE);
iMsg.SetTransform(xform);
iMsg.SetMsgOperateOn(m_pOwnerEnt->objectId());
TDbInterfaceMsgWrite msgWrite;
msgWrite.WriteInterfaceMsg(iMsg);
//更新接口记录接口信息
UpdateInterfaceRec(m_pOwnerEnt->objectId(), xform);
}
}
return Acad::eOk;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::getStretchPoints(AcGePoint3dArray& stretchPoints) const
{
if (NULL == m_pXDataMap)
return Acad::eNotApplicable;
// 取得位置点
AcGePoint3d ptCenter;
m_pXDataMap->GetAt(HVRV_CenterPoint, ptCenter);
stretchPoints.append(ptCenter);
return Acad::eOk;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::moveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
return moveGripPointsAt(indices,offset);
}
Acad::ErrorStatus THImpHvacVRVBrPipe::moveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
ASSERT(NULL != m_pXDataMap);
int nSize = indices.length();
if (nSize > 0)
{
// 取得位置点
AcGePoint3d ptCenter;
m_pXDataMap->GetAt(HVRV_CenterPoint, ptCenter);
AcGeVector3d vtMain,vtMainv;
m_pXDataMap->GetAt(HVRV_MainDir, vtMain);
// 选择多个夹点,以first为准
int nIndex = indices.first();
TDb::Position ePos = ExplainGripIndex(nIndex);
switch(ePos)
{
case TDb::eMid:
{
TDb::InterfaceOper eOper = TDb::eMoveGripPoint;
AcGeVector3d vtMove = offset;
ptCenter += vtMove;
m_pXDataMap->SetAt(HVRV_CenterPoint, ptCenter);
if (m_pOwnerEnt != NULL && m_pOwnerEnt->objectId().isValid())
{
// 写入接口更改消息
TInterfaceModifyMsg iMsg;
iMsg.SetMsgPoint(ptCenter);//new pos
iMsg.SetGripPosition(TDb::eMid);
iMsg.SetMoveGripOffset(vtMove);
if (eOper == TDb::eTransformBy)
iMsg.SetTransform(vtMove);
iMsg.SetMsgValidate(TRUE);
iMsg.SetInterfaceOper(eOper);
iMsg.SetMsgOperateOn(m_pOwnerEnt->objectId());
TDbInterfaceMsgWrite msgWrite;
msgWrite.WriteInterfaceMsg(iMsg);
//更新接口记录接口信息
AcGeMatrix3d xform;
xform.setToTranslation(vtMove);
UpdateInterfaceRec(m_pOwnerEnt->objectId(),xform);
}
break;
}
case TDb::eCommand0:
{
AcGePoint3dArray arpts;
if (!GetPts(arpts))
return Acad::eNotApplicable;
AcGePoint3d ptCom;
if (nIndex == 1)
{
ptCom = arpts[0];
}
else if (nIndex == 2)
{
ptCom = arpts[4];
}
else if (nIndex == 3)
{
ptCom = arpts[6];
}
CString sCmdStr;
GetGlobalContext()->GetAt(KEY_HVACMEDIAGRIPCMD, sCmdStr);
if (sCmdStr.IsEmpty())
return Acad::eNotApplicable;
// 写入接口更改消息
TInterfaceModifyMsg iMsg;
iMsg.SetMsgPoint(ptCom);//new pos
iMsg.SetGripPosition(ePos);
iMsg.SetMoveGripOffset(offset);
iMsg.SetMsgValidate(TRUE);
iMsg.SetInterfaceOper(TDb::eNewCommand);
iMsg.SetPreviewObjToCreate(TDb::eVRVBrPipe, 0);
AcDbSoftPointerId idOwner;
m_pXDataMap->GetAt(KEY_THISID,idOwner);
iMsg.SetMsgOperateOn(idOwner);
TDbInterfaceMsgWrite msgWrite;
msgWrite.WriteInterfaceMsg(iMsg);
// 发送消息
acedPostCommand(_T("\33"));
acedPostCommand(sCmdStr + _T("\n"));
break;
}
default:
break;
}
}
return Acad::eOk;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::getOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& pickPoint,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
AcGePoint3dArray arpts;
if (!GetPts(arpts))
return Acad::eNotApplicable;
// 根据捕捉模式处理
switch(osnapMode)
{
case AcDb::kOsModeEnd:
snapPoints.append(arpts[4]);
snapPoints.append(arpts[6]);
break;
case AcDb::kOsModeCen:
snapPoints.append(arpts[0]);
break;
case AcDb::kOsModeMid:
break;
case AcDb::kOsModePerp:
break;
case AcDb::kOsModeNear:
break;
}
return Acad::eOk;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::getGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
AcGePoint3dArray arpts;
if (!GetPts(arpts))
return Acad::eNotApplicable;
//移动夹点
gripPoints.append(arpts[0]);
//命令夹点
gripPoints.append(arpts[7]);
gripPoints.append(arpts[4]);
gripPoints.append(arpts[6]);
return Acad::eOk;
}
Acad::ErrorStatus THImpHvacVRVBrPipe::getClassID(CLSID* pClsid) const
{
// #if (ADS < 16)
// // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6E8}
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE8 }};
// #endif
//
// #if (ADS == 16)
// // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6E9}
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE9 }};
// #endif
//
// #if (ADS == 17)
// // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6EA}
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEA }};
// #endif
//
// #if (ADS == 18)
// CLSID CLSID_PipeBaseEntity = {0xD7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEB }};
// #endif
//
// #if (ADS == 19)
// CLSID CLSID_PipeBaseEntity = {0xD7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEB }};
// #endif
return Acad::eOk;
}
BOOL THImpHvacVRVBrPipe::OPMInfo(LPCTSTR pszName, TDb::OPMInfo* pInfo)
{
ASSERT(NULL != pszName && NULL != pInfo && NULL != m_pXDataMap);
// 暖通基本参数设置
if (0 == _tcsicmp(pszName, KEY_RUNTIME))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = FALSE;
// 提供数据列表和对应关系
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
{
pInfo->parsValues->Add(_T("分歧管"));
pInfo->parlValues->Add(TDb::eVRVBrPipe);
}
return TRUE;
}
if (0 == _tcsicmp(pszName, KEY_Model))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = TRUE;
return TRUE;
}
if (0 == _tcsicmp(pszName, KEY_StartPoint))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = TRUE;
// 整体移动
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
{
// 改变顶点变换行为
AcGePoint3d pt;
m_pXDataMap->GetAt(KEY_StartPoint, pt);
AcGeVector3d offset = asPnt3d(pInfo->pXData->dVal) - pt;
AcGeMatrix3d mat;
mat.setToTranslation(offset);
transformBy(mat);
pInfo->pXData->nVt = 0; // 设置处理完成标识
//TAuxTools::SetAndUpdateCover((TDbInterfacesObj*)m_pOwnerEnt, pszName, pInfo);
}
return TRUE;
}
// 多联机样式 为了注册列表名,保证其他管件能用到此参数
if (0 == _tcsicmp(pszName, HVRV_IType))
{
pInfo->bVisible = FALSE;
pInfo->bEditable = FALSE;
// 提供数据列表和对应关系
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
{
pInfo->parlValues->Add(0);
pInfo->parsValues->Add(_T("室内机"));
pInfo->parlValues->Add(1);
pInfo->parsValues->Add(_T("室外机"));
}
return TRUE;
}
return FALSE;
}
// 导出XML
// CString THImpHvacVRVBrPipe::GetXml() const
// {
// if (NULL == m_pXDataMap || NULL == m_pOwnerEnt)
// return _T("");
//
// int nValue(0);
// double dValue(0.0);
// int nPtPreci = 6; // 位置精度
// int nWhPreci = 0; // 宽度、高度精度
//
// TXmlTree xmlTree;
// CString csText;
// CString csX, csY, csZ;
// AcGePoint3d pt;
// AcGeVector3d vt;
// POSITION posRoot = xmlTree.Insert(_T("ATS_DBHEQUIPMENT"), NULL, NULL);
// {
// xmlTree.SetAttribute(posRoot, _T("name"), _T("分歧管"));
// xmlTree.SetAttribute(posRoot, _T("comment"), _T("上华对象名称"));
// }
//
// POSITION posItemNorDir = xmlTree.Insert(_T("NormalDir"),posRoot, NULL);
// {
// xmlTree.SetAttribute(posItemNorDir, _T("name"), _T("法向量"));
// m_pXDataMap->GetAt(HVAC_Normal, vt);
// TAuxTools::DoubleToString(vt.x, nPtPreci, csX);
// TAuxTools::DoubleToString(vt.y, nPtPreci, csY);
// TAuxTools::DoubleToString(vt.z, nPtPreci, csZ);
// csText.Format(_T("%s,%s,%s"), csX, csY, csZ);
// xmlTree.SetItemText(posItemNorDir, csText);
// }
//
// POSITION posItemCentPt = xmlTree.Insert(_T("CenterPoint"), posRoot, posItemNorDir);
// {
// xmlTree.SetAttribute(posItemCentPt, _T("name"), _T("中心点"));
// xmlTree.SetAttribute(posItemCentPt, _T("comment"), _T("布置点"));
// m_pXDataMap->GetAt(HVRV_CenterPoint, pt);
// TAuxTools::DoubleToString(pt.x, nPtPreci, csX);
// TAuxTools::DoubleToString(pt.y, nPtPreci, csY);
// TAuxTools::DoubleToString(pt.z, nPtPreci, csZ);
// csText.Format(_T("%s,%s,%s"), csX, csY, csZ);
// xmlTree.SetItemText(posItemCentPt, csText);
// }
//
// POSITION posItemMainDir = xmlTree.Insert(_T("MainDir"), posRoot, posItemCentPt);
// {
// xmlTree.SetAttribute(posItemMainDir, _T("name"), _T("主矢量"));
// xmlTree.SetAttribute(posItemMainDir, _T("comment"), _T("布置角度"));
// m_pXDataMap->GetAt(HVRV_MainDir, vt);
// TAuxTools::DoubleToString(vt.x, nPtPreci, csX);
// TAuxTools::DoubleToString(vt.y, nPtPreci, csY);
// TAuxTools::DoubleToString(vt.z, nPtPreci, csZ);
// csText.Format(_T("%s,%s,%s"), csX, csY, csZ);
// xmlTree.SetItemText(posItemMainDir, csText);
// }
//
// POSITION posItemBsPtIdx = xmlTree.Insert(_T("BasePtIndex"), posRoot, posItemMainDir);
// {
// xmlTree.SetAttribute(posItemBsPtIdx, _T("name"), _T("基点索引"));
// xmlTree.SetAttribute(posItemBsPtIdx, _T("comment"), _T("基点索引号"));
// m_pXDataMap->GetAt(KEY_SectType, nValue);
// csText.Format(_T("%d"), nValue);
// xmlTree.SetItemText(posItemBsPtIdx, csText);
// }
//
// POSITION posItemReverse = xmlTree.Insert(_T("IsReverse"), posRoot, posItemBsPtIdx);
// {
// xmlTree.SetAttribute(posItemReverse, _T("name"), _T("是否反向"));
// xmlTree.SetAttribute(posItemReverse, _T("comment"), _T("用于辅助绘制0:否,1:是"));
// m_pXDataMap->GetAt(HVRV_IsConverse, nValue);
// csText.Format(_T("%d"), nValue);
// xmlTree.SetItemText(posItemReverse, csText);
// }
//
// POSITION posItemLength = xmlTree.Insert(_T("Length"), posRoot, posItemReverse);
// {
// xmlTree.SetAttribute(posItemLength, _T("name"), _T("长度"));
// xmlTree.SetAttribute(posItemLength, _T("comment"), _T("设备长度"));
// m_pXDataMap->GetAt(HVRV_Length, dValue);
// TAuxTools::DoubleToString(dValue, nWhPreci, csText);
// xmlTree.SetItemText(posItemLength, csText);
// }
//
// POSITION posItemWidth = xmlTree.Insert(_T("Width"), posRoot, posItemLength);
// {
// xmlTree.SetAttribute(posItemWidth, _T("name"), _T("宽度"));
// xmlTree.SetAttribute(posItemWidth, _T("comment"), _T("设备宽度"));
// m_pXDataMap->GetAt(HVRV_Width, dValue);
// TAuxTools::DoubleToString(dValue, nWhPreci, csText);
// xmlTree.SetItemText(posItemWidth, csText);
// }
//
// CString csXml = xmlTree.GetXml();
//
// return csXml;
// }
CString THImpHvacVRVBrPipe::GetXml(const AcGeMatrix3d& mat) const
{
if (NULL == m_pXDataMap || NULL == m_pOwnerEnt)
return _T("");
int nValue(0);
double dValue(0.0);
int nPtPreci = 6; // 位置精度
int nWhPreci = 0; // 宽度、高度精度
TXmlTree xmlTree;
CString csText;
CString csX, csY, csZ;
AcGePoint3d pt;
AcGeVector3d vt;
POSITION posRoot = xmlTree.Insert(_T("ATS_DBHEQUIPMENT"), NULL, NULL);
{
xmlTree.SetAttribute(posRoot, _T("name"), _T("分歧管"));
xmlTree.SetAttribute(posRoot, _T("comment"), _T("上华对象名称"));
}
POSITION posItemNorDir = xmlTree.Insert(_T("NormalDir"),posRoot, NULL);
{
xmlTree.SetAttribute(posItemNorDir, _T("name"), _T("法向量"));
m_pXDataMap->GetAt(HVAC_Normal, vt);
TAuxTools::DoubleToString(vt.x, nPtPreci, csX);
TAuxTools::DoubleToString(vt.y, nPtPreci, csY);
TAuxTools::DoubleToString(vt.z, nPtPreci, csZ);
csText.Format(_T("%s,%s,%s"), csX, csY, csZ);
xmlTree.SetItemText(posItemNorDir, csText);
}
POSITION posItemCentPt = xmlTree.Insert(_T("CenterPoint"), posRoot, posItemNorDir);
{
xmlTree.SetAttribute(posItemCentPt, _T("name"), _T("中心点"));
xmlTree.SetAttribute(posItemCentPt, _T("comment"), _T("布置点"));
m_pXDataMap->GetAt(HVRV_CenterPoint, pt);
pt.transformBy(mat);
TAuxTools::DoubleToString(pt.x, nPtPreci, csX);
TAuxTools::DoubleToString(pt.y, nPtPreci, csY);
TAuxTools::DoubleToString(pt.z, nPtPreci, csZ);
csText.Format(_T("%s,%s,%s"), csX, csY, csZ);
xmlTree.SetItemText(posItemCentPt, csText);
}
POSITION posItemMainDir = xmlTree.Insert(_T("MainDir"), posRoot, posItemCentPt);
{
xmlTree.SetAttribute(posItemMainDir, _T("name"), _T("主矢量"));
xmlTree.SetAttribute(posItemMainDir, _T("comment"), _T("布置角度"));
m_pXDataMap->GetAt(HVRV_MainDir, vt);
TAuxTools::DoubleToString(vt.x, nPtPreci, csX);
TAuxTools::DoubleToString(vt.y, nPtPreci, csY);
TAuxTools::DoubleToString(vt.z, nPtPreci, csZ);
csText.Format(_T("%s,%s,%s"), csX, csY, csZ);
xmlTree.SetItemText(posItemMainDir, csText);
}
POSITION posItemBsPtIdx = xmlTree.Insert(_T("BasePtIndex"), posRoot, posItemMainDir);
{
xmlTree.SetAttribute(posItemBsPtIdx, _T("name"), _T("基点索引"));
xmlTree.SetAttribute(posItemBsPtIdx, _T("comment"), _T("基点索引号"));
m_pXDataMap->GetAt(KEY_SectType, nValue);
csText.Format(_T("%d"), nValue);
xmlTree.SetItemText(posItemBsPtIdx, csText);
}
POSITION posItemReverse = xmlTree.Insert(_T("IsReverse"), posRoot, posItemBsPtIdx);
{
xmlTree.SetAttribute(posItemReverse, _T("name"), _T("是否反向"));
xmlTree.SetAttribute(posItemReverse, _T("comment"), _T("用于辅助绘制0:否,1:是"));
m_pXDataMap->GetAt(HVRV_IsConverse, nValue);
csText.Format(_T("%d"), nValue);
xmlTree.SetItemText(posItemReverse, csText);
}
POSITION posItemLength = xmlTree.Insert(_T("Length"), posRoot, posItemReverse);
{
xmlTree.SetAttribute(posItemLength, _T("name"), _T("长度"));
xmlTree.SetAttribute(posItemLength, _T("comment"), _T("设备长度"));
m_pXDataMap->GetAt(HVRV_Length, dValue);
TAuxTools::DoubleToString(dValue, nWhPreci, csText);
xmlTree.SetItemText(posItemLength, csText);
}
POSITION posItemWidth = xmlTree.Insert(_T("Width"), posRoot, posItemLength);
{
xmlTree.SetAttribute(posItemWidth, _T("name"), _T("宽度"));
xmlTree.SetAttribute(posItemWidth, _T("comment"), _T("设备宽度"));
m_pXDataMap->GetAt(HVRV_Width, dValue);
TAuxTools::DoubleToString(dValue, nWhPreci, csText);
xmlTree.SetItemText(posItemWidth, csText);
}
CString csXml = xmlTree.GetXml();
return csXml;
}