Files
envi-code/SourceCode/Code2026/tg_shs/shs_TwtCalc/CalcFeedIndustryDlg.cpp
T
2026-09-28 15:28:50 +08:00

961 lines
28 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// CalcFeedIndustryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CalcFeedIndustryDlg.h"
#include "TWTDEF.h"
#include "TelDef.h"
#include <DbEquipment.h>
#include "TWordFormulasTemplet.h"
#include "TAPI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 工业建筑给水计算
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void IndustryFeedCalc()
{
Entity entMainPipe;
RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, _T("*"), NULL);
RBList rbMaskPipe = ads_buildlist( -4, _T("<or"),
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_PIPE_FEED, -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_VPIPE_FEED, -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_PIPE_FEED2, -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_VPIPE_FEED2, -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_PIPE_FEED3, -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_VPIPE_FEED3, -4, _T("and>"),
-4, _T("or>"), NULL);
if(SelectEntity(_T("\n请选择给水总干管<退出>"), entMainPipe, rbMaskPipe) != RTNORM)
return;
//第一步,选择总干管,并找到它之前的堵头
AcDbObjectId idMain = NULL;
OPENOBJ_BEGIN(entMainPipe, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe)
{
AcDbObjectId nodeId1(NULL), nodeId2(NULL);
nodeId1 = pPipe->GetNode(0);
nodeId2 = pPipe->GetNode(1);
OPENOBJ_BEGIN(nodeId1, AcDb::kForRead, TDbPipeNode, pNode);
if(pNode)
{
int num = pNode->GetInterfaceNum();
if(num == 1)
idMain = nodeId1;
}
OPENOBJ_END();
OPENOBJ_BEGIN(nodeId2, AcDb::kForRead, TDbPipeNode, pNode);
if(pNode)
{
int num = pNode->GetInterfaceNum();
if(num == 1)
idMain = nodeId2;
}
OPENOBJ_END();
}
OPENOBJ_END();
if(!idMain)
{
AfxMessageBox(_T("没有正确选择起点干管!"));
return;
}
ads_name entMain;
acdbGetAdsName(entMain, idMain);
SSearchPipeList *pListAll = new SSearchPipeList();
PickSet ssAll(SS_FREE);
ssAll += idMain;
pListAll->m_iType = 1;
if(!SearchSprinkPipeSys(entMain, NULL, pListAll, ssAll))
{
AfxMessageBox(_T("系统有回路!"));
delete pListAll;
return;
}
//第二步,搜索整个系统,计算管长,建立双向链表
CalcPipeLength2(pListAll, NULL);
//第三步,标注节点
int idx = 1;
SSearchPipeList *pNode = GetNextDimNode2(pListAll, NULL);
while(pNode)
{
idx = DoSerialNumber2(pNode, idx); //标注节点编号
pNode = GetNextDimNode2(pListAll, NULL); //得到下一支路起点节点
}
DoDimPipeSerialNumber(pListAll); //标注管段编号
CTemporaryResourceOverride over;
CCalcFeedIndustryDlg dlg;
dlg.SetListAll(pListAll);
if(dlg.DoModal() != IDOK)
{
delete pListAll;
return;
}
delete pListAll;
return;
}
/////////////////////////////////////////////////////////////////////////////
// CCalcFeedIndustryDlg dialog
CCalcFeedIndustryDlg::CCalcFeedIndustryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCalcFeedIndustryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCalcFeedIndustryDlg)
m_csLost = _T("");
m_bIsCalc = FALSE;
//}}AFX_DATA_INIT
}
void CCalcFeedIndustryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalcFeedIndustryDlg)
DDX_Text(pDX, IDC_EDIT_LOST, m_csLost);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCalcFeedIndustryDlg, CDialog)
//{{AFX_MSG_MAP(CCalcFeedIndustryDlg)
ON_BN_CLICKED(IDC_RECACULATE, OnRecaculate)
ON_BN_CLICKED(IDC_BOOKBTN, OnBookbtn)
ON_BN_CLICKED(IDC_SHEETBTN, OnSheetbtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalcFeedIndustryDlg message handlers
BOOL CCalcFeedIndustryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_publicGrid.Create(this,IDC_LIST_CACLARCH);
m_publicGrid.Refresh();
m_publicGrid.AppendCol(_T("管段名称"),60);
m_publicGrid.AppendCol(_T("管道流量L/s"),80);
m_publicGrid.AppendCol(_T("管长m"),45);
// m_publicGrid.AppendCol(_T("百分数"),50);
m_publicGrid.AppendCol(_T("标注管径"),60);
// m_publicGrid.AppendCol(_T("额定流量"),60);
m_publicGrid.AppendCol(_T("水力坡降mH2O/m"),88);
m_publicGrid.AppendCol(_T("流速m/s"),60);
m_publicGrid.AppendCol(_T("沿程损失mH2O"),80);
m_publicGrid.GetCol(0).SetReadOnly();
m_publicGrid.GetCol(1).SetReadOnly();
m_publicGrid.GetCol(2).SetReadOnly();
// m_publicGrid.GetCol(3).SetReadOnly();
// m_publicGrid.GetCol(5).SetReadOnly();
m_publicGrid.GetCol(3).SetComboSel();
m_publicGrid.GetCol(4).SetReadOnly();
m_publicGrid.GetCol(5).SetReadOnly();
m_publicGrid.GetCol(6).SetReadOnly();
m_publicGrid.GetCol(3).SetTextColor(RGB(255,0,0));
m_publicGrid.GetCol(4).SetTextColor(RGB(0,0,255));
m_publicGrid.GetCol(5).SetTextColor(RGB(0,0,255));
m_publicGrid.GetCol(6).SetTextColor(RGB(0,0,255));
CacluatePipe(1);
UpdatePublicGrid(m_listNode,FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCalcFeedIndustryDlg::SetListAll(SSearchPipeList *pListAll)
{
m_pListAll = pListAll;
}
void CCalcFeedIndustryDlg::ResetList(SSearchPipeList *pListAll)
{
pListAll->m_nDang = 0;
pListAll->m_nLost = 0;
pListAll->m_nLength = 0;
pListAll->m_nI = 0;
pListAll->m_nPipeQ = 0;
pListAll->m_nStartPress = 0;
pListAll->m_nV = 0;
pListAll->m_nSpare = 0;
pListAll->m_bNeedCale = FALSE;
long len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++)
{
SSearchPipeList *pList = pListAll->m_lstNode[i];
ResetList(pList);
}
}
//更新管径
void CCalcFeedIndustryDlg::UpdatePipeRadius()
{
CString sText;
int nLen = m_arId.length();
for (int i = 0; i < nLen; ++i)
{
OPENOBJ_BEGIN(m_arId.at(i), AcDb::kForWrite, TDbPipe, pPipe);
if(pPipe)
{
sText = m_publicGrid.GetCell(i,3).GetText();
pPipe->SetDnDiameter(_ttoi(sText));
}
OPENOBJ_END();
}
}
//得到最不利节点
SSearchPipeList* CCalcFeedIndustryDlg::GetFeedDisadvantageNode(SSearchPipeList *pListAll, SSearchPipeList *pDisadvantage)
{
AcDbObjectId id = NULL;
id = pListAll->m_ID;
double nCurPipeLength(0);
nCurPipeLength = pListAll->m_nLength;
if(IsEquipment(id)){
if(!pDisadvantage || (pDisadvantage && nCurPipeLength > pDisadvantage->m_nLength))
pDisadvantage = pListAll;
}
int len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++){
SSearchPipeList *pList = pListAll->m_lstNode[i];
pDisadvantage = GetFeedDisadvantageNode(pList, pDisadvantage);
}
return pDisadvantage;
}
//计算总的沿程水头损失
void CCalcFeedIndustryDlg::DoCalcFeedWaterLost(SSearchPipeList *pDisadvantage, double &dAllLostRet)
{
double nAllLost(-1);
nAllLost = pDisadvantage->m_nLost;
if(pDisadvantage->m_pPrevious)
{
// pDisadvantage->m_pPrevious->m_nLost += nAllLost;
if(pDisadvantage->m_iType == 0)
dAllLostRet += nAllLost;
DoCalcFeedWaterLost(pDisadvantage->m_pPrevious, dAllLostRet);
}
}
//计算 nMode = 0 初算 1 复算
void CCalcFeedIndustryDlg::CacluatePipe(int nMode)
{
UpdateData();
//更新管径
UpdatePipeRadius();
//计算
ResetList(m_pListAll);
m_listNode.Reset();
DoCalcPipeQ(m_pListAll, nMode);
DoDimFeedPipeDn(m_pListAll, nMode);
UpdateMultDim();
double dAllLost(0);
CalcPipeLength2(m_pListAll, NULL);
SSearchPipeList *pDisadvantage = NULL;
pDisadvantage = GetFeedDisadvantageNode(m_pListAll, NULL);
if(pDisadvantage != NULL)
DoCalcFeedWaterLost(pDisadvantage, dAllLost);
CalcPipeLength(m_pListAll);
m_csLost.Format(_T("%.2f"), dAllLost);
UpdateData(FALSE);
std::map<CString,int> mapLable;
SSearchPipeList *pNode = GetNextExportNode2(m_pListAll, NULL,mapLable);
int i = 0;
CString sText;
while(pNode)
{
SSearchPipeList *pNodeNew = new SSearchPipeList();
pNodeNew->m_ID = pNode->m_ID;
pNodeNew->m_iDn = pNode->m_iDn;
pNodeNew->m_csName = pNode->m_csName;
pNodeNew->m_nLength = pNode->m_nLength;
pNodeNew->m_nPipeQ = pNode->m_nPipeQ;
pNodeNew->m_nSpare = pNode->m_nSpare;
pNodeNew->m_nDang = pNode->m_nDang;
pNodeNew->m_nStartPress = pNode->m_nStartPress;
pNodeNew->m_nI = pNode->m_nI;
pNodeNew->m_nV = pNode->m_nV;
pNodeNew->m_nLost = pNode->m_nLost;
//更新数据结构管径的值
if (m_publicGrid.GetRowNum() > 0)
{
OPENOBJ_BEGIN(pNodeNew->m_ID, AcDb::kForWrite, TDbPipe, pPipe);
if(pPipe)
{
sText = m_publicGrid.GetCell(i,3).GetText();
if (nMode == 1)
pNodeNew->m_iDn = _ttoi(sText);
}
OPENOBJ_END();
i++;
}
m_listNode.Append(pNodeNew);
mapLable[pNode->m_csName] = 0;
pNode = GetNextExportNode2(m_pListAll, NULL,mapLable);
}
}
//得到下一个导出WORD节点 根据节点计算顺序排序
SSearchPipeList *CCalcFeedIndustryDlg::GetNextExportNode2(SSearchPipeList *pListAll, SSearchPipeList *pDisadvantage,std::map<CString,int> mapLable)
{
if (mapLable.find(pListAll->m_csName) == mapLable.end())
{
CString csName = pListAll->m_csName;
int idx = csName.Find(_T("-"));
CString csFront;
if(idx > -1)
{
csFront = csName.Left(idx);
int iFront = _ttoi(csFront);
if(!pDisadvantage)
pDisadvantage = pListAll;
else
{
csName = pDisadvantage->m_csName;
idx = csName.Find(_T("-"));
csFront = csName.Left(idx);
if(iFront < _ttoi(csFront))
pDisadvantage = pListAll;
}
}
}
int len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++)
{
SSearchPipeList *pList = pListAll->m_lstNode[i];
pDisadvantage = GetNextExportNode2(pList, pDisadvantage,mapLable);
}
return pDisadvantage;
}
void CCalcFeedIndustryDlg::DoCalcPipeQ(SSearchPipeList *pListAll, int iMode)
{
AcDbObjectId id = NULL;
id = pListAll->m_ID;
pListAll->m_iNum = 0;
double nDang(0), dRateQ(0), nQ(0);
if(pListAll->m_iType == -1)
{
AcDbObjectId id = pListAll->m_ID;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
if(pEquip){
nDang = pEquip->GetDang();
dRateQ = pEquip->GetSpare();
AcDbObjectId idBlk = pEquip->GetBlock2d();
CString csBlkName = GetBlkNameById(idBlk);
CString csSysName = pEquip->GetSysBlock();
if(_tcsicmp(_T("$TWTSYS$00000290"), csBlkName) == 0 || //大便器自闭式冲洗阀
_tcsicmp(_T("$TWTSYS$00000291"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000292"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000293"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000502"), csBlkName) == 0 || //大便器感应式冲洗阀
_tcsicmp(_T("$TWTSYS$00000503"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000504"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000505"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000430"), csBlkName) == 0 || //脚踏式大便器 sr 2009-8-22 add
_tcsicmp(_T("$TWTSYS$00000431"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000432"), csBlkName) == 0 ||
_tcsicmp(_T("$TWTSYS$00000433"), csBlkName) == 0 ||
_tcsicmp(_T("TWTSYS(00000502)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000503)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000504)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000505)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000430)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000431)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000432)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000433)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000290)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000291)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000292)"), csSysName) == 0 ||
_tcsicmp(_T("TWTSYS(00000293)"), csSysName) == 0 )
{ //大便器自闭式冲洗阀
pListAll->m_bNeedCale = TRUE; //临时存一下
}
}
OPENOBJ_END();
pListAll->m_nDang = nDang;
pListAll->m_nSpare = dRateQ;
if(pListAll->m_bNeedCale)
{
pListAll->m_nLost = 0;
pListAll->m_nV = nDang*dRateQ/100;
}
else
{
pListAll->m_nLost = nDang*dRateQ/100;
pListAll->m_nV = 0;
}
pListAll->m_nStartPress = dRateQ;
}
ads_name ent;
acdbGetAdsName(ent, id);
long len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++)
{
SSearchPipeList *pList = pListAll->m_lstNode[i];
pList->m_pPrevious = pListAll;
DoCalcPipeQ(pList, iMode);
if(pList->m_nStartPress > pListAll->m_nStartPress) //记录本管段最大额定流量
pListAll->m_nStartPress = pList->m_nStartPress;
if(pListAll->m_iType == 0 )
{
pListAll->m_nDang = pList->m_nDang;
pListAll->m_nSpare = pList->m_nSpare;
}
if(pList->m_bNeedCale)//如果下面节点有大便器自闭式冲洗阀
{
pListAll->m_bNeedCale = TRUE;
pListAll->m_nV += pList->m_nV; //记录本管道总计算流量(大便器)
}
// else
pListAll->m_nLost += pList->m_nLost; //记录本管道总计算流量(非大便器)
}
if(pListAll->m_bNeedCale)//如果是大便器自闭式冲洗阀
{
nQ = pListAll->m_nV;
if(pListAll->m_nV < 1.2)
nQ = 1.2;
nQ += pListAll->m_nLost;
if(nQ < pListAll->m_nStartPress)
nQ = pListAll->m_nStartPress;
}
else
{
nQ = pListAll->m_nLost;
if(nQ < pListAll->m_nStartPress)
nQ = pListAll->m_nStartPress;
}
pListAll->m_nPipeQ = nQ;
if(pListAll->m_iType != 0 || pListAll->m_nPipeQ < 0.001)
return;
/*
double nLost(-1), nI(-1), nSpeed(0);
int iDn(0);
if(iMode == 0){
iDn = GetPipeDnByQ(nQ, pListAll->m_ID, nLost, nI, nSpeed);
}
else{
CString csMat;
double nLength(1);
OPENOBJ_BEGIN(pListAll->m_ID, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe)
{
iDn = (int)pPipe->GetDnDiameter();
csMat = GetPipeMaterialByIdx(pPipe->GetMaterial());
nLength = pPipe->Length();
}
OPENOBJ_END();
double nCh(140); // 海澄-威廉系数
if(csMat == _T("镀锌钢管") || csMat == _T("给水铸铁管") || csMat == _T("排水铸铁管") || csMat == _T("焊接钢管") || csMat == _T("无缝钢管"))
nCh = 100;
else
nCh = 140;
double nRetDj = GetPipeDjByDn(csMat, iDn);
nQ = nQ /1000;
nSpeed = nQ / (0.25*PI*nRetDj*nRetDj);
nI = 105 * (pow(nRetDj, -4.87)) * (pow(nQ, 1.85)) * (pow(nCh, -1.85)) / 10;
nLost = nI * nLength;
}
pListAll->m_nLost = nLost;
pListAll->m_nI = nI;
pListAll->m_iDn = iDn;
pListAll->m_nV = nSpeed;
DoDimPipeDn(ent, iDn, _T("自动"), g_nPipeDnHeight, FALSE, FALSE);
*/
}
void CCalcFeedIndustryDlg::DoDimFeedPipeDn(SSearchPipeList *pListAll, int iMode)
{
AcDbObjectId id = NULL;
id = pListAll->m_ID;
ads_name ent;
acdbGetAdsName(ent, id);
long len = pListAll->m_lstNode.Length();
for(long i=0;i<len;i++)
{
SSearchPipeList *pList = pListAll->m_lstNode[i];
DoDimFeedPipeDn(pList, iMode);
}
if(pListAll->m_iType != 0 || pListAll->m_nPipeQ < 0.001)
return;
double nQ = pListAll->m_nPipeQ;
double nLost(-1), nI(-1), nSpeed(0);
int iDn(0);
if(iMode == 0){
iDn = GetPipeDnByQ(nQ, pListAll->m_ID, nLost, nI, nSpeed);
}
else{
CString csMat;
double nLength(1);
OPENOBJ_BEGIN(pListAll->m_ID, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe)
{
iDn = (int)pPipe->GetDnDiameter();
csMat = GetPipeMaterialByIdx(pPipe->GetMaterial());
nLength = pPipe->Length();
}
OPENOBJ_END();
double nCh(140); // 海澄-威廉系数
if(csMat == _T("镀锌钢管") || csMat == _T("给水铸铁管") || csMat == _T("排水铸铁管") || csMat == _T("焊接钢管") || csMat == _T("无缝钢管"))
nCh = 100;
else
nCh = 140;
double nRetDj = GetPipeDjByDn(csMat, iDn);
nQ = nQ /1000;
nSpeed = nQ / (0.25*PI*nRetDj*nRetDj);
nI = 105 * (pow(nRetDj, -4.87)) * (pow(nQ, 1.85)) * (pow(nCh, -1.85)) / 10;
nLost = nI * nLength;
}
pListAll->m_nLost = nLost;
pListAll->m_nI = nI;
pListAll->m_iDn = iDn;
pListAll->m_nV = nSpeed;
DoDimPipeDn(ent, iDn, _T("自动"), g_nPipeDnHeight, FALSE, FALSE);
}
//显示表中的类容 bshowre = TRUE 显示计算结果 否则不显示计算结果
void CCalcFeedIndustryDlg::UpdatePublicGrid(DList<SSearchPipeList> &lstNode,BOOL bShowRe)
{
m_publicGrid.Clear();
CString csTmp;
int nLen = lstNode.Length();
while (m_arId.length() > 0)
{
m_arId.removeAt(0);
}
for (int i = 0; i < nLen; ++i)
{
m_publicGrid.AppendRow();
m_publicGrid.GetCell(i,0).SetText(lstNode[i]->m_csName);
csTmp.Format(_T("%.3f"), lstNode[i]->m_nPipeQ);
m_publicGrid.GetCell(i,1).SetText(csTmp);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nLength);
m_publicGrid.GetCell(i,2).SetText(csTmp);
// csTmp.Format(_T("%.2f"), lstNode[i]->m_nDang);
// m_publicGrid.GetCell(i,3).SetText(csTmp);
csTmp.Format(_T("%d"), lstNode[i]->m_iDn);
m_publicGrid.GetCell(i,3).SetText(csTmp);
// csTmp.Format(_T("%.2f"), lstNode[i]->m_nSpare);
// m_publicGrid.GetCell(i, 5).SetText(csTmp);
if (bShowRe)
{
csTmp.Format(_T("%.3f"), lstNode[i]->m_nI);
m_publicGrid.GetCell(i,4).SetText(csTmp);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nV);
m_publicGrid.GetCell(i,5).SetText(csTmp);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nLost);
m_publicGrid.GetCell(i,6).SetText(csTmp);
}
m_arId.append(lstNode[i]->m_ID);
}
}
void CCalcFeedIndustryDlg::OnOK()
{
m_bIsCalc = TRUE;
UpdateData(TRUE);
//第三步,计算管径
CacluatePipe(0);
UpdatePublicGrid(m_listNode);
}
void CCalcFeedIndustryDlg::OnRecaculate()
{
m_bIsCalc = TRUE;
CacluatePipe(1);
UpdatePublicGrid(m_listNode);
}
void CCalcFeedIndustryDlg::OnBookbtn()
{
ImportFeedCalcWord(m_listNode);
}
//输出计算书函数
void CCalcFeedIndustryDlg::ImportFeedCalcWord(DList<SSearchPipeList> &lstNode)
{
if (m_pListAll == NULL)
return;
int len = lstNode.Length();
if(!m_bIsCalc)
{
MessageBox(_T("请先计算!"));
return;
}
//初始化
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR), vtTrue((short)TRUE), vtFalse((short)FALSE);
_Application wordApplication;
Documents wordDocuments;
_Document activeDocument;
Paragraphs wordParagraphs;
Selection wordSelection;
if (!wordApplication.CreateDispatch(_T("Word.Application")))
{
AfxMessageBox(_T("不能执行Microsoft Word 8.0!"));
return;
}
// cet 2010.6.28 add 打开公式模板
TWordFormulasTemplet wdFormula;
CString sPathName = g_csSysPath;
sPathName += _T("formula.doc");
if (!wdFormula.OpenWordFormulasTempletFile(sPathName))
{
return;
}
wordApplication.SetVisible(TRUE);
wordDocuments = wordApplication.GetDocuments();
activeDocument = wordDocuments.Add(vtOptional,vtOptional);
//写一行字
wordSelection = wordApplication.GetSelection();
wordParagraphs = wordSelection.GetParagraphs();
wordParagraphs.SetAlignment(0); // 0: 居左 1:居中 2:居右
// cet 2010.6.28 del
// wordSelection.TypeText(_T("按照建筑给水排水设计规范 (GB 50015-2003)进行计算:\n"));
// wordSelection.TypeText(_T("计算公式 \n"));
// wordSelection.TypeText(_T("工业企业的生活间、公共浴室、职工食堂或营业餐馆的厨房、体育场馆运动员休息室、剧院"));
// wordSelection.TypeText(_T("的化妆间、普通理化实验室等建筑的生活给水管道的设计秒流量,应按下式计算\n"));
// wordSelection.TypeText(_T("\n Qg=∑q0×N0×b\n"));
// wordSelection.TypeText(_T("\n式中 Qg--计算管段的给水设计秒流量(L/S)\n"));
// wordSelection.TypeText((_T("\n q0--同类型的一个卫生器具给水额定流量(L/S)\n")));
// wordSelection.TypeText((_T("\n N0--同类型卫生器具数\n")));
// wordSelection.TypeText((_T("\n b--卫生器具同时给水百分数\n")));
// cet 2010.6.28 add
_Font font;
font = wordSelection.GetFont();
wordSelection.TypeText(_T("按照建筑给水排水设计规范 (GB 50015-2003)(2009年版)进行计算:\n"));
wordSelection.TypeText(_T("宿舍(Ⅲ、Ⅳ类)、工业企业的生活间、公共浴室、职工食堂或营业餐馆的厨房、体育场馆、剧院"));
wordSelection.TypeText(_T("普通理化实验室等建筑的生活给水管道的设计秒流量,应按下式计算:\n"));
wordSelection.TypeText(_T(" "));
wdFormula.InsertFormula(5, wordSelection);
wordSelection.TypeText(_T("\n 式中"));
wordSelection.TypeText(_T(" q"));
font.SetSubscript(2); //处理下标
wordSelection.TypeText(_T("g"));
font.SetSubscript(0);
wordSelection.TypeText(_T("--计算管段的给水设计秒流量(L/S)\n"));
wordSelection.TypeText(_T(" q"));
font.SetSubscript(2); //处理下标
wordSelection.TypeText(_T("0"));
font.SetSubscript(0);
wordSelection.TypeText((_T("--同类型的一个卫生器具给水额定流量(L/S)\n")));
wordSelection.TypeText(_T(" n"));
font.SetSubscript(2); //处理下标
wordSelection.TypeText(_T("0"));
font.SetSubscript(0);
wordSelection.TypeText((_T("--同类型卫生器具数\n")));
wordSelection.TypeText((_T(" b--同类型卫生器具的同时给水百分数\n")));
wordSelection.TypeText(_T("\n注:1如果计算值小于该管段上一个最大卫生器具的给水额定流量时,应采用一个最大的卫"));
wordSelection.TypeText(_T("生器具给水额定流量作为设计秒流量\n"));
wordSelection.TypeText(_T("\t2大便器自闭式冲洗阀应单列计算,当单列计算值小于1.2L/S时,以1.2L/S计;"));
wordSelection.TypeText(_T("大于1.2L/S时,以计算计\n"));
wordSelection.TypeText(_T("\n计算结果:\n"));
Selection wSelection2 = wordApplication.GetSelection();
wSelection2.TypeParagraph();
//画表格
int rows(len+1), columns(8);
Selection wSelection = wordApplication.GetSelection();
Range oRange = wSelection.GetRange();
Tables oTables = activeDocument.GetTables();
_Table oTable = oTables.Add(oRange, rows, columns);
// cet 2010.3.25 add
Borders oBorders = oTable.GetBorders();
oBorders.SetInsideLineStyle(1); // 设置表格线型
oBorders.SetOutsideLineStyle(1);
Columns oColumns;
Column oColumn;
oColumns = oTable.GetColumns();
oColumn = oColumns.Item(1);
oColumn.SetWidth(40, 0); // 0 = wdAdjustNone
oColumn = oColumns.Item(2);
oColumn.SetWidth(50, 0);
oColumn = oColumns.Item(3);
oColumn.SetWidth(40, 0);
oColumn = oColumns.Item(4);
oColumn.SetWidth(55, 0);
oColumn = oColumns.Item(5);
oColumn.SetWidth(60, 0);
oColumn = oColumns.Item(6);
oColumn.SetWidth(60, 0);
oColumn = oColumns.Item(7);
oColumn.SetWidth(70, 0);
oColumn = oColumns.Item(8);
oColumn.SetWidth(55, 0);
Cell oCell;
oCell = oTable.Cell(1, 1);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("管段名称"));
oCell = oTable.Cell(1, 2);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("管道流量L/s"));
oCell = oTable.Cell(1, 3);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("管长m"));
oCell = oTable.Cell(1, 4);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("标注管径"));
oCell = oTable.Cell(1, 5);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("水力坡降mH2O/m"));
oCell = oTable.Cell(1, 6);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("流速m/s"));
oCell = oTable.Cell(1, 7);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("沿程损失mH2O"));
oCell = oTable.Cell(1, 8);
oRange = oCell.GetRange();
oRange.InsertAfter(_T("管材"));
for(int i=0; i<len; i++){
CString csTmp;
oCell = oTable.Cell(i+2, 1); //管段名称
oRange = oCell.GetRange();
oRange.InsertAfter(lstNode[i]->m_csName);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nPipeQ);
oCell = oTable.Cell(i+2, 2); //管道流量L/s
oRange = oCell.GetRange();
oRange.InsertAfter(csTmp);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nLength);
oCell = oTable.Cell(i+2, 3); //管长m
oRange = oCell.GetRange();
oRange.InsertAfter(csTmp);
csTmp.Format(_T("%d"), lstNode[i]->m_iDn);
oCell = oTable.Cell(i+2, 4); //管径mm
oRange = oCell.GetRange();
oRange.InsertAfter(csTmp);
csTmp.Format(_T("%.3f"), lstNode[i]->m_nI);
oCell = oTable.Cell(i+2, 5); //水力坡降mH2O/m
oRange = oCell.GetRange();
oRange.InsertAfter(csTmp);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nV);
oCell = oTable.Cell(i+2, 6); //流速m/s
oRange = oCell.GetRange();
oRange.InsertAfter(csTmp);
csTmp.Format(_T("%.2f"), lstNode[i]->m_nLost);
oCell = oTable.Cell(i+2, 7); //损失mH2O
oRange = oCell.GetRange();
oRange.InsertAfter(csTmp);
int iMat(0);
OPENOBJ_BEGIN(lstNode[i]->m_ID, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
iMat = pPipe->GetMaterial();
}
OPENOBJ_END();
CString csMat = GetPipeMaterialByIdx(iMat);
oCell = oTable.Cell(i+2, 8); //管材
oRange = oCell.GetRange();
oRange.InsertAfter(csMat);
}
COleVariant vtOptional2((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
wordSelection = wordApplication.GetSelection();
wordSelection.GoTo(COleVariant((short)3),
COleVariant((short)-1),vtOptional2,vtOptional2);
wSelection = wordApplication.GetSelection();
wSelection.TypeParagraph();
UpdateData(TRUE);
wordSelection.TypeText(XString(_T("总沿程水头损失= %s mH2O\n"), m_csLost));
wdFormula.CloseFile(); // cet 2010.6.28 add
}
void CCalcFeedIndustryDlg::OnSheetbtn()
{
UpdateData(TRUE);
HideDialog(this, TRUE);
XPoint pt;
if(acedGetPoint(NULL, _T("\n点取表格左上角位置:<返回>"), pt) != RTNORM)
{
HideDialog(this, FALSE);
return;
}
double nTextSize = g_nSheetHeight; //字高
double nTableHeight = g_nSheetHeight+2;
AcDbObjectId idTextStyle=InitTwtTextStyle(g_csSheetStyle);
TDbSheet *pSheet = new TDbSheet;
TGridStyle gridStyle;
gridStyle.SetOverrideAll(TRUE);
gridStyle.SetTextHeight(nTextSize);
gridStyle.SetTextStyleId(idTextStyle);
TSheetTitle &title=pSheet->GetTitle();
title.SetHeight(nTextSize);
title.SetText(_T("工业建筑给水计算表"));
TGridStyle &gridStyle2=title.GetGridStyle();
gridStyle2.SetTextHeight(nTextSize);
gridStyle2.SetTextStyleId(idTextStyle);
TDividerStyle &style=title.GetDividerStyle();
style.SetDividerFlag(TDividerStyle::kNone);
gridStyle.SetHorMode(AcDb::kTextCenter);
gridStyle.SetVerMode(AcDb::kTextVertMid);
gridStyle.SetLineSpaceFactor(0.2);
gridStyle.SetTextWrap(FALSE);
pSheet->SetGridStyle(gridStyle);
pSheet->SetRowHeight(nTableHeight);
pSheet->SetLayoutRotation(Ucs2Wcs(0.0));
pSheet->SetLocation(Ucs2Wcs(pt));
int nAllRow = (int)m_publicGrid.GetRowNum();
pSheet->InitSheet(nAllRow + 1, 7, nTableHeight, 50);
TDividerStyle &styleBorder = pSheet->GetBorderStyle();
styleBorder.SetLineWidth(0.2);
TSheetRow *pRow = pSheet->GetRow(0);
if (pRow != NULL)
{
TDividerStyle &styleRow = pRow->GetDividerStyle();
styleRow.SetLineWidth(0.2);
styleRow.SetDividerFlag(TDividerStyle::kLocal);
}
pSheet->SetLocation(Ucs2Wcs(pt));
XPoint ptex = pSheet->GetExtents(FALSE);
TSheetColumn column;
column.SetWidth(15);
pSheet->SetColumnAt(0, column);
column.SetWidth(20);
pSheet->SetColumnAt(1, column);
column.SetWidth(15);
pSheet->SetColumnAt(2, column);
column.SetWidth(15);
pSheet->SetColumnAt(3, column);
column.SetWidth(30);
pSheet->SetColumnAt(4, column);
column.SetWidth(15);
pSheet->SetColumnAt(5, column);
column.SetWidth(25);
pSheet->SetColumnAt(6, column);
TGridCell &cell01=*(*pSheet)(0, 0);
cell01.SetText(_T("管段名称"));
TGridCell &cell02=*(*pSheet)(0, 1);
cell02.SetText(_T("管道流量L/s"));
TGridCell &cell03=*(*pSheet)(0, 2);
cell03.SetText(_T("管长m"));
TGridCell &cell04=*(*pSheet)(0, 3);
cell04.SetText(_T("标注管径"));
TGridCell &cell05=*(*pSheet)(0, 4);
cell05.SetText(_T("水力坡降mH2O/m"));
TGridCell &cell06=*(*pSheet)(0, 5);
cell06.SetText(_T("流速m/s"));
TGridCell &cell07=*(*pSheet)(0, 6);
cell07.SetText(_T("沿程损失mH2O"));
for(int j = 1; j < m_publicGrid.GetRowNum() + 1; j++)
{
for (int i = 0; i < m_publicGrid.GetColNum(); i++)
{
TGridCell &Cell=*(*pSheet)(j, i);
CString sText = m_publicGrid.GetCell(j-1,i).GetText();
Cell.SetText(sText);
}
}
pSheet->AddToCSpace(TRUE);
TCHAR szTmp[32];
ads_getstring(NULL, _T("\n按任意键返回对话框:<返回>"), szTmp);
HideDialog(this, FALSE);
}