Medical Imaging Interaction Toolkit  2018.4.99-1640525a
Medical Imaging Interaction Toolkit
mitkStateMachineTransition.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkEventFactory.h"
16 #include "mitkStateMachineAction.h"
17 #include "mitkStateMachineState.h"
18 
20  const std::string &eventClass,
21  const std::string &eventVariant)
22  : m_EventClass(eventClass), m_EventVariant(eventVariant), m_NextStateName(nextStateName)
23 {
25  propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), eventClass.c_str());
26  m_TransitionEvent = EventFactory::CreateEvent(propertyList);
27 }
28 
30 {
31  // Create event based on incoming event type,
32  // then try to cast it to the type of event that this transition holds,
33  // if this is possible, the variant is checked
34 
35  // check for nullptr since a corrupted state machine might cause an empty event
36  if (m_TransitionEvent.IsNull())
37  {
38  return false;
39  }
41  propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(),
42  transition.m_EventClass.c_str());
44  if (tmpEvent.IsNull())
45  {
46  return false;
47  }
48 
49  if (m_TransitionEvent->IsSuperClassOf(tmpEvent.GetPointer()))
50  {
51  return (this->m_EventVariant == transition.m_EventVariant);
52  }
53  else
54  {
55  // if event variants match, but super class condition is violated
56  // this means that the configuration file, implements a class that does not
57  // support the type in the state machine.
58  if (this->m_EventVariant == transition.m_EventVariant)
59  {
60  MITK_WARN << "Event type in Statemachine " << m_EventClass << " is not compatible to configuration class "
61  << transition.m_EventClass;
62  }
63  return false;
64  }
65 }
66 
68 {
69  // needed for correct reference counting of mitkState//, for real???
70  m_NextState = nullptr;
71 
72  m_Actions.clear();
73  m_Conditions.clear();
74 }
75 
76 void mitk::StateMachineTransition::AddAction(const StateMachineAction::Pointer &action)
77 {
78  m_Actions.push_back(action);
79 }
80 
81 void mitk::StateMachineTransition::AddCondition(const StateMachineCondition &condition)
82 {
83  m_Conditions.push_back(condition);
84 }
85 
87 {
88  return m_NextState;
89 }
90 
92 {
93  return m_NextStateName;
94 }
95 
96 std::vector<mitk::StateMachineAction::Pointer> mitk::StateMachineTransition::GetActions() const
97 {
98  return m_Actions;
99 }
100 
102 {
103  return m_Conditions;
104 }
105 
107 {
108  m_NextState = nextState;
109 }
static Pointer New()
SpStateMachineState GetNextState() const
static const std::string xmlParameterEventClass()
static InteractionEvent::Pointer CreateEvent(PropertyList::Pointer eventDescription)
const ConditionVectorType & GetConditions() const
StateMachineTransition(const std::string &nextStateName, const std::string &eventClass, const std::string &eventVariant)
ActionVectorType GetActions() const
Get an iterator on the first action in list.
#define MITK_WARN
Definition: mitkLogMacros.h:19
Connects two states, and holds references to corresponding actions and conditions.
bool operator==(const StateMachineTransition &transition) const
void SetNextState(const SpStateMachineState &nextState)
Set the next state of this object.
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
std::vector< StateMachineCondition > ConditionVectorType