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

2353 lines
59 KiB
C++

// PipeInterCheckDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PipeInterCheckDlg.h"
#include "DbPsConfig.h"
#include "PipeWireMonitor.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
namespace
{
CString getClassName(ads_name ent)
{
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt)
{
if (!pEnt) return _T("");
return pEnt->isA()->name();
}
OPENOBJ_END()
}
bool IsEwPipe(ads_name ent)
{
CString className(getClassName(ent));
return CString(_T("AecDbEwPipe")) == className;
}
bool IsEwPipe(AcDbObjectId &id)
{
ads_name ent;
acdbGetAdsName(ent, id);
return IsEwPipe(ent);
}
CString GetArxDir()
{
TCHAR szPath[MAX_PATH];
::GetModuleFileName(_hdllInstance, szPath, MAX_PATH);
CString sPath(szPath);
sPath = sPath.Left(sPath.ReverseFind(_T('\\')));
return sPath;
}
template <class T>
bool loadCoreDll(T &proc, LPCSTR func, HINSTANCE &hmod)
{
if (!func) return false;
hmod = ::LoadLibrary(GetArxDir() + _T("\\CoreCommand.arx"));
if (!hmod) return false;
proc = (T)::GetProcAddress(hmod, func);
if (!proc)
{
::FreeLibrary(hmod);
return false;
}
return true;
}
#define func_process_void(sfunc, ...)\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadCoreDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
#define func_process_pt(sfunc, ...)\
AcGePoint3d pt(AcGePoint3d::kOrigin);\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadCoreDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
pt = proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
return pt
#define func_process_double(sfunc, ...)\
double d(.0);\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadCoreDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
d = proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
return d
#define func_process_int(sfunc, resType, ...)\
int d(0);\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadCoreDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
d = proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
return (resType)d
#define define_func_by_id(func_name, return_type)\
return_type func_name(AcDbObjectId id)\
{\
ads_name ent;\
acdbGetAdsName(ent, id);\
return func_name(ent);\
}
AcGePoint3d MidPoint(ads_name ent)
{
typedef AcGePoint3d (_cdecl *func_MidPoint)(ads_name);
func_process_pt(MidPoint, ent);
}
define_func_by_id(MidPoint, AcGePoint3d)
AcGePoint3d GetStartPoint(ads_name ent)
{
typedef AcGePoint3d (_cdecl *func_GetStartPoint)(ads_name);
func_process_pt(GetStartPoint, ent);
}
define_func_by_id(GetStartPoint, AcGePoint3d)
AcGePoint3d GetEndPoint(ads_name ent)
{
typedef AcGePoint3d (_cdecl *func_GetEndPoint)(ads_name);
func_process_pt(GetEndPoint, ent);
}
define_func_by_id(GetEndPoint, AcGePoint3d)
TPipeSys::FlowDirection GetFlowDir(ads_name ent)
{
typedef int (_cdecl *func_GetFlowDir)(ads_name);
func_process_int(GetFlowDir, TPipeSys::FlowDirection, ent);
}
define_func_by_id(GetFlowDir, TPipeSys::FlowDirection)
TPipeSys::SysType GetSysType(ads_name ent)
{
typedef int (_cdecl *func_GetSysType)(ads_name);
func_process_int(GetSysType, TPipeSys::SysType, ent);
}
define_func_by_id(GetSysType, TPipeSys::SysType)
double GetPipeOutDByDn(ads_name ent)
{
typedef double (_cdecl *func_GetPipeOutDByDn)(ads_name);
func_process_double(GetPipeOutDByDn, ent);
}
define_func_by_id(GetPipeOutDByDn, double)
double GetDnDiameter(ads_name ent)
{
typedef double(_cdecl *func_GetDnDiameter)(ads_name);
func_process_double(GetDnDiameter, ent);
}
define_func_by_id(GetDnDiameter, double)
double GetPipeDjByDn(ads_name ent)
{
typedef double(_cdecl *func_GetPipeDjByDn)(ads_name);
func_process_double(GetPipeDjByDn, ent);
}
define_func_by_id(GetPipeDjByDn, double)
double GetPipeThick(ads_name ent)
{
typedef double(_cdecl *func_GetPipeThick)(ads_name);
func_process_double(GetPipeThick, ent);
}
define_func_by_id(GetPipeThick, double)
double GetPipeGradient(ads_name ent)
{
typedef double(_cdecl *func_GetPipeGradient)(ads_name);
func_process_double(GetPipeGradient, ent);
}
define_func_by_id(GetPipeGradient, double)
AcDbObjectId GetID(ads_name ent)
{
AcDbObjectId id(AcDbObjectId::kNull);
acdbGetObjectId(id, ent);
return id;
}
void _GetPipePoint(Entity ent, XPoint &pt1, XPoint &pt2)
{
if (!IsEwPipe(ent))
{
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe) {
pt1 = pPipe->StartPoint();
pt2 = pPipe->EndPoint();
}
OPENOBJ_END();
}
else
{
pt1 = GetStartPoint(ent);
pt2 = GetEndPoint(ent);
}
}
void SetStartPoint(ads_name ent, const AcGePoint3d &pt)
{
typedef void(_cdecl *func_SetStartPoint)(ads_name, const AcGePoint3d &);
func_process_void(SetStartPoint, ent, pt);
}
void SetStartPoint(AcDbObjectId id, const AcGePoint3d &pt)
{
ads_name ent;
acdbGetAdsName(ent, id);
SetStartPoint(ent, pt);
}
void SetEndPoint(ads_name ent, const AcGePoint3d &pt)
{
typedef void(_cdecl *func_SetEndPoint)(ads_name, const AcGePoint3d &);
func_process_void(SetEndPoint, ent, pt);
}
void SetEndPoint(AcDbObjectId id, const AcGePoint3d &pt)
{
ads_name ent;
acdbGetAdsName(ent, id);
SetEndPoint(ent, pt);
}
ads_real GetPlanLength(ads_name ent)
{
double len(0);
XPoint ptS = GetStartPoint(ent);
XPoint ptE = GetEndPoint(ent);
ptS.z = 0;
ptE.z = 0;
len = ads_distance(ptS, ptE);//2008-11-24 米单位下显示长度是错的,现改为平面投影长度
if (!DocGetMeterUnitDraw())
len = len / 1000.0;
return len;
}
ads_real GetPlanLength(AcDbObjectId id)
{
ads_name ent;
acdbGetAdsName(ent, id);
return GetPlanLength(ent);
}
}
extern BOOL SearchOutdoorWell(Entity ent, Entity entEnd, SSearchPipeList *pListAll, PickSet &ssAll, BOOL bFeedSys);
extern BOOL GetWellListData2(SSearchPipeList *pListAll, DList<TWellData> &lstWellSys);
static CPipeInterCheckDlg *pDlg = NULL;
void CheckPipeInter()
{
RBList rbMask(RTDXF0, _T("ATS_PIPE,AEC_EWPIPE"), NULL);
PickSet ss(SS_FREE);
int nRet = SelectEntities(_T("\n请选择检查范围<整张图>:"), ss, rbMask);
if (nRet == RTCAN)
{
return;
}
else if (nRet != RTNORM)
{
ss.Get(_T("X"), NULL, NULL, rbMask);
}
if (ss.Length() == 0)
{
return;
}
CTemporaryResourceOverride vTemp;
if (pDlg == NULL)
{
pDlg = new CPipeInterCheckDlg;
pDlg->SetSelectedPipes(ss);
pDlg->Create(CPipeInterCheckDlg::IDD, acedGetAcadFrame());
}
if (pDlg->HasIntersectPipe())
{
pDlg->ShowWindow(SW_SHOW);
TCHAR szTmp[32];
ads_getstring(NULL, _T("\n按任意键退出:"), szTmp);
}
else
{
ads_printf(_T("\n未发现交叉点!"));
}
if (pDlg != NULL)
{
pDlg->DestroyWindow();
delete pDlg;
pDlg = NULL;
}
}
/////////////////////////////////////////////////////////////////////////////
// CPipeInterCheckDlg dialog
BOOL CPipeInterCheckDlg::m_bGrpSetStatus = false;
CPipeInterCheckDlg::CPipeInterCheckDlg(CWnd* pParent /*=NULL*/)
: WGroupDlg(CPipeInterCheckDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPipeInterCheckDlg)
m_dDownLen = 0.4;
m_dSafeDist = 0.0;
m_iDimType = 0;
m_iDownPipeType = 0;
m_iDimPipeNotInter = 0;
m_sElevUp = _T("");
m_sElevLow = _T("");
m_iPreWelldDeep = 3;
m_bIsVisible = true;
m_iCmbType = -1;
//}}AFX_DATA_INIT
}
void CPipeInterCheckDlg::DoDataExchange(CDataExchange* pDX)
{
WGroupDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPipeInterCheckDlg)
DDX_Control(pDX, IDC_COMBO_TYPE, m_cmbPipeType);
DDX_Text(pDX, IDC_EDIT_DOWNLEN, m_csDownLen);
DDX_Text(pDX, IDC_EDIT_SAFEDIST, m_csSafeDist);
DDX_Radio(pDX, IDC_RADIO_DIMTYPE1, m_iDimType);
DDX_Radio(pDX, IDC_RADIO_PIPETYPE1, m_iDownPipeType);
DDX_Radio(pDX, IDC_RADIO_NOTDIM, m_iDimPipeNotInter);
DDX_Text(pDX, IDC_STATIC_ELEV1, m_sElevUp);
DDX_Text(pDX, IDC_STATIC_ELEV2, m_sElevLow);
DDX_Control(pDX, IDC_STATIC_SET, m_grpSet);
DDX_GroupStatus(pDX,IDC_STATIC_SET, m_bGrpSetStatus);
DDX_CBIndex(pDX, IDC_COMBO_TYPE, m_iCmbType);
if (m_csDownLen.GetLength() > 1)
{
m_csDownLen.TrimLeft();
m_csDownLen.TrimRight();
m_csDownLen.TrimRight(_T("0"));
}
m_dDownLen = _tstof(m_csDownLen);
if (m_csSafeDist.GetLength() > 1)
{
m_csSafeDist.TrimLeft();
m_csSafeDist.TrimRight();
m_csSafeDist.TrimRight(_T("0"));
}
m_dSafeDist = _tstof(m_csSafeDist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPipeInterCheckDlg, WGroupDlg)
//{{AFX_MSG_MAP(CPipeInterCheckDlg)
ON_BN_CLICKED(IDC_RADIO_PIPETYPE1, OnRadioPipetype1)
ON_BN_CLICKED(IDC_RADIO_PIPETYPE2, OnRadioPipetype2)
ON_BN_CLICKED(IDC_RADIO_PIPETYPE3, OnRadioPipetype3)
ON_BN_CLICKED(IDC_RADIO_PIPETYPE4, OnRadioPipetype4)
ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType)
ON_WM_DESTROY()
ON_WM_CLOSE()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BTN_QUIT, OnBtnQuit)
ON_BN_CLICKED(IDC_BTN_NOTDOWN, OnBtnNotdown)
ON_BN_CLICKED(IDC_BTN_DOWN, OnBtnDown)
ON_BN_CLICKED(IDC_RADIO_DIMTYPE1, OnRadioDimtype1)
ON_BN_CLICKED(IDC_RADIO_DIMTYPE2, OnRadioDimtype2)
ON_EN_KILLFOCUS(IDC_EDIT_DOWNLEN, OnKillfocusEditDownlen)
ON_EN_KILLFOCUS(IDC_EDIT_SAFEDIST, OnKillfocusEditSafedist)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BTN_AUTODOWN, OnBtnAutoDown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPipeInterCheckDlg message handlers
void CPipeInterCheckDlg::SetSelectedPipes(PickSet ss)
{
m_ssPipe.Free();
std::multimap<double, Entity> mapPipe;
CString className(_T(""));
for (long l = 0l; l < ss.Length(); l++)
{
Entity entPipe = ss[l];
if (!IsEwPipe(entPipe))
{
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe != NULL)
{
XPoint pt = pPipe->MidPoint();
mapPipe.insert(std::make_pair(pt.x, entPipe));
}
OPENOBJ_END();
}
else
{
XPoint pt = MidPoint(entPipe);
mapPipe.insert(std::make_pair(pt.x, entPipe));
}
}
std::multimap<double, Entity>::iterator it;
for (it = mapPipe.begin(); it != mapPipe.end(); it++)
{
m_ssPipe += (*it).second;
}
}
bool CPipeInterCheckDlg::HasIntersectPipe()
{
if (m_mapInterPipeInfo.empty() && m_vecPtUnInter.empty())
{
return false;
}
return true;
}
double CPipeInterCheckDlg::GetPipeStartEle(Entity entPipe)
{
double dUnitMeter = 1000;
if (DocGetMeterUnitDraw())
dUnitMeter = 1;
if (!IsEwPipe(entPipe))
{
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
AcDbObjectId nodeId1(NULL);
double dn = pPipe->GetDnDiameter();
dn = GetPipeOutDByDn(pPipe->GetMaterial(), dn);
dn = dn / 2000;
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
if (dir == TPipeSys::kFromStart) {
return pPipe->StartPoint().z / dUnitMeter - dn;
}
else
{
return pPipe->EndPoint().z / dUnitMeter - dn;
}
}
OPENOBJ_END();
}
else
{
double dn = GetPipeOutDByDn(entPipe);
dn = dn / 2000;
TPipeSys::FlowDirection dir = GetFlowDir(entPipe);
if (dir == TPipeSys::kFromStart)
{
return GetStartPoint(entPipe).z / dUnitMeter - dn;
}
else
{
return GetEndPoint(entPipe).z / dUnitMeter - dn;
}
}
return 0;
}
double CPipeInterCheckDlg::GetPipeThick(Entity& ent)
{
double dThick = 0.0;
if (!IsEwPipe(ent))
{
TDbPipe *pPipe = NULL;
AcDbObjectId ident;
acdbGetObjectId(ident, ent);
double dDn1 = 0.0; // 外径
double dDn2 = 0.0; // 内径
acdbOpenObject(pPipe, ident, AcDb::kForRead);
if (pPipe != NULL)
{
double dDn = pPipe->GetDnDiameter();
int nMat = pPipe->GetMaterial();
dDn1 = GetPipeOutDByDn(nMat, dDn);
dDn1 = dDn1 / 1000;
CString strMat = GetPipeMaterialByIdx(nMat);
dDn2 = GetPipeDjByDn(strMat, (int)dDn);
pPipe->close();
}
dThick = (dDn1 - dDn2) / 2;
}
else
{
dThick = ::GetPipeThick(ent);
}
return dThick;
}
void CPipeInterCheckDlg::InitInterPipeInfo()
{
m_vecPtUnInter.clear();
m_mapInterPipeInfo.clear();
XPointList lstPtInt;
double dUnitMeter = 1000;
if(DocGetMeterUnitDraw())
dUnitMeter = 1;
AcDbObjectId id1, id2;
int len = m_ssPipe.Length();
for(long i = 0; i < m_ssPipe.Length(); i++)
{
Entity ent = m_ssPipe[i];
double nPipeEle(0), nDn(0), nDn2(0), nI(0), nI2(0), nDnPro(0), nDnPro2(0);
TPipeSys::SysType sys1, sys2;
nPipeEle = GetPipeStartEle(ent);
if(fabs(nPipeEle) < 0.001)
continue;
XPoint ptStart, ptEnd, ptInt, ptWell;
CString csMat;
if (!IsEwPipe(ent))
{
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
id1 = pPipe->id();
int iMaterial = pPipe->GetMaterial();
csMat = GetPipeMaterialByIdx(iMaterial);
sys1 = pPipe->GetSysType();
ptStart = pPipe->GetStartPoint();
ptEnd = pPipe->GetEndPoint();
nDnPro = pPipe->GetDnDiameter();
nI = pPipe->GetPipeGradient();
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nDn = GetPipeOutDByDn(csMat, (int)nDnPro);
}
OPENOBJ_END();
}
else
{
id1 = GetID(ent);
nDn = GetPipeOutDByDn(ent);
sys1 = GetSysType(ent);
ptStart = GetStartPoint(ent);
ptEnd = GetEndPoint(ent);
nDnPro = GetDnDiameter(ent);
nI = GetPipeGradient(ent);
TPipeSys::FlowDirection dir = GetFlowDir(ent);
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
}
ptStart.z = 0;
ptEnd.z = 0;
ptWell.z = 0;
AcDbLine line1(ptStart.AsAcGePoint3d(), ptEnd.AsAcGePoint3d());
PickSet ssF(SS_FREE);
RBList rbMask(RTDXF0, _T("ATS_PIPE,AEC_EWPIPE"), NULL);
TADSGePoint3d _pt1(Wcs2Ucs(ptStart)), _pt2(Wcs2Ucs(ptEnd));
acedSSGet(_T("C"), &_pt1, &_pt2, rbMask, ssF);
XPoint ptWell2;
for(long j = 0; j < ssF.Length(); j++)
{
Entity entTmp = ssF[j];
if(entTmp == ent)
continue;
XPoint pt1, pt2;
_GetPipePoint(entTmp, pt1, pt2);
pt1.z = 0;
pt2.z = 0;
AcDbLine line2(pt1.AsAcGePoint3d(), pt2.AsAcGePoint3d());
AcGePoint3dArray arrPt;
line2.intersectWith(&line1, AcDb::kOnBothOperands, arrPt);
if (arrPt.length() != 1)
{
continue;
}
ptInt = arrPt[0];
XPoint *ptFind = lstPtInt.FindPoint(ptInt);
if(ptInt == pt1 || ptInt == pt2 || ptInt == ptStart || ptInt == ptEnd || ptFind != NULL)
continue;
lstPtInt.NewAppend(ptInt);
double nPipeEle1(0), nPipeEle2(0);
double nDist2Well1 = ads_distance(ptInt, ptWell) / dUnitMeter;
nPipeEle1 = nPipeEle - nDist2Well1*nI;
nPipeEle2 = GetPipeStartEle(entTmp);
CString csMat2;
if (!IsEwPipe(entTmp))
{
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
id2 = pPipe->id();
int iMaterial = pPipe->GetMaterial();
csMat2 = GetPipeMaterialByIdx(iMaterial);
sys2 = pPipe->GetSysType();
ptStart = pPipe->StartPoint();
ptEnd = pPipe->EndPoint();
nI2 = pPipe->GetPipeGradient();
nDnPro2 = pPipe->GetDnDiameter();
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
if (dir == TPipeSys::kFromStart)
ptWell2 = ptStart;
else
ptWell2 = ptEnd;
ptWell2.z = 0;
double nDist2Well2 = ads_distance(ptInt, ptWell2) / dUnitMeter;
nPipeEle2 = nPipeEle2 - nDist2Well2 * nI2;
nDn2 = GetPipeOutDByDn(csMat2, (int)nDnPro2);
}
OPENOBJ_END();
}
else
{
id2 = GetID(entTmp);
sys2 = GetSysType(entTmp);
ptStart = GetStartPoint(entTmp);
ptEnd = GetEndPoint(entTmp);
nI2 = GetPipeGradient(entTmp);
nDnPro2 = GetDnDiameter(entTmp);
TPipeSys::FlowDirection dir = GetFlowDir(entTmp);
if (dir == TPipeSys::kFromStart)
ptWell2 = ptStart;
else
ptWell2 = ptEnd;
ptWell2.z = 0;
double nDist2Well2 = ads_distance(ptInt, ptWell2) / dUnitMeter;
nPipeEle2 = nPipeEle2 - nDist2Well2 * nI2;
nDn2 = GetPipeOutDByDn(ent);
}
BOOL bHasInter2=FALSE;
double dPipeEleUp1(0), dPipeEleUp2(0);
if(nPipeEle1 < nPipeEle2)
{
dPipeEleUp1 = nPipeEle1 + nDn;
double dDist2Pipe1 = dPipeEleUp1 - nPipeEle2; //底下管子的顶标高和上面管子底标高的距离
double dDist2Pipe2 = nPipeEle1 - nPipeEle2; //底下管子的底标高和上面管子底标高的距离
if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn) //1判断2管的距离小于安全距离
bHasInter2 = TRUE;
else if(nPipeEle2 > nPipeEle1 && nPipeEle2 < dPipeEleUp1) //2判断上面管子的底标高是否在下面管子内
bHasInter2 = TRUE;
}
else
{
dPipeEleUp2 = nPipeEle2 + nDn2;
double dDist2Pipe1 = dPipeEleUp2 - nPipeEle1;
double dDist2Pipe2 = nPipeEle2 - nPipeEle1;
if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn2)
bHasInter2 = TRUE;
else if(nPipeEle1 > nPipeEle2 && nPipeEle1 < dPipeEleUp2)
bHasInter2 = TRUE;
}
if (fabs(nPipeEle1) < 1e-6)
{
nPipeEle1 = fabs(nPipeEle1);
}
if (fabs(nPipeEle2) < 1e-6)
{
nPipeEle2 = fabs(nPipeEle2);
}
BOOL bIsGravityPipe1(FALSE), bIsGravityPipe2(FALSE);
if(sys1 == TPipeSys::kDirtWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kOther)
bIsGravityPipe1 = TRUE;
if(sys2 == TPipeSys::kDirtWater || sys2 == TPipeSys::kRainWater || sys2 == TPipeSys::kUselessWater || sys2 == TPipeSys::kOther)
bIsGravityPipe2 = TRUE;
InterPipesInfo info;
info.ptInter = ptInt;
// 标高相同时 降落管选取规则为重力流>压力流。
// 两个均为重力流时 污水>废水>雨水>其他重力流。
// 两个均为压力流的时候任意选择一个管线类型即可。
if (nPipeEle1 > nPipeEle2 || (fabs(nPipeEle1 - nPipeEle2) < 0.001 &&
((!bIsGravityPipe1 && bIsGravityPipe2) ||
(sys2 == TPipeSys::kDirtWater && (sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) ||
(sys2 == TPipeSys::kUselessWater && (sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) ||
(sys2 == TPipeSys::kRainWater && sys1 == TPipeSys::kOther))))
{
info.idLow = id2;
info.idUp = id1;
info.dElevLow = nPipeEle2;
info.dElevUp = nPipeEle1;
info.sysLow = sys2;
info.sysUp = sys1;
info.dDnLow = nDnPro2;
info.dDnUp = nDnPro;
if(bHasInter2)// 相交需要移动
{
ads_name name;
acdbGetAdsName(name, id2);
Entity ent = name;
nPipeEle2 += GetPipeThick(ent);
m_mapInterPipeInfo.insert(std::make_pair(nPipeEle2, info));
}
else
{
m_vecPtUnInter.push_back(info);
}
}
else
{
info.idLow = id1;
info.idUp = id2;
info.dElevLow = nPipeEle1;
info.dElevUp = nPipeEle2;
info.sysLow = sys1;
info.sysUp = sys2;
info.dDnLow = nDnPro;
info.dDnUp = nDnPro2;
if(bHasInter2)// 相交需要移动
{
ads_name name;
acdbGetAdsName(name, id1);
Entity ent = name;
nPipeEle1 += GetPipeThick(ent);
m_mapInterPipeInfo.insert(std::make_pair(nPipeEle1, info));
}
else
{
m_vecPtUnInter.push_back(info);
}
}
}
}
m_itCurPipe = m_mapInterPipeInfo.rbegin();
}
void CPipeInterCheckDlg::UpdateInterPipeInfo(const InterPipesInfo infoOld)
{
Entity ent1, ent2;
ads_name name;
acdbGetAdsName(name, infoOld.idLow);
ent1 = name;
acdbGetAdsName(name, infoOld.idUp);
ent2 = name;
double dUnitMeter = 1000;
if(DocGetMeterUnitDraw())
dUnitMeter = 1;
AcDbObjectId id1, id2;
double nPipeEle(0), nDn(0), nDn2(0), nI(0), nI2(0), nDnPro(0), nDnPro2(0);
TPipeSys::SysType sys1, sys2;
nPipeEle = GetPipeStartEle(ent1);
XPoint ptStart, ptEnd, ptInt, ptWell;
CString csMat;
if (!IsEwPipe(ent1))
{
OPENOBJ_BEGIN(ent1, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
id1 = pPipe->id();
int iMaterial = pPipe->GetMaterial();
csMat = GetPipeMaterialByIdx(iMaterial);
sys1 = pPipe->GetSysType();
ptStart = pPipe->StartPoint();
ptEnd = pPipe->EndPoint();
nDnPro = pPipe->GetDnDiameter();
nI = pPipe->GetPipeGradient();
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nDn = GetPipeOutDByDn(csMat, (int)nDnPro);
}
OPENOBJ_END();
}
else
{
id1 = GetID(ent1);
sys1 = GetSysType(ent1);
ptStart = GetStartPoint(ent1);
ptEnd = GetEndPoint(ent1);
nDnPro = GetDnDiameter(ent1);
nI = GetPipeGradient(ent1);
TPipeSys::FlowDirection dir = GetFlowDir(ent1);
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nDn = GetPipeOutDByDn(ent1);
}
ptInt = infoOld.ptInter;
double nPipeEle1(0), nPipeEle2(0);
double nDist2Well1 = ads_distance(ptInt, ptWell) / dUnitMeter;
nPipeEle1 = nPipeEle - nDist2Well1*nI;
nPipeEle2 = GetPipeStartEle(ent2);
CString csMat2;
if (!IsEwPipe(ent2))
{
OPENOBJ_BEGIN(ent2, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
id2 = pPipe->id();
int iMaterial = pPipe->GetMaterial();
csMat2 = GetPipeMaterialByIdx(iMaterial);
sys2 = pPipe->GetSysType();
ptStart = pPipe->StartPoint();
ptEnd = pPipe->EndPoint();
nI2 = pPipe->GetPipeGradient();
nDnPro2 = pPipe->GetDnDiameter();
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
XPoint ptWell;
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
ptWell.z = 0;
double nDist2Well2 = ads_distance(ptInt, ptWell) / dUnitMeter;
nPipeEle2 = nPipeEle2 - nDist2Well2 * nI2;
nDn2 = GetPipeOutDByDn(csMat2, (int)nDnPro2);
}
OPENOBJ_END();
}
else
{
id2 = GetID(ent2);
sys2 = GetSysType(ent2);
ptStart = GetStartPoint(ent2);
ptEnd = GetEndPoint(ent2);
nI2 = GetPipeGradient(ent2);
nDnPro2 = GetDnDiameter(ent2);
TPipeSys::FlowDirection dir = GetFlowDir(ent2);
XPoint ptWell;
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
ptWell.z = 0;
double nDist2Well2 = ads_distance(ptInt, ptWell) / dUnitMeter;
nPipeEle2 = nPipeEle2 - nDist2Well2 * nI2;
nDn2 = GetPipeOutDByDn(ent2);
}
BOOL bHasInter2 = FALSE;
double dPipeEleUp1(0), dPipeEleUp2(0);
if(nPipeEle1 < nPipeEle2)
{
dPipeEleUp1 = nPipeEle1 + nDn;
double dDist2Pipe1 = dPipeEleUp1 - nPipeEle2; //底下管子的顶标高和上面管子底标高的距离
double dDist2Pipe2 = nPipeEle1 - nPipeEle2; //底下管子的底标高和上面管子底标高的距离
if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn) //1判断2管的距离小于安全距离
bHasInter2 = TRUE;
else if(nPipeEle2 > nPipeEle1 && nPipeEle2 < dPipeEleUp1) //2判断上面管子的底标高是否在下面管子内
bHasInter2 = TRUE;
}
else
{
dPipeEleUp2 = nPipeEle2 + nDn2;
double dDist2Pipe1 = dPipeEleUp2 - nPipeEle1;
double dDist2Pipe2 = nPipeEle2 - nPipeEle1;
if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn2)
bHasInter2 = TRUE;
else if(nPipeEle1 > nPipeEle2 && nPipeEle1 < dPipeEleUp2)
bHasInter2 = TRUE;
}
if (fabs(nPipeEle1) < 1e-6)
{
nPipeEle1 = fabs(nPipeEle1);
}
if (fabs(nPipeEle2) < 1e-6)
{
nPipeEle2 = fabs(nPipeEle2);
}
BOOL bIsGravityPipe1(FALSE), bIsGravityPipe2(FALSE);
if(sys1 == TPipeSys::kDirtWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kOther)
bIsGravityPipe1 = TRUE;
if(sys2 == TPipeSys::kDirtWater || sys2 == TPipeSys::kRainWater || sys2 == TPipeSys::kUselessWater || sys2 == TPipeSys::kOther)
bIsGravityPipe2 = TRUE;
InterPipesInfo info;
info.ptInter = ptInt;
// 标高相同时 降落管选取规则为重力流>压力流。
// 两个均为重力流时 污水>废水>雨水>其他重力流。
// 两个均为压力流的时候任意选择一个管线类型即可。
if (nPipeEle1 > nPipeEle2 || (fabs(nPipeEle1 - nPipeEle2) < 0.001 &&
((!bIsGravityPipe1 && bIsGravityPipe2) ||
(sys2 == TPipeSys::kDirtWater && (sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) ||
(sys2 == TPipeSys::kUselessWater && (sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) ||
(sys2 == TPipeSys::kRainWater && sys1 == TPipeSys::kOther))))
{
info.idLow = id2;
info.idUp = id1;
info.dElevLow = nPipeEle2;
info.dElevUp = nPipeEle1;
info.sysLow = sys2;
info.sysUp = sys1;
info.dDnLow = nDnPro2;
info.dDnUp = nDnPro;
if(bHasInter2)// 相交需要移动
{
ads_name name;
acdbGetAdsName(name, id2);
Entity ent = name;
nPipeEle2 += GetPipeThick(ent);
m_mapInterPipeInfo.insert(std::make_pair(nPipeEle2, info));
}
else
{
m_vecPtUnInter.push_back(info);
}
}
else
{
info.idLow = id1;
info.idUp = id2;
info.dElevLow = nPipeEle1;
info.dElevUp = nPipeEle2;
info.sysLow = sys1;
info.sysUp = sys2;
info.dDnLow = nDnPro;
info.dDnUp = nDnPro2;
if(bHasInter2)// 相交需要移动
{
ads_name name;
acdbGetAdsName(name, id1);
Entity ent = name;
nPipeEle1 += GetPipeThick(ent);
m_mapInterPipeInfo.insert(std::make_pair(nPipeEle1, info));
}
else
{
m_vecPtUnInter.push_back(info);
}
}
}
void CPipeInterCheckDlg::ModifyInterPipeInfo()
{
std::multimap<double, InterPipesInfo> mapInterPipeInfo;
std::multimap<double, InterPipesInfo>::iterator itMap;
for (itMap = m_mapInterPipeInfo.begin(); itMap != m_mapInterPipeInfo.end(); itMap++)
{
mapInterPipeInfo.insert(*itMap);
}
std::vector<InterPipesInfo> vecPtUnInter;
std::vector<InterPipesInfo>::iterator it;
for (it = m_vecPtUnInter.begin(); it != m_vecPtUnInter.end(); it++)
{
vecPtUnInter.push_back(*it);
}
m_vecPtUnInter.clear();
m_mapInterPipeInfo.clear();
for (itMap = mapInterPipeInfo.begin(); itMap != mapInterPipeInfo.end(); itMap++)
{
InterPipesInfo infoOld = itMap->second;
UpdateInterPipeInfo(infoOld);
}
for (it = vecPtUnInter.begin(); it != vecPtUnInter.end(); it++)
{
UpdateInterPipeInfo(*it);
}
m_itCurPipe = m_mapInterPipeInfo.rbegin();
}
void CPipeInterCheckDlg::DrawXLineByPt()
{
m_idMove = NULL;
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
double nDist1 = 15*DocGetPScale();
double nDist2 = 5*DocGetPScale();
std::multimap<double, InterPipesInfo>::iterator itMap;
for (itMap = m_mapInterPipeInfo.begin(); itMap != m_mapInterPipeInfo.end(); itMap++)
{
XPoint ptInt = itMap->second.ptInter;
XPoint p1, p2, p3, p4;
ads_polar(ptInt, -Wcs2Ucs(0.0), nDist1, p1);
ads_polar(p1, PI/2 - Wcs2Ucs(0.0), nDist1, p1);
ads_polar(ptInt, PI - Wcs2Ucs(0.0), nDist1, p2);
ads_polar(p2, PI/2 - Wcs2Ucs(0.0), -nDist1, p2);
AcDbLine *pLine = new AcDbLine;
pLine->setStartPoint(p1);
pLine->setEndPoint(p2);
pLine->setColorIndex(2);
AcDbObjectId id1 = AddToModelSpace(pLine, Adesk::kTrue);
m_ssLine += id1;
ads_polar(ptInt, PI/2 - Wcs2Ucs(0.0), nDist1, p3);
ads_polar(p3, PI - Wcs2Ucs(0.0), nDist1, p3);
ads_polar(ptInt, PI/2 - Wcs2Ucs(0.0), -nDist1, p4);
ads_polar(p4, -Wcs2Ucs(0.0), nDist1, p4);
AcDbLine *pLine2 = new AcDbLine;
pLine2->setStartPoint(p3);
pLine2->setEndPoint(p4);
pLine2->setColorIndex(2);
AcDbObjectId id2 = AddToModelSpace(pLine2, Adesk::kTrue);
m_ssLine += id2;
}
std::vector<InterPipesInfo>::iterator it;
for (it = m_vecPtUnInter.begin(); it != m_vecPtUnInter.end(); it++)
{
XPoint ptInt = (*it).ptInter;
XPoint p1, p2, p3, p4;
ads_polar(ptInt, -Wcs2Ucs(0.0), nDist2, p1);
ads_polar(p1, PI/2 - Wcs2Ucs(0.0), nDist2, p1);
ads_polar(ptInt, PI - Wcs2Ucs(0.0), nDist2, p2);
ads_polar(p2, PI/2 - Wcs2Ucs(0.0), -nDist2, p2);
AcDbLine *pLine = new AcDbLine;
pLine->setStartPoint(p1);
pLine->setEndPoint(p2);
pLine->setColorIndex(1);
m_ssLine += AddToModelSpace(pLine, Adesk::kTrue);
ads_polar(ptInt, PI/2 - Wcs2Ucs(0.0), nDist2, p3);
ads_polar(p3, PI - Wcs2Ucs(0.0), nDist2, p3);
ads_polar(ptInt, PI/2 - Wcs2Ucs(0.0), -nDist2, p4);
ads_polar(p4, -Wcs2Ucs(0.0), nDist2, p4);
AcDbLine *pLine2 = new AcDbLine;
pLine2->setStartPoint(p3);
pLine2->setEndPoint(p4);
pLine2->setColorIndex(1);
m_ssLine += AddToModelSpace(pLine2, Adesk::kTrue);
}
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
}
void CPipeInterCheckDlg::SetCurrentDlgData()
{
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
m_ssLine.Erase();
m_ssLine.Free();
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
DrawXLineByPt();
m_idMove = NULL;
if (m_mapInterPipeInfo.empty())
{
SetDlgCtrlStu();
return;
}
m_itCurPipe= m_mapInterPipeInfo.rbegin();
m_infoPipe = m_itCurPipe->second;
ModifyDlgRadioStu();
UpdateData(FALSE);
SetCurSelPipe();
}
void CPipeInterCheckDlg::SetDimText()
{
CString sFormat;
sFormat.Format(_T("%%s%%.%df"), m_iPreWelldDeep);
CString sPipeNameUp = GetPipeNameBySys(m_infoPipe.sysUp);
CString sPipeNameLow = GetPipeNameBySys(m_infoPipe.sysLow);
double nPipeEle1 = m_infoPipe.dElevUp;
double nPipeEle2 = m_infoPipe.dElevLow;
double dDnUp = 0.0;
double dDnLow = 0.0;
CString csMat;
if (IsEwPipe(m_infoPipe.idUp))
{
OPENOBJ_BEGIN(m_infoPipe.idUp, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
int iMaterial = pPipe->GetMaterial();
csMat = GetPipeMaterialByIdx(iMaterial);
}
OPENOBJ_END();
dDnUp = GetPipeOutDByDn(csMat, (int)m_infoPipe.dDnUp);
}
else
{
dDnUp = GetPipeOutDByDn(m_infoPipe.idUp);
}
if (IsEwPipe(m_infoPipe.idLow))
{
OPENOBJ_BEGIN(m_infoPipe.idLow, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
int iMaterial = pPipe->GetMaterial();
csMat = GetPipeMaterialByIdx(iMaterial);
}
OPENOBJ_END();
dDnLow = GetPipeOutDByDn(csMat, (int)m_infoPipe.dDnLow);
}
else
{
dDnLow = GetPipeOutDByDn(m_infoPipe.idLow);
}
if (m_iDimType == 1) // 外底与外顶标高
{
nPipeEle2 += dDnLow;
}
else // 重力流内底与压力流中心标高
{
BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE);
if(m_infoPipe.sysUp == TPipeSys::kDirtWater || m_infoPipe.sysUp == TPipeSys::kRainWater || m_infoPipe.sysUp == TPipeSys::kUselessWater || m_infoPipe.sysUp == TPipeSys::kOther)
bIsGravityPipeUp = TRUE;
if(m_infoPipe.sysLow == TPipeSys::kDirtWater || m_infoPipe.sysLow == TPipeSys::kRainWater || m_infoPipe.sysLow == TPipeSys::kUselessWater || m_infoPipe.sysLow == TPipeSys::kOther)
bIsGravityPipeLow = TRUE;
if(!bIsGravityPipeUp)
nPipeEle1 += dDnUp/ 2.0;
else
{
ads_name name;
acdbGetAdsName(name, m_infoPipe.idUp);
Entity ent = name;
nPipeEle1 += GetPipeThick(ent);
}
if(!bIsGravityPipeLow)
nPipeEle2 += dDnLow / 2.0;
else
{
ads_name name;
acdbGetAdsName(name, m_infoPipe.idLow);
Entity ent = name;
nPipeEle2 += GetPipeThick(ent);
}
}
if (fabs(nPipeEle1) < 0.001)
{
nPipeEle1 = 0.0;
}
if (fabs(nPipeEle2) < 0.001)
{
nPipeEle2 = 0.0;
}
m_sElevUp.Format(sFormat, sPipeNameUp, nPipeEle1);
m_sElevLow.Format(sFormat, sPipeNameLow, nPipeEle2);
}
void CPipeInterCheckDlg::ModifyDlgRadioStu()
{
SetDimText();
CString sPipeNameUp = GetPipeNameBySys(m_infoPipe.sysUp);
CString sPipeNameLow = GetPipeNameBySys(m_infoPipe.sysLow);
m_cmbPipeType.ResetContent();
m_cmbPipeType.AddString(sPipeNameLow);
m_cmbPipeType.AddString(sPipeNameUp);
BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE);
if(m_infoPipe.sysUp == TPipeSys::kDirtWater || m_infoPipe.sysUp == TPipeSys::kRainWater || m_infoPipe.sysUp == TPipeSys::kUselessWater || m_infoPipe.sysUp == TPipeSys::kOther)
bIsGravityPipeUp = TRUE;
if(m_infoPipe.sysLow == TPipeSys::kDirtWater || m_infoPipe.sysLow == TPipeSys::kRainWater || m_infoPipe.sysLow == TPipeSys::kUselessWater || m_infoPipe.sysLow == TPipeSys::kOther)
bIsGravityPipeLow = TRUE;
CWnd *pWndType1 = GetDlgItem(IDC_RADIO_PIPETYPE2);
CWnd *pWndType2 = GetDlgItem(IDC_RADIO_PIPETYPE3);
CWnd *pWndType3 = GetDlgItem(IDC_RADIO_PIPETYPE4);
if (fabs(m_infoPipe.dDnLow - m_infoPipe.dDnUp) < 0.001)
{
pWndType1->EnableWindow(FALSE);
if (m_iDownPipeType == 1)
{
m_iDownPipeType = 0;
}
}
else
{
pWndType1->EnableWindow(TRUE);
}
if ((bIsGravityPipeLow && bIsGravityPipeUp) || (!bIsGravityPipeLow && !bIsGravityPipeUp))
{
pWndType2->EnableWindow(FALSE);
pWndType3->EnableWindow(FALSE);
if (m_iDownPipeType == 2 || m_iDownPipeType == 3)
{
m_iDownPipeType = 0;
}
}
else
{
pWndType2->EnableWindow(TRUE);
pWndType3->EnableWindow(TRUE);
}
}
void CPipeInterCheckDlg::SetCurSelPipe()
{
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
CWnd *pWnd(NULL);
if (IsEwPipe(m_infoPipe.idLow) || IsEwPipe(m_infoPipe.idUp))
{
pWnd = GetDlgItem(IDC_BTN_DOWN);
if (pWnd) pWnd->EnableWindow(false);
pWnd = GetDlgItem(IDC_BTN_AUTODOWN);
if (pWnd) pWnd->EnableWindow(false);
}
else
{
pWnd = GetDlgItem(IDC_BTN_DOWN);
if (pWnd) pWnd->EnableWindow(true);
pWnd = GetDlgItem(IDC_BTN_AUTODOWN);
if (pWnd) pWnd->EnableWindow(true);
}
BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE);
if(m_infoPipe.sysUp == TPipeSys::kDirtWater || m_infoPipe.sysUp == TPipeSys::kRainWater || m_infoPipe.sysUp == TPipeSys::kUselessWater || m_infoPipe.sysUp == TPipeSys::kOther)
bIsGravityPipeUp = TRUE;
if(m_infoPipe.sysLow == TPipeSys::kDirtWater || m_infoPipe.sysLow == TPipeSys::kRainWater || m_infoPipe.sysLow == TPipeSys::kUselessWater || m_infoPipe.sysLow == TPipeSys::kOther)
bIsGravityPipeLow = TRUE;
if (m_iDownPipeType == 0)
{
m_idMove = m_infoPipe.idLow;
m_cmbPipeType.SetCurSel(0);
m_iCmbType = 0;
}
else if (m_iDownPipeType == 1)
{
if (m_infoPipe.dDnLow > m_infoPipe.dDnUp)
{
m_idMove = m_infoPipe.idUp;
m_cmbPipeType.SetCurSel(1);
m_iCmbType = 1;
}
else
{
m_idMove = m_infoPipe.idLow;
m_cmbPipeType.SetCurSel(0);
m_iCmbType = 0;
}
}
else if (m_iDownPipeType == 2)
{
if (bIsGravityPipeLow)
{
m_idMove = m_infoPipe.idLow;
m_cmbPipeType.SetCurSel(0);
m_iCmbType = 0;
}
else
{
m_idMove = m_infoPipe.idUp;
m_cmbPipeType.SetCurSel(1);
m_iCmbType = 1;
}
}
else if (m_iDownPipeType == 3)
{
if (!bIsGravityPipeLow)
{
m_idMove = m_infoPipe.idLow;
m_cmbPipeType.SetCurSel(0);
m_iCmbType = 0;
}
else
{
m_idMove = m_infoPipe.idUp;
m_cmbPipeType.SetCurSel(1);
m_iCmbType = 1;
}
}
arxZoomTo(m_infoPipe.ptInter, 100*DocGetPScale(), 100*DocGetPScale());
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
}
void CPipeInterCheckDlg::UpdateDlgData(bool bRead)
{
CRegProperty regProp(GetRegLocation(), _T("TWTConfig"));
regProp.SetTopRootKey(HKEY_CURRENT_USER);
if (bRead)
{
if (!regProp.GetValue(_T("PipeInterDownLen"), m_dDownLen))
{
m_dDownLen = 0.4;
}
if (!regProp.GetValue(_T("PipeInterSafeDist"), m_dSafeDist))
{
m_dSafeDist = 0.0;
}
m_csDownLen.Format(_T("%.3f"), m_dDownLen);
// 消除数字小数点后面无意义的0
m_csDownLen.TrimRight(_T("0"));
m_csDownLen.TrimRight(_T("."));
m_csSafeDist.Format(_T("%.3f"), m_dSafeDist);
m_csSafeDist.TrimRight(_T("0"));
m_csSafeDist.TrimRight(_T("."));
regProp.GetValue(_T("PipeInterDimType"), m_iDimType);
regProp.GetValue(_T("PipeInterDimNotInter"), m_iDimPipeNotInter);
UpdateData(FALSE);
}
else
{
UpdateData(TRUE);
regProp.SetValue(_T("PipeInterDownLen"), m_dDownLen);
regProp.SetValue(_T("PipeInterSafeDist"), m_dSafeDist);
regProp.SetValue(_T("PipeInterDimType"), m_iDimType);
regProp.SetValue(_T("PipeInterDimNotInter"), m_iDimPipeNotInter);
}
}
BOOL CPipeInterCheckDlg::OnInitDialog()
{
WGroupDlg::OnInitDialog();
#if (ADS == 15)
SetTimer(1, 2000, NULL);
#else
SetTimer(1, 200, NULL);
#endif
// 获取标高标注精度
CRegProperty regProp(GetRegLocation(), _T("TWTConfig"));
regProp.SetTopRootKey(HKEY_CURRENT_USER);
TDbPsConfig *pConfig = GetDwgPsGlobal(AcDb::kForRead);
if (pConfig != NULL)
{
m_iPreWelldDeep = pConfig->GetWellDeepPrecision();
if(m_iPreWelldDeep == 99)
m_iPreWelldDeep = 0;
pConfig->close();
}
UpdateDlgData(true);
UpdateData(FALSE);
m_iOldDownPipeType = m_iDownPipeType;
InitInterPipeInfo();
SetCurrentDlgData();
return TRUE;
}
void CPipeInterCheckDlg::OnTimer(UINT_PTR nIDEvent)
{
ShowLine();
m_bIsVisible = !m_bIsVisible;
WGroupDlg::OnTimer(nIDEvent);
}
void CPipeInterCheckDlg::ShowLine()
{
if (m_idMove == NULL)
{
return;
}
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
for (long l = 0l; l < m_ssLine.Length(); l++)
{
Entity ent = m_ssLine[l];
OPENOBJ_BEGIN(ent, AcDb::kForWrite, AcDbLine, pLine);
if(pLine != NULL)
{
XPoint ptOnLine;
pLine->getClosestPointTo(m_infoPipe.ptInter, ptOnLine);
if (ptOnLine.Distance2d(m_infoPipe.ptInter) > 0.001)
{
continue;
}
if (m_bIsVisible)
{
pLine->setVisibility(AcDb::kVisible);
}
else
{
pLine->setVisibility(AcDb::kInvisible);
}
}
OPENOBJ_END();
}
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
}
void CPipeInterCheckDlg::OnRadioPipetype1()
{
UpdateData(TRUE);
m_iOldDownPipeType = m_iDownPipeType;
SetCurSelPipe();
}
void CPipeInterCheckDlg::OnRadioPipetype2()
{
UpdateData(TRUE);
m_iOldDownPipeType = m_iDownPipeType;
SetCurSelPipe();
}
void CPipeInterCheckDlg::OnRadioPipetype3()
{
UpdateData(TRUE);
m_iOldDownPipeType = m_iDownPipeType;
SetCurSelPipe();
}
void CPipeInterCheckDlg::OnRadioPipetype4()
{
UpdateData(TRUE);
m_iOldDownPipeType = m_iDownPipeType;
SetCurSelPipe();
}
void CPipeInterCheckDlg::OnSelchangeComboType()
{
int iOldType = m_iCmbType;
UpdateData();
if (iOldType == m_iCmbType)
{
return;
}
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
if (m_idMove == m_infoPipe.idLow)
{
m_idMove = m_infoPipe.idUp;
}
else
{
m_idMove = m_infoPipe.idLow;
}
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
acedGetAcadDwgView()->SetFocus();
}
void CPipeInterCheckDlg::OnDestroy()
{
WGroupDlg::OnDestroy();
m_vecPtUnInter.clear();
m_mapInterPipeInfo.clear();
m_ssPipe.Free();
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
m_bIsVisible = true;
ShowLine();
KillTimer(1);
m_idMove = NULL;
//m_ssLine.Erase();
m_ssLine.Free();
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
UpdateDlgData(false);
}
void CPipeInterCheckDlg::OnClose()
{
PostCommand(_T(" "));
WGroupDlg::OnClose();
}
void CPipeInterCheckDlg::OnBtnQuit()
{
UpdateData();
ModifyInterPipeInfo();
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
std::multimap<double, InterPipesInfo>::iterator itMap;
for (itMap = m_mapInterPipeInfo.begin(); itMap != m_mapInterPipeInfo.end(); itMap++)
{
DoDimIntersectPipes(itMap->second);
}
if (m_iDimPipeNotInter == 1)
{
std::vector<InterPipesInfo>::iterator it;
for (it = m_vecPtUnInter.begin(); it != m_vecPtUnInter.end(); it++)
{
DoDimIntersectPipes(*it);
}
}
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
PostCommand(_T(" "));
acedGetAcadDwgView()->SetFocus();
}
void CPipeInterCheckDlg::OnBtnNotdown()
{
UpdateData();
m_bIsVisible = true;
ShowLine();
m_itCurPipe++;
if (m_itCurPipe == m_mapInterPipeInfo.rend())
{
m_ssLine.Erase();
SetDlgCtrlStu();
OnBtnQuit();
return;
}
m_infoPipe = m_itCurPipe->second;
ModifyDlgRadioStu();
UpdateData(FALSE);
SetCurSelPipe();
acedGetAcadDwgView()->SetFocus();
}
void CPipeInterCheckDlg::OnBtnDown()
{
UpdateData();
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
ResetSelPipeSysElev();
m_iDownPipeType = m_iOldDownPipeType;
m_ssLine.Erase();
m_ssLine.Free();
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
ModifyInterPipeInfo();
SetCurrentDlgData();
acedGetAcadDwgView()->SetFocus();
}
void CPipeInterCheckDlg::SetDlgCtrlStu(bool bEnableWindow)
{
Invalidate();
if (!bEnableWindow)
{
m_cmbPipeType.ResetContent();
m_cmbPipeType.EnableWindow(TRUE);
m_cmbPipeType.AddString(_T("无碰撞点"));
m_iCmbType = 0;
m_cmbPipeType.EnableWindow(FALSE);
m_sElevLow.Empty();
m_sElevUp.Empty();
if (m_vecPtUnInter.size() == 1)
{
m_infoPipe = m_vecPtUnInter[0];
SetDimText();
}
CWnd *pWnd = GetDlgItem(IDC_EDIT_DOWNLEN);
if (pWnd != NULL)
{
pWnd->EnableWindow(FALSE);
}
CWnd *pWndType1 = GetDlgItem(IDC_BTN_DOWN);
CWnd *pWndType2 = GetDlgItem(IDC_BTN_NOTDOWN);
CWnd *pWndType3 = GetDlgItem(IDC_BTN_AUTODOWN);
pWndType1->EnableWindow(FALSE);
pWndType2->EnableWindow(FALSE);
pWndType3->EnableWindow(FALSE);
CWnd *pWndDownType1 = GetDlgItem(IDC_RADIO_PIPETYPE1);
CWnd *pWndDownType2 = GetDlgItem(IDC_RADIO_PIPETYPE2);
CWnd *pWndDownType3 = GetDlgItem(IDC_RADIO_PIPETYPE3);
CWnd *pWndDownType4 = GetDlgItem(IDC_RADIO_PIPETYPE4);
pWndDownType1->EnableWindow(FALSE);
pWndDownType2->EnableWindow(FALSE);
pWndDownType3->EnableWindow(FALSE);
pWndDownType4->EnableWindow(FALSE);
UpdateData(FALSE);
}
else
{
m_cmbPipeType.EnableWindow(TRUE);
m_sElevLow.Empty();
m_sElevUp.Empty();
CWnd *pWnd = GetDlgItem(IDC_EDIT_DOWNLEN);
if (pWnd != NULL)
{
pWnd->EnableWindow(TRUE);
}
CWnd *pWndType1 = GetDlgItem(IDC_BTN_DOWN);
CWnd *pWndType2 = GetDlgItem(IDC_BTN_NOTDOWN);
CWnd *pWndType3 = GetDlgItem(IDC_BTN_AUTODOWN);
pWndType1->EnableWindow(TRUE);
pWndType2->EnableWindow(TRUE);
pWndType3->EnableWindow(TRUE);
CWnd *pWndDownType1 = GetDlgItem(IDC_RADIO_PIPETYPE1);
CWnd *pWndDownType2 = GetDlgItem(IDC_RADIO_PIPETYPE2);
CWnd *pWndDownType3 = GetDlgItem(IDC_RADIO_PIPETYPE3);
CWnd *pWndDownType4 = GetDlgItem(IDC_RADIO_PIPETYPE4);
pWndDownType1->EnableWindow(TRUE);
pWndDownType2->EnableWindow(TRUE);
pWndDownType3->EnableWindow(TRUE);
pWndDownType4->EnableWindow(TRUE);
}
}
void CPipeInterCheckDlg::ResetSelPipeSysElev()
{
AcDbObjectId idNodeStart, idNodeEnd;
double dDeepStart = 0.0, dDeepEnd = 0.0;
double dDn = 0.0;
double dUnitMeter = 1000;
if(DocGetMeterUnitDraw())
dUnitMeter = 1.0;
if (!IsEwPipe(m_idMove))
{
OPENOBJ_BEGIN(m_idMove, AcDb::kForWrite, TDbPipe, pPipe);
if (pPipe != NULL)
{
XPoint ptS, ptE;
dDn = pPipe->GetDnDiameter() / 2;
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
if (dir == TPipeSys::kFromStart)
{
ptS = pPipe->GetStartPoint();
ptE = pPipe->GetEndPoint();
double dLen = pPipe->GetPlanLength();
double dI = pPipe->GetPipeGradient();
ptS.z -= m_dDownLen * dUnitMeter;
pPipe->SetStartPoint(ptS);
double nDrop = dLen * dI * dUnitMeter;
ptE.z = ptS.z - nDrop;
pPipe->SetEndPoint(ptE);
dDeepStart = ptS.z / dUnitMeter;
dDeepEnd = ptE.z / dUnitMeter;
idNodeStart = pPipe->GetNode(0);
idNodeEnd = pPipe->GetNode(1);
}
else
{
ptE = pPipe->GetEndPoint();
ptS = pPipe->GetStartPoint();
double dLen = pPipe->GetPlanLength();
double dI = pPipe->GetPipeGradient();
ptE.z -= m_dDownLen * dUnitMeter;
pPipe->SetEndPoint(ptE);
double nDrop = dLen * dI;
ptS.z = ptE.z - nDrop;
pPipe->SetStartPoint(ptS);
dDeepStart = ptE.z / dUnitMeter;
dDeepEnd = ptS.z / dUnitMeter;
idNodeEnd = pPipe->GetNode(0);
idNodeStart = pPipe->GetNode(1);
}
}
OPENOBJ_END();
}
else
{
XPoint ptS, ptE;
dDn = GetDnDiameter(m_idMove) / 2;
TPipeSys::FlowDirection dir = GetFlowDir(m_idMove);
if (dir == TPipeSys::kFromStart)
{
ptS = GetStartPoint(m_idMove);
ptE = GetEndPoint(m_idMove);
double dLen = GetPlanLength(m_idMove);
double dI = GetPipeGradient(m_idMove);
ptS.z -= m_dDownLen * dUnitMeter;
SetStartPoint(m_idMove, ptS);
double nDrop = dLen * dI * dUnitMeter;
ptE.z = ptS.z - nDrop;
SetEndPoint(m_idMove, ptE);
dDeepStart = ptS.z / dUnitMeter;
dDeepEnd = ptE.z / dUnitMeter;
idNodeStart = AcDbObjectId::kNull;
idNodeEnd = AcDbObjectId::kNull;
}
else
{
ptE = GetEndPoint(m_idMove);
ptS = GetStartPoint(m_idMove);
double dLen = GetPlanLength(m_idMove);
double dI = GetPipeGradient(m_idMove);
ptE.z -= m_dDownLen * dUnitMeter;
SetEndPoint(m_idMove, ptE);
double nDrop = dLen * dI;
ptS.z = ptE.z - nDrop;
SetStartPoint(m_idMove, ptS);
dDeepStart = ptE.z / dUnitMeter;
dDeepEnd = ptS.z / dUnitMeter;
idNodeEnd = AcDbObjectId::kNull;
idNodeStart = AcDbObjectId::kNull;
}
}
Entity entStartWell, entEndWell;
double nDeepStart = 0.0;
OPENOBJ_BEGIN(idNodeStart, AcDb::kForWrite, TDbWell, pWell);
if(pWell != NULL)
{
pWell->SetDropWell(TRUE);
nDeepStart = dDeepStart - dDn / 1000;
pWell->SetWellEleDown(nDeepStart);
ads_name name;
acdbGetAdsName(name, idNodeStart);
entStartWell = name;
}
OPENOBJ_END();
if (!entStartWell)
{
OPENOBJ_BEGIN(idNodeEnd, AcDb::kForWrite, TDbWell, pWell);
if(pWell != NULL)
{
nDeepStart = dDeepEnd - dDn / 1000;
pWell->SetWellEleDown(nDeepStart);
ads_name name;
acdbGetAdsName(name, idNodeEnd);
entStartWell = name;
}
OPENOBJ_END();
}
if (!!entStartWell)
{
SSearchPipeList *pListAll = new SSearchPipeList();
PickSet ssAll(SS_FREE);
ssAll += entStartWell;
SearchOutdoorWell(entStartWell, entEndWell, pListAll, ssAll, FALSE);
DList<TWellData> lstWellSys;
GetWellListData2(pListAll, lstWellSys);
ModifyWellSysByLastWell(lstWellSys, ssAll);
CalcWellPipeSys(nDeepStart, lstWellSys);
if (pListAll != NULL)
{
delete pListAll;
pListAll = NULL;
}
}
TPipePerDocData *pData = GetCurPipeDocData();
if (pData != NULL)
{
pData->ApplyUpdates();
}
}
void CPipeInterCheckDlg::ModifyWellSysByLastWell(DList<TWellData> &lstWellSys, const PickSet &ss)
{
if (lstWellSys.Length() < 2)
{
return;
}
AcDbObjectId id, idFront;
AcDbObjectId idLastWell;
id = lstWellSys[lstWellSys.Length() - 1]->m_ID;
idFront = lstWellSys[lstWellSys.Length() - 2]->m_ID;
if (!lstWellSys[lstWellSys.Length() - 1]->m_bIsWell)
{
PickSet ssNode;
GetAllPipeAndNodeByPipe(id, idFront, ssNode);
for (long l = 0; l < ssNode.Length(); l++)
{
Entity ent = ssNode[l];
if (ent.Is(_T("ATS_WELL")) && ent.In(&ss))
{
acdbGetObjectId(idLastWell, ent);
break;
}
}
if (idLastWell == NULL)
{
return;
}
}
else
{
return;
}
int nPos = 0;
for(int i = 0; i < lstWellSys.Length(); i++)
{
if (lstWellSys[i]->m_ID == idLastWell)
{
nPos = i + 1;
break;
}
}
while (lstWellSys.Length() > nPos)
{
lstWellSys.Remove(nPos);
}
}
void CPipeInterCheckDlg::CalcWellPipeSys(double nDeepStart, DList<TWellData> &lstWellSys)
{
double nPipeLen = 0.0;
double nI = 0.0;
double nFrontPipeEle = 0.0;
bool bFindDropWell = false;
for(int i = 0; i < lstWellSys.Length(); i++)
{
lstWellSys[i]->m_iSpare = 1;
if(lstWellSys[i]->m_bIsWell)
{//井
AcDbObjectId id = lstWellSys[i]->m_ID;
if(nPipeLen > 0)
{
double nWellEle = lstWellSys[i]->m_nUpEle;
double nWellDownEle = lstWellSys[i]->m_nDownEle;
double nLastEnd = nDeepStart - nI * nPipeLen;
double nWellDeep = nWellEle - nWellDownEle; //埋深 地面-井底
nFrontPipeEle = nLastEnd;
if(lstWellSys[i]->m_bIsDropWell && nDeepStart > lstWellSys[i]->m_nDownEle)
{
nDeepStart = lstWellSys[i]->m_nDownEle;
lstWellSys[i]->m_nFrondDownEle = nFrontPipeEle;
break;
}
else
{
if (lstWellSys[i]->m_bIsDropWell)
{
if (bFindDropWell)
{
break;
}
bFindDropWell = true;
}
lstWellSys[i]->m_bIsDropWell = FALSE;
double nRadiusFront(0), nRadiusBack(0);
nRadiusFront = lstWellSys[i-1]->m_iDn;
if(i != lstWellSys.Length()-1)
{
nRadiusBack = lstWellSys[i+1]->m_iDn;
}
//得到外径
double nDifference(0);
if(nRadiusFront > 0 && nRadiusBack > 0)
{//井前后管径差
nDifference = (nRadiusBack - nRadiusFront)/1000;
}
lstWellSys[i]->m_nFrondDownEle = nDeepStart - nI * nPipeLen;
//管顶平接
nDeepStart = nDeepStart - nI * nPipeLen - nDifference;
if(lstWellSys[i]->m_csName == _T("HC"))
{
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPool, pEquip);
if(pEquip != NULL)
{
if(pEquip->GetSpare() > 0.01)
nDeepStart -= pEquip->GetSpare();
else
nDeepStart -= 0.1;//化粪池
}
OPENOBJ_END();
}
}
lstWellSys[i]->m_nDownEle = nDeepStart;
nWellDeep = nWellEle - nDeepStart;
lstWellSys[i]->m_nDeep = nWellDeep;
}
}
else if(!lstWellSys[i]->m_bIsWell)
{ //管
if(i == lstWellSys.Length() - 1)
continue;
nPipeLen = lstWellSys[i]->m_nLength;
nI = lstWellSys[i]->m_nI;
CString csPipeName = lstWellSys[i-1]->m_csName + lstWellSys[i+1]->m_csName;
if(lstWellSys[i+1]->m_csName == _T("HC"))
csPipeName += _T("进");
else if(lstWellSys[i-1]->m_csName == _T("HC"))
csPipeName = lstWellSys[i-1]->m_csName + _T("出") + lstWellSys[i+1]->m_csName;
}
}
ModifyWellPipeElev(lstWellSys);
}
void CPipeInterCheckDlg::ModifyWellPipeElev(DList<TWellData> &lstWellSys)
{
for(int i=0;i<lstWellSys.Length();i++)
{
if(lstWellSys[i]->m_bIsWell)
{//井
AcDbObjectId id = lstWellSys[i]->m_ID;
XPoint ptLoc;
CString csEleLow, csEleUp;
csEleLow.Format(_T("%.2f"), lstWellSys[i]->m_nDownEle);
csEleUp.Format(_T("%.2f"), lstWellSys[i]->m_nUpEle);
if(lstWellSys[i]->m_csName == _T("HC"))
{
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbPool, pEquip);
if(pEquip != NULL)
{
pEquip->SetGroundEle(lstWellSys[i]->m_nUpEle);
}
OPENOBJ_END();
continue;
}
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbWell, pEquip);
if(pEquip != NULL)
{
pEquip->SetDropWell(lstWellSys[i]->m_bIsDropWell);
double nPipeDownEle = lstWellSys[i]->m_nFrondDownEle;
double nPipeDownEle2 = lstWellSys[i]->m_nDownEle;
if(i > 1)
{//设置前管道 管底标高
AcDbObjectId idPipe = lstWellSys[i-1]->m_ID;
pEquip->SetPipeEndEle(idPipe, XString(_T("%.3f"), lstWellSys[i]->m_nFrondDownEle));
}
if(i < lstWellSys.Length()-1)
{//设置后管道 管底标高
AcDbObjectId idPipe = lstWellSys[i+1]->m_ID;
pEquip->SetPipeEndEle(idPipe, XString(_T("%.3f"), lstWellSys[i]->m_nDownEle));
}
ptLoc = pEquip->GetLocation();
//搜索这个井其他连接管,最低标高才是井标高
int num = pEquip->GetInterfaceNum();
double nEleOther = lstWellSys[i]->m_nDownEle;
for(int m = 0; m < num; m++)
{
TPipeInterface iFace;
pEquip->GetInterface(m, iFace);
CString csLabel = pEquip->GetISysLabel(m);
if(csLabel != _T("") && nEleOther - _tstof(csLabel) > 0.001)
nEleOther = _tstof(csLabel);
}
if(fabs(nEleOther - lstWellSys[i]->m_nDownEle) < 0.001)
pEquip->SetWellEleDown(lstWellSys[i]->m_nDownEle);
pEquip->SetWellEleUp(lstWellSys[i]->m_nUpEle);
}
OPENOBJ_END();
}
else
{
int iDn = lstWellSys[i]->m_iDn;
double nI = lstWellSys[i]->m_nI*1000;
double nEleDown = lstWellSys[i-1]->m_nDownEle;
ads_name ent;
acdbGetAdsName(ent, lstWellSys[i]->m_ID);
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe);
if(pPipe != NULL)
{
if (lstWellSys[i]->m_iSpare != 1)
{
break;
}
pPipe->SetPipeGradient(nI/1000);
XPoint pt1(pPipe->GetStartPoint()), pt2(pPipe->GetEndPoint());
pt1.z = 0;
pt2.z = 0;
double dLen = pPipe->GetPlanLength();
double dI = pPipe->GetPipeGradient();
double nDrop = dLen*dI;
if(DocGetMeterUnitDraw())
{//米
if(pPipe->GetFlowDir() == TPipeSys::kFromStart)
{
pt1.z = nEleDown + (double)iDn/2000;
pt2.z = pt1.z - nDrop;
}
else
{
pt2.z = nEleDown + (double)iDn/2000;
pt1.z = pt2.z - nDrop;
}
}
else
{
nDrop = nDrop * 1000;
if(pPipe->GetFlowDir() == TPipeSys::kFromStart)
{
pt1.z = nEleDown*1000 + (double)iDn/2;
pt2.z = pt1.z - nDrop;
}
else
{
pt2.z = nEleDown*1000 + (double)iDn/2;
pt1.z = pt2.z - nDrop;
}
}
pPipe->SetStartPoint(pt1);
pPipe->SetEndPoint(pt2);
}
OPENOBJ_END();
}
}
}
void CPipeInterCheckDlg::OnRadioDimtype1()
{
UpdateData(TRUE);
SetDimText();
UpdateData(FALSE);
}
void CPipeInterCheckDlg::OnRadioDimtype2()
{
UpdateData(TRUE);
SetDimText();
UpdateData(FALSE);
}
void CPipeInterCheckDlg::OnKillfocusEditDownlen()
{
double dOldLen = m_dDownLen;
if (!UpdateData() || m_dDownLen <= 0.0)
{
m_dDownLen = dOldLen;
m_csDownLen.Format(_T("%.3f"), m_dDownLen);
m_csDownLen.TrimRight(_T("0"));
m_csDownLen.TrimRight(_T("."));
UpdateData(FALSE);
CEdit *pWnd = (CEdit *)GetDlgItem(IDC_EDIT_DOWNLEN);
if (pWnd != NULL)
{
pWnd->SetSel(0, -1);
}
}
}
bool StringIsAllNum(CString str)
{
// 判断字符是否是合法数字
CString sText = str.SpanIncluding(_T("0123456789.-"));
// 小数点可以出现在中间,但只能出现一次
int nIndex = sText.Find(_T("."), 0);
if (nIndex > 0)
{
nIndex = sText.Find(_T("."), ++nIndex);
}
// 负号可以出现在起始处,但只能出现一次
int nIndex2 = sText.Find(_T("-"));
if (nIndex2 == 0)
{
nIndex2 = sText.Find(_T("-"), 1);
}
bool bFigure = true;
if (str == sText && nIndex < 0 && nIndex2 <= 0)// 全是数字
{
return true;
}
return false;
}
void CPipeInterCheckDlg::OnKillfocusEditSafedist()
{
double dOldDst = m_dSafeDist;
if (!UpdateData() || m_dSafeDist < 0.0 || !StringIsAllNum(m_csSafeDist))
{
m_dSafeDist = dOldDst;
m_csSafeDist.Format(_T("%.3f"), m_dSafeDist);
m_csSafeDist.TrimRight(_T("0"));
m_csSafeDist.TrimRight(_T("."));
UpdateData(FALSE);
CEdit *pWnd = (CEdit *)GetDlgItem(IDC_EDIT_SAFEDIST);
if (pWnd != NULL)
{
pWnd->SetSel(0, -1);
}
}
if (dOldDst != m_dSafeDist)
{
m_iDownPipeType = m_iOldDownPipeType;
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc, AcAp::kWrite);
m_ssLine.Erase();
m_ssLine.Free();
acedUpdateDisplay();
actrTransactionManager->flushGraphics();
acDocManager->unlockDocument(pDoc);
SetDlgCtrlStu(true);
ModifyInterPipeInfo();
SetCurrentDlgData();
acedGetAcadDwgView()->SetFocus();
}
}
void CPipeInterCheckDlg::DoDimIntersectPipes(InterPipesInfo infoPipe)
{
double dUnitMeter = 1000;
if(DocGetMeterUnitDraw())
dUnitMeter = 1;
CString sFormat;
sFormat.Format(_T("%%s%%.%df"), m_iPreWelldDeep);
CString sPipeNameUp = GetPipeNameBySys(infoPipe.sysUp);
CString sPipeNameLow = GetPipeNameBySys(infoPipe.sysLow);
double nPipeEle1 = 0.0;
double nPipeEle2 = 0.0;
double dDnUp = 0.0;
double dDnLow = 0.0;
CString csMat;
if (!IsEwPipe(infoPipe.idUp))
{
OPENOBJ_BEGIN(infoPipe.idUp, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
int iMaterial = pPipe->GetMaterial();
csMat = GetPipeMaterialByIdx(iMaterial);
double dDn = pPipe->GetDnDiameter();
dDnUp = GetPipeOutDByDn(csMat, (int)dDn);
XPoint ptStart = pPipe->StartPoint();
XPoint ptEnd = pPipe->EndPoint();
double nI = pPipe->GetPipeGradient();
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
XPoint ptWell;
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nPipeEle1 = ptWell.z / dUnitMeter - dDnUp / 2;
ptWell.z = 0;
double nDist2Well = ptWell.Distance2d(infoPipe.ptInter) / dUnitMeter;
nPipeEle1 = nPipeEle1 - nDist2Well * nI;
}
OPENOBJ_END();
}
else
{
dDnUp = GetPipeOutDByDn(infoPipe.idUp);
XPoint ptStart = GetStartPoint(infoPipe.idUp);
XPoint ptEnd = GetEndPoint(infoPipe.idUp);
double nI = GetPipeGradient(infoPipe.idUp);
TPipeSys::FlowDirection dir = GetFlowDir(infoPipe.idUp);
XPoint ptWell;
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nPipeEle1 = ptWell.z / dUnitMeter - dDnUp / 2;
ptWell.z = 0;
double nDist2Well = ptWell.Distance2d(infoPipe.ptInter) / dUnitMeter;
nPipeEle1 = nPipeEle1 - nDist2Well * nI;
}
if (!IsEwPipe(infoPipe.idLow))
{
OPENOBJ_BEGIN(infoPipe.idLow, AcDb::kForRead, TDbPipe, pPipe);
if (pPipe != NULL)
{
int iMaterial = pPipe->GetMaterial();
csMat = GetPipeMaterialByIdx(iMaterial);
double dDn = pPipe->GetDnDiameter();
dDnLow = GetPipeOutDByDn(csMat, (int)dDn);
XPoint ptStart = pPipe->StartPoint();
XPoint ptEnd = pPipe->EndPoint();
double nI = pPipe->GetPipeGradient();
TPipeSys::FlowDirection dir = pPipe->GetFlowDir();
XPoint ptWell;
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nPipeEle2 = ptWell.z / dUnitMeter - dDnLow / 2;
ptWell.z = 0;
double nDist2Well = ptWell.Distance2d(infoPipe.ptInter) / dUnitMeter;
nPipeEle2 = nPipeEle2 - nDist2Well * nI;
}
OPENOBJ_END();
}
else
{
dDnLow = GetPipeOutDByDn(infoPipe.idLow);
XPoint ptStart = GetStartPoint(infoPipe.idLow);
XPoint ptEnd = GetEndPoint(infoPipe.idLow);
double nI = GetPipeGradient(infoPipe.idLow);
TPipeSys::FlowDirection dir = GetFlowDir(infoPipe.idLow);
XPoint ptWell;
if (dir == TPipeSys::kFromStart)
ptWell = ptStart;
else
ptWell = ptEnd;
nPipeEle2 = ptWell.z / dUnitMeter - dDnLow / 2;
ptWell.z = 0;
double nDist2Well = ptWell.Distance2d(infoPipe.ptInter) / dUnitMeter;
nPipeEle2 = nPipeEle2 - nDist2Well * nI;
}
if (m_iDimType == 1) // 外底与外顶标高
{
nPipeEle2 += dDnLow;
}
else // 重力流内底与压力流中心标高
{
BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE);
if(infoPipe.sysUp == TPipeSys::kDirtWater || infoPipe.sysUp == TPipeSys::kRainWater || infoPipe.sysUp == TPipeSys::kUselessWater || infoPipe.sysUp == TPipeSys::kOther)
bIsGravityPipeUp = TRUE;
if(infoPipe.sysLow == TPipeSys::kDirtWater || infoPipe.sysLow == TPipeSys::kRainWater || infoPipe.sysLow == TPipeSys::kUselessWater || infoPipe.sysLow == TPipeSys::kOther)
bIsGravityPipeLow = TRUE;
if(!bIsGravityPipeUp)
nPipeEle1 += dDnUp/ 2.0;
else
{
ads_name name;
acdbGetAdsName(name, infoPipe.idUp);
Entity ent = name;
nPipeEle1 += GetPipeThick(ent);
}
if(!bIsGravityPipeLow)
nPipeEle2 += dDnLow / 2.0;
else
{
ads_name name;
acdbGetAdsName(name, infoPipe.idLow);
Entity ent = name;
nPipeEle2 += GetPipeThick(ent);
}
}
if (fabs(nPipeEle1) < 0.001)
{
nPipeEle1 = 0.0;
}
if (fabs(nPipeEle2) < 0.001)
{
nPipeEle2 = 0.0;
}
CString sElevUp;
sElevUp.Format(sFormat, sPipeNameUp, nPipeEle1);
CString sElevLow;
sElevLow.Format(sFormat, sPipeNameLow, nPipeEle2);
XPoint ptTurn;
XPoint ptInt = infoPipe.ptInter;
double nDist1 = 15*DocGetPScale();
ads_polar(ptInt, PI/4, nDist1, ptTurn);
TDbSymbMultiLeader *pLeader = new TDbSymbMultiLeader;
XPointList lstVertexes;
lstVertexes.Append(new XPoint(ptInt));
pLeader->SetLayoutRotation(Ucs2Wcs(0.0));
pLeader->SetLeaderVertexes(lstVertexes);
pLeader->SetText1(sElevUp);
pLeader->SetText2(sElevLow);
pLeader->SetLeaderPoint(ptTurn);
pLeader->SetArrow(TDbSymbMultiLeader::kNone);
AcDbObjectId idTextStyle = InitTextStyle(g_csTwtDimStyle);
pLeader->SetTextStyleId(idTextStyle);
pLeader->SetTextLayerId(InitLayer(LAY_TEXT));
pLeader->SetTextHeight(g_nTwtDimHeight);
pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen()+2);
pLeader->AddToCSpace(Adesk::kTrue);
}
void CPipeInterCheckDlg::OnPaint()
{
CPaintDC dc(this);
if (m_vecPtUnInter.size() > 1 && m_mapInterPipeInfo.size() < 1)
{
return;
}
CStatic *pSta = (CStatic *)GetDlgItem(IDC_STATIC_LINE);
CRect rect;
pSta->GetWindowRect(rect);
ScreenToClient(rect);
CPen pen(PS_SOLID, 2, RGB(0,255,0));// 绿色
dc.SelectObject (&pen);
CPoint ptLeft = rect.TopLeft();
CPoint ptRight = ptLeft;
ptRight.x += 85;
dc.MoveTo(ptLeft);
dc.LineTo(ptRight);
dc.MoveTo(ptLeft);
CPoint ptBottom = ptLeft;
ptBottom.x -= 30;
ptBottom.y += 25;
dc.LineTo(ptBottom);
ReleaseDC(&dc);
}
void CPipeInterCheckDlg::OnBtnAutoDown()
{
while (!m_mapInterPipeInfo.empty())
{
OnBtnDown();
}
OnBtnQuit();
acedGetAcadDwgView()->SetFocus();
}