#include "StdAfx.h" #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 found; T2UnitInfo *unitInfo; for (found = Next(unitInfo); found; found = Next(unitInfo)) { unsigned int tenantID = unitInfo->GetTenantID(); if (tenantID != mLastIDSeen) { mLastIDSeen = tenantID; if (tenantID != 0) { outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); break; } } } return found; } void T2FInfoAreaIterator::GetTenantRect(RECT& outRect) { outRect.left = mCurrH; outRect.right = outRect.left; if (IsValidPosition()) { outRect.right++; T2UnitInfo *unitInfo = mCurrUnitInfo + 1; while (mLastIDSeen == unitInfo->GetTenantID()) { outRect.right++; unitInfo++; } } } BOOL T2FInfoAreaIterator::NextRequest(T2Request*& outRequest) { BOOL found; T2UnitInfo *unitInfo; for (found = Next(unitInfo); found; found = Next(unitInfo)) { unsigned int requestID = unitInfo->GetRequestID(); if (requestID != mLastIDSeen) { mLastIDSeen = requestID; if (requestID != 0) { outRequest = mFloorInfo.mRequestArrayList->GetRequestByID(requestID); break; } } } return found; } BOOL T2FInfoAreaIterator::NextMover(T2Mover*& outMover) { BOOL found; T2UnitInfo *unitInfo; for (found = Next(unitInfo); found; found = Next(unitInfo)) { unsigned int moverID = unitInfo->GetMoverID(); if (moverID != mLastIDSeen) { mLastIDSeen = moverID; if (moverID != 0) { outMover = mFloorInfo.mMoverArrayList->GetMoverByID(moverID); break; } } } return found; }