//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TAecSpaceWall 类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TAecSpaceWall 定义 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #include "StdAfx.h" #include "TAecSpaceWall.h" #include "TAecSpaceCell.h" #include "TSortWallOnPt.h" #include "TGGiWallVector.h" TDPtrList * TAecSpaceWall::g_pAllWalls = NULL; static TAecSpaceWall *g_pMarkSide = NULL; static int CmpWall(const TGGiWallVector *p1, const void *p2) { const TAecSpaceWall *pp2 = (const TAecSpaceWall *)p2; return (p1->pWall == pp2) ? 0 : 1; } TAecSpaceWall::TAecSpaceWall() : leftSpace(NULL), rightSpace(NULL) { m_pStartNode = m_pEndNode = NULL; } TAecSpaceWall::TAecSpaceWall(const TEntitySet &ent) : TWallData(ent), m_ent(ent), leftSpace(NULL), rightSpace(NULL) { m_pStartNode = m_pEndNode = NULL; } TAecSpaceWall::TAecSpaceWall(const TAecSpaceWall &src) : TWallData(src), leftSpace(NULL), rightSpace(NULL) { m_pStartNode = m_pEndNode = NULL; } AcDbObjectId TAecSpaceWall::GetMyObjectId() const { AcDbObjectId idRet; if (!!m_ent) { acdbGetObjectId(idRet, m_ent.name); } return idRet; } // 功能: 搜索房间 // 参数: // spt--当前向量的起点为, nSide--以spt为起点的相对左(0)右(1) // 返回: RTNORM--Find a Space; RTERROR--当前墙不构成封闭域; RTNONE--第一个墙不封闭 // 注意: 当前已经进栈(Top == Tail()) // 考虑了墙体标高 int TAecSpaceWall::Trival(TSortWallOnPt *spt, int nSide) { if (!g_pCurSpace) { return RTERROR; } TAecSpaceCell &aSpace = *g_pCurSpace; if (ads_usrbrk()) { g_pMarkSide = NULL; return RTCAN; } int nCurSide; TSortWallOnPt *nextPt; if (spt == m_pStartNode) { nextPt = m_pEndNode; nCurSide = nSide; } else { nextPt = m_pStartNode; nCurSide = !nSide; } curSide = nCurSide; //实际 nSide, 查找绝对的curSide TSortWallOnPt *pWallsOnPt = nextPt; if (!pWallsOnPt) { return RTERROR; } TSortWallOnPt &walls = *pWallsOnPt; int len = walls.Length(); TGGiWallVector *pVector = walls.FindNode(this, CmpWall); if (!pVector) { return RTERROR; } int nPos = walls.CurPosition(); int nLen = len; int retFlag = RTERROR; if (nSide == 1) //右侧,查找相对最左边的 { // 查找最左边的有效墙 for (int i = 1; i < len; i++) { int nIndex = i + nPos; if (nIndex >= len) { nIndex -= len; } TAecSpaceWall *nextWall = (TAecSpaceWall *)(walls[nIndex]->pWall); if (!nextWall) { continue; } else if (nextWall == aSpace.Head()) { if (nextPt == aSpace.Head()->m_pStartNode) { return RTNORM; // 找到房间 } else { g_pMarkSide = nextWall; return RTNONE; } } else if (aSpace.Exist(nextWall)) { g_pMarkSide = nextWall; return RTNONE;; } aSpace.Push(nextWall); retFlag = nextWall->Trival(nextPt, nSide); if (retFlag == RTNORM) { return retFlag; } aSpace.Pop(); if (retFlag == RTNONE) { //回退到标记 if (aSpace.Tail() != g_pMarkSide) { return RTNONE; } g_pMarkSide = NULL; //已经到标记 return RTERROR; } else if (retFlag == RTCAN) { return retFlag; } } } else // 左侧,查找相对最右边的 { for (int i = 1; i < len; i++) { int nIndex = nPos - i; if (nIndex < 0) { nIndex += len; } TAecSpaceWall *nextWall = (TAecSpaceWall *)(walls[nIndex]->pWall); if (!nextWall) { continue; } else if (nextWall == aSpace.Head()) { if (nextPt == aSpace.Head()->m_pStartNode) { #ifdef WALLDEBUG adsout << _T("\nFind a space ") << aSpace.index; aSpace.ShowMe(); #endif return RTNORM; } else { g_pMarkSide = nextWall; //回退到标记 return RTNONE; } } else if (aSpace.Exist(nextWall)) { g_pMarkSide = nextWall; //回退到标记 return RTNONE; // Z Modify here on 2001/12/28 } aSpace.Push(nextWall); retFlag = nextWall->Trival(nextPt, nSide); if (retFlag == RTNORM) { return retFlag; } aSpace.Pop(); if (retFlag == RTNONE) { //回退到标记 if (aSpace.Tail() != g_pMarkSide) { return RTNONE; } g_pMarkSide = NULL; //已经到标记 return RTERROR; } else if (retFlag == RTCAN) { return retFlag; } } } return RTERROR; } // 功能: 搜索路径 // 参数: // spt--当前向量的起点为, nSide--以spt为起点的相对左(0)右(1) // 返回: RTNORM--Find a Space; RTERROR--当前墙不构成封闭域; RTNONE--第一个墙不封闭 // 注意: 当前已经进栈(Top == Tail()) // 考虑了墙体标高 int TAecSpaceWall::TrivalTo(const TAecSpaceWall &toWall, TSortWallOnPt *spt, int nSide) { if (!g_pCurSpace) { return RTERROR; } if (this == &toWall) //找到一条路径 { return RTNORM; } TAecSpaceCell &aSpace = *g_pCurSpace; if (ads_usrbrk()) { return RTCAN; } int nCurSide; TSortWallOnPt *nextPt; if (spt == m_pStartNode) { nextPt = m_pEndNode; nCurSide = nSide; } else { nextPt = m_pStartNode; nCurSide = !nSide; } curSide = nCurSide; //实际 nSide,查找绝对的curSide TSortWallOnPt *pWallsOnPt = nextPt; if (!pWallsOnPt) { return RTERROR; } TSortWallOnPt &walls = *pWallsOnPt; int len = walls.Length(); TGGiWallVector *pVector = walls.FindNode(this, CmpWall); if (!pVector) { return RTERROR; } int nPos = walls.CurPosition(); int nLen = len; int retFlag = RTERROR; if (nSide == 1) { for (int i = 1; i < len; i++) { int nIndex = i + nPos; if (nIndex >= len) { nIndex -= len; } TAecSpaceWall *nextWall = (TAecSpaceWall *)(walls[nIndex]->pWall); if (!nextWall) { adsout << _T("\nFind bad wall"); continue; } else if (nextWall == aSpace.Head()) { continue; } else if (aSpace.Exist(nextWall)) { continue; } aSpace.Push(nextWall); retFlag = nextWall->TrivalTo(toWall, nextPt, nSide); if (retFlag == RTNORM || retFlag == RTNONE) { return retFlag; } aSpace.Pop(); } } else { for (int i = 1; i < len; i++) { int nIndex = nPos - i; if (nIndex < 0) { nIndex += len; } TAecSpaceWall *nextWall = (TAecSpaceWall *)(walls[nIndex]->pWall); if (!nextWall) { adsout << _T("\nFind bad wall"); continue; } else if (nextWall == aSpace.Head()) { continue; } else if (aSpace.Exist(nextWall)) { continue; } aSpace.Push(nextWall); retFlag = nextWall->TrivalTo(toWall, nextPt, nSide); if (retFlag == RTNORM || retFlag == RTNONE) { return retFlag; } aSpace.Pop(); } } return RTERROR; } AcDbObjectId TAecSpaceWall::GetMyOwnerId()const { AcDbEntity *pEnt = NULL; AcDbObjectId id = AcDbObjectId::kNull; acdbOpenObject(pEnt,GetMyObjectId(),AcDb::kForRead); if (pEnt != NULL) { id = pEnt->ownerId(); pEnt->close(); } return id; }