846 lines
20 KiB
C++
846 lines
20 KiB
C++
#include "stdafx.h"
|
|
#include "WPipeBatReplaceDlg.h"
|
|
#include "actrans.h"
|
|
#include "AecPipeJig.h"
|
|
#include "aecPipeLine.h"
|
|
#include "PipelineTools.h"
|
|
#include "coretools.h"
|
|
|
|
#define IMG_NULL 0
|
|
#define IMG_CURPOS 1
|
|
#define IMG_PROOK 2
|
|
|
|
//公称系列
|
|
static int g_nDNs[] = {10,15,20,25,32,40,50,65,80,90,100,125,150,200,250,300,350,400,450,500,600,700,750,800,850,900,950,1000,0};
|
|
|
|
IMPLEMENT_DYNAMIC(CWPipeBatReplaceDlg, CDialog)
|
|
|
|
CWPipeBatReplaceDlg::CWPipeBatReplaceDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CWPipeBatReplaceDlg::IDD, pParent)
|
|
, m_dDn(0)
|
|
, m_dEl(0)
|
|
{
|
|
m_bStart = true;
|
|
m_nType = 0;
|
|
}
|
|
|
|
CWPipeBatReplaceDlg::~CWPipeBatReplaceDlg()
|
|
{
|
|
PVOID pValue = NULL;
|
|
int nDn = 0;
|
|
for (POSITION ps = m_mapDn2OD.GetStartPosition(); ps != NULL;)
|
|
{
|
|
m_mapDn2OD.GetNextAssoc(ps,nDn,pValue);
|
|
|
|
if (pValue != NULL)
|
|
delete (CArray<float,float>*)pValue;
|
|
}
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_LISTWPIPE, m_wndListPipes);
|
|
DDX_Text(pDX, IDC_EDITDN, m_dDn);
|
|
DDX_Text(pDX, IDC_EDITEL, m_dEl);
|
|
DDX_Control(pDX, IDC_COMBOMATERIAL, m_wndComboMaters);
|
|
DDX_Control(pDX, IDC_COMBOTHICK, m_wndComboThick);
|
|
DDX_Control(pDX, IDC_COMBOSYSLAY, m_wndComboSys);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CWPipeBatReplaceDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CWPipeBatReplaceDlg::OnBnClickedOk)
|
|
ON_MESSAGE( WM_ACAD_KEEPFOCUS, &CWPipeBatReplaceDlg::onAcadKeepFocus )
|
|
ON_WM_CLOSE()
|
|
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LISTWPIPE, &CWPipeBatReplaceDlg::OnLvnItemchangedListwpipe)
|
|
ON_NOTIFY(NM_CLICK, IDC_LISTWPIPE, &CWPipeBatReplaceDlg::OnNMClickListwpipe)
|
|
END_MESSAGE_MAP()
|
|
|
|
LONG_PTR CWPipeBatReplaceDlg::onAcadKeepFocus( UINT_PTR, LONG_PTR)
|
|
{
|
|
POINT pt;
|
|
::GetCursorPos(&pt);
|
|
CRect rect;
|
|
GetWindowRect(&rect);
|
|
if(!(rect.PtInRect(pt)))
|
|
{
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::SetSideAndCenterLines(AcDbObjectIdArray& arSideIds,AcDbObjectIdArray& arCenIds)
|
|
{
|
|
m_arSideIds.append(arSideIds);
|
|
m_arCenIds.append(arCenIds);
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::SetSideAndCenterLayer(LPCTSTR pszCen,LPCTSTR pszSide)
|
|
{
|
|
if (pszSide != NULL) m_sSideLay = pszSide;
|
|
if (pszCen != NULL) m_sCenLay = pszCen;
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::SetDbServer(CUIISQLiteServer* pDb)
|
|
{
|
|
m_pDb = pDb;
|
|
}
|
|
|
|
BOOL CWPipeBatReplaceDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
m_wndListPipes.InsertColumn(0,_T("序号"),50,50);
|
|
m_wndListPipes.InsertColumn(1,_T("管线"),200,200);
|
|
|
|
CBitmap bmp;
|
|
if (!bmp.LoadBitmap (IDB_BITMAPDUCTSTA))
|
|
{
|
|
return FALSE;
|
|
}
|
|
BITMAP bmpObj;
|
|
bmp.GetBitmap (&bmpObj);
|
|
|
|
UINT nFlags = ILC_COLOR24 | ILC_MASK;
|
|
m_Imagelist.Create (16, bmpObj.bmHeight, nFlags, 0, 0);
|
|
m_Imagelist.Add (&bmp, RGB (255, 0, 0));
|
|
m_wndListPipes.SetImageList(&m_Imagelist,LVSIL_SMALL);
|
|
m_wndListPipes.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
|
|
|
//查壁厚
|
|
CString sSQL,sStd(CoreTools::getCurrentPipeSysTblName());
|
|
if (m_nType > 0)
|
|
{
|
|
CArray<float,float>* pThicks = NULL;
|
|
CStringArray arValues;
|
|
for (int i = 0;i < 100;i++)
|
|
{
|
|
if (g_nDNs[i] == 0)
|
|
break;
|
|
|
|
sSQL.Format(_T("select [外径] from aecod where [公称直径]=%d order by [外径]"),g_nDNs[i]);
|
|
arValues.RemoveAll();
|
|
m_pDb->GetSelData(sSQL,arValues);
|
|
|
|
pThicks = new CArray<float,float>;
|
|
for (int j = 0;j < arValues.GetSize();j++)
|
|
{
|
|
pThicks->Add(_ttof(arValues.GetAt(j)));
|
|
}
|
|
m_mapDn2OD.SetAt(g_nDNs[i],pThicks);
|
|
}
|
|
}
|
|
|
|
//分析管线
|
|
if (m_arCenIds.length() > 0)
|
|
{
|
|
PreFormatWPipeByCenter();
|
|
}
|
|
else
|
|
{
|
|
PreFormatWPipeBySide();
|
|
}
|
|
m_bStart = false;
|
|
InitMaterial();
|
|
|
|
//显示当前图层系统
|
|
//sSQL = _T("select tablename from wpipecfg where currstd=1");
|
|
//m_pDb->GetSelData(sSQL,sStd);
|
|
|
|
sSQL.Format(_T("select distinct system from %s"),sStd);
|
|
CStringArray arSyses;
|
|
m_pDb->GetSelData(sSQL,arSyses);
|
|
|
|
for (int i = 0;i < arSyses.GetSize();i++)
|
|
{
|
|
m_wndComboSys.AddString(arSyses.GetAt(i));
|
|
}
|
|
|
|
if (arSyses.GetSize() > 0)
|
|
{
|
|
m_wndComboSys.SetCurSel(0);
|
|
m_wndComboSys.GetLBText(0,m_sCurrSys);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::InitMaterial()
|
|
{
|
|
CString sSQL;
|
|
CStringArray arVals;
|
|
|
|
sSQL = _T("select [材质] from AecMaterial where [类型]='管道'");
|
|
m_pDb->GetSelData(sSQL,arVals);
|
|
|
|
for (int i = 0;i < arVals.GetSize();i++)
|
|
{
|
|
m_wndComboMaters.InsertString(i,arVals.GetAt(i));
|
|
}
|
|
|
|
sSQL = _T("select [材质] from AecMaterial where [类型]='管件'");
|
|
m_pDb->GetSelData(sSQL,arVals);
|
|
|
|
for (int i = 0;i < arVals.GetSize();i++)
|
|
{
|
|
m_wndComboMaters.InsertString(m_wndComboMaters.GetCount(),arVals.GetAt(i));
|
|
}
|
|
|
|
if ( arVals.GetSize() > 0)
|
|
m_wndComboMaters.SetCurSel(0);
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::OnClose()
|
|
{
|
|
CDialog::OnClose();
|
|
delete this;
|
|
}
|
|
|
|
BOOL CWPipeBatReplaceDlg::OnCommand(WPARAM wParam, LPARAM lParam)
|
|
{
|
|
switch (LOWORD(wParam))
|
|
{
|
|
case IDCANCEL:
|
|
return TRUE;
|
|
default:
|
|
break;
|
|
}
|
|
return CDialog::OnCommand(wParam, lParam);
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::PreFormatWPipeByCenter()
|
|
{
|
|
//锁定文档
|
|
AcApDocument* pDoc = acDocManager->curDocument();
|
|
acDocManager->lockDocument(pDoc);
|
|
|
|
double dDis = 0.0;
|
|
CString sNo,sDuct;
|
|
AcGePoint3d ptMid;
|
|
AcGeVector3d vtDir;
|
|
|
|
AcDbEntity* pEnt = NULL;
|
|
for (int i = 0;i < m_arCenIds.length();i++)
|
|
{
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_arCenIds.at(i),AcDb::kForRead))
|
|
{
|
|
AcDbLine* pLine = AcDbLine::cast(pEnt);
|
|
if (pLine != NULL)
|
|
{
|
|
dDis = pLine->endPoint().distanceTo(pLine->startPoint());
|
|
sNo.Format(_T("%d"),i + 1);
|
|
m_wndListPipes.InsertItem(i,sNo,IMG_NULL);
|
|
m_wndListPipes.SetItemData(i,0);
|
|
|
|
sDuct.Format(_T("管线 长度 : %.1f"),dDis);
|
|
m_wndListPipes.SetItemText(i,1,sDuct);
|
|
|
|
Midpoint(pLine->startPoint(),pLine->endPoint(),ptMid);
|
|
vtDir = pLine->endPoint() - pLine->startPoint();
|
|
|
|
m_arPoints.append(ptMid);
|
|
m_arDirs.append(vtDir);
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
acDocManager->unlockDocument(pDoc);
|
|
}
|
|
|
|
static BOOL IsDn(int nDn)
|
|
{
|
|
int i = 0;
|
|
while(g_nDNs[i] != 0)
|
|
{
|
|
if (nDn == g_nDNs[i])
|
|
{
|
|
return TRUE;
|
|
}
|
|
i += 1;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
int CWPipeBatReplaceDlg::IsOD(double dOD)
|
|
{
|
|
int nDn = 0;
|
|
double dOD2;
|
|
CArray<float,float>* pThicks;
|
|
for (POSITION ps = m_mapDn2OD.GetStartPosition();ps != NULL;)
|
|
{
|
|
m_mapDn2OD.GetNextAssoc(ps,nDn,(PVOID&)pThicks);
|
|
|
|
for(int i = 0;i < pThicks->GetSize();i++)
|
|
{
|
|
dOD2 = pThicks->GetAt(i);
|
|
if ( fabs(dOD - dOD2) < 1.e-3)
|
|
{
|
|
return nDn;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::PreFormatWPipeBySide()
|
|
{
|
|
//锁定文档
|
|
AcApDocument* pDoc = acDocManager->curDocument();
|
|
acDocManager->lockDocument(pDoc);
|
|
|
|
PipeSideLine sideLine;
|
|
CArray<PipeSideLine,PipeSideLine&> arSideLns;
|
|
|
|
double dLen = 0.0;
|
|
CString sNo,sDuct;
|
|
|
|
//提取数据
|
|
AcDbEntity* pEnt = NULL;
|
|
for (int i = 0;i < m_arSideIds.length();i++)
|
|
{
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_arSideIds.at(i),AcDb::kForRead))
|
|
{
|
|
AcDbLine* pLine = AcDbLine::cast(pEnt);
|
|
if (pLine != NULL)
|
|
{
|
|
sideLine.ptSta = pLine->startPoint();
|
|
sideLine.ptEnd = pLine->endPoint();
|
|
sideLine.id = m_arSideIds.at(i);
|
|
arSideLns.Add(sideLine);
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
acDocManager->unlockDocument(pDoc);
|
|
|
|
//长度,平行(同向),公称系列[间隙]
|
|
AcGeVector3d vtDir1,vtDir2,vtDir3;
|
|
AcGePoint3d ptOn,ptFr,ptTo,ptMid,ptCen,ptCen2;
|
|
PipeSide2Line pipeSide2ln;
|
|
|
|
int nDn = 0;
|
|
while(arSideLns.GetSize() > 0)
|
|
{
|
|
PipeSideLine sideLine1 = arSideLns.GetAt(0);
|
|
vtDir1 = sideLine1.ptEnd - sideLine1.ptSta;
|
|
|
|
//找余下的 长度,平行(同向),公称系列[间隙] 都满足的系列
|
|
arSideLns.RemoveAt(0);
|
|
|
|
for (int i = 0;i < arSideLns.GetSize();i++)
|
|
{
|
|
PipeSideLine sideLine2 = arSideLns.GetAt(i);
|
|
vtDir2 = sideLine2.ptEnd - sideLine2.ptSta;
|
|
|
|
//等长,同向,等标高
|
|
if ( /*fabs(vtDir1.length() - vtDir2.length() ) < 1.e-6 &&*/
|
|
vtDir1.isParallelTo(vtDir2) &&
|
|
fabs(sideLine1.ptSta.z - sideLine2.ptSta.z) < 1.e-6 )
|
|
{
|
|
//取最短,按最短的计算,且长度必须大于 2 * DN
|
|
double dLen1 = sideLine1.ptSta.distanceTo(sideLine1.ptEnd);
|
|
double dLen2 = sideLine2.ptSta.distanceTo(sideLine2.ptEnd);
|
|
|
|
AcDbLine ln(sideLine1.ptSta,sideLine1.ptEnd);
|
|
ln.getClosestPointTo(sideLine2.ptSta,ptOn,Adesk::kTrue);
|
|
|
|
//两线有交集
|
|
Midpoint(sideLine2.ptSta,sideLine2.ptEnd,ptMid);
|
|
ln.getClosestPointTo(ptMid,ptMid,Adesk::kTrue);
|
|
|
|
AcGeLineSeg3d lnSeg(sideLine1.ptSta,sideLine1.ptEnd);
|
|
if (!lnSeg.isOn(ptMid))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
nDn = (int)(sideLine2.ptSta.distanceTo(ptOn) + 0.4);//+0.4取整
|
|
|
|
if (m_nType > 0) //按外径绘制的识别
|
|
{
|
|
if ( ( nDn = IsOD( sideLine2.ptSta.distanceTo(ptOn) ) ) > 0 &&
|
|
__min(dLen1,dLen2) - 1.5 * nDn > 1.e-6) //长度符合条件
|
|
{
|
|
|
|
//取公共部分长度,折算到中心线上
|
|
if (dLen1 > dLen2)//
|
|
{
|
|
ln.setStartPoint(sideLine1.ptSta);
|
|
ln.setEndPoint(sideLine1.ptEnd);
|
|
|
|
ln.getClosestPointTo(sideLine2.ptSta,sideLine1.ptSta,Adesk::kTrue);
|
|
ln.getClosestPointTo(sideLine2.ptEnd,sideLine1.ptEnd,Adesk::kTrue);
|
|
}
|
|
else
|
|
{
|
|
ln.setStartPoint(sideLine2.ptSta);
|
|
ln.setEndPoint(sideLine2.ptEnd);
|
|
|
|
ln.getClosestPointTo(sideLine1.ptSta,sideLine2.ptSta,Adesk::kTrue);
|
|
ln.getClosestPointTo(sideLine1.ptEnd,sideLine2.ptEnd,Adesk::kTrue);
|
|
}
|
|
|
|
pipeSide2ln.ptSta1 = sideLine1.ptSta;
|
|
pipeSide2ln.ptEnd1 = sideLine1.ptEnd;
|
|
pipeSide2ln.id1 = sideLine1.id;
|
|
|
|
pipeSide2ln.ptSta2 = sideLine2.ptSta;
|
|
pipeSide2ln.ptEnd2 = sideLine2.ptEnd;
|
|
pipeSide2ln.id2 = sideLine2.id;
|
|
|
|
pipeSide2ln.nDN = nDn;
|
|
m_arPipeSide2lns.Add(pipeSide2ln);
|
|
|
|
arSideLns.RemoveAt(i);
|
|
i -= 1;//继续循环
|
|
}
|
|
}
|
|
else //按公称直径绘制的识别
|
|
{
|
|
//nDn = (int)(sideLine1.ptEnd.distanceTo(sideLine2.ptEnd) + 0.4);//+0.4取整
|
|
if (IsDn(nDn) && __min(dLen1,dLen2) - 1.5 * nDn > 1.e-6) //符合条件
|
|
{
|
|
//取公共部分长度,折算到中心线上
|
|
if (dLen1 > dLen2)//
|
|
{
|
|
ln.setStartPoint(sideLine1.ptSta);
|
|
ln.setEndPoint(sideLine1.ptEnd);
|
|
|
|
ln.getClosestPointTo(sideLine2.ptSta,sideLine1.ptSta,Adesk::kTrue);
|
|
ln.getClosestPointTo(sideLine2.ptEnd,sideLine1.ptEnd,Adesk::kTrue);
|
|
}
|
|
else
|
|
{
|
|
ln.setStartPoint(sideLine2.ptSta);
|
|
ln.setEndPoint(sideLine2.ptEnd);
|
|
|
|
ln.getClosestPointTo(sideLine1.ptSta,sideLine2.ptSta,Adesk::kTrue);
|
|
ln.getClosestPointTo(sideLine1.ptEnd,sideLine2.ptEnd,Adesk::kTrue);
|
|
}
|
|
|
|
pipeSide2ln.ptSta1 = sideLine1.ptSta;
|
|
pipeSide2ln.ptEnd1 = sideLine1.ptEnd;
|
|
pipeSide2ln.id1 = sideLine1.id;
|
|
|
|
pipeSide2ln.ptSta2 = sideLine2.ptSta;
|
|
pipeSide2ln.ptEnd2 = sideLine2.ptEnd;
|
|
pipeSide2ln.id2 = sideLine2.id;
|
|
|
|
pipeSide2ln.nDN = nDn;
|
|
m_arPipeSide2lns.Add(pipeSide2ln);
|
|
|
|
arSideLns.RemoveAt(i);
|
|
i -= 1;//继续循环
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//显示到list 中
|
|
int nItem = 0;
|
|
for (int i = 0;i < m_arPipeSide2lns.GetSize();i++)
|
|
{
|
|
PipeSide2Line& pside2ln = m_arPipeSide2lns.GetAt(i);
|
|
sDuct.Format(_T("管线 长度 : %.1f 公称直径 : %d"),pside2ln.ptSta1.distanceTo(pside2ln.ptEnd1),pside2ln.nDN );
|
|
|
|
sNo.Format(_T("%d"),i + 1);
|
|
m_wndListPipes.InsertItem(i,sNo,IMG_NULL);//
|
|
m_wndListPipes.SetItemData(i,0);
|
|
|
|
m_wndListPipes.SetItemText(i,1,sDuct);//
|
|
m_wndListPipes.SetItemData(i,(DWORD_PTR)i);
|
|
}
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::OnBnClickedOk()
|
|
{
|
|
//锁定文档
|
|
AcApDocument* pDoc = acDocManager->curDocument();
|
|
if (pDoc != NULL) acDocManager->lockDocument(pDoc);
|
|
|
|
DoPipeMakeCommand();
|
|
|
|
if (pDoc != NULL) acDocManager->unlockDocument(pDoc);
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::OnLvnItemchangedListwpipe(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
|
|
if (!m_bStart)
|
|
OnNMClickListwpipe(pNMHDR,pResult);
|
|
*pResult = 0;
|
|
}
|
|
|
|
bool CWPipeBatReplaceDlg::FindPipeWidth(AcGePoint3d* pptGes,AcGeVector3d& vtDir,AcGePoint3d ptMid,double dLen,double& dWidth)
|
|
{
|
|
int i = 0;
|
|
ads_point pt[4];
|
|
for (i = 0;i < 4;i++)
|
|
{
|
|
acdbWcs2Ucs(asDblArray(pptGes[i]),pt[i],false);
|
|
}
|
|
|
|
struct resbuf* pointlist;
|
|
pointlist = acutBuildList(RTPOINT, pt[0], RTPOINT, pt[1],
|
|
RTPOINT, pt[2], RTPOINT, pt[3], 0);
|
|
|
|
/*
|
|
for (i = 0;i < 3;i++)
|
|
{
|
|
acedGrDraw(pt[i],pt[i+1],1,0);
|
|
}
|
|
*/
|
|
|
|
TCHAR szBuf[64];
|
|
struct resbuf eb1,eb2;
|
|
eb1.restype = 0;
|
|
_tcscpy(szBuf, _T("LINE"));
|
|
eb1.resval.rstring = szBuf;
|
|
eb1.rbnext = &eb2;
|
|
|
|
eb2.restype = 8; // Layer name
|
|
eb2.resval.rstring = (TCHAR*)(LPCTSTR)m_sSideLay;
|
|
eb2.rbnext = NULL;
|
|
|
|
//锁定文档
|
|
AcApDocument* pDoc = acDocManager->curDocument();
|
|
acDocManager->lockDocument(pDoc);
|
|
|
|
ads_name ss,ent;
|
|
acedSSGet(_T("CP"),pointlist,NULL,&eb1,ss);
|
|
acutRelRb(pointlist);
|
|
|
|
Adesk::Int32 lLen = 0;
|
|
acedSSLength(ss,&lLen);
|
|
|
|
int nW,nCount = 0;
|
|
double dW;
|
|
CMap<int,int,int,int> mapWtoPair;
|
|
AcGePoint3d ptGeon;
|
|
AcGeVector3d vtDirS;
|
|
AcDbEntity* pEnt = NULL;
|
|
AcDbObjectId id;
|
|
for (i = 0;i < lLen;i++)
|
|
{
|
|
acedSSName(ss,i,ent);
|
|
acdbGetObjectId(id,ent);
|
|
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead))
|
|
{
|
|
AcDbLine* pLine = AcDbLine::cast(pEnt);
|
|
if (pLine != NULL)
|
|
{
|
|
vtDirS = pLine->endPoint() - pLine->startPoint();
|
|
if (vtDirS.isParallelTo(vtDir) && fabs(vtDirS.length() - dLen) < 1.e-1)
|
|
{
|
|
pLine->getClosestPointTo(ptMid,ptGeon,Adesk::kTrue);
|
|
dW = ptGeon.distanceTo(ptMid);
|
|
nW = (int)(dW + 0.2);
|
|
|
|
if (IsDn(nW * 2))
|
|
{
|
|
//配对
|
|
nCount = 0;
|
|
if ( mapWtoPair.Lookup(nW,nCount) )
|
|
{
|
|
mapWtoPair.SetAt(nW,nCount + 1);
|
|
}
|
|
else
|
|
{
|
|
mapWtoPair.SetAt(nW,1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
acedSSFree(ss);
|
|
|
|
int nMinW = -1;
|
|
for (POSITION ps = mapWtoPair.GetStartPosition();ps != NULL;)
|
|
{
|
|
mapWtoPair.GetNextAssoc(ps,nW,nCount);
|
|
|
|
if (nCount == 2)
|
|
{
|
|
nMinW = (nMinW < 0) ? nW : __min(nMinW,nW);
|
|
}
|
|
}
|
|
dWidth = nMinW;
|
|
acDocManager->unlockDocument(pDoc);
|
|
return (dWidth < 0) ? false : true;
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::FindPipeWidth(int nItem)
|
|
{
|
|
LVITEM lvItem;
|
|
memset(&lvItem,0,sizeof(LVITEM));
|
|
lvItem.mask = LVIF_IMAGE;
|
|
lvItem.iItem = nItem;
|
|
m_wndListPipes.GetItem(&lvItem);
|
|
|
|
if (lvItem.iImage == IMG_PROOK)
|
|
return;
|
|
|
|
//找到最近的双线;
|
|
if (nItem > -1 && nItem < m_arPoints.length())
|
|
{
|
|
AcGePoint3d ptMid = m_arPoints.at(nItem);
|
|
AcGeVector3d vtDir = m_arDirs.at(nItem);
|
|
double dDis = vtDir.length();
|
|
|
|
//选择实体,按最大2米半径选,取最小;
|
|
AcGeVector3d vtV = vtDir;
|
|
vtV.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
|
vtV.normalize();
|
|
vtDir.normalize();
|
|
|
|
AcGePoint3d ptGe[5];
|
|
ptGe[0] = ptMid;
|
|
ptGe[0] += 40.0 * vtDir;
|
|
ptGe[0] += 1000.0 * vtV;
|
|
|
|
ptGe[1] = ptGe[0] - 80.0 * vtDir;
|
|
ptGe[2] = ptGe[1] - 2000.0 * vtV;
|
|
ptGe[3] = ptGe[2] + 80.0 * vtDir;
|
|
|
|
double dWidth = 0.0;
|
|
FindPipeWidth(ptGe,vtDir,ptMid,dDis,dWidth);
|
|
|
|
m_dDn = dWidth * 2;
|
|
UpdateData(FALSE);
|
|
}
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::OnNMClickListwpipe(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
UpdateData();
|
|
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
|
|
|
|
int nItem = pNMLV->iItem;
|
|
if (nItem != -1)
|
|
{
|
|
CString sText;
|
|
LVITEM lvItem;
|
|
memset(&lvItem,0,sizeof(LVITEM));
|
|
lvItem.mask = LVIF_IMAGE;
|
|
lvItem.iItem = nItem;
|
|
m_wndListPipes.GetItem(&lvItem);
|
|
|
|
if (lvItem.iImage == IMG_NULL )
|
|
{
|
|
lvItem.iImage = IMG_CURPOS;
|
|
m_wndListPipes.SetItem(&lvItem);
|
|
}
|
|
|
|
if (lvItem.iImage == IMG_PROOK)
|
|
{
|
|
*pResult = 0;
|
|
return;
|
|
}
|
|
|
|
sText = m_wndListPipes.GetItemText(nItem,1);
|
|
if (sText.Find(_T("公称直径")) == -1)
|
|
{
|
|
//定位显示
|
|
AcDbObjectId id;
|
|
if (nItem > -1 && nItem < m_arPoints.length())
|
|
{
|
|
AcGePoint3d ptMid = m_arPoints.at(nItem);
|
|
PipelineTools::arxZoomTo(asDblArray(ptMid),2500.0,2500.0);
|
|
FindPipeWidth(nItem); // DN SHOW
|
|
|
|
//hilight
|
|
acedSSSetFirst(NULL, NULL);
|
|
|
|
ads_name entName;
|
|
acdbGetAdsName(entName, m_arCenIds.at(nItem));
|
|
|
|
ads_name ssPick;
|
|
acedSSAdd(entName, NULL, ssPick);
|
|
acedSSSetFirst(ssPick, ssPick);
|
|
|
|
acedSSFree(ssPick);
|
|
actrTransactionManager->flushGraphics();
|
|
acedUpdateDisplay();
|
|
}
|
|
}
|
|
else //无中心线定位
|
|
{
|
|
PipeSide2Line& side2ln = m_arPipeSide2lns.GetAt(nItem);
|
|
|
|
AcGePoint3d ptMid;
|
|
Midpoint(side2ln.ptSta1,side2ln.ptEnd2,ptMid);
|
|
PipelineTools::arxZoomTo(asDblArray(ptMid),2500.0,2500.0);
|
|
|
|
m_dDn = side2ln.nDN;
|
|
UpdateData(FALSE);
|
|
|
|
//hilight
|
|
acedSSSetFirst(NULL, NULL);
|
|
|
|
ads_name entName;
|
|
acdbGetAdsName(entName, side2ln.id1);
|
|
|
|
ads_name ssPick;
|
|
acedSSAdd(entName, NULL, ssPick);
|
|
|
|
acdbGetAdsName(entName, side2ln.id2);
|
|
acedSSAdd(entName,ssPick,ssPick);
|
|
acedSSSetFirst(ssPick, ssPick);
|
|
|
|
acedSSFree(ssPick);
|
|
actrTransactionManager->flushGraphics();
|
|
acedUpdateDisplay();
|
|
}
|
|
}
|
|
|
|
InitPipeThick();
|
|
|
|
*pResult = 0;
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::InitPipeParam(WPipe::PipeParam* pParam)
|
|
{
|
|
CString sThick,sMat;
|
|
int nSel = m_wndComboThick.GetCurSel();
|
|
m_wndComboThick.GetLBText(nSel,sThick);
|
|
|
|
nSel = m_wndComboMaters.GetCurSel();
|
|
m_wndComboMaters.GetLBText(nSel,sMat);
|
|
|
|
pParam->m_dD = m_dDn;
|
|
pParam->m_eD = WPipe::eDN;
|
|
pParam->m_dDN = m_dDn;
|
|
pParam->m_dOD = m_dDn;//
|
|
|
|
pParam->m_dThick = _ttof(sThick);
|
|
pParam->m_dEl = m_dEl;
|
|
pParam->m_dRRatio = 1.5;
|
|
pParam->m_eRed = WPipe::eCen;
|
|
pParam->m_vtECCen.set(0,0,0);
|
|
pParam->m_eElBase = WPipe::kCen;
|
|
pParam->m_dInsThk = _ttof(sThick);//默认同厚度
|
|
|
|
_tcscpy(pParam->szPipeno,_T("PIPENO"));
|
|
_tcscpy(pParam->szMertial,sMat);
|
|
_tcscpy(pParam->szZoneNo,_T("Zoneno"));
|
|
_tcscpy(pParam->szInsMtr,_T("*"));
|
|
_tcscpy(pParam->szDescr,_T("*"));
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::InitPipeThick()
|
|
{
|
|
CString sSQL;
|
|
sSQL.Format(_T("select [壁厚] from AecOD where [公称直径]=%d order by [壁厚]"),(int)m_dDn);
|
|
|
|
CStringArray arVals;
|
|
m_pDb->GetSelData(sSQL,arVals);
|
|
|
|
m_wndComboThick.ResetContent();
|
|
for (int i = 0;i < arVals.GetSize();i++)
|
|
{
|
|
m_wndComboThick.InsertString(i,arVals.GetAt(i));
|
|
}
|
|
if (arVals.GetSize() > 0) m_wndComboThick.SetCurSel(0);
|
|
}
|
|
|
|
void CWPipeBatReplaceDlg::DoPipeMakeCommand()
|
|
{
|
|
UpdateData();
|
|
|
|
int nCurSel = m_wndComboThick.GetCurSel();
|
|
if (nCurSel == -1)
|
|
{
|
|
AfxMessageBox(_T("请选择管子厚度!"));
|
|
return;
|
|
}
|
|
|
|
nCurSel = m_wndComboMaters.GetCurSel();
|
|
if (nCurSel == -1)
|
|
{
|
|
AfxMessageBox(_T("请选择管子材料!"));
|
|
return;
|
|
}
|
|
|
|
nCurSel = m_wndComboSys.GetCurSel();
|
|
if (nCurSel == -1)
|
|
{
|
|
AfxMessageBox(_T("没有选择系统!请选择分系统!"));
|
|
return;
|
|
}
|
|
|
|
m_wndComboSys.GetLBText(nCurSel,m_sCurrSys);
|
|
|
|
//设置系统
|
|
m_sCurrSys = PipelineTools::getCurrentLayerSys();
|
|
|
|
WPipe::PipeParam param;
|
|
memset(¶m,0,sizeof(WPipe::PipeParam));
|
|
InitPipeParam(¶m);
|
|
|
|
CString sText;
|
|
POSITION ps = m_wndListPipes.GetFirstSelectedItemPosition();
|
|
if (ps != NULL)
|
|
{
|
|
int nItem = m_wndListPipes.GetNextSelectedItem(ps);
|
|
|
|
LVITEM lvItem;
|
|
memset(&lvItem,0,sizeof(LVITEM));
|
|
lvItem.mask = LVIF_IMAGE;
|
|
lvItem.iItem = nItem;
|
|
m_wndListPipes.GetItem(&lvItem);
|
|
|
|
if (lvItem.iImage == IMG_PROOK)
|
|
{
|
|
return;
|
|
}
|
|
|
|
sText = m_wndListPipes.GetItemText(nItem,1);
|
|
TDbPipeJig jig;
|
|
TDbPipeLine pipeline(&jig);
|
|
pipeline.SetPipeParam(¶m);
|
|
|
|
AcGePoint3d ptSta,ptEnd;
|
|
|
|
if (sText.Find(_T("公称直径")) == -1)//根据中心线获取的管线
|
|
{
|
|
AcDbEntity* pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_arCenIds.at(nItem),AcDb::kForRead))
|
|
{
|
|
AcDbLine* pLine = AcDbLine::cast(pEnt);
|
|
if (pLine != NULL)
|
|
{
|
|
ptSta = pLine->startPoint();
|
|
ptEnd = pLine->endPoint();
|
|
}
|
|
pEnt->close();
|
|
}
|
|
ptSta.z = m_dEl;
|
|
ptEnd.z = m_dEl;
|
|
if ( pipeline.CreatePipe(ptSta,ptEnd,¶m) )
|
|
{
|
|
lvItem.iImage = IMG_PROOK;
|
|
m_wndListPipes.SetItem(&lvItem);
|
|
}
|
|
}
|
|
else//根据边线创建管线
|
|
{
|
|
PipeSide2Line& pipeSide2ln = m_arPipeSide2lns.GetAt(nItem);
|
|
|
|
Midpoint(pipeSide2ln.ptSta1,pipeSide2ln.ptSta2,ptSta);
|
|
Midpoint(pipeSide2ln.ptEnd1,pipeSide2ln.ptEnd2,ptEnd);
|
|
|
|
ptSta.z = m_dEl;
|
|
ptEnd.z = m_dEl;
|
|
|
|
if ( pipeline.CreatePipe(ptSta,ptEnd,¶m) )
|
|
{
|
|
lvItem.iImage = IMG_PROOK;
|
|
m_wndListPipes.SetItem(&lvItem);
|
|
}
|
|
}
|
|
}
|
|
}
|