diff --git a/Core/Code/Interactions/mitkEventFactory.cpp b/Core/Code/Interactions/mitkEventFactory.cpp index caebad426c..59c098cdc2 100755 --- a/Core/Code/Interactions/mitkEventFactory.cpp +++ b/Core/Code/Interactions/mitkEventFactory.cpp @@ -1,490 +1,507 @@ /*=================================================================== 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 "mitkEventFactory.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace { std::vector &split(const std::string &s, char delim, std::vector &elems) { std::stringstream ss(s); std::string item; while (std::getline(ss, item, delim)) { elems.push_back(item); } return elems; } std::vector split(const std::string &s, char delim) { std::vector < std::string > elems; return split(s, delim, elems); } } mitk::InteractionEvent::Pointer mitk::EventFactory::CreateEvent(PropertyList::Pointer list) { // std::string eventClass, eventVariant; list->GetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), eventClass); list->GetStringProperty(InteractionEventConst::xmlParameterEventVariant().c_str(), eventVariant); // Query all possible attributes, if they are not present, set their default values. // Position Events & Key Events std::string strModifiers; InteractionEvent::ModifierKeys modifiers = InteractionEvent::NoKey; std::string strEventButton; InteractionEvent::MouseButtons eventButton = InteractionEvent::NoButton; std::string strButtonState; InteractionEvent::MouseButtons buttonState = InteractionEvent::NoButton; std::string strKey; std::string key; std::string strWheelDelta; int wheelDelta; std::string strSignalName = ""; Point2D pos; pos.Fill(0); std::string strPos; // Position on screen if( list->GetStringProperty(InteractionEventConst::xmlEventPropertyPositionOnScreen().c_str(), strPos)) { //split comma separated string int commaPos; commaPos = strPos.find_first_of(','); pos[0] = static_cast(std::atof(strPos.substr(0, commaPos).c_str())); pos[1] = static_cast(std::atof(strPos.substr(commaPos+1, strPos.length()).c_str())); } // Parse modifier information if (list->GetStringProperty(InteractionEventConst::xmlEventPropertyModifier().c_str(), strModifiers)) { std::vector mods = split(strModifiers, ','); for (std::vector::iterator it = mods.begin(); it != mods.end(); ++it) { std::transform((*it).begin(), (*it).end(), (*it).begin(), ::toupper); if (*it == "CTRL") { modifiers = modifiers | InteractionEvent::ControlKey; } else if (*it == "ALT") { modifiers = modifiers | InteractionEvent::AltKey; } else if (*it == "SHIFT") { modifiers = modifiers | InteractionEvent::ShiftKey; } else { MITK_WARN<< "mitkEventFactory: Invalid event modifier in config file :" << (*it); } } } // Set EventButton if (list->GetStringProperty(InteractionEventConst::xmlEventPropertyEventButton().c_str(), strEventButton)) { std::transform(strEventButton.begin(), strEventButton.end(), strEventButton.begin(), ::toupper); if (strEventButton == "MIDDLEMOUSEBUTTON") { eventButton = InteractionEvent::MiddleMouseButton; } else if (strEventButton == "LEFTMOUSEBUTTON") { eventButton = InteractionEvent::LeftMouseButton; } else if (strEventButton == "RIGHTMOUSEBUTTON") { eventButton = InteractionEvent::RightMouseButton; } else { MITK_WARN<< "mitkEventFactory: Invalid event button in config file: " << strEventButton; } } // Parse ButtonStates if (list->GetStringProperty(InteractionEventConst::xmlEventPropertyButtonState().c_str(), strButtonState)) { std::vector mods = split(strButtonState, ','); for (std::vector::iterator it = mods.begin(); it != mods.end(); ++it) { std::transform((*it).begin(), (*it).end(), (*it).begin(), ::toupper); if (*it == "MIDDLEMOUSEBUTTON") { buttonState = buttonState | InteractionEvent::MiddleMouseButton; } else if (*it == "LEFTMOUSEBUTTON") { buttonState = buttonState | InteractionEvent::LeftMouseButton; } else if (*it == "RIGHTMOUSEBUTTON") { buttonState = buttonState | InteractionEvent::RightMouseButton; } else { MITK_WARN<< "mitkEventFactory: Invalid event buttonstate in config file:" << (*it); } } } // Key if (!list->GetStringProperty(InteractionEventConst::xmlEventPropertyKey().c_str(), strKey)) { key = ""; } else { key = strKey; } // WheelDelta if (!list->GetStringProperty(InteractionEventConst::xmlEventPropertyScrollDirection().c_str(), strWheelDelta)) { wheelDelta = 0; } else { std::transform(strWheelDelta.begin(), strWheelDelta.end(), strWheelDelta.begin(), ::toupper); if (strWheelDelta == "DOWN") { wheelDelta = -1; } else { wheelDelta = 1; } } // Internal Signals Name list->GetStringProperty(InteractionEventConst::xmlEventPropertySignalName().c_str(), strSignalName); + // Get BaseRenderer by name + mitk::BaseRenderer* renderer = NULL; + std::string strRenderer; + + if(list->GetStringProperty(mitk::InteractionEventConst::xmlEventPropertyRendererName().c_str(), strRenderer)) + { + //look up for renderer registered with the name in xml file + renderer = mitk::BaseRenderer::GetByName(strRenderer); + } + /* * Here the objects are created */ mitk::InteractionEvent::Pointer event; std::transform(eventClass.begin(), eventClass.end(), eventClass.begin(), ::toupper); if (eventClass == "MOUSEPRESSEVENT") { // buttonstates incorporate the event button (as in Qt) buttonState = buttonState | eventButton; - event = MousePressEvent::New(NULL, pos, buttonState, modifiers, eventButton); + event = MousePressEvent::New(renderer, pos, buttonState, modifiers, eventButton); } else if (eventClass == "MOUSEDOUBLECLICKEVENT") { buttonState = buttonState | eventButton; - event = MouseDoubleClickEvent::New(NULL, pos, buttonState, modifiers, eventButton); + event = MouseDoubleClickEvent::New(renderer, pos, buttonState, modifiers, eventButton); } else if (eventClass == "MOUSEMOVEEVENT") { - event = MouseMoveEvent::New(NULL, pos, buttonState, modifiers); + event = MouseMoveEvent::New(renderer, pos, buttonState, modifiers); } else if (eventClass == "MOUSERELEASEEVENT") { - event = MouseReleaseEvent::New(NULL, pos, buttonState, modifiers, eventButton); + event = MouseReleaseEvent::New(renderer, pos, buttonState, modifiers, eventButton); } else if (eventClass == "INTERACTIONKEYEVENT") { - event = InteractionKeyEvent::New(NULL, key, modifiers); + event = InteractionKeyEvent::New(renderer, key, modifiers); } else if (eventClass == "MOUSEWHEELEVENT") { - event = MouseWheelEvent::New(NULL, pos, buttonState, modifiers, wheelDelta); + event = MouseWheelEvent::New(renderer, pos, buttonState, modifiers, wheelDelta); } else if (eventClass == "INTERACTIONPOSITIONEVENT") { - event = InteractionPositionEvent::New(NULL, pos); + event = InteractionPositionEvent::New(renderer, pos); } else if (eventClass == "INTERNALEVENT") { - event = InternalEvent::New(NULL, NULL, strSignalName); + event = InternalEvent::New(renderer, NULL, strSignalName); } else if (eventClass == "INTERACTIONEVENT") { - event = InteractionEvent::New(NULL); + event = InteractionEvent::New(renderer); } if (event.IsNull()) { MITK_WARN<< "Event couldn't be constructed. Please check your StateMachine patterns and config files\n for the following event class, which is not valid: " << eventClass; return NULL; } return event; } std::string mitk::EventFactory::EventToXML(mitk::InteractionEvent *event) { std::string eventClass = event->GetNameOfClass(); std::string eventXML = "<" + InteractionEventConst::xmlTagEventVariant() + " " + InteractionEventConst::xmlParameterEventClass() + "=\""; std::transform(eventClass.begin(), eventClass.end(), eventClass.begin(), ::toupper); eventXML += eventClass + "\" >\n"; // here follow event specific attributes if (eventClass == "MOUSEPRESSEVENT" || eventClass == "MOUSERELEASEEVENT" || eventClass == "MOUSEDOUBLECLICKEVENT" || eventClass == "MOUSEMOVEEVENT" || eventClass == "MOUSEWHEELEVENT") { if (!(eventClass == "MOUSEMOVEEVENT") && !(eventClass == "MOUSEWHEELEVENT")) { // EventButton eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyEventButton() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetEventButton(event); eventXML += "\"/>\n"; } // ButtonState if (GetButtonState(event) != "") { eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyButtonState() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetButtonState(event); eventXML += "\"/>\n"; } // Modifiers if (GetModifierState(event) != "") { eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyModifier() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetModifierState(event); eventXML += "\"/>\n"; } // Position on Screen eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyPositionOnScreen() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetPositionOnScreen(event); eventXML += "\"/>\n"; // Position in World eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyPositionInWorld() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetPositionInWorld(event); eventXML += "\"/>\n"; } // TODO Implement Key Events!! // else if (eventClass == "INTERACTIONKEYEVENT") // { // event = InteractionKeyEvent::New(NULL, key, modifiers); // } else { MITK_WARN << "Event not recognized, discarding event of type " << event->GetNameOfClass(); } if (eventClass == "MOUSEWHEELEVENT") { MouseWheelEvent* we = dynamic_cast (event); int delta = we->GetWheelDelta(); std::stringstream ss; ss << delta; eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyWheelDelta() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += ss.str(); eventXML += "\"/>\n"; } + + // Renderer name + eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyRendererName() + "\" "; + eventXML += InteractionEventConst::xmlParameterValue() + "=\""; + eventXML += event->GetSender()->GetName(); + eventXML += "\"/>\n"; + // closing tag: eventXML += ""; return eventXML; } std::string mitk::EventFactory::GetButtonState(mitk::InteractionEvent *event) { InteractionEvent::MouseButtons buttonState = InteractionEvent::NoButton; std::string eventClass = event->GetNameOfClass(); std::transform(eventClass.begin(), eventClass.end(), eventClass.begin(), ::toupper); std::string strButtonState = ""; if (eventClass == "MOUSEPRESSEVENT") { MousePressEvent* mme = dynamic_cast (event); buttonState = mme->GetButtonStates(); } if (eventClass == "MOUSERELEASEEVENT") { MouseReleaseEvent* mme = dynamic_cast (event); buttonState = mme->GetButtonStates(); } if (eventClass == "MOUSEDOUBLECLICKEVENT") { MouseDoubleClickEvent* mme = dynamic_cast (event); buttonState = mme->GetButtonStates(); } if (eventClass == "MOUSEMOVEEVENT") { MouseMoveEvent* mme = dynamic_cast (event); buttonState = mme->GetButtonStates(); } if (eventClass == "MOUSEWHEELEVENT") { MouseWheelEvent* mme = dynamic_cast (event); buttonState = mme->GetButtonStates(); } if (buttonState & InteractionEvent::LeftMouseButton ) { strButtonState = "LeftMouseButton"; } if (buttonState & InteractionEvent::RightMouseButton ) { if (strButtonState != "") strButtonState += ","; strButtonState += "RightMouseButton"; } if (buttonState & InteractionEvent::MiddleMouseButton ) { if (strButtonState != "") strButtonState += ","; strButtonState += "MiddleMouseButton"; } return strButtonState; } std::string mitk::EventFactory::GetModifierState(mitk::InteractionEvent *event) { InteractionEvent::ModifierKeys modifierKeys = InteractionEvent::NoKey; std::string eventClass = event->GetNameOfClass(); std::transform(eventClass.begin(), eventClass.end(), eventClass.begin(), ::toupper); std::string strModKeys = ""; // TODO Add InteractionKey if (eventClass == "MOUSEPRESSEVENT") { MousePressEvent* mme = dynamic_cast (event); modifierKeys = mme->GetModifiers(); } if (eventClass == "MOUSERELEASEEVENT") { MouseReleaseEvent* mme = dynamic_cast (event); modifierKeys = mme->GetModifiers(); } if (eventClass == "MOUSEDOUBLECLICKEVENT") { MouseDoubleClickEvent* mme = dynamic_cast (event); modifierKeys = mme->GetModifiers(); } if (eventClass == "MOUSEMOVEEVENT") { MouseMoveEvent* mme = dynamic_cast (event); modifierKeys = mme->GetModifiers(); } if (eventClass == "MOUSEWHEELEVENT") { MouseWheelEvent* mme = dynamic_cast (event); modifierKeys = mme->GetModifiers(); } if (modifierKeys & InteractionEvent::ShiftKey ) { strModKeys = "SHIFT"; } if (modifierKeys & InteractionEvent::ControlKey ) { if (strModKeys != "") strModKeys += ","; strModKeys += "CTRL"; } if (modifierKeys & InteractionEvent::AltKey ) { if (strModKeys != "") strModKeys += ","; strModKeys += "ALT"; } return strModKeys; } std::string mitk::EventFactory::GetEventButton(mitk::InteractionEvent *event) { InteractionEvent::MouseButtons button = InteractionEvent::NoButton; std::string eventClass = event->GetNameOfClass(); std::transform(eventClass.begin(), eventClass.end(), eventClass.begin(), ::toupper); std::string stdButton = ""; // TODO Add InteractionKey if (eventClass == "MOUSEPRESSEVENT") { MousePressEvent* mme = dynamic_cast (event); button = mme->GetEventButton(); } if (eventClass == "MOUSERELEASEEVENT") { MouseReleaseEvent* mme = dynamic_cast (event); button = mme->GetEventButton(); } if (eventClass == "MOUSEDOUBLECLICKEVENT") { MouseDoubleClickEvent* mme = dynamic_cast (event); button = mme->GetEventButton(); } if (button & InteractionEvent::LeftMouseButton ) { stdButton = "LeftMouseButton"; } if (button & InteractionEvent::RightMouseButton ) { stdButton = "RightMouseButton"; } if (button & InteractionEvent::MiddleMouseButton ) { stdButton = "MiddleMouseButton"; } return stdButton; } std::string mitk::EventFactory::GetPositionInWorld(mitk::InteractionEvent *event) { std::stringstream ss; InteractionPositionEvent* pe = dynamic_cast (event); if (pe != NULL) { Point3D p = pe->GetPositionInWorld(); ss << p[0] << "," << p[1] << "," << p[2]; } return ss.str(); } std::string mitk::EventFactory::GetPositionOnScreen(mitk::InteractionEvent *event) { std::stringstream ss; InteractionPositionEvent* pe = dynamic_cast (event); if (pe != NULL) { Point2D p = pe->GetPointerPositionOnScreen(); ss << p[0] << "," << p[1]; } return ss.str(); } diff --git a/Core/Code/Interactions/mitkInteractionEventConst.cpp b/Core/Code/Interactions/mitkInteractionEventConst.cpp index 4dbee6047d..558eb107f5 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.cpp +++ b/Core/Code/Interactions/mitkInteractionEventConst.cpp @@ -1,125 +1,131 @@ /*=================================================================== 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::xmlTagConfigRoot() { static const std::string xmlTagConfigRoot = "config"; return xmlTagConfigRoot; } 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; +} + } diff --git a/Core/Code/Interactions/mitkInteractionEventConst.h b/Core/Code/Interactions/mitkInteractionEventConst.h index 1361b27eab..da7fdd81ba 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.h +++ b/Core/Code/Interactions/mitkInteractionEventConst.h @@ -1,56 +1,57 @@ /*=================================================================== 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 { // XML Tags static const std::string xmlTagConfigRoot(); // = "config"; static const std::string xmlTagParam(); // = "param"; static const std::string xmlTagEventVariant(); // = "event_variant"; static const std::string xmlTagAttribute(); // = "attribute"; // 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"; }; } //namespace mitk #endif //ifndef MITKINTERACTEVENTCONST_H diff --git a/Core/Code/Interactions/mitkXML2EventParser.cpp b/Core/Code/Interactions/mitkXML2EventParser.cpp index 5320f3f8b1..daf227e38c 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()) { 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; + //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; + //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."; } } diff --git a/Plugins/org.mitk.gui.qt.eventrecorder/src/internal/InteractionEventRecorder.cpp b/Plugins/org.mitk.gui.qt.eventrecorder/src/internal/InteractionEventRecorder.cpp index 60d067ac27..9bbaea2dea 100644 --- a/Plugins/org.mitk.gui.qt.eventrecorder/src/internal/InteractionEventRecorder.cpp +++ b/Plugins/org.mitk.gui.qt.eventrecorder/src/internal/InteractionEventRecorder.cpp @@ -1,110 +1,110 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Qmitk #include "InteractionEventRecorder.h" // Qt #include #include // us #include "usGetModuleContext.h" #include "usModuleContext.h" +#include "usModuleResource.h" #include #include #include #include "QmitkRenderWindow.h" US_INITIALIZE_MODULE("InteractionEventRecorder","liborg_mitk_gui_qt_eventrecorder") const std::string InteractionEventRecorder::VIEW_ID = "org.mitk.views.interactioneventrecorder"; void InteractionEventRecorder::SetFocus() { m_Controls.textFileName->setFocus(); } void InteractionEventRecorder::StartRecording() { MITK_INFO << "Start Recording"; m_CurrentObserver->SetOutputFile(m_Controls.textFileName->text().toStdString()); m_CurrentObserver->StartRecording(); } void InteractionEventRecorder::StopRecording() { MITK_INFO << "Stop Recording"; m_CurrentObserver->StopRecording(); } void InteractionEventRecorder::Play() { std::ifstream xmlStream(m_Controls.textFileName->text().toStdString().c_str()); mitk::XML2EventParser parser(xmlStream); mitk::XML2EventParser::EventContainerType events = parser.GetInteractions(); MITK_INFO << "parsed events"; for (int i=0; i < events.size(); ++i) { - events.at(i)->SetSender(this->GetRenderWindowPart()->GetQmitkRenderWindow("axial")->GetRenderer()); - this->GetRenderWindowPart()->GetQmitkRenderWindow("axial")->GetRenderer()->GetDispatcher()->ProcessEvent(events.at(i)); - } + //this->GetRenderWindowPart()->GetQmitkRenderWindow("axial")->GetRenderer()->GetDispatcher()->ProcessEvent(events.at(i)); + events.at(i)->GetSender()->GetDispatcher()->ProcessEvent(events.at(i)); + } MITK_INFO << "DONE"; } void InteractionEventRecorder::OpenFile() { QString fn = QFileDialog::getOpenFileName(NULL, "Open File...", QString(), "All Files (*)"); if (!fn.isEmpty()) this->m_Controls.textFileName->setText(fn); } void InteractionEventRecorder::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect( m_Controls.btnStopRecording, SIGNAL(clicked()), this, SLOT(StopRecording()) ); connect( m_Controls.btnStartRecording, SIGNAL(clicked()), this, SLOT(StartRecording()) ); connect( m_Controls.btnPlay, SIGNAL(clicked()), this, SLOT(Play()) ); connect( m_Controls.btnOpenFile, SIGNAL(clicked()), this, SLOT(OpenFile()) ); m_CurrentObserver = new mitk::EventRecorder(); // Register as listener via micro services us::ServiceProperties props; props["name"] = std::string("EventRecorder"); m_ServiceRegistration = us::GetModuleContext()->RegisterService(m_CurrentObserver,props); - /* delete m_CurrentObserverDEBUG; m_ServiceRegistrationDEBUG.Unregister(); */ }