#include "stdafx.h"
#include "face.h"
#include "facegroup.h"

FaceGroup::FaceGroup(int iInMaxElements)
{
	setLockMem( 0 );

	iNumElements = 0;
	iMaxElements = iInMaxElements;
	pElementList = new Face*[iInMaxElements];
}

FaceGroup::~FaceGroup()
{
	freeMem();
}

void FaceGroup::addElement(Face& inFace)
{
	if(iNumElements < iMaxElements) {
		pElementList[iNumElements] = new Face(inFace.getMaxNumVertex());
		pElementList[iNumElements]->assign(inFace);
		iNumElements++;
	}
	else {
		MessageBox( NULL, "To many faces","to many faces face", MB_OK );//throw( "Your Face is UGLY!!!(too many faces)" );
	}
}

int FaceGroup::getNumElements()
{
	return iNumElements;
}

int FaceGroup::getMaxElements()
{
	return iMaxElements;
}

void FaceGroup::setElementAt(int index, Face &inFace) {
	if(index < iNumElements) {
		pElementList[index]->assign(inFace);
	}
}

Face FaceGroup::getElementAt(int index)
{
	if ( index < iNumElements )
	{
		return *pElementList[index];
	}
	else
	{
		MessageBox( NULL, "face i","face i", MB_OK );//throw( "out of boundary face access attempt" );
	}
}

Face *FaceGroup::getElementAtPtr(int index)
{
	if ( index < iNumElements )
	{
		return &(*pElementList[index]);
	}
	else
	{
		MessageBox( NULL, "fAce index to big","fAce index to big", MB_OK );//throw( "out of boundary face access attempt" );
	}
}

void FaceGroup::freeMem()
{
//	if ( ! getLockMem() )
//	{
	for(int i = 0; i < iNumElements;i++) {
		delete pElementList[i];
	}
	delete pElementList;
//	}
}

void FaceGroup::setLockMem( int iInLockMem )
{
	iLockMem = iInLockMem;
}

int FaceGroup::getLockMem()
{
	return iLockMem;
}