Exemplo n.º 1
0
void  mitk::EventMapper::StartElement (const char *elementName, const char **atts)
{

  if ( elementName == EVENT )
  {

    // EventDescription(int type, int button, int buttonState,int key, std::string name, int id)
    EventDescription eventDescr( convertConstString2ConstInt( ReadXMLStringAttribut( TYPE, atts )),
      convertConstString2ConstInt( ReadXMLStringAttribut( BUTTON, atts )),
      ReadXMLIntegerAttribut( BUTTONSTATE, atts ),
      convertConstString2ConstInt( ReadXMLStringAttribut( KEY, atts )),
      ReadXMLStringAttribut( NAME, atts ),
      ReadXMLIntegerAttribut( ID, atts ));

    //check for a double entry unless it is an event for internal usage
    if (eventDescr.GetType()!= mitk::Type_User)
    {
      for (EventDescriptionVecIter iter = m_EventDescriptions.begin(); iter!=m_EventDescriptions.end(); iter++)
      {
        if (*iter == eventDescr)
        {
          MITK_DEBUG << "Event description " << eventDescr.GetName() << " already present! Skipping event description";
          return;
        }
      }
    }

    m_EventDescriptions.push_back(eventDescr);
  }
  else if ( elementName == EVENTS )
    m_StyleName = ReadXMLStringAttribut( STYLE, atts );

}
Exemplo n.º 2
0
void mitk::StateMachineFactory::StartElement(const char* elementName, const char **atts)
{
  //skip the state machine pattern because the name was not unique!
  if (m_SkipStateMachine)
    return;

  std::string name(elementName);

  if (name == CONFIG)
  {
    std::string tempStateMachineName = ReadXMLStringAttribut(NAME, atts);
    if (m_AllStateMachineMap.find(tempStateMachineName) != m_AllStateMachineMap.end())
    {
      //warning: Statemachine tempStateMachineName already exists!
      MITK_FATAL<< "State machine pattern " << tempStateMachineName << " already exists! Skipping state machine pattern";
      m_SkipStateMachine = true;
    }
    else //tempStateMachineName is unique, so add it
    {
      m_AktStateMachineName = tempStateMachineName;
      m_AllStateMachineMap[ m_AktStateMachineName ] = new StateMachineMapType;
    }
  }

  else if ( name == STATE )
  {
    std::string stateMachinName = ReadXMLStringAttribut( NAME, atts );
    int id = ReadXMLIntegerAttribut( ID, atts );

    //create a new instance
    m_AktState = mitk::State::New(stateMachinName , id);

    // store all states to be able to access a specific state (for persistence)
    StateMachineMapType* stateMachine = m_AllStateMachineMap[ m_AktStateMachineName ];
    (*stateMachine)[id] = m_AktState;

    std::pair<mitk::State::StateMapIter,bool> ok = m_AllStatesOfOneStateMachine.insert(mitk::State::StateMap::value_type(id , m_AktState));

    if ( ok.second == false )
    {
      MITK_INFO<<std::endl;
      MITK_INFO<<"Warning from StateMachineFactory: STATE_ID was not unique in pattern "<< m_AktStateMachineName<<"!"<<std::endl;
      return; //STATE_ID was not unique or something else didn't work in insert! EXITS the process
    }
    if ( ReadXMLBooleanAttribut( START_STATE, atts ) )
      m_StartStates.insert(StartStateMap::value_type(m_AktStateMachineName, m_AktState));
  }

  else if ( name == TRANSITION )
  {
    std::string transitionName = ReadXMLStringAttribut( NAME, atts );
    int nextStateId = ReadXMLIntegerAttribut( NEXT_STATE_ID, atts );
    int eventId = ReadXMLIntegerAttribut( EVENT_ID, atts );
    if ( m_AktState )
    {
      mitk::Transition* transition = new Transition(transitionName, nextStateId, eventId);
      if (!m_AktState->AddTransition( transition ))
      {
        delete transition;
        m_AktTransition = const_cast<Transition*>(m_AktState->GetTransition(eventId));
      }
      else
      {
        m_AktTransition = transition;
      }
    }
  }

  else if ( name == ACTION && m_AktTransition)
  {
    int actionId = ReadXMLIntegerAttribut( ID, atts );
    m_AktAction = Action::New( actionId );
    m_AktTransition->AddAction( m_AktAction );
  }

  else if ( name == BOOL_PARAMETER )
  {
    if ( !m_AktAction )
    return;

    bool value = ReadXMLBooleanAttribut( VALUE, atts );
    std::string name = ReadXMLStringAttribut( NAME, atts );
    m_AktAction->AddProperty( name.c_str(), BoolProperty::New( value ) );
  }

  else if ( name == INT_PARAMETER )
  {
    if ( !m_AktAction )
    return;

    int value = ReadXMLIntegerAttribut( VALUE, atts );
    std::string name = ReadXMLStringAttribut( NAME, atts );
    m_AktAction->AddProperty( name.c_str(), IntProperty::New( value ) );
  }

  else if ( name == FLOAT_PARAMETER )
  {
    if ( !m_AktAction )
    return;

    float value = ReadXMLIntegerAttribut( VALUE, atts );
    std::string name = ReadXMLStringAttribut( NAME, atts );
    m_AktAction->AddProperty( name.c_str(), FloatProperty::New( value ) );
  }

  else if ( name == DOUBLE_PARAMETER )
  {
    if ( !m_AktAction )
    return;

    double value = ReadXMLDoubleAttribut( VALUE, atts );
    std::string name = ReadXMLStringAttribut( NAME, atts );
    m_AktAction->AddProperty( name.c_str(), DoubleProperty::New( value ) );
  }

  else if ( name == STRING_PARAMETER )
  {
    if ( !m_AktAction )
    return;

    std::string value = ReadXMLStringAttribut( VALUE, atts );
    std::string name = ReadXMLStringAttribut( NAME, atts );
    m_AktAction->AddProperty( name.c_str(), StringProperty::New( value ) );
  }
}