29 std::vector<std::string> &split(
const std::string &s,
char delim, std::vector<std::string> &elems)
31 std::stringstream ss(s);
33 while (std::getline(ss, item, delim))
35 elems.push_back(item);
40 std::vector<std::string> split(
const std::string &s,
char delim)
42 std::vector<std::string> elems;
43 return split(s, delim, elems);
55 std::string eventClass =
event->GetNameOfClass();
56 std::transform(eventClass.cbegin(), eventClass.cend(), eventClass.begin(), ::toupper);
58 std::string strButtonState =
"";
59 if (eventClass ==
"MOUSEPRESSEVENT")
64 if (eventClass ==
"MOUSERELEASEEVENT")
69 if (eventClass ==
"MOUSEDOUBLECLICKEVENT")
74 if (eventClass ==
"MOUSEMOVEEVENT")
79 if (eventClass ==
"MOUSEWHEELEVENT")
87 strButtonState =
"LeftMouseButton";
91 if (strButtonState !=
"")
92 strButtonState +=
",";
94 strButtonState +=
"RightMouseButton";
98 if (strButtonState !=
"")
99 strButtonState +=
",";
101 strButtonState +=
"MiddleMouseButton";
103 return strButtonState;
114 std::string eventClass =
event->GetNameOfClass();
115 std::transform(eventClass.cbegin(), eventClass.cend(), eventClass.begin(), ::toupper);
116 std::string strModKeys =
"";
118 if (eventClass ==
"MOUSEPRESSEVENT")
123 if (eventClass ==
"MOUSERELEASEEVENT")
128 if (eventClass ==
"MOUSEDOUBLECLICKEVENT")
133 if (eventClass ==
"MOUSEMOVEEVENT")
138 if (eventClass ==
"MOUSEWHEELEVENT")
146 strModKeys =
"SHIFT";
150 if (strModKeys !=
"")
153 strModKeys +=
"CTRL";
157 if (strModKeys !=
"")
173 std::string eventClass =
event->GetNameOfClass();
174 std::transform(eventClass.cbegin(), eventClass.cend(), eventClass.begin(), ::toupper);
175 std::string stdButton =
"";
177 if (eventClass ==
"MOUSEPRESSEVENT")
182 if (eventClass ==
"MOUSERELEASEEVENT")
187 if (eventClass ==
"MOUSEDOUBLECLICKEVENT")
195 stdButton =
"LeftMouseButton";
199 stdButton =
"RightMouseButton";
203 stdButton =
"MiddleMouseButton";
215 std::stringstream ss;
220 ss << p[0] <<
"," << p[1] <<
"," << p[2];
232 std::stringstream ss;
237 ss << p[0] <<
"," << p[1];
245 std::string eventClass, eventVariant;
251 std::string strModifiers;
253 std::string strEventButton;
255 std::string strButtonState;
259 std::string strWheelDelta;
261 std::string strSignalName =
"";
272 commaPos = strPos.find_first_of(
',');
274 pos[0] =
static_cast<mitk::ScalarType>(std::atof(strPos.substr(0, commaPos).c_str()));
275 pos[1] =
static_cast<mitk::ScalarType>(std::atof(strPos.substr(commaPos + 1, strPos.length()).c_str()));
278 std::string strWorld;
284 const std::vector<std::string> coords = split(strWorld,
',');
286 for (
auto it = coords.cbegin(); it != coords.cend(); ++it, ++i)
288 worldPos[i] = atof((*it).c_str());
295 std::vector<std::string> mods = split(strModifiers,
',');
296 for (
auto it = mods.begin(); it != mods.end(); ++it)
298 std::transform((*it).cbegin(), (*it).cend(), (*it).begin(), ::toupper);
303 else if (*it ==
"ALT")
307 else if (*it ==
"SHIFT")
313 MITK_WARN <<
"mitkEventFactory: Invalid event modifier in config file :" << (*it);
321 std::transform(strEventButton.cbegin(), strEventButton.cend(), strEventButton.begin(), ::toupper);
322 if (strEventButton ==
"MIDDLEMOUSEBUTTON")
326 else if (strEventButton ==
"LEFTMOUSEBUTTON")
330 else if (strEventButton ==
"RIGHTMOUSEBUTTON")
336 MITK_WARN <<
"mitkEventFactory: Invalid event button in config file: " << strEventButton;
343 std::vector<std::string> mods = split(strButtonState,
',');
344 for (
auto it = mods.begin(); it != mods.end(); ++it)
346 std::transform((*it).cbegin(), (*it).cend(), (*it).begin(), ::toupper);
347 if (*it ==
"MIDDLEMOUSEBUTTON")
351 else if (*it ==
"LEFTMOUSEBUTTON")
355 else if (*it ==
"RIGHTMOUSEBUTTON")
361 MITK_WARN <<
"mitkEventFactory: Invalid event buttonstate in config file:" << (*it);
382 std::transform(strWheelDelta.cbegin(), strWheelDelta.cend(), strWheelDelta.begin(), ::toupper);
383 if (strWheelDelta ==
"DOWN")
397 std::string strRenderer;
409 if (renderer ==
nullptr)
418 std::transform(eventClass.cbegin(), eventClass.cend(), eventClass.begin(), ::toupper);
420 if (eventClass ==
"MOUSEPRESSEVENT")
423 buttonState = buttonState | eventButton;
426 else if (eventClass ==
"MOUSEDOUBLECLICKEVENT")
428 buttonState = buttonState | eventButton;
431 else if (eventClass ==
"MOUSEMOVEEVENT")
435 else if (eventClass ==
"MOUSERELEASEEVENT")
439 else if (eventClass ==
"INTERACTIONKEYEVENT")
443 else if (eventClass ==
"MOUSEWHEELEVENT")
447 else if (eventClass ==
"INTERACTIONPOSITIONEVENT")
451 else if (eventClass ==
"INTERNALEVENT")
455 else if (eventClass ==
"INTERACTIONEVENT")
461 MITK_WARN <<
"Event couldn't be constructed. Please check your StateMachine patterns and config files\n for the " 462 "following event class, which is not valid: " 475 std::string eventClass =
event->GetNameOfClass();
476 std::string eventXML =
479 std::transform(eventClass.cbegin(), eventClass.cend(), eventClass.begin(), ::toupper);
481 eventXML += eventClass +
"\" >\n";
483 if (eventClass ==
"MOUSEPRESSEVENT" || eventClass ==
"MOUSERELEASEEVENT" || eventClass ==
"MOUSEDOUBLECLICKEVENT" ||
484 eventClass ==
"MOUSEMOVEEVENT" || eventClass ==
"MOUSEWHEELEVENT")
486 if (!(eventClass ==
"MOUSEMOVEEVENT") && !(eventClass ==
"MOUSEWHEELEVENT"))
493 eventXML +=
"\"/>\n";
502 eventXML +=
"\"/>\n";
512 eventXML +=
"\"/>\n";
520 eventXML +=
"\"/>\n";
527 eventXML +=
"\"/>\n";
529 else if (eventClass ==
"INTERACTIONKEYEVENT")
537 eventXML += ke->GetKey();
538 eventXML +=
"\"/>\n";
542 MITK_WARN <<
"Event not recognized, discarding event of type " <<
event->GetNameOfClass();
544 if (eventClass ==
"MOUSEWHEELEVENT")
549 std::stringstream ss;
555 eventXML += ss.str();
556 eventXML +=
"\"/>\n";
561 eventXML += delta < 0 ?
"DOWN" :
"UP";
562 eventXML +=
"\"/>\n";
569 eventXML +=
event->GetSender()->GetName();
570 eventXML +=
"\"/>\n";
static const std::string xmlEventPropertyPositionInWorld()
static std::string EventToXML(InteractionEvent *event)
EventToXML Transforms an event into a XML tag describing it.
static const std::string xmlEventPropertyPositionOnScreen()
static const std::string xmlParameterName()
ModifierKeys GetModifiers() const
Super class for all position events.
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
static const std::string xmlEventPropertyRendererName()
static const std::string xmlParameterValue()
static const std::string xmlEventPropertyEventButton()
static std::string GetPositionOnScreen(mitk::InteractionEvent *event)
GetPositionOnScreen Return PositionOnScreen as String.
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
ModifierKeys GetModifiers() const
Organizes the rendering process.
static const std::string xmlEventPropertyModifier()
MouseButtons GetButtonStates() const
Class to create events from within the application to signal about internal events.
static std::string GetEventButton(mitk::InteractionEvent *event)
GetEventButton Return EventButton as String.
static Pointer New(BaseRenderer *_arga, const Point2D &_argb)
static const std::string xmlEventPropertyScrollDirection()
static const std::string xmlParameterEventClass()
static InteractionEvent::Pointer CreateEvent(PropertyList::Pointer eventDescription)
MouseButtons GetButtonStates() const
static Pointer New(BaseRenderer *_arg)
static std::string GetButtonState(mitk::InteractionEvent *event)
GetEventButton Return EventButton as String.
static const std::string xmlEventPropertyButtonState()
static const std::string xmlParameterEventVariant()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, int _arge)
MouseButtons GetButtonStates() const
static Pointer New(BaseRenderer *_arga, const std::string &_argb, ModifierKeys _argc)
int GetWheelDelta() const
MouseButtons GetButtonStates() const
static BaseRendererMapType baseRendererMap
static const std::string xmlEventPropertyWheelDelta()
static const std::string xmlEventPropertyKey()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd)
static const std::string xmlTagEventVariant()
static std::string GetModifierState(mitk::InteractionEvent *event)
GetModifierState Return ModifierState as String.
MouseButtons GetEventButton() const
ModifierKeys GetModifiers() const
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
ModifierKeys GetModifiers() const
Handles key events. Takes a std::string for pressed key or special key description, mitk::ModifierKeys for modifiers
static BaseRenderer * GetByName(const std::string &name)
MouseButtons GetButtonStates() const
static const std::string xmlEventPropertySignalName()
static Pointer New(BaseRenderer *_arga, DataInteractor *_argb, const std::string &_argc)
static std::string GetPositionInWorld(mitk::InteractionEvent *event)
GetPosition Return World Position as String.
MouseButtons GetEventButton() const
MouseButtons GetEventButton() const
ModifierKeys GetModifiers() const
static const std::string xmlTagAttribute()