diff --git a/Core/Code/Interactions/mitkEventConfig.cpp b/Core/Code/Interactions/mitkEventConfig.cpp index aeaaa7fd6e..ad0c4fa87e 100755 --- a/Core/Code/Interactions/mitkEventConfig.cpp +++ b/Core/Code/Interactions/mitkEventConfig.cpp @@ -1,393 +1,393 @@ /*=================================================================== 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 "mitkEventConfig.h" #include "mitkEventFactory.h" #include "mitkInteractionEvent.h" #include "mitkInternalEvent.h" #include "mitkInteractionKeyEvent.h" #include "mitkInteractionEventConst.h" // VTK #include #include // us #include "mitkGetModuleContext.h" #include "mitkModule.h" #include "mitkModuleResource.h" #include "mitkModuleResourceStream.h" namespace mitk { class EventConfigXMLParser : public vtkXMLParser { public: EventConfigXMLParser(EventConfigPrivate* d); protected: /** * @brief Derived from XMLReader **/ void StartElement(const char* elementName, const char **atts); /** * @brief Derived from XMLReader **/ void EndElement(const char* elementName); std::string ReadXMLStringAttribute(const std::string& name, const char** atts); bool ReadXMLBooleanAttribute(const std::string& name, const char** atts); private: EventConfigPrivate* const d; }; struct EventConfigPrivate : public SharedData { EventConfigPrivate(); EventConfigPrivate(const EventConfigPrivate& other); struct EventMapping { std::string variantName; InteractionEvent::ConstPointer interactionEvent; }; /** * Checks if mapping with the same parameters already exists, if so, it is replaced, * else the new mapping added */ void InsertMapping(const EventMapping& mapping); /** * @brief List of all global properties of the config object. */ PropertyList::Pointer m_PropertyList; /** * @brief Temporal list of all prMousePressEventoperties of a Event. Used to parse an Input-Event and collect all parameters between the two * and tags. */ PropertyList::Pointer m_EventPropertyList; EventMapping m_CurrEventMapping; typedef std::list EventListType; /** * Stores InteractionEvents and their corresponding VariantName */ EventListType m_EventList; bool m_Errors; // use member, because of inheritance from vtkXMLParser we can't return a success value for parsing the file. EventConfigXMLParser m_XmlParser; }; } mitk::EventConfigPrivate::EventConfigPrivate() : m_PropertyList(PropertyList::New()) , m_Errors(false) , m_XmlParser(this) { // Avoid VTK warning: Trying to delete object with non-zero reference count. m_XmlParser.SetReferenceCount(0); } mitk::EventConfigPrivate::EventConfigPrivate(const EventConfigPrivate& other) : SharedData(other) , m_PropertyList(other.m_PropertyList->Clone()) , m_EventPropertyList(other.m_EventPropertyList->Clone()) , m_CurrEventMapping(other.m_CurrEventMapping) , m_EventList(other.m_EventList) , m_Errors(other.m_Errors) , m_XmlParser(this) { // Avoid VTK warning: Trying to delete object with non-zero reference count. m_XmlParser.SetReferenceCount(0); } void mitk::EventConfigPrivate::InsertMapping(const EventMapping& mapping) { for (EventListType::iterator it = m_EventList.begin(); it != m_EventList.end(); ++it) { if (*(it->interactionEvent) == *mapping.interactionEvent) { //MITK_INFO<< "Configuration overwritten:" << (*it).variantName; m_EventList.erase(it); break; } } m_EventList.push_back(mapping); } mitk::EventConfigXMLParser::EventConfigXMLParser(EventConfigPrivate *d) : d(d) { } void mitk::EventConfigXMLParser::StartElement(const char* elementName, const char **atts) { std::string name(elementName); - if (name == InteractionEventConst::xmlTagConfigRoot) + if (name == InteractionEventConst::xmlTagConfigRoot()) { // } - else if (name == InteractionEventConst::xmlTagParam) + else if (name == InteractionEventConst::xmlTagParam()) { - std::string name = ReadXMLStringAttribute(InteractionEventConst::xmlParameterName, atts); - std::string value = ReadXMLStringAttribute(InteractionEventConst::xmlParameterValue, atts); + std::string name = ReadXMLStringAttribute(InteractionEventConst::xmlParameterName(), atts); + std::string value = ReadXMLStringAttribute(InteractionEventConst::xmlParameterValue(), atts); d->m_PropertyList->SetStringProperty(name.c_str(), value.c_str()); } - else if (name == InteractionEventConst::xmlTagEventVariant) + else if (name == InteractionEventConst::xmlTagEventVariant()) { - std::string eventClass = ReadXMLStringAttribute(InteractionEventConst::xmlParameterEventClass, atts); - std::string eventVariant = ReadXMLStringAttribute(InteractionEventConst::xmlParameterName, atts); + std::string eventClass = ReadXMLStringAttribute(InteractionEventConst::xmlParameterEventClass(), atts); + std::string eventVariant = ReadXMLStringAttribute(InteractionEventConst::xmlParameterName(), atts); // New list in which all parameters are stored that are given within the tag d->m_EventPropertyList = PropertyList::New(); - d->m_EventPropertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass.c_str(), eventClass.c_str()); - d->m_EventPropertyList->SetStringProperty(InteractionEventConst::xmlParameterEventVariant.c_str(), eventVariant.c_str()); + d->m_EventPropertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), eventClass.c_str()); + d->m_EventPropertyList->SetStringProperty(InteractionEventConst::xmlParameterEventVariant().c_str(), eventVariant.c_str()); d->m_CurrEventMapping.variantName = eventVariant; } - else if (name == InteractionEventConst::xmlTagAttribute) + 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); + std::string name = ReadXMLStringAttribute(InteractionEventConst::xmlParameterName(), atts); + std::string value = ReadXMLStringAttribute(InteractionEventConst::xmlParameterValue(), atts); d->m_EventPropertyList->SetStringProperty(name.c_str(), value.c_str()); } } void mitk::EventConfigXMLParser::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) + if (name == InteractionEventConst::xmlTagEventVariant()) { InteractionEvent::Pointer event = EventFactory::CreateEvent(d->m_EventPropertyList); if (event.IsNotNull()) { d->m_CurrEventMapping.interactionEvent = event; d->InsertMapping(d->m_CurrEventMapping); } else { MITK_WARN<< "EventConfig: Unknown Event-Type in config. Entry skipped: " << name; } } } std::string mitk::EventConfigXMLParser::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::EventConfigXMLParser::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::EventConfig::EventConfig() : d(new EventConfigPrivate) { } mitk::EventConfig::EventConfig(const EventConfig &other) : d(other.d) { } mitk::EventConfig::EventConfig(const std::string& filename, const Module* module) : d(new EventConfigPrivate) { if (module == NULL) { module = GetModuleContext()->GetModule(); } mitk::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; } EventConfig newConfig; mitk::ModuleResourceStream stream(resource); newConfig.d->m_XmlParser.SetStream(&stream); bool success = newConfig.d->m_XmlParser.Parse() && !newConfig.d->m_Errors; if (success) { *this = newConfig; } } mitk::EventConfig::EventConfig(std::istream &inputStream) : d(new EventConfigPrivate) { EventConfig newConfig; newConfig.d->m_XmlParser.SetStream(&inputStream); bool success = newConfig.d->m_XmlParser.Parse() && !newConfig.d->m_Errors; if (success) { *this = newConfig; } } mitk::EventConfig::EventConfig(const std::vector &configDescription) : d(new EventConfigPrivate) { std::vector::const_iterator it_end = configDescription.end(); for (std::vector::const_iterator it = configDescription.begin(); it != it_end; ++it) { InteractionEvent::Pointer event = EventFactory::CreateEvent(*it); if (event.IsNotNull()) { d->m_CurrEventMapping.interactionEvent = event; std::string eventVariant; - (*it)->GetStringProperty(InteractionEventConst::xmlTagEventVariant.c_str(), eventVariant); + (*it)->GetStringProperty(InteractionEventConst::xmlTagEventVariant().c_str(), eventVariant); d->m_CurrEventMapping.variantName = eventVariant; d->InsertMapping(d->m_CurrEventMapping); } else { MITK_WARN<< "EventConfig: Unknown Event-Type in config. When constructing from PropertyList."; } } } mitk::EventConfig& mitk::EventConfig::operator =(const mitk::EventConfig& other) { d = other.d; return *this; } mitk::EventConfig::~EventConfig() { } bool mitk::EventConfig::IsValid() const { return !d->m_EventList.empty(); } bool mitk::EventConfig::AddConfig(const std::string& fileName, const Module* module) { if (module == NULL) { module = GetModuleContext()->GetModule(); } mitk::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 false; } EventConfig newConfig(*this); mitk::ModuleResourceStream stream(resource); newConfig.d->m_XmlParser.SetStream(&stream); bool success = newConfig.d->m_XmlParser.Parse() && !newConfig.d->m_Errors; if (success) { *this = newConfig; } return success; } bool mitk::EventConfig::AddConfig(const EventConfig& config) { if (!config.IsValid()) return false; d->m_PropertyList->ConcatenatePropertyList(config.d->m_PropertyList->Clone(), true); d->m_EventPropertyList = config.d->m_EventPropertyList->Clone(); d->m_CurrEventMapping = config.d->m_CurrEventMapping; d->InsertMapping(config.d->m_CurrEventMapping); return true; } mitk::PropertyList::Pointer mitk::EventConfig::GetAttributes() const { return d->m_PropertyList; } std::string mitk::EventConfig::GetMappedEvent(const EventType& interactionEvent) const { // internal events are excluded from mapping if (std::strcmp(interactionEvent->GetNameOfClass(), "InternalEvent") == 0) { InternalEvent* internalEvent = dynamic_cast(interactionEvent.GetPointer()); return internalEvent->GetSignalName(); } for (EventConfigPrivate::EventListType::const_iterator it = d->m_EventList.begin(); it != d->m_EventList.end(); ++it) { if (*(it->interactionEvent) == *interactionEvent) { return (*it).variantName; } } // if this part is reached, no mapping has been found, // so here we handle key events and map a key event to the string "Std" + letter/code // so "A" will be returned as "StdA" if (std::strcmp(interactionEvent->GetNameOfClass(), "InteractionKeyEvent") == 0) { InteractionKeyEvent* keyEvent = dynamic_cast(interactionEvent.GetPointer()); return ("Std" + keyEvent->GetKey()); } return ""; } void mitk::EventConfig::ClearConfig() { d->m_PropertyList->Clear(); d->m_EventPropertyList->Clear(); d->m_CurrEventMapping.variantName.clear(); d->m_CurrEventMapping.interactionEvent = NULL; d->m_EventList.clear(); d->m_Errors = false; } diff --git a/Core/Code/Interactions/mitkEventFactory.cpp b/Core/Code/Interactions/mitkEventFactory.cpp index ad26f7e4dc..31a2e08c7a 100755 --- a/Core/Code/Interactions/mitkEventFactory.cpp +++ b/Core/Code/Interactions/mitkEventFactory.cpp @@ -1,224 +1,224 @@ /*=================================================================== 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 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); + 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); // Parse modifier information - if (list->GetStringProperty(InteractionEventConst::xmlEventPropertyModifier.c_str(), strModifiers)) + 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)) + 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)) + 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)) + if (!list->GetStringProperty(InteractionEventConst::xmlEventPropertyKey().c_str(), strKey)) { key = ""; } else { key = strKey; } // WheelDelta - if (!list->GetStringProperty(InteractionEventConst::xmlEventPropertyScrollDirection.c_str(), strWheelDelta)) + 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); + list->GetStringProperty(InteractionEventConst::xmlEventPropertySignalName().c_str(), strSignalName); /* * 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); } else if (eventClass == "MOUSEMOVEEVENT") { event = MouseMoveEvent::New(NULL, pos, buttonState, modifiers); } else if (eventClass == "MOUSERELEASEEVENT") { event = MouseReleaseEvent::New(NULL, pos, buttonState, modifiers, eventButton); } else if (eventClass == "INTERACTIONKEYEVENT") { event = InteractionKeyEvent::New(NULL, key, modifiers); } else if (eventClass == "MOUSEWHEELEVENT") { event = MouseWheelEvent::New(NULL, pos, buttonState, modifiers, wheelDelta); } else if (eventClass == "INTERACTIONPOSITIONEVENT") { event = InteractionPositionEvent::New(NULL, pos); } else if (eventClass == "INTERNALEVENT") { event = InternalEvent::New(NULL, NULL, strSignalName); } else if (eventClass == "INTERACTIONEVENT") { event = InteractionEvent::New(NULL); } 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; } diff --git a/Core/Code/Interactions/mitkInteractionEventConst.cpp b/Core/Code/Interactions/mitkInteractionEventConst.cpp index 35fb858ed3..810d1377af 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.cpp +++ b/Core/Code/Interactions/mitkInteractionEventConst.cpp @@ -1,41 +1,107 @@ /*=================================================================== 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 { -// XML Tags -const std::string InteractionEventConst::xmlTagConfigRoot = "config"; -const std::string InteractionEventConst::xmlTagParam = "param"; -const std::string InteractionEventConst::xmlTagEventVariant = "event_variant"; -const std::string InteractionEventConst::xmlTagAttribute = "attribute"; - -// XML Param -const std::string InteractionEventConst::xmlParameterName = "name"; -const std::string InteractionEventConst::xmlParameterValue = "value"; -const std::string InteractionEventConst::xmlParameterEventVariant = "event_variant"; -const std::string InteractionEventConst::xmlParameterEventClass = "class"; - -// Event Description -const std::string InteractionEventConst::xmlEventPropertyModifier = "Modifiers"; -const std::string InteractionEventConst::xmlEventPropertyEventButton = "EventButton"; -const std::string InteractionEventConst::xmlEventPropertyButtonState = "ButtonState"; -const std::string InteractionEventConst::xmlEventPropertyKey = "Key"; -const std::string InteractionEventConst::xmlEventPropertyScrollDirection = "ScrollDirection"; -const std::string InteractionEventConst::xmlEventPropertySignalName = "SignalName"; +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::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::xmlEventPropertySignalName() +{ + static const std::string xmlEventPropertySignalName = "SignalName"; + return xmlEventPropertySignalName; +} + } diff --git a/Core/Code/Interactions/mitkInteractionEventConst.h b/Core/Code/Interactions/mitkInteractionEventConst.h index 37ef831324..fea72b994c 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.h +++ b/Core/Code/Interactions/mitkInteractionEventConst.h @@ -1,54 +1,53 @@ /*=================================================================== 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"; + 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"; + 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 xmlEventPropertyKey; // = "Key"; - static const std::string xmlEventPropertyScrollDirection; // = "ScrollDirection"; - static const std::string xmlEventPropertySignalName; // = "SignalName"; - + static const std::string xmlEventPropertyModifier(); // = "Modifiers"; + static const std::string xmlEventPropertyEventButton(); // = "EventButton"; + static const std::string xmlEventPropertyButtonState(); // = "ButtonState"; + static const std::string xmlEventPropertyKey(); // = "Key"; + static const std::string xmlEventPropertyScrollDirection(); // = "ScrollDirection"; + static const std::string xmlEventPropertySignalName(); // = "SignalName"; }; } //namespace mitk #endif //ifndef MITKINTERACTEVENTCONST_H diff --git a/Core/Code/Interactions/mitkStateMachineTransition.cpp b/Core/Code/Interactions/mitkStateMachineTransition.cpp index d5b629df0e..020d23e7ad 100755 --- a/Core/Code/Interactions/mitkStateMachineTransition.cpp +++ b/Core/Code/Interactions/mitkStateMachineTransition.cpp @@ -1,99 +1,99 @@ /*=================================================================== 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 "mitkStateMachineTransition.h" #include "mitkStateMachineAction.h" #include "mitkStateMachineState.h" #include "mitkEventFactory.h" #include "mitkInteractionEventConst.h" mitk::StateMachineTransition::StateMachineTransition(const std::string& nextStateName, const std::string& eventClass, const std::string& eventVariant) : m_EventClass(eventClass) , m_EventVariant(eventVariant) , m_NextStateName(nextStateName) { PropertyList::Pointer propertyList = PropertyList::New(); - propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass.c_str(), eventClass.c_str()); + propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), eventClass.c_str()); m_TransitionEvent = EventFactory::CreateEvent(propertyList); } bool mitk::StateMachineTransition::operator ==(const StateMachineTransition& transition) const { // Create event based on incoming event type, // then try to cast it to the type of event that this transition holds, // if this is possible, the variant is checked // check for NULL since a corrupted state machine might cause an empty event if (m_TransitionEvent.IsNull()) { return false; } PropertyList::Pointer propertyList = PropertyList::New(); - propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass.c_str(), transition.m_EventClass.c_str()); + propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), transition.m_EventClass.c_str()); InteractionEvent::Pointer tmpEvent = EventFactory::CreateEvent(propertyList); if (tmpEvent.IsNull()) { return false; } if (m_TransitionEvent->IsSuperClassOf(tmpEvent.GetPointer())) { return (this->m_EventVariant == transition.m_EventVariant); } else { // if event variants match, but super class condition is violated // this means that the configuration file, implements a class that does not // support the type in the state machine. if (this->m_EventVariant == transition.m_EventVariant) { MITK_WARN<< "Event type in Statemachine " << m_EventClass << " is not compatible to configuration class " << transition.m_EventClass; } return false; } } mitk::StateMachineTransition::~StateMachineTransition() { //needed for correct reference counting of mitkState//, for real??? m_NextState = NULL; m_Actions.clear(); } void mitk::StateMachineTransition::AddAction(const StateMachineAction::Pointer& action) { m_Actions.push_back(action); } mitk::StateMachineState::Pointer mitk::StateMachineTransition::GetNextState() const { return m_NextState; } std::string mitk::StateMachineTransition::GetNextStateName() const { return m_NextStateName; } std::vector mitk::StateMachineTransition::GetActions() const { return m_Actions; } void mitk::StateMachineTransition::SetNextState(const SpStateMachineState& nextState) { m_NextState = nextState; } diff --git a/Core/Code/Testing/mitkEventConfigTest.cpp b/Core/Code/Testing/mitkEventConfigTest.cpp index 2419f5ae7f..f3db0b9efd 100644 --- a/Core/Code/Testing/mitkEventConfigTest.cpp +++ b/Core/Code/Testing/mitkEventConfigTest.cpp @@ -1,151 +1,151 @@ /*=================================================================== 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 "mitkTestingMacros.h" #include "mitkEventConfig.h" #include "mitkPropertyList.h" #include "mitkInteractionEvent.h" #include "mitkInteractionEventConst.h" #include "mitkMouseMoveEvent.h" #include "mitkMouseWheelEvent.h" #include "mitkMouseReleaseEvent.h" #include "mitkInteractionKeyEvent.h" #include "mitkMousePressEvent.h" #include "mitkModule.h" #include "mitkGetModuleContext.h" #include #include #include int mitkEventConfigTest(int argc, char* argv[]) { MITK_TEST_BEGIN("EventConfig") if (argc != 2) { MITK_ERROR << "Test needs configuration test file as parameter."; return -1; } /* * Loads a test a Config file and test if Config is build up correctly, * and if mapping from mitkEvents to EventVariant names works properly. * Indirectly this also tests the EventFactory Class, since we also test if the events have been constructed properly. * * The configuration object is constructed in three different ways, * each one is tested here. */ // Construction using compiled-in resrouces: mitk::Module *module = mitk::GetModuleContext()->GetModule(); mitk::EventConfig newConfig("StatemachineConfigTest.xml",module); MITK_TEST_CONDITION_REQUIRED( newConfig.IsValid() == true , "01 Check if file can be loaded and is valid" ); /* * Test the global properties: * Test if stored values match the ones in the test config file. */ mitk::PropertyList::Pointer properties = newConfig.GetAttributes(); std::string prop1, prop2; MITK_TEST_CONDITION_REQUIRED( properties->GetStringProperty("property1",prop1) && prop1 == "yes" && properties->GetStringProperty("scrollModus",prop2) && prop2 == "leftright" , "02 Check Global Properties"); /* * Check if Events get mapped to the proper Variants */ mitk::Point2D pos; mitk::MousePressEvent::Pointer mpe1 = mitk::MousePressEvent::New(NULL,pos,mitk::InteractionEvent::MiddleMouseButton | mitk::InteractionEvent::LeftMouseButton ,mitk::InteractionEvent::ControlKey | mitk::InteractionEvent::AltKey,mitk::InteractionEvent::LeftMouseButton ); mitk::MousePressEvent::Pointer standard1 = mitk::MousePressEvent::New(NULL,pos,mitk::InteractionEvent::LeftMouseButton,mitk::InteractionEvent::NoKey ,mitk::InteractionEvent::LeftMouseButton ); mitk::MouseMoveEvent::Pointer mme1 = mitk::MouseMoveEvent::New(NULL,pos,mitk::InteractionEvent::RightMouseButton | mitk::InteractionEvent::LeftMouseButton,mitk::InteractionEvent::ShiftKey ); mitk::MouseMoveEvent::Pointer mme2 = mitk::MouseMoveEvent::New(NULL,pos,mitk::InteractionEvent::RightMouseButton,mitk::InteractionEvent::ShiftKey ); mitk::MouseWheelEvent::Pointer mwe1 = mitk::MouseWheelEvent::New(NULL,pos,mitk::InteractionEvent::RightMouseButton,mitk::InteractionEvent::ShiftKey,-2 ); mitk::InteractionKeyEvent::Pointer ke = mitk::InteractionKeyEvent::New(NULL,"l",mitk::InteractionEvent::NoKey ); MITK_TEST_CONDITION_REQUIRED( newConfig.GetMappedEvent(mpe1.GetPointer()) == "Variant1" && newConfig.GetMappedEvent(standard1.GetPointer()) == "Standard1" && newConfig.GetMappedEvent(mme1.GetPointer()) == "Move2" && newConfig.GetMappedEvent(ke.GetPointer()) == "Key1" && newConfig.GetMappedEvent(mme2.GetPointer()) == "" // does not exist in file , "03 Check Mouse- and Key-Events " ); // Construction providing a input stream std::ifstream configStream(argv[1]); mitk::EventConfig newConfig2(configStream); MITK_TEST_CONDITION_REQUIRED( newConfig2.IsValid() == true , "01 Check if file can be loaded and is valid" ); /* * Test the global properties: * Test if stored values match the ones in the test config file. */ properties = newConfig2.GetAttributes(); MITK_TEST_CONDITION_REQUIRED( properties->GetStringProperty("property1",prop1) && prop1 == "yes" && properties->GetStringProperty("scrollModus",prop2) && prop2 == "leftright" , "02 Check Global Properties"); /* * Check if Events get mapped to the proper Variants */ MITK_TEST_CONDITION_REQUIRED( newConfig2.GetMappedEvent(mpe1.GetPointer()) == "Variant1" && newConfig2.GetMappedEvent(standard1.GetPointer()) == "Standard1" && newConfig2.GetMappedEvent(mme1.GetPointer()) == "Move2" && newConfig2.GetMappedEvent(ke.GetPointer()) == "Key1" && newConfig2.GetMappedEvent(mme2.GetPointer()) == "" // does not exist in file , "03 Check Mouse- and Key-Events " ); // always end with this! // Construction providing a property list mitk::PropertyList::Pointer propertyList1 = mitk::PropertyList::New(); - propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass.c_str(), "MousePressEvent"); - propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant.c_str(), "MousePressEventVariant"); + propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MousePressEvent"); + propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(), "MousePressEventVariant"); propertyList1->SetStringProperty("Modifiers","CTRL,ALT"); mitk::PropertyList::Pointer propertyList2 = mitk::PropertyList::New(); - propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass.c_str(), "MOUSERELEASEEVENT"); - propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant.c_str(), "MouseReleaseEventVariant"); + propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MOUSERELEASEEVENT"); + propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(), "MouseReleaseEventVariant"); propertyList2->SetStringProperty("Modifiers","SHIFT"); std::vector* configDescription = new std::vector(); configDescription->push_back(propertyList1); configDescription->push_back(propertyList2); mitk::EventConfig newConfig3(*configDescription); mitk::MousePressEvent::Pointer mousePress1 = mitk::MousePressEvent::New(NULL,pos,mitk::InteractionEvent::NoButton,mitk::InteractionEvent::AltKey | mitk::InteractionEvent::ControlKey ,mitk::InteractionEvent::NoButton ); mitk::MouseReleaseEvent::Pointer mousePress2 = mitk::MouseReleaseEvent::New(NULL,pos,mitk::InteractionEvent::NoButton,mitk::InteractionEvent::ShiftKey ,mitk::InteractionEvent::NoButton ); MITK_TEST_CONDITION_REQUIRED( newConfig3.GetMappedEvent(mousePress1.GetPointer()) == "MousePressEventVariant" && newConfig3.GetMappedEvent(mousePress2.GetPointer()) == "MouseReleaseEventVariant" , "04 Check Mouseevents from PropertyLists" ); MITK_TEST_END() }