Files
envi-code/SourceCode/Code2026/EarthWormCmd/PSGDDlg.cpp
T
2026-09-28 15:28:50 +08:00

538 lines
12 KiB
C++

#include "stdafx.h"
#include "PSGDDlg.h"
#include "AecDbEarthWorm.h"
#include "UITools.h"
#include "axlock.h"
#ifndef Plumbing_DB
#define Plumbing_DB _T("\\Plumbing.db")
#endif
extern CString IDCreate();
static void FreeBuffer(AcDbVoidPtrArray& arEntPtrs)
{
AcDbEntity* pEnt = NULL;
while (arEntPtrs.length() > 0 )
{
pEnt = (AcDbEntity*)arEntPtrs.last();
DELETE_PTR(pEnt);
arEntPtrs.removeLast();
}
}
static const Adesk::UInt16 kColorByBlock = 0;
static const Adesk::UInt16 kRed = 1;
static const Adesk::UInt16 kYellow = 2;
static const Adesk::UInt16 kGreen = 3;
static const Adesk::UInt16 kCyan = 4;
static const Adesk::UInt16 kBlue = 5;
static const Adesk::UInt16 kMagenta = 6;
static const Adesk::UInt16 kWhite = 7;
static const Adesk::UInt16 kColorByLayer = 256;
IMPLEMENT_DYNAMIC(CPSGDDlg, CDialog)
CPSGDDlg::CPSGDDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPSGDDlg::IDD, pParent)
, m_nFloor(1)
, m_nCableCount(1)
, m_dSpace(10)
, m_bDJ(FALSE)
, m_bAllRoom(FALSE)
, m_iNo(1)
{
m_nPipeColor = kRed;
m_sCurrSys = _T("");
m_sMertial = _T("");
m_dDn = 300.0;
m_sCrossSectionScr = _T("");
m_dt = 14;
m_sPipeNo = _T("PIPE-001");
m_dOD = 328.0;
m_idxRoom = 0;
m_pRectCell = new AcDbPolyline;
m_pRectCell->addVertexAt(0, AcGePoint2d::kOrigin);
m_pRectCell->addVertexAt(1, AcGePoint2d(1, 0));
m_pRectCell->addVertexAt(1, AcGePoint2d(1, 1));
m_pRectCell->addVertexAt(1, AcGePoint2d(0, 1));
m_pRectCell->setColorIndex(6);
m_pRectCell->setClosed(Adesk::kTrue);
m_pRectCell->setConstantWidth(0.1);
}
CPSGDDlg::~CPSGDDlg()
{
}
void CPSGDDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_wndPipeList);
DDX_Control(pDX, IDC_LIST2, m_wndListBoxMaters);
DDX_LBString(pDX, IDC_LIST2, m_sMertial);
DDX_Control(pDX, IDC_LIST3, m_wndSysListBox);
DDX_Text(pDX, IDC_EDIT6, m_sPipeNo);
DDX_Text(pDX, IDC_EDIT1, m_nFloor);
DDV_MinMaxInt(pDX, m_nFloor, 1, 99);
DDX_Text(pDX, IDC_EDIT3, m_nCableCount);
DDV_MinMaxInt(pDX, m_nCableCount, 1, 99);
DDX_Text(pDX, IDC_EDIT4, m_dSpace);
DDV_MinMaxDouble(pDX, m_dSpace, 0, 9999);
DDX_Radio(pDX, IDC_RADIO1, m_bDJ);
DDX_Check(pDX, IDC_CHECK2, m_bAllRoom);
DDX_Text(pDX, IDC_EDIT5, m_iNo);
DDV_MinMaxInt(pDX, m_dSpace, 0, 999);
}
BEGIN_MESSAGE_MAP(CPSGDDlg, CDialog)
ON_MESSAGE(WM_VIEW_LBUTTONDOWN, &CPSGDDlg::OnViewLButtonDown)
ON_STN_CLICKED(IDC_STATIC_COLOR, &CPSGDDlg::OnStnClickedStaticColor)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDOK, &CPSGDDlg::OnBnClickedOk)
END_MESSAGE_MAP()
BOOL CPSGDDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 子类化控件对象
if (!m_wndViewCtrl.SubclassDlgItem(IDC_STATIC_EW, this))
{
// 错误时,结束对话框
EndDialog(IDCANCEL);
return FALSE;
}
ShowEarthWorm();
m_wndPipeList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_wndPipeList.InsertColumn(0,_T("公称直径"),LVCFMT_LEFT,60);
m_wndPipeList.InsertColumn(1,_T("外径"),LVCFMT_LEFT,60);
m_wndPipeList.InsertColumn(2,_T("壁厚"),LVCFMT_LEFT,60);
m_wndPipeList.InsertColumn(3,_T("线比重"),LVCFMT_LEFT,100);
CString path = FilePath::GetSysDir() + Plumbing_DB;
if (!m_dbSQLite.InitADOServer(path))
{
AfxMessageBox(CString(_T("数据库初始化失败,请检查 sys")) + Plumbing_DB + _T("文件是否存在."));
return FALSE;
}
InitPipeList();
UpdateData(FALSE);
return TRUE;
}
void CPSGDDlg::InitPipeList()
{
CString sSQL,sText;
sSQL = _T("select [公称直径],[外径],[壁厚],[重量] from AecOD order by [公称直径]");
CUIIValueTable table;
m_dbSQLite.GetSelData(sSQL,table);
table.ShowToListCtrl(&m_wndPipeList);
double dT = 0.0;
CString sDnold;
sDnold.Format(_T("%d"),(int)m_dDn);
bool bFind = false;
for (int i = 0;i < m_wndPipeList.GetItemCount();i++)
{
sText = m_wndPipeList.GetItemText(i,0);
dT = _ttof(m_wndPipeList.GetItemText(i,2));
if (sText.CompareNoCase(sDnold) == 0 && fabs(m_dt - dT) < 1.e-2)
{
m_wndPipeList.SetItemState(i,LVIS_SELECTED,LVIS_SELECTED);
m_wndPipeList.EnsureVisible(i,TRUE);
bFind = true;
break;
}
}
if (!bFind)
{
if (m_wndPipeList.GetItemCount() > 0)
m_wndPipeList.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
}
//材质
CStringArray arVals;
sSQL = _T("select [材质] from AecMaterial where [类型]='管道'");
m_dbSQLite.GetSelData(sSQL,arVals);
int nCursel = 0;
for (i = 0;i < arVals.GetSize();i++)
{
m_wndListBoxMaters.AddString(arVals.GetAt(i));
if (m_sMertial.CompareNoCase(arVals.GetAt(i)) == 0)
{
nCursel = i;
}
}
m_wndListBoxMaters.SetCurSel(nCursel);
//系统
CString sStd,sTemp;
sSQL = _T("select tablename from wpipecfg where currstd=1");
m_dbSQLite.GetSelData(sSQL,sStd);
sSQL.Format(_T("select distinct system from %s"),sStd);
CStringArray arSyses;
m_dbSQLite.GetSelData(sSQL,arSyses);
nCursel = 0;
for (int i = 0;i < arSyses.GetSize();i++)
{
sTemp = arSyses.GetAt(i);
m_wndSysListBox.AddString(sTemp);
if (m_sCurrSys.CompareNoCase(sTemp) == 0)
{
nCursel = i;
}
}
m_wndSysListBox.SetCurSel(nCursel);
}
LRESULT CPSGDDlg::OnViewLButtonDown(WPARAM wp, LPARAM lp)
{
UpdateData();
AcGePoint3d* pPt = (AcGePoint3d*)lp;
pPt->z = 0.0;
//判断 点落在 room 内
AecDbEarthWorm worm;
worm.SetStartPoint(AcGePoint2d(0,0));
worm.SetEndPoint(AcGePoint2d(80.0,0));
worm.SetStartElevation(0.0);
worm.SetCrossSectionScr(m_sCrossSectionScr);
worm.SetChamferInter(100.0);
worm.AddSegment(0, 0.0, 80.0, _T("KZ001"));
ESection eType = eRect;
AcGePoint2dArray arDatas;
eType = worm.ExtractEarthWormScr(arDatas);
AcGeLineSeg3d ln;
AcGePoint3d pt2(1000.0, 0, 0);
ln.set(AcGePoint3d::kOrigin, pt2);
AcGePoint3d ptGe[4];
AcDbVoidPtrArray arRegPtrs;
int nRooms = worm.CreateSectionRoomRegion(ln, eType, arDatas, arRegPtrs);
if (nRooms > 0)
{
AcDbRegion* pReg = NULL;
for (int i = 0; i < arRegPtrs.length(); i++)
{
pReg = (AcDbRegion*)arRegPtrs.at(i);
if (pReg != NULL)
{
AcDbExtents ext;
pReg->getGeomExtents(ext);
ptGe[0] = ext.minPoint();
ptGe[1] = ptGe[0];
ptGe[1].x = ext.maxPoint().x;
ptGe[2] = ext.maxPoint();
ptGe[3] = ptGe[0];
ptGe[3].y = ext.maxPoint().y;
if (KTCADUtilityEx::IsPointInBoundary(*pPt, ptGe[0], ptGe[2]))
{
m_idxRoom = i;
AcGsView* pView = m_wndViewCtrl.view();
AcGsModel* pModel = m_wndViewCtrl.model();
if (pView != NULL)
{
if (m_pRectCell != NULL)
pView->erase(m_pRectCell);
}
if (m_pRectCell != NULL)
{
for (int i = 0; i < 4; i++)
{
m_pRectCell->setPointAt(i, ptGe[i].convert2d(AcGePlane::kXYPlane));
}
}
if (pView != NULL)
{
pView->add(m_pRectCell, pModel);
}
break;
}
}
}
if (m_idxRoom == -1)
{
m_pRectCell->setPointAt(0, AcGePoint2d::kOrigin);
m_pRectCell->setPointAt(1, AcGePoint2d(1, 0));
m_pRectCell->setPointAt(2, AcGePoint2d(1, 1));
m_pRectCell->setPointAt(3, AcGePoint2d(0, 1));
}
FreeBuffer(arRegPtrs);
m_wndViewCtrl.view()->invalidate();
m_wndViewCtrl.RedrawWindow();
}
return 0L;
}
void CPSGDDlg::OnStnClickedStaticColor()
{
acedSetColorDialog(m_nPipeColor, Adesk::kFalse, m_nPipeColor);
Invalidate();
}
HBRUSH CPSGDDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC)
{
if (pWnd != NULL && pWnd->GetDlgCtrlID() == IDC_STATIC_COLOR)
{
COLORREF crColor = RGB(255,255,255);
if (m_nPipeColor == kColorByLayer)
{
crColor = RGB(255,255,255);
}
else
{
crColor = acedGetRGB(m_nPipeColor);
}
CRect rc;
pWnd->GetClientRect(rc);
pDC->FillSolidRect(rc,crColor);
}
}
return hbr;
}
void CPSGDDlg::ShowEarthWorm()
{
m_wndViewCtrl.clearAll();
m_wndViewCtrl.init(true);
m_wndViewCtrl.SetOrbitFlag(OBF_PAN | OBF_ZOOM | OBF_COTE);
if (m_sCrossSectionScr.Find(_T("RECT:")) != -1)
{
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);
worm.SetChamferInter(100.0);
ESection eType = eRect;
AcGePoint2dArray arDatas;
eType = worm.ExtractEarthWormScr(arDatas);
AcGeLineSeg3d ln;
AcGePoint3d pt2(1000.0, 0, 0);
ln.set(AcGePoint3d::kOrigin, pt2);
AcDbRegion* pEWRegion = worm.CreateSectionRegion(ln, eType, arDatas);
if (pEWRegion != NULL)
{
AcDbVoidPtrArray arr;
int rooms = worm.CreateSectionRoomRegion(ln, eType, arDatas, arr);
Acad::ErrorStatus es;
AcDbRegion* pRegIn = NULL;
AcDbEntity* pEnt = NULL;
AcDbVoidPtrArray arr2;
worm.CreateSectionRoomAddition(ln,eType,arr2);
for (int i = 0; i < arr2.length(); i++)
{
pEnt = (AcDbEntity*)arr2.at(i);
pRegIn = AcDbRegion::cast(pEnt);
if (pRegIn != NULL)
{
es = pEWRegion->booleanOper(AcDb::kBoolUnite,pRegIn);
}
else
{
m_wndViewCtrl.Add(pEnt);
}
}
AcDbExtents exts;
pEWRegion->getGeomExtents(exts);
m_wndViewCtrl.InitFromCurrentView2D(exts,true);
m_wndViewCtrl.Add(pEWRegion);
m_wndViewCtrl.view()->invalidate();
m_wndViewCtrl.Invalidate();
m_wndViewCtrl.RedrawWindow();
}
}
else
{
}
}
int CPSGDDlg::GetPipe(AecDbEwPipe*& pPipe)
{
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);
worm.SetChamferInter(100.0);
AcGePoint3d ptOrg;
AcGePoint2d ptThick;
AcArray<ERoom> arRooms;
AcGeLineSeg3d ln(AcGePoint3d::kOrigin,AcGePoint3d(10.0,0.0,0));
worm.GetSectionRoomsTo(ln,arRooms,ptThick);
bool bIsModify = false;
if (pPipe == NULL)
{
pPipe = new AecDbEwPipe;
}
else
{
bIsModify = true;
}
if (m_idxRoom > -1)
{
//ERoom& room = arRooms.at(m_idxRoom);
//ptOrg = m_bRight ? room.ptGe[1] : room.ptGe[0];
//AcGeVector3d vtDirX = room.ptGe[1] - room.ptGe[0];
//if (m_bRight) vtDirX *= -1;
//vtDirX.normalize();
////抬高
//ptOrg.z += 0.5 * AS_MUNIT(m_dDn);
}
else
{
//ERoom& room = arRooms.at(0);
//ptOrg = m_bRight ? room.ptGe[1] : room.ptGe[0];
//AcGeVector3d vtDirX = room.ptGe[1] - room.ptGe[0];
//if (m_bRight) vtDirX *= -1;
//vtDirX.normalize();
////抬高
//ptOrg.z += 0.5 * AS_MUNIT(m_dDn);
}
AcGeVector3d vtZ = AcGeVector3d::kXAxis;
vtZ.normalize();
AcDbX3dSolid* pXSolid = NULL;
ptOrg += 40.0 * vtZ;
//设置半径和厚度
pPipe->SetSection(AS_MUNIT(m_dDn),0.0);//AS_MUNIT(m_dt)
//设置起始点,可以通过官位得到,后期改动
AcGePoint3d ptSta,ptEnd;
ptSta = ptOrg - vtZ * 40.0;
ptEnd = ptOrg + vtZ * 40.0;
if (!bIsModify)
{
pPipe->SetBaseCurve(ptSta,ptEnd);
}
//不需要BOOL并到Fit中的标志
pPipe->GetSpecialtyData()->SetAt(_T("COLOR"),m_nPipeColor);//系统默认KEY COLOR
//序列化BIM数据
pPipe->GetSpecialtyData()->SetAt(_T("m_dX"),0.0);
pPipe->GetSpecialtyData()->SetAt(_T("m_dZ"),0.0);
pPipe->GetSpecialtyData()->SetAt(_T("m_nN"),1);
pPipe->GetSpecialtyData()->SetAt(_T("m_dLen"),80.0);
//pPipe->GetSpecialtyData()->SetAt(_T("m_bRight"),m_bRight);
pPipe->GetSpecialtyData()->SetAt(_T("m_bRight"), false);
pPipe->GetSpecialtyData()->SetAt(_T("m_vtDir"),AcGeVector3d::kXAxis);
pPipe->GetSpecialtyData()->SetAt(_T("m_sCurrSys"),m_sCurrSys);
pPipe->GetSpecialtyData()->SetAt(_T("m_sMertial"),m_sMertial);
pPipe->GetSpecialtyData()->SetAt(_T("m_dDn"),m_dDn);
pPipe->GetSpecialtyData()->SetAt(_T("m_dt"),m_dt);
pPipe->GetSpecialtyData()->SetAt(_T("m_dOD"),m_dOD);
pPipe->GetSpecialtyData()->SetAt(_T("m_idxRoom"),m_idxRoom);
pPipe->GetSpecialtyData()->SetAt(_T("m_sCrossSectionScr"),m_sCrossSectionScr);
pPipe->GetSpecialtyData()->SetAt(_T("m_sPipeNo"),m_sPipeNo);
//统一管线接口
pPipe->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 1);
pPipe->GetSpecialtyData()->SetAt(PIPE_DN, AS_MUNIT(m_dDn));
pPipe->GetSpecialtyData()->SetAt(PIPE_OD, AS_MUNIT(m_dOD));
pPipe->GetSpecialtyData()->SetAt(PIPE_THICK, AS_MUNIT(m_dt));
pPipe->GetSpecialtyData()->SetAt(PIPE_MATERIAL, m_sMertial);
pPipe->GetSpecialtyData()->SetAt(PIPE_SYS, m_sCurrSys);
return TRUE;
}
void CPSGDDlg::OnBnClickedOk()
{
UpdateData();
if (m_idxRoom < 0 )
{
AfxMessageBox(_T("请选择舱室铺设管道!"));
}
int nItem = -1;
POSITION ps = m_wndPipeList.GetFirstSelectedItemPosition();
if (ps != NULL)
{
nItem = m_wndPipeList.GetNextSelectedItem(ps);
}
if (nItem == -1)
{
AfxMessageBox(_T("请选择管道规格!"));
return;
}
m_dDn = _ttof( m_wndPipeList.GetItemText(nItem,0) );
m_dOD = _ttof(m_wndPipeList.GetItemText(nItem,1));
m_dt = _ttof(m_wndPipeList.GetItemText(nItem,2));
int nSel = m_wndListBoxMaters.GetCurSel();
if (nSel == -1)
{
AfxMessageBox(_T("请选择管道材质!"));
return;
}
m_wndListBoxMaters.GetText(nSel,m_sMertial);
int nSys = m_wndSysListBox.GetCurSel();
if (nSys == -1)
{
AfxMessageBox(_T("请选择管道用途系统!"));
return;
}
m_wndSysListBox.GetText(nSys,m_sCurrSys);
if (m_idxRoom < 0 && !m_bAllRoom)
{
AfxMessageBox(_T("请选择舱室铺设管道!"));
}
OnOK();
}