00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #ifndef EVENTMAPPER_H_HEADER_INCLUDED 00020 #define EVENTMAPPER_H_HEADER_INCLUDED 00021 00022 #include <mitkEvent.h> 00023 #include <mitkCommon.h> 00024 #include <mitkEventDescription.h> 00025 #include <vtkXMLParser.h> 00026 00027 #include <mitkEventMapperAddOn.h> 00028 00029 namespace mitk { 00030 struct ltstr 00031 { 00032 bool operator()(const char* s1, const char* s2) const 00033 { 00034 return strcmp(s1, s2) < 0; 00035 } 00036 }; 00037 typedef std::string msgString; 00038 //for friendship wor to set the stateevent after calculating 00039 class GlobalInteraction; 00040 class StateMachine; 00041 class StateEvent; 00042 00043 //##Documentation 00044 //## @brief Maps an Event to its description 00045 //## 00046 //## EventMapping: 00047 //## This class mapps the Events, usually given by the OS or here by QT, to a MITK internal EventId. 00048 //## It loads all information from the xml-file (possible, understandable Events with the mitkEventID). 00049 //## If an event appears, the method MapEvent is called with the event params. 00050 //## This Method looks up the event params, and tries to find an mitkEventId to it. 00051 //## If yes, then sends the event and the found ID to the globalStateMachine, which handles all 00052 //## further operations of that event. 00053 //## For Undo-Mechanism a statechanging StateMachine::HandleEvent is connected to an ObjectEventID and an GroupEventId. 00054 //## That way a fine an raw Undo is possible (fine for ObjectID by ObjectID, raw for GroupID for GroupID) 00055 //## Here the ObjectEventID gets increased, 00056 //## not the GroupEventId(must get increased by a StateMachine, that has the information when a new Group of operation starts) 00057 //## @ingroup Interaction 00058 class MITK_CORE_EXPORT EventMapper : public vtkXMLParser 00059 { 00060 public: 00061 static EventMapper *New(); 00062 vtkTypeMacro(EventMapper,vtkXMLParser); 00063 00064 typedef std::vector<mitk::EventDescription> EventDescriptionVec; 00065 typedef std::vector<mitk::EventDescription>::iterator EventDescriptionVecIter; 00066 00067 typedef std::map<const char*, int, ltstr> ConstMap; 00068 typedef std::map<const char*, int, ltstr>::iterator ConstMapIter; 00069 00070 typedef std::vector<mitk::EventMapperAddOn::Pointer> AddOnVectorType; 00071 00072 //##Documentation 00073 //## searches the Event in m_EventDescription 00074 //## and if included transmits the event to globalInteraction. 00075 //## If specified, a custom instance of GlobalInteraction will be used, 00076 //## otherwise the method will retrieve the default (singleton) instance. 00077 //## the optional parameter should be used in a conference to avoid a 00078 //## feedback 00079 static bool MapEvent(Event* event, GlobalInteraction* globalInteraction = NULL, int mitkPostedEventID=0 ); 00080 00081 //##Documentation 00082 //## Searches for the event within stateEvent in the internal map of event descriptions 00083 //## If entry found the stateEvent ID is adapted 00084 //## maps the Event in m_EventDescription with the ID 00085 //## and if found returns true, 00086 //## if not found it returns false 00087 static bool RefreshStateEvent(StateEvent* stateEvent); 00088 00089 //##Documentation 00090 //## loads an XML-File containing Events into m_EventDescriptions 00091 //## also involved: EventMapper::startEvent(...) 00092 bool LoadBehavior(std::string fileName); 00093 00094 //##Documentation 00095 //## loads Events into m_EventDescriptions from xml string 00096 //## also involved: EventMapper::startEvent(...) 00097 bool LoadBehaviorString(std::string xmlString); 00098 00099 //##Documentation 00100 //## Try to load standard behavior file "StateMachine.xml" 00101 //## 00102 //## Search strategy: 00103 //## \li try environment variable "MITKCONF" (path to "StateMachine.xml") 00104 //## \li try "./StateMachine.xml" 00105 //## \li try via source directory (using MITKROOT from cmake-created 00106 //## mitkConfig.h) "MITKROOT/Interactions/mitkBaseInteraction/StateMachine.xml" 00107 bool LoadStandardBehavior(); 00108 00109 //##Documentation 00110 //## reads a Tag from an XML-file 00111 //## adds Events to m_EventDescription 00112 00113 std::string GetStyleName() const; 00114 00115 //friendship because of SetStateEvent for computing WorldCoordinates 00116 friend class mitk::GlobalInteraction; 00117 00121 void AddEventMapperAddOn(mitk::EventMapperAddOn* newAddOn); 00122 00126 void RemoveEventMapperAddOn(mitk::EventMapperAddOn* unusedAddOn); 00127 00128 00129 protected: 00130 EventMapper(); 00131 ~EventMapper(); 00132 00133 //##Documentation 00134 //##@brief method only for GlobalInteraction to change the Event (from DiplayPositionEvent to PositionEvent) 00135 static void SetStateEvent(Event* event); 00136 00137 private: 00138 00139 //##Documentation 00140 //## @brief method used in XLM-Reading; gets called when a start-tag is read 00141 void StartElement (const char *elementName, const char **atts); 00142 00143 //##Documentation 00144 //## @brief reads an XML-String-Attribute 00145 std::string ReadXMLStringAttribut( std::string name, const char** atts); 00146 00147 //##Documentation 00148 //## @brief reads an XML-Integer-Attribute 00149 int ReadXMLIntegerAttribut( std::string name, const char** atts ); 00150 00151 //##Documentation 00152 //## @brief converts the strings given by the XML-Behaviour-File to int 00153 inline int convertConstString2ConstInt(std::string input); 00154 //static std::string Convert2String(int input); 00155 //static std::string Convert2String(double input); 00156 //static std::string Convert2String(float input); 00157 00158 //##Documentation 00159 //## @brief maps the strings to int for convertion from XML-Behaviour-File 00160 ConstMap m_EventConstMap; 00161 00162 //##Documentation 00163 //## @brief stores the information for the connection between QT-Events and the internal EventId. 00164 //## gets this information from xml-File 00165 static EventDescriptionVec m_EventDescriptions; 00166 00167 static StateEvent m_StateEvent; 00168 00169 //##Documentation 00170 //## @brief stores the name of the Event-Style loaded 00171 static std::string m_StyleName; 00172 00173 static const std::string STYLE; 00174 static const std::string NAME; 00175 static const std::string ID; 00176 static const std::string TYPE; 00177 static const std::string BUTTON; 00178 static const std::string BUTTONSTATE; 00179 static const std::string KEY; 00180 static const std::string EVENTS; 00181 static const std::string EVENT; 00182 00186 AddOnVectorType m_AddOnVector; 00187 00188 }; 00189 } // namespace mitk 00190 00191 #endif /* EVENTMAPPER_H_HEADER_INCLUDED_C187864A */ 00192 00193