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

949 lines
28 KiB
C++

// SSearchPipeList.cpp: implementation of the SSearchPipeList class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "tapi.h"
#include <dbpipe.h>
#include <dbequipment.h>
#include <dbPipeValve.h>
#include <DbPipeLabel.h>
#include <DbWELL.h>
#include <DbPool.h>
#include "SSearchPipeList.h"
#include "twtdef.h"
#include "xtext.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CString I2Str(double i)
{
CString csText;
i = i/1000;
int iTmp = int(i * 1000) * 10;
int iTmp2 = int(i * 10000);
if(iTmp == iTmp2){
iTmp = int(i * 100) * 10;
iTmp2 = int(i * 1000);
if(iTmp == iTmp2)
csText.Format(_T("%.2f"), i);
else
csText.Format(_T("%.3f"), i);
}
else
csText.Format(_T("%.4f"), i);
return csText;
}
double GetPipeGradient(Entity ent)
{
double nGradient(0);
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe && !pPipe->IsVertical()){
nGradient = pPipe->GetPipeGradient();
if(nGradient > 10) //sr 2011-1-26 从大于1改为大于10,坡度还是有大于1的,但几乎没有大于10的。GetPipeGradient调的是小圆半径的值
nGradient = 0;
}
OPENOBJ_END();
return nGradient;
}
CString GetWellName(AcDbObjectId id)
{
CString csWellName;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWell, pEquip);
if(pEquip){
csWellName = pEquip->GetWellName();
}
OPENOBJ_END();
return csWellName;
}
CString GetWellName(Entity ent)
{
CString csWellName;
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWell, pEquip);
if(pEquip){
csWellName = pEquip->GetWellName();
}
OPENOBJ_END();
return csWellName;
}
//差值法 小的值 大的值 小的范围 大的范围 原范围
double GetValBetween2(double n1, double n2, double nRange1, double nRange2, double nFactor)
{
if(n1 < 0 || n2 < 0)
return -1;
double nSmall = nRange1 < nRange2 ? nRange1 : nRange2;
nRange1 = fabs(nRange1 - nRange2);
nSmall = nFactor - nSmall;
nSmall = nSmall/nRange1;
double nRet = n1 < n2 ? n1 : n2;
nRet = nRet + fabs(n1 - n2)*nSmall;
return nRet;
}
BOOL IsAppandEquip(DList<AcDbObjectId> &lstNode, AcDbObjectId id)
{
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
if(!pEquip){
return FALSE;
}
OPENOBJ_END();
int len = lstNode.Length();
int Index = -1;
for(int j=0;j<len;j++){
AcDbObjectId idTmp = *lstNode[j];
if(idTmp == id) {
Index = j;
break;
}
}
if(Index < 0){
lstNode.Append(new AcDbObjectId(id));
return TRUE;
}
return FALSE;
}
Entity GetEquipmentByPt(XPoint &pt, int nSnap, const TCHAR* szLayer)
{
RBList rbMaskPipe(RTDXF0, _T("ATS_EQUIPMENT"), 8, szLayer, NULL);
PickSet ss(SS_FREE);
XPoint ptUcs = Wcs2Ucs(pt);
GetPointPickSet(ptUcs, ss, rbMaskPipe, nSnap);
long len = ss.Length();
if(ss.Length() != 1)
return Entity();
Entity entPipe = ss[0L];
BOOL bFlag = FALSE;
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
pt = pEquip->GetLocation();
OPENOBJ_END();
return entPipe;
}
CString GetEquipBlkName(Entity ent)
{
CString csRet;
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip){
const TCHAR *szBlkName = NULL;
AcDbObjectId eqId = pEquip->GetBlock2d();
OPENOBJ_BEGIN(eqId, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord)
pRecord->getName(szBlkName);
OPENOBJ_END();
csRet = szBlkName;
}
OPENOBJ_END();
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipeValve, pValve);
if(pValve){
const TCHAR *szBlkName = NULL;
AcDbObjectId eqId = pValve->GetBlock2d();
OPENOBJ_BEGIN(eqId, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord)
pRecord->getName(szBlkName);
OPENOBJ_END();
csRet = szBlkName;
}
OPENOBJ_END();
if(ent.Is(_T("INSERT"))){
TCHAR szBlkName[256];
ent.GetData(2, szBlkName);
csRet = szBlkName;
}
return csRet;
}
BOOL GetEquipNameById(AcDbObjectId id, CString &csBlkName, CString &csDesName, int &iItem)
{
CString sDwbPath = g_sDwbPath;
csBlkName = _T("");
if(IsEquipment(id)){
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip){
const TCHAR *szBlkName = NULL;
AcDbObjectId eqId = pEquip->GetBlock2d();
OPENOBJ_BEGIN(eqId, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord)
pRecord->getName(szBlkName);
OPENOBJ_END();
csBlkName = szBlkName;
// if(csBlkName.Find(_T("00000132")) > -1) //sr del 2012-9-19 不记得当初为什么加这个过滤
// return FALSE;
if(_tcsicmp(csBlkName, _T("$TwtSys$00000434")) == 0){ // 单消火栓 正方形单一比例
XString xsTmp7;
CString csDwb = sDwbPath + _T("Twtsys");
if(LoadDwbBlock(csDwb, _T("00000427"), xsTmp7) != RTNORM) //标准比例
return FALSE;
csBlkName = xsTmp7;
}
else if(_tcsicmp(csBlkName, _T("$TwtSys$00000435")) == 0){// 双消火栓 正方形单一比例
XString xsTmp7;
CString csDwb = sDwbPath + _T("Twtsys");
if(LoadDwbBlock(csDwb, _T("00000421"), xsTmp7) != RTNORM) //标准比例
return FALSE;
csBlkName = xsTmp7;
}
CString csTKName, csRocord;
//以下图块显示系统图块
if(_tcsicmp(csBlkName, _T("$TwtSys$00000225")) == 0 || // 给水点
_tcsicmp(csBlkName, _T("$TwtSys$00000172")) == 0 || // 淋浴头
_tcsicmp(csBlkName, _T("$TwtSys$00000125")) == 0) // 喷淋头
{
csBlkName = pEquip->GetSysBlock();
XString xsTmp;
if(LoadDwbBlock(csBlkName, xsTmp) != RTNORM)
return TRUE;
csBlkName = xsTmp;
}
if(_tcsicmp(szBlkName, _T("$TwtSys$00000125")) == 0){// 喷淋头
if(pEquip->IsHidePipe()){
csDesName = _T("直立型喷头");
XString xsTmp;
if(LoadDwbBlock(_T("TwtSys(00000443)"), xsTmp) != RTNORM)
return TRUE;
csBlkName = xsTmp;
}
else
csDesName = _T("下垂型喷头");
iItem = 2;
return TRUE;
}
else if(_tcsicmp(szBlkName, _T("$TwtSys$00000128")) == 0){
csDesName = _T("上下喷头");
XString xsTmp;
if(LoadDwbBlock(_T("TwtSys(00000444)"), xsTmp) != RTNORM)
return TRUE;
csBlkName = xsTmp;
iItem = 2;
return TRUE;
}
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000529")) == 0) // cet 2014.9.17 add 水喷雾喷头
{
csDesName = _T("水喷雾喷头");
iItem = 2;
return TRUE;
}
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000540")) == 0) // cet 2014.9.17 add 直立型水幕喷头
{
csDesName = _T("直立型水幕喷头");
iItem = 2;
return TRUE;
}
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000541")) == 0) // cet 2014.9.17 add 下垂型水幕喷头
{
csDesName = _T("下垂型水幕喷头");
iItem = 2;
return TRUE;
}
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000129")) == 0) // cet 2014.9.17 add 侧墙喷头
{
csDesName = _T("侧墙喷头");
iItem = 2;
return TRUE;
}
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000131")) == 0) // cet 2014.9.17 add 侧喷喷头
{
csDesName = _T("侧喷喷头");
iItem = 2;
return TRUE;
}
if(csBlkName.Find(_T("$")) > -1){
SplitBlkStr(csBlkName, csTKName, csRocord);
csTKName = sDwbPath + csTKName + _T(".tk");
csDesName = GetBlkDesName((const TCHAR*)csRocord, (const TCHAR*)csTKName);
}
//描述名中有(打断)或-000000283, 不需要给用户提供
int idx = csDesName.Find(_T("-"));
if(idx > 0){
csDesName = csDesName.Left(idx);
}
int idx2 = csDesName.Find(_T("("));
if(idx2 > 0){
csDesName = csDesName.Left(idx2);
}
iItem = 2;
if(csBlkName != _T(""))
return TRUE;
}
OPENOBJ_END();
}
else{
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeNode, pNode);
if(pNode){
int num = pNode->GetInterfaceNum();
iItem = 3;
if(num == 1)
csDesName = _T("堵头");
else if(num == 2){
TPipeInterface face1;
pNode->GetInterface(0, face1);
AcDbObjectId nextPipeId = face1.m_idPipe;
AcGeVector3d vt1, vt2;
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
XPoint ptS = pPipe->StartPoint();
XPoint ptE = pPipe->EndPoint();
vt1 = AcGeVector3d(ptE.x - ptS.x, ptE.y - ptS.y, ptE.z - ptS.z);
}
OPENOBJ_END();
TPipeInterface face2;
pNode->GetInterface(1, face2);
nextPipeId = face2.m_idPipe;
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
XPoint ptS = pPipe->StartPoint();
XPoint ptE = pPipe->EndPoint();
vt2 = AcGeVector3d(ptE.x - ptS.x, ptE.y - ptS.y, ptE.z - ptS.z);
}
OPENOBJ_END();
if(vt1.isParallelTo(vt2) == Adesk::kTrue)
csDesName = _T("变径");
else
csDesName = _T("弯头");
}
else if(num == 3)
csDesName = _T("三通");
else if(num == 4)
csDesName = _T("四通");
else
return FALSE;
return TRUE;
}
OPENOBJ_END();
}
return FALSE;
}
BOOL IsEquipment(AcDbObjectId id)
{
BOOL ret = FALSE;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
ret = TRUE;
OPENOBJ_END();
return ret;
}
BOOL IsValve(AcDbObjectId id)
{
BOOL ret = FALSE;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeValve, pEquip);
if(pEquip)
ret = TRUE;
OPENOBJ_END();
return ret;
}
BOOL IsPipeLabel(AcDbObjectId id)
{
BOOL ret = FALSE;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeLabel, pLabel);
if(pLabel)
ret = TRUE;
OPENOBJ_END();
return ret;
}
BOOL IsWell(AcDbObjectId id)
{
CString csDesName, csBlkName;
int iItem;
GetEquipNameById(id, csBlkName, csDesName, iItem);
if(csDesName.Find(_T("井")) < 0)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWell, pEquip);
if(pEquip){
CString csName = pEquip->GetWellName();
if(csName != _T(""))
return TRUE;
}
OPENOBJ_END();
return FALSE;
}
void GetAllPipeAndNodeByNode(AcDbObjectId nodeId, AcDbObjectId idFront, PickSet &ss)
{
OPENOBJ_BEGIN(nodeId, AcDb::kForRead, TDbPipeNode, pNode);
if(pNode){
int num = pNode->GetInterfaceNum();
for(int i=0;i<num;i++){
TPipeInterface face;
pNode->GetInterface(i, face);
AcDbObjectId nextPipeId = face.m_idPipe;
if(nextPipeId == NULL)
continue;
// OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, pPipe);
// if(pPipe){
// if(pPipe->Length() < pPipe->GetPScale()/20)
// continue;
// }
// OPENOBJ_END();// 沈睿 remove it 2008-3-3 【喷淋管径】有时候有特短的管线
if(idFront == nextPipeId)
continue;
ss += nextPipeId;
int len = ss.Length();
}
}
OPENOBJ_END();
}
void GetAllPipeAndNodeByPipe(AcDbObjectId pipeId, AcDbObjectId idFront, PickSet &ss)
{
Entity entFront;
OPENOBJ_BEGIN(pipeId, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
AcDbObjectId nodeId1(NULL), nodeId2(NULL);
nodeId1 = pPipe->GetNode(0);
nodeId2 = pPipe->GetNode(1);
if(idFront != nodeId1 && !!nodeId1){
ss += nodeId1;
}
if(idFront != nodeId2 && !!nodeId2){
ss += nodeId2;
}
int len = ss.Length();
}
OPENOBJ_END();
return;
}
BOOL IsSprinkler(Entity ent)
{
if(!ent)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
XString xsTmp1 = _T("$twtsys$00000125");
XString xsTmp2 = _T("$twtsys$00000128");
XString xsTmp3 = _T("$twtsys$00000129");
XString xsTmp4 = _T("$twtsys$00000131");
XString xsTmp5 = _T("$twtsys$00000283");
XString xsTmp6 = _T("$twtsys$00000126");
XString xsTmp7 = _T("$twtsys$00000130");
XString xsTmp8 = _T("$twtsys$00000529");
XString xsTmp9 = _T("$twtsys$00000540"); //CET 2012-1-6 ADD
XString xsTmp10 = _T("$twtsys$00000541");
XString xsTmp11 = _T("$twtsys$00000542");
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 ||
_tcsicmp(szBlkName, xsTmp4) == 0 || _tcsicmp(szBlkName, xsTmp3) == 0||
_tcsicmp(szBlkName, xsTmp7) == 0 ||_tcsicmp(szBlkName, xsTmp5) == 0 ||
_tcsicmp(szBlkName, xsTmp9) == 0 ||_tcsicmp(szBlkName, xsTmp10) == 0 ||_tcsicmp(szBlkName, xsTmp11) == 0 ||
_tcsicmp(szBlkName, xsTmp6) == 0 || _tcsicmp(szBlkName, xsTmp8) == 0) //是喷头
return TRUE;
else
return FALSE;
}
BOOL IsHydrant(Entity ent)
{
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
CString csTKName, csRocord;
SplitBlkStr(szBlkName, csTKName, csRocord);
CString sDwbPath = g_sDwbPath;
csTKName = sDwbPath + csTKName + _T(".tk");
CString csDesName = GetBlkDesName((const TCHAR*)csRocord, (const TCHAR*)csTKName);
if(csDesName.Find(_T("消火栓")) > -1)
return TRUE;
return FALSE;
}
BOOL IsHydrant(AcDbObjectId idNode)
{
if(!idNode)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
CString csTKName, csRocord;
SplitBlkStr(szBlkName, csTKName, csRocord);
CString sDwbPath = g_sDwbPath;
csTKName = sDwbPath + csTKName + _T(".tk");
CString csDesName = GetBlkDesName((const TCHAR*)csRocord, (const TCHAR*)csTKName);
if(csDesName.Find(_T("系统消火栓")) > -1)
return FALSE;
if(csDesName.Find(_T("室外消火栓")) > -1)
return FALSE;
if(csDesName.Find(_T("消火栓")) > -1)
return TRUE;
return FALSE;
}
BOOL IsSysSprinkler(AcDbObjectId idNode)
{
if(!idNode)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
XString xsTmp1 = _T("$twtsys$00000126");
XString xsTmp2 = _T("$twtsys$00000283");
XString xsTmp3 = _T("$twtsys$00000130");
XString xsTmp4 = _T("$twtsys$00000542"); //CET 2012-1-6 ADD
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 ||
_tcsicmp(szBlkName, xsTmp3) == 0 || _tcsicmp(szBlkName, xsTmp4) == 0) //是喷头
return TRUE;
else
return FALSE;
}
BOOL IsSprinkler(AcDbObjectId idNode)
{
if(!idNode)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
CString csTmp1 = _T("$twtsys$00000125");
CString csTmp2 = _T("$twtsys$00000128");
CString csTmp3 = _T("$twtsys$00000129");
CString csTmp4 = _T("$twtsys$00000131");
CString csTmp5 = _T("$twtsys$00000529");
CString csTmp6 = _T("$twtsys$00000540"); //CET 2012-1-6 ADD
CString csTmp7 = _T("$twtsys$00000541");
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
CString csName = szBlkName;
csName.MakeLower();
int ret1 = csName.Find(csTmp1);
int ret2 = csName.Find(csTmp2);
int ret3 = csName.Find(csTmp3);
int ret4 = csName.Find(csTmp4);
int ret5 = csName.Find(csTmp5);
int ret6 = csName.Find(csTmp6);
int ret7 = csName.Find(csTmp7);
if(ret1 > -1 || ret2 > -1 || ret3 > -1 || ret4 > -1 || ret5 > -1 || ret6 > -1 || ret7 > -1)
return TRUE;
else
return FALSE;
// if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 ||
// _tcsicmp(szBlkName, xsTmp4) == 0 || _tcsicmp(szBlkName, xsTmp3) == 0) //是喷头
// return TRUE;
// else
// return FALSE;
}
BOOL IsPlanHydrant(AcDbObjectId idNode)
{
if(!idNode)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
XString xsTmp1 = _T("$twtsys$00000386");
XString xsTmp2 = _T("$twtsys$00000383");
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0)
return TRUE;
else
return FALSE;
}
BOOL IsPool(AcDbObjectId idNode)
{
if(!idNode)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbPool, pEquip);
if(pEquip)
return TRUE;
else
return FALSE;
OPENOBJ_END();
}
BOOL IsPool_old(AcDbObjectId idNode)
{
if(!idNode)
return FALSE;
AcDbObjectId idBlk = NULL;
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip)
idBlk = pEquip->GetBlock2d();
else
return FALSE;
OPENOBJ_END();
XString xsTmp1 = _T("$twtsys$00000353");
XString xsTmp2 = _T("$twtsys$00000354");
XString xsTmp3 = _T("$twtsys$00000355");
XString xsTmp4 = _T("$twtsys$00000356");
XString xsTmp5 = _T("$twtsys$00000357");
XString xsTmp6 = _T("$twtsys$00000399");
const TCHAR *szBlkName = NULL;
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
if(pRecord){
pRecord->getName(szBlkName);
}
OPENOBJ_END();
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 || _tcsicmp(szBlkName, xsTmp5) == 0 ||
_tcsicmp(szBlkName, xsTmp4) == 0 || _tcsicmp(szBlkName, xsTmp3) == 0 || _tcsicmp(szBlkName, xsTmp6) == 0)
return TRUE;
else
return FALSE;
}
int GetNodeType(Entity ent)
{
if(ent.Is(_T("ATS_PIPE")) || ent.Is(_T("ATS_PIPECANAL")))
return 0;
else if(ent.Is(_T("ATS_WELL")))
return 3;
else if(ent.Is(_T("ATS_EQUIPMENT"))){
AcDbObjectId id = NULL;
acdbGetObjectId(id, ent);
if(IsSprinkler(id) || IsSysSprinkler(id) || IsPlanHydrant(id))
return 2;
// if(IsPool(id))
// return 4;
// else
return -1;
}
else if(ent.Is(_T("ATS_POOL")))
return 4;
else if(ent.Is(_T("ATS_PIPEFITTING")))
return 1;
else
return -1;
}
BOOL SearchSprinkPipeSys(Entity ent, AcDbObjectId idFront, SSearchPipeList *pListAll, PickSet &ssAll)
{
AcDbObjectId id = NULL;
acdbGetObjectId(id, ent);
pListAll->m_ID = id;
AcDbObjectIdArray idArray;
int len(0);
{
PickSet ss(SS_FREE);
if(ent.Is(_T("ATS_PIPE")) || ent.Is(_T("ATS_PIPECANAL")))
GetAllPipeAndNodeByPipe(id, idFront, ss);
else
GetAllPipeAndNodeByNode(id, idFront, ss);
for(long j=0;j<ss.Length();j++){
Entity entTmp = ss[j];
if(entTmp.In(&ssAll) > 0){
PickSet ssLoop(SS_FREE);
ssLoop += entTmp;
//发现有回路,一直顺着头找所有的选择集,并把他们亮显
SSearchPipeList *pNode = NULL;
if(pListAll->m_pPrevious != NULL)
pNode = pListAll->m_pPrevious;
while(pNode != NULL){
ssLoop += pNode->m_ID;
if(pNode->m_pPrevious != NULL)
pNode = pNode->m_pPrevious;
else
break;
}
ssLoop.Redraw(3);
return FALSE;
}
}
ssAll += ss;
len = ss.Length();
for(long i=0;i<ss.Length();i++){
Entity entTmp = ss[i];
AcDbObjectId idTmp = NULL;
acdbGetObjectId(idTmp, entTmp);
idArray.append(idTmp);
}
}
len = idArray.length();
for(long i=0;i<len;i++){
AcDbObjectId idTmp = idArray[i];
ads_name entTmp;
acdbGetAdsName(entTmp, idTmp);
SSearchPipeList *pList = new SSearchPipeList();
pList->m_ID = idTmp;
pList->m_iType = GetNodeType(entTmp);
pList->m_pPrevious = pListAll;
pListAll->m_lstNode.Append(pList);
if(!SearchSprinkPipeSys(entTmp, id, pList, ssAll)){
return FALSE;
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//给排水,喷淋,给水 计算
//具体本节点进行标注
BOOL DoDimSerialNumber(AcDbObjectId id, int idx)
{
InitLayer(LAY_CALC_TEXT);
InitTwtTextStyle(g_csTwtDimStyle);
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeNode, pNode);
if(pNode){
CString csText;
csText.Format(_T("%d"), idx);
XPoint pt = pNode->GetLocation();
XPoint ptText;
double nDist = DocGetPScale();
if(IsWell(id))
nDist = nDist * g_nWellRadius / 2; //如果标注井,距离就大些
ads_polar(pt, PI/2, nDist, ptText);
ads_polar(ptText, 0, nDist, ptText);
XText text(csText, ptText, g_nTwtDimHeight * DocGetPScale(), g_nDimScale, g_csTwtDimStyle, LAY_CALC_TEXT);
text.Draw();
return TRUE;
}
OPENOBJ_END();
return FALSE;
}
//管道标注
void DoDimPipeSerialNumber(SSearchPipeList *pListAll)
{
if(pListAll->m_iType == 0){
CString csNum1 = pListAll->m_pPrevious->m_csName;
if(!pListAll->m_pPrevious->m_pPrevious && csNum1 == _T(""))
csNum1 = _T("末端");
int len2 = pListAll->m_lstNode.Length();
CString csNum2;
if(len2 > 0)
csNum2 = pListAll->m_lstNode[0]->m_csName;
if(csNum1 != _T("") && csNum2 != _T(""))
pListAll->m_csName = csNum2 + _T("-") + csNum1;
}
long len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++){
SSearchPipeList *pList = pListAll->m_lstNode[i];
DoDimPipeSerialNumber(pList);
}
}
//得到最末祖先的节点编号, 为了排序
int GetAncestorSerial(SSearchPipeList *pListLast)
{
int idx(0);
if(pListLast->m_iType == 2 || pListLast->m_iType == 1){ //1:节点 2:喷头
if(pListLast->m_csName != _T("")){
idx = _ttoi(pListLast->m_csName);
return idx;
}
}
if(pListLast->m_pPrevious)
idx = GetAncestorSerial(pListLast->m_pPrevious);
return idx;
}
//得到最先祖先的节点编号, 最靠近主干管
int GetFirstAncestorSerial(SSearchPipeList *pListLast)
{
int idx(0);
if(pListLast->m_iType == 2 || pListLast->m_iType == 1){ //1:节点 2:喷头
if(pListLast->m_csName != _T("")){
idx = _ttoi(pListLast->m_csName);
if(pListLast->m_nDang == 255)
return idx;
}
}
if(pListLast->m_pPrevious)
idx = GetFirstAncestorSerial(pListLast->m_pPrevious);
return idx;
}
//计算本管线长度
void CalcPipeLength(SSearchPipeList *pListAll)
{
if(pListAll->m_iType == 0){
OPENOBJ_BEGIN(pListAll->m_ID, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
pListAll->m_nLength = pPipe->Length();
}
OPENOBJ_END();
}
long len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++){
SSearchPipeList *pList = pListAll->m_lstNode[i];
CalcPipeLength(pList);
}
return;
}
//计算本节点往后共计管线长度
void CalcPipeLength2(SSearchPipeList *pListAll, SSearchPipeList *pListFront)
{
if(pListAll->m_iType == 0){
OPENOBJ_BEGIN(pListAll->m_ID, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
pListAll->m_nLength = pPipe->Length();
}
OPENOBJ_END();
}
if(pListFront)
pListAll->m_nLength += pListFront->m_nLength;
long len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++){
SSearchPipeList *pList = pListAll->m_lstNode[i];
pList->m_pPrevious = pListAll;
CalcPipeLength2(pList, pListAll);
}
return;
}
//得到下一个标注节点 根据节点编号是否为空
//3个条件
SSearchPipeList *GetNextDimNode2(SSearchPipeList *pListAll, SSearchPipeList *pDisadvantage)
{
AcDbObjectId id = NULL;
id = pListAll->m_ID;
double nCurPipeLength(0);
nCurPipeLength = pListAll->m_nLength;
if(pListAll->m_csName == _T("") && pListAll->m_iType != 0){
int idx = GetFirstAncestorSerial(pListAll);
if(pDisadvantage){
int idx2 = GetFirstAncestorSerial(pDisadvantage);
if(idx < idx2){ //条件1: 当前节点的祖先编号小于临时节点的祖先编号
pDisadvantage = pListAll;
}
else if(idx == 0){ //条件2:
if(pDisadvantage && nCurPipeLength > pDisadvantage->m_nLength)
pDisadvantage = pListAll;
}
else if(idx == idx2){//条件3: 当前节点的祖先编号等于临时节点的祖先编号, 但离起始节点最远
int iParentIdx1 = GetAncestorSerial(pListAll);
int iParentIdx2 = GetAncestorSerial(pDisadvantage);
if(iParentIdx1 == iParentIdx2){
if(pDisadvantage && nCurPipeLength > pDisadvantage->m_nLength)
pDisadvantage = pListAll;
}
else if(iParentIdx1 < iParentIdx2 || iParentIdx2 == idx2){
pDisadvantage = pListAll;
}
}
}
else
pDisadvantage = pListAll; //条件3: 临时节点为空
}
int len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++){
SSearchPipeList *pList = pListAll->m_lstNode[i];
pDisadvantage = GetNextDimNode2(pList, pDisadvantage);
}
return pDisadvantage;
}
//本节点往前所有节点进行标注
int DoSerialNumber2(SSearchPipeList *pListLast, int idx)
{
AcDbObjectId id = NULL;
id = pListLast->m_ID;
if(pListLast->m_iType == 2 || pListLast->m_iType == 1 || pListLast->m_iType == -1){
if(pListLast->m_csName != _T(""))
return idx;
pListLast->m_csName.Format(_T("%d"), idx);
if(DoDimSerialNumber(id, idx))
idx++;
else
return idx;
}
if(pListLast->m_pPrevious)
idx = DoSerialNumber2(pListLast->m_pPrevious, idx);
return idx;
}