
#include "nodeidcontrol.h"

using namespace VRUT;


// Register with wxWidgets' dynamic class subsystem.
IMPLEMENT_DYNAMIC_CLASS(NodeIDControl, wxComboBox)
IMPLEMENT_DYNAMIC_CLASS(NodeIDControlXmlHandler, wxXmlResourceHandler)

void NodeIDDetailPopup::OnDismiss()
{
	SceneNode::TypeMask	nodeTypes = 0;
	for (size_t i=1; i<typeFilters.size(); ++i)
		if (typeFilters[i-1]->GetValue())
			nodeTypes += 1<<(i-1);

	((NodeIDControl*)GetParent())->SetNodeTypes(nodeTypes);

	int	controlMode = 0;
	if (!typeFilters.empty() && typeFilters.back()->GetValue())
		controlMode += 1<<0;

	((NodeIDControl*)GetParent())->SetControlMode(controlMode);

	wxPopupTransientWindow::OnDismiss();
}

void NodeIDControl::SetControlMode(int newControlMode)
{
	if (newControlMode != controlMode)
	{
		if(	(newControlMode & (1<<0)) != (controlMode & (1<<0)))
		{
			Parameter::ParameterIdentifier pi = Parameter::ParameterIdentifier::FromParamName(GetName());
			wxString paramValue = wxString::Format("AutoFromNodeMode %i", ((newControlMode & (1<<0))) ? 1 : 0);
			KERNEL->GetMessageSink()->PostEvent(GET_EVT_PARAM_SET(pi, paramValue));
		}
	}

	controlMode = newControlMode;
}
