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

577 lines
17 KiB
C++

#include "stdafx.h"
#include "AcDbObjectPtr.h"
#include "dbgridsheet.h"
#include "WellCalcEarthworkDlg.h"
void CalcEarthwork()
{
Entity ent;
RBList rbMask(RTDXF0, _T("AEC_ZT_VERTICALSECTION,AEC_ZT_VERTICALSECTION_FEED"), NULL);
if (GlobalFunc::SelectEntity(_T("\n请选择纵断面图<退出>:"), ent, rbMask) != RTNORM)
return;
CTemporaryResourceOverride vTemp;
CWellCalcEarthworkDlg dlg;
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbVerticalSection, pVS);
if (pVS) {
pVS->GetWellDatas(dlg.m_lstWellSys);
}
OPENOBJ_END();
OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbVerticalSectionFeed, pVS);
if (pVS) {
pVS->GetWellDatas(dlg.m_lstFeedWell);
dlg.m_bIsFeed = TRUE;
}
OPENOBJ_END();
dlg.DoModal();
if (dlg.m_dRet > 0.001) {
int rows = dlg.m_grid.GetRowNum() + 1;
AcDbObjectId idTextStyle = GlobalFunc::InitTwtTextStyle(g_Option::instance().g_csSheetStyle);
CDbSheet *pSheet = new CDbSheet;
GridStyle gridStyle;
gridStyle.SetOverrideAll(TRUE);
gridStyle.SetTextHeight(g_Option::instance().g_nSheetHeight);
gridStyle.SetTextStyleId(idTextStyle);
SheetTitle &title = pSheet->GetTitle();
title.SetHeight(7.0);
title.SetText(_T("土方计算表"));
DividerStyle &style = title.GetDividerStyle();
style.SetDividerFlag(DividerStyle::kNone);
gridStyle.SetHorMode(AcDb::kTextCenter);
gridStyle.SetVerMode(AcDb::kTextVertMid);
gridStyle.SetLineSpaceFactor(0.2);
gridStyle.SetTextWrap(FALSE);
pSheet->SetGridStyle(gridStyle);
pSheet->SetRowHeight(g_Option::instance().g_nSheetHeight + 2);
pSheet->InitSheet(rows, 6, g_Option::instance().g_nSheetHeight + 2, 50);
SheetColumn column;
column.SetWidth(15);
pSheet->SetColumnAt(0, column);
GridCell &cell = *(*pSheet)(0, 0);
cell.SetText(_T("序号"));
column.SetWidth(15);
pSheet->SetColumnAt(1, column);
GridCell &cell4 = *(*pSheet)(0, 1);
cell4.SetText(_T("管长(m)"));
column.SetWidth(15);
pSheet->SetColumnAt(2, column);
GridCell &cell5 = *(*pSheet)(0, 2);
cell5.SetText(_T("管径(mm)"));
column.SetWidth(15);
pSheet->SetColumnAt(3, column);
GridCell &cell6 = *(*pSheet)(0, 3);
cell6.SetText(_T("坡度‰"));
column.SetWidth(20);
pSheet->SetColumnAt(4, column);
GridCell &cell7 = *(*pSheet)(0, 4);
cell7.SetText(_T("槽底挖宽m"));
column.SetWidth(20);
pSheet->SetColumnAt(5, column);
GridCell &cell8 = *(*pSheet)(0, 5);
cell8.SetText(_T("土方量(立方米)"));
int idx(1);
for (dlg.m_grid.MoveToFirst(); !dlg.m_grid.IsOut(); dlg.m_grid.MoveToNext()) {
WDGridRow *pRow = dlg.m_grid.CurRow();
CString csFrom = (LPCTSTR)(*pRow)[0].GetText();
CString csTo = (LPCTSTR)(*pRow)[1].GetText();
CString csLen = (LPCTSTR)(*pRow)[2].GetText();
CString csDn = (LPCTSTR)(*pRow)[3].GetText();
CString csI = (LPCTSTR)(*pRow)[4].GetText();
CString csWidth = (LPCTSTR)(*pRow)[7].GetText();
CString csV = (LPCTSTR)(*pRow)[8].GetText();
csFrom = csFrom + _T("-") + csTo;
GridCell &cell9 = *(*pSheet)(idx, 0);
cell9.SetText(csFrom);
GridCell &cell10 = *(*pSheet)(idx, 1);
cell10.SetText(csLen);
GridCell &cell11 = *(*pSheet)(idx, 2);
cell11.SetText(csDn);
GridCell &cell12 = *(*pSheet)(idx, 3);
cell12.SetText(csI);
GridCell &cell13 = *(*pSheet)(idx, 4);
cell13.SetText(csWidth);
GridCell &cell14 = *(*pSheet)(idx, 5);
cell14.SetText(csV);
idx++;
}
XPoint pt;
if (XGetPoint(NULL, _T("\n点取表格位置:<退出>"), pt) != RTNORM)
return;
pSheet->SetLocation(pt);
//pSheet->AddToCSpace(TRUE);
GlobalFunc::AddToCurrentSpace(pSheet, TRUE);
}
}
/////////////////////////////////////////////////////////////////////////////
// CWellCalcEarthworkDlg dialog
CWellCalcEarthworkDlg::CWellCalcEarthworkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWellCalcEarthworkDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWellCalcEarthworkDlg)
m_dGradient = 1;
m_dRet = 0.0;
m_dDeep = 100;
m_bIsFeed = FALSE;
//}}AFX_DATA_INIT
}
void CWellCalcEarthworkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWellCalcEarthworkDlg)
DDX_Text(pDX, IDC_EDIT_GRADIENT, m_dGradient);
DDX_Text(pDX, IDC_EDIT_RET, m_dRet);
DDX_Text(pDX, IDC_EDIT_DEEP, m_dDeep);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWellCalcEarthworkDlg, CDialog)
//{{AFX_MSG_MAP(CWellCalcEarthworkDlg)
ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWellCalcEarthworkDlg message handlers
BOOL CWellCalcEarthworkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_grid.Clear();
m_grid.AppendCol(_T("起点"), 35);
m_grid.AppendCol(_T("终点"), 35);
m_grid.AppendCol(_T("管长m"), 50);
m_grid.AppendCol(_T("管径mm"), 50);
m_grid.AppendCol(_T("坡度‰"), 55);
m_grid.AppendCol(_T("超挖深度mm"), 65);
m_grid.AppendCol(_T("边坡坡度"), 60);
m_grid.AppendCol(_T("槽底挖宽m"), 60);
m_grid.AppendCol(_T("土方量(立方米)"), 60);
m_grid.Create(this, IDC_LIST_PIPE);
m_grid.FitLastCol();
m_grid.SetNoAppendButton(TRUE);
m_grid.SetNoDefaultMenu(true);
COLORREF color = RGB(255, 0, 0);
m_grid.GetCol(5).SetTextColor(color);
m_grid.GetCol(6).SetTextColor(color);
COLORREF color2 = RGB(0, 0, 255);;
m_grid.GetCol(7).SetTextColor(color2);
m_grid.GetCol(8).SetTextColor(color2);
UpdateGrid();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CWellCalcEarthworkDlg::UpdateGrid()
{
long iCurRow = m_grid.GetCurRowIndex();
m_grid.Clear();
int idx = 0;
if (!m_bIsFeed)
{
for (int i = 0; i < m_lstWellSys.Length() - 1; i++) {
if (m_lstWellSys[i]->m_bIsWell) { //井
if (i == m_lstWellSys.Length() - 2)
break;
CString csName1 = m_lstWellSys[i]->m_csName;
CString csName2 = m_lstWellSys[i + 2]->m_csName;
if (csName1 == _T("") || csName2 == _T(""))
continue;
CString csArea, csAllArea, csFactor, csQ, csTime;
m_grid.AppendRow();
m_grid.GetCell(idx, 0).SetText(csName1);
m_grid.GetCell(idx, 1).SetText(csName2);
}
else { //管
if (i == m_lstWellSys.Length() - 1)
continue;
int iDn = m_lstWellSys[i]->m_iDn;
CString csDn, csPipeLen, csI, csWidth, csGradient;
csDn.Format(_T("%d"), iDn);
csI.Format(_T("%.3f"), m_lstWellSys[i]->m_nI * 1000);
csPipeLen.Format(_T("%.2f"), m_lstWellSys[i]->m_nLength);
m_grid.GetCell(idx, 2).SetText(csPipeLen);
m_grid.GetCell(idx, 3).SetText(csDn);
m_grid.GetCell(idx, 4).SetText(csI);
m_grid.GetCell(idx, 5).SetText(_T("默认"));
m_grid.GetCell(idx, 6).SetText(_T("默认"));
m_lstWellSys[i]->m_nFrondDownEle = -1;
m_lstWellSys[i]->m_nSpare = -1;
idx++;
}
}
}
else
{
for (int i = 0; i < m_lstFeedWell.Length() - 1; i++) {
if (m_lstFeedWell[i]->m_bIsWell) { //井
if (i == m_lstFeedWell.Length() - 2)
break;
CString csName1 = m_lstFeedWell[i]->m_csName;
CString csName2 = m_lstFeedWell[i + 2]->m_csName;
if (csName1 == _T("") || csName2 == _T(""))
continue;
CString csArea, csAllArea, csFactor, csQ, csTime;
m_grid.AppendRow();
m_grid.GetCell(idx, 0).SetText(csName1);
m_grid.GetCell(idx, 1).SetText(csName2);
}
else { //管
if (i == m_lstFeedWell.Length() - 1)
continue;
int iDn = m_lstFeedWell[i]->m_iDn;
CString csDn, csPipeLen, csI, csWidth, csGradient;
csDn.Format(_T("%d"), iDn);
csI.Format(_T("%.3f"), m_lstFeedWell[i]->m_nI * 1000);
double dPipeLengthAll(0);
int iPipeNum = m_lstFeedWell[i]->m_lstID.Length();
for (int j = 0; j < iPipeNum; j++)
{
AcDbObjectId id = *m_lstFeedWell[i]->m_lstID[j];
double dPipeLength(0);
OPENOBJ_BEGIN(id, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe) {
dPipeLength = pPipe->Length();
dPipeLengthAll += dPipeLength;
}
OPENOBJ_END();
}
csPipeLen.Format(_T("%.2f"), dPipeLengthAll);
m_grid.GetCell(idx, 2).SetText(csPipeLen);
m_grid.GetCell(idx, 3).SetText(csDn);
m_grid.GetCell(idx, 4).SetText(csI);
m_grid.GetCell(idx, 5).SetText(_T("默认"));
m_grid.GetCell(idx, 6).SetText(_T("默认"));
m_lstFeedWell[i]->m_nFrondDownEle = -1;
m_lstFeedWell[i]->m_nSpare = -1;
idx++;
}
}
}
m_grid.SelectRow(iCurRow, TRUE);
}
double CWellCalcEarthworkDlg::GetPipeThickness(AcDbObjectId id)
{
int iDn(0);
CString csMat;
OPENOBJ_BEGIN(id, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe) {
iDn = (int)pPipe->GetDnDiameter();
csMat = GlobalFunc::GetPipeMaterialByIdx(pPipe->GetMaterial());
}
OPENOBJ_END();
double dOutD = GlobalFunc::GetPipeOutDByDn(csMat, iDn) * 1000 - iDn;
return dOutD;
}
//详<<给水排水管道工程施工及验收规范>> GB50268-97 3.2.1条
double CWellCalcEarthworkDlg::GetLowWidth(AcDbObjectId id)
{
double dRet(0);
int iDn(0);
CString csMat;
OPENOBJ_BEGIN(id, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe) {
iDn = (int)pPipe->GetDnDiameter();
csMat = GlobalFunc::GetPipeMaterialByIdx(pPipe->GetMaterial());
}
OPENOBJ_END();
double dB1(0);
if (csMat.Find(_T("混凝土")) > -1) { //非金属管道
if (iDn <= 500)
dB1 = 400;
else if (iDn <= 1000)
dB1 = 500;
else if (iDn <= 1500)
dB1 = 600;
else
dB1 = 800;
}
else {
if (iDn <= 500)
dB1 = 300;
else if (iDn <= 1000)
dB1 = 400;
else if (iDn <= 1500)
dB1 = 600;
else
dB1 = 800;
}
double dB2 = 200;//b2——管道一侧的支撑厚度,可取150~200mm;
double dOutD = GlobalFunc::GetPipeOutDByDn(csMat, iDn) * 1000;
double dPipeThickness = (dOutD - iDn) / 2.0;
dRet = iDn + 2 * (dB1 + dB2 + dPipeThickness);//B=D1+2(b1+b2+b3)
return dRet / 1000.0;
}
void CWellCalcEarthworkDlg::OnOK()
{
UpdateData(TRUE);
for (m_grid.MoveToFirst(); !m_grid.IsOut(); m_grid.MoveToNext()) {
WDGridRow *pRow = m_grid.CurRow();
int idx = pRow->GetIndex();
CString csDeep = (LPCTSTR)(*pRow)[5].GetText(); //超挖深度
CString csGradient = (LPCTSTR)(*pRow)[6].GetText();//边坡坡度
if (m_bIsFeed)
{
if (csDeep != _T("默认"))
m_lstFeedWell[idx * 2 + 1]->m_nFrondDownEle = _tstof(csDeep);
if (csGradient != _T("默认"))
m_lstFeedWell[idx * 2 + 1]->m_nSpare = _tstof(csGradient);
}
else
{
if (csDeep != _T("默认"))
m_lstWellSys[idx * 2 + 1]->m_nFrondDownEle = _tstof(csDeep);
if (csGradient != _T("默认"))
m_lstWellSys[idx * 2 + 1]->m_nSpare = _tstof(csGradient);
}
}
int idx = 0;
double dAllV(0);
if (!m_bIsFeed)
{
for (int i = 0; i < m_lstWellSys.Length() - 1; i++) {
if (!m_lstWellSys[i]->m_bIsWell) { //管
if (i == m_lstWellSys.Length() - 1)
continue;
int iDn = m_lstWellSys[i]->m_iDn;
CString csWidth, csV;
AcDbObjectId id = m_lstWellSys[i]->m_ID;
double dB = GetLowWidth(id);
csWidth.Format(_T("%.3f"), dB);
m_grid.GetCell(idx, 7).SetText(csWidth);
double dPipeThick = GetPipeThickness(id) / 1000;
double nUpEle1 = m_lstWellSys[i - 1]->m_nUpEle;
double nDownEle1 = m_lstWellSys[i - 1]->m_nDownEle;
double nUpEle2 = m_lstWellSys[i + 1]->m_nUpEle;
double nDownEle2 = m_lstWellSys[i + 1]->m_nFrondDownEle;
double dDeepOver(0); //超挖深度
double dSlopeGradient(0);//边坡坡度
double dPipeLen = m_lstWellSys[i]->m_nLength;
if (m_lstWellSys[i]->m_nFrondDownEle < 0)
dDeepOver = m_dDeep;
else
dDeepOver = m_lstWellSys[i]->m_nFrondDownEle;
dDeepOver = dDeepOver / 1000;
if (m_lstWellSys[i]->m_nSpare < 0)
dSlopeGradient = m_dGradient;
else
dSlopeGradient = m_lstWellSys[i]->m_nSpare;
//如果是负数,说明采用默认值。
double dDeep1 = nUpEle1 - nDownEle1 + dPipeThick + dDeepOver; //起点井挖深
double dWidthUp1 = (dDeep1 * dSlopeGradient) * 2 + dB; //起点井地面挖宽
double dDeep2 = nUpEle2 - nDownEle2 + dPipeThick + dDeepOver; //终点井挖深
double dWidthUp2 = (dDeep2 * dSlopeGradient) * 2 + dB; //终点井地面挖宽
double dS1 = (dB + dWidthUp1) / 2.0 * dDeep1;
double dS2 = (dB + dWidthUp2) / 2.0 * dDeep2;
double dV(0);
dV = (sqrt(dS1 * dS2) + dS1 + dS2) * dPipeLen / 3.0;
dAllV += dV;
csV.Format(_T("%.3f"), dV);
m_grid.GetCell(idx, 8).SetText(csV);
idx++;
}
}
}
else
{
for (int i = 0; i < m_lstFeedWell.Length() - 1; i++) {
if (!m_lstFeedWell[i]->m_bIsWell) { //管
if (i == m_lstFeedWell.Length() - 1)
continue;
int iPipeNum = m_lstFeedWell[i]->m_lstID.Length();
double dBAll(0), dVAllPipe(0);;
for (int j = 0; j < iPipeNum; j++)
{
AcDbObjectId id = *m_lstFeedWell[i]->m_lstID[j];
double dB = GetLowWidth(id);
dBAll += dB;
double dDn(0);
double dPipeLength(0);
OPENOBJ_BEGIN(id, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe) {
dDn = pPipe->GetDnDiameter();
dPipeLength = pPipe->Length();
}
OPENOBJ_END();
double dPipeThick = GetPipeThickness(id) / 1000;
double nUpEle1 = m_lstFeedWell[i - 1]->m_nUpEle;
double nDownEle1 = m_lstFeedWell[i - 1]->m_nDownEle;
double nUpEle2 = m_lstFeedWell[i + 1]->m_nUpEle;
double nDownEle2 = m_lstFeedWell[i + 1]->m_nFrondDownEle;
double dDeepOver(0); //超挖深度
double dSlopeGradient(0);//边坡坡度
// double dPipeLen = m_lstFeedWell[i]->m_nLength;
if (m_lstFeedWell[i]->m_nFrondDownEle < 0)
dDeepOver = m_dDeep;
else
dDeepOver = m_lstFeedWell[i]->m_nFrondDownEle;
dDeepOver = dDeepOver / 1000;
if (m_lstFeedWell[i]->m_nSpare < 0)
dSlopeGradient = m_dGradient;
else
dSlopeGradient = m_lstFeedWell[i]->m_nSpare;
//如果是负数,说明采用默认值。
double dDeep1 = nUpEle1 - nDownEle1 + dDn / 2000 + dPipeThick + dDeepOver; //起点井挖深
double dWidthUp1 = (dDeep1 * dSlopeGradient) * 2 + dB; //起点井地面挖宽
double dDeep2 = nUpEle2 - nDownEle2 + dDn / 2000 + dPipeThick + dDeepOver; //终点井挖深
double dWidthUp2 = (dDeep2 * dSlopeGradient) * 2 + dB; //终点井地面挖宽
double dS1 = (dB + dWidthUp1) / 2.0 * dDeep1;
double dS2 = (dB + dWidthUp2) / 2.0 * dDeep2;
double dV(0);
dV = (sqrt(dS1 * dS2) + dS1 + dS2) * dPipeLength / 3.0;
dVAllPipe += dV;
}
CString csWidth, csV;
csWidth.Format(_T("%.3f"), dBAll);
m_grid.GetCell(idx, 7).SetText(csWidth);
csV.Format(_T("%.3f"), dVAllPipe);
m_grid.GetCell(idx, 8).SetText(csV);
dAllV += dVAllPipe;
/*
double dPipeThick = GetPipeThickness(id) / 1000;
double nUpEle1 = m_lstFeedWell[i-1]->m_nUpEle;
double nDownEle1 = m_lstFeedWell[i-1]->m_nDownEle;
double nUpEle2 = m_lstFeedWell[i+1]->m_nUpEle;
double nDownEle2 = m_lstFeedWell[i+1]->m_nFrondDownEle;
double dDeepOver(0); //超挖深度
double dSlopeGradient(0);//边坡坡度
double dPipeLen = m_lstFeedWell[i]->m_nLength;
if(m_lstFeedWell[i]->m_nFrondDownEle < 0)
dDeepOver = m_dDeep;
else
dDeepOver = m_lstFeedWell[i]->m_nFrondDownEle;
dDeepOver = dDeepOver / 1000;
if(m_lstFeedWell[i]->m_nSpare < 0)
dSlopeGradient = m_dGradient;
else
dSlopeGradient = m_lstFeedWell[i]->m_nSpare;
//如果是负数,说明采用默认值。
double dDeep1 = nUpEle1 - nDownEle1 + dPipeThick + dDeepOver; //起点井挖深
double dWidthUp1 = (dDeep1*dSlopeGradient)*2+dB; //起点井地面挖宽
double dDeep2 = nUpEle2 - nDownEle2 + dPipeThick + dDeepOver; //终点井挖深
double dWidthUp2 = (dDeep2*dSlopeGradient)*2+dB; //终点井地面挖宽
double dS1 = (dB + dWidthUp1)/2.0*dDeep1;
double dS2 = (dB + dWidthUp2)/2.0*dDeep2;
double dV(0);
dV = (sqrt(dS1*dS2)+dS1 + dS2)*dPipeLen/3.0;
dAllV+=dV;
csV.Format(_T("%.3f"), dV);
m_grid.GetCell(idx, 8).SetText(csV);
*/
idx++;
}
}
}
m_grid.Invalidate();
m_dRet = dAllV;
UpdateData(FALSE);
// UpdateGrid();
}
void CWellCalcEarthworkDlg::OnButtonHelp()
{
AfxMessageBox(_T("\n")
_T("《给水排水管道工程施工及验收规范》边坡坡度 (高:宽) \n\n")
_T("土的类别 坡顶无荷载 坡顶有静载 坡顶有动载 \n\n")
_T("中密的砂土 1:1 1:1.25 1:1.5 \n")
_T("硬塑的轻亚粘土 1:0.67 1:0.75 1:1\n")
_T("中密的碎石类土(充填物为砂土) 1:0.75 1:1 1:1.25\n")
_T("中密的碎石类土(充填物为粘性土) 1:0.5 1:0.67 1:0.75\n")
_T("硬塑的亚粘土、粘土 1:0.33 1:0.5 1:0.67\n")
_T("老黄土 1:0.1 1:0.25 1:0.33\n")
_T("软土 1:1 - -\n"));
}
void CWellCalcEarthworkDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CWnd *pImageBox1 = GetDlgItem(IDC_PREVIEW1);
GlobalFunc::DrawSlide(_T("TWT(EARTHWORK)"), pImageBox1);
}