void SceneSelectionSystem::Process(DAVA::float32 timeElapsed)
{
	ForceEmitSignals();

	if (IsLocked())
	{
		return;
	}

    // if boxes are invalid we should request them from collision system
    // and store them in selection entityGroup
    if(invalidSelectionBoxes)
    {
        for(DAVA::uint32 i = 0; i < curSelections.Size(); i++)
        {
            EntityGroupItem *item = curSelections.GetItem(i);
            item->bbox = GetSelectionAABox(curSelections.GetEntity(i));
        }

        invalidSelectionBoxes = false;
    }


	UpdateHoodPos();
}
void SceneSelectionSystem::SetSelection(DAVA::Entity *entity)
{
	// emit deselection for current selected items
	for(size_t i = 0; i < curSelections.Size(); ++i)
	{
		EntityGroupItem selectedItem = curSelections.GetItem(i);
		SceneSignals::Instance()->EmitDeselected((SceneEditorProxy *) GetScene(), selectedItem.solidEntity);
	}

	// clear current selection
	curSelections.Clear();

	// add new selection
	if(NULL != entity)
	{
		EntityGroupItem selectableItem = GetSelectableEntity(entity);
		curSelections.Add(selectableItem);

		SceneSignals::Instance()->EmitSelected((SceneEditorProxy *) GetScene(), selectableItem.solidEntity);
	}
	else
	{
		SceneSignals::Instance()->EmitSelected((SceneEditorProxy *) GetScene(), NULL);
	}

	UpdateHoodPos();
}
void SceneSelectionSystem::RemSelection(DAVA::Entity *entity)
{
	curSelections.Rem(entity);

	EntityGroupItem selectableItem = GetSelectableEntity(entity);
	SceneSignals::Instance()->EmitDeselected((SceneEditorProxy *) GetScene(), selectableItem.solidEntity);

	UpdateHoodPos();
}
void SceneSelectionSystem::SetLocked(bool lock)
{
	SceneSystem::SetLocked(lock);

	hoodSystem->LockAxis(lock);
	hoodSystem->SetVisible(!lock);

	if(!lock)
	{
		UpdateHoodPos();
	}
}
void SceneSelectionSystem::AddSelection(DAVA::Entity *entity)
{
	if(NULL != entity)
	{
		EntityGroupItem selectableItem = GetSelectableEntity(entity);
		curSelections.Add(selectableItem);

		SceneSignals::Instance()->EmitSelected((SceneEditorProxy *) GetScene(), selectableItem.solidEntity);
	}

	UpdateHoodPos();
}
void SceneSelectionSystem::RemSelection(DAVA::Entity *entity)
{
	if(!IsLocked())
	{
		if(curSelections.HasEntity(entity))
		{
			curSelections.Rem(entity);
			curDeselections.Add(entity);

			selectionHasChanges = true;
		}

		UpdateHoodPos();
	}
}
void SceneSelectionSystem::SetSelection(DAVA::Entity *entity)
{
	if(!IsLocked())
	{
		Clear();

		// add new selection
		if(NULL != entity)
		{
			AddSelection(entity);
		}

		UpdateHoodPos();
	}
}
void SceneSelectionSystem::AddSelection(DAVA::Entity *entity)
{
	if(!IsLocked())
	{
		if(NULL != entity)
		{
			EntityGroupItem selectableItem;

			selectableItem.entity = entity;
			selectableItem.bbox = GetSelectionAABox(entity);

			if(!curSelections.HasEntity(entity))
			{
				curSelections.Add(selectableItem);

				selectionHasChanges = true;
			}
		}

		UpdateHoodPos();
	}
}
void SceneSelectionSystem::Update(DAVA::float32 timeElapsed)
{
	UpdateHoodPos();
}