// CalcFeedDlg.cpp : implementation file // #include "stdafx.h" #include #include #include "CalcFeedDlg.h" #include "CalcFeedPublickDlg.h" #include "TWTDEF.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //extern void GetPipeSpecList(DList &lstSpec, const TCHAR* szMat); ///////////////////////////////////////////////////////////////////////////// // CCalcFeedDlg dialog CCalcFeedDlg::CCalcFeedDlg(CWnd* pParent /*=NULL*/) : CDialog(CCalcFeedDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCalcFeedDlg) m_iArch = 2; m_nA = 1.5; m_bWord = TRUE; m_iMode = 0; //}}AFX_DATA_INIT } void CCalcFeedDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCalcFeedDlg) DDX_CBIndex(pDX, IDC_COMBO_ARCH, m_iArch); DDX_Text(pDX, IDC_EDIT_ALPHA, m_nA); DDX_Check(pDX, IDC_CHECK_WORD, m_bWord); DDX_Radio(pDX, IDC_RADIO_MODE1, m_iMode); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCalcFeedDlg, CDialog) //{{AFX_MSG_MAP(CCalcFeedDlg) ON_CBN_SELCHANGE(IDC_COMBO_ARCH, OnSelchangeComboArch) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCalcFeedDlg message handlers void CCalcFeedDlg::OnSelchangeComboArch() { UpdateData(TRUE); if(m_iArch == 0) m_nA = 1.2; else if(m_iArch == 1) m_nA = 1.4; else if(m_iArch == 2) m_nA = 1.5; else if(m_iArch == 3) m_nA = 1.8; else if(m_iArch == 4) m_nA = 2.0; else if(m_iArch == 5) m_nA = 2.5; else if(m_iArch == 6) m_nA = 3.0; UpdateData(FALSE); } void CCalcFeedDlg::OnOK() { UpdateData(TRUE); if(m_iArch == 0) m_csArch = _T("幼儿园、托儿所、养老院"); else if(m_iArch == 1) m_csArch = _T("门诊部、诊疗所"); else if(m_iArch == 2) m_csArch = _T("办公楼、商场"); else if(m_iArch == 3) m_csArch = _T("学校"); else if(m_iArch == 4) m_csArch = _T("医院、疗养院、休养所"); else if(m_iArch == 5) m_csArch = _T("集体宿舍、旅馆、招待所、宾馆"); else if(m_iArch == 6) m_csArch = _T("客运站、会展中心、公共厕所"); CDialog::OnOK(); } //////////////////////////////////////////////////////////////////////////////////////////////////////// void GetPipeVIByDn(double nQ, AcDbObjectId id, int iDn, double &nLost, double &nI, double &nSpeed) { double nLength(-1); int nRet(-1); int iMat(-1); OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ iMat = pPipe->GetMaterial(); nLength = pPipe->Length() / 1000; } OPENOBJ_END(); CString csMat = GetPipeMaterialByIdx(iMat); double nCh(0); // 海澄-威廉系数 if(csMat == _T("镀锌钢管") || csMat == _T("给水铸铁管") || csMat == _T("排水铸铁管") || csMat == _T("焊接钢管") || csMat == _T("无缝钢管")) nCh = 100; else nCh = 140; // Q = 1/4 * PI * Dj * Dj * V nQ = nQ / 1000; double nRetDj = GetPipeDjByDn(csMat, iDn); 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; } void DoDimFeedPipeDn(SSearchPipeList *pListAll, double nA, int iMode) { AcDbObjectId id = NULL; id = pListAll->m_ID; pListAll->m_iNum = 0; double nDang(0), dRateQ(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(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; //临时存一下 nDang = 0.5; //大便器自闭式冲洗阀,当量按0.5 } else if(_tcsicmp(_T("$TWTSYS$00000132"), csBlkName) == 0 && pEquip->GetPipeLength() < 0) pListAll->m_bNeedCale = TRUE; //给水原理图,【修改当量】设置有自闭式冲洗阀 } OPENOBJ_END(); pListAll->m_nDang = nDang; pListAll->m_nSpare = dRateQ; pListAll->m_nStartPress = dRateQ; } ads_name ent; acdbGetAdsName(ent, id); long len = pListAll->m_lstNode.Length(); for(long i=0;im_lstNode[i]; pList->m_pPrevious = pListAll; DoDimFeedPipeDn(pList, nA, iMode); pListAll->m_nDang += pList->m_nDang; if(pList->m_nStartPress > pListAll->m_nStartPress) //记录本管段最大额定流量 pListAll->m_nStartPress = pList->m_nStartPress; pListAll->m_nSpare += pList->m_nSpare; //记录本管道总额定流量 if(pList->m_bNeedCale)//如果下面节点有大便器自闭式冲洗阀,则本节点流量也加1.1 pListAll->m_bNeedCale = TRUE; } double nQ = 0.2 * nA * sqrt(pListAll->m_nDang); //《建筑给水排水设计规范》2003 3.6.5 2006,10,30 sr 改为规范计算 if(pListAll->m_bNeedCale) nQ += 1.1; // 大便器延时自闭冲洗阀的给水管段,大便器延时自闭冲洗阀的给水当量均以0.5计,计算得到的 附加1.10L/s的流量后,为该管段的给水设计秒流量。 if(nQ > pListAll->m_nSpare) nQ = pListAll->m_nSpare; //如计算值大于该管段上按卫生器具给水额定流量累加所得流量值时,应按卫生器具给水额定流量累加所得流量值采用。 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); //大便器延时自闭冲洗阀 末端尽管流量很大,也不能用50的管径,一般末端用25, 倒数第二段用32 sr modify 2006-5-16 出自天津院 if(len == 1 && iDn == 50 && pListAll->m_bNeedCale){ SSearchPipeList *pList = pListAll->m_lstNode[0]; if(pList->m_lstNode.Length() == 0) iDn = 25; else if(pList->m_lstNode.Length() == 1){ SSearchPipeList *pList2 = pList->m_lstNode[0]; if(pList2->m_lstNode.Length() == 1){ SSearchPipeList *pList3 = pList2->m_lstNode[0]; if(pList3->m_lstNode.Length() == 0) iDn = 32; } } if(iDn != 50) GetPipeVIByDn(nQ, pListAll->m_ID, iDn, 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() / 1000; } 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); } //得到最不利节点 SSearchPipeList* 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;im_lstNode[i]; pDisadvantage = GetFeedDisadvantageNode(pList, pDisadvantage); } return pDisadvantage; } //得到下一个导出WORD节点 根据节点计算顺序排序 SSearchPipeList *GetNextExportNode2(SSearchPipeList *pListAll, SSearchPipeList *pDisadvantage) { 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;im_lstNode[i]; pDisadvantage = GetNextExportNode2(pList, pDisadvantage); } return pDisadvantage; } //输出计算书函数 void ImportFeedCalcWord(DList &lstNode, const TCHAR* szArch, double nA) { int len = lstNode.Length(); if(len < 1) 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; } wordApplication.SetVisible(TRUE); wordDocuments = wordApplication.GetDocuments(); activeDocument = wordDocuments.Add(vtOptional,vtOptional); //写一行字 wordSelection = wordApplication.GetSelection(); wordParagraphs = wordSelection.GetParagraphs(); wordParagraphs.SetAlignment(0); // 0: 居左 1:居中 2:居右 wordSelection.TypeText(_T("采用当量法计算\n")); wordSelection.TypeText(_T("计算原理参照《建筑给水排水设计规范GB50015-2003》,采用公共建筑采用当量法 \n")); wordSelection.TypeText(_T("基本计算公式 \n")); wordSelection.TypeText(_T("Q = 0.2 × SQRT(Ng) × α\n")); wordSelection.TypeText(_T("式中:\n")); wordSelection.TypeText(_T("Q-计算管段的给水设计秒流量(L/s) \n")); wordSelection.TypeText(_T("Ng-计算管段的卫生器具给水当量总数 \n")); wordSelection.TypeText(XString(_T("α-根据建筑物用途而定的系数:%.1f \n"), nA)); wordSelection.TypeText(XString(_T("建筑类型:%s\n"), szArch)); // wordSelection.TypeText(XString(_T("末端压力:%.3f MPa\n"), nPress)); // wordSelection.TypeText(XString(_T("局部损失系数:%.0f %\n"), nFactor)); wordSelection.TypeText(_T("计算结果:\n")); // wordSelection.TypeText(XString(_T("沿程损失:%.3f MPa\n"), nLost)); // wordSelection.TypeText(XString(_T("起点压力:%.3f MPa\n"), nStartPress)); Selection wSelection2 = wordApplication.GetSelection(); wSelection2.TypeParagraph(); //画表格 int rows(len+1), columns(9); 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(40, 0); oColumn = oColumns.Item(6); oColumn.SetWidth(60, 0); oColumn = oColumns.Item(7); oColumn.SetWidth(50, 0); oColumn = oColumns.Item(8); oColumn.SetWidth(55, 0); oColumn = oColumns.Item(9); oColumn.SetWidth(60, 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("标注管径")); oCell = oTable.Cell(1, 6); oRange = oCell.GetRange(); oRange.InsertAfter(_T("水力坡降mH2O/m")); oCell = oTable.Cell(1, 7); oRange = oCell.GetRange(); oRange.InsertAfter(_T("流速m/s")); oCell = oTable.Cell(1, 8); oRange = oCell.GetRange(); oRange.InsertAfter(_T("沿程损失mH2O")); oCell = oTable.Cell(1, 9); oRange = oCell.GetRange(); oRange.InsertAfter(_T("管材")); for(int i=0; im_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("%.2f"), lstNode[i]->m_nDang); oCell = oTable.Cell(i+2, 4); //当量长度m oRange = oCell.GetRange(); oRange.InsertAfter(csTmp); csTmp.Format(_T("%d"), lstNode[i]->m_iDn); oCell = oTable.Cell(i+2, 5); //管径mm oRange = oCell.GetRange(); oRange.InsertAfter(csTmp); csTmp.Format(_T("%.3f"), lstNode[i]->m_nI); oCell = oTable.Cell(i+2, 6); //水力坡降mH2O/m oRange = oCell.GetRange(); oRange.InsertAfter(csTmp); csTmp.Format(_T("%.2f"), lstNode[i]->m_nV); oCell = oTable.Cell(i+2, 7); //流速m/s oRange = oCell.GetRange(); oRange.InsertAfter(csTmp); csTmp.Format(_T("%.2f"), lstNode[i]->m_nLost); oCell = oTable.Cell(i+2, 8); //损失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, 9); //管材 oRange = oCell.GetRange(); oRange.InsertAfter(csMat); } COleVariant vtOptional2((long)DISP_E_PARAMNOTFOUND,VT_ERROR); wordSelection = wordApplication.GetSelection(); wordSelection.GoTo(COleVariant((short)3), // 3 = wdGoToLine COleVariant((short)-1),vtOptional2,vtOptional2); // -1 = wdGoToLast wSelection = wordApplication.GetSelection(); wSelection.TypeParagraph(); } void DoCalcFeedWater(SSearchPipeList *pDisadvantage) { double nAllLost(-1); nAllLost = pDisadvantage->m_nLost; if(pDisadvantage->m_pPrevious){ pDisadvantage->m_pPrevious->m_nLost += nAllLost; DoCalcFeedWater(pDisadvantage->m_pPrevious); } } //公共建筑给水计算 主函数 void CalcFeedPipeDn2() { Entity entMainPipe; ads_name entMain; RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, _T("*"), NULL); RBList rbMaskPipe = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -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; } 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); CTemporaryResourceOverride over; CCalcFeedDlg dlg; if(dlg.DoModal() != IDOK){ delete pListAll; return; } //第三步,计算管径 DoDimFeedPipeDn(pListAll, dlg.m_nA, dlg.m_iMode); UpdateMultDim(); //第三步,标注节点 if(dlg.m_bWord){ int idx = 1; SSearchPipeList *pNode = GetNextDimNode2(pListAll, NULL); while(pNode){ idx = DoSerialNumber2(pNode, idx); //标注节点编号 pNode = GetNextDimNode2(pListAll, NULL); //得到下一支路起点节点 } DoDimPipeSerialNumber(pListAll); //标注管段编号 } SSearchPipeList *pDisadvantage = NULL; pDisadvantage = GetFeedDisadvantageNode(pListAll, NULL); if(pDisadvantage != NULL) DoCalcFeedWater(pDisadvantage); CalcPipeLength(pListAll); if(dlg.m_bWord){ DList lstNode; SSearchPipeList *pNode = GetNextExportNode2(pListAll, NULL); 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_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; lstNode.Append(pNodeNew); pNode->m_csName = _T(""); pNode = GetNextExportNode2(pListAll, NULL); } ImportFeedCalcWord(lstNode, dlg.m_csArch, dlg.m_nA); } delete pListAll; return; }