/******************************************************************** created: 2004/03/01 created: 1:3:2004 9:59 filename: f:\tg_dev\telecdev\twtkernal\outdoor.cpp file path: f:\tg_dev\telecdev\twtkernal file base: outdoor file ext: cpp author: 沈睿 purpose: 室外 *********************************************************************/ #include "stdafx.h" #include "TAPI.h" #include "twtdef.h" #include "SSearchPipeList.h" #include "EdJigEx.h" #include "teldef.h" #include #include #include #include #include #include #include #include #include #include #include #include "SelectBlkDlg.h" #include "TWellJig.h" #include "SetDataSourceDlg.h" #include "CollectElevation.h" // 双击汇流面积 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); //GEOAPI double g_nAcadVer; //从 TWT_KERNAL 拷贝过来,有时间统一放在public下 //Acad::ErrorStatus AssureInCurrentView_New(const XPoint &ptLow, const XPoint &ptUp) //{ // XPoint lowCorner, upCorner; // AT_ScrCorner(lowCorner, upCorner); // XPoint pt1=ptLow, pt2=ptUp; // pt1.z=pt2.z=lowCorner.z; // XPoint ptMin=Min(pt1, lowCorner), ptMax=Max(pt2, upCorner); // Acad::ErrorStatus es=Acad::eNotApplicable; // if(ptMin!=lowCorner || ptMax!=upCorner) // { //点不在屏幕当前视图之内 // // //2004下UCS, AssureInCurrentView运行特别慢 2009-8-12 sr // BOOL bIsUcs = FALSE; // XPoint ptUcsLow = Wcs2Ucs(ptLow); // XPoint ptUcsUp = Wcs2Ucs(ptUp); // if(ptUcsLow != ptLow && ptUcsUp != ptUp) // bIsUcs = TRUE; // // if(g_nAcadVer>15.0001 && g_nAcadVer<16.01 && bIsUcs) // SHads_command(RTSTR, _T("ZOOM"), RTSTR, _T("W"), RT3DPOINT, &ptUcsLow, RT3DPOINT, &ptUcsUp, NULL); // else // AssureInCurrentView(ptLow, ptUp); // // // } // return es; //} 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; 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; 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())>_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); } } 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; 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=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 { adsout << _T("\n无效的选择!"); goto LAB_RESELECT; } } } } else if(nCode==RTNORM) { ptStart=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("ATS_PIPE"))){ pListAll->m_iType = 0; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, 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 = GetPipeGradient(ent); GetAllPipeAndNodeByPipe(id, idFront, ss); } else if(ent.Is(_T("ATS_POOL"))){ //2009-4-3 池改用单独对象实现 OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPool, pEquip); if(pEquip){ pListAll->m_nDang = pEquip->GetGroundEle(); } OPENOBJ_END(); pListAll->m_iType = 4; pListAll->m_csName = _T("HC"); GetAllPipeAndNodeByNode(id, idFront, ss); } else{ OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWell, pEquip); if(pEquip){ pListAll->m_nDang = pEquip->GetWellEleUp(); //井地面标高 pListAll->m_csName = pEquip->GetWellName(); //井编号 pListAll->m_iType = 3; AcDbObjectId idBlk = pEquip->GetBlock2d(); CString csBlkName = 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(); GetAllPipeAndNodeByNode(id, idFront, ss); } ss -= ent; PickSet ssDel(SS_FREE); XPoint ptFront; OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeNode, pNode); if(pNode){ ptFront = pNode->GetLocation(); ptFront.z = 0; } OPENOBJ_END(); for(long j=0;j 0){ return FALSE; } if(entTmp.Is(_T("ATS_PIPE"))){ OPENOBJ_BEGIN(entTmp, AcDb::kForRead, TDbPipe, 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("ATS_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 != _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;im_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("ATS_PIPE"))){ pListAll->m_iType = 0; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ pListAll->m_nLength = pPipe->Length(); pListAll->m_iDn = (int)pPipe->GetDnDiameter(); } OPENOBJ_END(); pListAll->m_nI = GetPipeGradient(ent); } else{ OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWell, pEquip); if(pEquip){ pListAll->m_nDang = pEquip->GetWellEleUp(); //井地面标高 pListAll->m_csName = pEquip->GetWellName(); //井编号 pListAll->m_iType = 3; AcDbObjectId idBlk = pEquip->GetBlock2d(); CString csBlkName = 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; adsout << _T("\n2管线相交之处缺少井!"); //AfxMessageBox(_T("2管线相交之处缺少井!")); //return FALSE; } OPENOBJ_END(); } long len = pListAll->m_lstNode.Length(); for(long i=0;im_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;im_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, TDbPipeNode, pNode); if(pNode){ ptFront = pNode->GetLocation(); } OPENOBJ_END(); } OPENOBJ_BEGIN(pListNew->m_ID, AcDb::kForWrite, TDbPipe, 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;im_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(!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, TDbEquipment, pEquip); if(pEquip){ AcDbObjectId idRec = pEquip->GetBlock2d(); if(_tcsicmp(GetBlkNameById(idRec), _T("$TwtSys$00000336")) == 0) bIsRectWell = TRUE; } OPENOBJ_END(); CString csWellRadius = 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, TDbEquipment, 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) { TDbPool *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(!DocGetMeterUnitDraw()) // pList->m_nLength = pList->m_nLength/1000; lstWellSys.Append(pList); BOOL bRet = TRUE; long len = pListAll->m_lstNode.Length(); for(long i=0;im_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){ adsout << _T("\n所输入起始井或终止井的编号不存在!"); return; } CString csBase(szText1); CString csFinish(szText2); while(1){ CString csTmp = PlusString(csBase, 1, TRUE); if(csTmp == csFinish){ adsout << _T("\n没有漏井!"); return; } idx1 = lstWellName.Index(csTmp, 0); CString csPrompt; csPrompt.Format(_T("\n%s井不存在!"), csTmp); if(idx1 < 0){ adsout << (const TCHAR*)csPrompt; return; } csBase = csTmp; } } void FindWell() { TCHAR szText[256]; RBList rbMask(RTDXF0, _T("ATS_WELL"), NULL); PickSet ss(SS_FREE); ss.Get(_T("X"), NULL, NULL, rbMask); long len = ss.Length(); XStringList lstWellName, lstRepeat; for(long i=0;iIsDrawLabel()) 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:"), szText) != RTNORM){ FindMissWell(lstWellName); return; } if(_tcsicmp(szText, _T("")) == 0){ FindMissWell(lstWellName); return; } int count = 0; PickSet ssWell(SS_FREE); for(i=0;iIsDrawLabel()) 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) adsout << _T("\n没有发现该编号的井!"); else if(count > 1){ adsout << _T("\n发现多个重名的井!"); AssureInCurrentView(ptLow, ptUp); } else{ adsout << _T("\n已经成功发现!该井位于屏幕中心黄叉处。"); arxZoomTo(ptCen, 100*DocGetPScale(), 100*DocGetPScale()); } for(i=0;i"), entMain, rbMask) != RTNORM) return; AcDbObjectId id = NULL; OPENOBJ_BEGIN(entMain, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ id = pPipe->GetNode(0); OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWell, pEquip); if(!pEquip){ adsout << _T("\n请选择室外连井的管线!"); return; } OPENOBJ_END(); } OPENOBJ_END(); TCHAR szLay[256]; entMain.GetData(8, szLay); RBList rbMask2(RTDXF0, _T("ATS_PIPE"), 8, szLay, NULL); if(SelectEntities(_T("\n请选择出户管<退出>"), ss, rbMask2) != RTNORM) return; XPoint p1, p2, p3, p4, ptTmp3, ptTmp4, ptInter; GetPipePoint(entMain, p1, p2); XLine line1(p1, p2); line1.StartPoint().z = 0; line1.EndPoint().z = 0; AcGePoint3dArray arBreak; for(long i=0;igetClosestPointTo(ptInter, AcGeVector3d::kZAxis, secPt); ptPro=secPt; } OPENOBJ_END(); //判断附近有没有井,规范有间距限制 BOOL bIsTooClose = FALSE; const double dDist = DocGetCurMeterUnitDraw() ? 0.5 : 500;// zxl 2012.08.15 add for(int m=0;m ads_distance(p4, ptInter) ? p3 : p4; OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ pPipe->SetModelType(TPipeSys::kModel); ptTmp4.z = nElevation; ptInter.z = nElevation; pPipe->SetStartPoint(ptTmp4); pPipe->SetEndPoint(ptInter); } OPENOBJ_END(); } // for(long i=0;iStartPoint().z; // AcGeLineSeg3d lineDb1(ptInter.AsAcGePoint3d(), ptTmp.AsAcGePoint3d()); // AcGeLineSeg3d lineDb2(pPipe->StartPoint().AsAcGePoint3d(), pPipe->EndPoint().AsAcGePoint3d()); // AcGePoint3d secPt; // BOOL bRet2 = lineDb1.intersectWith(lineDb2, secPt); // //如果经过埋深计算后的管线,是有坡度的,注意secPt是干管上的交点 // XPoint ptPro=secPt; // // AcDbObjectId idNew = pPipe->BreakAt(ptPro, PS_SNAP); sr remove 在后面统一打断 // // BOOL bIsTooClose = FALSE; // for(int m=0;m ads_distance(p4, ptInter) ? p3 : p4; // OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, 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, TDbPipe, pPipe); if(pPipe){ pPipe->getSplitCurves(arBreak, curves); for(long k=0; k 0) pPipe->erase(); } OPENOBJ_END(); TPipePerDocData *pData = GetCurPipeDocData(); pData->ApplyUpdates(); int len = arBreak.length(); for(int n=0;nclone(); ptInter.z = 0; pNew->SetLocation(ptInter); pNew->SetInsert(ptInter); pNew->SetWellName(_T("")); pNew->SetLabelLocation(XPoint()); pNew->EnableDrawLabel(TRUE, 1.5); pNew->SetDropWell(FALSE); 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, TDbEquipment, pEquip); if(pEquip) { AcDbObjectId id = pEquip->GetBlock2d(); CString sName = GetBlkNameById(id); CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp1; if(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, TDbPipe, 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() { g_ssPickFirst.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("ATS_PIPE"), 8, LAY_PIPE_RAIN, NULL); if(SelectEntities(_T("\n请选择雨水口和就近的雨水井<退出>:"), ss, rbMask) != RTNORM) return; ssAll+=ss; // ssAll.Get(_T("X"), NULL, NULL, rbMask); InitPipeLayer(LAY_PIPE_RAIN); long len = ss.Length(); for(long i=0;iGetBlock2d(); CString csBlkName = 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;iGetInterface(i, face); AcDbObjectId nextPipeId = face.m_idPipe; OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, 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, TDbEquipment, 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;iGetLocation(); } OPENOBJ_END(); double nDist = -1; Entity entNearWellOrGully;//找到雨水口最近的检查井, 或雨水口 XPoint ptNearWellOrGully; //检查井的插入点 for(long j=0;jGetLocation(); } 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;mGetLocation(); } 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); 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, TDbEquipment, pEquip); if(pEquip) { AcDbObjectId id = pEquip->GetBlock2d(); CString sName = GetBlkNameById(id); CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp1; if(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, TDbWell, 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, TDbEquipment, pEquip); if(pEquip){ pEquip->SetLocation(ptCurGullyLoc); // zxl 2013.05.29 add AcDbObjectId id = pEquip->GetBlock2d(); CString sName = GetBlkNameById(id); CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp1; if(LoadDwbBlock(csDwb, _T("00000424"), xsTmp1) != RTNORM) //单蓖 return; bool bSingle = true; if (sName.Compare(xsTmp1) != 0) { bSingle = false; dDn = 300; } } OPENOBJ_END(); TDbPipe *pNewPipe = new TDbPipe; pNewPipe->SetStartPoint(ptCurGullyLoc); pNewPipe->SetEndPoint(ptNearWellOrGully); // cet 2013.1.4 add 自动修正上华带文字线型的逆向管线 CString sLineType = GetLayerLineType(LAY_PIPE_RAIN); if(sLineType.Find(_T("TG")) > -1) { AcGeVector3d vtDir = Wcs2Ucs(ptNearWellOrGully) - 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_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(GetPipeWireLayLineType(LAY_PIPE_RAIN)); pNewPipe->setColor(AcCmColor()); AcDbObjectId id = AddToCurrentSpace(pNewPipe, Adesk::kTrue); if (!bLinkWithGully) { vecPipe.push_back(id); } bLinkWithGully = false; } } ModifyPipeDn(mapEq, vecPipe); } //*************************************************************************************************** // 室外图库 //*************************************************************************************************** void OutLib() { InitLayer(LAY_TWT_OUT); XPushVarStr clayer(_T("CLAYER"), LAY_TWT_OUT); XString sLibFile, sTkw; sLibFile << g_sDwbPath << _T("室外库.TKW"); XString xsTmp = _T("00000001"); InvokeTkwMan(sLibFile, FALSE, xsTmp); } void PoolLib() { InitLayer(LAY_TWT_OUT); XPushVarStr clayer(_T("CLAYER"), LAY_TWT_OUT); XString sLibFile, sTkw; sLibFile << g_sDwbPath << _T("水池库.TKW"); XString xsTmp = _T("00000001"); InvokeTkwMan(sLibFile, FALSE, xsTmp); } //*************************************************************************************************** // 管线交叉检查 //*************************************************************************************************** double GetPipeStartEle(Entity entPipe) { double dUnitMeter = 1000; if(DocGetMeterUnitDraw()) dUnitMeter = 1; OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ AcDbObjectId nodeId1(NULL); double dn = pPipe->GetDnDiameter(); dn = 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(); // OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe); // if(pPipe){ // AcDbObjectId nodeId1(NULL); // TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); // if(dir == TPipeSys::kFromStart) // nodeId1 = pPipe->GetNode(0); // else // nodeId1 = pPipe->GetNode(1); // // OPENOBJ_BEGIN(nodeId1, AcDb::kForRead, TDbEquipment, pEquip); // if(pEquip){ // int num = pEquip->GetInterfaceNum(); // for(int i=0;iGetInterface(i, face); // CString csPipeDownEle = pEquip->GetISysLabel(i); // AcDbObjectId nextPipeId = face.m_idPipe; // if(nextPipeId == pPipe->objectId()){ // double nPipeEle = _tstof(csPipeDownEle); // return nPipeEle; // } // } // } // OPENOBJ_END(); // } // OPENOBJ_END(); return 0; } // cet 2013.1.23 del 移入public // CString GetPipeNameBySys(TPipeSys::SysType sys) // { // CString csRet; // if(sys == TPipeSys::kFeedWater) // csRet = _T("给水"); // else if(sys == TPipeSys::kHeatFeedWater) // csRet = _T("热给水"); // else if(sys == TPipeSys::kHeatBackWater) // csRet = _T("热回水"); // else if(sys == TPipeSys::kDirtWater) // csRet = _T("污水"); // else if(sys == TPipeSys::kUselessWater) // csRet = _T("废水"); // else if(sys == TPipeSys::kRainWater) // csRet = _T("雨水"); // else if(sys == TPipeSys::kUsedWater) // csRet = _T("中水"); // else if(sys == TPipeSys::kFireFighting) // csRet = _T("消防"); // else if(sys == TPipeSys::kSprinkle) // csRet = _T("喷淋"); // else if(sys == TPipeSys::kCoagulate) // csRet = _T("凝结"); // else if(sys == TPipeSys::kDrink) // csRet = _T("直饮"); // else if(sys == TPipeSys::kPressDirt) // csRet = _T("压力污"); // else if(sys == TPipeSys::kPressUseless) // csRet = _T("压力废"); // else if(sys == TPipeSys::kPressRain) // csRet = _T("压力雨"); // else if(sys == TPipeSys::kOther) // csRet = _T("其它管"); // else if(sys == TPipeSys::kCivilFeed) // csRet = _T("市政给水"); // else if(sys == TPipeSys::kCycleFeed) // csRet = _T("循环给水"); // // return csRet; // } double GetPipeThick(Entity& ent) { double dThick = 0.0; TDbPipe *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 = GetPipeOutDByDn(nMat, dDn); dDn1 = dDn1 / 1000; CString strMat = GetPipeMaterialByIdx(nMat); dDn2 = GetPipeDjByDn(strMat, (int)dDn); pPipe->close(); } dThick = (dDn1 - dDn2) / 2; return dThick; } // zxl 2013.10.12 del 交叉检查重写 // void CheckPipeInter2() // { // RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL); // PickSet ss(SS_FREE); // if(SelectEntities(_T("\n请选择检查范围<整张图>:"), ss, rbMask) != RTNORM){ // ss.Get(_T("X"), NULL, NULL, rbMask); // } // // // cet 2013.2.26 add // if (ss.Length() == 0) // { // return; // } // // double dSafeDist(0.01); // if (ads_getreal(_T("\n请给出最小安全距离(m)<两管紧挨才算碰撞>:"), &dSafeDist) == RTCAN) // cet 2013.2.26 modify 支持esc退出 // { // return; // } // // cet 2013.2.26 add 增加标注类型 // int nRet = 0; // static bool bDimOuter = false; // 标注外侧标高 // bool bDimOuterTemp = false; // 记录默认标注类型 // CString sTip; // if (bDimOuter) // { // sTip = _T("\n标注类型[外底与外顶标高(A)/重力流内底与压力流中心标高(B)]:"); // bDimOuterTemp = true; // } // else // { // sTip = _T("\n标注类型[外底与外顶标高(A)/重力流内底与压力流中心标高(B)]:"); // bDimOuterTemp = false; // } // TCHAR szKey[256]; // INITGET_BEG(0,_T("A B")) // nRet = acedGetKword(sTip, szKey); // INITGET_END() // if (nRet == RTNONE) // { // bDimOuter = bDimOuterTemp; // } // else if (nRet == RTNORM) // { // if (szKey[0] == _T('A')) // { // bDimOuter = true; // } // else if (szKey[0] == _T('B')) // { // bDimOuter = false; // } // } // else if (nRet == RTCAN || nRet == RTERROR) // { // return; // } // // BOOL bDim = FALSE; // TCHAR szTmp[32]; // // cet 2013.2.26 modify 支持esc退出 // //ads_getstring(0, _T("\n没有发生碰撞的交叉管线是否标注:"), szTmp); // INITGET_BEG(0, _T("Y N")); // nRet = acedGetKword(_T("\n没有发生碰撞的交叉管线是否标注:"), szTmp); // INITGET_END(); // if (nRet == RTNORM) // { // if (szTmp[0] == _T('Y')) // { // bDim = TRUE; // } // } // else if (nRet == RTCAN || nRet == RTERROR) // { // return; // } // // if(_tcsicmp(szTmp, _T("Y")) == 0) // bDim = TRUE; // double dUnitMeter = 1000; // if(DocGetMeterUnitDraw()) // dUnitMeter = 1; // // XPointList lstPtInt, lstPt1, lstPt2; // double nDist1 = 15*DocGetPScale(); // double nDist2 = 5*DocGetPScale(); // // CRegProperty regProp(GetRegLocation(), _T("TWTConfig")); // regProp.SetTopRootKey(HKEY_CURRENT_USER); // TDbPsConfig *pConfig = GetDwgPsGlobal(AcDb::kForRead); // int iPreWelldDeep = 3; // if (pConfig) // { // iPreWelldDeep = pConfig->GetWellDeepPrecision(); // if(iPreWelldDeep == 99) // iPreWelldDeep = 0; // pConfig->close(); // } // // BOOL bHasInter = TRUE; // for(long i=0;iGetMaterial(); // csMat = GetPipeMaterialByIdx(iMaterial); // sys1 = pPipe->GetSysType(); // if(sys1 == TPipeSys::kDirtWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kOther) // bIsGravityPipe1 = TRUE; // ptStart = pPipe->StartPoint(); // ptEnd = pPipe->EndPoint(); // nDn = pPipe->GetDnDiameter(); // nI = pPipe->GetPipeGradient(); // TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); // if(dir == TPipeSys::kFromStart) // ptWell = ptStart; // else // ptWell = ptEnd; // } // OPENOBJ_END(); // nDn = GetPipeOutDByDn(csMat, (int)nDn); // // ptStart.z = 0; // ptEnd.z = 0; // ptWell.z = 0; // //cet 2012.5.13 modify // //XLine line1(ptStart, ptEnd, 1); // AcDbLine line1(ptStart.AsAcGePoint3d(), ptEnd.AsAcGePoint3d()); // // PickSet ssF(SS_FREE); // struct resbuf *pointlist; // pointlist = ads_buildlist(RTPOINT, &Wcs2Ucs(ptStart), RTPOINT, &Wcs2Ucs(ptEnd), NULL); // ssF.Get(_T("F"), pointlist, NULL, rbMask); // ads_relrb(pointlist); // XPoint ptWell2; // cet 2010.3.18 add // for(long j=0;jGetMaterial(); // csMat2 = GetPipeMaterialByIdx(iMaterial); // // sys2 = pPipe->GetSysType(); // if(sys2 == TPipeSys::kDirtWater || sys2 == TPipeSys::kRainWater || sys2 == TPipeSys::kUselessWater || sys2 == TPipeSys::kOther) // bIsGravityPipe2 = TRUE; // // ptStart = pPipe->StartPoint(); // ptEnd = pPipe->EndPoint(); // nI2 = pPipe->GetPipeGradient(); // nDn2 = pPipe->GetDnDiameter(); // TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); // if(dir == TPipeSys::kFromStart) // ptWell2 = ptStart; // cet 2010.3.18 add // // ptWell = ptStart; // cet 2010.3.18 del // else // ptWell2 = ptEnd; // cet 2010.3.18 add // // ptWell = ptEnd; // cet 2010.3.18 del // // ptWell.z = 0; cet 2010.8.27 del // ptWell2.z = 0; // cet 2010.8.27 add // // double nDist2Well2 = ads_distance(ptInt, ptWell) / dUnitMeter; // cet 2010.3.18 del // double nDist2Well2 = ads_distance(ptInt, ptWell2) / dUnitMeter; // cet 2010.3.18 add // nPipeEle2 = nPipeEle2 - nDist2Well2*nI2; // } // OPENOBJ_END(); // nDn2 = GetPipeOutDByDn(csMat2, (int)nDn2); // XPoint ptTurn; // BOOL bHasInter2=FALSE; // double dPipeEleUp1(0), dPipeEleUp2(0); // if(nPipeEle1 < nPipeEle2){ // dPipeEleUp1 = nPipeEle1 + nDn; // double dDist2Pipe1 = dPipeEleUp1 - nPipeEle2; //底下管子的顶标高和上面管子底标高的距离 // double dDist2Pipe2 = nPipeEle1 - nPipeEle2; //底下管子的底标高和上面管子底标高的距离 // if(fabs(dDist2Pipe1) < dSafeDist || fabs(dDist2Pipe2) < dSafeDist) //1判断2管的距离小于安全距离 // bHasInter2 = TRUE; // else if(nPipeEle2 > nPipeEle1 && nPipeEle2 < dPipeEleUp1) //2判断上面管子的底标高是否在下面管子内 // bHasInter2 = TRUE; // } // else{ // dPipeEleUp2 = nPipeEle2 + nDn2; // double dDist2Pipe1 = dPipeEleUp2 - nPipeEle1; // double dDist2Pipe2 = nPipeEle2 - nPipeEle1; // if(fabs(dDist2Pipe1) < dSafeDist || fabs(dDist2Pipe2) < dSafeDist) // bHasInter2 = TRUE; // else if(nPipeEle1 > nPipeEle2 && nPipeEle1 < dPipeEleUp2) // bHasInter2 = TRUE; // } // // cet 2013.2.26 modify 增加新标注样式 // // if(!bIsGravityPipe1) // // nPipeEle1 += nDn / 2.0; // // else // cet 2010.3.18 add 将原来的底外侧标高改成底内侧标高 // // { // // nPipeEle1 += GetPipeThick(ent); // // } // // if(!bIsGravityPipe2) // // nPipeEle2 += nDn2 / 2.0; // // else // cet 2010.3.18 add 将原来的底外侧标高改成底内侧标高 // // { // // nPipeEle2 += GetPipeThick(entTmp); // // } // if (bDimOuter) // 外底与外顶标高 // { // if (nPipeEle1 < nPipeEle2) // { // nPipeEle1 += nDn; // } // else // { // nPipeEle2 += nDn2; // double dTemp = nPipeEle1; // nPipeEle1 = nPipeEle2; // nPipeEle2 = dTemp; // } // } // else // 重力流内底与压力流中心标高 // { // if(!bIsGravityPipe1) // nPipeEle1 += nDn / 2.0; // else // cet 2010.3.18 add 将原来的底外侧标高改成底内侧标高 // { // nPipeEle1 += GetPipeThick(ent); // } // if(!bIsGravityPipe2) // nPipeEle2 += nDn2 / 2.0; // else // cet 2010.3.18 add 将原来的底外侧标高改成底内侧标高 // { // nPipeEle2 += GetPipeThick(entTmp); // } // } // // if(bDim || bHasInter2){ // ads_polar(ptInt, PI/4, nDist1, ptTurn); // TDbSymbMultiLeader *pLeader = new TDbSymbMultiLeader; // XPointList lstVertexes; // lstVertexes.Append(new XPoint(ptInt)); // pLeader->SetLayoutRotation(Ucs2Wcs(0.0)); // pLeader->SetLeaderVertexes(lstVertexes); // // // 根据埋深精度 设定交叉检查 精度 zxl 2012.08.28 modify // // pLeader->SetText1(XString(_T("%s%.3f"), GetPipeNameBySys(sys2), nPipeEle2)); // // pLeader->SetText2(XString(_T("%s%.3f"), GetPipeNameBySys(sys1), nPipeEle1)); // // CString sText1 = _T(""), sText2 = _T(""); // // cet 2013.2.26 modify 消除-0 // // // 排除掉 -0 的情形 // // if (nPipeEle2 > -0.5 && nPipeEle2 < 0.0) // // { // // nPipeEle2 = 0; // // } // // if (nPipeEle1 > -0.5 && nPipeEle1 < 0.0) // // { // // nPipeEle1 = 0; // // } // if (fabs(nPipeEle1) < 1e-6) // { // nPipeEle1 = fabs(nPipeEle1); // } // if (fabs(nPipeEle2) < 1e-6) // { // nPipeEle2 = fabs(nPipeEle2); // } // // CString sFormat; // sFormat.Format(_T("%%s%%.%df"), iPreWelldDeep); // sText1.Format(sFormat, GetPipeNameBySys(sys2), nPipeEle2); // sText2.Format(sFormat, GetPipeNameBySys(sys1), nPipeEle1); // // pLeader->SetText1(sText1); // pLeader->SetText2(sText2); // // pLeader->SetLeaderPoint(ptTurn); // pLeader->SetArrow(TDbSymbMultiLeader::kNone); // AcDbObjectId idTextStyle = InitTextStyle(g_csTwtDimStyle); // pLeader->SetTextStyleId(idTextStyle); // pLeader->SetTextLayerId(InitLayer(LAY_TEXT)); // pLeader->SetTextHeight(g_nTwtDimHeight); // pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen()+2); // pLeader->AddToCSpace(Adesk::kTrue); // } // // if(bHasInter2) // lstPt1.NewAppend(ptInt); // else // lstPt2.NewAppend(ptInt); // // XPoint p1, p2, p3, p4; // // ads_polar(ptInt, 0, nDist2, p1); // // ads_polar(p1, PI/2, nDist2, p1); // // ads_polar(ptInt, PI, nDist2, p2); // // ads_polar(p2, PI/2, -nDist2, p2); // // ads_grdraw(p1, p2, 1, 0); // // ads_polar(ptInt, PI/2, nDist2, p3); // // ads_polar(p3, PI, nDist2, p3); // // ads_polar(ptInt, PI/2, -nDist2, p4); // // ads_polar(p4, 0, nDist2, p4); // // ads_grdraw(p3, p4, 1, 0); // // } // } // SHads_command(RTNONE); // //2009-8-17 把ads_grdraw从循环中提出来,原因是ACAD2009无法显示 // for(int m=0;m 0) // adsout << _T("\n黄叉表示室外管线存在碰撞!"); // } //*************************************************************************************************** // 污井流量 //*************************************************************************************************** void SetDirtWellQ() { double nQ(0); CString csQ; RBList rbMask(RTDXF0, _T("ATS_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;jGetLocation(); nScale = pEquip->GetScale(); } OPENOBJ_END(); XText text(XString(_T("Q=%s(L/S)"), csQ), ptLoc, g_nTwtDimHeight * DocGetPScale(), g_nDimScale, g_csTwtDimStyle, LAY_CALC_TEXT); text.Draw(); Entity entCir2; entCir2.GetLast(); ssDel += entCir2; } } if(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:"), szText) != RTNORM) return; RBList rbMask(RTDXF0, _T("ATS_WELL"), 8, LAY_WELL_RAIN, NULL); PickSet ss(SS_FREE); if(_tcsicmp(szText, _T("3")) == 0){ Entity ent; if(SelectEntity(_T("\n请选择起点雨水井:<退出>"), ent, rbMask) != RTNORM) return; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWell, pEquip); if(pEquip){ int num = pEquip->GetInterfaceNum(); if(num != 1){ adsout << _T("\n不是起点井!"); return; } } OPENOBJ_END(); ss+=ent; } else{ if(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;im_outline; // RBList rbFence = poly2d.Fence(); // PickSet ss(SS_FREE); // ss.Get(_T("CP"), rbFence, NULL, rbMask); // int len = ss.Length(); // if(len == 1){ // CString csArea; // double nArea = pDbSpace->m_nUseArea; // if(nArea < 1 && DocGetMeterUnitDraw()) // nArea = nArea * 1000000; // csArea.Format(_T("%.2f"), nArea); // WriteXdata(ss[0L], _T("TG-WELLAREA"), csArea); // } // } // OPENOBJ_END(); // } RBList rbMask2(RTDXF0, _T("ATS_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;im_nUseArea; if(nArea < 1 && DocGetMeterUnitDraw()) nArea = nArea * 1000000; csArea.Format(_T("%.2f"), nArea); ads_name name; acdbGetAdsName(name, pDbSpace->GetWellId()); Entity entWell = name; WriteXdata(entWell, _T("TG-WELLAREA"), csArea); } OPENOBJ_END(); } } // zxl 2013.12.18 add void RemoveWellArea(Entity ent) { OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbWell, 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, TDbWell, 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_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, TDbWell, 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) { g_ssPickFirst.Free(); RBList rbMask(RTDXF0, _T("ATS_SPACE"), 8, LAY_CALC_AREA, NULL); Entity entSel; XPoint ptPick; if (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 = Ucs2Wcs(ptPick); TADSGePoint3d _pt1(Wcs2Ucs(ptPick)); int nRet = SHads_command(RTSTR, _T("COPY"), RTPICKS, (TLong_ptr *)ss, RTSTR, _T(""), RT3DPOINT, &_pt1, RTSTR, PAUSE, 0); Entity ent; ent.GetLast(); ReNewWellArea(entWell, ent); } } bool CheckWellArea(Entity entWell) { g_ssPickFirst.Free(); OPENOBJ_BEGIN(entWell, AcDb::kForRead, TDbWell, 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, TDbWell, 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; g_ssPickFirst.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)); TADSGePoint3d _pt1(Wcs2Ucs(pt)); rbFence.Append(acutBuildList(RTPOINT,&_pt1, NULL)); } PickSet ss(SS_FREE); RBList rbMask(RTDXF0, _T("ATS_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("ATS_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("ATS_WELL"), 8, LAY_WELL_RAIN, NULL); RBList rbMask2(RTDXF0, _T("ATS_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;jSetHighlight(TRUE); } OPENOBJ_END(); } int nRet; TCHAR cKey = _T('\0'); INITGET_BEG(0, _T("G ")); nRet = SelectEntities(_T("\n请选择雨水井[关联存在的汇流面积与井(G)]:<退出>"), ss, rbMask, _T("G "), cKey); INITGET_END(); if (nRet == RTKWORD && cKey==_T('G')) { g_ssPickFirst.Free(); RBList rbMask3 = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); PickSet ssWellAndArea(SS_FREE); if(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;iGetLocation(); 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(!DocGetMeterUnitDraw()) nArea = _AS_SQMETER(poly2d.Area()); else nArea = poly2d.Area(); 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_csDimWellStyle)); pDbSpace->SetTextHeight(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, TDbWell, 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;iGetInterfaceNum(); i++) { CString s = pWell->GetWellName(); TPipeInterface face; idWell = pWell->id(); face = pWell->GetInterface(i); TDbPipe *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(TDbWell *pWell) { int iColor = -1; pWell->layerId(); AcDbObjectId id = pWell->GetLabelLayer(); iColor = GetLayerColor(id); if (iColor < 0) { } return iColor; } void RainWellAreaCmd() { // CString csAreaLayer = _T("TWT_汇流面积"); // 8.0发行之前要修改过来 // zxl 2012.03.30 add RBList rbMask(RTDXF0, _T("ATS_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;lvisibility() != 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(); } UpdateGraphic(ssAllWall); // zxl 2012.03.30 modify RainWellArea(); // zxl 2012.03.30 add for(long j=0;jvisibility() != 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(); } UpdateGraphic(ssAllWall); } //*************************************************************************************************** // 水表井 //*************************************************************************************************** void InsWaterMeter() { CString csDwb = g_csDwbPath + _T("TwtSys"); XString xsTmp; if(LoadDwbBlock(csDwb, _T("00000311"), xsTmp) != RTNORM) return; XPoint ptIns; InitLayer(LAY_TWT_OUT); xg_getvar(_T("VIEWCTR"), ptIns); ptIns = Ucs2Wcs(ptIns); g_csInsBlkName = xsTmp; BOOL bRotate(FALSE), bMirror(FALSE); TBlockEdJig jig(g_csInsBlkName, ptIns, 1); int nOsMode=0; double nScale = 3*DocGetPScale()/100; if(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(); TDbEquipment *pEquip = new TDbEquipment; pEquip->SetBlock2d(GetBlkIdByName(g_csInsBlkName)); pEquip->SetHidePipe(TRUE); pEquip->SetScale(nScale); pEquip->MirrorByY(bMirror); pEquip->setLayer(LAY_TWT_OUT); pEquip->setColor(AcCmColor()); //随层 pEquip->SetLocation(ptIns); AcDbObjectId id = 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); 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 = 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; SplitSlbName(csRet, xsTKName, xsRocord); XString xsBlk; LoadDwbBlock(xsTKName, xsRocord, xsBlk); csInsBlkName = xsBlk; } else return; } else{ TCHAR szBlkName[256]; entSel.GetData(2, szBlkName); csInsBlkName = szBlkName; } InitLayer(LAY_TWT_TREE); XPushVarStr clayer(_T("CLAYER"), LAY_TWT_TREE); if(ads_getpoint(NULL, _T("\n请输入起始点<退出>:"), ptStart) != RTNORM){ return; } double nScale(1), nDist(120); nScale = nScale/100*DocGetPScale(); nDist = nDist * DocGetPScale(); InsertBlock((const TCHAR*)csInsBlkName, asPnt3d(ptStart), nScale, nScale, 0, LAY_TWT_TREE); double nOld = g_nSprinklerRadius; int iMode = 1; while(1){ 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; GetPointList(seg, nDist, lstPt); double nRotate = line.Direction(); int len = lstPt.Length(); for(int i=0;i"), 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("ATS_TEXT")) || ent.Is(_T("POINT")) || ent.Is(_T("CIRCLE")) || ent.Is(_T("INSERT")) || ent.Is(_T("ATS_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,ATS_TEXT,ATS_ELEVATION"), NULL); Entity entInsert; if(SelectEntity(_T("\n请选择要配置的数据源对象:<退出>"), entInsert, rbMask) != RTNORM) return; // cet 2011.12.1 add 支持从外部参照中获取数据源 bool bExternalBlock = false; Entity entSel; if (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(SelectEntities(_T("\n请选择需要采集高程的井:<退出>"), ssAll, rbMask) != RTNORM) return; // cet 2011.3.25 添加进度条 acedSetStatusBarProgressMeter(_T("计算中..."), 0, ssAll.Length()); for(long j=0;jGetLocation(); } OPENOBJ_END(); OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPool, pPump); if(pPump){ ptLoc = pPump->GetLocation(); } OPENOBJ_END(); //获得高程 int nType = sourceDlg.GetDataSourceType(); // cet 2010.4.16 del 更改算法 // switch(nType) // { // case 0: // case 1: // case 2: // case 3: // case 5: // nEle = collect.GetSelectPointElevation(ptLoc,entInsert,nType); // break; // case 4: // //图块属性值 // if (!collect.GetTextTag(sTag,entInsert)) // { // AfxMessageBox(_T("图块存在多个属性字或图块不存在!")); // return; // } // else // { // nEle = collect.GetSelectPointElevation(ptLoc,entInsert,nType,sTag); // } // break; // default: // break; // } // // //精确到小数点后三位 // CString sTmpEl; // sTmpEl.Format(_T("%.3f"),nEle); // nEle = _tstof(sTmpEl); // //设置高程 // OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbWell, pEquip); // if(pEquip) // { // pEquip->SetWellEleUp(nEle); // } // OPENOBJ_END(); // if(ent.Is(_T("ATS_POOL"))){ // OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPool, pPool); // if(pPool){ // pPool->SetGroundEle(nEle); // } // OPENOBJ_END(); // } // 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("ATS_WELL"))) { TDbWell *pWell = NULL; acdbGetObjectId(id, ent); acdbOpenObject(pWell, id, AcDb::kForWrite); if (pWell != NULL) { pWell->SetWellEleUp(dEle); pWell->close(); } } else if (ent.Is(_T("ATS_POOL"))) { TDbPool *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 添加进度条 UpdateGraphic(ssAll); XPoint ptLow,ptUp; ssAll.GetExtend(ptLow,ptUp); AssureInCurrentView_New(ptLow,ptUp); } else { return; } }