<commit_before>#include "mitkHierarchicalInteractor.h"
#include "mitkAction.h"
#include "mitkInteractionConst.h"
#include <mitkProperties.h>

mitk::HierarchicalInteractor::HierarchicalInteractor(const char * type, DataTreeNode* dataTreeNode)
:Interactor(type,dataTreeNode)
{
  m_SelectedInteractors.clear();
  m_AllInteractors.clear();
}

bool mitk::HierarchicalInteractor::IsSubSelected() const 
{
  return (m_Mode==SMSUBSELECTED);
}

bool mitk::HierarchicalInteractor::HandleEvent(StateEvent const* stateEvent, int objectEventId, int groupEventId)
{
  bool ok = Interactor::HandleEvent( stateEvent, objectEventId, groupEventId );

  if ( IsSubSelected() ) {

    ok = TransmitEvent( stateEvent, objectEventId, groupEventId ) || ok ;
  }

  return ok;
}

bool mitk::HierarchicalInteractor::TransmitEvent( StateEvent const* stateEvent, int objectEventId, int groupEventId ) 
{
  InteractorListIter i = m_SelectedInteractors.begin();
  const InteractorListIter end = m_SelectedInteractors.end();
  bool ok = false;
  bool subSelected = false;

  while ( i != end )
  {
  
    ok = (*i)->HandleEvent( stateEvent, objectEventId, groupEventId ) || ok;
    subSelected = (*i)->IsSelected() || subSelected;
    i++;
  }

  if ( !subSelected ) 
  {
    StateEvent sd( EIDSUBDESELCT, stateEvent->GetEvent() );
    HandleEvent( &sd, objectEventId, groupEventId );
  }

  return ok;
}

bool mitk::HierarchicalInteractor::ExecuteAction(Action* action, mitk::StateEvent const* stateEvent, int objectEventId, int groupEventId) 
{
  switch (action->GetActionId())
  {
    case AcMODEDESELECT:
      {
        // ToDo
        // Operation op( OPSelect, ... )
        // m_DataTreeNode->GetData()->ExecuteOperation( &op );
        m_Mode = SMDESELECTED;
        m_SelectedInteractors.clear();
        return true;
      }
    case AcMODESELECT:
      { 
        // ToDo
        // Operation op( OPSelect, ... )
        // m_DataTreeNode->GetData()->ExecuteOperation( &op );
        m_Mode = SMSELECTED;
        m_SelectedInteractors.clear();
        return true;
      }
    case AcMODESUBSELECT:
      {
        m_Mode = SMSUBSELECTED;
        return true;
      }
    case AcCHECKONESUBINTERACTOR:
      {
        m_SelectedInteractors.clear();
        InteractorListIter i = m_AllInteractors.begin();
        InteractorListIter bestInteractor = m_AllInteractors.end();
        const InteractorListIter end = m_AllInteractors.end();
        float jurisdiction = 0.0f;

        while ( i != end )
        {
          float currentJurisdiction = CalculateJurisdiction( stateEvent );
    
          if ( jurisdiction > currentJurisdiction )          
          {
            jurisdiction = currentJurisdiction;
            bestInteractor = i;
          }

          i++;
        }
        
        FloatProperty* thresholdProperty = dynamic_cast<FloatProperty*>(action->GetProperty("threshold"));
        float threshold;

        if ( thresholdProperty )
          threshold = thresholdProperty->GetValue();
        else 
          threshold = 0.5;         

        if ( jurisdiction >= threshold )  
        {          
          m_SelectedInteractors.push_back( *i );
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StYES, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );
        }
        else 
        {
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StNO, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );        
        }      
          
        return true;
      }
    case AcCHECKSUBINTERACTORS:
      {

        FloatProperty* thresholdProperty = dynamic_cast<FloatProperty*>(action->GetProperty("threshold"));
        float threshold;

        if ( thresholdProperty )
          threshold = thresholdProperty->GetValue();
        else 
          threshold = 0.5;         

        m_SelectedInteractors.clear();
        InteractorListIter i = m_AllInteractors.begin();
        InteractorListIter bestInteractor = m_AllInteractors.end();
        const InteractorListIter end = m_AllInteractors.end();
        float jurisdiction = 0.0f;

        while ( i != end )
        {
          float jurisdiction = CalculateJurisdiction( stateEvent );
    
          if ( jurisdiction > threshold )          
            m_SelectedInteractors.push_back( *i );

          i++;
        }
        
        if ( !m_SelectedInteractors.empty() )
        {          
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StYES, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );
        }
        else 
        {
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StNO, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );        
        }      
          
        return true;
      }
    default:
      return Interactor::ExecuteAction( action, stateEvent, objectEventId, groupEventId);
  }   
}

bool mitk::HierarchicalInteractor::AddInteractor(mitk::Interactor::Pointer interactor)
{
  if (interactor.IsNotNull())
  {
    m_AllInteractors.push_back(interactor);
    return true;
  }
  else
    return false;
}<commit_msg>Modechanges are done through operations (undo-supporting)<commit_after>#include "mitkHierarchicalInteractor.h"
#include "mitkAction.h"
#include "mitkInteractionConst.h"
#include <mitkProperties.h>

mitk::HierarchicalInteractor::HierarchicalInteractor(const char * type, DataTreeNode* dataTreeNode)
:Interactor(type,dataTreeNode)
{
  m_SelectedInteractors.clear();
  m_AllInteractors.clear();
}

bool mitk::HierarchicalInteractor::IsSubSelected() const 
{
  return (m_Mode==SMSUBSELECTED);
}

bool mitk::HierarchicalInteractor::HandleEvent(StateEvent const* stateEvent, int objectEventId, int groupEventId)
{
  bool ok = Interactor::HandleEvent( stateEvent, objectEventId, groupEventId );

  if ( IsSubSelected() ) 
  {
    ok = TransmitEvent( stateEvent, objectEventId, groupEventId ) || ok ;
  }

  return ok;
}

bool mitk::HierarchicalInteractor::TransmitEvent( StateEvent const* stateEvent, int objectEventId, int groupEventId ) 
{
  InteractorListIter i = m_SelectedInteractors.begin();
  const InteractorListIter end = m_SelectedInteractors.end();
  bool ok = false;
  bool subSelected = false;

  while ( i != end )
  {
  
    ok = (*i)->HandleEvent( stateEvent, objectEventId, groupEventId ) || ok;
    subSelected = (*i)->IsSelected() || subSelected;
    i++;
  }

  if ( !subSelected ) 
  {
    StateEvent sd( EIDSUBDESELCT, stateEvent->GetEvent() );
    HandleEvent( &sd, objectEventId, groupEventId );
  }

  return ok;
}

bool mitk::HierarchicalInteractor::ExecuteAction(Action* action, mitk::StateEvent const* stateEvent, int objectEventId, int groupEventId) 
{
  switch (action->GetActionId())
  {
    case AcMODEDESELECT:
      {
        //declare operations for modechange:
        this->CreateModeOperation(SMDESELECTED, objectEventId, groupEventId);
        m_SelectedInteractors.clear();
        return true;
      }
    case AcMODESELECT:
      { 
        //declare operations for modechange:
        this->CreateModeOperation(SMSELECTED, objectEventId, groupEventId);
        m_SelectedInteractors.clear();
        return true;
      }
    case AcMODESUBSELECT:
      {
        //declare operations for modechange:
        this->CreateModeOperation(SMSUBSELECTED, objectEventId, groupEventId);
        return true;
      }
    case AcCHECKONESUBINTERACTOR:
      {
        m_SelectedInteractors.clear();
        InteractorListIter i = m_AllInteractors.begin();
        InteractorListIter bestInteractor = m_AllInteractors.end();
        const InteractorListIter end = m_AllInteractors.end();
        float jurisdiction = 0.0f;

        while ( i != end )
        {
          float currentJurisdiction = CalculateJurisdiction( stateEvent );
    
          if ( jurisdiction > currentJurisdiction )          
          {
            jurisdiction = currentJurisdiction;
            bestInteractor = i;
          }

          i++;
        }
        
        FloatProperty* thresholdProperty = dynamic_cast<FloatProperty*>(action->GetProperty("threshold"));
        float threshold;

        if ( thresholdProperty )
          threshold = thresholdProperty->GetValue();
        else 
          threshold = 0.5;         

        if ( jurisdiction >= threshold )  
        {          
          m_SelectedInteractors.push_back( *i );
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StYES, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );
        }
        else 
        {
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StNO, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );        
        }      
          
        return true;
      }
    case AcCHECKSUBINTERACTORS:
      {

        FloatProperty* thresholdProperty = dynamic_cast<FloatProperty*>(action->GetProperty("threshold"));
        float threshold;

        if ( thresholdProperty )
          threshold = thresholdProperty->GetValue();
        else 
          threshold = 0.5;         

        m_SelectedInteractors.clear();
        InteractorListIter i = m_AllInteractors.begin();
        InteractorListIter bestInteractor = m_AllInteractors.end();
        const InteractorListIter end = m_AllInteractors.end();
        float jurisdiction = 0.0f;

        while ( i != end )
        {
          float jurisdiction = CalculateJurisdiction( stateEvent );
    
          if ( jurisdiction > threshold )          
            m_SelectedInteractors.push_back( *i );

          i++;
        }
        
        if ( !m_SelectedInteractors.empty() )
        {          
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StYES, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );
        }
        else 
        {
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(StNO, stateEvent->GetEvent());
          this->HandleEvent( newStateEvent, objectEventId, groupEventId );        
        }      
          
        return true;
      }
    default:
      return Superclass::ExecuteAction( action, stateEvent, objectEventId, groupEventId);
  }   
}

bool mitk::HierarchicalInteractor::AddInteractor(mitk::Interactor::Pointer interactor)
{
  if (interactor.IsNotNull())
  {
    m_AllInteractors.push_back(interactor);
    return true;
  }
  else
    return false;
}
{'fraction_non_alphanumeric': 0.10169651272384543, 'fraction_numerical': 0.0015080113100848257, 'mean_word_length': 2.5823767724510467, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6979476', 'n_tokens_mistral': 3112, 'n_tokens_neox': 2989, 'n_words': 582}