982 lines
27 KiB
C++
982 lines
27 KiB
C++
#include "StdAfx.h"
|
|
#include "DbEquipment.h"
|
|
#include "LinkHydrantDlg.h"
|
|
#include "AcDbObjectPtr.h"
|
|
#include "globalFunc.h"
|
|
#include "PickEntSet.h"
|
|
#include "DbPipe.h"
|
|
#include "layerdef.h"
|
|
#include "TRegProperty.h"
|
|
|
|
extern CString GetLayerNames(const TCHAR *szTgSubName);
|
|
extern AcDbObjectId InitLayer(const TCHAR *szLayer, AcDbDatabase *pDb = NULL);
|
|
|
|
|
|
namespace
|
|
{
|
|
CString GetPipeLayerByVPipeLay(const TCHAR *szLayer)
|
|
{
|
|
CString csLayer = szLayer;
|
|
CString csRet;
|
|
if (csLayer == LAY_VPIPE_FEED || csLayer == LAY_PIPE_FEED)
|
|
csRet = LAY_PIPE_FEED;
|
|
else if (csLayer == LAY_VPIPE_HEADFEED || csLayer == LAY_PIPE_HEADFEED)
|
|
csRet = LAY_PIPE_HEADFEED;
|
|
else if (csLayer == LAY_VPIPE_HEADBACK || csLayer == LAY_PIPE_HEADBACK)
|
|
csRet = LAY_PIPE_HEADBACK;
|
|
else if (csLayer == LAY_VPIPE_DIRT || csLayer == LAY_PIPE_DIRT)
|
|
csRet = LAY_PIPE_DIRT;
|
|
else if (csLayer == LAY_VPIPE_USELESS || csLayer == LAY_PIPE_USELESS)
|
|
csRet = LAY_PIPE_USELESS;
|
|
else if (csLayer == LAY_VPIPE_RAIN || csLayer == LAY_PIPE_RAIN)
|
|
csRet = LAY_PIPE_RAIN;
|
|
else if (csLayer == LAY_VPIPE_USED || csLayer == LAY_PIPE_USED)
|
|
csRet = LAY_PIPE_USED;
|
|
else if (csLayer == LAY_VPIPE_FIRE || csLayer == LAY_PIPE_FIRE)
|
|
csRet = LAY_PIPE_FIRE;
|
|
else if (csLayer == LAY_VPIPE_SPRINKLE || csLayer == LAY_PIPE_SPRINKLE)
|
|
csRet = LAY_PIPE_SPRINKLE;
|
|
else if (csLayer == LAY_VPIPE_COAGULATE || csLayer == LAY_PIPE_COAGULATE)
|
|
csRet = LAY_PIPE_COAGULATE;
|
|
else if (csLayer == LAY_VPIPE_DRINK || csLayer == LAY_PIPE_DRINK)
|
|
csRet = LAY_PIPE_DRINK;
|
|
else if (csLayer == LAY_VPIPE_PRESSDIRT || csLayer == LAY_PIPE_PRESSDIRT)
|
|
csRet = LAY_PIPE_PRESSDIRT;
|
|
else if (csLayer == LAY_VPIPE_PRESSUSELESS || csLayer == LAY_PIPE_PRESSUSELESS)
|
|
csRet = LAY_PIPE_PRESSUSELESS;
|
|
else if (csLayer == LAY_VPIPE_PRESSRAIN || csLayer == LAY_PIPE_PRESSRAIN)
|
|
csRet = LAY_PIPE_PRESSRAIN;
|
|
else if (csLayer == LAY_VPIPE_OTHER || csLayer == LAY_PIPE_OTHER)
|
|
csRet = LAY_PIPE_OTHER;
|
|
else if (csLayer == LAY_VPIPE_FEED2 || csLayer == LAY_PIPE_FEED2)
|
|
csRet = LAY_PIPE_FEED2;
|
|
else if (csLayer == LAY_VPIPE_FEED3 || csLayer == LAY_PIPE_FEED3)
|
|
csRet = LAY_PIPE_FEED3;
|
|
else if (csLayer == LAY_VPIPE_HEADFEED2 || csLayer == LAY_PIPE_HEADFEED2)
|
|
csRet = LAY_PIPE_HEADFEED2;
|
|
else if (csLayer == LAY_VPIPE_HEADFEED3 || csLayer == LAY_PIPE_HEADFEED3)
|
|
csRet = LAY_PIPE_HEADFEED3;
|
|
else if (csLayer == LAY_VPIPE_HEADBACK2 || csLayer == LAY_PIPE_HEADBACK2)
|
|
csRet = LAY_PIPE_HEADBACK2;
|
|
else if (csLayer == LAY_VPIPE_HEADBACK3 || csLayer == LAY_PIPE_HEADBACK3)
|
|
csRet = LAY_PIPE_HEADBACK3;
|
|
else if (csLayer == LAY_VPIPE_FIRE2 || csLayer == LAY_PIPE_FIRE2)
|
|
csRet = LAY_PIPE_FIRE2;
|
|
else if (csLayer == LAY_VPIPE_FIRE3 || csLayer == LAY_PIPE_FIRE3)
|
|
csRet = LAY_PIPE_FIRE3;
|
|
else if (csLayer == LAY_VPIPE_SPRINKLE2 || csLayer == LAY_PIPE_SPRINKLE2)
|
|
csRet = LAY_PIPE_SPRINKLE2;
|
|
else if (csLayer == LAY_VPIPE_SPRINKLE3 || csLayer == LAY_PIPE_SPRINKLE3)
|
|
csRet = LAY_PIPE_SPRINKLE3;
|
|
else if (csLayer == LAY_VPIPE_USED2 || csLayer == LAY_PIPE_USED2)
|
|
csRet = LAY_PIPE_USED2;
|
|
else if (csLayer == LAY_VPIPE_USED3 || csLayer == LAY_PIPE_USED3)
|
|
csRet = LAY_PIPE_USED3;
|
|
else if (csLayer == LAY_PIPE_USER1 || csLayer == LAY_VPIPE_USER1)
|
|
csRet = LAY_PIPE_USER1;
|
|
else if (csLayer == LAY_PIPE_USER2 || csLayer == LAY_VPIPE_USER2)
|
|
csRet = LAY_PIPE_USER2;
|
|
else if (csLayer == LAY_PIPE_USER3 || csLayer == LAY_VPIPE_USER3) // cet 2011.12.12 add user3-user8
|
|
csRet = LAY_PIPE_USER3;
|
|
else if (csLayer == LAY_PIPE_USER4 || csLayer == LAY_VPIPE_USER4)
|
|
csRet = LAY_PIPE_USER4;
|
|
else if (csLayer == LAY_PIPE_USER5 || csLayer == LAY_VPIPE_USER5)
|
|
csRet = LAY_PIPE_USER5;
|
|
else if (csLayer == LAY_PIPE_USER6 || csLayer == LAY_VPIPE_USER6)
|
|
csRet = LAY_PIPE_USER6;
|
|
else if (csLayer == LAY_PIPE_USER7 || csLayer == LAY_VPIPE_USER7)
|
|
csRet = LAY_PIPE_USER7;
|
|
else if (csLayer == LAY_PIPE_USER8 || csLayer == LAY_VPIPE_USER8)
|
|
csRet = LAY_PIPE_USER8;
|
|
|
|
return csRet;
|
|
}
|
|
|
|
void GetAllLineByEq(Entity ent, DList<XLine> &lstLine)
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if (pEquip) {
|
|
AcDbVoidPtrArray entSet;
|
|
pEquip->explode(entSet);
|
|
for (int i = 0; i<1; i++) {
|
|
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
|
|
AcDbBlockReference *pBlkRef = NULL;
|
|
if (pBlkRef = AcDbBlockReference::cast(pEnt)) {
|
|
AcDbVoidPtrArray entSet2;
|
|
pBlkRef->explode(entSet2);
|
|
int len = entSet2.length();
|
|
for (int j = 0; j<len; j++) {
|
|
AcDbEntity *pEnt2 = (AcDbEntity *)entSet2[j];
|
|
AcDbLine *pLine = NULL;
|
|
if (pLine = AcDbLine::cast(pEnt2)) {
|
|
XPoint pS = pLine->startPoint();
|
|
XPoint pE = pLine->endPoint();
|
|
pS.z = 0;
|
|
pE.z = 0;
|
|
XLine *line = new XLine(pS, pE);
|
|
lstLine.Append(line);
|
|
}
|
|
}
|
|
GlobalFunc::ReleaseEntSet(entSet2);
|
|
}
|
|
|
|
}
|
|
GlobalFunc::ReleaseEntSet(entSet);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
}
|
|
|
|
bool PartitionVPipeSys(PickSet &ss, PickSet &ssVPipe, PickSet &ssHydrant)
|
|
{
|
|
bool bRet = false;
|
|
for (long l = 0; l < ss.Length(); l++)
|
|
{
|
|
Entity ent = ss[l];
|
|
if(ent.Is(_T("AEC_ZT_PIPE")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe && pPipe->IsVertical())
|
|
{
|
|
ssVPipe += ent;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else
|
|
{
|
|
ssHydrant += ent;
|
|
}
|
|
}
|
|
|
|
if (ssVPipe.Length() > 0 && ssHydrant.Length() > 0)
|
|
{
|
|
bRet = true;
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
void DoLinkHydrantWithVPipe(Entity entEq, Entity entPipe, CLinkHydrantDlg &dlg)
|
|
{
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp1, xsTmp2;
|
|
if(g_Option::instance().g_bBlk3D)
|
|
{
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000441"), xsTmp1) != RTNORM)
|
|
return;
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000442"), xsTmp2) != RTNORM)
|
|
return;
|
|
}
|
|
OPENOBJ_BEGIN(entEq, AcDb::kForWrite, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
if(dlg.m_nHydrantLinkType_VPipe == 0)
|
|
{
|
|
pEquip->SetPipeLength(250);//上
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp1));
|
|
}
|
|
else if(dlg.m_nHydrantLinkType_VPipe == 1)
|
|
{
|
|
pEquip->SetPipeLength(0); //平
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp2));
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
CString csLay;
|
|
XPoint ptPipe;
|
|
//立管管径
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe != NULL && pPipe->IsVertical())
|
|
{
|
|
csLay = pPipe->GetLayer();
|
|
if(pPipe->upgradeOpen()==Acad::eOk)
|
|
{
|
|
pPipe->SetDnDiameter(dlg.m_dDnVPipe_VPipe);
|
|
pPipe->downgradeOpen();
|
|
}
|
|
ptPipe = pPipe->StartPoint();
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
OPENOBJ_END();
|
|
csLay = GetPipeLayerByVPipeLay(csLay);
|
|
ptPipe.z = 0;
|
|
|
|
DList<XLine> lstLine;
|
|
GetAllLineByEq(entEq, lstLine);//得到消火栓图块全部线段
|
|
|
|
XPoint ptInsert, ptInt, ptPipeEnd;
|
|
OPENOBJ_BEGIN(entEq, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
ptInsert = pEquip->GetInsert();
|
|
ptInsert.z = 0;
|
|
XVector3D vt = pEquip->GetDirection();
|
|
vt.Normalize();
|
|
vt *= 1000;
|
|
XPoint ptTmp;
|
|
ptTmp = ptInsert + vt;
|
|
XLine line1(ptInsert, ptTmp);
|
|
ptPipe.Project(&line1, ptInt);
|
|
XLine line2(ptPipe, ptInt);
|
|
line2.SetLineFlag(1);
|
|
|
|
int len = lstLine.Length();
|
|
double nDist(-1);
|
|
for(int i=0;i<len;i++)
|
|
{
|
|
XPoint ptIntTmp;
|
|
XLine line = *lstLine[i];
|
|
line.SetLineFlag(1);
|
|
int ret = line.Intersection(&line2, ptIntTmp);
|
|
if(ret > 0)
|
|
{
|
|
double n = ads_distance(ptPipe, ptIntTmp);
|
|
if(n < nDist || nDist < 0)
|
|
{
|
|
ptPipeEnd = ptIntTmp;// 有交点,立管直接接消火栓
|
|
nDist = n;
|
|
}
|
|
}
|
|
}
|
|
if(!ptPipeEnd)
|
|
{
|
|
vt = pEquip->GetDirection();
|
|
vt.Normalize();
|
|
vt.Rotate(PI/2.0);
|
|
vt *= 1000;
|
|
ptTmp = ptInsert + vt;
|
|
XLine line4(ptInsert, ptTmp);
|
|
XPoint ptInt2;
|
|
ptPipe.Project(&line4, ptInt2);
|
|
XLine line5(ptPipe, ptInt2);
|
|
line5.SetLineFlag(1);
|
|
|
|
for(int i=0;i<len;i++)
|
|
{
|
|
XPoint ptIntTmp;
|
|
XLine line = *lstLine[i];
|
|
line.SetLineFlag(1);
|
|
int ret = line.Intersection(&line5, ptIntTmp);
|
|
if(ret > 0)
|
|
{
|
|
double n = ads_distance(ptPipe, ptIntTmp);
|
|
if(n < nDist || nDist < 0)
|
|
{
|
|
ptPipeEnd = ptIntTmp;// 有交点,立管直接接消火栓
|
|
nDist = n;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
double dEle = dlg.GetElev() * 1000;
|
|
XPoint ptStart, ptEnd;
|
|
ptStart = ptPipe;
|
|
ptStart.z = dEle;
|
|
if(!!ptPipeEnd)
|
|
ptEnd = ptPipeEnd;
|
|
else
|
|
ptEnd = ptInt;
|
|
|
|
ptEnd.z = dEle;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe != NULL)
|
|
{
|
|
CDbPipe *pNewPipe = (CDbPipe *)pPipe->clone();
|
|
pNewPipe->SetEndPoint(ptEnd);
|
|
pNewPipe->SetStartPoint(ptStart);
|
|
pNewPipe->SetDnDiameter(dlg.m_dDnPipe_VPipe);
|
|
pNewPipe->setLayer(InitLayer(csLay));
|
|
GlobalFunc::AddToCurrentSpace(pNewPipe, Adesk::kTrue);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if(!!ptPipeEnd)
|
|
{//立管直接连接消火栓
|
|
if(pEquip->upgradeOpen()==Acad::eOk)
|
|
{
|
|
pEquip->SetLocation(ptEnd);
|
|
pEquip->downgradeOpen();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ptStart = ptInt;
|
|
ptStart.z = dEle;
|
|
|
|
ptEnd = ptInsert;
|
|
|
|
ptEnd.z = dEle;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe != NULL)
|
|
{
|
|
CDbPipe *pNewPipe2 = (CDbPipe *)pPipe->clone();
|
|
pNewPipe2->setLayer(InitLayer(csLay));
|
|
pNewPipe2->SetEndPoint(ptEnd);
|
|
pNewPipe2->SetStartPoint(ptStart);
|
|
pNewPipe2->SetDnDiameter(dlg.m_dDnPipe_VPipe);
|
|
GlobalFunc::AddToCurrentSpace(pNewPipe2, Adesk::kTrue);
|
|
}
|
|
OPENOBJ_END();
|
|
if(pEquip->upgradeOpen()==Acad::eOk)
|
|
{
|
|
ptInsert.z = ptEnd.z;
|
|
pEquip->SetLocation(ptInsert);
|
|
pEquip->downgradeOpen();
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
bool HasLinked(std::vector<Entity> &vecEq, Entity &entEq)
|
|
{
|
|
std::vector<Entity>::iterator it;
|
|
AcDbObjectId id, idEq;
|
|
acdbGetObjectId(idEq, entEq);
|
|
for (it = vecEq.begin(); it != vecEq.end(); it++)
|
|
{
|
|
acdbGetObjectId(id, *it);
|
|
if (id == idEq)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 去处掉选择集中已连接的消火栓
|
|
void ReMoveEntByHydrant(PickSet &ssHydrant)
|
|
{
|
|
for (long l = 0; l < ssHydrant.Length(); l++)
|
|
{
|
|
Entity entHy = ssHydrant[l];
|
|
OPENOBJ_BEGIN(entHy, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
int nNum = pEquip->GetInterfaceNum();
|
|
if (nNum > 0)
|
|
{
|
|
ssHydrant -= entHy;
|
|
l--;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
bool HasLinkedEnt(SSearchPipeList *pList, int &nIndex)
|
|
{
|
|
if (pList != NULL)
|
|
{
|
|
Entity ent;
|
|
ads_name entName;
|
|
AcDbObjectId id = pList->m_ID;
|
|
acdbGetAdsName(entName, id);
|
|
ent = entName;
|
|
TCHAR szLay[256];
|
|
ent.GetData(8, szLay);
|
|
if(ent.Is(_T("AEC_ZT_EQUIPMENT")) && _tcsicmp(szLay, _T("EQUIP_消火栓")) == 0)
|
|
{
|
|
return true;
|
|
}
|
|
else if (nIndex == 6)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
nIndex++;
|
|
for (int i = 0; i < pList->m_lstNode.Length(); i++)
|
|
{
|
|
if (HasLinkedEnt(pList->m_lstNode[i], nIndex))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 去处掉选择集中已连接的立管
|
|
void ReMoveEntByVPipe(PickSet &ssVPipe)
|
|
{
|
|
for (long ll = 0; ll < ssVPipe.Length(); ll++)
|
|
{
|
|
Entity entPipe = ssVPipe[ll];
|
|
SSearchPipeList *pList = new SSearchPipeList();
|
|
PickSet ssAll(SS_FREE);
|
|
if(!GlobalFunc::SearchSprinkPipeSys(entPipe, NULL, pList, ssAll))
|
|
{
|
|
delete pList;
|
|
pList = NULL;
|
|
continue;
|
|
}
|
|
|
|
int nIndex = 0;
|
|
if (HasLinkedEnt(pList, nIndex))
|
|
{
|
|
ssVPipe -= entPipe;
|
|
ll--;
|
|
}
|
|
if (pList != NULL)
|
|
{
|
|
delete pList;
|
|
pList = NULL;
|
|
}
|
|
}
|
|
}
|
|
// 排除掉已连接的消火栓和立管
|
|
void ReMoveLinkedEnt(PickSet &ssVPipe, PickSet &ssHydrant)
|
|
{
|
|
ReMoveEntByHydrant(ssHydrant);
|
|
ReMoveEntByVPipe(ssVPipe);
|
|
}
|
|
|
|
void LinkHydrantWithVPipe(PickSet &ss, CLinkHydrantDlg &dlg)
|
|
{
|
|
PickSet ssVPipe, ssHydrant, ssLinked;
|
|
if (!PartitionVPipeSys(ss, ssVPipe, ssHydrant))
|
|
{
|
|
ss.Free();
|
|
return;
|
|
}
|
|
|
|
if (ssVPipe.Length() == 1 && ssHydrant.Length() == 1)
|
|
{
|
|
DoLinkHydrantWithVPipe(ssHydrant[0l], ssVPipe[0l], dlg);
|
|
ssHydrant.Free();
|
|
}
|
|
else
|
|
{
|
|
XPoint ptLoc, ptPipe;
|
|
ReMoveLinkedEnt(ssVPipe, ssHydrant);
|
|
std::map<double, std::pair<Entity, Entity> > mapPipe;
|
|
for (long l = 0; l < ssHydrant.Length(); l++)
|
|
{
|
|
Entity entHy = ssHydrant[l];
|
|
OPENOBJ_BEGIN(entHy, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
ptLoc = pEquip->GetInsert();
|
|
ptLoc.z = 0;
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
for (long ll = 0; ll < ssVPipe.Length(); ll++)
|
|
{
|
|
Entity entPipe = ssVPipe[ll];
|
|
double dDistMin = 5.0 * 1000;
|
|
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe != NULL)
|
|
{
|
|
ptPipe = pPipe->GetStartPoint();
|
|
ptPipe.z = 0;
|
|
}
|
|
double dDist = ptPipe.Distance2d(ptLoc);
|
|
if (dDistMin - dDist > 0.0)// 消火栓距离立管小于5m
|
|
{
|
|
mapPipe.insert(std::make_pair(dDist, std::make_pair(entHy, entPipe)));
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
std::map<double, std::pair<Entity, Entity> >::iterator it;
|
|
std::vector<Entity> vecEq, vecPipe;
|
|
Entity entEq, entPipe;
|
|
for (it = mapPipe.begin(); it != mapPipe.end(); it++)
|
|
{
|
|
if (ssHydrant.Length() == 0)
|
|
{
|
|
break;
|
|
}
|
|
entEq = it->second.first;
|
|
entPipe = it->second.second;
|
|
if (!HasLinked(vecEq, entEq) && !HasLinked(vecPipe, entPipe))
|
|
{
|
|
DoLinkHydrantWithVPipe(entEq, entPipe, dlg);
|
|
vecEq.push_back(entEq);
|
|
vecPipe.push_back(entPipe);
|
|
ssHydrant -= entEq;
|
|
}
|
|
}
|
|
}
|
|
ss.Free();
|
|
ss = ssHydrant;// 未连接的消火栓
|
|
}
|
|
|
|
// 修改管线颜色,bChange为true时变黄,false时随层
|
|
void ChangePipeColor(PickSet &ssPipeLine, bool bChange)
|
|
{
|
|
for (long l = 0; l < ssPipeLine.Length(); l++)
|
|
{
|
|
Entity ent = ssPipeLine[l];
|
|
if(ent.Is(_T("AEC_ZT_PIPE")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, CDbPipe, pPipe);
|
|
if(pPipe != NULL && !pPipe->IsVertical())
|
|
{
|
|
if (bChange)
|
|
{
|
|
pPipe->setColorIndex(2);
|
|
}
|
|
else
|
|
{
|
|
pPipe->setColor(AcCmColor());
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
}
|
|
|
|
bool PartitionPipeLineSys(PickSet &ss, Entity &entPipeLine, PickSet &ssHydrant)
|
|
{
|
|
bool bRet = false;
|
|
PickSet ssPipeLine;
|
|
for (long l = 0; l < ss.Length(); l++)
|
|
{
|
|
Entity ent = ss[l];
|
|
if(ent.Is(_T("AEC_ZT_PIPE")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe != NULL && !pPipe->IsVertical())
|
|
{
|
|
ssPipeLine += ent;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else
|
|
{
|
|
ssHydrant += ent;
|
|
}
|
|
}
|
|
|
|
if (ssPipeLine.Length() == 1 && ssHydrant.Length() > 0)
|
|
{
|
|
entPipeLine = ssPipeLine[0l];
|
|
bRet = true;
|
|
}
|
|
else if (ssPipeLine.Length() > 1 && ssHydrant.Length() > 0)
|
|
{
|
|
CString csPipeLayer;
|
|
csPipeLayer.Format(_T("%s,%s,%s"), LAY_PIPE_FIRE, LAY_PIPE_FIRE2, LAY_PIPE_FIRE3);
|
|
RBList rbMask(RTDXF0, _T("AEC_ZT_PIPE"), 8, csPipeLayer, NULL);
|
|
ChangePipeColor(ssPipeLine, true);
|
|
int nRet = GlobalFunc::SelectEntity(_T("\n存在多跟消防干管,请确定主消防干管!<退出>:"), entPipeLine, rbMask);
|
|
if (nRet == RTNORM)
|
|
{
|
|
bRet = true;
|
|
}
|
|
ChangePipeColor(ssPipeLine, false);
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
bool IsHydrantParallel2Pipe(Entity &ent, const AcGeVector3d &vt)
|
|
{
|
|
double dLenMin = 0.0, dLenMax = 0.0, dLenMid = 0.0;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
AcDbVoidPtrArray entSet;
|
|
pEquip->explode(entSet);
|
|
for(int i=0;i<1;i++)
|
|
{
|
|
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
|
|
AcDbBlockReference *pBlkRef = NULL;
|
|
if(pBlkRef = AcDbBlockReference::cast(pEnt))
|
|
{
|
|
AcDbVoidPtrArray entSet2;
|
|
pBlkRef->explode(entSet2);
|
|
int len = entSet2.length();
|
|
for(int j=0;j<len;j++)
|
|
{
|
|
AcDbEntity *pEnt2 = (AcDbEntity *)entSet2[j];
|
|
AcDbLine *pLine = NULL;
|
|
if(pLine = AcDbLine::cast(pEnt2))
|
|
{
|
|
XPoint pS = pLine->startPoint();
|
|
XPoint pE = pLine->endPoint();
|
|
pS.z = 0;
|
|
pE.z = 0;
|
|
double dDist = pS.Distance2d(pE);
|
|
if (dLenMax < dDist)
|
|
{
|
|
dLenMax = dDist;
|
|
}
|
|
|
|
if (dLenMin > dDist || dLenMin == 0)
|
|
{
|
|
dLenMin = dDist;
|
|
}
|
|
|
|
AcGeVector3d vtH = pE - pS;
|
|
vtH.normalize();
|
|
if (vtH.isParallelTo(vt))
|
|
{
|
|
dLenMid = dDist;
|
|
}
|
|
}
|
|
}
|
|
GlobalFunc::ReleaseEntSet(entSet2);
|
|
}
|
|
|
|
}
|
|
GlobalFunc::ReleaseEntSet(entSet);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if (dLenMid > dLenMin && dLenMid < dLenMax)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
CString GetVPipeLayerByPipeLay(const TCHAR* szLayer)
|
|
{
|
|
CString csLayer = szLayer;
|
|
CString csRet;
|
|
if(csLayer == LAY_VPIPE_FEED || csLayer == LAY_PIPE_FEED)
|
|
csRet = LAY_VPIPE_FEED;
|
|
else if(csLayer == LAY_VPIPE_HEADFEED || csLayer == LAY_PIPE_HEADFEED)
|
|
csRet = LAY_VPIPE_HEADFEED;
|
|
else if(csLayer == LAY_VPIPE_HEADBACK || csLayer == LAY_PIPE_HEADBACK)
|
|
csRet = LAY_VPIPE_HEADBACK;
|
|
else if(csLayer == LAY_VPIPE_DIRT || csLayer == LAY_PIPE_DIRT)
|
|
csRet = LAY_VPIPE_DIRT;
|
|
else if(csLayer == LAY_VPIPE_USELESS || csLayer == LAY_PIPE_USELESS)
|
|
csRet = LAY_VPIPE_USELESS;
|
|
else if(csLayer == LAY_VPIPE_RAIN || csLayer == LAY_PIPE_RAIN)
|
|
csRet = LAY_VPIPE_RAIN;
|
|
else if(csLayer == LAY_VPIPE_USED || csLayer == LAY_PIPE_USED)
|
|
csRet = LAY_VPIPE_USED;
|
|
else if(csLayer == LAY_VPIPE_FIRE || csLayer == LAY_PIPE_FIRE)
|
|
csRet = LAY_VPIPE_FIRE;
|
|
else if(csLayer == LAY_VPIPE_SPRINKLE || csLayer == LAY_PIPE_SPRINKLE)
|
|
csRet = LAY_VPIPE_SPRINKLE;
|
|
else if(csLayer == LAY_VPIPE_COAGULATE || csLayer == LAY_PIPE_COAGULATE)
|
|
csRet = LAY_VPIPE_COAGULATE;
|
|
else if(csLayer == LAY_VPIPE_DRINK || csLayer == LAY_PIPE_DRINK)
|
|
csRet = LAY_VPIPE_DRINK;
|
|
else if(csLayer == LAY_VPIPE_PRESSDIRT || csLayer == LAY_PIPE_PRESSDIRT)
|
|
csRet = LAY_VPIPE_PRESSDIRT;
|
|
else if(csLayer == LAY_VPIPE_PRESSUSELESS || csLayer == LAY_PIPE_PRESSUSELESS)
|
|
csRet = LAY_VPIPE_PRESSUSELESS;
|
|
else if(csLayer == LAY_VPIPE_PRESSRAIN || csLayer == LAY_PIPE_PRESSRAIN)
|
|
csRet = LAY_VPIPE_PRESSRAIN;
|
|
else if(csLayer == LAY_VPIPE_OTHER || csLayer == LAY_PIPE_OTHER)
|
|
csRet = LAY_VPIPE_OTHER;
|
|
else if(csLayer == LAY_VPIPE_FEED2 || csLayer == LAY_PIPE_FEED2)
|
|
csRet = LAY_VPIPE_FEED2;
|
|
else if(csLayer == LAY_VPIPE_FEED3 || csLayer == LAY_PIPE_FEED3)
|
|
csRet = LAY_VPIPE_FEED3;
|
|
else if(csLayer == LAY_VPIPE_HEADFEED2 || csLayer == LAY_PIPE_HEADFEED2)
|
|
csRet = LAY_VPIPE_HEADFEED2;
|
|
else if(csLayer == LAY_VPIPE_HEADFEED3 || csLayer == LAY_PIPE_HEADFEED3)
|
|
csRet = LAY_VPIPE_HEADFEED3;
|
|
else if(csLayer == LAY_VPIPE_HEADBACK2 || csLayer == LAY_PIPE_HEADBACK2)
|
|
csRet = LAY_VPIPE_HEADBACK2;
|
|
else if(csLayer == LAY_VPIPE_HEADBACK3 || csLayer == LAY_PIPE_HEADBACK3)
|
|
csRet = LAY_VPIPE_HEADBACK3;
|
|
else if(csLayer == LAY_VPIPE_FIRE2 || csLayer == LAY_PIPE_FIRE2)
|
|
csRet = LAY_VPIPE_FIRE2;
|
|
else if(csLayer == LAY_VPIPE_FIRE3 || csLayer == LAY_PIPE_FIRE3)
|
|
csRet = LAY_VPIPE_FIRE3;
|
|
else if(csLayer == LAY_VPIPE_SPRINKLE2 || csLayer == LAY_PIPE_SPRINKLE2)
|
|
csRet = LAY_VPIPE_SPRINKLE2;
|
|
else if(csLayer == LAY_VPIPE_SPRINKLE3 || csLayer == LAY_PIPE_SPRINKLE3)
|
|
csRet = LAY_VPIPE_SPRINKLE3;
|
|
else if(csLayer == LAY_VPIPE_USED2 || csLayer == LAY_PIPE_USED2)
|
|
csRet = LAY_VPIPE_USED2;
|
|
else if(csLayer == LAY_VPIPE_USED3 || csLayer == LAY_PIPE_USED3)
|
|
csRet = LAY_VPIPE_USED3;
|
|
else if(csLayer == LAY_PIPE_USER1 || csLayer == LAY_VPIPE_USER1)
|
|
csRet = LAY_VPIPE_USER1;
|
|
else if(csLayer == LAY_PIPE_USER2 || csLayer == LAY_VPIPE_USER2)
|
|
csRet = LAY_VPIPE_USER2;
|
|
else if(csLayer == LAY_PIPE_USER3 || csLayer == LAY_VPIPE_USER3)
|
|
csRet = LAY_VPIPE_USER3;
|
|
else if(csLayer == LAY_PIPE_USER4 || csLayer == LAY_VPIPE_USER4)
|
|
csRet = LAY_VPIPE_USER4;
|
|
else if(csLayer == LAY_PIPE_USER5 || csLayer == LAY_VPIPE_USER5)
|
|
csRet = LAY_VPIPE_USER5;
|
|
else if(csLayer == LAY_PIPE_USER6 || csLayer == LAY_VPIPE_USER6)
|
|
csRet = LAY_VPIPE_USER6;
|
|
else if(csLayer == LAY_PIPE_USER7 || csLayer == LAY_VPIPE_USER7)
|
|
csRet = LAY_VPIPE_USER7;
|
|
else if(csLayer == LAY_PIPE_USER8 || csLayer == LAY_VPIPE_USER8)
|
|
csRet = LAY_VPIPE_USER8;
|
|
|
|
return csRet;
|
|
}
|
|
|
|
void DrawPipeLine(XPoint ptS, XPoint ptE, double dDn, CDbPipe *pPipe)
|
|
{
|
|
if (pPipe == NULL)
|
|
{
|
|
return;
|
|
}
|
|
CDbPipe *pPipeNew = (CDbPipe *)pPipe->clone();
|
|
pPipeNew->SetStartPoint(ptS);
|
|
pPipeNew->SetEndPoint(ptE);
|
|
pPipeNew->SetDnDiameter(dDn);
|
|
if (ptS.Distance2d(ptE) < 0.001 && fabs(ptS.z - ptE.z) > 0.001)// 立管
|
|
{
|
|
int iPipeIdx = GlobalFunc::GetPipeLayerIdxByName(pPipe->GetLayer());
|
|
pPipeNew->SetRadius(g_Option::instance().g_nPipeRadius[iPipeIdx]);
|
|
CString sVPipeLayer = GetVPipeLayerByPipeLay(pPipe->GetLayer());
|
|
InitLayer(sVPipeLayer);
|
|
pPipeNew->setLayer(sVPipeLayer);
|
|
}
|
|
GlobalFunc::AddToCurrentSpace(pPipeNew, Adesk::kTrue);
|
|
}
|
|
|
|
void LinkHydrant2PipeLine(AcGePoint3d &ptOnPipe, AcGePoint3d &ptTurn, AcGePoint3d &ptLoc, CLinkHydrantDlg &dlg, CString &sLayer, CDbPipe *pPipe)
|
|
{
|
|
AcGePoint3d ptTurn2 = ptTurn;;
|
|
double dElePipe = dlg.m_dElePipe_Pipe * 1000;
|
|
double dEleHy = dlg.GetElev() * 1000;
|
|
double dDnVPipe = dlg.m_dDnVPipe_Pipe;
|
|
double dDnPipe = dlg.m_dDn2Pipe_Pipe;
|
|
if (dlg.m_nPipeLinkType_Pipe == 0)// 水平连接
|
|
{
|
|
ptOnPipe.z = dElePipe;
|
|
ptTurn.z = dElePipe;
|
|
ptTurn2.z = dEleHy;
|
|
ptLoc.z = dEleHy;
|
|
DrawPipeLine(ptOnPipe, ptTurn, dDnVPipe, pPipe);
|
|
DrawPipeLine(ptTurn, ptTurn2, dDnVPipe, pPipe);
|
|
}
|
|
else// 垂直连接
|
|
{
|
|
ptTurn = ptOnPipe;
|
|
ptOnPipe.z = dElePipe;
|
|
ptTurn.z = dEleHy;
|
|
ptTurn2.z = dEleHy;
|
|
ptLoc.z = dEleHy;
|
|
DrawPipeLine(ptOnPipe, ptTurn, dDnVPipe, pPipe);
|
|
DrawPipeLine(ptTurn, ptTurn2, dDnPipe, pPipe);
|
|
}
|
|
DrawPipeLine(ptTurn2, ptLoc, dDnPipe, pPipe);
|
|
}
|
|
|
|
void DoLinkHydrantWithPipeLine(Entity entEq, Entity entPipe, CLinkHydrantDlg &dlg)
|
|
{
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp1, xsTmp2;
|
|
XPoint ptLoc, ptTurn, ptOnPipe, ptS, ptE;
|
|
double dLenHy = 0.0;
|
|
if(g_Option::instance().g_bBlk3D)
|
|
{
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000441"), xsTmp1) != RTNORM)
|
|
return;
|
|
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000442"), xsTmp2) != RTNORM)
|
|
return;
|
|
}
|
|
|
|
AcDbLine linePipe;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForWrite, CDbPipe, pPipe);
|
|
CString sLayer;
|
|
if(pPipe != NULL)
|
|
{
|
|
sLayer = pPipe->GetLayer();
|
|
ptS = pPipe->GetStartPoint();
|
|
ptE = pPipe->GetEndPoint();
|
|
ptS.z = dlg.m_dElePipe_Pipe * 1000;
|
|
ptE.z = dlg.m_dElePipe_Pipe * 1000;
|
|
pPipe->SetStartPoint(ptS);
|
|
pPipe->SetEndPoint(ptE);
|
|
pPipe->SetDnDiameter(dlg.m_dDnPipe_Pipe);
|
|
linePipe.setStartPoint(ptS);
|
|
linePipe.setEndPoint(ptE);
|
|
OPENOBJ_BEGIN(entEq, AcDb::kForWrite, CDbEquipment, pEquip);
|
|
if(pEquip != NULL)
|
|
{
|
|
if(dlg.m_nHydrantLinkType_Pipe == 0)
|
|
{
|
|
pEquip->SetPipeLength(250);//上
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp1));
|
|
}
|
|
else if(dlg.m_nHydrantLinkType_Pipe == 1)
|
|
{
|
|
pEquip->SetPipeLength(0); //平
|
|
pEquip->SetBlock3d(GlobalFunc::GetBlockIdFromString(xsTmp2));
|
|
}
|
|
|
|
ptLoc = pEquip->GetInsert();
|
|
ptLoc.z = 0.0;
|
|
linePipe.getClosestPointTo(ptLoc, ptOnPipe, Adesk::kTrue);
|
|
|
|
dLenHy = pEquip->GetScale();
|
|
double dOffSet = dlg.m_dDistPipe2Hy_Pipe * 1000 + dLenHy / 2;
|
|
ptOnPipe.z = 0.0;
|
|
AcGeVector3d vt = ptOnPipe - ptLoc;
|
|
vt.normalize();
|
|
if (dlg.m_nVPipePos_Pipe == 0)
|
|
{
|
|
vt = vt.rotateBy(PI / 2, AcGeVector3d::kZAxis);
|
|
}
|
|
else
|
|
{
|
|
vt = vt.rotateBy(-PI / 2, AcGeVector3d::kZAxis);
|
|
}
|
|
ptTurn = ptLoc + vt * dOffSet;
|
|
ptOnPipe = ptOnPipe + vt * dOffSet;
|
|
|
|
ptOnPipe.z = ptS.z;
|
|
double dLenPipe = ptS.Distance(ptE);
|
|
double dDist2S = ptOnPipe.Distance(ptS);
|
|
double dDist2E = ptOnPipe.Distance(ptE);
|
|
if (dDist2S >= dDist2E + dLenPipe)// 干管末端延长
|
|
{
|
|
CDbPipe *pNewPipe = (CDbPipe *)pPipe->clone();
|
|
pNewPipe->SetEndPoint(ptOnPipe);
|
|
pNewPipe->SetStartPoint(ptE);
|
|
GlobalFunc::AddToCurrentSpace(pNewPipe, Adesk::kTrue);
|
|
}
|
|
else if (dDist2E >= dDist2S + dLenPipe)// 干管首端延长
|
|
{
|
|
CDbPipe *pNewPipe = (CDbPipe *)pPipe->clone();
|
|
pNewPipe->SetEndPoint(ptS);
|
|
pNewPipe->SetStartPoint(ptOnPipe);
|
|
GlobalFunc::AddToCurrentSpace(pNewPipe, Adesk::kTrue);
|
|
}
|
|
|
|
ptOnPipe.z = 0;
|
|
LinkHydrant2PipeLine(ptOnPipe, ptTurn, ptLoc, dlg, sLayer, pPipe);
|
|
pEquip->SetLocation(ptLoc);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
// 干管连接消火栓
|
|
void LinkHydrantWithPipeLine(PickSet &ss, CLinkHydrantDlg &dlg)
|
|
{
|
|
PickSet ssHydrant, ssUnLinked;
|
|
Entity entPipe;
|
|
if (!PartitionPipeLineSys(ss, entPipe, ssHydrant))
|
|
{
|
|
ss.Free();
|
|
return;
|
|
}
|
|
|
|
AcGeVector3d vtPipe;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe);
|
|
if(pPipe != NULL)
|
|
{
|
|
XPoint ptS = pPipe->GetStartPoint();
|
|
XPoint ptE = pPipe->GetEndPoint();
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
vtPipe = ptE - ptS;
|
|
vtPipe.normalize();
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if (ssHydrant.Length() > 1)
|
|
{
|
|
ReMoveEntByHydrant(ssHydrant);
|
|
}
|
|
for (long l = 0; l < ssHydrant.Length(); l++)
|
|
{
|
|
Entity entHy = ssHydrant[l];
|
|
if (!IsHydrantParallel2Pipe(entHy, vtPipe))
|
|
{
|
|
ssUnLinked += entHy;
|
|
continue;
|
|
}
|
|
|
|
DoLinkHydrantWithPipeLine(entHy, entPipe, dlg);
|
|
}
|
|
ss.Free();
|
|
ss += ssUnLinked;
|
|
}
|
|
|
|
// 接消火栓
|
|
void LinkHydrantNew()
|
|
{
|
|
GlobalFunc::DocGetPickFirst().Free();
|
|
int nType = 0;
|
|
TRegProperty regProp(_T("SoftWare\\SHANGHUASOFT\\2023"), _T("SHS-WTConfig"));
|
|
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
|
bool bRet = regProp.GetValue(_T("LinkHydrantPipeType"), nType);
|
|
|
|
CLinkHydrantDlg dlg(nType, acedGetAcadFrame());
|
|
{
|
|
CTemporaryResourceOverride vTemp;
|
|
dlg.Create(IDD_LINK_HYDRANY, acedGetAcadFrame());
|
|
}
|
|
dlg.ShowWindow(SW_SHOW);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_ZT_PIPE"), 8, GetLayerNames(_T("消防")), -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_ZT_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, -4, _T("and>"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
while(true)
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
dlg.UpdataDlgData();
|
|
CString csPrompt;
|
|
if (!bRet || nType == 0)// 立消连接
|
|
{
|
|
csPrompt = _T("\n请框选消火栓与消防立管(支持多选)<退出>:");
|
|
}
|
|
else// 干消连接
|
|
{
|
|
csPrompt = _T("\n请选择单根消防干管与多个消火栓<退出>:");
|
|
}
|
|
|
|
int ret = GlobalFunc::SelectEntities(csPrompt, ss, rbMask);// 连接方式改变时,发送error消息,m_bChangeMode设置为true
|
|
if(ret == RTNORM)
|
|
{
|
|
dlg.UpdataDlgData();
|
|
if (!bRet || nType == 0)// 立消连接
|
|
{
|
|
LinkHydrantWithVPipe(ss, dlg);
|
|
}
|
|
else// 干消连接
|
|
{
|
|
LinkHydrantWithPipeLine(ss, dlg);
|
|
}
|
|
|
|
//TPipePerDocData *pData = GetCurPipeDocData();
|
|
//pData->ApplyUpdates();
|
|
//if (ss.Length() > 0)// 高亮显示未连接的消火栓
|
|
//{
|
|
// CString sNote = _T("");
|
|
// sNote.Format(_T("总共有%d个消火栓未完成连接!"), ss.Length());
|
|
// acutPrintf(sNote);
|
|
// dlg.SetUnLinkedEq(ss);
|
|
//
|
|
// TCHAR sz[10];
|
|
// acedGetString(0, _T("\n<退出>:"),sz);
|
|
// dlg.EndHydrantBlink();
|
|
//}
|
|
break;
|
|
}
|
|
else if(ret == RTERROR && dlg.m_bChangeMode)
|
|
{
|
|
dlg.m_bChangeMode = FALSE;
|
|
nType = dlg.m_nType;
|
|
continue;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
regProp.SetValue(_T("LinkHydrantPipeType"), dlg.m_nType);
|
|
dlg.SetRegDataFromDlg();
|
|
dlg.DestroyWindow();
|
|
} |