#include "VisualizationPlugin.h"
#include "ritkDebugManager.h"
#include "ritkManager.h"


VisualizationPlugin::VisualizationPlugin()
{
	// Create the widget
	m_Widget = new VisualizationWidget();
	connect(this, SIGNAL(UpdateGUI()), m_Widget, SLOT(UpdateGUI()));
}

VisualizationPlugin::~VisualizationPlugin()
{
	delete m_Widget;
}


//----------------------------------------------------------------------------
QString
VisualizationPlugin::GetName()
{
	return tr("VisualizationPlugin");
}


//----------------------------------------------------------------------------
QWidget*
VisualizationPlugin::GetPluginGUI()
{
	return m_Widget;
}


//----------------------------------------------------------------------------
void
VisualizationPlugin::ProcessEvent(ritk::Event::Pointer EventP)
{
	// New frame event
	if ( EventP->type() == ritk::NewFrameEvent::EventType )
	{
		// Cast the event
		ritk::NewFrameEvent::Pointer NewFrameEventP = qSharedPointerDynamicCast<ritk::NewFrameEvent,ritk::Event>(EventP);
		if ( !NewFrameEventP )
		{
			LOG_DEB("Event mismatch detected: Type=" << EventP->type());
			return;
		}
		ritk::NewFrameEvent::RImageConstPointer CurrentFrameP = NewFrameEventP->RImage;

		LockPlugin();
		m_Widget->SetRangeData(CurrentFrameP);
		UnlockPlugin();
	}
	else
	{
		LOG_DEB("Unknown event");
	}
}
