16 #include <vtkObjectFactory.h> 17 #include <vtkXMLDataElement.h> 30 const std::string
NAME =
"name";
31 const std::string
CONFIG =
"statemachine";
32 const std::string
STATE =
"state";
61 if (module ==
nullptr)
68 mitkThrow() << (
"Resource not valid. State machine pattern not found:" + fileName);
71 this->SetStream(&stream);
72 m_Filename = fileName;
73 return this->Parse() && !m_errors;
84 void mitk::StateMachineContainer::ConnectStates()
86 for (
auto it = m_States.begin(); it != m_States.end(); ++it)
88 if ((*it)->ConnectTransitions(&m_States) ==
false)
95 std::string name(elementName);
101 else if (name ==
STATE)
103 std::string stateName = ReadXMLStringAttribut(
NAME, atts);
104 std::transform(stateName.begin(), stateName.end(), stateName.begin(), ::toupper);
105 std::string stateMode = ReadXMLStringAttribut(
STATEMODE, atts);
106 std::transform(stateMode.begin(), stateMode.end(), stateMode.begin(), ::toupper);
107 bool isStartState = ReadXMLBooleanAttribut(
STARTSTATE, atts);
111 m_StartStateFound =
true;
115 if (stateMode ==
"" || stateMode ==
"REGULAR")
117 stateMode =
"REGULAR";
119 else if (stateMode !=
"GRAB_INPUT" && stateMode !=
"PREFER_INPUT")
121 MITK_WARN <<
"Invalid State Modus " << stateMode <<
". Mode assumed to be REGULAR";
122 stateMode =
"REGULAR";
127 m_StartState = m_CurrState;
131 std::string eventClass = ReadXMLStringAttribut(
EVENTCLASS, atts);
132 std::string eventVariant = ReadXMLStringAttribut(
EVENTVARIANT, atts);
133 std::string target = ReadXMLStringAttribut(
TARGET, atts);
134 std::transform(target.begin(), target.end(), target.begin(), ::toupper);
140 m_CurrState->AddTransition(transition);
144 MITK_WARN <<
"Malformed Statemachine Pattern. Transition has no origin. \n Will be ignored.";
145 MITK_WARN <<
"Malformed Transition details: target=" << target <<
", event class:" << eventClass
146 <<
", event variant:" << eventVariant;
148 m_CurrTransition = transition;
153 std::string actionName = ReadXMLStringAttribut(
NAME, atts);
155 if (m_CurrTransition)
156 m_CurrTransition->AddAction(action);
158 MITK_WARN <<
"Malformed state machine Pattern. Action without transition. \n Will be ignored.";
163 if (!m_CurrTransition)
164 MITK_WARN <<
"Malformed state machine Pattern. Condition without transition. \n Will be ignored.";
166 std::string conditionName = ReadXMLStringAttribut(
NAME, atts);
167 std::string inverted = ReadXMLStringAttribut(
INVERTED, atts);
168 if (inverted ==
"" || inverted ==
"false")
181 std::string name(elementName);
185 if (m_StartState.IsNull())
187 MITK_ERROR <<
"State machine pattern has no start state and cannot be used: " << m_Filename;
193 m_CurrTransition =
nullptr;
203 else if (name ==
STATE)
205 m_States.push_back(m_CurrState);
206 m_CurrState =
nullptr;
210 std::string mitk::StateMachineContainer::ReadXMLStringAttribut(std::string name,
const char **atts)
214 const char **attsIter = atts;
218 if (name == *attsIter)
228 return std::string();
231 bool mitk::StateMachineContainer::ReadXMLBooleanAttribut(std::string name,
const char **atts)
233 std::string s = ReadXMLStringAttribut(name, atts);
234 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)
void StartElement(const char *elementName, const char **atts) override
Derived from XMLReader.
Module * GetModule() const
const std::string INVERTED
ModuleResource GetResource(const std::string &path) const
vtkStandardNewMacro(AnatomicalStructureColorPresets)
StateMachineState::Pointer GetStartState() const
Returns the StartState of the StateMachine.
const std::string STATEMODE
const std::string EVENTVARIANT
static Pointer New(const std::string &_arga, const std::string &_argb, const std::string &_argc)
~StateMachineContainer() override
const std::string CONDITION
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