private void UpdateState(State state, Transition transition)
{
// change the state.
m_lastState = m_currentStateName;
m_currentStateName = state;
// update the status information to reflect the new state.
if (m_currentStateName != null)
{
m_currentState.DisplayName = m_currentStateName.DisplayName;
}
// update the status information to reflect an invalid state.
else
{
m_currentState.DisplayName = String.Empty;
// override the status code all properties.
OverrideValueStatus(StatusCodes.UncertainLastUsableValue);
}
// save the transition information.
if (transition != null)
{
//m_lastTransition.BrowseName.Value = transition.BrowseName;
//m_lastTransition.DisplayName.Value = transition.DisplayName;
}
else
{
//m_lastTransition.BrowseName.Value = QualifiedName.Null;
//m_lastTransitionDisplayName.Value = String.Empty;
}
//m_timeOfLastTransition.Value = DateTime.UtcNow;
// get the list of available causes.
Dictionary<QualifiedName,MethodSource> methods = new Dictionary<QualifiedName,MethodSource>();
foreach (Transition current in m_transitions)
{
if (!Object.ReferenceEquals(current.FromState, m_currentStateName))
{
continue;
}
foreach (MethodSource cause in current.Causes)
{
methods[cause.BrowseName] = cause;
}
}
// set executable bit for the available causes
foreach (MethodSource cause in m_causes.Values)
{
cause.Executable = methods.ContainsKey(cause.BrowseName);
cause.UserExecutable = cause.Executable;
}
// update submachines.
foreach (StateMachine submachine in m_substateMachines)
{
QualifiedName stateName = (m_currentStateName != null)?m_currentStateName.BrowseName:null;
QualifiedName transitionName = (transition != null)?transition.BrowseName:null;
submachine.ParentMachineStateChanged(stateName, transitionName);
}
// update collapsed substate after updating statemachines.
UpdateCollapsedSubstate();
}
#endregion