diff --git a/Core/Code/Interactions/mitkEventRecorder.cpp b/Core/Code/Interactions/mitkEventRecorder.cpp
index d707aca1c5..229eb3a007 100644
--- a/Core/Code/Interactions/mitkEventRecorder.cpp
+++ b/Core/Code/Interactions/mitkEventRecorder.cpp
@@ -1,161 +1,162 @@
/*===================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "mitkEventRecorder.h"
#include "mitkEventFactory.h"
#include "mitkInteractionEvent.h"
#include "mitkInteractionEventConst.h"
#include "mitkBaseRenderer.h"
static void WriteEventXMLHeader(std::ofstream& stream)
{
stream << mitk::InteractionEventConst::xmlHead() << "\n";
}
static void WriteEventXMLConfig(std::ofstream& stream)
{
//
stream << " <" << mitk::InteractionEventConst::xmlTagConfigRoot() << ">\n";
//write renderer config
//for all registered 2D renderers write name and viewdirection.
mitk::BaseRenderer::BaseRendererMapType::iterator rendererIterator = mitk::BaseRenderer::baseRendererMap.begin();
mitk::BaseRenderer::BaseRendererMapType::iterator end = mitk::BaseRenderer::baseRendererMap.end();
for(; rendererIterator != end; rendererIterator++)
{
if((*rendererIterator).second->GetMapperID() == mitk::BaseRenderer::Standard2D)
{
std::string rendererName = (*rendererIterator).second->GetName();
mitk::SliceNavigationController::ViewDirection viewDirection = (*rendererIterator).second->GetSliceNavigationController()->GetDefaultViewDirection();
//
stream << " <" << mitk::InteractionEventConst::xmlTagRenderer() << " " << mitk::InteractionEventConst::xmlEventPropertyRendererName() << "=\"" << rendererName << "\" " << mitk::InteractionEventConst::xmlEventPropertyViewDirection() << "=\"" << viewDirection << "\"/>\n";
}
}
//
stream << " " << mitk::InteractionEventConst::xmlTagConfigRoot() << ">\n";
}
static void WriteEventXMLEventsOpen(std::ofstream& stream)
{
stream << " <" << mitk::InteractionEventConst::xmlTagEvents() << ">\n";
}
static void WriteEventXMLEventsClose(std::ofstream& stream)
{
stream << " " << mitk::InteractionEventConst::xmlTagEvents() << ">\n";
}
static void WriteEventXMLInteractionsOpen(std::ofstream& stream)
{
stream << "<" << mitk::InteractionEventConst::xmlTagInteractions() << ">\n";
}
static void WriteEventXMLInteractionsClose(std::ofstream& stream)
{
stream << "" << mitk::InteractionEventConst::xmlTagInteractions() << ">";
}
static void WriteEventXMLClose(std::ofstream& stream)
{
WriteEventXMLEventsClose(stream);
WriteEventXMLInteractionsClose(stream);
}
mitk::EventRecorder::EventRecorder()
: m_Active(false)
{
}
mitk::EventRecorder::~EventRecorder()
{
if (m_FileStream.is_open())
{
m_FileStream.flush();
m_FileStream.close();
}
}
void mitk::EventRecorder::Notify(mitk::InteractionEvent *interactionEvent, bool /*isHandled*/)
{
std::cout << EventFactory::EventToXML(interactionEvent) << "\n";
if (m_FileStream.is_open())
m_FileStream << EventFactory::EventToXML(interactionEvent) << "\n";
}
void mitk::EventRecorder::SetEventIgnoreList(std::vector list)
{
m_IgnoreList = list;
}
void mitk::EventRecorder::StartRecording()
{
if (m_FileName == "")
{
MITK_ERROR << "EventRecorder::StartRecording - Filename needs to be set first.";
return;
}
if (m_FileStream.is_open())
{
MITK_ERROR << "EventRecorder::StartRecording - Still recording. Stop recording before starting it again.";
return;
}
m_FileStream.open(m_FileName.c_str(), std::ofstream::out );
if ( !m_FileStream.good() )
{
MITK_ERROR << "File " << m_FileName << " could not be opened!";
m_FileStream.close();
return;
}
//write head and config
//
//
//
- // .
- // .
+ //
+ //
+ // ...
//
//
WriteEventXMLHeader(m_FileStream);
WriteEventXMLInteractionsOpen(m_FileStream);
WriteEventXMLConfig(m_FileStream);
WriteEventXMLEventsOpen(m_FileStream);
}
void mitk::EventRecorder::StopRecording()
{
if (m_FileStream.is_open())
{
//write end tag
//
//
WriteEventXMLClose(m_FileStream);
m_FileStream.flush();
m_FileStream.close();
}
}
diff --git a/Core/Code/Interactions/mitkEventRecorder.h b/Core/Code/Interactions/mitkEventRecorder.h
index 9f66c6724c..68fe37a843 100644
--- a/Core/Code/Interactions/mitkEventRecorder.h
+++ b/Core/Code/Interactions/mitkEventRecorder.h
@@ -1,84 +1,92 @@
/*===================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef mitkEventRecorder_h
#define mitkEventRecorder_h
#include
#include "mitkInteractionEventObserver.h"
#include "iostream"
namespace mitk
{
/**
*\class EventRecorder
*@brief Observer that enables recoding of all user interaction with the render windows and storing it in an XML file.
*
* @ingroup Interaction
*
* XML file will look like
*
*
*
*
+ *
+ *
+ *
*
*
+ *
+ *
+ *
+ *
+ *
*
*
**/
class MITK_CORE_EXPORT EventRecorder: public InteractionEventObserver
{
public:
EventRecorder();
~EventRecorder();
/**
* By this function the Observer gets notified about new events.
*/
virtual void Notify(InteractionEvent* interactionEvent, bool);
/**
* @brief SetEventIgnoreList Optional. Provide a list of strings that describe which events are to be ignored
*/
void SetEventIgnoreList(std::vector list);
void StartRecording();
void StopRecording();
void SetOutputFile(std::string filename)
{
m_FileName = filename;
}
private:
/**
* @brief m_IgnoreList lists the names of events that are dropped
*/
std::vector m_IgnoreList;
/**
* @brief m_Active determindes if events are caught and written to file
*/
bool m_Active;
std::string m_FileName;
std::ofstream m_FileStream;
};
}
#endif