protected void AnalyseAction(IStateGlyph state, string actions)
 {
     if (IsNotEmptyString (actions))
     {
         string[] names = ParseNames (actions);
     }
 }
예제 #2
0
 protected void AnalyseAction(IStateGlyph state, string actions)
 {
     if (IsNotEmptyString(actions))
     {
         string[] names = ParseNames(actions);
     }
 }
예제 #3
0
        public bool IsProperInnerTransition()
        {
            bool        sameState = true;
            IStateGlyph lastState = null;

            foreach (IGlyph contact in ContactPoints)
            {
                IStateGlyph state = contact.Parent as IStateGlyph;
                if (lastState == null)
                {
                    lastState = state;
                }
                if (lastState != state)
                {
                    sameState = false;
                    break;
                }
                lastState = state;
            }
            if (sameState)
            {
                if (IsInnerTransition)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #4
0
 void DoNewTransitionList(IStateGlyph state, ArrayList transitionList)
 {
     if (NewTransitionList != null)
     {
         NewTransitionList(this, new TransitionListEventArgs(state, transitionList));
     }
 }
예제 #5
0
        protected string StateNameFrom(IStateGlyph state)
        {
            string name = state.FullyQualifiedStateName;

            name = name.Replace(".", "_");
            return(name);
        }
예제 #6
0
        protected ArrayList GetTransitionList(IStateGlyph state)
        {
            ArrayList transitionList = new ArrayList();

            GetTransitionList(transitionList, state);
            return(transitionList);
        }
예제 #7
0
 public TransitionInfo(ITransitionGlyph trans, string fromStateName, string toStateName, IStateGlyph toStateGlyph)
 {
     Transition    = trans;
     FromStateName = fromStateName;
     ToStateName   = toStateName;
     ToStateGlyph  = toStateGlyph;
 }
예제 #8
0
            public void Visit(ITransitionGlyph transition)
            {
                WriteDefaults(transition);
                _Writer.WriteElementString("EventSignal", transition.EventSignal);
                _Writer.WriteElementString("EventSource", transition.EventSource);
                _Writer.WriteElementString("GuardCondition", transition.GuardCondition);
                _Writer.WriteElementString("Action", transition.Action);
                _Writer.WriteElementString("EvaluationOrderPriority", transition.EvaluationOrderPriority.ToString());
                _Writer.WriteElementString("EventType", transition.EventType);
                _Writer.WriteElementString("IsInnerTransition", transition.IsInnerTransition.ToString().ToLower());
                _Writer.WriteElementString("TimeOutExpression", transition.TimeOutExpression);
                _Writer.WriteElementString("TransitionType", transition.TransitionType.ToString());

                foreach (ITransitionContactPointGlyph contactPoint in transition.ContactPoints)
                {
                    if (contactPoint.Parent != null)
                    {
                        IStateGlyph state = contactPoint.Parent as IStateGlyph;
                        System.Diagnostics.Debug.Assert(state != null);
                        _Writer.WriteStartElement("State");
                        try
                        {
                            _Writer.WriteElementString("Id", state.Id);
                            _Writer.WriteElementString("Name", state.Name);
                        }
                        finally
                        {
                            _Writer.WriteEndElement();
                        }
                    }
                }
            }
예제 #9
0
        private string GetStateName(IStateGlyph stateGlyph)
        {
            string sname = "S_" + stateGlyph.FullyQualifiedStateName;

            sname = sname.Replace(".", "_");
            return(sname);
        }
예제 #10
0
        protected override bool AcceptParentInFullyQualifiedName(IGlyph glyph)
        {
            System.Diagnostics.Debug.Assert(glyph != null);
            IStateGlyph state = glyph as IStateGlyph;

            System.Diagnostics.Debug.Assert(state != null);
            return(!state.IsOverriding);
        }
예제 #11
0
        protected string OuterMostStateName()
        {
            IStateGlyph state = OuterMostState();

            if (state != null)
            {
                return(StateNameFrom(state));
            }
            return("NO_STATE_AT_OUTER_LEVEL_MARKED_AS_START_STATE");
        }
예제 #12
0
        protected void UpdateAllParentsDeepHistory()
        {
            IStateGlyph state = _CurrentState;

            while (state != null)
            {
                _DeepHistory [state] = _CurrentState;
                state = state.Parent as IStateGlyph;
            }
        }
예제 #13
0
 protected bool StateHasAfterTransitions(IStateGlyph state)
 {
     foreach (TransitionInfo transInfo in GetTransitionList(state))
     {
         if (IsNotEmptyString(transInfo.Transition.TimeOutExpression))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #14
0
 protected bool StateOrParentHasDeepHistoryTransition(IStateGlyph state)
 {
     while (state != null)
     {
         if (_StatesWithHistoryTransitions.Contains(state))
         {
             return(true);
         }
         state = state.Parent as IStateGlyph;
     }
     return(false);
 }
예제 #15
0
 protected bool StateHasAsAnyParent(IStateGlyph state, IStateGlyph possibleParentState)
 {
     while (state != null)
     {
         if (state.Parent == possibleParentState)
         {
             return(true);
         }
         state = state.Parent as IStateGlyph;
     }
     return(false);
 }
 protected ArrayList GetStateAfterTransitions(IStateGlyph state)
 {
     ArrayList list = new ArrayList ();
     foreach (TransitionInfo transInfo in GetTransitionList (state))
     {
         if (IsNotEmptyString (transInfo.Transition.TimeOutExpression))
         {
             list.Add (transInfo.Transition);
         }
     }
     return list;
 }
예제 #17
0
        protected void RefreshCurrentStateView(string qhsmName, string currentTransitionName)
        {
            ClearCurrentStateView();

            foreach (IGlyph glyph in _View.StateControl.Model.Glyphs)
            {
                if (currentTransitionName == null)
                {
                    IStateGlyph stateGlyph = glyph as IStateGlyph;
                    if (stateGlyph != null)
                    {
                        if (qhsmName == GetStateName(stateGlyph))
                        {
                            stateGlyph.Selected = true;
                        }
                    }
                }
                else
                {
                    ITransitionGlyph trans = glyph as ITransitionGlyph;
                    if (trans != null)
                    {
                        string sx = trans.FullyQualifiedStateName;
                        foreach (IGlyph owned in trans.OwnedItems)
                        {
                            IStateGlyph sg = owned.Parent as IStateGlyph;
                            if (sg != null)
                            {
                                if (GetStateName(sg) == qhsmName)
                                {
                                    string transName = trans.CompleteEventText(true, true);
                                    if (trans.Action != "")
                                    {
                                        transName = transName + "/" + trans.Action;
                                    }
                                    if (transName == currentTransitionName)
                                    {
                                        trans.Selected = true;
                                        _View.StateControl.RefreshView();
                                        if (_TransitionDelay > 0)
                                        {
                                            System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(_TransitionDelay));
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            _View.StateControl.RefreshView();
        }
예제 #18
0
        protected ArrayList GetStateAfterTransitions(IStateGlyph state)
        {
            ArrayList list = new ArrayList();

            foreach (TransitionInfo transInfo in GetTransitionList(state))
            {
                if (IsNotEmptyString(transInfo.Transition.TimeOutExpression))
                {
                    list.Add(transInfo.Transition);
                }
            }
            return(list);
        }
예제 #19
0
        public void Start()
        {
            Prepare();

            IStateGlyph state = OuterMostState();

            if (state == null)
            {
                throw new Exception("No parent start state found!");
            }
            CurrentState = state;
            DoRefresh();
        }
 protected ArrayList GetStateOrParentsThatHasDeepHistoryTransition(IStateGlyph state)
 {
     ArrayList list = new ArrayList ();
     while (state != null)
     {
         if (_StatesWithHistoryTransitions.Contains (state))
         {
             list.Add (state);
         }
         state = state.Parent as IStateGlyph;
     }
     return list;
 }
예제 #21
0
        public int Compare(object x, object y)
        {
            /// State ahead of Transition
            ///
            /// State sorted in Parent Depth order
            /// Same Depth - sort by name
            ///
            /// Transition sorted by event

            if (x == y)
            {
                return(0);
            }

            if (x is IStateGlyph && y is IStateGlyph)
            {
                IStateGlyph X = x as IStateGlyph;
                IStateGlyph Y = y as IStateGlyph;

                int overrideComp = X.IsOverriding.CompareTo(Y.IsOverriding);
                if (overrideComp == 0)
                {
                    string xname = X.FullyQualifiedStateName;
                    string yname = Y.FullyQualifiedStateName;
                    return(xname.CompareTo(yname));
                }
                else
                {
                    return(overrideComp);
                }
            }
            else if (x is ITransitionGlyph && y is ITransitionGlyph)
            {
                ITransitionGlyph X      = x as ITransitionGlyph;
                ITransitionGlyph Y      = y as ITransitionGlyph;
                string           xevent = X.Event != null ? X.Event : "";
                string           yevent = Y.Event != null ? Y.Event : "";
                return(xevent.CompareTo(yevent));
            }
            else
            {
                if (x is IStateGlyph)                 // states to front of list
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
        }
예제 #22
0
        protected ArrayList GetStateOrParentsThatHasDeepHistoryTransition(IStateGlyph state)
        {
            ArrayList list = new ArrayList();

            while (state != null)
            {
                if (_StatesWithHistoryTransitions.Contains(state))
                {
                    list.Add(state);
                }
                state = state.Parent as IStateGlyph;
            }
            return(list);
        }
예제 #23
0
        protected virtual void PrepareGlyphs()
        {
            _Glyphs = (ArrayList)_SourceGlyphs.Clone();
            _Glyphs.Sort(new ConvertToCodeGlyphSorter());

            _States      = new ArrayList();
            _Transitions = new ArrayList();
            _Ports       = new ArrayList();
            foreach (IGlyph glyph in _Glyphs)
            {
                IStateGlyph state = glyph as IStateGlyph;
                if (state != null)
                {
                    _States.Add(state);
                }

                ITransitionGlyph trans = glyph as ITransitionGlyph;
                if (trans != null)
                {
                    _Transitions.Add(trans);
                }

                IStateTransitionPortGlyph port = glyph as IStateTransitionPortGlyph;
                if (port != null)
                {
                    _Ports.Add(port);
                }
            }

            _StatesWithHistoryTransitions = new Hashtable();
            foreach (IStateGlyph state in _States)
            {
                foreach (TransitionInfo info in GetTransitionList(state))
                {
                    if (info.Transition.TransitionType == TransitionType.History)
                    {
                        throw new NotImplementedException("History not yet implemented");
                    }
                    if (info.Transition.TransitionType == TransitionType.DeepHistory)
                    {
                        IStateGlyph historyKeeper = info.ToStateGlyph;
                        if (!_StatesWithHistoryTransitions.Contains(historyKeeper))
                        {
                            _StatesWithHistoryTransitions.Add(historyKeeper, info);
                        }
                    }
                }
            }
        }
예제 #24
0
        void LoadStateGlyph(TextReader sr)
        {
            string id;
            int    X, Y, width, height;

            LoadBounds(sr, out id, out X, out Y, out width, out height);
            string parentId = NextLine(sr);

            if (parentId != "NOPARENT")
            {
                _ParentChildRel [id] = parentId;
            }
            IStateGlyph glyph = _Factory.CreateState(id, new Rectangle(X, Y, width, height));

            LoadGlyphCommon(sr, glyph);

            IStateGlyph state = glyph;

            state.Name = LoadText(sr, "NAME");
            string isStart = LoadText(sr, "ISSTARTSTATE");

            state.IsStartState = bool.Parse(isStart);
            string isFinal = LoadText(sr, "ISFINALSTATE", false.ToString());

            state.IsFinalState = bool.Parse(isFinal);
            state.EntryAction  = LoadText(sr, "ENTRY");
            state.ExitAction   = LoadText(sr, "EXIT");
            state.DoAction     = LoadText(sr, "DO");
            string isOverriding = LoadText(sr, "ISOVERRIDING");

            state.IsOverriding = bool.Parse(isOverriding);

            string cmds = LoadText(sr, "STATECOMMANDS", "");

            state.StateCommands.Clear();
            cmds = cmds.Trim();
            if (cmds != null && cmds.Trim() != "")
            {
                string[] commandsArray = cmds.Split(';');
                state.StateCommands.AddRange(commandsArray);
            }
            // kludge - when stringcollection displayed in propertygrid - cannot create new string instances - so adding 10 by default (beyond what is already there).
            state.StateCommands.AddRange(new string[] { "", "", "", "", "", "", "", "", "", "" });

            BlankLine(sr);              // blank line
            _GlyphLookup.Add(id, glyph);
            _Glyphs.Add(glyph);
        }
예제 #25
0
        protected void CreateNewTransitionList(IStateGlyph state)
        {
            ArrayList list = new ArrayList();

            while (state != null)
            {
                GetTransitionList(list, state);
                IGlyph parent = state.Parent;
                state = parent as IStateGlyph;
                if (parent != null)
                {
                    System.Diagnostics.Debug.Assert(state != null);
                }
            }
            _TransitionList = list;
            DoNewTransitionList(_CurrentState, list);
        }
예제 #26
0
        protected void AnalyseTransition(IStateGlyph state, ArrayList groupedTransitionList)
        {
            foreach (TransitionInfo transInfo in groupedTransitionList)
            {
                ITransitionGlyph trans = transInfo.Transition;

                if (HasGuardCondition (trans))
                {
                    AnalyseGuardAction (state, trans, trans.GuardCondition);
                }

                if (IsNotEmptyString (trans.Action))
                {
                    AnalyseAction (state, trans, trans.Action);
                }
            }
        }
예제 #27
0
        protected void AnalyseTransition(IStateGlyph state, ArrayList groupedTransitionList)
        {
            foreach (TransitionInfo transInfo in groupedTransitionList)
            {
                ITransitionGlyph trans = transInfo.Transition;

                if (HasGuardCondition(trans))
                {
                    AnalyseGuardAction(state, trans, trans.GuardCondition);
                }

                if (IsNotEmptyString(trans.Action))
                {
                    AnalyseAction(state, trans, trans.Action);
                }
            }
        }
예제 #28
0
        protected void GetTransitionList(ArrayList transitionList, IStateGlyph state)
        {
            // now find transitions
            foreach (IGlyph child in state.Children)
            {
                ITransitionContactPointGlyph transContactPoint = child as ITransitionContactPointGlyph;
                if (transContactPoint != null)
                {
                    ITransitionGlyph trans = transContactPoint.Owner as ITransitionGlyph;

                    if (transContactPoint.WhichEnd == TransitionContactEnd.From)
                    {
                        // this is a from transition

                        ITransitionContactPointGlyph transTo = null;
                        foreach (ITransitionContactPointGlyph contactPoint in trans.ContactPoints)
                        {
                            if (contactPoint.WhichEnd == TransitionContactEnd.To)
                            {
                                transTo = contactPoint;
                                break;
                            }
                        }
                        System.Diagnostics.Debug.Assert(transTo != null, "Transition To Contact Point not found");

                        IStateGlyph toStateGlyph = transTo.Parent as IStateGlyph;
                        string      toStateName  = "TRANSITION_TOSTATE_NOT_SET";
                        if (toStateGlyph != null)
                        {
                            if (IsNotEmptyString(toStateGlyph.Name))
                            {
                                toStateName = StateNameFrom(toStateGlyph);
                            }
                            else
                            {
                                toStateName = "TRANSITION_TOSTATE_SET_BUT_STATE_NOT_NAMED";
                            }
                        }

                        TransitionInfo info = new TransitionInfo(trans, StateNameFrom(state), toStateName, toStateGlyph);
                        transitionList.Add(info);
                    }
                }
            }
        }
예제 #29
0
        protected bool StepNextEvent()
        {
            if (_EventQueue.Count == 0)
            {
                DoNoEvents();
                return(false);
            }

            string eventName = _EventQueue.Dequeue() as string;

            foreach (TransitionInfo info in _TransitionList)
            {
                if (info.Transition.Event == eventName)
                {
                    DoTransitionEvent(eventName);
                    switch (info.Transition.TransitionType)
                    {
                    case TransitionType.History:
                    {
                        throw new NotSupportedException("History not supported");
                    } break;

                    case TransitionType.DeepHistory:
                    {
                        IStateGlyph toState = _DeepHistory [info.ToStateGlyph] as IStateGlyph;
                        if (toState == null)
                        {
                            toState = info.ToStateGlyph;
                        }
                        CurrentState = toState;
                    } break;

                    default:
                    {
                        CurrentState = info.ToStateGlyph;
                    } break;
                    }
                    return(true);
                }
            }

            DoDropEvent(eventName);

            return(false);
        }
예제 #30
0
        bool FindInnerStartState()
        {
            if (CurrentState == null)
            {
                return(false);
            }

            foreach (IGlyph glyph in CurrentState.Children)
            {
                IStateGlyph state = glyph as IStateGlyph;
                if (state != null && state.IsStartState)
                {
                    CurrentState = state;
                    return(true);
                }
            }

            return(false);
        }
예제 #31
0
        protected void DrawContactPoints(IGraphicsContext GC, bool isOk, bool usePrimary, Color primary, out Color fromColor, out Color toColor)
        {
            fromColor = primary;
            toColor   = primary;
            foreach (ITransitionContactPointGlyph contact in ContactPoints)
            {
                switch (contact.WhichEnd)
                {
                case TransitionContactEnd.From: GC.Thickness = 3; break;

                case TransitionContactEnd.To: GC.Thickness = 5; break;

                default: throw new NotSupportedException("Unknown TransitionContactEnd: " + contact.WhichEnd.ToString());
                }
                IStateGlyph state = contact.Parent as IStateGlyph;
                if (usePrimary == false && state != null)
                {
                    if (isOk)
                    {
                        switch (contact.WhichEnd)
                        {
                        case TransitionContactEnd.From: fromColor = state.StateColor; break;

                        case TransitionContactEnd.To: toColor = state.StateColor; break;

                        default: throw new NotSupportedException("Unknown TransitionContactEnd: " + contact.WhichEnd.ToString());
                        }
                    }
                    GC.Color = state.StateColor;
                }
                else
                {
                    GC.Color = primary;
                }
                if (usePrimary)
                {
                    fromColor = primary;
                    toColor   = primary;
                }
                contact.Draw(GC);
            }
        }
예제 #32
0
 public void Visit(IStateGlyph state)
 {
     WriteDefaults(state);
     _Writer.WriteElementString("IsStartState", state.IsStartState.ToString().ToLower());
     _Writer.WriteElementString("EntryAction", state.EntryAction);
     _Writer.WriteElementString("ExitAction", state.ExitAction);
     _Writer.WriteStartElement("StateCommands");
     try
     {
         foreach (string cmd in state.StateCommands)
         {
             if (cmd != null && cmd.Trim().Length > 0)
             {
                 _Writer.WriteElementString("Command", cmd);
             }
         }
     }
     finally
     {
         _Writer.WriteEndElement();
     }
 }
예제 #33
0
        void SaveStateGlyph(TextWriter sw, IStateGlyph glyph)
        {
            SaveBounds(sw, "STATE:", glyph);
            if (glyph.Parent != null)
            {
                sw.WriteLine(glyph.Parent.Id);
            }
            else
            {
                sw.WriteLine("NOPARENT");
            }

            SaveGlyphCommon(sw, glyph);

            IStateGlyph state = glyph;

            SaveText(sw, "NAME", state.Name);
            SaveText(sw, "ISSTARTSTATE", state.IsStartState.ToString());
            SaveText(sw, "ISFINALSTATE", state.IsFinalState.ToString());
            SaveText(sw, "ENTRY", state.EntryAction);
            SaveText(sw, "EXIT", state.ExitAction);
            SaveText(sw, "DO", state.DoAction);
            SaveText(sw, "ISOVERRIDING", state.IsOverriding.ToString());

            ArrayList commandList = new ArrayList();

            foreach (string commandName in state.StateCommands)
            {
                if (commandName != null && commandName.Trim() != "")
                {
                    commandList.Add(commandName);
                }
            }
            string[] commandsArray = (string[])commandList.ToArray(typeof(string));
            string   cmds          = string.Join(";", commandsArray);

            SaveTextIfNotDefault(sw, "STATECOMMANDS", cmds, "");
        }
예제 #34
0
 public void Visit(IStateGlyph state)
 {
     WriteDefaults (state);
     _Writer.WriteElementString ("IsStartState", state.IsStartState.ToString ());
     _Writer.WriteElementString ("EntryAction", state.EntryAction);
     _Writer.WriteElementString ("ExitAction", state.ExitAction);
     _Writer.WriteStartElement ("StateCommands");
     try
     {
         foreach (string cmd in state.StateCommands)
         {
             if (cmd != null && cmd.Trim ().Length > 0)
             {
                 _Writer.WriteElementString ("Command", cmd);
             }
         }
     }
     finally
     {
         _Writer.WriteEndElement ();
     }
 }
        public override void KeyUp(object sender, KeyEventArgs e)
        {
            if (_LastSelectedGlyph == null)
            {
                return;
            }

            if (_Model.IsStateGlyph(_LastSelectedGlyph))
            {
                if (IsControlKey(e, Keys.T))                  // Toggle Start State
                {
                    IStateGlyph stateGlyph = _LastSelectedGlyph as IStateGlyph;
                    stateGlyph.IsStartState = !stateGlyph.IsStartState;
                }
                if (IsControlKey(e, Keys.N))                  // name
                {
                    _LastSelectedGlyph.Name = InputDialog.Execute(_Context.ParentStateDiagramView, "State Property Input", "State Name", _LastSelectedGlyph.Name);
                }
                else if (IsControlKey(e, Keys.E))                  // entry action
                {
                    IStateGlyph stateGlyph = _LastSelectedGlyph as IStateGlyph;
                    stateGlyph.EntryAction = InputDialog.Execute(_Context.ParentStateDiagramView, "State Property Input", "State Entry Action", stateGlyph.EntryAction);
                }
                else if (IsControlKey(e, Keys.X))                  // exit action
                {
                    IStateGlyph stateGlyph = _LastSelectedGlyph as IStateGlyph;
                    stateGlyph.ExitAction = InputDialog.Execute(_Context.ParentStateDiagramView, "State Property Input", "State Exit Action", stateGlyph.ExitAction);
                }
                else if (IsControlKey(e, Keys.F))
                {
                    IStateGlyph stateGlyph = _LastSelectedGlyph as IStateGlyph;
                    stateGlyph.IsFinalState = !stateGlyph.IsFinalState;
                }
            }
            else if (_Model.IsTransitionGlyph(_LastSelectedGlyph))
            {
                if (IsControlKey(e, Keys.N))
                {
                    _LastSelectedGlyph.Name = InputDialog.Execute(_Context.ParentStateDiagramView, "Transition Property Input", "Transition Name", _LastSelectedGlyph.Name);
                }
                else if (IsControlKey(e, Keys.V))
                {
                    ITransitionGlyph transitionGlyph = _LastSelectedGlyph as ITransitionGlyph;
                    transitionGlyph.EventSignal = InputDialog.Execute(_Context.ParentStateDiagramView, "Transition Property Input", "Transition Event Signal", transitionGlyph.EventSignal);
                }
                else if (IsControlKey(e, Keys.K))
                {
                    ITransitionGlyph transitionGlyph = _LastSelectedGlyph as ITransitionGlyph;
                    transitionGlyph.EventSource = InputDialog.Execute(_Context.ParentStateDiagramView, "Transition Property Input", "Transition Event Source", transitionGlyph.EventSource);
                }
                else if (IsControlKey(e, Keys.G))
                {
                    ITransitionGlyph transitionGlyph = _LastSelectedGlyph as ITransitionGlyph;
                    transitionGlyph.GuardCondition = InputDialog.Execute(_Context.ParentStateDiagramView, "Transition Property Input", "Transition Event Guard Condition", transitionGlyph.GuardCondition);
                }
                else if (IsControlKey(e, Keys.A))
                {
                    ITransitionGlyph transitionGlyph = _LastSelectedGlyph as ITransitionGlyph;
                    transitionGlyph.Action = InputDialog.Execute(_Context.ParentStateDiagramView, "Transition Property Input", "Transition Event Action", transitionGlyph.Action);
                }
                else if (IsControlKey(e, Keys.I))
                {
                    ITransitionGlyph transitionGlyph = _LastSelectedGlyph as ITransitionGlyph;
                    transitionGlyph.IsInnerTransition = !transitionGlyph.IsInnerTransition;
                }
            }
            else if (_Model.IsStateTransitionPortGlyph(_LastSelectedGlyph))
            {
                if (IsControlKey(e, Keys.N))
                {
                    _LastSelectedGlyph.Name = InputDialog.Execute(_Context.ParentStateDiagramView, "State Transition Port Property Input", "Port Name", _LastSelectedGlyph.Name);
                }
            }
            else if (_Model.IsComponentGlyph(_LastSelectedGlyph))
            {
                if (IsControlKey(e, Keys.N))
                {
                    _LastSelectedGlyph.Name = InputDialog.Execute(_Context.ParentStateDiagramView, "Component Property Input", "Component Name", _LastSelectedGlyph.Name);
                }
            }
            else
            {
                if (IsControlKey(e, Keys.N))
                {
                    _LastSelectedGlyph.Name = InputDialog.Execute(_Context.ParentStateDiagramView, "Property Input", "Name", _LastSelectedGlyph.Name);
                }
            }

            _Context.RefreshView();
        }
        public void Start()
        {
            Prepare ();

            IStateGlyph state = OuterMostState ();
            if (state == null)
            {
                throw new Exception ("No parent start state found!");
            }
            CurrentState = state;
            DoRefresh ();
        }
        protected void GetTransitionList(ArrayList transitionList, IStateGlyph state)
        {
            // now find transitions
            foreach (IGlyph child in state.Children)
            {
                ITransitionContactPointGlyph transContactPoint = child as ITransitionContactPointGlyph;
                if (transContactPoint != null)
                {
                    ITransitionGlyph trans = transContactPoint.Owner as ITransitionGlyph;

                    if (transContactPoint.WhichEnd == TransitionContactEnd.From)
                    {
                        // this is a from transition

                        ITransitionContactPointGlyph transTo = null;
                        foreach (ITransitionContactPointGlyph contactPoint in trans.ContactPoints)
                        {
                            if (contactPoint.WhichEnd == TransitionContactEnd.To)
                            {
                                transTo = contactPoint;
                                break;
                            }
                        }
                        System.Diagnostics.Debug.Assert (transTo != null, "Transition To Contact Point not found");

                        IStateGlyph toStateGlyph = transTo.Parent as IStateGlyph;
                        string toStateName = "TRANSITION_TOSTATE_NOT_SET";
                        if (toStateGlyph != null)
                        {
                            if (IsNotEmptyString (toStateGlyph.Name))
                            {
                                toStateName = StateNameFrom (toStateGlyph);
                            }
                            else
                            {
                                toStateName = "TRANSITION_TOSTATE_SET_BUT_STATE_NOT_NAMED";
                            }
                        }

                        TransitionInfo info = new TransitionInfo (trans, StateNameFrom (state), toStateName, toStateGlyph);
                        transitionList.Add (info);
                    }
                }
            }
        }
 protected string StateNameFrom(IStateGlyph state)
 {
     string name = state.FullyQualifiedStateName;
     name = name.Replace (".", "_");
     return name;
 }
 public TransitionInfo(ITransitionGlyph trans, string fromStateName, string toStateName, IStateGlyph toStateGlyph)
 {
     Transition = trans;
     FromStateName = fromStateName;
     ToStateName = toStateName;
     ToStateGlyph = toStateGlyph;
 }
예제 #40
0
 protected void WriteStaticTransitionChains(IStateGlyph state, ArrayList transitionList)
 {
     Hashtable writtenTrans = new Hashtable ();
     transitionList.Sort (new TransitionVarComparer ());
     foreach (TransitionInfo transInfo in transitionList)
     {
         ITransitionGlyph trans = transInfo.Transition;
         if (!trans.IsProperInnerTransition ())
         {
             string sv = transInfo.TransitionVarName;
             if (!writtenTrans.Contains (sv))
             {
                 WriteLine ("protected static int {0} = s_TransitionChainStore.GetOpenSlot ();", sv);
                 writtenTrans.Add (sv, sv);
             }
         }
     }
 }
 protected bool StateHasAfterTransitions(IStateGlyph state)
 {
     foreach (TransitionInfo transInfo in GetTransitionList (state))
     {
         if (IsNotEmptyString (transInfo.Transition.TimeOutExpression))
         {
             return true;
         }
     }
     return false;
 }
예제 #42
0
 protected bool CanInstrument(IStateGlyph state)
 {
     return _Instrument && state.DoNotInstrument == false;
 }
예제 #43
0
        protected void WriteTransition(IStateGlyph state, ArrayList groupedTransitionList)
        {
            ITransitionGlyph trans = (groupedTransitionList [0] as TransitionInfo).Transition;
            WriteLine ("case {0}{1}.{2}: {{", _SignalTypeCast, _QualifiedSignalClassName, trans.Event);
            Inc ();
            int round = 0;
            string breakString = "break;"; // if no non-empty guard condition so execution could fall through all tests - so break at end of case block.
            CheckTransitions (state, groupedTransitionList);
            foreach (TransitionInfo transInfo in groupedTransitionList)
            {
                trans = transInfo.Transition;

                bool transitionHasAction = IsNotEmptyString (trans.Action);
                bool transitionHasGuard = HasGuardCondition (trans);

                if (transitionHasGuard == false)
                {
                    breakString = ""; // empty guard condition and empty source - so conditionless handler - no need for break as no fall-through.
                }

                if (transitionHasGuard)
                {
                    string elseOp = round > 0 ? "else" : "";
                    string condition = trans.GuardCondition;
                    WriteLine ("{1} if ({0}) {{", condition, elseOp);
                    Inc ();
                }
                else if (round > 0)
                {
                    WriteLine ("else {");
                    Inc ();
                }

                switch (trans.TransitionType)
                {
                    case TransitionType.History:
                    {
                        throw new NotSupportedException ("History transitions are not yet supported");
                    }
                    case TransitionType.DeepHistory:
                    {
                        WriteLine ("QState toState_{0} = _{0}_DeepHistory == null ? s_{0} : _{0}_DeepHistory;", transInfo.ToStateName);
                    } break;
                }

                /*
                if (trans.IsProperInnerTransition ())
                {
                    WriteLog (StateLogType.EventBeforeInternalTransition, state, transInfo);
                }
                else
                {
                    switch (trans.TransitionType)
                    {
                        case TransitionType.History:
                        {
                            throw new NotSupportedException ("History transitions are not yet supported");
                        }
                        case TransitionType.DeepHistory:
                        {
                            WriteLog (StateLogType.EventBeforeTransition, state, transInfo, "toState");
                        } break;
                        default:
                        {
                            WriteLog (StateLogType.EventBeforeTransition, state, transInfo);
                        } break;
                    }
                }
                */

                string codeBlockName = _SignalClassName + "." + trans.QualifiedEvent;
                if (transitionHasGuard)
                {
                    if (IsNotEmptyString (trans.Name) == false)
                    {
                        string msg = string.Format ("State {0} - transition with guard condition must have a name: {1}", StateNameFrom (state), trans.DisplayText ());
                        throw new ArgumentException (msg);
                    }
                    codeBlockName += ":" + trans.Name;
                }
                WriteStateCodeBlock (state, codeBlockName);

                if (transitionHasAction)
                {
                    string action = ParseAction (trans.Action);
                    WriteLine ("{0};", action);
                }

                if (!trans.IsProperInnerTransition ())
                {
                    switch (trans.TransitionType)
                    {
                        case TransitionType.History:
                        {
                            throw new NotSupportedException ("History transitions are not yet supported");
                        }
                        case TransitionType.DeepHistory:
                        {
                            WriteLog (StateLogType.EventTransition, state, transInfo, "toState");
                            WriteLine ("TransitionTo (toState_{0});", transInfo.ToStateName);
                        } break;
                        default:
                        {
                            WriteLog (StateLogType.EventTransition, state, transInfo);
                            WriteLine ("TransitionTo (s_{0}, {1});", transInfo.ToStateName, transInfo.TransitionVarName);
                        } break;
                    }
                }

                if (trans.IsProperInnerTransition ())
                {
                    WriteLog (StateLogType.EventInternalTransition, state, transInfo);
                }

                WriteLine ("return null;");

                if (transitionHasGuard || round > 0)
                {
                    Dec ();
                    WriteLine ("}");
                }

                round++;
            }
            Dec ();
            WriteLine ("}} {0} // {1}", breakString, trans.QualifiedEvent);
        }
예제 #44
0
 protected void WriteLog(StateLogType logType, IStateGlyph state, IStateGlyph initState)
 {
     if (CanInstrument (state))
     {
         WriteLine ("LogStateEvent (StateLogType.{0}, s_{1}, s_{2});", logType, StateNameFrom (state), StateNameFrom (initState));
     }
 }
예제 #45
0
 protected void WriteLog(StateLogType logType, IStateGlyph state)
 {
     if (CanInstrument (state))
     {
         string action = null;
         switch (logType)
         {
             case StateLogType.Entry:
             {
                 action = NormalisedActionDisplayText (state.EntryAction);
             } break;
             case StateLogType.Exit:
             {
                 action = NormalisedActionDisplayText (state.ExitAction);
             } break;
         }
         if (action == null)
         {
             WriteLine ("LogStateEvent (StateLogType.{0}, s_{1});", logType, StateNameFrom (state));
         }
         else
         {
             WriteLine ("LogStateEvent (StateLogType.{0}, s_{1}, \"{2}\");", logType, StateNameFrom (state), action);
         }
     }
 }
 private string GetStateName(IStateGlyph stateGlyph)
 {
     string sname = "S_" + stateGlyph.FullyQualifiedStateName;
     sname = sname.Replace (".", "_");
     return sname;
 }
예제 #47
0
 protected void WriteLog(StateLogType logType, IStateGlyph state, TransitionInfo transitionInfo, string transitionFieldNamePrefix)
 {
     if (CanInstrument (state))
     {
         string text = NormalisedTransitionDisplayText (transitionInfo);
         WriteLine ("LogStateEvent (StateLogType.{0}, s_{1}, {5}_{2}, \"{3}\", \"{4}\");", logType, StateNameFrom (state), transitionInfo.ToStateName, transitionInfo.Transition.QualifiedEvent, text, transitionFieldNamePrefix);
     }
 }
예제 #48
0
        protected void CheckTransitions_DuplicateTransitionsNoGuard(IStateGlyph state, ArrayList groupedTransitionList)
        {
            // not really necessary - but supplies extra info.
            bool guardLessTransFound = false;
            foreach (TransitionInfo transInfo in groupedTransitionList)
            {
                ITransitionGlyph trans = transInfo.Transition;

                if (IsNotEmptyString (trans.GuardCondition) == false)
                {
                    if (guardLessTransFound)
                    {
                        string msg = string.Format ("Two transitions from the same State: {0} have the same event {1} without guard conditions", StateNameFrom (state), trans.QualifiedEvent);
                        throw new ArgumentException (msg);
                    }
                    guardLessTransFound = true;
                }
            }
        }
예제 #49
0
 protected void WriteLog(StateLogType logType, IStateGlyph state, TransitionInfo transitionInfo)
 {
     WriteLog(logType, state, transitionInfo, "s");
 }
예제 #50
0
        protected void WriteStateDefaults(IStateGlyph state)
        {
            IStateGlyph initState = null;
            foreach (IGlyph child in state.Children)
            {
                IStateGlyph childState = child as IStateGlyph;
                if (childState != null && childState.IsStartState)
                {
                    System.Diagnostics.Debug.Assert (initState == null, "More than one child marked as StartState: " + state.Name);
                    initState = childState;
                }
            }

            if (initState != null)
            {
                WriteLine ("case {0}QSignals.Init: {{", _SignalTypeCast);
                Inc ();
                WriteLog (StateLogType.Init, state, initState);
                WriteStateCodeBlock (state, "Init");
                WriteLine ("InitializeState (s_{0});", StateNameFrom (initState));
                Dec ();
                WriteLine ("} return null;");
            }

            if (IsNotEmptyString (state.DoAction))
            {
                throw new NotSupportedException ("DoAction not supported. Found in state: " + StateNameFrom (state));
            }

            bool isFinalState = state.IsFinalState;
            bool hasEntryAction = IsNotEmptyString (state.EntryAction);
            bool stateMustKeepHistory = StateOrParentHasDeepHistoryTransition (state);
            bool hasAfterTransitions = StateHasAfterTransitions (state);
            if (hasEntryAction || isFinalState || stateMustKeepHistory || hasAfterTransitions)
            {
                WriteLine ("case {0}QSignals.Entry: {{", _SignalTypeCast);
                Inc ();
                WriteLog (StateLogType.Entry, state);
                WriteStateCodeBlock (state, "Entry");
                if (stateMustKeepHistory)
                {
                    ArrayList historyKeepers = GetStateOrParentsThatHasDeepHistoryTransition (state);
                    foreach (IStateGlyph historyKeeper in historyKeepers)
                    {
                        WriteLine ("_{0}_DeepHistory = s_{1};", StateNameFrom (historyKeeper), StateNameFrom (state));
                    }
                }
                if (hasEntryAction)
                {
                    WriteLine ("{0};", ParseAction (state.EntryAction));
                }
                if (hasAfterTransitions)
                {
                    ArrayList afterTransitions = GetStateAfterTransitions (state);
                    foreach (ITransitionGlyph trans in afterTransitions)
                    {
                        if (trans.IsInnerTransition)
                        {
                            throw new NotSupportedException ("After Timeout transitions are not supported for InnerTransitions");
                        }
                        string timeOutExpression = trans.TimeOutExpression.Trim ();
                        if (timeOutExpression.IndexOf (" ") == -1)
                        {
                            // this is the original timeout request
                            WriteLine ("SetTimeOut (\"{0}_{1}_{2}\", TimeSpan.FromSeconds ({3}), new QEvent (\"{4}\"));", StateNameFrom (state), trans.Name, trans.Event, trans.TimeOutExpression, trans.QualifiedEvent);
                        }
                        else
                        {
                            string[] strList = timeOutExpression.Split (' ');
                            string timeOut = strList [strList.Length - 1].Trim ();
                            string flag = "Single";
                            if (timeOutExpression.StartsWith ("every"))
                            {
                                flag = "Repeat";
                            }
                            if (timeOutExpression.StartsWith ("at"))
                            {
                                flag = "Single";
                                WriteLine ("SetTimeOut (\"{0}_{1}_{2}\", {3}, new QEvent (\"{4}\"), TimeOutType.{5});", StateNameFrom (state), trans.Name, trans.Event, timeOut, trans.QualifiedEvent, flag);
                            }
                            else
                            {
                                WriteLine ("SetTimeOut (\"{0}_{1}_{2}\", TimeSpan.FromSeconds ({3}), new QEvent (\"{4}\"), TimeOutType.{5});", StateNameFrom (state), trans.Name, trans.Event, timeOut, trans.QualifiedEvent, flag);
                            }
                        }
                    }
                }
                if (isFinalState)
                {
                    WriteLine ("DoFinalStateReached (this, s_{0});", StateNameFrom (state));
                }
                Dec ();
                WriteLine ("} return null;");
            }
            else if (!state.IsOverriding)
            {
                WriteLine ("case {0}QSignals.Entry: {{", _SignalTypeCast);
                Inc ();
                WriteLog (StateLogType.Entry, state);
                WriteStateCodeBlock (state, "Entry");
                Dec ();
                WriteLine ("} return null;");
            }

            if (hasAfterTransitions || IsNotEmptyString (state.ExitAction))
            {
                WriteLine ("case {0}QSignals.Exit: {{", _SignalTypeCast);
                Inc ();
                if (hasAfterTransitions)
                {
                    ArrayList afterTransitions = GetStateAfterTransitions (state);
                    foreach (ITransitionGlyph trans in afterTransitions)
                    {
                        WriteLine ("ClearTimeOut (\"{0}_{1}_{2}\");", StateNameFrom (state), trans.Name, trans.Event);
                    }
                }
                WriteStateCodeBlock (state, "Exit");
                if (IsNotEmptyString (state.ExitAction))
                {
                    WriteLine ("{0};", ParseAction (state.ExitAction));
                }
                WriteLog (StateLogType.Exit, state);
                Dec ();
                WriteLine ("} return null;");
            }
            else if (!state.IsOverriding)
            {
                WriteLine ("case {0}QSignals.Exit: {{", _SignalTypeCast);
                Inc ();
                WriteStateCodeBlock (state, "Exit");
                WriteLog (StateLogType.Exit, state);
                Dec ();
                WriteLine ("} return null;");
            }
        }
 protected bool StateHasAsAnyParent(IStateGlyph state, IStateGlyph possibleParentState)
 {
     while (state != null)
     {
         if (state.Parent == possibleParentState)
         {
             return true;
         }
         state = state.Parent as IStateGlyph;
     }
     return false;
 }
예제 #52
0
 protected void WriteStateCodeBlock(IStateGlyph state, string eventName)
 {
     string stateName = StateNameFrom (state);
     string codeBlockName = string.Format ("{0}:{1}", stateName, eventName);
     if (_WriteStateCodeBlocks)
     {
         WriteCodeBlock (codeBlockName);
     }
     else
     {
         string block = GetCodeBlock (codeBlockName);
         if (IsNotEmptyString (block))
         {
             throw new Exception ("Don't want to use these code blocks for now... - can put them back in later!\n\nCodeBlock: " + block);
         }
     }
 }
 protected bool StateOrParentHasDeepHistoryTransition(IStateGlyph state)
 {
     while (state != null)
     {
         if (_StatesWithHistoryTransitions.Contains (state))
         {
             return true;
         }
         state = state.Parent as IStateGlyph;
     }
     return false;
 }
예제 #54
0
        protected void WriteState(IStateGlyph state)
        {
            ArrayList transitionList = GetTransitionList (state);
            Inc ();
            WriteLine ("");
            WriteLine ("#region State {0}", StateNameFrom (state));

            WriteStaticTransitionChains (state, transitionList);

            WriteLine ("[StateMethod (\"{0}\")]", StateNameFrom (state));
            foreach (string stateCommandName in state.StateCommands)
            {
                if (IsNotEmptyString (stateCommandName))
                {
                    WriteLine ("[StateCommand (\"{0}\")]", stateCommandName);
                }
            }
            string overrideOrVirtual = state.IsOverriding ? "override" : "virtual";
            WriteLine ("protected {0} QState S_{1} (IQEvent ev){{", overrideOrVirtual, StateNameFrom (state));
            Inc ();
            WriteLine ("switch (ev.QSignal){");
            WriteStateDefaults (state);

            // now find transitions
            ArrayList groupedTransitions = GroupTransitionsByEvent (transitionList);
            foreach (ArrayList groupedTransitionList in groupedTransitions)
            {
                WriteTransition (state, groupedTransitionList);
            }
            WriteLine ("} // switch");

            // get return parent state
            string parentName = "TopState";
            IGlyph parentGlyph = state.Parent;
            if (parentGlyph != null)
            {
                IStateGlyph parentState = parentGlyph as IStateGlyph;
                parentName = "s_" + StateNameFrom (parentState);
            }

            WriteLine ("");
            if (state.IsOverriding)
            {
                WriteLine ("return base.S_{0} (ev);", StateNameFrom (state));
            }
            else
            {
                WriteLine ("return {0};", parentName);
            }

            Dec ();
            WriteLine ("}} // S_{0}", StateNameFrom (state));
            WriteLine ("#endregion");
            Dec ();
        }
예제 #55
0
 protected void AnalyseGuardAction(IStateGlyph state, ITransitionGlyph trans, string actions)
 {
     string[] names = ParseNames (actions);
 }
예제 #56
0
        protected void CheckTransitions_CheckUniqueNames(IStateGlyph state, ArrayList groupedTransitionList)
        {
            Hashtable catcher = new Hashtable ();
            foreach (TransitionInfo transInfo in groupedTransitionList)
            {
                ITransitionGlyph trans = transInfo.Transition;

                string text = trans.Name;
                if (IsNotEmptyString (text))
                {
                    if (catcher.Contains (text))
                    {
                        string msg = string.Format ("More than one transition has same name {0}. Last one found in state {1} event {2}", text, StateNameFrom (state), trans.DisplayText ());
                        throw new ArgumentException (msg);
                    }
                    catcher.Add (text, text);
                }
            }
        }
 protected ArrayList GetTransitionList(IStateGlyph state)
 {
     ArrayList transitionList = new ArrayList ();
     GetTransitionList (transitionList, state);
     return transitionList;
 }
예제 #58
0
        protected void CheckTransitions_CatchDuplicateEvents(IStateGlyph state, ArrayList groupedTransitionList)
        {
            Hashtable catcher = new Hashtable ();
            foreach (TransitionInfo transInfo in groupedTransitionList)
            {
                ITransitionGlyph trans = transInfo.Transition;

                string eventText = trans.CompleteEventText (false, false);
                if (catcher.Contains (eventText))
                {
                    string msg = string.Format ("More than one transition from the same State: {0} have the same event {1}", StateNameFrom (state), eventText);
                    throw new ArgumentException (msg);
                }
                catcher.Add (eventText, eventText);
            }
        }
예제 #59
0
 protected void CheckTransitions(IStateGlyph state, ArrayList groupedTransitionList)
 {
     CheckTransitions_DuplicateTransitionsNoGuard (state, groupedTransitionList);
     CheckTransitions_CatchDuplicateEvents (state, groupedTransitionList);
     CheckTransitions_CheckUniqueNames (state, groupedTransitionList);
 }
        void SaveStateGlyph(TextWriter sw, IStateGlyph glyph)
        {
            SaveBounds (sw, "STATE:", glyph);
            if (glyph.Parent != null)
            {
                sw.WriteLine (glyph.Parent.Id);
            }
            else
            {
                sw.WriteLine ("NOPARENT");
            }

            SaveGlyphCommon (sw, glyph);

            IStateGlyph state = glyph;
            SaveText (sw, "NAME", state.Name);
            SaveText (sw, "ISSTARTSTATE", state.IsStartState.ToString ());
            SaveText (sw, "ISFINALSTATE", state.IsFinalState.ToString ());
            SaveText (sw, "ENTRY", state.EntryAction);
            SaveText (sw, "EXIT", state.ExitAction);
            SaveText (sw, "DO", state.DoAction);
            SaveText (sw, "ISOVERRIDING", state.IsOverriding.ToString ());

            ArrayList commandList = new ArrayList ();
            foreach (string commandName in state.StateCommands)
            {
                if (commandName != null && commandName.Trim () != "")
                {
                    commandList.Add (commandName);
                }
            }
            string[] commandsArray = (string[]) commandList.ToArray (typeof (string));
            string cmds = string.Join (";", commandsArray);
            SaveTextIfNotDefault (sw, "STATECOMMANDS", cmds, "");
        }