void mitk::XML2EventParser::EndElement(const char *elementName)
 {
   std::string name(elementName);
   // At end of input section, all necessary infos are collected to created an interaction event.
   if (name == InteractionEventConst::xmlTagEventVariant())
   {
     InteractionEvent::Pointer event = EventFactory::CreateEvent(m_EventPropertyList);
     if (event.IsNotNull())
     {
       m_InteractionList.push_back(event);
     }
     else
     {
       MITK_WARN << "EventConfig: Unknown Event-Type in config. Entry skipped: " << name;
     }
   }
 }
void mitk::EventConfigXMLParser::EndElement(const char *elementName)
{
  const std::string name(elementName);
  // At end of input section, all necessary infos are collected to created an interaction event.
  if (name == InteractionEventConst::xmlTagEventVariant())
  {
    InteractionEvent::Pointer event = EventFactory::CreateEvent(d->m_EventPropertyList);
    if (event.IsNotNull())
    {
      d->m_CurrEventMapping.interactionEvent = event;
      d->InsertMapping(d->m_CurrEventMapping);
    }
    else
    {
      MITK_WARN << "EventConfig: Unknown Event-Type in config. Entry skipped: " << name;
    }
  }
}
Beispiel #3
0
mitk::EventConfig::EventConfig(const std::vector<PropertyList::Pointer> &configDescription)
: d(new EventConfigPrivate)
{
  std::vector<PropertyList::Pointer>::const_iterator it_end = configDescription.end();
  for (std::vector<PropertyList::Pointer>::const_iterator it = configDescription.begin(); it != it_end; ++it)
  {
    std::string typeVariant;
    (*it)->GetStringProperty(InteractionEventConst::xmlTagEventVariant().c_str(), typeVariant);
    if ( typeVariant != "" )
    {
      InteractionEvent::Pointer event = EventFactory::CreateEvent(*it);
      if (event.IsNotNull())
      {

        d->m_CurrEventMapping.interactionEvent = event;
        std::string eventVariant;
        (*it)->GetStringProperty(InteractionEventConst::xmlTagEventVariant().c_str(), eventVariant);
        d->m_CurrEventMapping.variantName = eventVariant;
        d->InsertMapping(d->m_CurrEventMapping);
      }
      else
      {
        MITK_WARN<< "EventConfig: Unknown Event-Type in config. When constructing from PropertyList.";
      }
    }
    else
    {
      (*it)->GetStringProperty(InteractionEventConst::xmlTagParam().c_str(), typeVariant);
      if ( typeVariant != "" )
      {
        std::string name, value;
        (*it)->GetStringProperty(InteractionEventConst::xmlParameterName().c_str(), name);
        (*it)->GetStringProperty(InteractionEventConst::xmlParameterValue().c_str(), value);
        d->m_PropertyList->SetStringProperty(name.c_str(), value.c_str());
      }
    }
  }
}
Beispiel #4
0
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<InternalEvent*>(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 (std::strcmp(p->GetNameOfClass(), "MouseReleaseEvent") == 0)
    {
      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<DataInteractor::Pointer>::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 (std::strcmp(p->GetNameOfClass(), "MousePressEvent") == 0 && m_ProcessingMode == REGULAR)
        {
          m_SelectedInteractor = dataInteractor;
          m_ProcessingMode = CONNECTEDMOUSEACTION;
        }
        eventIsHandled = true;
        break;
      }
    }
  }

  /* Notify InteractionEventObserver  */
  std::list<mitk::ServiceReference> listEventObserver;
  m_EventObserverTracker->GetServiceReferences(listEventObserver);
  for (std::list<mitk::ServiceReference>::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;
}
bool mitk::InteractionEvent::IsSuperClassOf(const InteractionEvent::Pointer& baseClass) const
{
    return (dynamic_cast<InteractionEvent*>(baseClass.GetPointer()) != NULL) ;
}
Beispiel #6
0
bool mitk::Dispatcher::ProcessEvent(InteractionEvent* event)
{
  InteractionEvent::Pointer p = event;
  bool eventIsHandled = false;
  /* Filter out and handle Internal Events separately */
  InternalEvent* internalEvent = dynamic_cast<InternalEvent*>(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 (std::strcmp(p->GetNameOfClass(), "MouseReleaseEvent") == 0)
    {
      m_ProcessingMode = REGULAR;
      eventIsHandled = m_SelectedInteractor->HandleEvent(event, m_SelectedInteractor->GetDataNode());
      // delete reference to interactor as soon as connected action is finished
      m_SelectedInteractor = NULL;
    }
    // give event to selected interactor
    if (eventIsHandled == false && m_SelectedInteractor.IsNotNull())
    {
      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))
  {
    if (std::strcmp(p->GetNameOfClass(), "MousePressEvent") == 0)
      event->GetSender()->GetRenderingManager()->SetRenderWindowFocus(event->GetSender()->GetRenderWindow());
    m_Interactors.sort(cmp()); // sorts interactors by layer (descending);

    // copy the list to prevent iterator invalidation as executing actions
    // in HandleEvent() can cause the m_Interactors list to be updated
    const std::list<DataInteractor::Pointer> tmpInteractorList( m_Interactors );
    std::list<DataInteractor::Pointer>::const_iterator it;
    for ( it=tmpInteractorList.cbegin(); it!=tmpInteractorList.cend(); ++it )
    {
      DataInteractor::Pointer dataInteractor = *it;
      if ( (*it)->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 (std::strcmp(p->GetNameOfClass(), "MousePressEvent") == 0 && m_ProcessingMode == REGULAR)
        {
          m_SelectedInteractor = dataInteractor;
          m_ProcessingMode = CONNECTEDMOUSEACTION;
        }
        eventIsHandled = true;
        break;
      }
    }
  }

  /* Notify InteractionEventObserver  */
  const std::vector<us::ServiceReference<InteractionEventObserver> > listEventObserver =
      m_EventObserverTracker->GetServiceReferences();
  for (std::vector<us::ServiceReference<InteractionEventObserver> >::const_iterator it = listEventObserver.cbegin();
       it != listEventObserver.cend(); ++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;
}
Beispiel #7
0
bool mitk::MouseReleaseEvent::IsSuperClassOf(InteractionEvent::Pointer baseClass)
{
  return (dynamic_cast<MouseReleaseEvent*>(baseClass.GetPointer()) != NULL) ;
}