20 #include <vtkObjectFactory.h>
21 #include <vtkXMLDataElement.h>
34 const std::string
NAME =
"name";
35 const std::string
CONFIG =
"statemachine";
36 const std::string
STATE =
"state";
72 mitkThrow() << (
"Resource not valid. State machine pattern not found:" + fileName);
75 this->SetStream(&stream);
76 m_Filename = fileName;
77 return this->Parse() && !m_errors;
88 void mitk::StateMachineContainer::ConnectStates()
90 for (StateMachineCollectionType::iterator it = m_States.begin(); it != m_States.end(); ++it)
92 if ((*it)->ConnectTransitions(&m_States) ==
false)
99 std::string name(elementName);
105 else if (name ==
STATE)
107 std::string stateName = ReadXMLStringAttribut(
NAME, atts);
108 std::transform(stateName.begin(), stateName.end(), stateName.begin(), ::toupper);
109 std::string stateMode = ReadXMLStringAttribut(
STATEMODE, atts);
110 std::transform(stateMode.begin(), stateMode.end(), stateMode.begin(), ::toupper);
111 bool isStartState = ReadXMLBooleanAttribut(
STARTSTATE, atts);
115 m_StartStateFound =
true;
119 if (stateMode ==
"" || stateMode ==
"REGULAR")
121 stateMode =
"REGULAR";
123 else if (stateMode !=
"GRAB_INPUT" && stateMode !=
"PREFER_INPUT")
125 MITK_WARN <<
"Invalid State Modus " << stateMode <<
". Mode assumed to be REGULAR";
126 stateMode =
"REGULAR";
131 m_StartState = m_CurrState;
135 std::string eventClass = ReadXMLStringAttribut(
EVENTCLASS, atts);
136 std::string eventVariant = ReadXMLStringAttribut(
EVENTVARIANT, atts);
137 std::string target = ReadXMLStringAttribut(
TARGET, atts);
138 std::transform(target.begin(), target.end(), target.begin(), ::toupper);
144 m_CurrState->AddTransition(transition);
148 MITK_WARN <<
"Malformed Statemachine Pattern. Transition has no origin. \n Will be ignored.";
149 MITK_WARN <<
"Malformed Transition details: target=" << target <<
", event class:" << eventClass
150 <<
", event variant:" << eventVariant;
152 m_CurrTransition = transition;
157 std::string actionName = ReadXMLStringAttribut(
NAME, atts);
159 if (m_CurrTransition)
160 m_CurrTransition->AddAction(action);
162 MITK_WARN <<
"Malformed state machine Pattern. Action without transition. \n Will be ignored.";
167 if (!m_CurrTransition)
168 MITK_WARN <<
"Malformed state machine Pattern. Condition without transition. \n Will be ignored.";
170 std::string conditionName = ReadXMLStringAttribut(
NAME, atts);
171 std::string inverted = ReadXMLStringAttribut(
INVERTED, atts);
172 if (inverted ==
"" || inverted ==
"false")
185 std::string name(elementName);
189 if (m_StartState.IsNull())
191 MITK_ERROR <<
"State machine pattern has no start state and cannot be used: " << m_Filename;
197 m_CurrTransition = NULL;
207 else if (name ==
STATE)
209 m_States.push_back(m_CurrState);
214 std::string mitk::StateMachineContainer::ReadXMLStringAttribut(std::string name,
const char **atts)
218 const char **attsIter = atts;
222 if (name == *attsIter)
232 return std::string();
235 bool mitk::StateMachineContainer::ReadXMLBooleanAttribut(std::string name,
const char **atts)
237 std::string s = ReadXMLStringAttribut(name, atts);
238 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
bool LoadBehavior(const std::string &fileName, const us::Module *module)
Loads XML resource.
static Pointer New(const std::string &_arg)
const std::string STARTSTATE
const std::string NAME
This class builds up all the necessary structures for a statemachine. and stores one start-state for ...
DataCollection - Class to facilitate loading/accessing structured data.
static Pointer New(const std::string &_arga, const std::string &_argb)
StateMachineState::Pointer GetStartState() const
Returns the StartState of the StateMachine.
void StartElement(const char *elementName, const char **atts) override
Derived from XMLReader.
Module * GetModule() const
virtual ~StateMachineContainer()
const std::string INVERTED
vtkStandardNewMacro(AnatomicalStructureColorPresets)
const std::string STATEMODE
const std::string EVENTVARIANT
static Pointer New(const std::string &_arga, const std::string &_argb, const std::string &_argc)
const std::string CONDITION
ModuleResource GetResource(const std::string &path) const
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
const std::string EVENTCLASS
void EndElement(const char *elementName) override
Derived from XMLReader.
const std::string TRANSITION