diff --git a/Core/Code/Interactions/mitkEventRecorder.cpp b/Core/Code/Interactions/mitkEventRecorder.cpp index ef6397f012..d707aca1c5 100644 --- a/Core/Code/Interactions/mitkEventRecorder.cpp +++ b/Core/Code/Interactions/mitkEventRecorder.cpp @@ -1,83 +1,161 @@ /*=================================================================== 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 << " \n"; +} + +static void WriteEventXMLEventsOpen(std::ofstream& stream) +{ + stream << " <" << mitk::InteractionEventConst::xmlTagEvents() << ">\n"; +} + + +static void WriteEventXMLEventsClose(std::ofstream& stream) +{ + stream << " \n"; +} + + +static void WriteEventXMLInteractionsOpen(std::ofstream& stream) +{ + stream << "<" << mitk::InteractionEventConst::xmlTagInteractions() << ">\n"; +} + + +static void WriteEventXMLInteractionsClose(std::ofstream& stream) +{ + stream << ""; +} + + +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 ; + return; } - //write open tag - m_FileStream << "\n"; + //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 - m_FileStream << "\n"; + // + // + WriteEventXMLClose(m_FileStream); m_FileStream.flush(); m_FileStream.close(); } } diff --git a/Core/Code/Interactions/mitkEventRecorder.h b/Core/Code/Interactions/mitkEventRecorder.h index 7013d4a5c9..9f66c6724c 100644 --- a/Core/Code/Interactions/mitkEventRecorder.h +++ b/Core/Code/Interactions/mitkEventRecorder.h @@ -1,74 +1,84 @@ /*=================================================================== 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 diff --git a/Core/Code/Interactions/mitkInteractionEventConst.cpp b/Core/Code/Interactions/mitkInteractionEventConst.cpp index 558eb107f5..49dc5cc910 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.cpp +++ b/Core/Code/Interactions/mitkInteractionEventConst.cpp @@ -1,131 +1,159 @@ /*=================================================================== 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 "mitkInteractionEventConst.h" namespace mitk { +const std::string InteractionEventConst::xmlHead() +{ + static const std::string xmlHead = ""; + return xmlHead; +} + const std::string InteractionEventConst::xmlTagConfigRoot() { static const std::string xmlTagConfigRoot = "config"; return xmlTagConfigRoot; } +const std::string InteractionEventConst::xmlTagEvents() +{ + static const std::string xmlTagEvents = "events"; + return xmlTagEvents; +} + +const std::string InteractionEventConst::xmlTagInteractions() +{ + static const std::string xmlTagInteractions = "interactions"; + return xmlTagInteractions; +} + +const std::string InteractionEventConst::xmlTagRenderer() +{ + static const std::string xmlTagRenderer = "renderer"; + return xmlTagRenderer; +} + const std::string InteractionEventConst::xmlTagParam() { static const std::string xmlTagParam = "param"; return xmlTagParam; - } const std::string InteractionEventConst::xmlTagEventVariant() { static const std::string xmlTagEventVariant = "event_variant"; return xmlTagEventVariant; } const std::string InteractionEventConst::xmlTagAttribute() { static const std::string xmlTagAttribute = "attribute"; return xmlTagAttribute; } const std::string InteractionEventConst::xmlParameterName() { static const std::string xmlParameterName = "name"; return xmlParameterName; } const std::string InteractionEventConst::xmlParameterValue() { static const std::string xmlParameterValue = "value"; return xmlParameterValue; } const std::string InteractionEventConst::xmlParameterEventVariant() { static const std::string xmlParameterEventVariant = "event_variant"; return xmlParameterEventVariant; } const std::string InteractionEventConst::xmlParameterEventClass() { static const std::string xmlParameterEventClass = "class"; return xmlParameterEventClass; } const std::string InteractionEventConst::xmlEventPropertyModifier() { static const std::string xmlEventPropertyModifier = "Modifiers"; return xmlEventPropertyModifier; } const std::string InteractionEventConst::xmlEventPropertyEventButton() { static const std::string xmlEventPropertyEventButton = "EventButton"; return xmlEventPropertyEventButton; } const std::string InteractionEventConst::xmlEventPropertyButtonState() { static const std::string xmlEventPropertyButtonState = "ButtonState"; return xmlEventPropertyButtonState; } const std::string InteractionEventConst::xmlEventPropertyPositionInWorld() { static const std::string xmlEventPropertyPosition = "PositionInWorld"; return xmlEventPropertyPosition; } const std::string InteractionEventConst::xmlEventPropertyPositionOnScreen() { static const std::string xmlEventPropertyPosition = "PositionOnScreen"; return xmlEventPropertyPosition; } const std::string InteractionEventConst::xmlEventPropertyKey() { static const std::string xmlEventPropertyKey = "Key"; return xmlEventPropertyKey; } const std::string InteractionEventConst::xmlEventPropertyScrollDirection() { static const std::string xmlEventPropertyScrollDirection = "ScrollDirection"; return xmlEventPropertyScrollDirection; } const std::string InteractionEventConst::xmlEventPropertyWheelDelta() { static const std::string xmlEventPropertyWheelDelta = "WheelDelta"; return xmlEventPropertyWheelDelta; } const std::string InteractionEventConst::xmlEventPropertySignalName() { static const std::string xmlEventPropertySignalName = "SignalName"; return xmlEventPropertySignalName; } const std::string InteractionEventConst::xmlEventPropertyRendererName() { static const std::string xmlEventPropertyRendererName = "RendererName"; return xmlEventPropertyRendererName; } +const std::string InteractionEventConst::xmlEventPropertyViewDirection() +{ + static const std::string xmlEventPropertyViewDirection = "ViewDirection"; + return xmlEventPropertyViewDirection; +} } diff --git a/Core/Code/Interactions/mitkInteractionEventConst.h b/Core/Code/Interactions/mitkInteractionEventConst.h index da7fdd81ba..5fb599d6b6 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.h +++ b/Core/Code/Interactions/mitkInteractionEventConst.h @@ -1,57 +1,63 @@ /*=================================================================== 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 MITKINTERACTEVENTCONST_H #define MITKINTERACTEVENTCONST_H #include #include namespace mitk { /** * @brief Constants to describe Mouse Events and special Key Events. */ struct MITK_CORE_EXPORT InteractionEventConst { + static const std::string xmlHead(); // = ""; + // XML Tags static const std::string xmlTagConfigRoot(); // = "config"; + static const std::string xmlTagEvents(); // = "events"; + static const std::string xmlTagInteractions(); // = "interactions"; static const std::string xmlTagParam(); // = "param"; static const std::string xmlTagEventVariant(); // = "event_variant"; static const std::string xmlTagAttribute(); // = "attribute"; + static const std::string xmlTagRenderer(); // = "renderer"; // XML Param static const std::string xmlParameterName(); // = "name"; static const std::string xmlParameterValue(); // = "value"; static const std::string xmlParameterEventVariant(); // = "event_variant"; static const std::string xmlParameterEventClass(); // = "class"; // Event Description static const std::string xmlEventPropertyModifier(); // = "Modifiers"; static const std::string xmlEventPropertyEventButton(); // = "EventButton"; static const std::string xmlEventPropertyButtonState(); // = "ButtonState"; static const std::string xmlEventPropertyPositionInWorld(); // = "PositionInWorld"; static const std::string xmlEventPropertyPositionOnScreen(); // = "PositionOnScreen"; static const std::string xmlEventPropertyKey(); // = "Key"; static const std::string xmlEventPropertyScrollDirection(); // = "ScrollDirection"; static const std::string xmlEventPropertyWheelDelta(); // = "WheelDelta"; static const std::string xmlEventPropertySignalName(); // = "SignalName"; static const std::string xmlEventPropertyRendererName(); // = "RendererName"; + static const std::string xmlEventPropertyViewDirection(); // = "ViewDirection"; }; } //namespace mitk #endif //ifndef MITKINTERACTEVENTCONST_H diff --git a/Core/Code/Interactions/mitkXML2EventParser.cpp b/Core/Code/Interactions/mitkXML2EventParser.cpp index daf227e38c..00e4ebae7a 100755 --- a/Core/Code/Interactions/mitkXML2EventParser.cpp +++ b/Core/Code/Interactions/mitkXML2EventParser.cpp @@ -1,137 +1,137 @@ /*=================================================================== 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 "mitkXML2EventParser.h" #include "mitkEventFactory.h" #include "mitkInteractionEvent.h" #include "mitkInternalEvent.h" #include "mitkInteractionKeyEvent.h" #include "mitkInteractionEventConst.h" // VTK #include // us #include "usGetModuleContext.h" #include "usModule.h" #include "usModuleResource.h" #include "usModuleResourceStream.h" namespace mitk { void mitk::XML2EventParser::StartElement(const char* elementName, const char **atts) { std::string name(elementName); if (name == InteractionEventConst::xmlTagConfigRoot()) { // } - else if (name == InteractionEventConst::xmlTagEventVariant()) + else if (name == InteractionEventConst::xmlTagEventVariant()) { std::string eventClass = ReadXMLStringAttribute(InteractionEventConst::xmlParameterEventClass(), atts); // New list in which all parameters are stored that are given within the tag m_EventPropertyList = PropertyList::New(); m_EventPropertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), eventClass.c_str()); //MITK_INFO << "event class " << eventClass; } else if (name == InteractionEventConst::xmlTagAttribute()) { // Attributes that describe an Input Event, such as which MouseButton triggered the event,or which modifier keys are pressed std::string name = ReadXMLStringAttribute(InteractionEventConst::xmlParameterName(), atts); std::string value = ReadXMLStringAttribute(InteractionEventConst::xmlParameterValue(), atts); //MITK_INFO << "tag attr " << value; m_EventPropertyList->SetStringProperty(name.c_str(), value.c_str()); } } void mitk::XML2EventParser::EndElement(const char* elementName) { std::string name(elementName); // At end of input section, all necessary infos are collected to created an interaction event. if (name == InteractionEventConst::xmlTagEventVariant()) { InteractionEvent::Pointer event = EventFactory::CreateEvent(m_EventPropertyList); if (event.IsNotNull()) { m_InteractionList.push_back(event); } else { MITK_WARN<< "EventConfig: Unknown Event-Type in config. Entry skipped: " << name; } } } std::string mitk::XML2EventParser::ReadXMLStringAttribute(const std::string& name, const char** atts) { if (atts) { const char** attsIter = atts; while (*attsIter) { if (name == *attsIter) { attsIter++; return *attsIter; } attsIter += 2; } } return std::string(); } bool mitk::XML2EventParser::ReadXMLBooleanAttribute(const std::string& name, const char** atts) { std::string s = ReadXMLStringAttribute(name, atts); std::transform(s.begin(), s.end(), s.begin(), ::toupper); return s == "TRUE"; } mitk::XML2EventParser::XML2EventParser(const std::string& filename, const us::Module* module) { if (module == NULL) { module = us::GetModuleContext()->GetModule(); } us::ModuleResource resource = module->GetResource("Interactions/" + filename); if (!resource.IsValid()) { MITK_ERROR << "Resource not valid. State machine pattern in module " << module->GetName() << " not found: /Interactions/" << filename; return; } us::ModuleResourceStream stream(resource); this->SetStream(&stream); bool success = this->Parse(); if (!success) MITK_ERROR << "Error occured during parsing of EventXML File."; } mitk::XML2EventParser::XML2EventParser(std::istream &inputStream) { this->SetStream(&inputStream); bool success = this->Parse(); if (!success) MITK_ERROR << "Error occured during parsing of EventXML File."; } }