//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TPtNode.cpp // = Version : ver2.0 // = Author : xlc // = CreateDate : 2002-09-09 // = Description: ÀàµÄ¶¨Òå // = Maintainers: // //-----------------------------------------------------------------------------+ #include "StdAfx.h" #include "TPtNode.h" #include "TPtList.h" TPtNode::TPtNode() : nextA(NULL),nextB(NULL),preA(NULL),preB(NULL),paA(0),paB(0), pRefA(NULL),pRefB(NULL),pRefC(NULL) { } TPtNode::TPtNode(const TGPoint&pt,int flag) : TWFlag(flag),TGPoint(pt), nextA(NULL),nextB(NULL),preA(NULL),preB(NULL),paA(0),paB(0), pRefA(NULL),pRefB(NULL),pRefC(NULL) { } TPtNode::~TPtNode() { } TPtNode* TPtNode::PreA()const { return preA; } TPtNode* TPtNode::PreB()const { return preB; } TPtNode* TPtNode::NextA()const { return nextA; } TPtNode* TPtNode::NextB()const { return nextB; } void TPtNode::CNNextA(TPtNode*p) { nextA = p; p->preA = this; } void TPtNode::CNNextB(TPtNode*p) { nextB = p; p->preB = this; } double TPtNode::PaA()const { return paA; } double TPtNode::PaB()const { return paB; } void TPtNode::SetPaA(double pa) { paA = pa; } void TPtNode::SetPaB(double pa) { paB = pa; } bool TPtNode::IsRefA()const { return pRefA != NULL; } bool TPtNode::IsRefB()const { return pRefB != NULL; } bool TPtNode::IsRefC()const { return pRefC != NULL; } TPtNode*& TPtNode::RefA()const { return (TPtNode*&)(*pRefA); } TPtNode*& TPtNode::RefB()const { return (TPtNode*&)(*pRefB); } TPtNode*& TPtNode::RefC()const { return (TPtNode*&)(*pRefC); } void TPtNode::SetRefA(TPtNode**p) { pRefA = p; } void TPtNode::SetRefB(TPtNode**p) { pRefB = p; } void TPtNode::SetRefC(TPtNode**p) { pRefC = p; } bool TPtNode::IsANode()const { return NextA() != NULL; } bool TPtNode::IsBNode()const { return NextB() != NULL; } bool TPtNode::IsABNode()const { return IsANode() && IsBNode(); } void TPtNode::Replace(TPtNode*p) { if (p == this) { return; } AddFlag(p->GetFlag()); if (p->PreA() != NULL) { p->PreA()->CNNextA(this); } if (p->PreB() != NULL) { p->PreB()->CNNextB(this); } if (p->NextA() != NULL) { CNNextA(p->NextA()); } if (p->NextB() != NULL) { CNNextB(p->NextB()); } if (p->IsRefA()) { p->RefA() = this; SetRefA(&(p->RefA())); } if (p->IsRefB()) { p->RefB() = this; SetRefB(&(p->RefB())); } if (p->IsRefC()) { p->RefC() = this; SetRefC(&(p->RefC())); } delete p; } void TPtNode::MakeListIn(TPDList &res) { if (Is(A_IN) && IsNot(A_VISITED)) { AddFlag(A_VISITED); bool bAtA = true; TPtList*pList = new TPtList(*this); TPtList*pCur = pList; TPtNode*p = NextA(); TList lstNode; while(p != this && lstNode.Find(p) == NOT_FOUND) { lstNode.AddTail(p); pCur->CNNext(new TPtList(*p)); pCur = pCur->Next(); if (bAtA) { if (p->Is(B_IN)) { bAtA = false; p->AddFlag(B_VISITED); p = p->NextB(); } else { p->AddFlag(A_VISITED); p = p->NextA(); } } else { if (p->Is(A_IN)) { bAtA = true; p->AddFlag(A_VISITED); p = p->NextA(); } else { p->AddFlag(B_VISITED); p = p->NextB(); } } } if (p != this) { delete pList; } else { pCur->CNNext(pList); res << pList; } } if (Is(B_IN) && IsNot(B_VISITED)) { AddFlag(B_VISITED); bool bAtA = false; TPtList*pList = new TPtList(*this); TPtList*pCur = pList; TPtNode*p = NextB(); TList lstNode; while(p != this && lstNode.Find(p) == NOT_FOUND) { lstNode.AddTail(p); pCur->CNNext(new TPtList(*p)); pCur = pCur->Next(); if (bAtA) { if (p->Is(B_IN)) { bAtA = false; p->AddFlag(B_VISITED); p = p->NextB(); } else { p->AddFlag(A_VISITED); p = p->NextA(); } } else { if (p->Is(A_IN)) { bAtA = true; p->AddFlag(A_VISITED); p = p->NextA(); } else { p->AddFlag(B_VISITED); p = p->NextB(); } } } if (p != this) { delete pList; } else { pCur->CNNext(pList); res << pList; } } } void TPtNode::MakeListOut(TPDList &res) { if (Is(A_OUT) && IsNot(A_VISITED)) { AddFlag(A_VISITED); bool bAtA = true; TPtList*pList = new TPtList(*this); TPtList*pCur = pList; TPtNode*p = NextA(); TList lstNode; while(p != this && lstNode.Find(p) == NOT_FOUND) { lstNode.AddTail(p); pCur->CNNext(new TPtList(*p)); pCur = pCur->Next(); if (bAtA) { if (p->Is(B_OUT)) { bAtA = false; p->AddFlag(B_VISITED); p = p->NextB(); } else { p->AddFlag(A_VISITED); p = p->NextA(); } } else { if (p->Is(A_OUT)) { bAtA = true; p->AddFlag(A_VISITED); p = p->NextA(); } else { p->AddFlag(B_VISITED); p = p->NextB(); } } } if (p != this) { delete pList; } else { pCur->CNNext(pList); res << pList; } } if (Is(B_OUT) && IsNot(B_VISITED)) { AddFlag(B_VISITED); bool bAtA = false; TPtList*pList = new TPtList(*this); TPtList*pCur = pList; TPtNode*p = NextB(); TList lstNode; while(p != this && lstNode.Find(p) == NOT_FOUND) { lstNode.AddTail(p); pCur->CNNext(new TPtList(*p)); pCur = pCur->Next(); if (bAtA) { if (p->Is(B_OUT)) { bAtA = false; p->AddFlag(B_VISITED); p = p->NextB(); } else { p->AddFlag(A_VISITED); p = p->NextA(); } } else { if (p->Is(A_OUT)) { bAtA = true; p->AddFlag(A_VISITED); p = p->NextA(); } else { p->AddFlag(B_VISITED); p = p->NextB(); } } } if (p != this) { delete pList; } else { pCur->CNNext(pList); res << pList; } } }