#include "stdafx.h" #include "GeCurveInline.h" #include "AcDbObjectPtr.h" #include "ElevationCalc.h" #include "PickEntSet.h" #include "EdJigEx.h" #include "DbWell.h" #include "rxregsvc.h" #include "DbVerticalSection.h" #include "DbWellDim.h" #include "DbPool.h" #include "dbxutil.h" #include "xtext.h" #include "TBlockEdJig.h" #include "SelectBlkDlg.h" #include "TWellJig.h" #include "SetDataSourceDlg.h" #include "CollectElevation.h" #include "layerdef.h" extern CString GetLayerNames(const TCHAR * szTgSubName); extern AcDbObjectId InitLayer(const TCHAR *szLayer, BOOL bApplyChange = TRUE); extern AcDbObjectId InitTextStyle(TTextStyle ts, AcDbDatabase *pDb = NULL); extern AcDbObjectId InitTextStyle(const TCHAR *pszStyle, AcDbDatabase *pDb); extern AcDbObjectId InitBlock(const TCHAR *pszBlock, AcDbDatabase *pDb = NULL); // 双击汇流面积 zxl 2013.12.25 add int EditConflunceArea(AcDbObjectId id) { //TDbConfluenceArea *pArea = NULL; //acdbOpenObject(pArea, id, AcDb::kForRead); //if (pArea == NULL) //{ // return 0; //} //AecObjectEditMethod pMethod = NULL; //pMethod = pArea->GetEditMethodPoint(); //pArea->Close(); //if (pMethod != NULL) //{ // Acad::ErrorStatus es = acdbOpenObject(pArea, id, AcDb::kForWrite); // pArea->Close(); // pMethod(id); //} return 1; } extern void GrdrawRect(XRectAngle &rect); class TPolyEdJig2 : public TSymbEdJig { public: enum TPolyOper { kNone = 0, kLinePoint = 1, kArcPoint = 2, kArcMidPoint = 3, kArcRadius = 4 }; protected: TPolyOper m_nOperCode; // I/O AcDbPolyline *m_pDrawEnt; public: TPolyEdJig2(AcDbPolyline *); virtual int DoIt(int *pKeyIndex = NULL); DragStatus GetPoint(XPoint &pt); protected: virtual Adesk::Boolean update(); virtual AcDbEntity* entity() const; public: void SetOperCode(TPolyEdJig2::TPolyOper opCode) { m_nOperCode = opCode; } TPolyOper GetOperCode() { return m_nOperCode; } }; TPolyEdJig2::TPolyEdJig2(AcDbPolyline *pElev) { m_pDrawEnt = pElev; } AcEdJig::DragStatus TPolyEdJig2::GetPoint(XPoint &pt) { AcGePoint3d ptBase; m_pDrawEnt->getPointAt(m_pDrawEnt->numVerts() - 1, ptBase); //if(m_nOperCode!=kArcMidPoint m_nOperCode!=kArcRadius) // return acquirePoint(pt); return acquirePoint(pt, ptBase); } // 开始执行拖动 int TPolyEdJig2::DoIt(int *keyIndex) { XPoly2D poly2d; GlobalFunc::PolyConvert(*m_pDrawEnt, poly2d); if (m_nOperCode == kLinePoint || m_nOperCode == kArcPoint) { m_ptResult = *poly2d.Tail(); } else if (m_nOperCode == kArcMidPoint) { // MidPoint XCurveSegment cv; poly2d.Nth(poly2d.TotalSegments() - 1, cv); m_ptResult = cv.MidPoint(); } int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } // 更新实体数据 Adesk::Boolean TPolyEdJig2::update() { Adesk::Boolean bRet = Adesk::kTrue; XPoly2D poly2d; GlobalFunc::PolyConvert(*m_pDrawEnt, poly2d); if (m_nOperCode == kLinePoint || m_nOperCode == kArcPoint) { //*poly2d.Tail()=m_ptResult; } else if (m_nOperCode == kArcMidPoint) { XDirectionCurve cv; poly2d.Nth(poly2d.TotalSegments() - 1, cv); XCurveSegment seg; seg = XArc(cv.StartPoint(), m_ptResult, cv.EndPoint()); if (!!seg) { if (seg.StartPoint().Distance(cv.StartPoint()) > g_DimOption::instance()._distSnap) seg.SetBulge(-seg.GetBulge());// 2011-8-9 bsl TELEC8.2之后反向绘制弧线变成直线:seg.SetBulge(seg.GetBulge()-seg.GetBulge()); // *poly2d.bulges[poly2d.Length()-2]=seg.GetBulge(); poly2d.SetBulge(poly2d.Length() - 2, seg.GetBulge()); } } else if (m_nOperCode == kArcRadius) { XPoint ptBase, ptPrev; int numVert = m_pDrawEnt->numVerts(); m_pDrawEnt->getPointAt(numVert - 1, (AcGePoint3d &)ptBase); m_pDrawEnt->getPointAt(numVert - 2, (AcGePoint3d &)ptPrev); double nChordLen = ptBase.Distance2d(ptPrev); double nRadius = ptBase.Distance2d(m_ptResult); if (nChordLen < 2.0 * nRadius + 1.0E-6) { double bulge = 2.0 * asin(nChordLen / 2.0 / nRadius); if (XLine(ptPrev, ptBase).OnWhichSide(m_ptResult) == OFFSET_LEFT) bulge = -bulge; //*poly2d.bulges[poly2d.Length()-2]=bulge; poly2d.SetBulge(poly2d.Length() - 2, bulge); } } GlobalFunc::PolyConvert(poly2d, *m_pDrawEnt); return bRet; } AcDbEntity* TPolyEdJig2::entity() const { return (AcDbEntity *)m_pDrawEnt; } int DragInputPoly2d(XPoint ptStart, XPoly2D &poly2dRet) { AcDbPolyline pline; pline.addVertexAt(0, ptStart); TPolyEdJig2 jig(&pline); jig.SetPrompt(_T("\n直段下一点 [弧段(A)/回退(U)} <结束>: ")); jig.SetOperCode(TPolyEdJig2::kLinePoint); jig.SetKeyword(_T("A U")); while (1) { int nKeyIndex = 0; int nRetCode = jig.DoIt(&nKeyIndex); if (nRetCode == RTNORM) { pline.addVertexAt(pline.numVerts(), (AcGePoint2d &)jig.GetPickPoint()); if (jig.GetOperCode() == TPolyEdJig2::kArcPoint) { TPolyEdJig2 jig1(&pline); jig1.SetOperCode(TPolyEdJig2::kArcMidPoint); jig1.SetPrompt(_T("\n点取弧上一点 [输入半径(R)]:")); jig1.SetKeyword(_T("R")); int nKeyIdx; int nRetCode1 = jig1.DoIt(&nKeyIdx); if (nRetCode1 == RTKWORD) { TPolyEdJig2 jig2(&pline); jig2.SetOperCode(TPolyEdJig2::kArcRadius); jig2.SetPrompt(_T("\n输入半径(光标位置确定弧的方向):")); jig2.DoIt(); } } else { //直段 jig.SetPrompt(_T("\n直段下一点 [弧段(A)/回退(U)] <结束>: ")); jig.SetOperCode(TPolyEdJig2::kLinePoint); jig.SetKeyword(_T("A U")); } } else if (nRetCode == RTKWORD) { if (jig.GetOperCode() == TPolyEdJig2::kLinePoint) { if (nKeyIndex == 0) { jig.SetOperCode(TPolyEdJig2::kArcPoint); jig.SetPrompt(_T("\n弧段下一点 [直段(L)/回退(U)] <结束>: ")); jig.SetKeyword(_T("L U")); } else if (nKeyIndex == 1) { int numVert = pline.numVerts(); if (numVert > 1) { pline.removeVertexAt(numVert - 1); pline.setBulgeAt(numVert - 2, 0.0); } } } else if (jig.GetOperCode() == TPolyEdJig2::kArcPoint) { if (nKeyIndex == 0) { jig.SetOperCode(TPolyEdJig2::kLinePoint); jig.SetPrompt(_T("\n直段下一点 [弧段(A)/回退(U)] <结束>: ")); jig.SetKeyword(_T("A U")); } else if (nKeyIndex == 1) { int numVert = pline.numVerts(); if (numVert > 1) { pline.removeVertexAt(numVert - 1); pline.setBulgeAt(numVert - 2, 0.0); } } } } else if (nRetCode == RTNONE) { break; } else if (nRetCode == RTCAN) { return RTERROR; } } int numVert = pline.numVerts(); if (numVert < 2) return RTERROR; GlobalFunc::PolyConvert(pline, poly2dRet); return RTNORM; } int GetOpenPoly2D2(const TCHAR *pMsg, XPoly2D &poly2d) { XString szPrompt; if (pMsg) szPrompt << pMsg; else szPrompt << _T("\n曲线起点"); szPrompt << _T("或 [点取图中曲线(P)/点取参考点(R)/复制已有汇流面积(C)]<退出>:"); XPoint ptStart; int nCode; INITGET_BEG(0, _T("C P R")); nCode = ads_getpoint(NULL, szPrompt, ptStart); INITGET_END(); if (nCode == RTKWORD) { XString sKeyword; VERIFY(ads_getinput(sKeyword) == RTNORM); if (sKeyword[0] == _T('R')) { XPoint ptRef; if (ads_getpoint(NULL, _T("\n输入参考点<退出>:"), ptRef) != RTNORM) return RTERROR; if (ads_getpoint(ptRef, _T("\n曲线起点<退出>:"), ptStart) != RTNORM) return RTERROR; ptStart = GlobalFunc::Ucs2Wcs(ptStart); nCode = DragInputPoly2d(ptStart, poly2d); } else if (sKeyword[0] == _T('C') || sKeyword[0] == _T('c'))//复制汇流面积 { return RTPICKS; } else { RBList mask(RTDXF0, _T("POLYLINE,LWPOLYLINE,LINE,ARC"), NULL); Entity ent; LAB_RESELECT: if ((nCode = ent.FilterSelect(_T("\n选择一曲线(LINE/ARC/PLINE):"), mask)) != RTNORM) return RTERROR; if (ent.Is(_T("LINE")) || ent.Is(_T("ARC"))) { XCurveSegment cv(ent); poly2d.Reset(); cv.AsPoly2D(poly2d); } else { XPoly2D poly(ent); if (!!poly) { poly2d = poly; } else { g_Option::instance().adsout << _T("\n无效的选择!"); goto LAB_RESELECT; } } } } else if (nCode == RTNORM) { ptStart = GlobalFunc::Ucs2Wcs(ptStart); nCode = DragInputPoly2d(ptStart, poly2d); } else { // return nCode; } return nCode; } //*************************************************************************************************** // 世界坐标系 //*************************************************************************************************** void SetWcsCoord() { SHads_command(RTSTR, _T("UCS"), RTSTR, _T("W"), 0); } //*************************************************************************************************** // 测量坐标系 //*************************************************************************************************** void SetMeasureCoord() { Acad::ErrorStatus eStat; AcDbObjectId idRec; AcDbUCSTable* pTable = NULL; acdbCurDwg()->getUCSTable(pTable, AcDb::kForWrite); if (pTable != NULL) { struct resbuf rb1, rb2, rb3; acedGetVar(_T("UCSORG"), &rb1); acedGetVar(_T("UCSXDIR"), &rb2); acedGetVar(_T("UCSYDIR"), &rb3); ads_point ptOrg; ads_point vtX, vtY; (rb1.resval.rpoint, ptOrg, false); acdbUcs2Wcs(rb2.resval.rpoint, vtX, true); acdbUcs2Wcs(rb3.resval.rpoint, vtY, true); AcGePoint3d ptGeOrg = asPnt3d(ptOrg); AcGeVector3d vtX1 = asVec3d(rb2.resval.rpoint); AcGeVector3d vtY1 = asVec3d(rb3.resval.rpoint); AcDbUCSTableRecord* pRecord = NULL; if (Acad::eOk != pTable->getAt(_T("Tg_MeasureCoord"), pRecord, AcDb::kForWrite)) { pRecord = new AcDbUCSTableRecord; pRecord->setName(_T("Tg_MeasureCoord")); pRecord->setOrigin(ptGeOrg); pRecord->setXAxis(vtY1); pRecord->setYAxis(vtX1); eStat = pTable->add(idRec, pRecord); pRecord->close(); } else { if (pRecord != NULL) { idRec = pRecord->objectId(); pRecord->close(); } } pTable->close(); } SHads_command(RTSTR, _T("UCS"), RTSTR, _T("_R"), RTSTR, _T("Tg_MeasureCoord"), 0); } //*************************************************************************************************** // 搜索室外井系统 //*************************************************************************************************** // sr modify 2004/10/25 2005/5/24 // 搜索室外系统,可以定终止井,entEnd输入空,自动搜索最后一个井 // 搜索原则:顺着流向方向找,如果有分叉就结束,有汇集不关,继续向前 BOOL AutoSearchOutdoorWell(Entity ent, AcDbObjectId idFront, SSearchPipeList *pListAll, PickSet &ssAll) { AcDbObjectId id = NULL; acdbGetObjectId(id, ent); pListAll->m_ID = id; AcDbObjectIdArray idArray; int len(0); { PickSet ss(SS_FREE); if (ent.Is(_T("AEC_ZT_PIPE"))) { pListAll->m_iType = 0; OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { //2008.4.30 增加以下代码, 在室外中, 标注管长不需要标注真实管长, 只需要标注平面管长 double dLen = pPipe->GetPlanLength(); pListAll->m_nLength = dLen; pListAll->m_iDn = (int)pPipe->GetDnDiameter(); } OPENOBJ_END(); pListAll->m_nI = GlobalFunc::GetPipeGradient(ent); GlobalFunc::GetAllPipeAndNodeByPipe(id, idFront, ss); } else if (ent.Is(_T("AEC_ZT_POOL"))) { //2009-4-3 池改用单独对象实现 OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPool, pEquip); if (pEquip) { pListAll->m_nDang = pEquip->GetGroundEle(); } OPENOBJ_END(); pListAll->m_iType = 4; pListAll->m_csName = _T("HC"); GlobalFunc::GetAllPipeAndNodeByNode(id, idFront, ss); } else { OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { pListAll->m_nDang = pEquip->GetWellEleUp(); //井地面标高 pListAll->m_csName = pEquip->GetWellName(); //井编号 pListAll->m_iType = 3; AcDbObjectId idBlk = pEquip->GetBlock2d(); CString csBlkName = GlobalFunc::GetBlkNameById(idBlk); if (_tcsicmp(_T("$TWTSYS$00000186"), csBlkName) == 0) //阀门井 pListAll->m_iNum = 1; else if (_tcsicmp(_T("$TWTSYS$00000187"), csBlkName) == 0 || _tcsicmp(_T("$TWTSYS$00000336"), csBlkName) == 0) //检查井 pListAll->m_iNum = 2; else if (_tcsicmp(_T("$TWTSYS$00000190"), csBlkName) == 0) //水封井 pListAll->m_iNum = 3; else if (_tcsicmp(_T("$TWTSYS$00000191"), csBlkName) == 0) //跌水井 pListAll->m_iNum = 4; if (pEquip->IsDropWell()) pListAll->m_iNum = 4; pListAll->m_nStartPress = pEquip->GetWellEleDown(); //跌水井底标高 pListAll->m_nLost = pEquip->GetScale(); //井口直径 } else if (pListAll->m_iType != 4) { pListAll->m_iType = -1; } OPENOBJ_END(); GlobalFunc::GetAllPipeAndNodeByNode(id, idFront, ss); } ss -= ent; PickSet ssDel(SS_FREE); XPoint ptFront; OPENOBJ_BEGIN(id, AcDb::kForRead, CDbPipeNode, pNode); if (pNode) { ptFront = pNode->GetLocation(); ptFront.z = 0; } OPENOBJ_END(); for (long j = 0; j < ss.Length(); j++) { Entity entTmp = ss[j]; if (entTmp.In(&ssAll) > 0) { return FALSE; } if (entTmp.Is(_T("AEC_ZT_PIPE"))) { OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { XPoint ptS = pPipe->StartPoint(); XPoint ptE = pPipe->EndPoint(); ptS.z = 0; ptE.z = 0; TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); BOOL bDel = FALSE; if (!ent.Is(_T("AEC_ZT_POOL"))) { //从起点->终点 或 按【管线坡度】的方向 if (dir == TPipeSys::kUnknownDir) { bDel = TRUE; } else if (dir == TPipeSys::kFromStart) { double nDist = fabs(ads_distance(ptFront, ptS)); if (ptFront != ptS && nDist > 0.1) //xpoint != g_Option::instance()._distSnap=0.01 室外坐标过大的时候,精度太小 bDel = TRUE; } else if (dir == TPipeSys::kFromEnd) { double nDist = fabs(ads_distance(ptFront, ptE)); if (ptFront != ptE && nDist > 0.1) bDel = TRUE; } } double dn = pPipe->GetDnDiameter(); if (bDel) ssDel += entTmp; if (!bDel && dn < 0) { AfxMessageBox(_T("管线没有进行管径标注")); return TRUE; } } OPENOBJ_END(); } } ss -= ssDel; len = ss.Length(); if (len != 1) //自动搜索,只能顺水流方向搜索,如果有分叉就结束 return TRUE; ssAll += ss; for (long i = 0; i < ss.Length(); i++) { Entity entTmp = ss[i]; AcDbObjectId idTmp = NULL; acdbGetObjectId(idTmp, entTmp); idArray.append(idTmp); } } len = idArray.length(); for (long i = 0; i < len; i++) { AcDbObjectId idTmp = idArray[i]; ads_name ent; Entity entTmp; acdbGetAdsName(ent, idTmp); entTmp = ent; SSearchPipeList *pList = new SSearchPipeList(); pList->m_ID = idTmp; pList->m_pPrevious = pListAll; pListAll->m_lstNode.Append(pList); if (!AutoSearchOutdoorWell(entTmp, id, pList, ssAll)) return FALSE; if (pList->m_lstNode.Length() == 0 && pList->m_iType == -1) { pListAll->m_lstNode.Remove(0); ssAll -= entTmp; } if (pList->m_lstNode.Length() == 0 && pList->m_iType == 0) { pListAll->m_lstNode.Remove(0); ssAll -= entTmp; } } return TRUE; } //将井编号写入链表 BOOL SetWellData(SSearchPipeList *pListAll) { BOOL bRet = TRUE; AcDbObjectId id = NULL; id = pListAll->m_ID; ads_name adsent; acdbGetAdsName(adsent, id); Entity ent = adsent; if (ent.Is(_T("AEC_ZT_PIPE"))) { pListAll->m_iType = 0; OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { pListAll->m_nLength = pPipe->Length(); pListAll->m_iDn = (int)pPipe->GetDnDiameter(); } OPENOBJ_END(); pListAll->m_nI = GlobalFunc::GetPipeGradient(ent); } else { OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { pListAll->m_nDang = pEquip->GetWellEleUp(); //井地面标高 pListAll->m_csName = pEquip->GetWellName(); //井编号 pListAll->m_iType = 3; AcDbObjectId idBlk = pEquip->GetBlock2d(); CString csBlkName = GlobalFunc::GetBlkNameById(idBlk); if (_tcsicmp(_T("$TWTSYS$00000186"), csBlkName) == 0) //阀门井 pListAll->m_iNum = 1; else if (_tcsicmp(_T("$TWTSYS$00000187"), csBlkName) == 0 || _tcsicmp(_T("$TWTSYS$00000336"), csBlkName) == 0) //检查井 pListAll->m_iNum = 2; else if (_tcsicmp(_T("$TWTSYS$00000190"), csBlkName) == 0) //水封井 pListAll->m_iNum = 3; else if (_tcsicmp(_T("$TWTSYS$00000191"), csBlkName) == 0) //跌水井 pListAll->m_iNum = 4; if (pEquip->IsDropWell()) pListAll->m_iNum = 4; pListAll->m_nStartPress = pEquip->GetWellEleDown(); //跌水井底标高 pListAll->m_nLost = pEquip->GetScale(); //井口直径 } else if (pListAll->m_iType == 4) { pListAll->m_csName = _T("HC"); //井编号 } else { pListAll->m_iType = -1; g_Option::instance().adsout << _T("\n2管线相交之处缺少井!"); //AfxMessageBox(_T("2管线相交之处缺少井!")); //return FALSE; } OPENOBJ_END(); } long len = pListAll->m_lstNode.Length(); for (long i = 0; i < len; i++) { SSearchPipeList *pList = pListAll->m_lstNode[i]; bRet = SetWellData(pList); } return bRet; } //本节点往下走,能通向终止井吗? BOOL IsNodeLink2EndWell(SSearchPipeList *pListAll, Entity entEnd) { BOOL bRet = FALSE; AcDbObjectId id = NULL; if (pListAll->m_iType == 3) { id = pListAll->m_ID; ads_name adsent; acdbGetAdsName(adsent, id); Entity ent = adsent; if (ent == entEnd) return TRUE; } long len = pListAll->m_lstNode.Length(); for (long i = 0; i < len; i++) { SSearchPipeList *pList = pListAll->m_lstNode[i]; bRet = IsNodeLink2EndWell(pList, entEnd); if (bRet) return TRUE; } return bRet; } //将整个系统pListAll的唯一通道提取出来放到pListNew中 //pListNew 是一个从 “起始井”到“终止井”的单向链表 BOOL SearchSysFromAll(SSearchPipeList *pListAll, SSearchPipeList *pListNew, Entity entEnd, PickSet &ssAll, BOOL bModifyDir) { BOOL bRet = TRUE; //复制内容 pListNew->m_iDn = pListAll->m_iDn; pListNew->m_bNeedCale = pListAll->m_bNeedCale; pListNew->m_iNum = pListAll->m_iNum; pListNew->m_ID = pListAll->m_ID; pListNew->m_iType = pListAll->m_iType; pListNew->m_csName = pListAll->m_csName; pListNew->m_nLength = pListAll->m_nLength; pListNew->m_nPipeQ = pListAll->m_nPipeQ; pListNew->m_nDang = pListAll->m_nDang; pListNew->m_nStartPress = pListAll->m_nStartPress; pListNew->m_nI = pListAll->m_nI; pListNew->m_nV = pListAll->m_nV; pListNew->m_nLost = pListAll->m_nLost; long len = pListAll->m_lstNode.Length(); ssAll += pListNew->m_ID; //重新确定水流方向 if (pListAll->m_iType == 0 && bModifyDir) { XPoint ptFront; if (pListAll->m_pPrevious != NULL) { OPENOBJ_BEGIN(pListAll->m_pPrevious->m_ID, AcDb::kForRead, CDbPipeNode, pNode); if (pNode) { ptFront = pNode->GetLocation(); } OPENOBJ_END(); } OPENOBJ_BEGIN(pListNew->m_ID, AcDb::kForWrite, CDbPipe, pPipe); if (pPipe) { XPoint p1 = ptFront; p1.z = 0; XPoint p2 = pPipe->StartPoint(); p2.z = 0; if (p1 == p2) pPipe->SetFlowDir(TPipeSys::kFromStart); else pPipe->SetFlowDir(TPipeSys::kFromEnd); } OPENOBJ_END(); } for (long i = 0; i < len; i++) { SSearchPipeList *pList = pListAll->m_lstNode[i]; if (!IsNodeLink2EndWell(pList, entEnd)) continue; SSearchPipeList *pNodeNew = new SSearchPipeList(); pNodeNew->m_pPrevious = pListNew; pListNew->m_lstNode.Append(pNodeNew); bRet = SearchSysFromAll(pList, pNodeNew, entEnd, ssAll, bModifyDir); } return bRet; } BOOL SearchOutdoorWell(Entity ent, Entity entEnd, SSearchPipeList *pListAll, PickSet &ssAll, BOOL bModifyDir) { if (!entEnd) //没有指定终止井 return AutoSearchOutdoorWell(ent, NULL, pListAll, ssAll); //有指定井,由于系统绘制方向可能不是有序的,首先搜索整个系统 SSearchPipeList *pListAll2 = new SSearchPipeList(); PickSet ss(SS_FREE); ss += ent; if (!GlobalFunc::SearchSprinkPipeSys(ent, NULL, pListAll2, ss)) { delete pListAll2; return FALSE; } long len = ss.Length(); int pos = entEnd.In(&ss); // ss.Redraw(3); if (pos == 0) { delete pListAll2; return FALSE; } SetWellData(pListAll2); //2008-5-8 增加bModifyDir是否强制修改管道的方向,纵断面图需要修改,而计算地面标高则不需要 BOOL ret = SearchSysFromAll(pListAll2, pListAll, entEnd, ssAll, bModifyDir); delete pListAll2; len = ssAll.Length(); return ret; } //把树结构的数据转化为DLIST链表结构 BOOL GetWellListData(SSearchPipeList *pListAll, DList &lstWellSys) { if (pListAll->m_iType == -1) return FALSE; TWellData *pList = new TWellData(); pList->m_iDn = pListAll->m_iDn; if (pListAll->m_iType == 3 || pListAll->m_iType == 4) { pList->m_bIsWell = TRUE; AcDbObjectId id = pListAll->m_ID; ads_name ent; acdbGetAdsName(ent, id); BOOL bIsRectWell = FALSE; OPENOBJ_BEGIN(id, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { AcDbObjectId idRec = pEquip->GetBlock2d(); if (_tcsicmp(GlobalFunc::GetBlkNameById(idRec), _T("$TwtSys$00000336")) == 0) bIsRectWell = TRUE; } OPENOBJ_END(); CString csWellRadius = GlobalFunc::ReadXdata(ent, _T("TG-WELL-RADIUS")); pList->m_nWellRadius = _tstof(csWellRadius) / 2.0; //转化为半径 if (fabs(pList->m_nWellRadius) < 0.1) pList->m_nWellRadius = 350; if (bIsRectWell) pList->m_nWellRadius *= (-1); } else pList->m_bIsWell = FALSE; if (pListAll->m_iNum == 4) pList->m_bIsDropWell = TRUE; //如果接化粪池,管线长度要减去化粪池遮挡的部分 if (pListAll->m_iType == 0) { SSearchPipeList *pListPrevious = pListAll->m_pPrevious; BOOL bFlag = FALSE; if (pListPrevious != NULL && pListPrevious->m_iType == 4) { bFlag = TRUE; } else if (pListAll->m_lstNode.Length() == 1) { pListPrevious = pListAll->m_lstNode[0]; if (pListPrevious != NULL && pListPrevious->m_iType == 4) bFlag = TRUE; } if (bFlag) { AcDbObjectId id = pListPrevious->m_ID; OPENOBJ_BEGIN(id, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { double nXScale = pEquip->GetScale(); pListAll->m_nLength = pListAll->m_nLength - nXScale / 2;//管长=对象长-井直径 } OPENOBJ_END(); } } pList->m_csName = pListAll->m_csName; pList->m_ID = pListAll->m_ID; pList->m_nI = pListAll->m_nI; pList->m_nUpEle = pListAll->m_nDang; //井地面标高 // cet 2012.7.26 add 化粪池地面标高 if (pListAll->m_iType == 4) { CDbPool *pPool = NULL; acdbOpenObject(pPool, pListAll->m_ID, AcDb::kForRead); if (pPool != NULL) { pList->m_nUpEle = pPool->GetGroundEle(); pPool->close(); } } pList->m_nDownEle = pListAll->m_nStartPress; //跌水井底标高 pList->m_nLength = pListAll->m_nLength; // if(!GlobalFunc::DocGetMeterUnitDraw()) // pList->m_nLength = pList->m_nLength/1000; lstWellSys.Append(pList); BOOL bRet = TRUE; long len = pListAll->m_lstNode.Length(); for (long i = 0; i < len; i++) { SSearchPipeList *pList = pListAll->m_lstNode[i]; bRet = GetWellListData(pList, lstWellSys); } return bRet; } //*************************************************************************************************** // 搜索井 //*************************************************************************************************** void FindMissWell(XStringList &lstWellName) { TCHAR szText1[256]; TCHAR szText2[256]; if (ads_getstring(NULL, _T("\n请输入要起始井的编号<退出>:"), szText1) != RTNORM) { return; } if (ads_getstring(NULL, _T("\n请输入要终止井的编号<退出>:"), szText2) != RTNORM) { return; } int idx1 = lstWellName.Index(szText1, 0); int idx2 = lstWellName.Index(szText2, 0); if (idx1 < 0 || idx2 < 0) { g_Option::instance().adsout << _T("\n所输入起始井或终止井的编号不存在!"); return; } CString csBase(szText1); CString csFinish(szText2); while (1) { CString csTmp = GlobalFunc::PlusString(csBase, 1, TRUE); if (csTmp == csFinish) { g_Option::instance().adsout << _T("\n没有漏井!"); return; } idx1 = lstWellName.Index(csTmp, 0); CString csPrompt; csPrompt.Format(_T("\n%s井不存在!"), csTmp); if (idx1 < 0) { g_Option::instance().adsout << (const TCHAR*)csPrompt; return; } csBase = csTmp; } } void FindWell() { TCHAR szText[256]; RBList rbMask(RTDXF0, _T("AEC_ZT_WELL"), NULL); PickSet ss(SS_FREE); ss.Get(_T("X"), NULL, NULL, rbMask); long len = ss.Length(); XStringList lstWellName, lstRepeat; for (long i = 0; i < len; i++) { Entity ent = ss[i]; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { if (!pEquip->IsDrawLabel()) continue; CString csName = pEquip->GetWellName(); if (lstWellName.Index(csName, 0) < 0) lstWellName.Append(tstrnew(csName)); else lstRepeat.Append(tstrnew(csName)); } OPENOBJ_END(); } for (int j = 0; j < lstRepeat.Length(); j++) { g_Option::instance().adsout << XString(_T("\n编号为%s的井有重复。"), lstRepeat[j]); } if (ads_getstring(NULL, _T("\n请输入要搜索井的编号<搜索漏井>:"), szText) != RTNORM) { FindMissWell(lstWellName); return; } if (_tcsicmp(szText, _T("")) == 0) { FindMissWell(lstWellName); return; } int count = 0; PickSet ssWell(SS_FREE); for (i = 0; i < len; i++) { Entity ent = ss[i]; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { if (!pEquip->IsDrawLabel()) continue; CString csName = pEquip->GetWellName(); if (_tcsicmp(csName, szText) == 0) { ssWell += ent; count++; } } OPENOBJ_END(); } XPoint ptCen, ptLow, ptUp; double x, y, z; ssWell.GetExtend(ptCen, &x, &y, &z); ptLow = ptUp = ptCen; ptLow.x -= x; ptLow.y -= y; ptUp.x += x; ptUp.y += y; if (count < 1) g_Option::instance().adsout << _T("\n没有发现该编号的井!"); else if (count > 1) { g_Option::instance().adsout << _T("\n发现多个重名的井!"); GlobalFunc::AssureInCurrentView(ptLow, ptUp); } else { g_Option::instance().adsout << _T("\n已经成功发现!该井位于屏幕中心黄叉处。"); GlobalFunc::ArxZoomTo(ptCen, 100 * GlobalFunc::DocGetPScale(), 100 * GlobalFunc::DocGetPScale()); } for (i = 0; i < count; i++) { Entity ent = ssWell[i]; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { XPoint ptCen; double nX(1), nY(1); ent.GetExtend(ptCen, &nX, &nY); double nDist = GlobalFunc::DocGetPScale() * 100; XPoint p1, p2, p3, p4; ads_polar(ptCen, 0, nDist, p1); ads_polar(p1, PI / 2, nDist, p1); ads_polar(ptCen, PI, nDist, p2); ads_polar(p2, PI / 2, -nDist, p2); ads_grdraw(GlobalFunc::Wcs2Ucs(p1), GlobalFunc::Wcs2Ucs(p2), 2, 0); ads_polar(ptCen, PI / 2, nDist, p3); ads_polar(p3, PI, nDist, p3); ads_polar(ptCen, PI / 2, -nDist, p4); ads_polar(p4, 0, nDist, p4); ads_grdraw(GlobalFunc::Wcs2Ucs(p3), GlobalFunc::Wcs2Ucs(p4), 2, 0); } OPENOBJ_END(); } } //*************************************************************************************************** // 出户连井 //*************************************************************************************************** void ExtendOutdoorPipe() { RBList rbMask(RTDXF0, _T("AEC_ZT_PIPE"), 8, GetLayerNames(_T("管线")), NULL); Entity entMain; PickSet ss(SS_FREE); if (GlobalFunc::SelectEntity(_T("\n请选择室外干管<退出>"), entMain, rbMask) != RTNORM) return; AcDbObjectId id = NULL; OPENOBJ_BEGIN(entMain, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { id = pPipe->GetNode(0); OPENOBJ_BEGIN(id, AcDb::kForRead, AecXDbWell, pEquip); if (!pEquip) { g_Option::instance().adsout << _T("\n请选择室外连井的管线!"); return; } OPENOBJ_END(); } OPENOBJ_END(); TCHAR szLay[256]; entMain.GetData(8, szLay); RBList rbMask2(RTDXF0, _T("AEC_ZT_PIPE"), 8, szLay, NULL); if (GlobalFunc::SelectEntities(_T("\n请选择出户管<退出>"), ss, rbMask2) != RTNORM) return; XPoint p1, p2, p3, p4, ptTmp3, ptTmp4, ptInter; GlobalFunc::GetPipePoint(entMain, p1, p2); XLine line1(p1, p2); line1.StartPoint().z = 0; line1.EndPoint().z = 0; AcGePoint3dArray arBreak; for (long i = 0; i < ss.Length(); i++) { double nElevation(0); Entity ent = ss[i]; GlobalFunc::GetPipePoint(ent, p3, p4); XLine line2(p3, p4); line2.StartPoint().z = 0; line2.EndPoint().z = 0; int ret = line1.Intersection(&line2, ptInter); if (ret != 1) continue; XPoint ptPro; OPENOBJ_BEGIN(entMain, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { AcGePoint3d secPt; pPipe->getClosestPointTo(ptInter, AcGeVector3d::kZAxis, secPt); ptPro = secPt; } OPENOBJ_END(); //判断附近有没有井,规范有间距限制 BOOL bIsTooClose = FALSE; const double dDist = GlobalFunc::DocGetCurMeterUnitDraw() ? 0.5 : 500;// zxl 2012.08.15 add for (int m = 0; m < arBreak.length(); m++) { XPoint ptTmp1 = arBreak[m]; ptTmp1.z = 0; XPoint ptTmp2 = ptPro; ptTmp2.z = 0; double dDist2 = ads_distance(ptTmp1, ptTmp2); //if(ads_distance(ptTmp1, ptTmp2) < 500) // zxl 2012.08.15 modify if (ads_distance(ptTmp1, ptTmp2) < dDist) { bIsTooClose = TRUE; break; } } if (bIsTooClose) continue; arBreak.append(ptPro); nElevation = ptPro.z; ptTmp4 = ads_distance(p3, ptInter) > ads_distance(p4, ptInter) ? p3 : p4; OPENOBJ_BEGIN(ent, AcDb::kForWrite, CDbPipe, pPipe); if (pPipe) { pPipe->SetModelType(TPipeSys::kModel); ptTmp4.z = nElevation; ptInter.z = nElevation; pPipe->SetStartPoint(ptTmp4); pPipe->SetEndPoint(ptInter); } OPENOBJ_END(); } //2008-11-14 sr 收集所有的打断点,这里一次性打断 AcDbVoidPtrArray curves; OPENOBJ_BEGIN(entMain, AcDb::kForWrite, CDbPipe, pPipe); if (pPipe) { pPipe->getSplitCurves(arBreak, curves); for (long k = 0; k < curves.length(); k++) { AcDbCurve *pCurve0 = (AcDbCurve *)curves[k]; GlobalFunc::AddToCurrentSpace(pCurve0, Adesk::kTrue); } if (curves.length() > 0) pPipe->erase(); } OPENOBJ_END(); //TPipePerDocData *pData = GetCurPipeDocData(); //pData->ApplyUpdates(); int len = arBreak.length(); for (int n = 0; n < len; n++) { XPoint ptInter = arBreak[n]; OPENOBJ_BEGIN(id, AcDb::kForRead, AecXDbWell, pWell); if (pWell) { AecXDbWell *pNew = (AecXDbWell*)pWell->clone(); ptInter.z = 0; pNew->SetLocation(ptInter); pNew->SetInsert(ptInter); pNew->SetWellName(_T("")); pNew->SetLabelLocation(XPoint()); pNew->EnableDrawLabel(TRUE, 1.5); pNew->SetDropWell(FALSE); GlobalFunc::AddToCurrentSpace(pNew, Adesk::kTrue); } OPENOBJ_END(); } return; } //*************************************************************************************************** // 雨水口连井 //*************************************************************************************************** void ModifyPipeDn(const std::map > &mapEq, const std::vector &vecPipe) { AcGePoint3d ptLoc; std::map >::const_iterator itM = mapEq.begin(); for (; itM != mapEq.end(); itM++) { bool bSingle = true;// 不存在多篦 std::vector::const_iterator it = (itM->second).begin(); for (; it != (itM->second).end(); it++) { if (*it == 1) { bSingle = false; break; } } int nType = 0; OPENOBJ_BEGIN(itM->first, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { AcDbObjectId id = pEquip->GetBlock2d(); CString sName = GlobalFunc::GetBlkNameById(id); CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp1; if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000424"), xsTmp1) != RTNORM) //单蓖 return; if (sName.Compare(xsTmp1) != 0) { nType = 1; } ptLoc = pEquip->GetLocation(); } OPENOBJ_END(); double dDn = 300; if ((itM->second).size() > 1 && (nType == 1 || !bSingle)) { dDn = 400; } std::vector::const_iterator itV = vecPipe.begin(); for (; itV != vecPipe.end(); itV++) { OPENOBJ_BEGIN(*itV, AcDb::kForWrite, CDbPipe, pPipe); if (pPipe != NULL) { if (pPipe->StartPoint().Distance(ptLoc) < 1e-3 || pPipe->EndPoint().Distance(ptLoc) < 1e-3) { pPipe->SetDnDiameter(dDn); break; } } OPENOBJ_END(); } } } void Gully2Well() { GlobalFunc::DocGetPickFirst().Free(); PickSet ss(SS_FREE); PickSet ssAll(SS_FREE); PickSet ssGully(SS_FREE); PickSet ssWell(SS_FREE); XPushVar vOsMode(_T("OSMODE"), 0); RBList rbMask = ads_buildlist(-4, _T(""), -4, _T(""), -4, _T("or>"), NULL); RBList rbMaskPipe(RTDXF0, _T("AEC_ZT_PIPE"), 8, LAY_PIPE_RAIN, NULL); if (GlobalFunc::SelectEntities(_T("\n请选择雨水口和就近的雨水井<退出>:"), ss, rbMask) != RTNORM) return; ssAll += ss; // ssAll.Get(_T("X"), NULL, NULL, rbMask); GlobalFunc::InitPipeLayer(LAY_PIPE_RAIN); long len = ss.Length(); for (long i = 0; i < len; i++) { Entity ent = ss[i]; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (!pEquip) { ssGully += ent; } OPENOBJ_END(); } if (ssGully.Length() < 1) return; if (ssGully.Length() == ssAll.Length()) ssAll.Get(_T("X"), NULL, NULL, rbMask); len = ssAll.Length(); for (i = 0; i < len; i++) { Entity ent = ssAll[i]; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { BOOL bFlag = FALSE; AcDbObjectId idBlk = pEquip->GetBlock2d(); CString csBlkName = GlobalFunc::GetBlkNameById(idBlk); // if(_tcsicmp(_T("$TWTSYS$00000187"), csBlkName) == 0 // || _tcsicmp(_T("$TWTSYS$00000336"), csBlkName) == 0 // || _tcsicmp(_T("$TWTSYS$00000375"), csBlkName) == 0 // || _tcsicmp(_T("$TWTSYS$00000414"), csBlkName) == 0 // || _tcsicmp(_T("$TWTSYS$00000376"), csBlkName) == 0 ) { //检查井 int num = pEquip->GetInterfaceNum(); for (int i = 0; i < num; i++) { CPipeInterface face; pEquip->GetInterface(i, face); AcDbObjectId nextPipeId = face.m_idPipe; OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { if (pPipe->GetSysType() == TPipeSys::kRainWater) { bFlag = TRUE; break; } } OPENOBJ_END(); } if (bFlag) ssWell += ent; // } } OPENOBJ_END(); } //以上代码,是把检查井,雨水口 分开 len = ssGully.Length(); // 重新更新雨水口,以确保由于copy时连续插入多个雨水口时, // 清除新雨水口中错误的接口连接 cet 2013.3.15 add for (i = 0; i < len; ++i) { OPENOBJ_BEGIN(ssGully[i], AcDb::kForWrite, CDbEquipment, pEquip) OPENOBJ_END(); } //TPipePerDocData* pDoc = GetCurPipeDocData(); //if (pDoc != NULL) //{ // pDoc->ApplyUpdates(); //} // zxl 2013.05.29 add std::map > mapEq; std::vector vecPipe; bool bLinkWithGully = false; for (i = 0; i < len; i++) { Entity entCurGully = ssGully[i]; XPoint ptCurGullyLoc; BOOL bHasLinkPipe = FALSE; SSearchPipeList *pListAll = new SSearchPipeList(); PickSet ssSearch(SS_FREE); GlobalFunc::SearchSprinkPipeSys(entCurGully, NULL, pListAll, ssSearch); delete pListAll; for (long m = 0; m < ssSearch.Length(); m++) { Entity entTmp = ssSearch[m]; if (entTmp.Is(_T("AEC_ZT_WELL"))) { bHasLinkPipe = TRUE; break; } } if (bHasLinkPipe)//如果这个雨水口已经接管线,就不理会他 continue; OPENOBJ_BEGIN(entCurGully, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { ptCurGullyLoc = pEquip->GetLocation(); } OPENOBJ_END(); double nDist = -1; Entity entNearWellOrGully;//找到雨水口最近的检查井, 或雨水口 XPoint ptNearWellOrGully; //检查井的插入点 for (long j = 0; j < ssWell.Length(); j++) { Entity entWell = ssWell[j]; XPoint ptLoc2; OPENOBJ_BEGIN(entWell, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { ptLoc2 = pEquip->GetLocation(); } OPENOBJ_END(); double n = ads_distance(ptCurGullyLoc, ptLoc2); if (nDist < 0 || nDist > n) { nDist = n; entNearWellOrGully = entWell; ptNearWellOrGully = ptLoc2; } } if (!!entNearWellOrGully) {//看看这个检查井最近的雨水口是否是它自己 double nDist2 = -1; Entity entNearGully;//找到检查井最近的雨水口 XPoint ptNearGully; //最近的雨水口的插入点 for (long m = 0; m < len; m++) { Entity ent3 = ssGully[m]; XPoint ptLoc3; OPENOBJ_BEGIN(ent3, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { ptLoc3 = pEquip->GetLocation(); } OPENOBJ_END(); double n = ads_distance(ptNearWellOrGully, ptLoc3); if (nDist2 < 0 || nDist2 > n) { nDist2 = n; entNearGully = ent3; ptNearGully = ptLoc3; } } if (!(entNearGully == entCurGully)) { double n = ads_distance(ptCurGullyLoc, ptNearGully);//2雨水口的距离 struct resbuf *pointlist; PickSet ssPipe(SS_FREE); GlobalFunc::AssureInCurrentView(ptCurGullyLoc, ptNearGully); pointlist = ads_buildlist(RTPOINT, &ptCurGullyLoc, RTPOINT, &ptNearGully, NULL); ssPipe.Get(_T("F"), pointlist, NULL, rbMaskPipe); ads_relrb(pointlist); long e = ssPipe.Length(); if (ssPipe.Length() == 0 && n < nDist) {//2雨水口相连 entNearWellOrGully = entNearGully; ptNearWellOrGully = ptNearGully; // zxl 2013.05.29 add int nType = 0; bLinkWithGully = true; AcDbObjectId idGully; acdbGetObjectId(idGully, entNearWellOrGully); OPENOBJ_BEGIN(entCurGully, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { AcDbObjectId id = pEquip->GetBlock2d(); CString sName = GlobalFunc::GetBlkNameById(id); CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp1; if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000424"), xsTmp1) != RTNORM) //单蓖 return; if (sName.Compare(xsTmp1) != 0) { nType = 1; } } OPENOBJ_END(); std::map >::iterator it = mapEq.find(idGully); std::vector vecGullyType; if (it != mapEq.end()) { vecGullyType = it->second; vecGullyType.push_back(nType); it->second = vecGullyType; } else { vecGullyType.push_back(nType); mapEq.insert(std::make_pair(idGully, vecGullyType)); } } } } if (!!entNearWellOrGully) { OPENOBJ_BEGIN(entNearWellOrGully, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { double dEle = pEquip->GetWellEleDown(); ptCurGullyLoc.z = dEle * 1000; ptNearWellOrGully.z = dEle * 1000; } OPENOBJ_END(); double dDn = 200;// zxl 2013.05.29 add OPENOBJ_BEGIN(entCurGully, AcDb::kForWrite, CDbEquipment, pEquip); if (pEquip) { pEquip->SetLocation(ptCurGullyLoc); // zxl 2013.05.29 add AcDbObjectId id = pEquip->GetBlock2d(); CString sName = GlobalFunc::GetBlkNameById(id); CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp1; if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000424"), xsTmp1) != RTNORM) //单蓖 return; bool bSingle = true; if (sName.Compare(xsTmp1) != 0) { bSingle = false; dDn = 300; } } OPENOBJ_END(); CDbPipe *pNewPipe = new CDbPipe; pNewPipe->SetStartPoint(ptCurGullyLoc); pNewPipe->SetEndPoint(ptNearWellOrGully); // cet 2013.1.4 add 自动修正上华带文字线型的逆向管线 CString sLineType = GlobalFunc::GetLayerLineType(LAY_PIPE_RAIN); if (sLineType.Find(_T("TG")) > -1) { AcGeVector3d vtDir = GlobalFunc::Wcs2Ucs(ptNearWellOrGully) - GlobalFunc::Wcs2Ucs(ptCurGullyLoc); vtDir.z = 0.0; double dAngle = (AcGeVector3d::kXAxis).angleTo(vtDir, AcGeVector3d::kZAxis); if (dAngle > PI / 2 && dAngle < (PI / 2 * 3 + 0.001)) { pNewPipe->SetStartPoint(ptNearWellOrGully); pNewPipe->SetEndPoint(ptCurGullyLoc); } } pNewPipe->SetPipeWeight(g_Option::instance().g_nPipeWidth[5]); pNewPipe->SetSysType(TPipeSys::kRainWater); pNewPipe->SetModelType(TPipeSys::kModel); pNewPipe->SetMaterial(12);//钢筋混凝土 // zxl 2013.05.29 modify // pNewPipe->SetDnDiameter(200); pNewPipe->SetDnDiameter(dDn); pNewPipe->SetPipeGradient(0.01); pNewPipe->setLayer(LAY_PIPE_RAIN); pNewPipe->setLinetype(GlobalFunc::GetPipeWireLayLineType(LAY_PIPE_RAIN)); pNewPipe->setColor(AcCmColor()); AcDbObjectId id = GlobalFunc::AddToCurrentSpace(pNewPipe, Adesk::kTrue); if (!bLinkWithGully) { vecPipe.push_back(id); } bLinkWithGully = false; } } ModifyPipeDn(mapEq, vecPipe); } //*************************************************************************************************** // 室外图库 //*************************************************************************************************** void OutLib() { InitLayer(LAY_TWT_OUT); GlobalFunc::PushVarStr clayer(_T("CLAYER"), LAY_TWT_OUT); XString sLibFile, sTkw; sLibFile << g_csDwbPath << _T("室外库.TKW"); XString xsTmp = _T("00000001"); //InvokeTkwMan(sLibFile, FALSE, xsTmp); } void PoolLib() { InitLayer(LAY_TWT_OUT); GlobalFunc::PushVarStr clayer(_T("CLAYER"), LAY_TWT_OUT); XString sLibFile, sTkw; sLibFile << g_csDwbPath << _T("水池库.TKW"); XString xsTmp = _T("00000001"); //InvokeTkwMan(sLibFile, FALSE, xsTmp); } //*************************************************************************************************** // 管线交叉检查 //*************************************************************************************************** double GetPipeStartEle(Entity entPipe) { double dUnitMeter = 1000; if (GlobalFunc::DocGetMeterUnitDraw()) dUnitMeter = 1; OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe); if (pPipe) { AcDbObjectId nodeId1(NULL); double dn = pPipe->GetDnDiameter(); dn = GlobalFunc::GetPipeOutDByDn(pPipe->GetMaterial(), dn); // cet 2010.3.18 add dn = dn / 2000; TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if (dir == TPipeSys::kFromStart) { return pPipe->StartPoint().z / dUnitMeter - dn; } else { return pPipe->EndPoint().z / dUnitMeter - dn; } } OPENOBJ_END(); return 0; } double GetPipeThick(Entity& ent) { double dThick = 0.0; CDbPipe *pPipe = NULL; AcDbObjectId ident; acdbGetObjectId(ident, ent); double dDn1 = 0.0; // 外径 double dDn2 = 0.0; // 内径 acdbOpenObject(pPipe, ident, AcDb::kForRead); if (pPipe != NULL) { double dDn = pPipe->GetDnDiameter(); int nMat = pPipe->GetMaterial(); dDn1 = GlobalFunc::GetPipeOutDByDn(nMat, dDn); dDn1 = dDn1 / 1000; CString strMat = GlobalFunc::GetPipeMaterialByIdx(nMat); dDn2 = GlobalFunc::GetPipeDjByDn(strMat, (int)dDn); pPipe->close(); } dThick = (dDn1 - dDn2) / 2; return dThick; } //*************************************************************************************************** // 污井流量 //*************************************************************************************************** void SetDirtWellQ() { double nQ(0); CString csQ; RBList rbMask(RTDXF0, _T("AEC_ZT_WELL"), 8, LAY_WELL_DIRT, NULL); PickSet ss(SS_FREE); PickSet ssAll(SS_FREE), ssDel(SS_FREE); ssAll.Get(_T("X"), NULL, NULL, rbMask); for (long j = 0; j < ssAll.Length(); j++) { Entity ent = ssAll[j]; csQ = GlobalFunc::ReadXdata(ent, _T("TG-DIRTWELLQ")); if (csQ != _T("")) { XPoint ptLoc; double nScale(0); OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbEquipment, pEquip); if (pEquip) { ptLoc = pEquip->GetLocation(); nScale = pEquip->GetScale(); } OPENOBJ_END(); XText text(XString(_T("Q=%s(L/S)"), csQ), ptLoc, g_Option::instance().g_nTwtDimHeight * GlobalFunc::DocGetPScale(), g_Option::instance().g_nDimScale, g_Option::instance().g_csTwtDimStyle, LAY_CALC_TEXT); text.Draw(); Entity entCir2; entCir2.GetLast(); ssDel += entCir2; } } if (GlobalFunc::SelectEntities(_T("\n请选择污水井:<退出>"), ss, rbMask) != RTNORM) { ssDel.Erase(); return; } ssDel.Erase(); long len = ss.Length(); if (ads_getreal(_T("\n请给出流入污水井的流量(L/S)(注意不包括转输流量)<退出>:"), &nQ) != RTNORM) return; csQ.Format(_T("%.2f"), nQ); for (long i = 0; i < len; i++) { Entity ent = ss[i]; GlobalFunc::WriteXdata(ent, _T("TG-DIRTWELLQ"), csQ); } } //*************************************************************************************************** // 雨水参数 //*************************************************************************************************** void RainCalcParm() { TCHAR szText[256]; if (ads_getstring(0, _T("\n请选择要输入的雨水井参数1:径流系数 2:重现期 3:汇水时间<径流系数>:"), szText) != RTNORM) return; RBList rbMask(RTDXF0, _T("AEC_ZT_WELL"), 8, LAY_WELL_RAIN, NULL); PickSet ss(SS_FREE); if (_tcsicmp(szText, _T("3")) == 0) { Entity ent; if (GlobalFunc::SelectEntity(_T("\n请选择起点雨水井:<退出>"), ent, rbMask) != RTNORM) return; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { int num = pEquip->GetInterfaceNum(); if (num != 1) { g_Option::instance().adsout << _T("\n不是起点井!"); return; } } OPENOBJ_END(); ss += ent; } else { if (GlobalFunc::SelectEntities(_T("\n请选择雨水井:<退出>"), ss, rbMask) != RTNORM) return; } CString csTime, csFactor, csP; if (_tcsicmp(szText, _T("2")) == 0) { int iP(0); if (ads_getint(_T("\n请给出重现期<默认>:"), &iP) == RTNORM) { if (iP > 0.001) { csP.Format(_T("%d"), iP); } } } else if (_tcsicmp(szText, _T("3")) == 0) { int iTime(0); if (ads_getint(_T("\n请给出汇水时间(5~15分钟)<默认>:"), &iTime) == RTNORM) { if (iTime > 0.1) { csTime.Format(_T("%d"), iTime); } } } else { double nFactor(-1); if (ads_getreal(_T("\n请给出单井径流系数(如:绿地0.15, 沥青路面0.6等))<默认>:"), &nFactor) == RTNORM) { if (nFactor > 0.001) { csFactor.Format(_T("%.2f"), nFactor); } } } for (long i = 0; i < ss.Length(); i++) { Entity ent = ss[i]; if (csFactor != _T("")) GlobalFunc::WriteXdata(ent, _T("TG-RAINWELLFACTOR"), csFactor); if (csP != _T("")) GlobalFunc::WriteXdata(ent, _T("TG-RAINWELLP"), csP); if (csTime != _T("")) GlobalFunc::WriteXdata(ent, _T("TG-WELLTIME"), csTime); } } //*************************************************************************************************** // 汇流面积 //*************************************************************************************************** void UpdateRainWellArea() { RBList rbMask2(RTDXF0, _T("AEC_ZT_SPACE"), 8, LAY_CALC_AREA, NULL); PickSet ss(SS_FREE); PickSet ssAll(SS_FREE); ssAll.Get(_T("X"), NULL, NULL, rbMask2); int len = ssAll.Length(); if (len < 1) return; for (long i = 0; i < len; i++) { Entity ent = ssAll[i]; //OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbConfluenceArea, pDbSpace); //if (pDbSpace) //{ // CString csArea; // double nArea = pDbSpace->m_nUseArea; // if (nArea < 1 && GlobalFunc::DocGetMeterUnitDraw()) // nArea = nArea * 1000000; // csArea.Format(_T("%.2f"), nArea); // ads_name name; // acdbGetAdsName(name, pDbSpace->GetWellId()); // Entity entWell = name; // GlobalFunc::WriteXdata(entWell, _T("TG-WELLAREA"), csArea); //} //OPENOBJ_END(); } } // zxl 2013.12.18 add void RemoveWellArea(Entity ent) { OPENOBJ_BEGIN(ent, AcDb::kForWrite, AecXDbWell, pEquip); if (pEquip != NULL) { AcDbObjectId idSpace = pEquip->GetSpaceId(); pEquip->SetSpaceId(NULL); //OPENOBJ_BEGIN(idSpace, AcDb::kForWrite, TDbConfluenceArea, pSpace); //if (pSpace != NULL) //{ // pSpace->SetWellId(NULL); //} //OPENOBJ_END(); } OPENOBJ_END(); } void RemoveAreaWell(Entity &ent) { // 如果是旧的TDBSPACE实体,转换为新实体TDBCONFLUENCEAREA bool bIsNewObj = false; //OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbConfluenceArea, pArea); //if (pArea != NULL) //{ // AcDbObjectId idWell = pArea->GetWellId(); // pArea->SetWellId(NULL); // OPENOBJ_BEGIN(idWell, AcDb::kForWrite, AecXDbWell, pEquip); // if (pEquip != NULL) // { // pEquip->SetSpaceId(NULL); // } // OPENOBJ_END(); // bIsNewObj = true; //} //OPENOBJ_END(); if (!bIsNewObj) { //OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbSpace, pSpace); //if (pSpace != NULL) //{ // TDbConfluenceArea *pArea = new TDbConfluenceArea(); // pArea->m_ptLocation = pSpace->m_ptLocation; // pArea->SetHas3D(FALSE); // pArea->SetHighlight(TRUE); // pArea->m_nUseArea = pSpace->m_nUseArea; // pArea->m_nOccuArea = 0; // pArea->m_nCeilArea = 0; // pArea->m_nWallSurfArea = 0; // pArea->m_nExtWallArea = 0; // pArea->m_nExtWinArea = 0; // pArea->m_nExtDoorArea = 0; // pArea->m_nPerimeter = 0; // pArea->m_nKickboardLength = 0; // pArea->SetShowOutline(TRUE); // pArea->SetTextStyleId(InitTextStyle(g_Option::instance().g_csDimWellStyle)); // AcDbObjectId idArea = pArea->AddToCSpace(Adesk::kFalse); // pArea->setLayer(InitLayer(LAY_CALC_AREA)); // pArea->m_outline = pSpace->m_outline; // pArea->m_sName = pSpace->m_sName; // pArea->SetWellId(NULL); // pArea->Close(); //} //OPENOBJ_END(); ent.Erase(); ent.GetLast(); } } void ReNewWellArea(Entity entWell, Entity entArea)// 绑定井和汇流面积 { AcDbObjectId idWell, idArea; RemoveWellArea(entWell); RemoveAreaWell(entArea); acdbGetObjectId(idWell, entWell); acdbGetObjectId(idArea, entArea); OPENOBJ_BEGIN(entWell, AcDb::kForWrite, AecXDbWell, pEquip); if (pEquip != NULL) { pEquip->SetSpaceId(idArea); //OPENOBJ_BEGIN(entArea, AcDb::kForWrite, TDbConfluenceArea, pSpace); //if (pSpace != NULL) //{ // pSpace->SetWellId(idWell); //} //OPENOBJ_END(); } OPENOBJ_END(); } void CopyArea2Well(Entity entWell) { GlobalFunc::DocGetPickFirst().Free(); RBList rbMask(RTDXF0, _T("AEC_ZT_SPACE"), 8, LAY_CALC_AREA, NULL); Entity entSel; XPoint ptPick; if (GlobalFunc::SelectEntity(_T("\n请选择要复制的汇流面积:<退出>"), entSel, ptPick, rbMask) == RTNORM) { xg_setvar(_T("CMDECHO"), 0); int nOsMode = 0; xg_getvar(_T("OSMODE"), &nOsMode); //if (g_bTgOsnap) //{ // nOsMode &= ~0x4000; // nOsMode |= OS_INT | OS_NEA | OS_PER | OS_END | OS_CEN; //} XPushVar vOsMode(_T("OSMODE"), nOsMode); double dCeltScale = 1; xg_getvar(_T("CELTSCALE"), &dCeltScale); PickSet ss(SS_FREE); ss += entSel; ads_printf(_T("\n请点取位置点:<退出>")); ptPick = GlobalFunc::Ucs2Wcs(ptPick); ADSGePoint3d _pt(GlobalFunc::Wcs2Ucs(ptPick)); int nRet = SHads_command(RTSTR, _T("COPY"), RTPICKS, (TLong_ptr *)ss, RTSTR, _T(""), RT3DPOINT, &_pt, RTSTR, PAUSE, 0); Entity ent; ent.GetLast(); ReNewWellArea(entWell, ent); } } bool CheckWellArea(Entity entWell) { //GlobalFunc::DocGetPickFirst().Free(); //OPENOBJ_BEGIN(entWell, AcDb::kForRead, AecXDbWell, pEquip); //if (pEquip != NULL) //{ // AcDbObjectId idSpace = pEquip->GetSpaceId(); // OPENOBJ_BEGIN(idSpace, AcDb::kForRead, TDbSpace, pSpace); // if (pSpace != NULL) // { // XPoly2D poly2d = pSpace->m_outline; // if ((pEquip->GetInsert() & poly2d) == PR_INSIDE) // { // return true; // } // } // OPENOBJ_END(); //} //OPENOBJ_END(); return false; } XPoint GetWellLoction(Entity ent) { XPoint ptLoc; OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip != NULL) { ptLoc = pEquip->GetInsert(); } OPENOBJ_END(); return ptLoc; } void BindArea2Well(Entity entWell, PickSet ssArea) { double dArea = 0.0; Entity entArea; int nIndex = 0; GlobalFunc::DocGetPickFirst().Free(); XPoint ptLoc = GetWellLoction(entWell); for (long l = 0l; l < ssArea.Length(); l++) { Entity ent1 = ssArea[l]; //OPENOBJ_BEGIN(ent1, AcDb::kForRead, TDbSpace, pSpace); //if (pSpace != NULL) //{ // XPoly2D poly2d = pSpace->m_outline; // bool bInSide = (ptLoc & poly2d) == PR_INSIDE ? true : false; // RBList rbFence; // for (int i = 0; i < poly2d.Length(); i++) // { // XPoint pt = *(poly2d.GetAt(i)); // rbFence.Append(acutBuildList(RTPOINT, &GlobalFunc::Wcs2Ucs(pt), NULL)); // } // PickSet ss(SS_FREE); // RBList rbMask(RTDXF0, _T("AEC_ZT_WELL"), 8, LAY_WELL_RAIN, NULL); // ss.Get(_T("CP"), rbFence, NULL, rbMask); // int len = 0.0; // for (long l = 0; l < ss.Length(); l++) // { // XPoint pt = GetWellLoction(ss[l]); // if ((pt & poly2d) == PR_INSIDE) // { // len++; // } // } // if (len == 1 && bInSide)// 汇流面积只包含该井 // { // double dAreaNew = pSpace->m_nUseArea; // if (nIndex == 0) // { // dArea = dAreaNew; // nIndex++; // entArea = ent1; // } // else if (dArea > dAreaNew) // { // dArea = dAreaNew; // entArea = ent1; // } // } //} //OPENOBJ_END(); } if (!!entArea) { ReNewWellArea(entWell, entArea); } } void BindArea2Well(PickSet &ss) { PickSet ssWell(SS_FREE); PickSet ssArea(SS_FREE); for (long l = 0l; l < ss.Length(); l++) { Entity ent = ss[l]; if (ent.Is(_T("AEC_ZT_WELL"))) { ssWell += ent; } else { ssArea += ent; } } if (ssWell.Length() == 0 || ssArea.Length() == 0) { return; } else if (ssWell.Length() == 1 && ssArea.Length() == 1) { ReNewWellArea(ssWell[0l], ssArea[0l]); } else { for (long l = 0l; l < ssWell.Length(); l++) { Entity ent = ssWell[l]; if (!CheckWellArea(ent))// 未绑定汇流面积或者绑定的汇流面积没有包围井,重新绑定 { BindArea2Well(ent, ssArea); } } } } void RainWellArea() { double nArea(0); CString csArea; RBList rbMask(RTDXF0, _T("AEC_ZT_WELL"), 8, LAY_WELL_RAIN, NULL); RBList rbMask2(RTDXF0, _T("AEC_ZT_SPACE"), 8, LAY_CALC_AREA, NULL); PickSet ss(SS_FREE); PickSet ssAll(SS_FREE); ssAll.Get(_T("X"), NULL, NULL, rbMask2); for (long j = 0; j < ssAll.Length(); j++) { Entity ent = ssAll[j]; //OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbSpace, pSpace); //if (pSpace) { // pSpace->SetHighlight(TRUE); //} //OPENOBJ_END(); } int nRet; TCHAR cKey = _T('\0'); INITGET_BEG(0, _T("G ")); nRet = GlobalFunc::SelectEntities(_T("\n请选择雨水井[关联存在的汇流面积与井(G)]:<退出>"), ss, rbMask, _T("G "), cKey); INITGET_END(); if (nRet == RTKWORD && cKey == _T('G')) { GlobalFunc::DocGetPickFirst().Free(); RBList rbMask3 = ads_buildlist(-4, _T(""), -4, _T(""), -4, _T("or>"), NULL); PickSet ssWellAndArea(SS_FREE); if (GlobalFunc::SelectEntities(_T("\n请选择需要关联的井和汇流面积<退出>"), ssWellAndArea, rbMask3) != RTNORM) return; BindArea2Well(ssWellAndArea); return; } else if (nRet != RTNORM) { return; } long len = ss.Length(); if (len == 1) { XPoly2D poly2d; nRet = GetOpenPoly2D2(_T("\n请勾绘封闭汇流面积:"), poly2d); if (nRet != RTNORM) { if (poly2d.Length() == 0 && nRet == RTPICKS)// 复制汇流面积 { CopyArea2Well(ss[0l]); return; } int iRet = ads_getreal(_T("\n请给出单井汇流面积(平方米)<退出>:"), &nArea); if (iRet != RTNORM) return; // zxl 2013.12.18 add csArea.Format(_T("%.2f"), nArea); for (long i = 0; i < len; i++) { Entity ent = ss[i]; RemoveWellArea(ent); GlobalFunc::WriteXdata(ent, _T("TG-WELLAREA"), csArea); } } else { if (!poly2d.IsClosed()) poly2d.SetFlag(1); XPoint ptLoc; CString csName; AcDbObjectId idWell; OPENOBJ_BEGIN(ss[0L], AcDb::kForWrite, AecXDbWell, pEquip); if (pEquip) { ptLoc = pEquip->GetLocation(); csName = pEquip->GetWellName(); // zxl 2013.12.17 del // double nScale = pEquip->GetScale(); // ads_polar(ptLoc, -PI/2, nScale*2, ptLoc); idWell = pEquip->id(); } OPENOBJ_END(); if (!GlobalFunc::DocGetMeterUnitDraw()) nArea = _AS_SQMETER(poly2d.Area()); else nArea = poly2d.Area(); g_Option::instance().adsout << _T("汇流面积=") << nArea << _T("(平方米)\n"); //TDbConfluenceArea *pDbSpace = new TDbConfluenceArea(); //pDbSpace->m_sName = csName + _T("汇流面积"); //pDbSpace->m_ptLocation = ptLoc; //pDbSpace->SetHas3D(FALSE); //pDbSpace->SetHighlight(TRUE); //pDbSpace->m_outline = poly2d; //pDbSpace->m_nUseArea = nArea; //pDbSpace->m_nOccuArea = 0; //pDbSpace->m_nCeilArea = 0; //pDbSpace->m_nWallSurfArea = 0; //pDbSpace->m_nExtWallArea = 0; //pDbSpace->m_nExtWinArea = 0; //pDbSpace->m_nExtDoorArea = 0; //pDbSpace->m_nPerimeter = 0; //pDbSpace->m_nKickboardLength = 0; //pDbSpace->SetShowOutline(TRUE); //pDbSpace->SetTextStyleId(InitTextStyle(g_Option::instance().g_csDimWellStyle)); //pDbSpace->SetTextHeight(g_Option::instance().g_nDimWellHeight); //AcDbObjectId idSpace = pDbSpace->AddToCSpace(Adesk::kFalse); //pDbSpace->setLayer(InitLayer(LAY_CALC_AREA)); // zxl 2013.12.18 add RemoveWellArea(ss[0L]); //OPENOBJ_BEGIN(idWell, AcDb::kForWrite, AecXDbWell, pEquip); //if (pEquip != NULL) //{ // pEquip->SetSpaceId(idSpace); // pDbSpace->SetWellId(idWell); //} //OPENOBJ_END(); //pDbSpace->close(); } } else { int iRet = ads_getreal(_T("\n请给出单井汇流面积(平方米)<退出>:"), &nArea); if (iRet != RTNORM) return; // zxl 2013.12.18 add csArea.Format(_T("%.2f"), nArea); for (long i = 0; i < len; i++) { Entity ent = ss[i]; RemoveWellArea(ent); GlobalFunc::WriteXdata(ent, _T("TG-WELLAREA"), csArea); } } // zxl 2013.12.18 del // csArea.Format(_T("%.2f"), nArea); // for(long i=0;iGetInterfaceNum(); i++) { CString s = pWell->GetWellName(); CPipeInterface face; idWell = pWell->id(); face = pWell->GetInterface(i); CDbPipe *pPipe = NULL; acdbOpenObject(pPipe, face.m_idPipe, AcDb::kForRead); if (pPipe != NULL) { if (pPipe->GetNode(0) == idWell) { id = pPipe->GetNode(1); } else { id = pPipe->GetNode(0); } acdbOpenObject(pEnt, id, AcDb::kForRead); if (pEnt) { CString sLayer = pEnt->layer(); if (sLayer.Compare(LAY_TWT_GULLY) == 0) { bRet = true; } pEnt->close(); } pPipe->close(); } } return bRet; } void GetWellColor(std::map &mapColor, AcDbObjectId id, int iColor) { mapColor.insert(std::make_pair(id, iColor)); } int SetWellColor(AcDbObjectId id, std::map mapColor) { std::map::iterator it; for (it = mapColor.begin(); it != mapColor.end(); it++) { if ((*it).first == id) { return (*it).second; } } return -1; } int GetWellTextColor(AecXDbWell *pWell) { int iColor = -1; pWell->layerId(); AcDbObjectId id = pWell->GetLabelLayer(); iColor = GlobalFunc::GetLayerColor(id); if (iColor < 0) { } return iColor; } void RainWellAreaCmd() { // CString csAreaLayer = _T("TWT_汇流面积"); // 8.0发行之前要修改过来 // zxl 2012.03.30 add RBList rbMask(RTDXF0, _T("AEC_ZT_WELL"), 8, LAY_WELL_RAIN, NULL); PickSet ssAllWall(SS_FREE); ssAllWall.Get(_T("X"), NULL, NULL, rbMask); CString sWallName, sArea; AcDbObjectId id; std::map mapColor; for (long l = 0; l < ssAllWall.Length(); l++) { Entity ent = ssAllWall[l]; XPoint ptLoc; double nScale(1), nEle(0); acdbGetObjectId(id, ent); sArea = GlobalFunc::ReadXdata(ent, _T("TG-WELLAREA")); OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { if (pEquip->visibility() != AcDb::kInvisible) { if (Acad::eOk == pEquip->upgradeOpen()) { pEquip->SetUpdatable(false); sWallName = pEquip->GetWellName(); if (!sArea.IsEmpty()) { sWallName += _T("("); sWallName += sArea; sWallName += _T(")"); pEquip->SetWellName(sWallName); } else { int iColor = GetWellTextColor(pEquip); GetWellColor(mapColor, id, pEquip->colorIndex()); if (Well2Gully(pEquip)) { if (iColor == 1) { pEquip->setColorIndex(2); } else { pEquip->setColorIndex(1); } } else { if (iColor == 3) { pEquip->setColorIndex(6); } else { pEquip->setColorIndex(3); } } } pEquip->downgradeOpen(); } } } OPENOBJ_END(); } GlobalFunc::UpdateGraphic(ssAllWall); // zxl 2012.03.30 modify RainWellArea(); // zxl 2012.03.30 add for (long j = 0; j < ssAllWall.Length(); j++) { Entity ent = ssAllWall[j]; acdbGetObjectId(id, ent); OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { if (pEquip->visibility() != AcDb::kInvisible) { if (Acad::eOk == pEquip->upgradeOpen()) { sWallName = pEquip->GetWellName(); if (sWallName.Find(_T("(")) > 0) { sWallName = sWallName.Left(sWallName.Find(_T("("))); pEquip->SetWellName(sWallName); } pEquip->setColorIndex(SetWellColor(id, mapColor)); pEquip->SetUpdatable(false); pEquip->downgradeOpen(); } } } OPENOBJ_END(); } GlobalFunc::UpdateGraphic(ssAllWall); } //*************************************************************************************************** // 水表井 //*************************************************************************************************** void InsWaterMeter() { CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp; if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000311"), xsTmp) != RTNORM) return; XPoint ptIns; InitLayer(LAY_TWT_OUT); xg_getvar(_T("VIEWCTR"), ptIns); ptIns = GlobalFunc::Ucs2Wcs(ptIns); g_Option::instance().g_csInsBlkName = xsTmp; BOOL bRotate(FALSE), bMirror(FALSE); TBlockEdJig jig(g_Option::instance().g_csInsBlkName, ptIns, 1); int nOsMode = 0; double nScale = 3 * GlobalFunc::DocGetPScale() / 100; if (g_Option::instance().g_bEquipByScale) nScale = 3; nOsMode |= OS_INT | OS_NEA | OS_MID; XPushVar vOsMode(_T("OSMODE"), nOsMode); while (1) { jig.m_nSacle = nScale; jig.m_bReversal = bMirror; CString csPrompt, csRotate; if (bRotate) csRotate = _T("不旋转"); else csRotate = _T("旋转"); csPrompt.Format(_T("\n请点取水表井插入点[放大(E)/缩小(D)/左右翻转(F)/%s(R)]<完成>:"), csRotate); jig.SetPrompt(csPrompt); jig.SetKeyword(_T("E D F R")); int nKeyIndex = 0; int ret = jig.DoIt(&nKeyIndex); if (ret == RTKWORD) { if (nKeyIndex == 0) nScale += 0.5; else if (nKeyIndex == 1 && jig.m_nSacle > 0.5) nScale -= 0.5; else if (nKeyIndex == 2) bMirror = !bMirror; else if (nKeyIndex == 3) bRotate = !bRotate; continue; } else if (ret != RTNORM) break; ptIns = jig.GetPickPoint(); CDbEquipment *pEquip = new CDbEquipment; pEquip->SetBlock2d(GlobalFunc::GetBlockIdFromString(g_Option::instance().g_csInsBlkName)); pEquip->SetHidePipe(TRUE); pEquip->SetScale(nScale); pEquip->MirrorByY(bMirror); pEquip->setLayer(LAY_TWT_OUT); pEquip->setColor(AcCmColor()); //随层 pEquip->SetLocation(ptIns); AcDbObjectId id = GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue); if (bRotate) { Entity entLast; entLast.GetLast(); double nRotate(0); entLast.Rotate(ptIns, &nRotate); } } } //*************************************************************************************************** // 平面树 //*************************************************************************************************** BOOL InsertBlock2(const TCHAR*szBlkName, XPoint pt, double nScale, double Rotation, const TCHAR* szLayer) { InitBlock(szBlkName); AcDbBlockTable *pBlockTable; AcDbBlockTableRecord* pRecord; acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead); if ((pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead)) != Acad::eOk) return FALSE; pBlockTable->close(); AcDbObjectId BlockId; BlockId = pRecord->objectId(); pRecord->close(); AcDbBlockReference *pBlkRef = new AcDbBlockReference; pBlkRef->setBlockTableRecord(BlockId); pBlkRef->setRotation(Rotation); pBlkRef->setPosition(AcGePoint3d(pt)); pBlkRef->setScaleFactors(nScale); pBlkRef->setLayer(szLayer); GlobalFunc::PostToDb(pBlkRef); pBlkRef->close(); return TRUE; } void DrawTreeCmd() { int nOsMode = 0; xg_getvar(_T("OSMODE"), &nOsMode); nOsMode &= ~0x4000; nOsMode |= OS_INT | OS_NEA; XPushVar vOsMode(_T("OSMODE"), nOsMode); XPoint ptStart, ptEnd; Entity entSel; RBList rbMask = ads_buildlist(-4, _T(""), -4, _T(""), -4, _T("or>"), NULL); PickSet ss(SS_FREE); ss.Get(_T("X"), NULL, NULL, rbMask); int ret = -1; CString csInsBlkName; if (ss.Length() > 0) ret = GlobalFunc::SelectEntity(_T("\n请选择图中已有树作为样本树<从图库中选取>"), entSel, rbMask); if (ret != RTNORM) { XPoint ptIns; ads_prompt(_T("\n请在图库中选择一树<确定>")); xg_getvar(_T("VIEWCTR"), ptIns); CPoint ptDwgView; int cvport = 0; VERIFY(xg_getvar(_T("CVPORT"), &cvport) == RTNORM); acedCoordFromWorldToPixel(cvport, ptIns, ptDwgView); acedGetAcadDwgView()->ClientToScreen(&ptDwgView); CTemporaryResourceOverride vTemp; CSelectBlkDlg dlg; dlg.m_staticSlide.m_iRowNum = 4; dlg.m_staticSlide.m_iColNum = 4; dlg.m_csTkName = _T("out"); dlg.m_csType = _T("树"); dlg.m_ptBase = ptDwgView; if (dlg.DoModal() == IDOK) { CString csRet = dlg.m_staticSlide.m_csCurRecord; XString xsTKName, xsRocord; GlobalFunc::SplitSlbName(csRet, xsTKName, xsRocord); XString xsBlk; GlobalFunc::LoadDwbBlock(xsTKName, xsRocord, xsBlk); csInsBlkName = xsBlk; } else return; } else { TCHAR szBlkName[256]; entSel.GetData(2, szBlkName); csInsBlkName = szBlkName; } InitLayer(LAY_TWT_TREE); GlobalFunc::PushVarStr clayer(_T("CLAYER"), LAY_TWT_TREE); if (ads_getpoint(NULL, _T("\n请输入起始点<退出>:"), ptStart) != RTNORM) { return; } double nScale(1), nDist(120); nScale = nScale / 100 * GlobalFunc::DocGetPScale(); nDist = nDist * GlobalFunc::DocGetPScale(); GlobalFunc::InsertBlock((const TCHAR*)csInsBlkName, asPnt3d(ptStart), nScale, nScale, 0, LAY_TWT_TREE); double nOld = g_Option::instance().g_nSprinklerRadius; int iMode = 1; while (1) { g_Option::instance().g_nSprinklerRadius = 1500; TWellJig jig(ptStart); jig.SetKeyword(_T("F S L D")); CString csPrompt; if (iMode == 0) { jig.m_nDist = nDist; } else if (iMode == 2) { jig.SetDist2(nDist); } csPrompt.Format(_T("\n请点取插入点[等距布置(F)/任意布置(S)/两点均布(L)/间距(D)]<退出>:")); jig.SetPrompt(csPrompt); // jig.SetStartPoint(ptStart); int nKeyIndex; int nRetCode = jig.DoIt(&nKeyIndex); if (nRetCode == RTKWORD) { if (nKeyIndex == 0) { iMode = 0; } else if (nKeyIndex == 1) { iMode = 1; } else if (nKeyIndex == 2) { iMode = 2; } else if (nKeyIndex == 3) { ads_getdist(ptStart, _T("\n请输入树的间距<任意>:"), &nDist); } continue; } else if (nRetCode != RTNORM) break; XLine line(ptStart, jig.GetPickPoint(), 1); ptStart = jig.GetPickPoint(); if (iMode == 2) { XCurveSegment seg; seg = line; XPointList lstPt; GlobalFunc::GetPointList(seg, nDist, lstPt); double nRotate = line.Direction(); int len = lstPt.Length(); for (int i = 0; i < len; i++) { XPoint ptIns = *lstPt[i]; SHads_command(RTSTR, _T(".INSERT"), RTSTR, (const TCHAR*)csInsBlkName, RT3DPOINT, &ptIns, RTREAL, nScale, RTREAL, nScale, RTREAL, nRotate, NULL); ptStart = ptIns; } } else GlobalFunc::InsertBlock((const TCHAR*)csInsBlkName, asPnt3d(ptStart), nScale, nScale, 0, LAY_TWT_TREE); } g_Option::instance().g_nSprinklerRadius = nOld; SHads_command(RTNONE); return; } //*************************************************************************************************** // 改管高程 //*************************************************************************************************** //2007-11-14 修改管的标高,可以连带修改前后管的高程 void ModifyPipeEle() { RBList rbMask(RTDXF0, _T("AEC_ZT_PIPE"), 8, GetLayerNames(_T("管线")), NULL); Entity entMainPipe; if (GlobalFunc::SelectEntity(_T("\n请选择要修改高程的管线(注意选择点):<退出>"), entMainPipe, rbMask) != RTNORM) return; } //*************************************************************************************************** // 采集高程 //*************************************************************************************************** // 判断实体是否为数据源对象 cet 2011.12.2 add bool IsNeedDataObj(Entity &ent) { AcDbObjectId id; acdbGetObjectId(id, ent); AcDbEntity *pEnt = NULL; acdbOpenObject(pEnt, id, AcDb::kForRead); CString s = pEnt->isA()->dxfName(); if (ent.Is(_T("TEXT")) || ent.Is(_T("AEC_ZT_TEXT")) || ent.Is(_T("POINT")) || ent.Is(_T("CIRCLE")) || ent.Is(_T("INSERT")) || ent.Is(_T("AEC_ZT_ELEVATION"))) { return true; } return false; } // 从外部参照中获取数据源 cet 2011.12.2 add bool GetDataFromExternalBlock(Entity &ent, Entity &entSel) { // 从外部参照中选择数据源 ads_name adsent; ads_point ptResult; ads_matrix xformres; resbuf* refstkres = NULL; int result = acedNEntSelP(_T("\n外部参照!请继续选择外部参照上的数据源<退出>: "), adsent, ptResult, 0, xformres, &refstkres); if (refstkres != NULL) ads_relrb(refstkres); if (result == RTNORM) { entSel = adsent; } else { return false; } // 判断数据源是否是需要的实体数据来源, 不是数据源entsel设置为空 if (IsNeedDataObj(entSel)) { return true; } else { Entity entNull; entSel = entNull; return false; } } // 获得外部参照的转换矩阵 bool GetBlkMat(Entity &ent, AcGeMatrix3d &mat) { AcDbBlockReference *pRef = NULL; AcDbObjectId idRef; acdbGetObjectId(idRef, ent); acdbOpenObject(pRef, idRef, AcDb::kForRead); if (pRef) { mat = pRef->blockTransform(); pRef->close(); return true; } return false; } //2008-02-28 谢真 void CollectElevWell() { RBList rbMask(RTDXF0, _T("INSERT,TEXT,POINT,CIRCLE,AEC_DANHTEXT,AEC_BIAOGAOBIAOZHU"), NULL); Entity entInsert; if (GlobalFunc::SelectEntity(_T("\n请选择要配置的数据源对象:<退出>"), entInsert, rbMask) != RTNORM) return; // cet 2011.12.1 add 支持从外部参照中获取数据源 bool bExternalBlock = false; Entity entSel; if (GlobalFunc::IsExternalBlock(entInsert)) { if (!GetDataFromExternalBlock(entInsert, entSel)) { if (!entSel) { acutPrintf(_T("\n外部参照中选择数据源错误!")); } return; } bExternalBlock = true; } // 获得外部参照转换矩阵 AcGeMatrix3d mat; if (bExternalBlock && !GetBlkMat(entInsert, mat)) { return; } CTemporaryResourceOverride vTemp; CSetDataSourceDlg sourceDlg; sourceDlg.SetSelEntity(entInsert); // cet 2011.12.2 add if (bExternalBlock) { sourceDlg.SetSelEntity(entSel); sourceDlg.SetExternalBlk(entInsert); sourceDlg.SetExternalBlk(bExternalBlock); sourceDlg.SetExnternalBlkMat(mat); } CString sTag; double dZValue = 0.0; //图块Z坐标值 if (sourceDlg.DoModal() == IDOK) { PickSet ss(SS_FREE); sourceDlg.GetPickSet(ss); CCollectElevation collect; collect.SetPickSet(ss); // cet 2010.5.17 del // if (sourceDlg.m_nLandForm != 2) // collect.SetCollectObjectCount(5); // else // collect.SetCollectObjectCount(20); collect.SetLandForm(sourceDlg.m_nLandForm); // cet 2011.12.2 add collect.SetExternalBlk(bExternalBlock); collect.SetExnternalBlkMat(mat); CString csPrompt; RBList rbMask = ads_buildlist(-4, _T(""), -4, _T(""), -4, _T("or>"), NULL); PickSet ssAll(SS_FREE); if (GlobalFunc::SelectEntities(_T("\n请选择需要采集高程的井:<退出>"), ssAll, rbMask) != RTNORM) return; // cet 2011.3.25 添加进度条 acedSetStatusBarProgressMeter(_T("计算中..."), 0, ssAll.Length()); for (long j = 0; j < ssAll.Length(); j++) { acedSetStatusBarProgressMeterPos(j); // cet 2011.3.25 添加进度条 Entity ent = ssAll[j]; XPoint ptLoc; double nScale(1), nEle(0); OPENOBJ_BEGIN(ent, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { ptLoc = pEquip->GetLocation(); } OPENOBJ_END(); OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPool, pPump); if (pPump) { ptLoc = pPump->GetLocation(); } OPENOBJ_END(); //获得高程 int nType = sourceDlg.GetDataSourceType(); // cet 2010.4.16 add double dEle = 0.0; bool bRet = true; bRet = collect.GetSelectPointElevation(ptLoc, entInsert, nType, dEle); if (bRet) { //精确到小数点后三位 CString sTmpEl; sTmpEl.Format(_T("%.3f"), dEle); nEle = _tstof(sTmpEl); //设置高程 AcDbObjectId id; if (ent.Is(_T("AEC_ZT_WELL"))) { AecXDbWell *pWell = NULL; acdbGetObjectId(id, ent); acdbOpenObject(pWell, id, AcDb::kForWrite); if (pWell != NULL) { pWell->SetWellEleUp(dEle); pWell->close(); } } else if (ent.Is(_T("AEC_ZT_POOL"))) { CDbPool *pPool = NULL; acdbGetObjectId(id, ent); acdbOpenObject(pPool, id, AcDb::kForWrite); if (pPool != NULL) { pPool->SetGroundEle(nEle); pPool->close(); } } } else { CString strTip = _T("\n出错,无法设置标高!"); acutPrintf(strTip); } } acedRestoreStatusBar(); // cet 2011.3.25 添加进度条 GlobalFunc::UpdateGraphic(ssAll); XPoint ptLow, ptUp; ssAll.GetExtend(ptLow, ptUp); GlobalFunc::AssureInCurrentView_New(ptLow, ptUp); } else { return; } }