#include "GlobalFunc.h" #include "T2FInfoAreaIterator.h" #include "T2FloorInfo.h" #include "T2MoverArrayList.h" #include "T2RequestArrayList.h" #include "T2TenantArrayList.h" #include "T2UnitInfo.h" T2FInfoAreaIterator::T2FInfoAreaIterator(const T2FloorInfo& inFloorInfo, const RECT& inRect) : mFloorInfo(inFloorInfo) { mRect = mFloorInfo.mBuildArea; InsetRect(&mRect, -1, 0); if (mRect.left < 0) mRect.left = 0; if (mRect.right > inFloorInfo.mHRange) mRect.right = inFloorInfo.mHRange; IntersectRect(&mRect, &inRect, &mRect); mSkipAmount = mFloorInfo.mHRange - (mRect.right - mRect.left) + 1; Reset(); } /*virtual*/ T2FInfoAreaIterator::~T2FInfoAreaIterator() { } void T2FInfoAreaIterator::Reset() { mCurrV = mRect.top; if (!IsRectEmpty(&mRect)) { mCurrH = -1; mCurrUnitInfo = mFloorInfo.GetUnitInfo(mCurrV, mRect.left); #line 68 _ASSERT(mCurrUnitInfo != NULL); } else { mCurrH = -2; } mLastIDSeen = 0; } BOOL T2FInfoAreaIterator::CalcNextUnitInfo() { BOOL result = true; if (mCurrH != -2) { if (mCurrH != -1) { mCurrH++; if (mCurrH < mRect.right) { mCurrUnitInfo++; } else { mCurrH = mRect.left; mCurrV++; if (mCurrV < mRect.bottom) { mCurrUnitInfo += mSkipAmount; } else { mCurrH = -2; result = false; } } } else { mCurrH = mRect.left; } } else { result = false; } return result; } BOOL T2FInfoAreaIterator::CurrentV(int& outV) const { BOOL result = true; if (IsValidPosition()) outV = mCurrV; else result = false; return result; } BOOL T2FInfoAreaIterator::Current(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (IsValidPosition()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoAreaIterator::Next(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (CalcNextUnitInfo()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoAreaIterator::NextTenant(T2Tenant*& outTenant) { BOOL result; T2UnitInfo *unitInfo; for (result = Next(unitInfo); result; result = Next(unitInfo)) { unsigned int tenantID = unitInfo->GetTenantID(); if (tenantID != mLastIDSeen) { mLastIDSeen = tenantID; if (tenantID != 0) { outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); break; } } } return result; } void T2FInfoAreaIterator::GetTenantRect(RECT& outRect) { outRect.left = mCurrH; outRect.right = outRect.left; if (IsValidPosition()) { outRect.right++; T2UnitInfo *unitInfo = mCurrUnitInfo + 1; while (unitInfo->GetTenantID() == mLastIDSeen) { outRect.right++; unitInfo++; } } } BOOL T2FInfoAreaIterator::NextRequest(T2Request*& outRequest) { BOOL result; T2UnitInfo *unitInfo; for (result = Next(unitInfo); result; result = Next(unitInfo)) { unsigned int requestID = unitInfo->GetRequestID(); if (requestID != mLastIDSeen) { mLastIDSeen = requestID; if (requestID != 0) { outRequest = mFloorInfo.mRequestArrayList->GetRequestByID(requestID); break; } } } return result; } BOOL T2FInfoAreaIterator::NextMover(T2Mover*& outMover) { BOOL result; T2UnitInfo *unitInfo; for (result = Next(unitInfo); result; result = Next(unitInfo)) { unsigned int moverID = unitInfo->GetMoverID(); if (moverID != mLastIDSeen) { mLastIDSeen = moverID; if (moverID != 0) { outMover = mFloorInfo.mMoverArrayList->GetMoverByID(moverID); break; } } } return result; } T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo& inFloorInfo, POINT inPt) : mFloorInfo(inFloorInfo) , mLeftBound(mFloorInfo.mBuildArea.left) , mRightBound(mFloorInfo.mBuildArea.right - 1) { if (PtInRect(&mFloorInfo.mBuildArea, inPt)) { mCurrH = inPt.x; mCurrUnitInfo = mFloorInfo.GetUnitInfo(inPt.y, mCurrH); mLastIDSeen = 0; } else { mCurrH = -2; } } /*virtual*/ T2FInfoPtIterator::~T2FInfoPtIterator() { } BOOL T2FInfoPtIterator::CurrentH(int& outH) const { BOOL result = true; if (IsValidPosition()) outH = mCurrH; else result = false; return result; } BOOL T2FInfoPtIterator::CalcRightUnitInfo() { BOOL result = true; if (mCurrH != -2) { if (mCurrH != -1) { if (mCurrH < mRightBound) { mCurrH++; mCurrUnitInfo++; } else { mCurrH = -2; result = false; } } else { mCurrH = mLeftBound; } } else { result = false; } return result; } BOOL T2FInfoPtIterator::CalcLeftUnitInfo() { BOOL result = true; if (mCurrH != -2) { if (mCurrH != -1) { if (mCurrH > mLeftBound) { mCurrH--; mCurrUnitInfo--; } else { result = false; } } else { mCurrH = mRightBound; } } else { result = false; } return result; } BOOL T2FInfoPtIterator::Current(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (IsValidPosition()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoPtIterator::Right(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (CalcRightUnitInfo()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoPtIterator::Left(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (CalcLeftUnitInfo()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoPtIterator::RightTenant(T2Tenant*& outTenant) { BOOL result; T2UnitInfo *unitInfo; for (result = Right(unitInfo); result; result = Right(unitInfo)) { unsigned int tenantID = unitInfo->GetTenantID(); if (tenantID != mLastIDSeen) { mLastIDSeen = tenantID; if (tenantID != 0) { outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); break; } } } return result; } BOOL T2FInfoPtIterator::LeftTenant(T2Tenant*& outTenant) { BOOL result; T2UnitInfo *unitInfo; for (result = Left(unitInfo); result; result = Left(unitInfo)) { unsigned int tenantID = unitInfo->GetTenantID(); if (tenantID != mLastIDSeen) { mLastIDSeen = tenantID; if (tenantID != 0) { outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); break; } } } return result; }