diff --git a/Core/Code/Interactions/mitkDataInteractor.cpp b/Core/Code/Interactions/mitkDataInteractor.cpp index 7567b5bd61..358b47ecac 100644 --- a/Core/Code/Interactions/mitkDataInteractor.cpp +++ b/Core/Code/Interactions/mitkDataInteractor.cpp @@ -1,93 +1,98 @@ /*=================================================================== 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 "mitkDataInteractor.h" #include "mitkInteractor.h" #include "mitkPointSet.h" #include "mitkDataNode.h" #include "mitkStateMachineState.h" +// Predefined internal events/signals +const std::string mitk::DataInteractor::IntDeactivateMe = "DeactivateMe"; +const std::string mitk::DataInteractor::IntLeaveWidget = "LeaveWidget"; +const std::string mitk::DataInteractor::IntEnterWidget = "EnterWidget"; + mitk::DataInteractor::DataInteractor() { } mitk::DataInteractor::NodeType mitk::DataInteractor::GetDataNode() const { return m_DataNode; } void mitk::DataInteractor::SetDataNode(DataNode::Pointer dataNode) { if (dataNode == m_DataNode) return; if (m_DataNode.IsNotNull()) { // if DataInteractors' DataNode is set to null, the "old" DataNode has to be notified (else the Dispatcher won't be notified either) m_DataNode->SetDataInteractor(NULL); } m_DataNode = dataNode; if (m_DataNode.IsNotNull()) { m_DataNode->SetDataInteractor(this); } // notify implementations ... DataNodeChanged(); } int mitk::DataInteractor::GetLayer() const { int layer = -1; if (m_DataNode.IsNotNull()) { m_DataNode->GetIntProperty("layer", layer); } return layer; } mitk::DataInteractor::~DataInteractor() { if (m_DataNode.IsNotNull()) { m_DataNode->SetInteractor(NULL); } } void mitk::DataInteractor::ConnectActionsAndFunctions() { MITK_WARN<< "ConnectActionsAndFunctions in DataInteractor not implemented.\n DataInteractor will not be able to process any events."; } mitk::ProcessEventMode mitk::DataInteractor::GetMode() const { if (GetCurrentState()->GetMode() == "PREFER_INPUT") { return PREFERINPUT; } if (GetCurrentState()->GetMode() == "GRAB_INPUT") { return GRABINPUT; } return REGULAR; } void mitk::DataInteractor::DataNodeChanged() { } diff --git a/Core/Code/Interactions/mitkDataInteractor.h b/Core/Code/Interactions/mitkDataInteractor.h index f85a2469e4..9fc9e8435e 100644 --- a/Core/Code/Interactions/mitkDataInteractor.h +++ b/Core/Code/Interactions/mitkDataInteractor.h @@ -1,100 +1,105 @@ /*=================================================================== 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 MITKEVENTINTERACTOR_H_ #define MITKEVENTINTERACTOR_H_ #include "itkSmartPointer.h" #include "itkObjectFactory.h" #include "mitkCommon.h" #include #include "mitkEventStateMachine.h" #include namespace mitk { /** * \class DataInteractor * * \brief Base class from with interactors that handle DataNodes are to be derived. * * Base class from with interactors that handle DataNodes are to be derived. * Provides an interface that is relevant for the interactor to work together with the dispatcher. * To implement a new interactor overwrite the ConnectActionsAndFunctions to connect the actions. */ // Public 'cause it's also used by the mitk::Dispatcher enum ProcessEventMode { REGULAR = 0, GRABINPUT = 1, PREFERINPUT = 2, CONNECTEDMOUSEACTION = 3 // only used by mitk::Dispatcher }; class DataNode; class MITK_CORE_EXPORT DataInteractor: public EventStateMachine { public: typedef itk::SmartPointer NodeType; mitkClassMacro(DataInteractor, EventStateMachine) itkNewMacro(Self) /** * Set/Change the DataNode of the DataInteractor */ void SetDataNode(NodeType); /** * @brief Returns the mode the DataInteractor currently is in. See in mitkDispatcher the description of m_ProcessingMode for further details. */ ProcessEventMode GetMode() const; NodeType GetDataNode() const; int GetLayer() const; + // Predefined internal events/signals + static const std::string IntDeactivateMe; // = "DeactivateMe"; + static const std::string IntLeaveWidget; // = "LeaveWidget"; + static const std::string IntEnterWidget; // = "EnterWidget"; + protected: DataInteractor(); virtual ~DataInteractor(); /** * @brief Overwrite this function to connect actions from StateMachine description with functions. * * Following example shows how to connect the 'addpoint' action from the StateMachine XML description using the CONNECT_FUNCTION macro * with the AddPoint() function in the TestInteractor. * @code * void mitk::TestInteractor::ConnectActionsAndFunctions() { CONNECT_FUNCTION("addpoint", AddPoint); } * @endcode */ virtual void ConnectActionsAndFunctions(); /** \brief Is called when a DataNode is initially set or changed * To be implemented by sub-classes for initialization code which require a DataNode. * \note New DataInteractors usually are expected to have the focus, but this only works if they have the highest Layer, * since empty DataNodes have a layer of -1, the DataNode must be filled here in order to get a layer assigned. * \note Is also called when the DataNode is set to NULL. */ virtual void DataNodeChanged(); private: NodeType m_DataNode; }; } /* namespace mitk */ #endif /* MITKEVENTINTERACTOR_H_ */ diff --git a/Core/Code/Interactions/mitkDispatcher.cpp b/Core/Code/Interactions/mitkDispatcher.cpp index a90637e3d8..6abc280f28 100644 --- a/Core/Code/Interactions/mitkDispatcher.cpp +++ b/Core/Code/Interactions/mitkDispatcher.cpp @@ -1,230 +1,231 @@ /*=================================================================== 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 "mitkDispatcher.h" #include "mitkInteractionEvent.h" #include "mitkInternalEvent.h" // MicroServices #include "mitkGetModuleContext.h" #include "mitkModule.h" #include "mitkModuleRegistry.h" #include "mitkInteractionEventObserver.h" mitk::Dispatcher::Dispatcher() : m_ProcessingMode(REGULAR) { m_EventObserverTracker = new mitk::ServiceTracker(GetModuleContext()); m_EventObserverTracker->Open(); } void mitk::Dispatcher::AddDataInteractor(const DataNode* dataNode) { RemoveDataInteractor(dataNode); RemoveOrphanedInteractors(); DataInteractor::Pointer dataInteractor = dataNode->GetDataInteractor(); if (dataInteractor.IsNotNull()) { m_Interactors.push_back(dataInteractor); } } /* * Note: One DataInteractor can only have one DataNode and vice versa, * BUT the m_Interactors list may contain another DataInteractor that is still connected to this DataNode, * in this case we have to remove >1 DataInteractor. (Some special case of switching DataNodes between DataInteractors and registering a * DataNode to a DataStorage after assigning it to an DataInteractor) */ void mitk::Dispatcher::RemoveDataInteractor(const DataNode* dataNode) { for (ListInteractorType::iterator it = m_Interactors.begin(); it != m_Interactors.end();) { if ((*it)->GetDataNode() == dataNode) { it = m_Interactors.erase(it); } else { ++it; } } } size_t mitk::Dispatcher::GetNumberOfInteractors() { return m_Interactors.size(); } mitk::Dispatcher::~Dispatcher() { m_EventObserverTracker->Close(); delete m_EventObserverTracker; } bool mitk::Dispatcher::ProcessEvent(InteractionEvent* event) { InteractionEvent::Pointer p = event; //MITK_INFO << event->GetEventClass(); bool eventIsHandled = false; /* Filter out and handle Internal Events separately */ InternalEvent* internalEvent = dynamic_cast(event); if (internalEvent != NULL) { eventIsHandled = HandleInternalEvent(internalEvent); // InternalEvents that are handled are not sent to the listeners if (eventIsHandled) { return true; } } switch (m_ProcessingMode) { case CONNECTEDMOUSEACTION: // finished connected mouse action if (p->GetEventClass() == "MouseReleaseEvent") { m_ProcessingMode = REGULAR; eventIsHandled = m_SelectedInteractor->HandleEvent(event, m_SelectedInteractor->GetDataNode()); } // give event to selected interactor if (eventIsHandled == false) { eventIsHandled = m_SelectedInteractor->HandleEvent(event, m_SelectedInteractor->GetDataNode()); } break; case GRABINPUT: eventIsHandled = m_SelectedInteractor->HandleEvent(event, m_SelectedInteractor->GetDataNode()); SetEventProcessingMode(m_SelectedInteractor); break; case PREFERINPUT: if (m_SelectedInteractor->HandleEvent(event, m_SelectedInteractor->GetDataNode()) == true) { SetEventProcessingMode(m_SelectedInteractor); eventIsHandled = true; } break; case REGULAR: break; } // Standard behavior. Is executed in STANDARD mode and PREFERINPUT mode, if preferred interactor rejects event. if (m_ProcessingMode == REGULAR || (m_ProcessingMode == PREFERINPUT && eventIsHandled == false)) { m_Interactors.sort(cmp()); // sorts interactors by layer (descending); for (std::list::iterator it = m_Interactors.begin(); it != m_Interactors.end(); ++it) { // explicit copy of pointer because HandleEvent function causes the m_Interactors list to be updated, // which in turn invalidates the iterator. DataInteractor::Pointer dataInteractor = *it; if (dataInteractor->HandleEvent(event, dataInteractor->GetDataNode())) { // if an event is handled several properties are checked, in order to determine the processing mode of the dispatcher SetEventProcessingMode(dataInteractor); if (p->GetEventClass() == "MousePressEvent" && m_ProcessingMode == REGULAR) { m_SelectedInteractor = dataInteractor; m_ProcessingMode = CONNECTEDMOUSEACTION; } eventIsHandled = true; break; } } } /* Notify InteractionEventObserver */ std::list listEventObserver; m_EventObserverTracker->GetServiceReferences(listEventObserver); for (std::list::iterator it = listEventObserver.begin(); it != listEventObserver.end(); ++it) { InteractionEventObserver* interactionEventObserver = m_EventObserverTracker->GetService(*it); if (interactionEventObserver != NULL) { if (interactionEventObserver->IsEnabled()) { interactionEventObserver->Notify(event, eventIsHandled); } } } // Process event queue if (!m_QueuedEvents.empty()) { InteractionEvent::Pointer e = m_QueuedEvents.front(); m_QueuedEvents.pop_front(); ProcessEvent(e); } return eventIsHandled; } /* * Checks if DataNodes associated with DataInteractors point back to them. * If not remove the DataInteractors. (This can happen when s.o. tries to set DataNodes to multiple DataInteractors) */ void mitk::Dispatcher::RemoveOrphanedInteractors() { for (ListInteractorType::iterator it = m_Interactors.begin(); it != m_Interactors.end();) { DataNode::Pointer dn = (*it)->GetDataNode(); if (dn.IsNull()) { it = m_Interactors.erase(it); } else { DataInteractor::Pointer interactor = dn->GetDataInteractor(); if (interactor != it->GetPointer()) { it = m_Interactors.erase(it); } else { ++it; } } } } void mitk::Dispatcher::QueueEvent(InteractionEvent* event) { m_QueuedEvents.push_back(event); } void mitk::Dispatcher::SetEventProcessingMode(DataInteractor::Pointer dataInteractor) { m_ProcessingMode = dataInteractor->GetMode(); if (dataInteractor->GetMode() != REGULAR) { m_SelectedInteractor = dataInteractor; } } bool mitk::Dispatcher::HandleInternalEvent(InternalEvent* internalEvent) { - if (internalEvent->GetSignalName() == IntDeactivateMe && internalEvent->GetTargetInteractor() != NULL) + if (internalEvent->GetSignalName() == DataInteractor::IntDeactivateMe && + internalEvent->GetTargetInteractor() != NULL) { internalEvent->GetTargetInteractor()->GetDataNode()->SetDataInteractor(NULL); internalEvent->GetTargetInteractor()->SetDataNode(NULL); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); return true; } return false; } diff --git a/Core/Code/Interactions/mitkEventConfig.cpp b/Core/Code/Interactions/mitkEventConfig.cpp index d79146ea2d..e828c13e0a 100755 --- a/Core/Code/Interactions/mitkEventConfig.cpp +++ b/Core/Code/Interactions/mitkEventConfig.cpp @@ -1,196 +1,302 @@ /*=================================================================== 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 -#include -#include -#include -#include + #include "mitkEventFactory.h" #include "mitkInteractionEvent.h" #include "mitkInternalEvent.h" #include "mitkInteractionKeyEvent.h" #include "mitkInteractionEventConst.h" + +// VTK +#include +#include + // us #include "mitkModule.h" #include "mitkModuleResource.h" #include "mitkModuleResourceStream.h" #include "mitkModuleRegistry.h" -namespace mitk +namespace mitk { + +class EventConfigXMLParser : public vtkXMLParser { - vtkStandardNewMacro(EventConfig); -} -mitk::EventConfig::EventConfig() : - m_Errors(false) +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 { - if (m_PropertyList.IsNull()) + + EventConfigPrivate(); + EventConfigPrivate(const EventConfigPrivate& other); + + struct EventMapping { - m_PropertyList = PropertyList::New(); - } + 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 properties 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::EventConfig::~EventConfig() + +mitk::EventConfigPrivate::EventConfigPrivate() + : m_PropertyList(PropertyList::New()) + , m_Errors(false) + , m_XmlParser(this) +{ +} + +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) { } -void mitk::EventConfig::InsertMapping(EventMapping mapping) +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); } -/** - * @brief Loads the xml file filename and generates the necessary instances. - **/ -bool mitk::EventConfig::LoadConfig(const std::string& fileName, const std::string& moduleName) +mitk::EventConfigXMLParser::EventConfigXMLParser(EventConfigPrivate *d) + : d(d) { - mitk::Module* module = mitk::ModuleRegistry::GetModule(moduleName); - mitk::ModuleResource resource = module->GetResource("Interactions/" + fileName); - if (!resource.IsValid()) - { - mitkThrow()<< ("Resource not valid. State machine pattern not found:" + fileName); - } - mitk::ModuleResourceStream stream(resource); - this->SetStream(&stream); - return this->Parse() && !m_Errors; } -void mitk::EventConfig::StartElement(const char* elementName, const char **atts) +void mitk::EventConfigXMLParser::StartElement(const char* elementName, const char **atts) { std::string name(elementName); - if (name == xmlTagConfigRoot) + if (name == InteractionEventConst::xmlTagConfigRoot) { // } - else if (name == xmlTagParam) + else if (name == InteractionEventConst::xmlTagParam) { - std::string name = ReadXMLStringAttribut(xmlParameterName, atts); - std::string value = ReadXMLStringAttribut(xmlParameterValue, atts); - m_PropertyList->SetStringProperty(name.c_str(), value.c_str()); + 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 == xmlTagEventVariant) + else if (name == InteractionEventConst::xmlTagEventVariant) { - std::string eventClass = ReadXMLStringAttribut(xmlParameterEventClass, atts); - std::string eventVariant = ReadXMLStringAttribut(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 - m_EventPropertyList = PropertyList::New(); - m_EventPropertyList->SetStringProperty(xmlParameterEventClass.c_str(), eventClass.c_str()); - m_EventPropertyList->SetStringProperty(xmlParameterEventVariant.c_str(), eventVariant.c_str()); - m_CurrEventMapping.variantName = eventVariant; + 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_CurrEventMapping.variantName = eventVariant; } - else if (name == 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 = ReadXMLStringAttribut(xmlParameterName, atts); - std::string value = ReadXMLStringAttribut(xmlParameterValue, atts); - m_EventPropertyList->SetStringProperty(name.c_str(), value.c_str()); + 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::EventConfig::EndElement(const char* elementName) +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 == xmlTagEventVariant) + if (name == InteractionEventConst::xmlTagEventVariant) { - InteractionEvent::Pointer event = EventFactory::CreateEvent(m_EventPropertyList); + InteractionEvent::Pointer event = EventFactory::CreateEvent(d->m_EventPropertyList); if (event.IsNotNull()) { - m_CurrEventMapping.interactionEvent = event; - InsertMapping(m_CurrEventMapping); + 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::EventConfig::ReadXMLStringAttribut(const std::string& name, const char** atts) +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& 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::LoadConfig(const std::string& fileName, const std::string& moduleName) +{ + mitk::Module* module = mitk::ModuleRegistry::GetModule(moduleName); + mitk::ModuleResource resource = module->GetResource("Interactions/" + fileName); + if (!resource.IsValid()) + { + mitkThrow()<< ("Resource not valid. State machine pattern not found:" + fileName); + } + mitk::ModuleResourceStream stream(resource); + d->m_XmlParser.SetStream(&stream); + return d->m_XmlParser.Parse() && !d->m_Errors; +} + mitk::PropertyList::Pointer mitk::EventConfig::GetAttributes() const { - return m_PropertyList; + return d->m_PropertyList; } std::string mitk::EventConfig::GetMappedEvent(const EventType& interactionEvent) const { // internal events are excluded from mapping - if (interactionEvent->GetEventClass() == "InternalEvent") + if (interactionEvent->GetNameOfClass() == "InternalEvent") { InternalEvent* internalEvent = dynamic_cast(interactionEvent.GetPointer()); return internalEvent->GetSignalName(); } - for (EventListType::const_iterator it = m_EventList.begin(); it != m_EventList.end(); ++it) + 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 (interactionEvent->GetEventClass() == "KeyEvent") + if (interactionEvent->GetNameOfClass() == "InteractionKeyEvent") { InteractionKeyEvent* keyEvent = dynamic_cast(interactionEvent.GetPointer()); return ("Std" + keyEvent->GetKey()); } return ""; } void mitk::EventConfig::ClearConfig() { - m_EventList.clear(); -} - -bool mitk::EventConfig::ReadXMLBooleanAttribut(const std::string& name, const char** atts) -{ - std::string s = ReadXMLStringAttribut(name, atts); - std::transform(s.begin(), s.end(), s.begin(), ::toupper); - - return s == "TRUE"; + d->m_EventList.clear(); } diff --git a/Core/Code/Interactions/mitkEventConfig.h b/Core/Code/Interactions/mitkEventConfig.h index 7f1dddc952..b7ebdae1e1 100755 --- a/Core/Code/Interactions/mitkEventConfig.h +++ b/Core/Code/Interactions/mitkEventConfig.h @@ -1,144 +1,102 @@ /*=================================================================== 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 mitkStateMachineConfig_h #define mitkStateMachineConfig_h -#include -#include -#include "mitkCommon.h" #include -#include -#include + +#include "mitkSharedData.h" +#include "mitkPropertyList.h" + +#include "itkSmartPointer.h" namespace mitk { class InteractionEvent; - - class EventConfigReader: public vtkXMLParser - { - public: - - private: - }; + struct EventConfigPrivate; /** * \class EventConfig * \brief Configuration Object for Statemachines. * * Reads given config file, which translates specific user inputs (InteractionEvents) into EventVariants that can be processed * by the StateMachine. * Refer to \ref ConfigFileDescriptionSection . * * @ingroup Interaction **/ - - class EventConfig: public vtkXMLParser + class MITK_CORE_EXPORT EventConfig { + public: - static EventConfig *New(); - vtkTypeMacro(EventConfig,vtkXMLParser) + typedef itk::SmartPointer EventType; + /** + * @brief Constructs an invalid EventConfig object. + * + * Call LoadConfig to create a valid configuration object. + */ + EventConfig(); + EventConfig(const EventConfig& other); - typedef itk::SmartPointer EventType; + EventConfig& operator=(const EventConfig& other); + + ~EventConfig(); + + /** + * @brief Checks wether this EventConfig object is valid. + * @return Returns \c true if a configuration was successfully loaded, \c false otherwise. + */ + bool IsValid() const; /** * @brief Loads XML resource * * Loads a XML resource file in the given module context. * The files have to be placed in the Resources/Interaction folder of their respective module. **/ bool LoadConfig(const std::string& fileName, const std::string& moduleName = "Mitk"); void ClearConfig(); + /** * Returns a PropertyList that contains the properties set in the configuration file. * All properties are stored as strings. */ PropertyList::Pointer GetAttributes() const; /** * Checks if the config object has a definition for the given event. If it has, the corresponding variant name is returned, else * an empty string is returned. * \note mitk::InternalEvents are handled differently. Their signal name is returned as event variant. So there is no need * to configure them in a config file. * \note mitk::InteractionKeys may have a defined event variant, if this is the case, this function returns it. If no * such definition is found key events are mapped to Std + Key , so an 'A' will be return as 'StdA' . */ std::string GetMappedEvent(const EventType& interactionEvent) const; - protected: - - EventConfig(); - virtual ~EventConfig(); - - /** - * @brief Derived from XMLReader - **/ - void StartElement(const char* elementName, const char **atts); - /** - * @brief Derived from XMLReader - **/ - void EndElement(const char* elementName); - private: - /** - * @brief Derived from XMLReader - **/ - std::string ReadXMLStringAttribut(const std::string& name, const char** atts); - /** - * @brief Derived from XMLReader - **/ - bool ReadXMLBooleanAttribut(const std::string& name, const char** atts); - - /** - * @brief List of all global properties of the config object. - */ - PropertyList::Pointer m_PropertyList; - - /** - * @brief Temporal list of all properties of a Event. Used to parse an Input-Event and collect all parameters between the two - * and tags. - */ - PropertyList::Pointer m_EventPropertyList; - struct EventMapping - { - std::string variantName; - EventType interactionEvent; - }; + SharedDataPointer d; - /** - * Checks if mapping with the same parameters already exists, if so, it is replaced, - * else the new mapping added - */ - void InsertMapping(EventMapping mapping); - - typedef std::list EventListType; - EventMapping m_CurrEventMapping; - - /** - * 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. }; } // namespace mitk #endif /* mitkStateMachineConfig_h */ diff --git a/Core/Code/Interactions/mitkEventFactory.cpp b/Core/Code/Interactions/mitkEventFactory.cpp index 9fcc7d3078..fcb08c9c80 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(xmlParameterEventClass.c_str(), eventClass); - list->GetStringProperty(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; - ModifierKeys modifiers = NoKey; + InteractionEvent::ModifierKeys modifiers = InteractionEvent::NoKey; std::string strEventButton; - MouseButtons eventButton = NoButton; + InteractionEvent::MouseButtons eventButton = InteractionEvent::NoButton; std::string strButtonState; - MouseButtons buttonState = NoButton; + 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(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 | ControlKey; + modifiers = modifiers | InteractionEvent::ControlKey; } else if (*it == "ALT") { - modifiers = modifiers | AltKey; + modifiers = modifiers | InteractionEvent::AltKey; } else if (*it == "SHIFT") { - modifiers = modifiers | ShiftKey; + modifiers = modifiers | InteractionEvent::ShiftKey; } else { MITK_WARN<< "mitkEventFactory: Invalid event modifier in config file :" << (*it); } } } // Set EventButton - if (list->GetStringProperty(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 = MiddleMouseButton; + eventButton = InteractionEvent::MiddleMouseButton; } else if (strEventButton == "LEFTMOUSEBUTTON") { - eventButton = LeftMouseButton; + eventButton = InteractionEvent::LeftMouseButton; } else if (strEventButton == "RIGHTMOUSEBUTTON") { - eventButton = RightMouseButton; + eventButton = InteractionEvent::RightMouseButton; } else { MITK_WARN<< "mitkEventFactory: Invalid event button in config file: " << strEventButton; } } // Parse ButtonStates - if (list->GetStringProperty(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 | MiddleMouseButton; + buttonState = buttonState | InteractionEvent::MiddleMouseButton; } else if (*it == "LEFTMOUSEBUTTON") { - buttonState = buttonState | LeftMouseButton; + buttonState = buttonState | InteractionEvent::LeftMouseButton; } else if (*it == "RIGHTMOUSEBUTTON") { - buttonState = buttonState | RightMouseButton; + buttonState = buttonState | InteractionEvent::RightMouseButton; } else { MITK_WARN<< "mitkEventFactory: Invalid event buttonstate in config file:" << (*it); } } } // Key - if (!list->GetStringProperty(xmlEventPropertyKey.c_str(), strKey)) + if (!list->GetStringProperty(InteractionEventConst::xmlEventPropertyKey.c_str(), strKey)) { key = ""; } else { key = strKey; } // WheelDelta - if (!list->GetStringProperty(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(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 == "KEYEVENT") { event = InteractionKeyEvent::New(NULL, key, modifiers); } else if (eventClass == "MOUSEWHEELEVENT") { event = MouseWheelEvent::New(NULL, pos, buttonState, modifiers, wheelDelta); } else if (eventClass == "POSITIONEVENT") { event = InteractionPositionEvent::New(NULL, pos, "PositionEvent"); } else if (eventClass == "INTERNALEVENT") { event = InternalEvent::New(NULL, NULL, strSignalName); } else if (eventClass == "INTERACTIONEVENT") { event = InteractionEvent::New(NULL, strSignalName); } 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/mitkInteractionEvent.cpp b/Core/Code/Interactions/mitkInteractionEvent.cpp index 46a269f0e4..0a207c8280 100644 --- a/Core/Code/Interactions/mitkInteractionEvent.cpp +++ b/Core/Code/Interactions/mitkInteractionEvent.cpp @@ -1,63 +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. ===================================================================*/ #include "mitkException.h" #include "mitkInteractionEvent.h" +const std::string mitk::InteractionEvent::KeyEsc = "Escape"; +const std::string mitk::InteractionEvent::KeyEnter = "Enter"; +const std::string mitk::InteractionEvent::KeyReturn = "Return"; +const std::string mitk::InteractionEvent::KeyDelete = "Delete"; +const std::string mitk::InteractionEvent::KeyArrowUp = "ArrowUp"; +const std::string mitk::InteractionEvent::KeyArrowDown = "ArrowDown"; +const std::string mitk::InteractionEvent::KeyArrowLeft = "ArrowLeft"; +const std::string mitk::InteractionEvent::KeyArrowRight = "ArrowRight"; + +const std::string mitk::InteractionEvent::KeyF1 = "F1"; +const std::string mitk::InteractionEvent::KeyF2 = "F2"; +const std::string mitk::InteractionEvent::KeyF3 = "F3"; +const std::string mitk::InteractionEvent::KeyF4 = "F4"; +const std::string mitk::InteractionEvent::KeyF5 = "F5"; +const std::string mitk::InteractionEvent::KeyF6 = "F6"; +const std::string mitk::InteractionEvent::KeyF7 = "F7"; +const std::string mitk::InteractionEvent::KeyF8 = "F8"; +const std::string mitk::InteractionEvent::KeyF9 = "F9"; +const std::string mitk::InteractionEvent::KeyF10 = "F10"; +const std::string mitk::InteractionEvent::KeyF11 = "F11"; +const std::string mitk::InteractionEvent::KeyF12 = "F12"; + +const std::string mitk::InteractionEvent::KeyPos1 = "Pos1"; +const std::string mitk::InteractionEvent::KeyEnd = "End"; +const std::string mitk::InteractionEvent::KeyInsert = "Insert"; +const std::string mitk::InteractionEvent::KeyPageUp = "PageUp"; +const std::string mitk::InteractionEvent::KeyPageDown = "PageDown"; +const std::string mitk::InteractionEvent::KeySpace = "Space"; + mitk::InteractionEvent::InteractionEvent(BaseRenderer* baseRenderer, const std::string& eventClass) : m_Sender(baseRenderer) , m_EventClass(eventClass) { } void mitk::InteractionEvent::SetSender(mitk::BaseRenderer* sender) { m_Sender = sender; } mitk::BaseRenderer* mitk::InteractionEvent::GetSender() const { return m_Sender; } bool mitk::InteractionEvent::IsEqual(const InteractionEvent&) const { return true; } mitk::InteractionEvent::~InteractionEvent() { } bool mitk::InteractionEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const { return (dynamic_cast(baseClass.GetPointer()) != NULL) ; } std::string mitk::InteractionEvent::GetEventClass() const { return m_EventClass; } bool mitk::operator==(const InteractionEvent& a, const InteractionEvent& b) { return (typeid(a) == typeid(b) && a.IsEqual(b)); } bool mitk::operator!=(const InteractionEvent& a, const InteractionEvent& b) { return !(a == b); } diff --git a/Core/Code/Interactions/mitkInteractionEvent.h b/Core/Code/Interactions/mitkInteractionEvent.h index adf189adf2..c61d5301f3 100644 --- a/Core/Code/Interactions/mitkInteractionEvent.h +++ b/Core/Code/Interactions/mitkInteractionEvent.h @@ -1,79 +1,157 @@ /*=================================================================== 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 MITKINTERACTIONEVENT_H_ #define MITKINTERACTIONEVENT_H_ #include "itkLightObject.h" #include "itkObjectFactory.h" #include "mitkCommon.h" #include "mitkBaseRenderer.h" #include #include namespace mitk { class MITK_CORE_EXPORT InteractionEvent: public itk::LightObject { public: mitkClassMacro(InteractionEvent,itk::LightObject) mitkNewMacro2Param(Self,BaseRenderer*, const std::string&) void SetSender(BaseRenderer* sender); BaseRenderer* GetSender() const; /** * Return unique string identifier that gives the event class of this object, as it can be used in a state machine pattern. * --- itk */ std::string GetEventClass() const; /** * This class implements an up cast to check if the provided baseClass object is derived from this class. * This function is used to support polymorphism on state machine pattern (XML) level. */ virtual bool IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const; + /** + * Mouse/keyboard state values + */ + enum MouseButtons + { + NoButton = 0x0000, + LeftMouseButton = 0x0001, + RightMouseButton = 0x0002, + MiddleMouseButton = 0x0004 + }; + + enum ModifierKeys + { + NoKey = 0x0000, + ShiftKey = 0x0100, + ControlKey = 0x0200, + AltKey = 0x0400 + }; + + /** + * KeyConstants Constants for special keys + */ + // Special Keys + static const std::string KeyEsc; // = "Escape"; + static const std::string KeyEnter; // = "Enter"; + static const std::string KeyReturn; // = "Return"; + static const std::string KeyDelete; // = "Delete"; + static const std::string KeyArrowUp; // = "ArrowUp"; + static const std::string KeyArrowDown; // = "ArrowDown"; + static const std::string KeyArrowLeft; // = "ArrowLeft"; + static const std::string KeyArrowRight; // = "ArrowRight"; + + static const std::string KeyF1; // = "F1"; + static const std::string KeyF2; // = "F2"; + static const std::string KeyF3; // = "F3"; + static const std::string KeyF4; // = "F4"; + static const std::string KeyF5; // = "F5"; + static const std::string KeyF6; // = "F6"; + static const std::string KeyF7; // = "F7"; + static const std::string KeyF8; // = "F8"; + static const std::string KeyF9; // = "F9"; + static const std::string KeyF10; // = "F10"; + static const std::string KeyF11; // = "F11"; + static const std::string KeyF12; // = "F12"; + + static const std::string KeyPos1; // = "Pos1"; + static const std::string KeyEnd; // = "End"; + static const std::string KeyInsert; // = "Insert"; + static const std::string KeyPageUp; // = "PageUp"; + static const std::string KeyPageDown; // = "PageDown"; + static const std::string KeySpace; // = "Space"; + // End special keys + protected: InteractionEvent(BaseRenderer*, const std::string&); virtual ~InteractionEvent(); friend MITK_CORE_EXPORT bool operator==(const InteractionEvent&, const InteractionEvent&); virtual bool IsEqual(const InteractionEvent& other) const; private: BaseRenderer* m_Sender; std::string m_EventClass; }; /** * Implementation of equality for event classes. * Equality does \b not mean an exact copy or pointer equality. * * A match is determined by agreement in all attributes that are necessary to describe * the event for a state machine transition. * E.g. for a mouse event press event, it is important which modifiers are used, * which mouse button was used to triggered the event, but the mouse position is irrelevant. */ MITK_CORE_EXPORT bool operator==(const InteractionEvent& a, const InteractionEvent& b); MITK_CORE_EXPORT bool operator!=(const InteractionEvent& a, const InteractionEvent& b); + /* + * Allow bitwise OR operation on enums. + */ + inline InteractionEvent::MouseButtons operator|(InteractionEvent::MouseButtons a, InteractionEvent::MouseButtons b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + + inline InteractionEvent::MouseButtons& operator|=(InteractionEvent::MouseButtons& a, InteractionEvent::MouseButtons& b) + { + a = static_cast(static_cast(a) | static_cast(b)); + return a; + } + + inline InteractionEvent::ModifierKeys operator|(InteractionEvent::ModifierKeys a, InteractionEvent::ModifierKeys b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + + inline InteractionEvent::ModifierKeys& operator|=(InteractionEvent::ModifierKeys& a, InteractionEvent::ModifierKeys& b) + { + a = static_cast(static_cast(a) | static_cast(b)); + return a; + } + } /* namespace mitk */ #endif /* MITKINTERACTIONEVENT_H_ */ diff --git a/Core/Code/Interactions/mitkInteractionEventConst.cpp b/Core/Code/Interactions/mitkInteractionEventConst.cpp new file mode 100644 index 0000000000..35fb858ed3 --- /dev/null +++ b/Core/Code/Interactions/mitkInteractionEventConst.cpp @@ -0,0 +1,41 @@ +/*=================================================================== + + 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"; + +} diff --git a/Core/Code/Interactions/mitkInteractionEventConst.h b/Core/Code/Interactions/mitkInteractionEventConst.h index cc06f391fd..754ed83c23 100644 --- a/Core/Code/Interactions/mitkInteractionEventConst.h +++ b/Core/Code/Interactions/mitkInteractionEventConst.h @@ -1,132 +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 -//##Documentation -//## @file mitkInteractionEventConst.h -//## @brief Constants to describe Mouse Events and special Key Events. - #include namespace mitk { -//##ButtonState -// Mouse/keyboard state values - enum MouseButtons - { - NoButton = 0x0000, - LeftMouseButton = 0x0001, - RightMouseButton = 0x0002, - MiddleMouseButton = 0x0004, - }; - - enum ModifierKeys - { - NoKey = 0x0000, - ShiftKey = 0x0100, - ControlKey = 0x0200, - AltKey = 0x0400 - }; - - /* - * Allow bitwise OR operation on enums. - */ - inline MouseButtons operator|(MouseButtons a, MouseButtons b) - { - return static_cast(static_cast(a) | static_cast(b)); - } - - inline MouseButtons& operator|=(MouseButtons& a, MouseButtons& b) - { - a = static_cast(static_cast(a) | static_cast(b)); - return a; - } - - inline ModifierKeys operator|(ModifierKeys a, ModifierKeys b) - { - return static_cast(static_cast(a) | static_cast(b)); - } - - inline ModifierKeys& operator|=(ModifierKeys& a, ModifierKeys& b) - { - a = static_cast(static_cast(a) | static_cast(b)); - return a; - } - - /** - * KeyConstants Constants for special keys - */ - // Special Keys - const std::string KeyEsc = "Escape"; - const std::string KeyEnter = "Enter"; - const std::string KeyReturn = "Return"; - const std::string KeyDelete = "Delete"; - const std::string KeyArrowUp = "ArrowUp"; - const std::string KeyArrowDown = "ArrowDown"; - const std::string KeyArrowLeft = "ArrowLeft"; - const std::string KeyArrowRight = "ArrowRight"; - - const std::string KeyF1 = "F1"; - const std::string KeyF2 = "F2"; - const std::string KeyF3 = "F3"; - const std::string KeyF4 = "F4"; - const std::string KeyF5 = "F5"; - const std::string KeyF6 = "F6"; - const std::string KeyF7 = "F7"; - const std::string KeyF8 = "F8"; - const std::string KeyF9 = "F9"; - const std::string KeyF10 = "F10"; - const std::string KeyF11 = "F11"; - const std::string KeyF12 = "F12"; - - const std::string KeyPos1 = "Pos1"; - const std::string KeyEnd = "End"; - const std::string KeyInsert = "Insert"; - const std::string KeyPageUp = "PageUp"; - const std::string KeyPageDown = "PageDown"; - const std::string KeySpace = "Space"; - // End special keys - +/** + * @brief Constants to describe Mouse Events and special Key Events. + */ +struct InteractionEventConst +{ // XML Tags - const std::string xmlTagConfigRoot = "config"; - const std::string xmlTagParam = "param"; - const std::string xmlTagEventVariant = "event_variant"; - 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 - const std::string xmlParameterName = "name"; - const std::string xmlParameterValue = "value"; - const std::string xmlParameterEventVariant = "event_variant"; - 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 - const std::string xmlEventPropertyModifier = "Modifiers"; - const std::string xmlEventPropertyEventButton = "EventButton"; - const std::string xmlEventPropertyButtonState = "ButtonState"; - const std::string xmlEventPropertyKey = "Key"; - const std::string xmlEventPropertyScrollDirection = "ScrollDirection"; - const std::string xmlEventPropertySignalName = "SignalName"; - - // Predefined internal events/signals - const std::string IntDeactivateMe = "DeactivateMe"; - const std::string IntLeaveWidget = "LeaveWidget"; - const std::string IntEnterWidget = "EnterWidget"; + 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/mitkInteractionEventHandler.cpp b/Core/Code/Interactions/mitkInteractionEventHandler.cpp index 16a622a58e..2aa5d57bf5 100644 --- a/Core/Code/Interactions/mitkInteractionEventHandler.cpp +++ b/Core/Code/Interactions/mitkInteractionEventHandler.cpp @@ -1,75 +1,77 @@ /*=================================================================== 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 "mitkInteractionEventHandler.h" #include "mitkInteractionEvent.h" -mitk::InteractionEventHandler::InteractionEventHandler(): - m_EventConfig(NULL) +mitk::InteractionEventHandler::InteractionEventHandler() + : m_EventConfig() { } mitk::InteractionEventHandler::~InteractionEventHandler() { } bool mitk::InteractionEventHandler::LoadEventConfig(const std::string& filename, const std::string& moduleName) { - m_EventConfig = vtkSmartPointer::New(); // notify sub-classes that new config is set - bool success = m_EventConfig->LoadConfig(filename, moduleName); + bool success = m_EventConfig.LoadConfig(filename, moduleName); ConfigurationChanged(); return success; } bool mitk::InteractionEventHandler::AddEventConfig(const std::string& filename, const std::string& moduleName) { - if (m_EventConfig == NULL) + if (!m_EventConfig.IsValid()) { MITK_ERROR<< "LoadEventConfig has to be called before AddEventConfig can be used."; return false; } // notify sub-classes that new config is set - bool success = m_EventConfig->LoadConfig(filename, moduleName); + bool success = m_EventConfig.LoadConfig(filename, moduleName); ConfigurationChanged(); return success; } mitk::PropertyList::Pointer mitk::InteractionEventHandler::GetAttributes() const { - if (m_EventConfig != NULL) { - return m_EventConfig->GetAttributes(); - } else { + if (m_EventConfig.IsValid()) + { + return m_EventConfig.GetAttributes(); + } + else + { MITK_ERROR << "InteractionEventHandler::GetAttributes() requested, but not configuration loaded."; return NULL; } } std::string mitk::InteractionEventHandler::MapToEventVariant(InteractionEvent* interactionEvent) { - if (m_EventConfig != NULL) + if (m_EventConfig.IsValid()) { - return m_EventConfig->GetMappedEvent(interactionEvent); + return m_EventConfig.GetMappedEvent(interactionEvent); } else { return ""; } } void mitk::InteractionEventHandler::ConfigurationChanged() { } diff --git a/Core/Code/Interactions/mitkInteractionEventHandler.h b/Core/Code/Interactions/mitkInteractionEventHandler.h index 2340013bba..5a34256136 100644 --- a/Core/Code/Interactions/mitkInteractionEventHandler.h +++ b/Core/Code/Interactions/mitkInteractionEventHandler.h @@ -1,84 +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 MITKEVENTHANDLER_H_ #define MITKEVENTHANDLER_H_ #include "itkLightObject.h" #include "itkObjectFactory.h" -#include "mitkEvent.h" + #include "mitkCommon.h" #include #include "mitkEventConfig.h" #include "mitkPropertyList.h" -#include + #include namespace mitk { /** * \class EventHandler * Serves as a base class for all objects and classes that handle mitk::InteractionEvents. * * It provides an interface to load configuration objects map of events to variant names. */ class InteractionEvent; class MITK_CORE_EXPORT InteractionEventHandler : public itk::LightObject { public: mitkClassMacro(InteractionEventHandler, itk::LightObject) itkNewMacro(Self) /** * @brief Loads XML resource * * Loads a XML resource file in the given module context. * Default is the Mitk module (core). * The files have to be placed in the Resources/Interaction folder of their respective module. * This method will remove all existing configuration and replaces it with the new one. */ virtual bool LoadEventConfig(const std::string& filename, const std::string& moduleName = "Mitk"); /** * This method EXTENDs the configuration. * The configuration from the resource provided is loaded and only the ones conflicting are replaced by the new one. * This way several configuration files can be combined */ virtual bool AddEventConfig(const std::string& filename, const std::string& moduleName = "Mitk"); protected: InteractionEventHandler(); virtual ~InteractionEventHandler(); /** * Returns a PropertyList in which the parameters defined in the config file are listed. */ PropertyList::Pointer GetAttributes() const; std::string MapToEventVariant(InteractionEvent* interactionEvent); /** * Is called whenever a new config object ist set. * Overwrite this method e.g. to initialize EventHandler with parameters in configuration file. */ virtual void ConfigurationChanged(); private: - vtkSmartPointer m_EventConfig; + EventConfig m_EventConfig; }; } /* namespace mitk */ #endif /* MITKEVENTHANDLER_H_ */ diff --git a/Core/Code/Interactions/mitkInteractionKeyEvent.cpp b/Core/Code/Interactions/mitkInteractionKeyEvent.cpp index 675d4c3dc1..4e80ee89c8 100644 --- a/Core/Code/Interactions/mitkInteractionKeyEvent.cpp +++ b/Core/Code/Interactions/mitkInteractionKeyEvent.cpp @@ -1,49 +1,49 @@ /*=================================================================== 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 "mitkInteractionKeyEvent.h" -mitk::InteractionKeyEvent::InteractionKeyEvent(mitk::BaseRenderer* baseRenderer, const std::string& key, mitk::ModifierKeys modifiers = ControlKey) : - InteractionEvent(baseRenderer, "KeyEvent"), m_Key(key), m_Modifiers(modifiers) +mitk::InteractionKeyEvent::InteractionKeyEvent(mitk::BaseRenderer* baseRenderer, const std::string& key, ModifierKeys modifiers = ControlKey) : + InteractionEvent(baseRenderer), m_Key(key), m_Modifiers(modifiers) { } -mitk::ModifierKeys mitk::InteractionKeyEvent::GetModifiers() const +mitk::InteractionEvent::ModifierKeys mitk::InteractionKeyEvent::GetModifiers() const { return m_Modifiers; } std::string mitk::InteractionKeyEvent::GetKey() const { return m_Key; } mitk::InteractionKeyEvent::~InteractionKeyEvent() { } bool mitk::InteractionKeyEvent::IsEqual(const mitk::InteractionEvent& interactionEvent) const { const mitk::InteractionKeyEvent& keyEvent = static_cast(interactionEvent); return (this->GetModifiers() == keyEvent.GetModifiers() && this->GetKey() == keyEvent.GetKey() && Superclass::IsEqual(interactionEvent)); } bool mitk::InteractionKeyEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const { return (dynamic_cast(baseClass.GetPointer()) != NULL) ; } diff --git a/Core/Code/Interactions/mitkMouseMoveEvent.cpp b/Core/Code/Interactions/mitkMouseMoveEvent.cpp index 54e5b17615..9dc1668d83 100644 --- a/Core/Code/Interactions/mitkMouseMoveEvent.cpp +++ b/Core/Code/Interactions/mitkMouseMoveEvent.cpp @@ -1,61 +1,61 @@ /*=================================================================== 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 "mitkException.h" #include "mitkMouseMoveEvent.h" -mitk::MouseMoveEvent::MouseMoveEvent(mitk::BaseRenderer* baseRenderer, const mitk::Point2D& mousePosition , mitk::MouseButtons buttonStates, mitk::ModifierKeys modifiers) +mitk::MouseMoveEvent::MouseMoveEvent(mitk::BaseRenderer* baseRenderer, const mitk::Point2D& mousePosition , MouseButtons buttonStates, ModifierKeys modifiers) : InteractionPositionEvent(baseRenderer, mousePosition, "MouseMoveEvent") , m_ButtonStates(buttonStates) , m_Modifiers(modifiers) { } mitk::ModifierKeys mitk::MouseMoveEvent::GetModifiers() const { return m_Modifiers; } mitk::MouseButtons mitk::MouseMoveEvent::GetButtonStates() const { return m_ButtonStates; } void mitk::MouseMoveEvent::SetModifiers(ModifierKeys modifiers) { m_Modifiers = modifiers; } void mitk::MouseMoveEvent::SetButtonStates(MouseButtons buttons) { m_ButtonStates = buttons; } mitk::MouseMoveEvent::~MouseMoveEvent() { } bool mitk::MouseMoveEvent::IsEqual(const mitk::InteractionEvent& interactionEvent) const { const mitk::MouseMoveEvent& mpe = static_cast(interactionEvent); return (this->GetModifiers() == mpe.GetModifiers() && this->GetButtonStates() == mpe.GetButtonStates() && Superclass::IsEqual(interactionEvent)); } bool mitk::MouseMoveEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const { return (dynamic_cast(baseClass.GetPointer()) != NULL) ; } diff --git a/Core/Code/Interactions/mitkMouseMoveEvent.h b/Core/Code/Interactions/mitkMouseMoveEvent.h index a8fe4b3872..074e508ac3 100644 --- a/Core/Code/Interactions/mitkMouseMoveEvent.h +++ b/Core/Code/Interactions/mitkMouseMoveEvent.h @@ -1,58 +1,59 @@ /*=================================================================== 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 MITKMOUSEMOVEEVENT_H_ #define MITKMOUSEMOVEEVENT_H_ #include "itkObject.h" #include "itkObjectFactory.h" #include "mitkCommon.h" #include "mitkInteractionEventConst.h" #include "mitkInteractionPositionEvent.h" #include "mitkBaseRenderer.h" #include "mitkInteractionEvent.h" #include namespace mitk { class MITK_CORE_EXPORT MouseMoveEvent : public InteractionPositionEvent { public: mitkClassMacro(MouseMoveEvent,InteractionPositionEvent); mitkNewMacro4Param(Self, BaseRenderer*, const Point2D& , MouseButtons , ModifierKeys); ModifierKeys GetModifiers() const; MouseButtons GetButtonStates() const; void SetModifiers(ModifierKeys modifiers); void SetButtonStates(MouseButtons buttons); virtual bool IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const; protected: - MouseMoveEvent(BaseRenderer*, const Point2D& = Point2D(), MouseButtons buttonStates = NoButton, mitk::ModifierKeys modifiers = NoKey); + MouseMoveEvent(BaseRenderer*, const Point2D& = Point2D(), MouseButtons buttonStates = NoButton, + ModifierKeys modifiers = NoKey); virtual ~MouseMoveEvent(); virtual bool IsEqual(const InteractionEvent&) const; private: MouseButtons m_ButtonStates; ModifierKeys m_Modifiers; }; } /* namespace mitk */ #endif /* MITKMOUSEMOVEEVENT_H_ */ diff --git a/Core/Code/Interactions/mitkMousePressEvent.cpp b/Core/Code/Interactions/mitkMousePressEvent.cpp index 24d617c2be..09518f0936 100644 --- a/Core/Code/Interactions/mitkMousePressEvent.cpp +++ b/Core/Code/Interactions/mitkMousePressEvent.cpp @@ -1,77 +1,77 @@ /*=================================================================== 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 "mitkException.h" #include "mitkMousePressEvent.h" mitk::MousePressEvent::MousePressEvent(mitk::BaseRenderer* baseRenderer, const mitk::Point2D& mousePosition, - mitk::MouseButtons buttonStates, - mitk::ModifierKeys modifiers, - mitk::MouseButtons eventButton) + MouseButtons buttonStates, + ModifierKeys modifiers, + MouseButtons eventButton) : InteractionPositionEvent(baseRenderer, mousePosition, "MousePressEvent") , m_EventButton(eventButton) , m_ButtonStates(buttonStates) , m_Modifiers( modifiers) { } -mitk::MouseButtons mitk::MousePressEvent::GetEventButton() const +mitk::InteractionEvent::MouseButtons mitk::MousePressEvent::GetEventButton() const { return m_EventButton; } void mitk::MousePressEvent::SetEventButton(MouseButtons buttons) { m_EventButton = buttons; } -mitk::ModifierKeys mitk::MousePressEvent::GetModifiers() const +mitk::InteractionEvent::ModifierKeys mitk::MousePressEvent::GetModifiers() const { return m_Modifiers; } -mitk::MouseButtons mitk::MousePressEvent::GetButtonStates() const +mitk::InteractionEvent::MouseButtons mitk::MousePressEvent::GetButtonStates() const { return m_ButtonStates; } void mitk::MousePressEvent::SetModifiers(ModifierKeys modifiers) { m_Modifiers = modifiers; } void mitk::MousePressEvent::SetButtonStates(MouseButtons buttons) { m_ButtonStates = buttons; } mitk::MousePressEvent::~MousePressEvent() { } bool mitk::MousePressEvent::IsEqual(const mitk::InteractionEvent& interactionEvent) const { const mitk::MousePressEvent& mpe = static_cast(interactionEvent); return (this->GetEventButton() == mpe.GetEventButton() && this->GetModifiers() == mpe.GetModifiers() && this->GetButtonStates() == mpe.GetButtonStates() && Superclass::IsEqual(interactionEvent)); } bool mitk::MousePressEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const { return (dynamic_cast(baseClass.GetPointer()) != NULL) ; } diff --git a/Core/Code/Interactions/mitkMousePressEvent.h b/Core/Code/Interactions/mitkMousePressEvent.h index 3a72b85f00..6b931236a2 100644 --- a/Core/Code/Interactions/mitkMousePressEvent.h +++ b/Core/Code/Interactions/mitkMousePressEvent.h @@ -1,63 +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 MITKMOUSEPRESSEVENT_H_ #define MITKMOUSEPRESSEVENT_H_ #include "itkObject.h" #include "itkObjectFactory.h" #include "mitkCommon.h" #include "mitkInteractionEventConst.h" #include "mitkInteractionPositionEvent.h" #include "mitkBaseRenderer.h" #include "mitkInteractionEvent.h" #include namespace mitk { class MITK_CORE_EXPORT MousePressEvent: public InteractionPositionEvent { public: mitkClassMacro(MousePressEvent,InteractionPositionEvent) mitkNewMacro5Param(Self, BaseRenderer*, const Point2D& , MouseButtons , ModifierKeys, MouseButtons) ModifierKeys GetModifiers() const; MouseButtons GetButtonStates() const; void SetModifiers(ModifierKeys modifiers); void SetButtonStates(MouseButtons buttons); MouseButtons GetEventButton() const; void SetEventButton(MouseButtons buttons); virtual bool IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const; protected: - MousePressEvent(BaseRenderer*, const Point2D& = Point2D(), mitk::MouseButtons buttonStates = NoButton, mitk::ModifierKeys modifiers = - NoKey, mitk::MouseButtons eventButton = NoButton); + MousePressEvent(BaseRenderer*, const Point2D& = Point2D(), MouseButtons buttonStates = NoButton, + ModifierKeys modifiers = NoKey, MouseButtons eventButton = NoButton); virtual ~MousePressEvent(); virtual bool IsEqual(const InteractionEvent&) const; private: MouseButtons m_EventButton; MouseButtons m_ButtonStates; ModifierKeys m_Modifiers; }; } /* namespace mitk */ #endif /* MITKMOUSEPRESSEVENT_H_ */ diff --git a/Core/Code/Interactions/mitkMouseReleaseEvent.cpp b/Core/Code/Interactions/mitkMouseReleaseEvent.cpp index 50253f8d6c..c2e06bfa58 100644 --- a/Core/Code/Interactions/mitkMouseReleaseEvent.cpp +++ b/Core/Code/Interactions/mitkMouseReleaseEvent.cpp @@ -1,78 +1,78 @@ /*=================================================================== 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 "mitkException.h" #include "mitkMouseReleaseEvent.h" mitk::MouseReleaseEvent::MouseReleaseEvent(mitk::BaseRenderer* baseRenderer, const mitk::Point2D& mousePosition, - mitk::MouseButtons buttonStates, - mitk::ModifierKeys modifiers, - mitk::MouseButtons eventButton) + MouseButtons buttonStates, + ModifierKeys modifiers, + MouseButtons eventButton) : InteractionPositionEvent(baseRenderer, mousePosition, "MouseReleaseEvent") , m_EventButton(eventButton) , m_ButtonStates(buttonStates) , m_Modifiers(modifiers) { } -mitk::MouseButtons mitk::MouseReleaseEvent::GetEventButton() const +mitk::InteractionEvent::MouseButtons mitk::MouseReleaseEvent::GetEventButton() const { return m_EventButton; } void mitk::MouseReleaseEvent::SetEventButton(MouseButtons buttons) { m_EventButton = buttons; } -mitk::ModifierKeys mitk::MouseReleaseEvent::GetModifiers() const +mitk::InteractionEvent::ModifierKeys mitk::MouseReleaseEvent::GetModifiers() const { return m_Modifiers; } -mitk::MouseButtons mitk::MouseReleaseEvent::GetButtonStates() const +mitk::InteractionEvent::MouseButtons mitk::MouseReleaseEvent::GetButtonStates() const { return m_ButtonStates; } void mitk::MouseReleaseEvent::SetModifiers(ModifierKeys modifiers) { m_Modifiers = modifiers; } void mitk::MouseReleaseEvent::SetButtonStates(MouseButtons buttons) { m_ButtonStates = buttons; } mitk::MouseReleaseEvent::~MouseReleaseEvent() { } bool mitk::MouseReleaseEvent::IsEqual(const mitk::InteractionEvent& interactionEvent) const { const mitk::MouseReleaseEvent& mre = static_cast(interactionEvent); return (this->GetEventButton() == mre.GetEventButton() && this->GetModifiers() == mre.GetModifiers() && this->GetButtonStates() == mre.GetButtonStates() && Superclass::IsEqual(interactionEvent)); } bool mitk::MouseReleaseEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const { return (dynamic_cast(baseClass.GetPointer()) != NULL) ; } diff --git a/Core/Code/Interactions/mitkMouseReleaseEvent.h b/Core/Code/Interactions/mitkMouseReleaseEvent.h index 460dbfa977..b2699544a5 100644 --- a/Core/Code/Interactions/mitkMouseReleaseEvent.h +++ b/Core/Code/Interactions/mitkMouseReleaseEvent.h @@ -1,66 +1,66 @@ /*=================================================================== 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 MITKMOUSERELEASEEVENT_H_ #define MITKMOUSERELEASEEVENT_H_ #include "itkObject.h" #include "itkObjectFactory.h" #include "mitkCommon.h" #include "mitkInteractionPositionEvent.h" #include "mitkInteractionEventConst.h" #include "mitkBaseRenderer.h" #include "mitkInteractionEvent.h" #include namespace mitk { class MITK_CORE_EXPORT MouseReleaseEvent: public InteractionPositionEvent { public: mitkClassMacro(MouseReleaseEvent,InteractionPositionEvent) mitkNewMacro5Param(Self, BaseRenderer*, const Point2D& ,MouseButtons , ModifierKeys, MouseButtons) ModifierKeys GetModifiers() const; MouseButtons GetButtonStates() const; void SetModifiers(ModifierKeys modifiers); void SetButtonStates(MouseButtons buttons); MouseButtons GetEventButton() const; void SetEventButton(MouseButtons buttons); virtual bool IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const; protected: MouseReleaseEvent(BaseRenderer*, const mitk::Point2D& mousePosition = Point2D(), - mitk::MouseButtons buttonStates = NoButton, - mitk::ModifierKeys modifiers = NoKey, - mitk::MouseButtons eventButton = NoButton); + MouseButtons buttonStates = NoButton, + ModifierKeys modifiers = NoKey, + MouseButtons eventButton = NoButton); virtual ~MouseReleaseEvent(); virtual bool IsEqual(const InteractionEvent&) const; private: MouseButtons m_EventButton; MouseButtons m_ButtonStates; ModifierKeys m_Modifiers; }; } /* namespace mitk */ #endif /* MITKMOUSERELEASEEVENT_H_ */ diff --git a/Core/Code/Interactions/mitkMouseWheelEvent.cpp b/Core/Code/Interactions/mitkMouseWheelEvent.cpp index 6f1572a549..cbadf9c0a5 100644 --- a/Core/Code/Interactions/mitkMouseWheelEvent.cpp +++ b/Core/Code/Interactions/mitkMouseWheelEvent.cpp @@ -1,76 +1,76 @@ /*=================================================================== 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 "mitkMouseWheelEvent.h" mitk::MouseWheelEvent::MouseWheelEvent(BaseRenderer* baseRenderer, const Point2D& mousePosition, MouseButtons buttonStates, ModifierKeys modifiers, int wheelDelta) : InteractionPositionEvent(baseRenderer, mousePosition, "MouseWheelEvent") , m_WheelDelta(wheelDelta) , m_ButtonStates(buttonStates) , m_Modifiers(modifiers) { } int mitk::MouseWheelEvent::GetWheelDelta() const { return m_WheelDelta; } void mitk::MouseWheelEvent::SetWheelDelta(int delta) { m_WheelDelta = delta; } -mitk::ModifierKeys mitk::MouseWheelEvent::GetModifiers() const +mitk::InteractionEvent::ModifierKeys mitk::MouseWheelEvent::GetModifiers() const { return m_Modifiers; } -mitk::MouseButtons mitk::MouseWheelEvent::GetButtonStates() const +mitk::InteractionEvent::MouseButtons mitk::MouseWheelEvent::GetButtonStates() const { return m_ButtonStates; } void mitk::MouseWheelEvent::SetModifiers(ModifierKeys modifiers) { m_Modifiers = modifiers; } void mitk::MouseWheelEvent::SetButtonStates(MouseButtons buttons) { m_ButtonStates = buttons; } mitk::MouseWheelEvent::~MouseWheelEvent() { } bool mitk::MouseWheelEvent::IsEqual(const mitk::InteractionEvent& interactionEvent) const { const mitk::MouseWheelEvent& mwe = static_cast(interactionEvent); return ((this->GetWheelDelta() * mwe.GetWheelDelta() > 0) // Consider WheelEvents to be equal if the scrolling is done in the same direction. && this->GetModifiers() == mwe.GetModifiers() && this->GetButtonStates() == mwe.GetButtonStates() && Superclass::IsEqual(interactionEvent)); } bool mitk::MouseWheelEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const { return (dynamic_cast(baseClass.GetPointer()) != NULL) ; } diff --git a/Core/Code/Interactions/mitkStateMachineTransition.cpp b/Core/Code/Interactions/mitkStateMachineTransition.cpp index fcce659d99..587d049991 100755 --- a/Core/Code/Interactions/mitkStateMachineTransition.cpp +++ b/Core/Code/Interactions/mitkStateMachineTransition.cpp @@ -1,96 +1,96 @@ /*=================================================================== 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(std::string nextStateName, std::string eventClass, std::string eventVariant) : m_EventClass(eventClass), m_EventVariant(eventVariant), m_NextStateName(nextStateName) { PropertyList::Pointer propertyList = PropertyList::New(); - propertyList->SetStringProperty(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(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(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(SpStateMachineState nextState) { m_NextState = nextState; } diff --git a/Core/Code/Interactions/mitkVtkEventAdapter.cpp b/Core/Code/Interactions/mitkVtkEventAdapter.cpp index 21612021f1..2b5b907da3 100644 --- a/Core/Code/Interactions/mitkVtkEventAdapter.cpp +++ b/Core/Code/Interactions/mitkVtkEventAdapter.cpp @@ -1,453 +1,463 @@ /*=================================================================== 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 "mitkVtkEventAdapter.h" #include // INTERACTION LEGACY #include // INTERACTION LEGACY #include "mitkInteractionEventConst.h" #include #include "vtkCommand.h" namespace mitk { std::map VtkEventAdapter::buttonStateMap; } mitk::MouseEvent mitk::VtkEventAdapter::AdaptMouseEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { mitk::Point2D p; p[0] = rwi->GetEventPosition()[0]; p[1] = rwi->GetEventPosition()[1]; p[1] = rwi->GetSize()[1] - p[1]; // flip y axis // http://doc.trolltech.com/4.6/qt.html#MouseButton-enum int button = 0; int type = 0; int state = 0; // vtkRenderWindowInteractor does not provide information about mouse buttons during // mouse move events... // some button action might be going on during mouse move events // that needs to be temp. saved in our buttonStateMap int tmpstate = 0; if (buttonStateMap.find(sender) != buttonStateMap.end()) tmpstate = buttonStateMap.find(sender)->second; if (tmpstate != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent) buttonStateMap.erase(buttonStateMap.find(sender)); //press or release event with active map caching switch (vtkCommandEventId) { case vtkCommand::MouseMoveEvent: type = 5; button = mitk::BS_NoButton; if (tmpstate != 0) { state = tmpstate; /* // debug output static char tmp; sprintf(&tmp,"%d",tmpstate); std::cout << tmp << std::endl; */ } break; case vtkCommand::LeftButtonReleaseEvent: type = 3; button = mitk::BS_LeftButton; state = tmpstate; buttonStateMap[sender] = (tmpstate - button); break; case vtkCommand::MiddleButtonReleaseEvent: type = 3; button = mitk::BS_MidButton; state = tmpstate; buttonStateMap[sender] = (tmpstate - button); break; case vtkCommand::RightButtonReleaseEvent: type = 3; button = mitk::BS_RightButton; state = tmpstate; buttonStateMap[sender] = (tmpstate - button); break; case vtkCommand::LeftButtonPressEvent: type = 2; button = mitk::BS_LeftButton; tmpstate |= button; buttonStateMap[sender] = tmpstate; break; case vtkCommand::MiddleButtonPressEvent: type = 2; button = mitk::BS_MidButton; tmpstate |= button; buttonStateMap[sender] = tmpstate; break; case vtkCommand::RightButtonPressEvent: type = 2; button = mitk::BS_RightButton; tmpstate |= button; buttonStateMap[sender] = tmpstate; break; } if (rwi->GetShiftKey()) { state |= mitk::BS_ShiftButton; } if (rwi->GetControlKey()) { state |= mitk::BS_ControlButton; } if (rwi->GetAltKey()) { state |= mitk::BS_AltButton; } mitk::MouseEvent mitkEvent(sender, type, button, state, mitk::Key_none, p); return mitkEvent; } mitk::WheelEvent //mitk::VtkEventAdapter::AdaptWheelEvent(mitk::BaseRenderer* sender, QWheelEvent* wheelEvent) mitk::VtkEventAdapter::AdaptWheelEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { mitk::Point2D p; p[0] = rwi->GetEventPosition()[0]; p[1] = rwi->GetEventPosition()[1]; // http://doc.trolltech.com/4.6/qt.html#MouseButton-enum int button = 0; int type = 0; int state = 0; int delta = 0; switch (vtkCommandEventId) { case vtkCommand::MouseWheelForwardEvent: type = 31; // wheel event, // see qcoreevent enum "type" button = 0x00000000; delta = +120; //http://doc.trolltech.com/3.3/qwheelevent.html#delta break; case vtkCommand::MouseWheelBackwardEvent: type = 31; // wheel event, // see qcoreevent enum "type" button = 0x00000000; delta = -120; //http://doc.trolltech.com/3.3/qwheelevent.html#delta break; } if (rwi->GetShiftKey()) state |= mitk::BS_ShiftButton; if (rwi->GetControlKey()) state |= mitk::BS_ControlButton; if (rwi->GetAltKey()) state |= mitk::BS_AltButton; mitk::WheelEvent mitkEvent(sender, type, button, state, mitk::Key_none, p, delta); return mitkEvent; } mitk::KeyEvent //mitk::VtkEventAdapter::AdaptKeyEvent(mitk::BaseRenderer* sender, QKeyEvent* keyEvent, const QPoint& cp) mitk::VtkEventAdapter::AdaptKeyEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { // TODO: is this viable? int key = (int) rwi->GetKeyCode(); // Those keycodes changed in Qt 4 if (key >= 0x01000000 && key <= 0x01000060) key -= (0x01000000 - 0x1000); else if (key >= 0x01001120 && key <= 0x01001262) key -= 0x01000000; mitk::Point2D p; p[0] = rwi->GetEventPosition()[0]; p[1] = rwi->GetEventPosition()[1]; int type = 0; if (vtkCommandEventId == vtkCommand::KeyPressEvent) type = 6; // http://doc.trolltech.com/4.6/qevent.html#Type-enum int state = 0; if (rwi->GetShiftKey()) state |= mitk::BS_ShiftButton; if (rwi->GetControlKey()) state |= mitk::BS_ControlButton; if (rwi->GetAltKey()) state |= mitk::BS_AltButton; mitk::KeyEvent mke(sender, type, mitk::BS_NoButton, state, key, std::string(rwi->GetKeySym()), p); return mke; } mitk::MousePressEvent::Pointer mitk::VtkEventAdapter::AdaptMousePressEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { mitk::Point2D point; point[0] = rwi->GetEventPosition()[0]; point[1] = rwi->GetEventPosition()[1]; point[1] = rwi->GetSize()[1] - point[1]; // flip y axis int button = 0; int modifiers = 0; int buttonState = 0; // vtkRenderWindowInteractor does not provide information about mouse buttons during // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap // this button state is then provided for mouse move events if (buttonStateMap.find(sender) != buttonStateMap.end()) buttonState = buttonStateMap.find(sender)->second; if (buttonState != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent) buttonStateMap.erase(buttonStateMap.find(sender)); //press or release event with active map caching switch (vtkCommandEventId) { case vtkCommand::LeftButtonPressEvent: - button = mitk::LeftMouseButton; + button = InteractionEvent::LeftMouseButton; buttonState |= button; buttonStateMap[sender] = buttonState; break; case vtkCommand::MiddleButtonPressEvent: - button = mitk::MiddleMouseButton; + button = InteractionEvent::MiddleMouseButton; buttonState |= button; buttonStateMap[sender] = buttonState; break; case vtkCommand::RightButtonPressEvent: - button = mitk::RightMouseButton; + button = InteractionEvent::RightMouseButton; buttonState |= button; buttonStateMap[sender] = buttonState; break; } if (rwi->GetShiftKey()) { - modifiers |= mitk::ShiftKey; + modifiers |= InteractionEvent::ShiftKey; } if (rwi->GetControlKey()) { - modifiers |= mitk::ControlKey; + modifiers |= InteractionEvent::ControlKey; } if (rwi->GetAltKey()) { - modifiers |= mitk::AltKey; + modifiers |= InteractionEvent::AltKey; } - MousePressEvent::Pointer mpe = MousePressEvent::New(sender, point, (MouseButtons) buttonState, (ModifierKeys) modifiers, - (MouseButtons) button); + MousePressEvent::Pointer mpe = MousePressEvent::New(sender, point, + static_cast(buttonState), + static_cast(modifiers), + static_cast(button)); return mpe; } mitk::MouseMoveEvent::Pointer mitk::VtkEventAdapter::AdaptMouseMoveEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { mitk::Point2D point; point[0] = rwi->GetEventPosition()[0]; point[1] = rwi->GetEventPosition()[1]; point[1] = rwi->GetSize()[1] - point[1]; // flip y axis int modifiers = 0; // vtkRenderWindowInteractor does not provide information about mouse buttons during // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap // this button state is then provided for mouse move events int buttonState = 0; if (buttonStateMap.find(sender) != buttonStateMap.end()) { // set stored button state buttonState = buttonStateMap.find(sender)->second; } if (vtkCommandEventId == vtkCommand::MouseMoveEvent) { if (buttonState != 0) { modifiers = buttonState; } } else { MITK_WARN<< "Wrong usage of function AdaptMouseMoveEvent. Wrong input type."; } if (rwi->GetShiftKey()) { - modifiers |= mitk::ShiftKey; + modifiers |= InteractionEvent::ShiftKey; } if (rwi->GetControlKey()) { - modifiers |= mitk::ControlKey; + modifiers |= InteractionEvent::ControlKey; } if (rwi->GetAltKey()) { - modifiers |= mitk::AltKey; + modifiers |= InteractionEvent::AltKey; } - MouseMoveEvent::Pointer mme = MouseMoveEvent::New(sender, point, (MouseButtons) buttonState, (ModifierKeys) modifiers); + MouseMoveEvent::Pointer mme = MouseMoveEvent::New(sender, point, + static_cast(buttonState), + static_cast(modifiers)); return mme; } mitk::MouseReleaseEvent::Pointer mitk::VtkEventAdapter::AdaptMouseReleaseEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { mitk::Point2D point; point[0] = rwi->GetEventPosition()[0]; point[1] = rwi->GetEventPosition()[1]; point[1] = rwi->GetSize()[1] - point[1]; // flip y axis int button = 0; int modifiers = 0; int buttonState = 0; // vtkRenderWindowInteractor does not provide information about mouse buttons during // mouse move events therefore the Press/Release functions update the button state in the buttonStateMap // this button state is then provided for mouse move events if (buttonStateMap.find(sender) != buttonStateMap.end()) buttonState = buttonStateMap.find(sender)->second; if (buttonState != 0 && vtkCommandEventId != vtkCommand::MouseMoveEvent) buttonStateMap.erase(buttonStateMap.find(sender)); //press or release event with active map caching switch (vtkCommandEventId) { case vtkCommand::LeftButtonReleaseEvent: - button = mitk::LeftMouseButton; + button = InteractionEvent::LeftMouseButton; // remove left mouse button from button state buttonStateMap[sender] = (buttonState - button); break; case vtkCommand::MiddleButtonReleaseEvent: - button = mitk::MiddleMouseButton; + button = InteractionEvent::MiddleMouseButton; // remove middle button from button state buttonStateMap[sender] = (buttonState - button); break; case vtkCommand::RightButtonReleaseEvent: - button = mitk::RightMouseButton; + button = InteractionEvent::RightMouseButton; // remove right mouse button from button state buttonStateMap[sender] = (buttonState - button); break; } if (rwi->GetShiftKey()) { - modifiers |= mitk::ShiftKey; + modifiers |= InteractionEvent::ShiftKey; } if (rwi->GetControlKey()) { - modifiers |= mitk::ControlKey; + modifiers |= InteractionEvent::ControlKey; } if (rwi->GetAltKey()) { - modifiers |= mitk::AltKey; + modifiers |= InteractionEvent::AltKey; } // after releasing button is no longer pressed, to update it if (buttonStateMap.find(sender) != buttonStateMap.end()) { buttonState = buttonStateMap.find(sender)->second; } - MouseReleaseEvent::Pointer mre = MouseReleaseEvent::New(sender, point, (MouseButtons) buttonState, (ModifierKeys) modifiers, - (MouseButtons) button); + MouseReleaseEvent::Pointer mre = MouseReleaseEvent::New(sender, point, + static_cast(buttonState), + static_cast(modifiers), + static_cast(button)); return mre; } mitk::MouseWheelEvent::Pointer mitk::VtkEventAdapter::AdaptMouseWheelEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { mitk::Point2D p; p[0] = rwi->GetEventPosition()[0]; p[1] = rwi->GetEventPosition()[1]; int delta = 0; switch (vtkCommandEventId) { case vtkCommand::MouseWheelForwardEvent: delta = +120; //http://doc.trolltech.com/3.3/qwheelevent.html#delta break; case vtkCommand::MouseWheelBackwardEvent: delta = -120; //http://doc.trolltech.com/3.3/qwheelevent.html#delta break; } int modifiers = 0; if (rwi->GetShiftKey()) { modifiers |= mitk::BS_ShiftButton; } if (rwi->GetControlKey()) { modifiers |= mitk::BS_ControlButton; } if (rwi->GetAltKey()) { modifiers |= mitk::BS_AltButton; } mitk::Point2D point; point[0] = rwi->GetEventPosition()[0]; point[1] = rwi->GetEventPosition()[1]; point[1] = rwi->GetSize()[1] - point[1]; // flip y axis // vtkWheelEvent does not have a buttonState or event button int buttonState = 0; - MouseWheelEvent::Pointer mpe = MouseWheelEvent::New(sender, point, (MouseButtons) buttonState, (ModifierKeys) modifiers, delta); + MouseWheelEvent::Pointer mpe = MouseWheelEvent::New(sender, point, + static_cast(buttonState), + static_cast(modifiers), + delta); return mpe; } mitk::InteractionKeyEvent::Pointer mitk::VtkEventAdapter::AdaptInteractionKeyEvent(mitk::BaseRenderer* sender, unsigned long vtkCommandEventId, vtkRenderWindowInteractor* rwi) { if (vtkCommandEventId != vtkCommand::KeyPressEvent) { MITK_WARN<< "mitk::VtkEventAdapter::AdaptInteractionKeyEvent() called with wrong argument"; return NULL; } int modifiers = 0; if (rwi->GetShiftKey()) { modifiers |= mitk::BS_ShiftButton;} if (rwi->GetControlKey()) { modifiers |= mitk::BS_ControlButton;} if (rwi->GetAltKey()) { modifiers |= mitk::BS_AltButton; } - InteractionKeyEvent::Pointer ike = InteractionKeyEvent::New(sender, std::string(rwi->GetKeySym()), (ModifierKeys)modifiers ); + InteractionKeyEvent::Pointer ike = InteractionKeyEvent::New(sender, std::string(rwi->GetKeySym()), + static_cast(modifiers)); return ike; } diff --git a/Core/Code/Testing/mitkInteractionEventTest.cpp b/Core/Code/Testing/mitkInteractionEventTest.cpp index bf6051a190..6017b66343 100644 --- a/Core/Code/Testing/mitkInteractionEventTest.cpp +++ b/Core/Code/Testing/mitkInteractionEventTest.cpp @@ -1,96 +1,96 @@ /*=================================================================== 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 "mitkMousePressEvent.h" #include "mitkMouseReleaseEvent.h" #include "mitkMouseMoveEvent.h" #include "mitkVtkPropRenderer.h" #include "mitkInteractionEventConst.h" #include "mitkTestingMacros.h" int mitkInteractionEventTest(int /*argc*/, char* /*argv*/[]) { /* * Create different Events, fill them with data. * And check if isEqual method is implemented properly. */ MITK_TEST_BEGIN("InteractionEvent") mitk::VtkPropRenderer::Pointer renderer = NULL; - mitk::MouseButtons buttonStates = mitk::LeftMouseButton | mitk::RightMouseButton; - mitk::MouseButtons eventButton = mitk::LeftMouseButton; - mitk::ModifierKeys modifiers = mitk::ControlKey | mitk::AltKey; + mitk::InteractionEvent::MouseButtons buttonStates = mitk::InteractionEvent::LeftMouseButton | mitk::InteractionEvent::RightMouseButton; + mitk::InteractionEvent::MouseButtons eventButton = mitk::InteractionEvent::LeftMouseButton; + mitk::InteractionEvent::ModifierKeys modifiers = mitk::InteractionEvent::ControlKey | mitk::InteractionEvent::AltKey; mitk::Point2D point; point[0] = 17; point[1] = 170; // MousePress Events mitk::MousePressEvent::Pointer me1 = mitk::MousePressEvent::New(renderer,point, buttonStates, modifiers, eventButton); mitk::MousePressEvent::Pointer me2 = mitk::MousePressEvent::New(renderer,point, buttonStates, modifiers, eventButton); point[0] = 178; point[1] = 170; mitk::MousePressEvent::Pointer me3 = mitk::MousePressEvent::New(renderer,point, buttonStates, modifiers, eventButton); - modifiers = mitk::ControlKey; + modifiers = mitk::InteractionEvent::ControlKey; mitk::MousePressEvent::Pointer me4 = mitk::MousePressEvent::New(renderer,point, buttonStates, modifiers, eventButton); MITK_TEST_CONDITION_REQUIRED( *me1 == *me2 && *me1 == *me3 && *me2 == *me3 && *me3 != *me4 , "Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MousePressEvent"); // MouseReleaseEvents mitk::MouseReleaseEvent::Pointer mr1 = mitk::MouseReleaseEvent::New(renderer,point, buttonStates, modifiers, eventButton); mitk::MouseReleaseEvent::Pointer mr2 = mitk::MouseReleaseEvent::New(renderer,point, buttonStates, modifiers, eventButton); point[0] = 178; point[1] = 170; mitk::MouseReleaseEvent::Pointer mr3 = mitk::MouseReleaseEvent::New(renderer,point, buttonStates, modifiers, eventButton); - eventButton = mitk::RightMouseButton; + eventButton = mitk::InteractionEvent::RightMouseButton; mitk::MouseReleaseEvent::Pointer mr4 = mitk::MouseReleaseEvent::New(renderer,point, buttonStates, modifiers, eventButton); MITK_TEST_CONDITION_REQUIRED( *mr1 == *mr2 && *mr1 == *mr3 && *mr2 == *mr3 && *mr3 != *mr4 , "Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MouseReleaseEvent"); // MouseMoveEvents mitk::MouseMoveEvent::Pointer mm1 = mitk::MouseMoveEvent::New(renderer,point, buttonStates, modifiers); point[0] = 178; point[1] = 170; mitk::MouseMoveEvent::Pointer mm3 = mitk::MouseMoveEvent::New(renderer,point, buttonStates, modifiers); - modifiers = mitk::AltKey; + modifiers = mitk::InteractionEvent::AltKey; mitk::MouseMoveEvent::Pointer mm4 = mitk::MouseMoveEvent::New(renderer,point, buttonStates, modifiers); MITK_TEST_CONDITION_REQUIRED( *mm1 == *mm3 && *mm3 != *mm4 , "Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MouseMoveEvent"); // always end with this! MITK_TEST_END() } diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index 95032ca2f9..a962092fd6 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,359 +1,360 @@ set(H_FILES Algorithms/itkImportMitkImageContainer.h Algorithms/itkImportMitkImageContainer.txx Algorithms/itkLocalVariationImageFilter.h Algorithms/itkLocalVariationImageFilter.txx Algorithms/itkMITKScalarImageToHistogramGenerator.h Algorithms/itkMITKScalarImageToHistogramGenerator.txx Algorithms/itkTotalVariationDenoisingImageFilter.h Algorithms/itkTotalVariationDenoisingImageFilter.txx Algorithms/itkTotalVariationSingleIterationImageFilter.h Algorithms/itkTotalVariationSingleIterationImageFilter.txx Algorithms/mitkBilateralFilter.h Algorithms/mitkBilateralFilter.cpp Algorithms/mitkInstantiateAccessFunctions.h Algorithms/mitkPixelTypeList.h # Preprocessor macros taken from Boost Algorithms/mitkPPArithmeticDec.h Algorithms/mitkPPArgCount.h Algorithms/mitkPPCat.h Algorithms/mitkPPConfig.h Algorithms/mitkPPControlExprIIf.h Algorithms/mitkPPControlIf.h Algorithms/mitkPPControlIIf.h Algorithms/mitkPPDebugError.h Algorithms/mitkPPDetailAutoRec.h Algorithms/mitkPPDetailDMCAutoRec.h Algorithms/mitkPPExpand.h Algorithms/mitkPPFacilitiesEmpty.h Algorithms/mitkPPFacilitiesExpand.h Algorithms/mitkPPLogicalBool.h Algorithms/mitkPPRepetitionDetailDMCFor.h Algorithms/mitkPPRepetitionDetailEDGFor.h Algorithms/mitkPPRepetitionDetailFor.h Algorithms/mitkPPRepetitionDetailMSVCFor.h Algorithms/mitkPPRepetitionFor.h Algorithms/mitkPPSeqElem.h Algorithms/mitkPPSeqForEach.h Algorithms/mitkPPSeqForEachProduct.h Algorithms/mitkPPSeq.h Algorithms/mitkPPSeqEnum.h Algorithms/mitkPPSeqSize.h Algorithms/mitkPPSeqToTuple.h Algorithms/mitkPPStringize.h Algorithms/mitkPPTupleEat.h Algorithms/mitkPPTupleElem.h Algorithms/mitkPPTupleRem.h Algorithms/mitkClippedSurfaceBoundsCalculator.h Algorithms/mitkExtractSliceFilter.h Algorithms/mitkConvert2Dto3DImageFilter.h Algorithms/mitkPlaneClipping.h Common/mitkExceptionMacro.h Common/mitkServiceBaseObject.h Common/mitkTestingMacros.h DataManagement/mitkImageAccessByItk.h DataManagement/mitkImageCast.h DataManagement/mitkImagePixelAccessor.h DataManagement/mitkImagePixelReadAccessor.h DataManagement/mitkImagePixelWriteAccessor.h DataManagement/mitkImageReadAccessor.h DataManagement/mitkImageWriteAccessor.h DataManagement/mitkITKImageImport.h DataManagement/mitkITKImageImport.txx DataManagement/mitkImageToItk.h DataManagement/mitkImageToItk.txx Interactions/mitkEventMapperAddOn.h Interfaces/mitkIDataNodeReader.h IO/mitkPixelTypeTraits.h ) set(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkBaseProcess.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkGeometry2DDataToSurfaceFilter.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkConvert2Dto3DImageFilter.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkCoreActivator.cpp Controllers/mitkFocusManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSlicesCoordinator.cpp Controllers/mitkSlicesRotator.cpp Controllers/mitkSlicesSwiveller.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkInteractorCameraController.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkBaseData.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkDataStorage.cpp #DataManagement/mitkDataTree.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataNodeFactory.cpp #DataManagement/mitkDataTreeStorage.cpp DataManagement/mitkDisplayGeometry.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkGeometry2D.cpp DataManagement/mitkGeometry2DData.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageVtkAccessor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkLandmarkBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTables.cpp # specializations of GenericLookupTable DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModeOperation.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFirstLevel.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateSource.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStateTransitionOperation.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTimeSlicedGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkVector.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkVtkVolumeRenderingProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkRenderingModeProperty.cpp DataManagement/mitkShaderProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkMaterial.cpp Interactions/mitkAction.cpp Interactions/mitkAffineInteractor.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkCoordinateSupplier.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkDisplayPositionEvent.cpp # Interactions/mitkDisplayVectorInteractorLevelWindow.cpp # legacy, prob even now unneeded # Interactions/mitkDisplayVectorInteractorScroll.cpp Interactions/mitkEvent.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventDescription.cpp Interactions/mitkEventFactory.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkEventMapper.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkGlobalInteraction.cpp Interactions/mitkInteractor.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkInteractionEvent.cpp + Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMovePointSetInteractor.cpp Interactions/mitkMoveBaseDataInteractor.cpp Interactions/mitkNodeDepententPointSetInteractor.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkPointSetInteractor.cpp Interactions/mitkPositionEvent.cpp Interactions/mitkPositionTracker.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkState.cpp Interactions/mitkStateMachineContainer.cpp Interactions/mitkStateEvent.cpp Interactions/mitkStateMachine.cpp Interactions/mitkStateMachineFactory.cpp Interactions/mitkTransition.cpp Interactions/mitkWheelEvent.cpp Interactions/mitkKeyEvent.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkCrosshairPositionEvent.cpp Interfaces/mitkInteractionEventObserver.cpp Interfaces/mitkIShaderRepository.cpp IO/mitkBaseDataIOFactory.cpp IO/mitkCoreDataNodeReader.cpp IO/mitkDicomSeriesReader.cpp IO/mitkFileReader.cpp IO/mitkFileSeriesReader.cpp IO/mitkFileWriter.cpp #IO/mitkIpPicGet.c IO/mitkImageGenerator.cpp IO/mitkImageWriter.cpp IO/mitkImageWriterFactory.cpp IO/mitkItkImageFileIOFactory.cpp IO/mitkItkImageFileReader.cpp IO/mitkItkLoggingAdapter.cpp IO/mitkItkPictureWrite.cpp IO/mitkIOUtil.cpp IO/mitkLookupTableProperty.cpp IO/mitkOperation.cpp #IO/mitkPicFileIOFactory.cpp #IO/mitkPicFileReader.cpp #IO/mitkPicFileWriter.cpp #IO/mitkPicHelper.cpp #IO/mitkPicVolumeTimeSeriesIOFactory.cpp #IO/mitkPicVolumeTimeSeriesReader.cpp IO/mitkPixelType.cpp IO/mitkPointSetIOFactory.cpp IO/mitkPointSetReader.cpp IO/mitkPointSetWriter.cpp IO/mitkPointSetWriterFactory.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSTLFileIOFactory.cpp IO/mitkSTLFileReader.cpp IO/mitkSurfaceVtkWriter.cpp IO/mitkSurfaceVtkWriterFactory.cpp IO/mitkVtkLoggingAdapter.cpp IO/mitkVtiFileIOFactory.cpp IO/mitkVtiFileReader.cpp IO/mitkVtkImageIOFactory.cpp IO/mitkVtkImageReader.cpp IO/mitkVtkSurfaceIOFactory.cpp IO/mitkVtkSurfaceReader.cpp IO/vtkPointSetXMLParser.cpp IO/mitkLog.cpp Rendering/mitkBaseRenderer.cpp Rendering/mitkVtkMapper.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkGeometry2DDataMapper2D.cpp Rendering/mitkGeometry2DDataVtkMapper3D.cpp Rendering/mitkGLMapper.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkManufacturerLogo.cpp Rendering/mitkMapper.cpp Rendering/mitkPointSetGLMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkPolyDataGLMapper2D.cpp Rendering/mitkSurfaceGLMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVolumeDataVtkMapper3D.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowBase.cpp Rendering/mitkShaderRepository.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkMitkLevelWindowFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp Rendering/mitkRenderingTestHelper.cpp Common/mitkException.cpp Common/mitkCommon.h Common/mitkCoreObjectFactoryBase.cpp Common/mitkCoreObjectFactory.cpp Common/mitkCoreServices.cpp ) list(APPEND CPP_FILES ${CppMicroServices_SOURCES}) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfig.xml Interactions/DisplayConfigPACS.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigMITK.xml Interactions/PointSet.xml Interactions/Legacy/StateMachine.xml Interactions/Legacy/DisplayConfigMITKTools.xml Interactions/PointSetConfig.xml Shaders/mitkShaderLighting.xml mitkLevelWindowPresets.xml ) diff --git a/Modules/Qmitk/QmitkRenderWindow.cpp b/Modules/Qmitk/QmitkRenderWindow.cpp index f9cf89a97d..e86f813537 100644 --- a/Modules/Qmitk/QmitkRenderWindow.cpp +++ b/Modules/Qmitk/QmitkRenderWindow.cpp @@ -1,542 +1,542 @@ /*=================================================================== 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 "QmitkRenderWindow.h" #include #include #include #include #include #include #include #include #include "QmitkEventAdapter.h" // TODO: INTERACTION_LEGACY #include "mitkMousePressEvent.h" #include "mitkMouseMoveEvent.h" #include "mitkMouseReleaseEvent.h" #include "mitkInteractionKeyEvent.h" #include "mitkMouseWheelEvent.h" #include "mitkInternalEvent.h" #include "QmitkRenderWindowMenu.h" QmitkRenderWindow::QmitkRenderWindow(QWidget *parent, QString name, mitk::VtkPropRenderer* /*renderer*/, mitk::RenderingManager* renderingManager) : QVTKWidget(parent), m_ResendQtEvents(true), m_MenuWidget(NULL), m_MenuWidgetActivated(false), m_LayoutIndex(0) { Initialize(renderingManager, name.toStdString().c_str()); // Initialize mitkRenderWindowBase setFocusPolicy(Qt::StrongFocus); setMouseTracking(true); } QmitkRenderWindow::~QmitkRenderWindow() { Destroy(); // Destroy mitkRenderWindowBase } void QmitkRenderWindow::SetResendQtEvents(bool resend) { m_ResendQtEvents = resend; } void QmitkRenderWindow::SetLayoutIndex(unsigned int layoutIndex) { m_LayoutIndex = layoutIndex; if (m_MenuWidget) m_MenuWidget->SetLayoutIndex(layoutIndex); } unsigned int QmitkRenderWindow::GetLayoutIndex() { if (m_MenuWidget) return m_MenuWidget->GetLayoutIndex(); else return 0; } void QmitkRenderWindow::LayoutDesignListChanged(int layoutDesignIndex) { if (m_MenuWidget) m_MenuWidget->UpdateLayoutDesignList(layoutDesignIndex); } void QmitkRenderWindow::mousePressEvent(QMouseEvent *me) { mitk::MousePressEvent::Pointer mPressEvent = mitk::MousePressEvent::New(m_Renderer, GetMousePosition(me), GetButtonState(me), GetModifiers(me), GetEventButton(me)); if (!this->HandleEvent(mPressEvent.GetPointer())) { // TODO: INTERACTION_LEGACY mitk::MouseEvent myevent(QmitkEventAdapter::AdaptMouseEvent(m_Renderer, me)); this->mousePressMitkEvent(&myevent); } QVTKWidget::mousePressEvent(me); if (m_ResendQtEvents) me->ignore(); } void QmitkRenderWindow::mouseReleaseEvent(QMouseEvent *me) { mitk::MouseReleaseEvent::Pointer mReleaseEvent = mitk::MouseReleaseEvent::New(m_Renderer, GetMousePosition(me), GetButtonState(me), GetModifiers(me), GetEventButton(me)); if (!this->HandleEvent(mReleaseEvent.GetPointer())) { // TODO: INTERACTION_LEGACY mitk::MouseEvent myevent(QmitkEventAdapter::AdaptMouseEvent(m_Renderer, me)); this->mouseReleaseMitkEvent(&myevent); } QVTKWidget::mouseReleaseEvent(me); if (m_ResendQtEvents) me->ignore(); } void QmitkRenderWindow::mouseMoveEvent(QMouseEvent *me) { this->AdjustRenderWindowMenuVisibility(me->pos()); mitk::MouseMoveEvent::Pointer mMoveEvent = mitk::MouseMoveEvent::New(m_Renderer, GetMousePosition(me), GetButtonState(me), GetModifiers(me)); if (!this->HandleEvent(mMoveEvent.GetPointer())) { // TODO: INTERACTION_LEGACY mitk::MouseEvent myevent(QmitkEventAdapter::AdaptMouseEvent(m_Renderer, me)); this->mouseMoveMitkEvent(&myevent); } QVTKWidget::mouseMoveEvent(me); } void QmitkRenderWindow::wheelEvent(QWheelEvent *we) { mitk::MouseWheelEvent::Pointer mWheelEvent = mitk::MouseWheelEvent::New(m_Renderer, GetMousePosition(we), GetButtonState(we), GetModifiers(we), GetDelta(we)); if (!this->HandleEvent(mWheelEvent.GetPointer())) { // TODO: INTERACTION_LEGACY mitk::WheelEvent myevent(QmitkEventAdapter::AdaptWheelEvent(m_Renderer, we)); this->wheelMitkEvent(&myevent); } QVTKWidget::wheelEvent(we); if (m_ResendQtEvents) we->ignore(); } void QmitkRenderWindow::keyPressEvent(QKeyEvent *ke) { - mitk::ModifierKeys modifiers = GetModifiers(ke); + mitk::InteractionEvent::ModifierKeys modifiers = GetModifiers(ke); std::string key = GetKeyLetter(ke); mitk::InteractionKeyEvent::Pointer keyEvent = mitk::InteractionKeyEvent::New(m_Renderer, key, modifiers); if (!this->HandleEvent(keyEvent.GetPointer())) { // TODO: INTERACTION_LEGACY QPoint cp = mapFromGlobal(QCursor::pos()); mitk::KeyEvent mke(QmitkEventAdapter::AdaptKeyEvent(m_Renderer, ke, cp)); this->keyPressMitkEvent(&mke); ke->accept(); } QVTKWidget::keyPressEvent(ke); if (m_ResendQtEvents) ke->ignore(); } void QmitkRenderWindow::enterEvent(QEvent *e) { // TODO implement new event QVTKWidget::enterEvent(e); } void QmitkRenderWindow::DeferredHideMenu() { MITK_DEBUG << "QmitkRenderWindow::DeferredHideMenu"; if (m_MenuWidget) m_MenuWidget->HideMenu(); } void QmitkRenderWindow::leaveEvent(QEvent *e) { mitk::InternalEvent::Pointer internalEvent = mitk::InternalEvent::New(this->m_Renderer, NULL, "LeaveRenderWindow"); if (!this->HandleEvent(internalEvent.GetPointer())) // TODO implement new event MITK_DEBUG << "QmitkRenderWindow::leaveEvent"; if (m_MenuWidget) m_MenuWidget->smoothHide(); QVTKWidget::leaveEvent(e); } void QmitkRenderWindow::paintEvent(QPaintEvent* /*event*/) { //We are using our own interaction and thus have to call the rendering manually. this->GetRenderer()->GetRenderingManager()->RequestUpdate(GetRenderWindow()); } void QmitkRenderWindow::resizeEvent(QResizeEvent* event) { this->resizeMitkEvent(event->size().width(), event->size().height()); QVTKWidget::resizeEvent(event); emit resized(); } void QmitkRenderWindow::moveEvent(QMoveEvent* event) { QVTKWidget::moveEvent(event); // after a move the overlays need to be positioned emit moved(); } void QmitkRenderWindow::showEvent(QShowEvent* event) { QVTKWidget::showEvent(event); // this singleshot is necessary to have the overlays positioned correctly after initial show // simple call of moved() is no use here!! QTimer::singleShot(0, this, SIGNAL( moved() )); } void QmitkRenderWindow::ActivateMenuWidget(bool state, QmitkStdMultiWidget* stdMultiWidget) { m_MenuWidgetActivated = state; if (!m_MenuWidgetActivated && m_MenuWidget) { //disconnect Signal/Slot Connection disconnect(m_MenuWidget, SIGNAL( SignalChangeLayoutDesign(int) ), this, SLOT(OnChangeLayoutDesign(int))); disconnect(m_MenuWidget, SIGNAL( ResetView() ), this, SIGNAL( ResetView())); disconnect(m_MenuWidget, SIGNAL( ChangeCrosshairRotationMode(int) ), this, SIGNAL( ChangeCrosshairRotationMode(int))); delete m_MenuWidget; m_MenuWidget = 0; } else if (m_MenuWidgetActivated && !m_MenuWidget) { //create render window MenuBar for split, close Window or set new setting. m_MenuWidget = new QmitkRenderWindowMenu(this, 0, m_Renderer, stdMultiWidget); m_MenuWidget->SetLayoutIndex(m_LayoutIndex); //create Signal/Slot Connection connect(m_MenuWidget, SIGNAL( SignalChangeLayoutDesign(int) ), this, SLOT(OnChangeLayoutDesign(int))); connect(m_MenuWidget, SIGNAL( ResetView() ), this, SIGNAL( ResetView())); connect(m_MenuWidget, SIGNAL( ChangeCrosshairRotationMode(int) ), this, SIGNAL( ChangeCrosshairRotationMode(int))); } } void QmitkRenderWindow::AdjustRenderWindowMenuVisibility(const QPoint& /*pos*/) { if (m_MenuWidget) { m_MenuWidget->ShowMenu(); m_MenuWidget->MoveWidgetToCorrectPos(1.0f); } } void QmitkRenderWindow::HideRenderWindowMenu() { // DEPRECATED METHOD } void QmitkRenderWindow::OnChangeLayoutDesign(int layoutDesignIndex) { emit SignalLayoutDesignChanged(layoutDesignIndex); } void QmitkRenderWindow::OnWidgetPlaneModeChanged(int mode) { if (m_MenuWidget) m_MenuWidget->NotifyNewWidgetPlanesMode(mode); } void QmitkRenderWindow::FullScreenMode(bool state) { if (m_MenuWidget) m_MenuWidget->ChangeFullScreenMode(state); } void QmitkRenderWindow::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("application/x-mitk-datanodes")) { event->accept(); } } void QmitkRenderWindow::dropEvent(QDropEvent * event) { if (event->mimeData()->hasFormat("application/x-mitk-datanodes")) { QString arg = QString(event->mimeData()->data("application/x-mitk-datanodes").data()); QStringList listOfDataNodes = arg.split(","); std::vector vectorOfDataNodePointers; for (int i = 0; i < listOfDataNodes.size(); i++) { long val = listOfDataNodes[i].toLong(); mitk::DataNode* node = static_cast((void*) val); vectorOfDataNodePointers.push_back(node); } emit NodesDropped(this, vectorOfDataNodePointers); } } -mitk::Point2D QmitkRenderWindow::GetMousePosition(QMouseEvent* me) +mitk::Point2D QmitkRenderWindow::GetMousePosition(QMouseEvent* me) const { mitk::Point2D point; point[0] = me->x(); point[1] = me->y(); return point; } -mitk::Point2D QmitkRenderWindow::GetMousePosition(QWheelEvent* we) +mitk::Point2D QmitkRenderWindow::GetMousePosition(QWheelEvent* we) const { mitk::Point2D point; point[0] = we->x(); point[1] = we->y(); return point; } -mitk::MouseButtons QmitkRenderWindow::GetEventButton(QMouseEvent* me) +mitk::InteractionEvent::MouseButtons QmitkRenderWindow::GetEventButton(QMouseEvent* me) const { - mitk::MouseButtons eventButton; + mitk::InteractionEvent::MouseButtons eventButton; switch (me->button()) { case Qt::LeftButton: - eventButton = mitk::LeftMouseButton; + eventButton = mitk::InteractionEvent::LeftMouseButton; break; case Qt::RightButton: - eventButton = mitk::RightMouseButton; + eventButton = mitk::InteractionEvent::RightMouseButton; break; case Qt::MidButton: - eventButton = mitk::MiddleMouseButton; + eventButton = mitk::InteractionEvent::MiddleMouseButton; break; default: - eventButton = mitk::NoButton; + eventButton = mitk::InteractionEvent::NoButton; break; } return eventButton; } -mitk::MouseButtons QmitkRenderWindow::GetButtonState(QMouseEvent* me) +mitk::InteractionEvent::MouseButtons QmitkRenderWindow::GetButtonState(QMouseEvent* me) const { - mitk::MouseButtons buttonState = mitk::NoButton; + mitk::InteractionEvent::MouseButtons buttonState = mitk::InteractionEvent::NoButton; if (me->buttons() & Qt::LeftButton) { - buttonState = buttonState | mitk::LeftMouseButton; + buttonState = buttonState | mitk::InteractionEvent::LeftMouseButton; } if (me->buttons() & Qt::RightButton) { - buttonState = buttonState | mitk::RightMouseButton; + buttonState = buttonState | mitk::InteractionEvent::RightMouseButton; } if (me->buttons() & Qt::MidButton) { - buttonState = buttonState | mitk::MiddleMouseButton; + buttonState = buttonState | mitk::InteractionEvent::MiddleMouseButton; } return buttonState; } -mitk::ModifierKeys QmitkRenderWindow::GetModifiers(QMouseEvent* me) +mitk::InteractionEvent::ModifierKeys QmitkRenderWindow::GetModifiers(QMouseEvent* me) const { - mitk::ModifierKeys modifiers = mitk::NoKey; + mitk::InteractionEvent::ModifierKeys modifiers = mitk::InteractionEvent::NoKey; if (me->modifiers() & Qt::ALT) { - modifiers = modifiers | mitk::AltKey; + modifiers = modifiers | mitk::InteractionEvent::AltKey; } if (me->modifiers() & Qt::CTRL) { - modifiers = modifiers | mitk::ControlKey; + modifiers = modifiers | mitk::InteractionEvent::ControlKey; } if (me->modifiers() & Qt::SHIFT) { - modifiers = modifiers | mitk::ShiftKey; + modifiers = modifiers | mitk::InteractionEvent::ShiftKey; } return modifiers; } -mitk::MouseButtons QmitkRenderWindow::GetButtonState(QWheelEvent* we) +mitk::InteractionEvent::MouseButtons QmitkRenderWindow::GetButtonState(QWheelEvent* we) const { - mitk::MouseButtons buttonState = mitk::NoButton; + mitk::InteractionEvent::MouseButtons buttonState = mitk::InteractionEvent::NoButton; if (we->buttons() & Qt::LeftButton) { - buttonState = buttonState | mitk::RightMouseButton; + buttonState = buttonState | mitk::InteractionEvent::RightMouseButton; } if (we->buttons() & Qt::RightButton) { - buttonState = buttonState | mitk::LeftMouseButton; + buttonState = buttonState | mitk::InteractionEvent::LeftMouseButton; } if (we->buttons() & Qt::MidButton) { - buttonState = buttonState | mitk::MiddleMouseButton; + buttonState = buttonState | mitk::InteractionEvent::MiddleMouseButton; } return buttonState; } -mitk::ModifierKeys QmitkRenderWindow::GetModifiers(QWheelEvent* we) +mitk::InteractionEvent::ModifierKeys QmitkRenderWindow::GetModifiers(QWheelEvent* we) const { - mitk::ModifierKeys modifiers = mitk::NoKey; + mitk::InteractionEvent::ModifierKeys modifiers = mitk::InteractionEvent::NoKey; if (we->modifiers() & Qt::ALT) { - modifiers = modifiers | mitk::AltKey; + modifiers = modifiers | mitk::InteractionEvent::AltKey; } if (we->modifiers() & Qt::CTRL) { - modifiers = modifiers | mitk::ControlKey; + modifiers = modifiers | mitk::InteractionEvent::ControlKey; } if (we->modifiers() & Qt::SHIFT) { - modifiers = modifiers | mitk::ShiftKey; + modifiers = modifiers | mitk::InteractionEvent::ShiftKey; } return modifiers; } -mitk::ModifierKeys QmitkRenderWindow::GetModifiers(QKeyEvent* ke) +mitk::InteractionEvent::ModifierKeys QmitkRenderWindow::GetModifiers(QKeyEvent* ke) const { - mitk::ModifierKeys modifiers = mitk::NoKey; + mitk::InteractionEvent::ModifierKeys modifiers = mitk::InteractionEvent::NoKey; if (ke->modifiers() & Qt::ShiftModifier) - modifiers = modifiers | mitk::ShiftKey; + modifiers = modifiers | mitk::InteractionEvent::ShiftKey; if (ke->modifiers() & Qt::CTRL) - modifiers = modifiers | mitk::ControlKey; + modifiers = modifiers | mitk::InteractionEvent::ControlKey; if (ke->modifiers() & Qt::ALT) - modifiers = modifiers | mitk::AltKey; + modifiers = modifiers | mitk::InteractionEvent::AltKey; return modifiers; } -std::string QmitkRenderWindow::GetKeyLetter(QKeyEvent *ke) +std::string QmitkRenderWindow::GetKeyLetter(QKeyEvent *ke) const { // Converting Qt Key Event to string element. std::string key = ""; int tkey = ke->key(); if (tkey < 128) { //standard ascii letter key = (char) toupper(tkey); } else { // special keys switch (tkey) { case Qt::Key_Return: - key = mitk::KeyReturn; + key = mitk::InteractionEvent::KeyReturn; break; case Qt::Key_Enter: - key = mitk::KeyEnter; + key = mitk::InteractionEvent::KeyEnter; break; case Qt::Key_Escape: - key = mitk::KeyEnter; + key = mitk::InteractionEvent::KeyEnter; break; case Qt::Key_Delete: - key = mitk::KeyDelete; + key = mitk::InteractionEvent::KeyDelete; break; case Qt::Key_Up: - key = mitk::KeyArrowUp; + key = mitk::InteractionEvent::KeyArrowUp; break; case Qt::Key_Down: - key = mitk::KeyArrowDown; + key = mitk::InteractionEvent::KeyArrowDown; break; case Qt::Key_Left: - key = mitk::KeyArrowLeft; + key = mitk::InteractionEvent::KeyArrowLeft; break; case Qt::Key_Right: - key = mitk::KeyArrowRight; + key = mitk::InteractionEvent::KeyArrowRight; break; case Qt::Key_F1: - key = mitk::KeyF1; + key = mitk::InteractionEvent::KeyF1; break; case Qt::Key_F2: - key = mitk::KeyF2; + key = mitk::InteractionEvent::KeyF2; break; case Qt::Key_F3: - key = mitk::KeyF3; + key = mitk::InteractionEvent::KeyF3; break; case Qt::Key_F4: - key = mitk::KeyF4; + key = mitk::InteractionEvent::KeyF4; break; case Qt::Key_F5: - key = mitk::KeyF5; + key = mitk::InteractionEvent::KeyF5; break; case Qt::Key_F6: - key = mitk::KeyF6; + key = mitk::InteractionEvent::KeyF6; break; case Qt::Key_F7: - key = mitk::KeyF7; + key = mitk::InteractionEvent::KeyF7; break; case Qt::Key_F8: - key = mitk::KeyF8; + key = mitk::InteractionEvent::KeyF8; break; case Qt::Key_F9: - key = mitk::KeyF9; + key = mitk::InteractionEvent::KeyF9; break; case Qt::Key_F10: - key = mitk::KeyF10; + key = mitk::InteractionEvent::KeyF10; break; case Qt::Key_F11: - key = mitk::KeyF11; + key = mitk::InteractionEvent::KeyF11; break; case Qt::Key_F12: - key = mitk::KeyF12; + key = mitk::InteractionEvent::KeyF12; break; case Qt::Key_End: - key = mitk::KeyEnd; + key = mitk::InteractionEvent::KeyEnd; break; case Qt::Key_Home: - key = mitk::KeyPos1; + key = mitk::InteractionEvent::KeyPos1; break; case Qt::Key_Insert: - key = mitk::KeyInsert; + key = mitk::InteractionEvent::KeyInsert; break; case Qt::Key_PageDown: - key = mitk::KeyPageDown; + key = mitk::InteractionEvent::KeyPageDown; break; case Qt::Key_PageUp: - key = mitk::KeyPageUp; + key = mitk::InteractionEvent::KeyPageUp; break; case Qt::Key_Space: - key = mitk::KeySpace; + key = mitk::InteractionEvent::KeySpace; break; } } return key; } -int QmitkRenderWindow::GetDelta(QWheelEvent* we) +int QmitkRenderWindow::GetDelta(QWheelEvent* we) const { return we->delta(); } diff --git a/Modules/Qmitk/QmitkRenderWindow.h b/Modules/Qmitk/QmitkRenderWindow.h index 0763cd2e1e..b41332a344 100644 --- a/Modules/Qmitk/QmitkRenderWindow.h +++ b/Modules/Qmitk/QmitkRenderWindow.h @@ -1,180 +1,180 @@ /*=================================================================== 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 QMITKRENDERWINDOW_H_HEADER_INCLUDED_C1C40D66 #define QMITKRENDERWINDOW_H_HEADER_INCLUDED_C1C40D66 #include "mitkRenderWindowBase.h" #include #include "QVTKWidget.h" #include "QmitkRenderWindowMenu.h" #include "mitkInteractionEventConst.h" class QmitkStdMultiWidget; class QDragEnterEvent; class QDropEvent; /** * \ingroup QmitkModule * \brief MITK implementation of the QVTKWidget */ class QMITK_EXPORT QmitkRenderWindow: public QVTKWidget, public mitk::RenderWindowBase { Q_OBJECT public: QmitkRenderWindow(QWidget *parent = 0, QString name = "unnamed renderwindow", mitk::VtkPropRenderer* renderer = NULL, mitk::RenderingManager* renderingManager = NULL); virtual ~QmitkRenderWindow(); /** * \brief Whether Qt events should be passed to parent (default: true) * * With introduction of the QVTKWidget the behaviour regarding Qt events changed. * QVTKWidget "accepts" Qt events like mouse clicks (i.e. set an "accepted" flag). * When this flag is set, Qt fininshed handling of this event -- otherwise it is * reached through to the widget's parent. * * This reaching through to the parent was implicitly required by QmitkMaterialWidget / QmitkMaterialShowCase. *QmitkStdMultiWidget * The default behaviour of QmitkRenderWindow is now to clear the "accepted" flag * of Qt events after they were handled by QVTKWidget. This way parents can also * handle events. * * If you don't want this behaviour, call SetResendQtEvents(true) on your render window. */ virtual void SetResendQtEvents(bool resend); // Set Layout Index to define the Layout Type void SetLayoutIndex(unsigned int layoutIndex); // Get Layout Index to define the Layout Type unsigned int GetLayoutIndex(); //MenuWidget need to update the Layout Design List when Layout had changed void LayoutDesignListChanged(int layoutDesignIndex); void HideRenderWindowMenu(); //Activate or Deactivate MenuWidget. void ActivateMenuWidget(bool state, QmitkStdMultiWidget* stdMultiWidget = 0); bool GetActivateMenuWidgetFlag() { return m_MenuWidgetActivated; } // Get it from the QVTKWidget parent virtual vtkRenderWindow* GetVtkRenderWindow() { return GetRenderWindow(); } virtual vtkRenderWindowInteractor* GetVtkRenderWindowInteractor() { return NULL; } void FullScreenMode(bool state); protected: // overloaded move handler virtual void moveEvent(QMoveEvent* event); // overloaded show handler void showEvent(QShowEvent* event); // overloaded resize handler virtual void resizeEvent(QResizeEvent* event); // overloaded paint handler virtual void paintEvent(QPaintEvent* event); // overloaded mouse press handler virtual void mousePressEvent(QMouseEvent* event); // overloaded mouse move handler virtual void mouseMoveEvent(QMouseEvent* event); // overloaded mouse release handler virtual void mouseReleaseEvent(QMouseEvent* event); // overloaded key press handler virtual void keyPressEvent(QKeyEvent* event); // overloaded enter handler virtual void enterEvent(QEvent*); // overloaded leave handler virtual void leaveEvent(QEvent*); /// \brief Simply says we accept the event type. virtual void dragEnterEvent(QDragEnterEvent *event); /// \brief If the dropped type is application/x-mitk-datanodes we process the request by converting to mitk::DataNode pointers and emitting the NodesDropped signal. virtual void dropEvent(QDropEvent * event); #ifndef QT_NO_WHEELEVENT // overload wheel mouse event virtual void wheelEvent(QWheelEvent*); #endif void AdjustRenderWindowMenuVisibility(const QPoint& pos); signals: void ResetView(); // \brief int parameters are enum from QmitkStdMultiWidget void ChangeCrosshairRotationMode(int); void SignalLayoutDesignChanged(int layoutDesignIndex); void moved(); void resized(); /// \brief Emits a signal to say that this window has had the following nodes dropped on it. void NodesDropped(QmitkRenderWindow *thisWindow, std::vector nodes); protected slots: void OnChangeLayoutDesign(int layoutDesignIndex); void OnWidgetPlaneModeChanged(int); void DeferredHideMenu(); private: // Helper Functions to Convert Qt-Events to Mitk-Events - mitk::Point2D GetMousePosition(QMouseEvent* me); - mitk::Point2D GetMousePosition(QWheelEvent* we); - mitk::MouseButtons GetEventButton(QMouseEvent* me); - mitk::MouseButtons GetButtonState(QMouseEvent* me); - mitk::ModifierKeys GetModifiers(QMouseEvent* me); - mitk::MouseButtons GetButtonState(QWheelEvent* we); - mitk::ModifierKeys GetModifiers(QWheelEvent* we); - mitk::ModifierKeys GetModifiers(QKeyEvent* ke); - std::string GetKeyLetter(QKeyEvent* ke); - int GetDelta(QWheelEvent* we); + mitk::Point2D GetMousePosition(QMouseEvent* me) const; + mitk::Point2D GetMousePosition(QWheelEvent* we) const; + mitk::InteractionEvent::MouseButtons GetEventButton(QMouseEvent* me) const; + mitk::InteractionEvent::MouseButtons GetButtonState(QMouseEvent* me) const; + mitk::InteractionEvent::ModifierKeys GetModifiers(QMouseEvent* me) const; + mitk::InteractionEvent::MouseButtons GetButtonState(QWheelEvent* we) const; + mitk::InteractionEvent::ModifierKeys GetModifiers(QWheelEvent* we) const; + mitk::InteractionEvent::ModifierKeys GetModifiers(QKeyEvent* ke) const; + std::string GetKeyLetter(QKeyEvent* ke) const; + int GetDelta(QWheelEvent* we) const; bool m_ResendQtEvents; QmitkRenderWindowMenu* m_MenuWidget; bool m_MenuWidgetActivated; unsigned int m_LayoutIndex; }; #endif