Files
envi-code/SourceCode/Code2026/tg_shs/shs_outdoor/PerpeDistanceTable.cpp
T

837 lines
21 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "StdAfx.h"
2026-09-28 15:28:50 +08:00
#include "TAPI.h"
#include "PipeTools.h"
#include <map>
#include "TwtDef.h"
#include <functional>
/*============================================================================*
* Copyright(c), 1994-2007, Beijing Tangent Engineering Software Co.Ltd.
2026-10-04 00:04:20 +08:00
* 作 者: 陈恩涛
* 创建时间: 2010-3-15
* 描 述: 垂距表
* 归属项目: 给排水
* 历史记录:
2026-09-28 15:28:50 +08:00
=============================================================================*/
//extern CString GetPipeNameBySys(TPipeSys::SysType sys);
typedef struct
{
2026-10-04 00:04:20 +08:00
CString strPipeType; // 管道类型
CString strPipeSpec; // 管道规格
CString strPipeHigh; // 管道高程
CString strHighType; // 标高类型
CString strOppositePos; // 相对位置
2026-09-28 15:28:50 +08:00
}PIPEINFO;
typedef struct
{
2026-10-04 00:04:20 +08:00
CString strNum; // 交点编号
2026-09-28 15:28:50 +08:00
PIPEINFO pipeInfo1;
PIPEINFO pipeInfo2;
2026-10-04 00:04:20 +08:00
CString strDist; // 垂直净距
CString strRemark; // 备注
2026-09-28 15:28:50 +08:00
}TABLEIFO;
2026-10-04 00:04:20 +08:00
//用于比较编号大小
2026-09-28 15:28:50 +08:00
class LESS
{
public:
bool operator() (const CString &strA, const CString &strB) const
{
CString strChA, strChB, strNumA, strNumB;
SplitString(strA, strChA, strNumA);
SplitString(strB, strChB, strNumB);
if (strChA < strChB)
{
return true;
}
else if (strChA > strChB)
{
return false;
}
else
{
int nA = 0, nB = 0;
nA = _ttoi(strNumA);
nB = _ttoi(strNumB);
if (nA <= nB)
{
return true;
}
return false;
}
return true;
}
private:
void SplitString(const CString &str, CString &strCh, CString &strNum) const
{
int nLen = str.GetLength();
int i = nLen - 1;
TCHAR ch;
for (; i >= 0; i--)
{
ch = str.GetAt(i);
if (ch >= _T('0') && ch <= _T('9'))
{
continue;
}
break;
}
strNum = str.Right(nLen - i - 1);
strCh = str.Left(i + 1);
}
};
2026-10-04 00:04:20 +08:00
// 获取管道高程
// 输入: strPipeTye 管道类型; ptIns 交叉编号图块插入点
// 输出: dHigh 管道高程; strHighType 标高类型
2026-09-28 15:28:50 +08:00
void GetPipeElevation(const TDbPipe *pPipe, const XPoint &ptIns, const CString &strPipeType, double &dHigh, CString &strHighType)
{
if (pPipe != NULL)
{
2026-10-04 00:04:20 +08:00
// cet 2013.1.24 modify 给水、中水、消防有低中高三种类型,名称不同
// if(strPipeType.Compare(_T("给水")) == 0 || strPipeType.Compare(_T("中水")) == 0
// || strPipeType.Compare(_T("消防")) == 0)
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
// zxl 2013.07.05 modify 其他管线都为压力流
// if(strPipeType.Find(_T("给水")) != -1 || strPipeType.Find(_T("中水")) != -1
// || strPipeType.Find(_T("消防")) != -1 || strPipeType.Find(_T("喷淋")) != -1)
2026-09-28 15:28:50 +08:00
// {
2026-10-04 00:04:20 +08:00
strHighType = _T("CEN"); // 管子中心的标高
2026-09-28 15:28:50 +08:00
// }
// else
2026-10-04 00:04:20 +08:00
if (strPipeType.Compare(_T("污水")) == 0 || strPipeType.Compare(_T("废水")) == 0
|| strPipeType.Compare(_T("雨水")) == 0 || strPipeType.Compare(_T("其它管")) == 0)
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
strHighType = _T("BOT"); // 管内底标高
2026-09-28 15:28:50 +08:00
}
double dUnitMeter = 1000;
if(DocGetMeterUnitDraw())
{
dUnitMeter = 1;
}
double dI = pPipe->GetPipeGradient();
double dn = pPipe->GetDnDiameter();
int iMaterial = pPipe->GetMaterial();
CString csMat = GetPipeMaterialByIdx(iMaterial);
2026-10-04 00:04:20 +08:00
dn = GetPipeDjByDn(csMat, (int)dn); //内径
2026-09-28 15:28:50 +08:00
// zxl modify 2013.07.04
// TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
// XPoint ptWell;
// if(dir == TPipeSys::kFromStart)
// {
// if (strHighType.Compare(_T("CEN")) == 0)
// {
// dHigh = pPipe->StartPoint().z / dUnitMeter;
// }
// else
// {
// dHigh = pPipe->StartPoint().z / dUnitMeter - dn / 2;
// }
// ptWell = pPipe->StartPoint();
// }
// else
// {
// if (strHighType.Compare(_T("CEN")) == 0)
// {
// dHigh = pPipe->EndPoint().z / dUnitMeter;
// }
// else
// {
// dHigh = pPipe->EndPoint().z / dUnitMeter - dn / 2;
// }
// ptWell = pPipe->EndPoint();
// }
// ptWell.z = 0;
// double nDistWell = ads_distance(ptIns, ptWell) / dUnitMeter;
// dHigh = dHigh - nDistWell * dI;
AcGePoint3d pt = ptIns;
pt.z = 100;
AcDbLine line(pt, ptIns);
AcGePoint3dArray arrays;
arrays.setLogicalLength(0);
line.intersectWith(pPipe, AcDb::kExtendBoth, arrays);
if (arrays.length() == 1)
{
pt = arrays[0];
}
if (strHighType.Compare(_T("CEN")) == 0)
{
dHigh = pt.z / dUnitMeter;
}
else
{
dHigh = pt.z / dUnitMeter - dn / 2;
}
}
}
2026-10-04 00:04:20 +08:00
// 获取图块插入点和编号
2026-09-28 15:28:50 +08:00
// zxl 2013.07.05 modify
// void GetBlockPosNum(Entity &ent, XPoint &ptIns, CString& strNum)
void GetBlockPosNum(Entity &ent, XPoint &ptIns, CString& strNum, double &dSc)
{
AcDbBlockReference *pRef = NULL;
AcDbObjectId ident;
acdbGetObjectId(ident, ent);
acdbOpenObject(pRef, ident, AcDb::kForRead);
if (pRef != NULL)
{
ptIns = pRef->position();
// zxl 2013.07.05 add
AcGeScale3d sc = pRef->scaleFactors();
dSc = sc[0];
AcDbObjectIterator *pIter=pRef->attributeIterator();
if (pIter != NULL)
{
AcDbObjectId idAtt = AcDbObjectId::kNull;
for (pIter->start(); !pIter->done(); pIter->step())
{
idAtt = pIter->objectId();
AcDbEntity *pEntAtrri = NULL;
Acad::ErrorStatus stus = acdbOpenAcDbEntity(pEntAtrri, idAtt, AcDb::kForWrite);
if (stus == Acad::eOk)
{
AcDbAttribute *pAtt = AcDbAttribute::cast(pEntAtrri);
if (pAtt != NULL)
{
2026-10-04 00:04:20 +08:00
TCHAR *pszName = pAtt->tag(); //得到标记
if(_tcsicmp(pszName, _T("交点编号")) == 0)
2026-09-28 15:28:50 +08:00
{
strNum = pAtt->textString();
}
}
pEntAtrri->close();
}
}
delete pIter;
pIter = NULL;
}
pRef->close();
}
}
2026-10-04 00:04:20 +08:00
// 获取两管相对位置
2026-09-28 15:28:50 +08:00
void GetPipeOppositePos(const AcDbObjectId id1, const AcDbObjectId id2, CString &strPos1, CString &strPos2)
{
TDbPipe *pPipe1 = NULL, *pPipe2 = NULL;
AcGePoint3d ptS1, ptS2, ptE1, ptE2;
double dDia1 = 0.0, dDia2 = 0.0;
acdbOpenObject(pPipe1, id1, AcDb::kForRead);
if (pPipe1 != NULL)
{
ptS1 = pPipe1->StartPoint();
ptE1 = pPipe1->EndPoint();
dDia1 = GetPipeOutDByDn(pPipe1->GetMaterial(), pPipe1->GetDnDiameter());
pPipe1->Close();
}
acdbOpenObject(pPipe2, id2, AcDb::kForRead);
if (pPipe2 != NULL)
{
ptS2 = pPipe2->StartPoint();
ptE2 = pPipe2->EndPoint();
dDia2 = GetPipeOutDByDn(pPipe2->GetMaterial(), pPipe2->GetDnDiameter());
pPipe2->Close();
}
2026-10-04 00:04:20 +08:00
// 构造经过原点的平面
2026-09-28 15:28:50 +08:00
AcGeVector3d vePipe1, vePipe2;
vePipe1 = ptE1 - ptS1;
vePipe2 = ptE2 - ptS2;
AcGePlane plan(AcGePoint3d::kOrigin, vePipe1, vePipe2);
AcGePoint3d pt1, pt2;
2026-10-04 00:04:20 +08:00
pt1 = ptS1.orthoProject(plan); // 获得管线上的一点到平面的投影
2026-09-28 15:28:50 +08:00
pt2 = ptS2.orthoProject(plan);
double dDist1 = 0.0, dDist2 = 0.0;
dDist1 = pt1.distanceTo(ptS1);
dDist2 = pt2.distanceTo(ptS2);
if (dDist1 >= dDist2)
{
2026-10-04 00:04:20 +08:00
strPos1 = _T("上行");
strPos2 = _T("下行");
2026-09-28 15:28:50 +08:00
}
else
{
2026-10-04 00:04:20 +08:00
strPos1 = _T("下行");
strPos2 = _T("上行");
2026-09-28 15:28:50 +08:00
}
}
2026-10-04 00:04:20 +08:00
// 垂直净距
// 重新定义垂直净距 zxl 2013.07.04 modify
2026-09-28 15:28:50 +08:00
// double Get2PipeDistance(const AcDbObjectId id1, const AcDbObjectId id2)
double Get2PipeDistance(const AcDbObjectId id1, const AcDbObjectId id2, const AcGePoint3d ptInt)
{
double dDist = 0.0;
TDbPipe *pPipe1 = NULL, *pPipe2 = NULL;
AcGePoint3d ptS1, ptS2, ptE1, ptE2;
double dDia1 = 0.0, dDia2 = 0.0;
AcGePoint3d pt = ptInt;
pt.z = 100;
AcDbLine line(ptInt, pt);
AcGePoint3dArray arrays;
acdbOpenObject(pPipe1, id1, AcDb::kForRead);
if (pPipe1 != NULL)
{
// zxl 2013.07.04 modify
// ptS1 = pPipe1->StartPoint();
// ptE1 = pPipe1->EndPoint();
arrays.setLogicalLength(0);
line.intersectWith(pPipe1, AcDb::kExtendBoth, arrays);
if (arrays.length() == 1)
{
pt = arrays[0];
}
dDia1 = GetPipeOutDByDn(pPipe1->GetMaterial(), pPipe1->GetDnDiameter());
pPipe1->Close();
}
acdbOpenObject(pPipe2, id2, AcDb::kForRead);
if (pPipe2 != NULL)
{
// zxl 2013.07.04 modify
// ptS2 = pPipe2->StartPoint();
// ptE2 = pPipe2->EndPoint();
arrays.setLogicalLength(0);
line.intersectWith(pPipe2, AcDb::kExtendBoth, arrays);
if (arrays.length() == 1)
{
ptS2 = arrays[0];
}
dDia2 = GetPipeOutDByDn(pPipe2->GetMaterial(), pPipe2->GetDnDiameter());
pPipe2->Close();
}
// zxl 2013.07.04 modify
// AcGeVector3d vePipe1, vePipe2;
// vePipe1 = ptE1 - ptS1;
// vePipe2 = ptE2 - ptS2;
// AcGePlane plan(ptS1, vePipe1, vePipe2);
// AcGePoint3d pt;
// pt = ptS2.orthoProject(plan);
double dUnitMeter = 1;
if(DocGetMeterUnitDraw())
{
dUnitMeter = 1000;
}
dDist = pt.distanceTo(ptS2) - (dDia1 + dDia2) / (2 * dUnitMeter);
2026-10-04 00:04:20 +08:00
// 转换为m
2026-09-28 15:28:50 +08:00
if (!DocGetMeterUnitDraw())
{
dDist /= 1000;
}
return dDist;
}
void InsPerpeDistTable(std::multimap<CString, TABLEIFO, LESS> &mapData)
{
2026-10-04 00:04:20 +08:00
double nTextSize = g_nSheetHeight; //字高
2026-09-28 15:28:50 +08:00
double nTableHeight = g_nSheetHeight+2;
XPoint pt;
2026-10-04 00:04:20 +08:00
if(acedGetPoint(NULL, _T("\n点取表格左上角位置"), pt) != RTNORM)
2026-09-28 15:28:50 +08:00
{
return;
}
AcDbObjectId idTextStyle=InitTwtTextStyle(g_csSheetStyle);
TDbSheet *pSheet = new TDbSheet;
TGridStyle gridStyle;
gridStyle.SetOverrideAll(TRUE);
gridStyle.SetTextHeight(nTextSize);
gridStyle.SetTextStyleId(idTextStyle);
TSheetTitle &title=pSheet->GetTitle();
title.SetHeight(7.0);
2026-10-04 00:04:20 +08:00
title.SetText(_T("管道交叉垂距表"));
2026-09-28 15:28:50 +08:00
TGridStyle &gridStyle2=title.GetGridStyle();
gridStyle2.SetTextHeight(nTextSize);
gridStyle2.SetTextStyleId(idTextStyle);
TDividerStyle &style=title.GetDividerStyle();
style.SetDividerFlag(TDividerStyle::kNone);
gridStyle.SetHorMode(AcDb::kTextCenter);
gridStyle.SetVerMode(AcDb::kTextVertMid);
gridStyle.SetLineSpaceFactor(0.2);
gridStyle.SetTextWrap(FALSE);
pSheet->SetGridStyle(gridStyle);
pSheet->SetRowHeight(nTableHeight);
pSheet->SetLayoutRotation(Ucs2Wcs(0.0));
int nAllRow(0);
nAllRow = (int)mapData.size() * 2;
pSheet->InitSheet(nAllRow + 1, 8, nTableHeight, 50);
TSheetColumn column;
2026-10-04 00:04:20 +08:00
column.SetWidth(15); //交点编号
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(0, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(15); //管道类型
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(1, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(15); //管道规格
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(2, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(20); //管道高程
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(3, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(15); //标高类型
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(4, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(15); //相对位置
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(5, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(20); //垂直净距
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(6, column);
2026-10-04 00:04:20 +08:00
column.SetWidth(15); //备注
2026-09-28 15:28:50 +08:00
pSheet->SetColumnAt(7, column);
TGridCell &cell=*(*pSheet)(0, 0);
2026-10-04 00:04:20 +08:00
cell.SetText(_T("交点编号"));
2026-09-28 15:28:50 +08:00
TGridCell &cell2=*(*pSheet)(0, 1);
2026-10-04 00:04:20 +08:00
cell2.SetText(_T("管道类型"));
2026-09-28 15:28:50 +08:00
TGridCell &cell3=*(*pSheet)(0, 2);
2026-10-04 00:04:20 +08:00
cell3.SetText(_T("管道规格"));
2026-09-28 15:28:50 +08:00
TGridCell &cell4=*(*pSheet)(0, 3);
2026-10-04 00:04:20 +08:00
cell4.SetText(_T("管道高程(m)"));
2026-09-28 15:28:50 +08:00
TGridCell &cell5=*(*pSheet)(0, 4);
2026-10-04 00:04:20 +08:00
cell5.SetText(_T("标高类型"));
2026-09-28 15:28:50 +08:00
TGridCell &cell6=*(*pSheet)(0, 5);
2026-10-04 00:04:20 +08:00
cell6.SetText(_T("相对位置"));
2026-09-28 15:28:50 +08:00
TGridCell &cell7=*(*pSheet)(0, 6);
2026-10-04 00:04:20 +08:00
cell7.SetText(_T("垂直净距(m)"));
2026-09-28 15:28:50 +08:00
TGridCell &cell8=*(*pSheet)(0, 7);
2026-10-04 00:04:20 +08:00
cell8.SetText(_T("备注"));
2026-09-28 15:28:50 +08:00
pSheet->SetLocation(Ucs2Wcs(pt));
int index=0;
std::multimap<CString, TABLEIFO, LESS>::iterator iter;
TABLEIFO info;
for(iter = mapData.begin(); iter != mapData.end(); iter++)
{
info = (*iter).second;
index++;
index++;
pSheet->MergeCells(index - 1, 0, index, 0);
TGridCell &Cell11=*(*pSheet)(index, 0);
Cell11.SetText(info.strNum);
TGridCell &Cell12=*(*pSheet)(index - 1, 1);
Cell12.SetText(info.pipeInfo1.strPipeType);
TGridCell &Cell22=*(*pSheet)(index, 1);
Cell22.SetText(info.pipeInfo2.strPipeType);
TGridCell &Cell13=*(*pSheet)(index - 1, 2);
Cell13.SetText(info.pipeInfo1.strPipeSpec);
TGridCell &Cell23=*(*pSheet)(index, 2);
Cell23.SetText(info.pipeInfo2.strPipeSpec);
TGridCell &Cell14=*(*pSheet)(index - 1, 3);
Cell14.SetText(info.pipeInfo1.strPipeHigh);
TGridCell &Cell24=*(*pSheet)(index, 3);
Cell24.SetText(info.pipeInfo2.strPipeHigh);
TGridCell &Cell15=*(*pSheet)(index - 1, 4);
Cell15.SetText(info.pipeInfo1.strHighType);
TGridCell &Cell25=*(*pSheet)(index, 4);
Cell25.SetText(info.pipeInfo2.strHighType);
TGridCell &Cell16=*(*pSheet)(index - 1, 5);
Cell16.SetText(info.pipeInfo1.strOppositePos);
TGridCell &Cell26=*(*pSheet)(index, 5);
Cell26.SetText(info.pipeInfo2.strOppositePos);
pSheet->MergeCells(index - 1, 6, index, 6);
TGridCell &Cell17=*(*pSheet)(index, 6);
Cell17.SetText(info.strDist);
pSheet->MergeCells(index - 1, 7, index,7);
TGridCell &Cell18=*(*pSheet)(index, 7);
Cell18.SetText(info.strRemark);
}
pSheet->AddToCSpace(TRUE);
}
2026-10-04 00:04:20 +08:00
// 改变图块颜色
2026-09-28 15:28:50 +08:00
void SetBlockColor(const AcDbObjectId idBlock, int nColor)
{
AcDbBlockReference *pRef = NULL;
Acad::ErrorStatus sts = acdbOpenObject(pRef, idBlock, AcDb::kForWrite);
if (pRef != NULL)
{
2026-10-04 00:04:20 +08:00
//设置块颜色
2026-09-28 15:28:50 +08:00
pRef->setColorIndex(nColor);
AcDbObjectId idBlkRec = AcDbObjectId::kNull;
idBlkRec = pRef->blockTableRecord();
if (!idBlkRec.isValid())
{
return;
}
2026-10-04 00:04:20 +08:00
//设置块引用颜色
2026-09-28 15:28:50 +08:00
AcDbBlockTableRecord *pBlkRec = NULL;
Acad::ErrorStatus st = acdbOpenObject(pBlkRec, idBlkRec, AcDb::kForWrite);
if (pBlkRec != NULL)
{
AcDbBlockTableRecordIterator *pItr = NULL;
pBlkRec->newIterator(pItr);
AcDbEntity *pEnt = NULL;
for (pItr->start(); !pItr->done(); pItr->step())
{
pItr->getEntity(pEnt, AcDb::kForWrite);
if (pEnt != NULL)
{
pEnt->setColorIndex(nColor);
pEnt->close();
}
}
pBlkRec->close();
delete pItr;
pItr = NULL;
}
2026-10-04 00:04:20 +08:00
//设置属性字颜色
2026-09-28 15:28:50 +08:00
AcDbObjectIterator *pIter=pRef->attributeIterator();
if (pIter != NULL)
{
AcDbObjectId idAtt = AcDbObjectId::kNull;
for (pIter->start(); !pIter->done();pIter->step())
{
idAtt = pIter->objectId();
AcDbEntity *pEntAtrri = NULL;
Acad::ErrorStatus stus = acdbOpenAcDbEntity(pEntAtrri, idAtt, AcDb::kForWrite);
if (stus == Acad::eOk)
{
AcDbAttribute *pAtt = AcDbAttribute::cast(pEntAtrri);
if (pAtt != NULL)
{
pAtt->setColorIndex(nColor);
}
pEntAtrri->close();
}
}
delete pIter;
pIter = NULL;
}
pRef->close();
}
}
2026-10-04 00:04:20 +08:00
// 检查有几根管线经过ptIns点,并将经过ptIns点的管线保存于ssSel中
2026-09-28 15:28:50 +08:00
void CheckIsPtOnPipe(XPoint ptIns, PickSet& ssSel)
{
Entity ent;
XPoint pt1, pt2, pt3;
ptIns.z = 0;
PickSet ssAll(SS_FREE);
for (long i = 0; i < ssSel.Length(); i++)
{
ent = ssSel[i];
GetPipePoint(ent, pt1, pt2);
pt1.z = 0;
pt2.z = 0;
AcDbLine line(pt1, pt2);
line.getClosestPointTo(ptIns, pt3);
if (ptIns.Distance(pt3) < 1e-3)
{
ssAll += ent;
}
}
ssSel.Free();
ssSel += ssAll;
}
2026-10-04 00:04:20 +08:00
// 垂距表
2026-09-28 15:28:50 +08:00
void PerpeDistanceTable()
{
2026-10-04 00:04:20 +08:00
// 选择交点编号
RBList rbMask(RTDXF0, _T("INSERT"), 8, _T("TWT_室外"), NULL);
2026-09-28 15:28:50 +08:00
PickSet ssAll(SS_FREE);
int nStatus(0);
TCHAR chKey;
INITGET_BEG(0, _T("P"));
2026-10-04 00:04:20 +08:00
nStatus = SelectEntities(_T("\n请框选范围{选择闭合pline线(P)}:<整张图>"), ssAll, rbMask, _T("P"), chKey);
2026-09-28 15:28:50 +08:00
INITGET_END();
2026-10-04 00:04:20 +08:00
if (nStatus == RTKWORD) //选择关键字
2026-09-28 15:28:50 +08:00
{
Entity entPoly;
RBList rbMask2(RTDXF0, _T("LWPOLYLINE"), 8, _T("*"), NULL);
2026-10-04 00:04:20 +08:00
if(SelectEntity(_T("\n请选择表示范围的闭合PLINE:<退出>"), entPoly, rbMask2) != RTNORM)
2026-09-28 15:28:50 +08:00
{
return;
}
AcDbObjectId idLine;
acdbGetObjectId(idLine, entPoly);
AcDbPolyline *pPLine = NULL;
acdbOpenObject(pPLine, idLine, AcDb::kForRead);
if (pPLine != NULL)
{
if (!pPLine->isClosed())
{
pPLine->close();
return;
}
pPLine->close();
}
XPoly2D poly2(entPoly);
XPoint ptLow3, ptUp3;
poly2.GetExtend(ptLow3, ptUp3);
poly2.TransUCS(Groups(0), Groups(1)); //Groups(0) wcs, Groups(1) ucs
RBList rbFence = poly2.Fence();
AssureInCurrentView(ptLow3, ptUp3);
ssAll.Get(_T("CP"), rbFence, NULL, rbMask);
}
2026-10-04 00:04:20 +08:00
else if (nStatus == RTERROR) //默认选择
2026-09-28 15:28:50 +08:00
{
acedSSGet(_T("A"), NULL, NULL, rbMask, ssAll);
}
else if(nStatus != RTNORM)
{
return;
}
if (ssAll.Length() == 0)
{
return;
}
Entity ent;
AcDbObjectId idPipe1, idPipe2;
Entity entPipe1, entPipe2;
AcDbObjectId idBlock;
std::multimap<CString, TABLEIFO, LESS> mapData;
for (long i = 0; i < ssAll.Length(); i++)
{
ent = ssAll[i];
acdbGetObjectId(idBlock, ent);
2026-10-04 00:04:20 +08:00
// 获取图块插入点和属性字编号
2026-09-28 15:28:50 +08:00
XPoint ptIns;
CString strNum;
// zxl 2013.07.05 modify
// GetBlockPosNum(ent, ptIns, strNum);
double dScale = 0.0;
GetBlockPosNum(ent, ptIns, strNum, dScale);
ptIns.z = 0;
2026-10-04 00:04:20 +08:00
// 获取交点编号处的管子
2026-09-28 15:28:50 +08:00
XPoint pt1, pt2, pt3, pt4;
// zxl 2013.07.05 modify
//const double dLen = 2 * DocGetPScale();
const double dLen = 2 * dScale;
ptIns = Wcs2Ucs(ptIns);
pt1 = ptIns - AcGeVector3d::kXAxis * dLen + AcGeVector3d::kYAxis * dLen;
pt2 = ptIns - AcGeVector3d::kXAxis * dLen - AcGeVector3d::kYAxis * dLen;
pt3 = pt2 + AcGeVector3d::kXAxis * 2 * dLen;
pt4 = pt1 + AcGeVector3d::kXAxis * 2 * dLen;
ptIns = Ucs2Wcs(ptIns);
PickSet ssSel(SS_FREE);
2026-10-04 00:04:20 +08:00
RBList rbMask2(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL);
2026-09-28 15:28:50 +08:00
RBList rbPt = acutBuildList(RTPOINT,&pt1,RTPOINT,&pt2,RTPOINT,&pt3,RTPOINT,&pt4,NULL);
acedSSGet(_T("CP"),rbPt,NULL,rbMask2,ssSel);
if (ssSel.Length() == 2)
{
entPipe1 = ssSel[0l];
entPipe2 = ssSel[1l];
}
else if (ssSel.Length() > 2)
{
2026-10-04 00:04:20 +08:00
// 检查有几根管线经过ptIns点
2026-09-28 15:28:50 +08:00
CheckIsPtOnPipe(ptIns, ssSel);
if (ssSel.Length() != 2)
{
TABLEIFO info;
info.strNum = strNum;
2026-10-04 00:04:20 +08:00
info.strRemark = _T("错误");
2026-09-28 15:28:50 +08:00
mapData.insert(std::make_pair(strNum, info));
continue;
}
entPipe1 = ssSel[0l];
entPipe2 = ssSel[1l];
}
else
{
TABLEIFO info;
info.strNum = strNum;
2026-10-04 00:04:20 +08:00
info.strRemark = _T("错误");
2026-09-28 15:28:50 +08:00
mapData.insert(std::make_pair(strNum, info));
continue;
}
acdbGetObjectId(idPipe1, entPipe1);
acdbGetObjectId(idPipe2, entPipe2);
2026-10-04 00:04:20 +08:00
// 求交点
GetPipePoint(entPipe1, pt1, pt2); // 获取管线起始点
2026-09-28 15:28:50 +08:00
GetPipePoint(entPipe2, pt3, pt4);
pt1[Z] = 0;
pt2[Z] = 0;
pt3[Z] = 0;
pt4[Z] = 0;
AcDbLine l1(pt1, pt2), l2(pt3, pt4);
AcGePoint3dArray arPt;
l1.intersectWith(&l2, AcDb::kOnBothOperands, arPt);
AcGePoint3d ptInt;
2026-10-04 00:04:20 +08:00
if (arPt.length() == 1) // 相交
2026-09-28 15:28:50 +08:00
{
ptInt = arPt[0];
}
2026-10-04 00:04:20 +08:00
else // 无交点
2026-09-28 15:28:50 +08:00
{
TABLEIFO info;
info.strNum = strNum;
2026-10-04 00:04:20 +08:00
info.strRemark = _T("错误");
2026-09-28 15:28:50 +08:00
mapData.insert(std::make_pair(strNum, info));
continue;
}
2026-10-04 00:04:20 +08:00
// 获取管子信息
2026-09-28 15:28:50 +08:00
TDbPipe *pPipe1 = NULL;
TPipeSys::SysType sys1;
2026-10-04 00:04:20 +08:00
CString strPipeType1; // 管道类型
CString strPipeSpec1; // 管道规格
double dHigh1 = 0.0; // 管道高程
CString strType1; // 标高类型
2026-09-28 15:28:50 +08:00
acdbOpenObject(pPipe1, idPipe1, AcDb::kForRead);
if (pPipe1 != NULL)
{
sys1 = pPipe1->GetSysType();
CString strLabel = pPipe1->GetLabel();
double dPipeDia = pPipe1->GetDnDiameter();
CString strTmp;
strTmp.Format(_T("%.0f"), dPipeDia);
strPipeSpec1 = strLabel + strTmp;
strPipeType1 = GetPipeNameBySys(sys1);
GetPipeElevation(pPipe1, ptInt, strPipeType1, dHigh1, strType1);
pPipe1->close();
}
TDbPipe *pPipe2 = NULL;
TPipeSys::SysType sys2;
2026-10-04 00:04:20 +08:00
CString strPipeType2; // 管道类型
CString strPipeSpec2; // 管道规格
double dHigh2 = 0.0; // 管道高程
CString strType2; // 标高类型
2026-09-28 15:28:50 +08:00
acdbOpenObject(pPipe2, idPipe2, AcDb::kForRead);
if (pPipe2 != NULL)
{
sys2 = pPipe2->GetSysType();
CString strLabel = pPipe2->GetLabel();
double dPipeDia = pPipe2->GetDnDiameter();
CString strTmp;
strTmp.Format(_T("%.0f"), dPipeDia);
strPipeSpec2 = strLabel + strTmp;
strPipeType2 = GetPipeNameBySys(sys2);
GetPipeElevation(pPipe2, ptInt, strPipeType2, dHigh2, strType2);
pPipe2->close();
}
CString strPos1, strPos2;
double dDist = 0.0;
2026-10-04 00:04:20 +08:00
// 求两管相对位置: 上行, 下行
2026-09-28 15:28:50 +08:00
// GetPipeOppositePos(idPipe1, idPipe2, strPos1, strPos2); zxl 2013.07.05 modify
if (dHigh1 >= dHigh2)
{
2026-10-04 00:04:20 +08:00
strPos1 = _T("上行");
strPos2 = _T("下行");
2026-09-28 15:28:50 +08:00
}
else
{
2026-10-04 00:04:20 +08:00
strPos1 = _T("下行");
strPos2 = _T("上行");
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
// 求垂直净距
// 重新定义垂直净距 zxl 2013.07.04 modify
2026-09-28 15:28:50 +08:00
// dDist = Get2PipeDistance(idPipe1, idPipe2);
dDist = Get2PipeDistance(idPipe1, idPipe2, ptInt);
2026-10-04 00:04:20 +08:00
// 保存信息
2026-09-28 15:28:50 +08:00
TABLEIFO info;
int nNum = _ttoi(strNum);
info.strNum = strNum;
CString strTmp;
2026-10-04 00:04:20 +08:00
if (strPos1.Compare(_T("上行")) == 0)
2026-09-28 15:28:50 +08:00
{
info.pipeInfo1.strPipeType = strPipeType1;
info.pipeInfo2.strPipeType = strPipeType2;
info.pipeInfo1.strPipeSpec = strPipeSpec1;
info.pipeInfo2.strPipeSpec = strPipeSpec2;
strTmp.Format(_T("%.3f"), dHigh1);
info.pipeInfo1.strPipeHigh = strTmp;
strTmp.Format(_T("%.3f"), dHigh2);
info.pipeInfo2.strPipeHigh = strTmp;
info.pipeInfo1.strHighType = strType1;
info.pipeInfo2.strHighType = strType2;
info.pipeInfo1.strOppositePos = strPos1;
info.pipeInfo2.strOppositePos = strPos2;
}
else
{
info.pipeInfo1.strPipeType = strPipeType2;
info.pipeInfo2.strPipeType = strPipeType1;
info.pipeInfo1.strPipeSpec = strPipeSpec2;
info.pipeInfo2.strPipeSpec = strPipeSpec1;
strTmp.Format(_T("%.3f"), dHigh2);
info.pipeInfo1.strPipeHigh = strTmp;
strTmp.Format(_T("%.3f"), dHigh1);
info.pipeInfo2.strPipeHigh = strTmp;
info.pipeInfo1.strHighType = strType2;
info.pipeInfo2.strHighType = strType1;
info.pipeInfo1.strOppositePos = strPos2;
info.pipeInfo2.strOppositePos = strPos1;
}
if (dDist > 0.0)
{
strTmp.Format(_T("%.3f"), dDist);
info.strDist = strTmp;
}
else
{
2026-10-04 00:04:20 +08:00
info.strDist = _T("相交");
2026-09-28 15:28:50 +08:00
}
mapData.insert(std::make_pair(strNum, info));
}
2026-10-04 00:04:20 +08:00
// 生成表格
2026-09-28 15:28:50 +08:00
InsPerpeDistTable(mapData);
}