289 lines
8.2 KiB
C++
289 lines
8.2 KiB
C++
// TPipeGraph.cpp: implementation of the TPipeGraph class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "TPipeGraph.h"
|
|
#include "TAPI.h"
|
|
#include <DbWell.h>
|
|
#include "DbSymbolAnnotate.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
void SearchOneselfNode(AcDbObjectId idNode, TPipeGraph &PipeGraph);
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 强改管长
|
|
//***************************************************************************************************
|
|
void SetPipeLength()
|
|
{
|
|
Entity entSel;
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPE"), NULL);
|
|
if(SelectEntity(_T("\n请选择要更改的管线:<退出>"), entSel, rbMask) != RTNORM)
|
|
return;
|
|
CString csText;
|
|
double dLen(0);
|
|
ads_getreal(_T("\n请输入管长<0>:"), &dLen);
|
|
csText.Format(_T("len%.2f"), dLen);
|
|
|
|
OPENOBJ_BEGIN(entSel, AcDb::kForWrite, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
pPipe->SetSpareStr(csText);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 标注流量
|
|
//***************************************************************************************************
|
|
void DimFeedNodeQ()
|
|
{
|
|
Entity entSel;
|
|
RBList rbMask(RTDXF0, _T("ATS_WELL"), NULL);
|
|
if(SelectEntity(_T("\n请选择要标注的给水节点:<退出>"), entSel, rbMask) != RTNORM)
|
|
return;
|
|
double dQ(0);
|
|
double dArrowLen = 5*DocGetPScale();
|
|
AcDbObjectId idTextStyle = InitTextStyle(_T("_TWT_WELL"));
|
|
if(!idTextStyle)
|
|
return;
|
|
CString csText;
|
|
|
|
ads_getreal(_T("\n请输入节点流量<0>:"), &dQ);
|
|
csText.Format(_T("%.2f"), dQ);
|
|
WriteXdata(entSel, _T("TG-FEEDNODE-Q"), csText);
|
|
|
|
XPoint ptStart, ptEnd, ptText;
|
|
OPENOBJ_BEGIN(entSel, AcDb::kForRead, TDbWell, pWell);
|
|
if(pWell){
|
|
ptStart = pWell->GetLocation();
|
|
}
|
|
OPENOBJ_END();
|
|
ads_polar(ptStart, PI/4, dArrowLen, ptEnd);
|
|
ads_polar(ptEnd, PI/4, dArrowLen/2, ptText);
|
|
|
|
|
|
InitLayer(LAY_DIM);
|
|
TDbSymbArrow *pArrow = new TDbSymbArrow;
|
|
XPoly2D poly;
|
|
poly.AppendNode(ptStart);
|
|
poly.AppendNode(ptEnd);
|
|
double nRotateText = ads_angle(ptStart, ptEnd);
|
|
pArrow->SetPoly2D(poly);
|
|
pArrow->SetTextStyleId(idTextStyle);
|
|
pArrow->SetTextHeight(3);
|
|
pArrow->SetTextAlign(TDbSymbArrow::kAtSide);
|
|
pArrow->SetArrowSize(2);
|
|
pArrow->SetText(csText);
|
|
pArrow->SetTextLayerId(InitLayer(LAY_TEXT));
|
|
pArrow->SetTextLocation(ptText);
|
|
pArrow->AddToCSpace(Adesk::kTrue);
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 插给水点
|
|
//***************************************************************************************************
|
|
|
|
void InsertFeedNode()
|
|
{
|
|
PickSet ssAll;
|
|
|
|
XPoint ptTmp1, ptTmp2;
|
|
if(ads_getpoint(NULL, _T("\n请输入第一角点:<退出>"), ptTmp1) != RTNORM)
|
|
return;
|
|
if(ads_getcorner(ptTmp1, _T("\n再点取其对角点<退出>:"), ptTmp2) != RTNORM)
|
|
return;
|
|
Entity entTmp;
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPE"), NULL);
|
|
|
|
ssAll.Get(_T("C"), ptTmp1, ptTmp2, rbMask);
|
|
XPointList lstPt;
|
|
for(long i=0;i<ssAll.Length();i++){
|
|
Entity entTmp = ssAll[i];
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
XPoint ps;
|
|
pPipe->getStartPoint(ps);
|
|
XPoint pe;
|
|
pPipe->getEndPoint(pe);
|
|
lstPt.NewAppend(ps);
|
|
lstPt.NewAppend(pe);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
XString xsTmp;
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
|
|
if(LoadDwbBlock(csDwb, _T("00000389"), xsTmp) != RTNORM) //单蓖
|
|
return;
|
|
|
|
for(int m=0;m<lstPt.Length();m++){
|
|
XPoint ptTmp = *lstPt[m];
|
|
ptTmp.z = 0;
|
|
|
|
TDbWell *pEquip = new TDbWell;
|
|
pEquip->SetBlock2d(GetBlockIdFromString(xsTmp));
|
|
pEquip->SetHidePipe(FALSE);
|
|
pEquip->SetAngle(0);
|
|
pEquip->SetLabelLayer(InitLayer(LAY_WELL_TEXT));
|
|
|
|
pEquip->SetLocation(ptTmp);
|
|
pEquip->SetTextHeight(2);
|
|
pEquip->SetTextStyleId(InitTextStyle(_T("_TWT_WELL")));
|
|
pEquip->SetScale(2);
|
|
pEquip->setLayer(LAY_WELL_FEED);
|
|
pEquip->SetWellEleUp(0);
|
|
pEquip->SetWellEleDown(0);
|
|
pEquip->EnableDrawLabel(FALSE);
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
}
|
|
}
|
|
|
|
BOOL CheckExist(AcDbObjectId id, TPipeGraph &PipeGraph)
|
|
{
|
|
int len1 = PipeGraph.m_lstEdge.Length();
|
|
for(int i=0;i<len1;i++){
|
|
AcDbObjectId idTmp = PipeGraph.m_lstEdge[i]->m_idPipe;
|
|
if(idTmp == id)
|
|
return TRUE;
|
|
}
|
|
|
|
int len2 = PipeGraph.m_lstNode.Length();
|
|
for(i=0;i<len2;i++){
|
|
AcDbObjectId idTmp = PipeGraph.m_lstNode[i]->m_idNode;
|
|
if(idTmp == id)
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL GetExistNode(AcDbObjectId id, TPipeGraph &PipeGraph, TPipeNode *&pNode)
|
|
{
|
|
int len2 = PipeGraph.m_lstNode.Length();
|
|
for(int i=0;i<len2;i++){
|
|
AcDbObjectId idTmp = PipeGraph.m_lstNode[i]->m_idNode;
|
|
if(idTmp == id){
|
|
pNode = PipeGraph.m_lstNode[i];
|
|
return TRUE;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
void SearchOneselfPipe(AcDbObjectId idPipe, TPipeGraph &PipeGraph)
|
|
{
|
|
TPipeEdge *pEdge = new TPipeEdge();
|
|
pEdge->m_idPipe = idPipe;
|
|
pEdge->m_bVisited = TRUE;
|
|
PipeGraph.m_lstEdge.Append(pEdge);
|
|
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
AcDbObjectId nodeId1(NULL), nodeId2(NULL);
|
|
nodeId1 = pPipe->GetNode(0);
|
|
nodeId2 = pPipe->GetNode(1);
|
|
TPipeNode *pNode1 = NULL;
|
|
TPipeNode *pNode2 = NULL;
|
|
|
|
if(!GetExistNode(nodeId1, PipeGraph, pNode1)){
|
|
pNode1 = new TPipeNode();
|
|
pNode1->m_idNode = nodeId1;
|
|
PipeGraph.m_lstNode.Append(pNode1);
|
|
}
|
|
|
|
if(!GetExistNode(nodeId2, PipeGraph, pNode2)){
|
|
pNode2 = new TPipeNode();
|
|
pNode2->m_idNode = nodeId2;
|
|
PipeGraph.m_lstNode.Append(pNode2);
|
|
}
|
|
pEdge->m_pNode1 = pNode1;
|
|
pEdge->m_pNode2 = pNode2;
|
|
pNode1->m_lstEdge.Append(pEdge);
|
|
pNode2->m_lstEdge.Append(pEdge);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
|
|
OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
AcDbObjectId nodeId1(NULL), nodeId2(NULL);
|
|
nodeId1 = pPipe->GetNode(0);
|
|
nodeId2 = pPipe->GetNode(1);
|
|
SearchOneselfNode(nodeId1, PipeGraph);
|
|
SearchOneselfNode(nodeId2, PipeGraph);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
|
|
void SearchOneselfNode(AcDbObjectId idNode, TPipeGraph &PipeGraph)
|
|
{
|
|
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbPipeNode, pNode);
|
|
if(pNode){
|
|
int num = pNode->GetInterfaceNum();
|
|
for(int j=0;j<num;j++){
|
|
TPipeInterface face;
|
|
pNode->GetInterface(j, face);
|
|
AcDbObjectId nextPipeId = face.m_idPipe;
|
|
if(!CheckExist(nextPipeId, PipeGraph))
|
|
SearchOneselfPipe(nextPipeId, PipeGraph);
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
|
|
void SearchPipeSys()
|
|
{
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL);
|
|
Entity entSel;
|
|
if(SelectEntity(_T("\n请拾取系统上的管线<退出>:"), entSel, rbMask)!=RTNORM)
|
|
return;
|
|
AcDbObjectId idPipe;
|
|
acdbGetObjectId(idPipe, entSel);
|
|
|
|
TPipeGraph PipeGraph;
|
|
SearchOneselfPipe(idPipe, PipeGraph);
|
|
int len2 = PipeGraph.m_lstEdge.Length();
|
|
int len1 = PipeGraph.m_lstNode.Length();
|
|
PickSet ss(SS_FREE);
|
|
for(int i=0;i<len2;i++){
|
|
AcDbObjectId idTmp = PipeGraph.m_lstEdge[i]->m_idPipe;
|
|
ss += idTmp;
|
|
}
|
|
ss.Redraw(3);
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
TPipeNode::TPipeNode()
|
|
{
|
|
m_lstEdge.SetDelFlag(FALSE);
|
|
m_bVisited = FALSE;
|
|
}
|
|
|
|
TPipeEdge::TPipeEdge()
|
|
{
|
|
m_bVisited = FALSE;
|
|
}
|
|
|
|
TPipeGraph::TPipeGraph()
|
|
{
|
|
|
|
}
|
|
|
|
TPipeGraph::~TPipeGraph()
|
|
{
|
|
|
|
}
|