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

1198 lines
29 KiB
C++

#include "stdafx.h"
#include "DbPool.h"
#include "DbPipe.h"
#include "DbWellDim.h"
const Adesk::UInt8 TDbPool::g_nVersion = 1;
ACRX_DXF_DEFINE_MEMBERS(ATSPool, ATSHDbEquipment, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, ATS_POOL, "ATS_POOL图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbPool);
void InitDbPool(BOOL bTrue)
{
if (bTrue)
{
TDbPool::rxInit();
TDbPool::InitMatchProtocol(TRUE);
}
else
{
TDbPool::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbPool::desc());
}
}
TDbPool::TDbPool()
{
m_dBottomBanEle = 0.0;
m_dGroundEle = 0.0;
m_dTopBanEle = 0.0;
m_dSpare = 0.0;
m_nSpare = 0;
m_sSpare = _T("");
m_bIsModify = false;
}
TDbPool::~TDbPool()
{
}
Acad::ErrorStatus TDbPool::subGetClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
Acad::ErrorStatus TDbPool::dwgInFields (AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = THDbEquipment::dwgInFields(pFiler);
if(es != Acad::eOk)
return es;
Adesk::UInt8 nVer = 0;
pFiler->readItem(&nVer);
if(nVer>g_nVersion)
{// Version is too new
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_dTopBanEle);
pFiler->readItem(&m_dBottomBanEle);
pFiler->readItem(&m_dGroundEle);
pFiler->readItem(&m_dSpare);
pFiler->readItem(&m_nSpare);
ReadString(pFiler,m_sSpare);
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbPool::dwgOutFields(AcDbDwgFiler *pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = THDbEquipment::dwgOutFields(pFiler);
if(es != Acad::eOk)
return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_dTopBanEle);
pFiler->writeItem(m_dBottomBanEle);
pFiler->writeItem(m_dGroundEle);
pFiler->writeItem(m_dSpare);
pFiler->writeItem(m_nSpare);
pFiler->writeString(m_sSpare);
//写入起点个数
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbPool::dxfInFields (AcDbDxfFiler *pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = THDbEquipment::dxfInFields(pFiler);
if(es!=Acad::eOk)
return pFiler->filerStatus();
if (!pFiler->atSubclassData(_T("TDbPool")))
{
return Acad::eBadDxfSequence;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbPool::dxfOutFields(AcDbDxfFiler *pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es=THDbEquipment::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbPool"));
assert(es == Acad::eOk);
return Acad::eOk;
}
AcGeScale3d TDbPool::GetInsert2dScale() const
{
assertReadEnabled();
AcGeScale3d scale(1);
scale.sx *= m_dSizeX;
scale.sy *= m_dSizeY;
if (IsMirrorByY())
scale.sx *= -1;
if (IsMirrorByX())
scale.sy *= -1;
return scale;
}
Acad::ErrorStatus TDbPool::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
if (player.openStatus() == Acad::eOk && player->isOff())
{
return Acad::eOk;
}
if(!m_idBlock2d.isValid())
return Acad::eInvalidInput;
if(fabs(m_vtDirection.x)<1.0E-6 && fabs(m_vtDirection.y)<1.0E-6)
return Acad::eOk; //垂直设备
AcGeScale3d scale=GetInsert2dScale();
OPENOBJ_BEGIN(m_idBlock2d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if(pBlock != NULL) {
XPoint ptLocation(m_ptLocation);
ptLocation.z=0;
double dAngle = ads_angle(XPoint(),m_vtDirection);
// BOOL bNewMethod=(g_nAcadVer>15.0001 && g_bMakeBlock);
// sg add 091105,强制打印时,不使用新方法
// if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor())==0 && dc.IsPlotGeneration())
// bNewMethod = FALSE;
//2011-9-30 沈睿dc.DrawBlock(*pBlock,ptInsert,GetInsertScale(),dAngle,TRUE); 采用旧方法,从8.0版本开始,TRUE参数对于打印不起作用。关闭图层,仍然打印
//dc.DrawBlock(*pBlock,ptLocation,scale,dAngle,bNewMethod);
dc.DrawBlock(*pBlock,ptLocation,scale,dAngle,TRUE);
}
OPENOBJ_END();
/*
//绘制接口
for(int i=0; i<m_lstInterface.Length(); i++) {
const TPipeInterface &iFace=m_lstInterface[i];
if(!iFace.m_idPipe.isValid())
{
XPoint ptDir;
if (DocGet)
ptDir =iFace.m_ptLocation+iFace.m_vtLocation;
dc << XLine(iFace.m_ptLocation,ptDir);
}
}
*/
if(m_bDrawLabel) // 绘制标注
DrawLabelText(dc);
return Acad::eOk;
}
Acad::ErrorStatus TDbPool::ExplodeOrDraw3d(XExplodeDraw &dc) const
{
//求图块边缘点
AcDbBlockReference insert(GetLocation(), m_idBlock2d);
AcGeScale3d scale = GetInsert2dScale();
insert.setScaleFactors(scale);
XPoint ptHole;
AcDbExtents extents;
if(insert.geomExtentsBestFit(extents)==Acad::eOk)
{
XPoint ptMax = extents.maxPoint();
XPoint ptMin = extents.minPoint();
ptHole.x = (ptMax.x + ptMin.x)/2;
ptHole.y = (ptMax.y + ptMin.y)/2;
ptHole.z = GetLocation().z;
}
TDbRect rect2;
rect2.SetSizeX(GetSizeX());
rect2.SetSizeY(GetSizeY());
rect2.SetCenter(ptHole);
rect2.SetRotation(GetAngle());
XPoint ptLowLeft=rect2.GetLowLeft();
XPoint ptLowRight=rect2.GetLowRight();
XPoint ptUpRight=rect2.GetUpRight();
XPoint ptUpLeft=rect2.GetUpLeft();
XPoly2D poly2d2(1);
poly2d2.AppendNode(ptLowLeft);
poly2d2.AppendNode(ptLowRight);
poly2d2.AppendNode(ptUpRight);
poly2d2.AppendNode(ptUpLeft);
XVector3D vt2 = XVector3D(0,0,1);
vt2.Normalize();
// vt2 *= 1* (m_dTopBanEle - m_dBottomBanEle)*1000; cet 2011.5.27 del
// cet 2011.5.27 add
double dMeter = 1.0;
if (!DocGetCurMeterUnitDraw())
{
dMeter = 1000;
}
vt2 *= (m_dTopBanEle - m_dBottomBanEle)*dMeter;
int nNum = GetInterfaceNum();
AcDbObjectId idPipe;
XPoint pt;
for (int i = 0; i < nNum; i++)
{
TPipeInterface face;
GetInterface(i, face);
if (face.m_idPipe.isValid())
{
idPipe = face.m_idPipe;
pt = face.m_ptLocation;
break;
}
}
if (idPipe.isValid())
{
XPoint ptS, ptE;
TDbPipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (pPipe != NULL)
{
pPipe->GetStartPoint(ptS);
pPipe->GetEndPoint(ptE);
pPipe->close();
}
double dEle = m_ptLocation.z;
if (ptS.Distance2d(pt) < _DIST_SNAP)
{
dEle = ptS.z;
}
else if (ptE.Distance2d(pt) < _DIST_SNAP)
{
dEle = ptE.z;
}
AcGeVector3d vt = AcGeVector3d::kZAxis;
if (dEle >= m_dBottomBanEle * dMeter && dEle <= m_dTopBanEle * dMeter)
{
vt *= (dEle - m_dBottomBanEle * dMeter) * (-1);
}
else if (dEle < m_dBottomBanEle * dMeter && dEle < m_dTopBanEle * dMeter)
{
double dMin = m_dBottomBanEle < m_dTopBanEle ? m_dBottomBanEle: m_dTopBanEle;
vt *= (dMin * dMeter - dEle);
}
else if (dEle > m_dBottomBanEle * dMeter && dEle > m_dTopBanEle * dMeter)
{
double dMin = m_dBottomBanEle < m_dTopBanEle ? m_dBottomBanEle: m_dTopBanEle;
vt *= (dMin * dMeter - dEle);
}
AcGeMatrix3d mat;
AcGeVector3d vt2 = AcGeVector3d::kZAxis;
vt2 *= (dEle - m_ptLocation.z);
mat.setTranslation(vt2);
poly2d2.TransformBy(mat);
mat.setTranslation(vt);
poly2d2.TransformBy(mat);
}
dc.DrawBody(poly2d2, vt2);
return Acad::eOk;
}
Acad::ErrorStatus
TDbPool::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
Acad::ErrorStatus es=Acad::eOk;
if (osnapMode == AcDb::kOsModeIns || osnapMode == AcDb::kOsModeCen)
{
snapPoints.append(m_ptLocation);
}
AcDbVoidPtrArray arEnts;
AcDbVoidPtrArray arBlocks;
AcDbBlockReference *pBlock = NULL;
this->explode(arEnts);
//第一次炸碎成图块和文字
for (int j = 0; j < arEnts.length(); ++j)
{
pBlock = AcDbBlockReference::cast((AcDbEntity*)arEnts[j]);
if (pBlock != NULL)
break;
}
if (pBlock != NULL)
{
pBlock->explode(arBlocks);
for (int i = 0; i < arBlocks.length(); ++i)
{
AcDbEntity *pEnt = (AcDbEntity*)arBlocks[i];
pEnt->getOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
viewXform, snapPoints, geomIds);
}
}
es = TDbPipeNode::subGetOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
viewXform, snapPoints, geomIds);
ReleaseEntSet(arEnts);
ReleaseEntSet(arBlocks);
return es;
}
// 对st类型的接口进行重新连接
void TDbPool::UpdateLinkage(const XPoint &ptAt, TPipeSys::SysType st,
const DList<AcDbObjectId> &idPipes)
{
// 更新接口 cet 2011.11.10 add
std::vector<AcDbObjectId> vecId;
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
if (m_lstInterface[i]->m_idPipe.isValid() && !m_lstInterface[i]->m_idPipe.isErased())
{
if (!CanLinkSide(m_lstInterface[i]->m_idPipe, 0) && !CanLinkSide(m_lstInterface[i]->m_idPipe, 1))
{
m_lstInterface[i]->m_idPipe.setNull();
}
}
}
XPoint ptFit;
for (int j = 0; j < idPipes.Length(); ++j)
{
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
OPENOBJ_BEGIN(idPipes[j], AcDb::kForRead, TDbPipePrototype, pPipe);
if (pPipe != NULL)
{
ptFit = GetILocation(i);
XPoint ptPipeS,ptPipeE;
ptPipeS = pPipe->StartPoint();
ptPipeE = pPipe->EndPoint();
ptPipeS.z = 0;
ptPipeE.z = 0;
ptFit.z = 0;
AcGeVector3d vtDir1 = ptFit - ptPipeE;
AcGeVector3d vtDir2 = ptFit - ptPipeS;
//判断连接点是否有管子
if (vtDir1.isParallelTo(vtDir2) || vtDir1.isZeroLength() || vtDir2.isZeroLength())
{
if (ptFit.Distance(ptPipeS) <= ptPipeE.Distance(ptPipeS)
&& ptFit.Distance(ptPipeE) <= ptPipeS.Distance(ptPipeE))
{
TPipeInterface &iFace = *m_lstInterface[i];
iFace.m_sysType = pPipe->GetSysType();
iFace.m_idPipe = pPipe->objectId();
iFace.m_faceType = TPipeInterface::kNodeLocation;
break;
}
}
else
{
XLine line(pPipe->GetStartPoint(),pPipe->GetEndPoint(), LS_FINITE); // cet 2013.3.6 modify 保证在直线内计算
//求得炸碎的实体
AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > arSegs;
GetExplodeCurves(this,arSegs); //sr modify : GetExplodeCurves(this,arSegs); 091109
//判断是否连接
XPoint ptCon;
BOOL bRet1 = CheckIsConnect(pPipe->StartPoint(),arSegs,line,ptCon);
BOOL bRet2 = CheckIsConnect(pPipe->EndPoint(),arSegs,line,ptCon);
if (bRet1 || bRet2)
{
// cet 2016.4.27 modify 先查找管道是否已存在接口点,不存在时,使用空闲接口
// int nIndex = GetFreeInterfaceIndex();
int nIndex = -1;
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
if (m_lstInterface[i]->m_idPipe.isValid() && m_lstInterface[i]->m_idPipe == pPipe->id())
{
nIndex = i;
break;
}
}
if (nIndex < 0)
{
nIndex = GetFreeInterfaceIndex();
}
if (nIndex < 0)
{
//没有空闲的接口则增加新的接口
if (!FindInterfaceByPt(ptCon))
{
// cet 2016.4.27 modify 接口从1开始查找未使用的序号
// CString sCount;
// sCount.Format(_T("%d"),m_lstInterface.Length()+1);
// AddInterface(sCount,ptCon,m_vtDirection);
std::set<CString> setIndex;
CString sLabel;
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
const TPipeInterface& iFace= GetInterface(i);
sLabel = TString(iFace.m_sSysLabel);
setIndex.insert(sLabel);
}
int nNum = 1;
CString sCount;
sCount.Format(_T("%d"), nNum);
while(setIndex.count(sCount) != 0)
{
++nNum;
sCount.Format(_T("%d"), nNum);
}
AddInterface(sCount,ptCon,m_vtDirection);
FindInterface(sCount)->m_idPipe = pPipe->objectId();
FindInterface(sCount)->m_sysType = pPipe->GetSysType();
FindInterface(sCount)->m_faceType = TPipeInterface::kNodeLocation;
}
}
else
{
//移动空闲接口到合适位置
m_lstInterface[nIndex]->m_idPipe = pPipe->objectId();
m_lstInterface[nIndex]->m_sysType = pPipe->GetSysType();
m_lstInterface[nIndex]->m_faceType = TPipeInterface::kNodeLocation;
m_lstInterface[nIndex]->m_ptLocation = ptCon;
}
break;
}
}
}
OPENOBJ_END();
}
}
}
// 判断节点是否可以连接管段. nPos: 0--start; 1--end
BOOL TDbPool::CanLinkSide(const AcDbObjectId &idPipe, int nPos) const
{
BOOL bRet=FALSE;
/*
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
if(pPipe) {
XPoint ptRef = nPos? pPipe->EndPoint() : pPipe->StartPoint();
ptRef.z = 0;
XPoint ptLoc=GetLocation();
ptLoc.z = 0;
// if(ptRef.Distance(ptLoc)<PS_SNAP)
// bRet = TRUE;
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
XPoint ptFit = GetILocation(i);
ptFit.z = 0;
if (ptRef.Distance(ptFit)<PS_SNAP)
bRet = TRUE;
}
}
OPENOBJ_END();
*/
//得到管线
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
if(pPipe)
{
XPoint ptRef = nPos? pPipe->EndPoint() : pPipe->StartPoint();
ptRef.z = 0;
XLine line(pPipe->GetStartPoint(),pPipe->GetEndPoint());
//求得炸碎的实体
AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > arSegs;
GetExplodeCurves(this->objectId(),arSegs);
//判断是否连接
XPoint ptCon;
bRet = CheckIsConnect(ptRef,arSegs,line,ptCon);
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
XPoint ptFit = GetILocation(i);
ptFit.z = 0;
if (ptRef.Distance(ptFit)<PS_SNAP)
bRet = TRUE;
}
}
OPENOBJ_END();
return bRet;
}
Acad::ErrorStatus TDbPool::subTransformBy(const AcGeMatrix3d& xform)
{
THDbEquipment::subTransformBy(xform);
return Acad::eOk;
}
//长度
void TDbPool::SetPoolLength(double dLen, BOOL bApply)
{
assertWriteEnabled();
SetSize(dLen,GetSizeY(),GetSizeZ(),bApply);
}
//宽度
void TDbPool::SetPoolWidth(double dWidth, BOOL bApply)
{
assertWriteEnabled();
SetSize(GetSizeX(),dWidth,GetSizeZ(),bApply);
}
//高度
void TDbPool::SetPoolHeight(double dHeight, BOOL bApply)
{
assertWriteEnabled();
SetSize(GetSizeX(),GetSizeY(),dHeight,bApply);
}
//顶板标高
void TDbPool::SetTopBanEle(double dEle)
{
assertWriteEnabled();
m_dTopBanEle = dEle;
}
//底板标高
void TDbPool::SetBottomBanEle(double dEle)
{
assertWriteEnabled();
m_dBottomBanEle = dEle;
}
//地面标高
void TDbPool::SetGroundEle(double dEle)
{
assertWriteEnabled();
m_dGroundEle = dEle;
}
//设备属性
double TDbPool::GetPoolLength()
{
return GetSizeX();
}
double TDbPool::GetPoolWidth()
{
return GetSizeY();
}
double TDbPool::GetPoolHeight()
{
return GetSizeZ();
}
//标高属性
double TDbPool::GetTopBanEle()
{
return m_dTopBanEle;
}
double TDbPool::GetBottomBanEle()
{
return m_dBottomBanEle;
}
double TDbPool::GetGroundEle()
{
return m_dGroundEle;
}
void TDbPool::SetSize(double x, double y, double z, BOOL bApply)
{
assertWriteEnabled();
double dOldAng = GetAngle();
SetAngle(0.0);
THDbEquipment::SetSize(x,y,z,bApply);
SetAngle(dOldAng);
SetLabelOut(GetLabelLocation());
m_bIsModify = true;
}
//更新管子位置
void TDbPool::UpdatePipes(const AcDbObjectIdArray &arIds)
{
XPoint ptFit;
//更新管子的位置
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
for (int j = 0; j < arIds.length(); ++j)
{
OPENOBJ_BEGIN(arIds[j], AcDb::kForWrite, TDbPipePrototype, pPipe);
if (pPipe != NULL)
{
ptFit = GetILocation(i);
XPoint ptPipeS,ptPipeE;
ptPipeS = pPipe->StartPoint();
ptPipeE = pPipe->EndPoint();
ptPipeS.z = 0;
ptPipeE.z = 0;
ptFit.z = 0;
AcGeVector3d vtDir1 = ptFit - ptPipeE;
AcGeVector3d vtDir2 = ptFit - ptPipeS;
if (vtDir1.isParallelTo(vtDir2) || vtDir1.isZeroLength() || vtDir2.isZeroLength())
{
if (ptFit.Distance(ptPipeS) <= ptPipeE.Distance(ptPipeS)
&& ptFit.Distance(ptPipeE) <= ptPipeS.Distance(ptPipeE))
{
//导线过长需要裁剪
if (ptPipeS.Distance(m_ptLocation) < ptPipeE.Distance(m_ptLocation))
{
ptFit.z = pPipe->StartPoint().z;
pPipe->SetStartPoint(ptFit);
}
else
{
ptFit.z = pPipe->EndPoint().z;
pPipe->SetEndPoint(ptFit);
}
TPipeInterface &iFace = *m_lstInterface[i];
iFace.m_sysType = pPipe->GetSysType();
iFace.m_idPipe = pPipe->objectId();
iFace.m_faceType = TPipeInterface::kNodeLocation;
}
else
{
//导线过短,需要补上
XPoint ptLocation = GetLocation();
ptLocation.z = 0;
AcGeVector3d vt = ptLocation - ptFit;
AcGeVector3d vt1 = ptLocation - ptPipeS;
AcGeVector3d vt2 = ptLocation - ptPipeE;
if (vt.angleTo(vt1) < PI/2 || vt.angleTo(vt2) < PI/2)
{
if (ptPipeS.Distance(m_ptLocation) < ptPipeE.Distance(m_ptLocation))
{
ptFit.z = pPipe->StartPoint().z;
pPipe->SetStartPoint(ptFit);
}
else
{
ptFit.z = pPipe->EndPoint().z;
pPipe->SetEndPoint(ptFit);
}
TPipeInterface &iFace = *m_lstInterface[i];
iFace.m_sysType = pPipe->GetSysType();
iFace.m_idPipe = pPipe->objectId();
iFace.m_faceType = TPipeInterface::kNodeLocation;
}
}
}
else
{
if (m_lstInterface[i]->m_idPipe == pPipe->objectId())
{
if (ptPipeS.Distance(m_ptLocation) < ptPipeE.Distance(m_ptLocation))
{
ptFit.z = pPipe->StartPoint().z;
pPipe->SetStartPoint(ptFit);
}
else
{
ptFit.z = pPipe->EndPoint().z;
pPipe->SetEndPoint(ptFit);
}
}
}
}
OPENOBJ_END();
}
}
}
//更新接口关系
void TDbPool::UpdataPipeInterface()
{
assertWriteEnabled();
AcDbObjectIdArray arIds;
int nFind = 0;
for (int k = 0; k < m_lstInterface.Length(); ++k)
{
if (m_lstInterface[k]->m_idPipe.isValid())
{
if (!arIds.find(m_lstInterface[k]->m_idPipe,nFind))
arIds.append(m_lstInterface[k]->m_idPipe);
}
}
UpdatePipes(arIds);
}
Acad::ErrorStatus
TDbPool::MoveGSPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AcGeMatrix3d mat;
mat.setToTranslation(offset);
BOOL bOutLabel=IsOutLabel();
int nNodeGrip=TDbPipeNode::GetGripNumber();
int nThisGrip=GetGripNumber();
int nCount = indices.length();
for(int i=0; i<nCount;i++) {
if(indices[i]>=nThisGrip)
continue;
if(indices[i]==nNodeGrip){
m_ptLocation.TransformBy(mat);
m_ptLabel.TransformBy(mat);
m_ptLabelOut.TransformBy(mat);
m_bIsModify = true; // zxl 2013.09.29 add
for(int j=0; j<m_lstInterface.Length(); j++) {
TPipeInterface &iFace=*m_lstInterface[j];
iFace.m_ptLocation.TransformBy(mat);
}
break;
}
else if(indices[i]==nNodeGrip+1) {
if(!bOutLabel) {
m_ptLabel.TransformBy(mat);
m_ptLabelOut.TransformBy(mat);
} else
m_ptLabel.TransformBy(mat);
}
else if(IsOutLabel() && indices[i]==nNodeGrip+2) {
m_ptLabelOut.TransformBy(mat);
}
}
if(m_ptLabel==m_ptLocation)
m_ptLabelOut = m_ptLocation;
return Acad::eOk;
}
//zxl 2013.07.23 add 池子大小或位置变化时,调整池子标注位置
void TDbPool::ModifyPoolDimPos(const TPipeInterface iFace)
{
AcDbBlockTableRecord *pRecord = NULL;
AcDbBlockTable* pBlockTable = NULL;
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
if(pBlockTable == NULL)
return;
if(Acad::eOk != pBlockTable->getAt(ACDB_MODEL_SPACE, pRecord, AcDb::kForRead))
{
pBlockTable->close();
return;
}
pBlockTable->close();
AcDbBlockTableRecordIterator *pIterator = NULL;
pRecord->newIterator(pIterator);
pRecord->close();
AcDbEntity *pEnt = NULL;
TDbWellDim *pDim = NULL;
for(pIterator->start(); !pIterator->done(); pIterator->step())
{
pIterator->getEntity(pEnt, AcDb::kForRead);
if (pEnt != NULL)
{
pDim = TDbWellDim::cast(pEnt);
if(pDim != NULL && pDim->GetIsNewDim() && pDim->GetPipeId() == iFace.m_idPipe && pDim->GetWellId() == id())
{
XPoint ptLoc = iFace.m_ptLocation;
if (pDim->upgradeOpen() == Acad::eOk)
{
AcGeVector3d vt = ptLoc - pDim->GetStartPoint();
pDim->SetStartPoint(ptLoc);
XPoint ptTurn = pDim->GetTurnPoint() + vt;
pDim->SetTurnPoint(ptTurn);
pDim->downgradeOpen();
}
}
pEnt->close();
}
}
delete pIterator;
}
TSubText* TDbPool::HitTestText(XPoint pt) const
{
return THDbEquipment::HitTestText(pt);
}
void TDbPool::SetSubText(long i, CString sText)
{
SetLabel(sText);
}
//zxl 2013.07.23 add
Acad::ErrorStatus TDbPool::subClose()
{
Acad::ErrorStatus es = THDbEquipment::subClose();
if (es != Acad::eOk)
{
return es;
}
if(m_bIsModify && !IsTransformCmd())
{
m_bIsModify = false;
if(isModified() && database()==acdbCurDwg())
{
int nCount = m_lstInterface.Length();
for (int i=0; i<nCount; i++)
{
TPipeInterface &iFace = *m_lstInterface[i];
ModifyPoolDimPos(iFace);
}
}
}
return es;
}
Acad::ErrorStatus TDbPool::DrawLabelText(XExplodeDraw &dc) const
{
AcDbObjectId idLayerOld=dc.GetLayerId();
if(m_idLabelLayer.isValid())
dc.SetLayer(m_idLabelLayer);
TDbMText text;
text.setPropertiesFrom(this);
text.setLayer(m_idLabelLayer);
text.setColorIndex(GetTextColor()); // cet 2018.2.6 add 可修改文字颜色
text.SetStyleId(m_idTextStyle);
text.SetText((const TCHAR*)m_sLabel);
text.SetHeight(m_dTextHeight);
text.SetAlignment(XExplodeDraw::kLeft);
text.SetLineSpace(0.4*m_dTextHeight);
text.SetPageWidth(200*m_dTextHeight/3.5);
AcDbExtents extents;
if(text.getGeomExtents(extents)==Acad::eOk) {
XPoint ptMin=extents.minPoint();
XPoint ptMax=extents.maxPoint();
double x=ptMax.x-ptMin.x;
double y=ptMax.y-ptMin.y;
XPoint ptLabel=m_ptLabel;
ptLabel.z=0;
if(IsOutLabel()) { // 引出标注
double dDist = GetPScale()*m_dTextHeight/3;
XPoint ptMid(ptLabel.x+dDist,ptLabel.y+y+dDist,0);
text.SetLocation(ptMid);
XPoint ptLabelOut=m_ptLabelOut;
ptLabelOut.z=0;
XPoint ptLabel2(ptLabel.x+x+2*dDist,ptLabel.y,0);
dc << XLine(ptLabel,ptLabel2)
<< XLine(ptLabel,ptLabelOut);
} else { // 非引出标注
double dAngle=GetTextRotation();
XPoint ptMid=ptLabel;
ptMid.x -= x/2;
ptMid.y += y/2;
ads_matrix mat;
ptLabel.GetRotationMatrix(dAngle,mat);
ptMid.TransformBy(mat);
text.SetRotation(dAngle);
text.SetLocation(ptMid);
}
dc.DrawEntity(text);
}
double dDD = GetLayoutRotation();
dc.SetLayer(idLayerOld);
return Acad::eOk;
}
//得到炸碎的实体
void TDbPool::GetExplodeCurves(const AcDbObjectId &id,AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > &arCurves) const
{
AcDbVoidPtrArray arEnts;
AcDbVoidPtrArray arBlocks;
AcDbBlockReference *pBlock = NULL;
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbEntity, pEntPool);
if (pEntPool != NULL)
{
//第一次炸碎成图块和文字
pEntPool->explode(arEnts);
for (int j = 0; j < arEnts.length(); ++j)
{
pBlock = AcDbBlockReference::cast((AcDbEntity*)arEnts[j]);
if (pBlock != NULL)
break;
}
//第二次炸开图块
if (pBlock != NULL)
{
pBlock->explode(arBlocks);
for (int i =0; i < arBlocks.length(); ++i)
{
AcDbEntity *pEnt = (AcDbEntity*)arBlocks[i];
if (pEnt != NULL)
{
AcDbLine *pLine = NULL;
AcDbArc *pArc = NULL;
AcDbCircle *pCir = NULL;
XCurveSegment seg;
if(pLine = AcDbLine::cast(pEnt)){
XLine line(XPoint(pLine->startPoint()), XPoint(pLine->endPoint()));
seg = line;
arCurves.append(seg);
// break;
}
else if(pArc = AcDbArc::cast(pEnt)){
AcGePoint3d ptStart, ptEnd;
pArc->getStartPoint(ptStart);
pArc->getEndPoint(ptEnd);
double dAng(0), dLen(0);
pArc->getDistAtPoint(ptEnd, dLen);
dAng = dLen / pArc->radius();
XArc arc(XPoint(ptStart), XPoint(ptStart), dAng);
seg = arc;
arCurves.append(seg);
}
else if(pCir = AcDbCircle::cast(pEnt)){
AcGePoint3d ptCen = pCir->center();
XCircle cir(XPoint(ptCen), pCir->radius());
seg = cir;
arCurves.append(seg);
}
//sr 091109 del
// AcDbObjectId idT = AddToCurrentSpace(pEnt,Adesk::kTrue);
// ads_name ent;
// if (acdbGetAdsName(ent,idT) == Acad::eOk)
// {
// Entity entSeg(ent);
// XCurveSegment seg(entSeg);
// arCurves.append(seg);
//
// if (!!entSeg)
// entSeg.Erase();
// }
}
}
}
}
OPENOBJ_END();
ReleaseEntSet(arBlocks);//SR MODIFY 091109
ReleaseEntSet(arEnts);//SR MODIFY 091109
//释放炸开后的内存
// while (arEnts.length() > 0)
// {
// delete (AcRxObject*)arEnts[0];
// arEnts.removeFirst();
// }
}
// sr 091109 del
void TDbPool::GetExplodeCurves(AcDbEntity *pEnt,AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > &arCurves) const
{
if (pEnt != NULL)
{
AcDbVoidPtrArray arEnts;
AcDbVoidPtrArray arBlocks;
AcDbBlockReference *pBlock = NULL;
//第一次炸碎成图块和文字
pEnt->explode(arEnts);
for (int j = 0; j < arEnts.length(); ++j)
{
pBlock = AcDbBlockReference::cast((AcDbEntity*)arEnts[j]);
if (pBlock != NULL)
break;
}
//第二次炸开图块
if (pBlock != NULL)
{
pBlock->explode(arBlocks);
for (int i =0; i < arBlocks.length(); ++i)
{
AcDbEntity *pEnt = (AcDbEntity*)arBlocks[i];
if (pEnt != NULL)
{
AcDbLine *pLine = NULL;
AcDbArc *pArc = NULL;
AcDbCircle *pCir = NULL;
XCurveSegment seg;
if(pLine = AcDbLine::cast(pEnt)){
XLine line(XPoint(pLine->startPoint()), XPoint(pLine->endPoint()));
seg = line;
arCurves.append(seg);
}
else if(pArc = AcDbArc::cast(pEnt)){
AcGePoint3d ptStart, ptEnd;
pArc->getStartPoint(ptStart);
pArc->getEndPoint(ptEnd);
double dAng(0), dLen(0);
pArc->getDistAtPoint(ptEnd, dLen);
dAng = dLen / pArc->radius();
XArc arc(XPoint(ptStart), XPoint(ptStart), dAng);
seg = arc;
arCurves.append(seg);
}
else if(pCir = AcDbCircle::cast(pEnt)){
AcGePoint3d ptCen = pCir->center();
XCircle cir(XPoint(ptCen), pCir->radius());
seg = cir;
arCurves.append(seg);
}
// AcDbObjectId idT = AddToCurrentSpace(pEnt,Adesk::kTrue);
// ads_name ent;
// if (acdbGetAdsName(ent,idT) == Acad::eOk)
// {
// Entity entSeg(ent);
// XCurveSegment seg(entSeg);
// arCurves.append(seg);
//
// if (!!entSeg)
// entSeg.Erase();
// }
}
}
}
ReleaseEntSet(arBlocks);//SR MODIFY 091109
ReleaseEntSet(arEnts);//SR MODIFY 091109
//释放炸开后的内存
// while (arEnts.length() > 0)
// {
// delete (AcRxObject*)arEnts[0];
// arEnts.removeFirst();
// }
}
}
//判断是否连接
BOOL TDbPool::CheckIsConnect(const XPoint &pt,const AcArray<XCurveSegment, AcArrayObjectCopyReallocator<XCurveSegment> > &arSegs,const XLine &line,XPoint &ptCon) const
{
BOOL bTrue = FALSE;
XCurveSegment seg;
XPoint pt1,pt2;
//找到管线与实体交点,并判断交点是否在实体表面
for (int i = 0; i < arSegs.length(); ++i)
{
seg = arSegs[i];
seg.SetLineFlag(LS_FINITE); // cet 2013.3.6 add 不在seg延长线上求交,保证交点在池子上
if (seg.Intersection(line,pt1,pt2) == 1)
{
if (pt1.Distance2d(pt) < 1E-3)
{
bTrue = TRUE;
ptCon = pt1;
break;
}
}
}
return bTrue;
}
//得到空闲的接口序号
int TDbPool::GetFreeInterfaceIndex() const
{
int nIndex = -1;
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
if (!m_lstInterface[i].m_idPipe.isValid() || m_lstInterface[i].m_idPipe.isErased())
{
nIndex = i;
break;
}
else
{
OPENOBJ_BEGIN(m_lstInterface[i].m_idPipe, AcDb::kForRead, TDbPipePrototype, pPipe);
if(pPipe)
{
if (pPipe->StartPoint().Distance2d(m_lstInterface[i].m_ptLocation) > 1e-3
&& pPipe->EndPoint().Distance2d(m_lstInterface[i].m_ptLocation) > 1e-3)
{
nIndex = i;
break;
}
}
OPENOBJ_END();
}
}
return nIndex;
}
Acad::ErrorStatus TDbPool::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es=Acad::eOk;
CString sDes;
if(idx>=0 && idx<m_lstInterface.Length())
{
const TPipeInterface& iFace=m_lstInterface[idx];
CString csLabel = TString(iFace.m_sSysLabel).cs(); // sg modify
cs = _T("接口") + csLabel;
if (iFace.m_idPipe.isValid() && !iFace.m_idPipe.isErased())
sDes = _T("(已连接管线)");
else
sDes = _T("(无管连接)");
cs += sDes;
}
int nNodeGrip=TDbPipeNode::GetGripNumber();
if(idx>=nNodeGrip && idx<GetGripNumber()) {
if(idx==nNodeGrip)
cs=_T("移动设备");
else if(idx==nNodeGrip+1)
cs=_T("移动标注点");
else if(IsOutLabel() && idx==nNodeGrip+2)
cs = _T("移动引注点");
}
return es;
}
//是否找到接口
bool TDbPool::FindInterfaceByPt(const AcGePoint3d &pt)
{
bool bFind = FALSE;
for (int i = 0; i < m_lstInterface.Length(); ++i)
{
if (pt.distanceTo(m_lstInterface[i]->m_ptLocation) < 1e-3)
{
bFind = true;
break;
}
}
return bFind;
}
CString TDbPool::GetName(bool *pRet) const
{
const TEntityFields &fd = GetFields();
CString sName;
bool bRet = fd.GFD(_T("POOL_NAME"), sName);
if (pRet != NULL)
{
*pRet = bRet; // 是否设置了名称
}
return sName;
}
void TDbPool::SetName(const CString &sName)
{
assertWriteEnabled();
TEntityFields &fd = Fields();
fd.SFD(_T("POOL_NAME"), sName);
}