Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
18 #include "mitkEventFactory.h"
20 #include "mitkStateMachineAction.h"
21 #include "mitkStateMachineState.h"
22 
24  const std::string &eventClass,
25  const std::string &eventVariant)
26  : m_EventClass(eventClass), m_EventVariant(eventVariant), m_NextStateName(nextStateName)
27 {
29  propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(), eventClass.c_str());
30  m_TransitionEvent = EventFactory::CreateEvent(propertyList);
31 }
32 
34 {
35  // Create event based on incoming event type,
36  // then try to cast it to the type of event that this transition holds,
37  // if this is possible, the variant is checked
38 
39  // check for NULL since a corrupted state machine might cause an empty event
40  if (m_TransitionEvent.IsNull())
41  {
42  return false;
43  }
45  propertyList->SetStringProperty(InteractionEventConst::xmlParameterEventClass().c_str(),
46  transition.m_EventClass.c_str());
48  if (tmpEvent.IsNull())
49  {
50  return false;
51  }
52 
53  if (m_TransitionEvent->IsSuperClassOf(tmpEvent.GetPointer()))
54  {
55  return (this->m_EventVariant == transition.m_EventVariant);
56  }
57  else
58  {
59  // if event variants match, but super class condition is violated
60  // this means that the configuration file, implements a class that does not
61  // support the type in the state machine.
62  if (this->m_EventVariant == transition.m_EventVariant)
63  {
64  MITK_WARN << "Event type in Statemachine " << m_EventClass << " is not compatible to configuration class "
65  << transition.m_EventClass;
66  }
67  return false;
68  }
69 }
70 
72 {
73  // needed for correct reference counting of mitkState//, for real???
74  m_NextState = NULL;
75 
76  m_Actions.clear();
77  m_Conditions.clear();
78 }
79 
80 void mitk::StateMachineTransition::AddAction(const StateMachineAction::Pointer &action)
81 {
82  m_Actions.push_back(action);
83 }
84 
85 void mitk::StateMachineTransition::AddCondition(const StateMachineCondition &condition)
86 {
87  m_Conditions.push_back(condition);
88 }
89 
91 {
92  return m_NextState;
93 }
94 
96 {
97  return m_NextStateName;
98 }
99 
100 std::vector<mitk::StateMachineAction::Pointer> mitk::StateMachineTransition::GetActions() const
101 {
102  return m_Actions;
103 }
104 
106 {
107  return m_Conditions;
108 }
109 
111 {
112  m_NextState = nextState;
113 }
static Pointer New()
SpStateMachineState GetNextState() const
ActionVectorType GetActions() const
Get an iterator on the first action in list.
static const std::string xmlParameterEventClass()
static InteractionEvent::Pointer CreateEvent(PropertyList::Pointer eventDescription)
StateMachineTransition(const std::string &nextStateName, const std::string &eventClass, const std::string &eventVariant)
#define MITK_WARN
Definition: mitkLogMacros.h:23
Connects two states, and holds references to corresponding actions and conditions.
const ConditionVectorType & GetConditions() const
bool operator==(const StateMachineTransition &transition) const
void SetNextState(const SpStateMachineState &nextState)
Set the next state of this object.
std::vector< StateMachineCondition > ConditionVectorType