157 lines
3.9 KiB
C++
157 lines
3.9 KiB
C++
// TPipeGraph.cpp: implementation of the TPipeGraph class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "TPipeGraph.h"
|
|
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
void SearchOneselfNode(AcDbObjectId idNode, TPipeGraph &PipeGraph);
|
|
|
|
|
|
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()
|
|
{
|
|
|
|
}
|