Example #1
0
        private void BuildBasicObjectsTrees()
        {
            Trees           = new List <BasicObjectsTree>();
            GlobalObjects   = new List <IBasicGlobal>();
            BasicStatesList = new List <BasicState>();
            foreach (IGlobal global in Book.Globals)
            {
                switch (global)
                {
                case Origin origin:
                    if (origin.Father == null)
                    {
                        var basicObjectsTree = new BasicObjectsTree(origin.OwnerDraw.OwnerSheet, origin);
                        Trees.Add(basicObjectsTree);
                        if (!basicObjectsTree.AddStatesToList(BasicStatesList))
                        {
                            MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "There is one or more states used in diferent state machines.", null));
                        }
                        GlobalObjects.Add(basicObjectsTree);
                    }
                    break;

                case Relation indir:
                    GlobalObjects.Add(RelationsList.Find(bi => bi.Relation == indir));
                    break;

                case Equation eq:
                    GlobalObjects.Add(EquationsList.Find(be => be.Equation == eq));
                    break;
                }
            }
            if (Trees.Count == 0)
            {
                MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "There is not a valid state machine to check.", null));
            }
        }
Example #2
0
 private void GetUsedObjects(DrawingSheet sheet, VariableCollection variables)
 {
     if (sheet is ModelSheet model)
     {
         UsedModels.Add(model);
     }
     else
     {
         UsedSheets.Add(sheet);
     }
     foreach (DrawableObject obj in sheet.Sketch.Objects)
     {
         if (obj is Relation indir)
         {
             Variable input  = VariableCollection.GetIndirectInput(sheet, indir.Trigger);
             Variable output = VariableCollection.GetIndirectOutput(sheet, indir.Output);
             if (input == null)
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation trigger variable not found.", indir));
             }
             if (output == null)
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation output variable not found.", indir));
             }
             if (input != null && output != null)
             {
                 BasicRelation ibindir = RelationsList.FirstOrDefault(ind => ind.Input.Name == input.Name);
                 BasicRelation obindir = RelationsList.FirstOrDefault(ind => ind.Action.Output.Name == input.Name);
                 if (ibindir != null)
                 {
                     MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation has same input than other one.", indir, ibindir.Relation));
                 }
                 if (obindir != null)
                 {
                     MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation has same output than other one.", indir, obindir.Relation));
                 }
                 if (ibindir == null && obindir == null)
                 {
                     BasicOutput   action = indir.Action == null ? null : new BasicOutput((OperationType)Enum.Parse(typeof(OperationType), indir.Action), output);
                     BasicRelation bindir = new BasicRelation(indir, input, action);
                     RelationsList.Add(bindir);
                 }
             }
         }
         else if (obj is Equation eq)
         {
             IInternalOutput output = variables.IndirectOutputs.FirstOrDefault(io => io.Name == eq.AssignTo);
             if (output == null)
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation trigger variable not found.", eq));
             }
             if (eq.Operation == "")
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Equation does not have operation.", eq));
             }
             LexicalAnalyzer lexAnalyzer = new LexicalAnalyzer();
             SyntaxAnalyzer  syntaxAnalyzer;
             lexAnalyzer.Source = eq.Operation;
             syntaxAnalyzer     = new SyntaxAnalyzer(lexAnalyzer, VariableCollection.GetConditionDictionary(eq.OwnerDraw.OwnerSheet).Keys.ToList());
             foreach (SyntaxToken token in syntaxAnalyzer.Tokens)
             {
                 if (token.Qualifier != SyntaxToken.Qualifiers.Correct)
                 {
                     MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, string.Format("{0}: {1}.", eq.Name, token.ToString()), eq));
                 }
             }
             EquationsList.Add(new BasicEquation(eq));
         }
         else if (obj is Transition trans)
         {
             TransitionsList.Add(trans);
             if (trans.StartObject == null)
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition without start connection.", trans));
             }
             if (trans.EndObject == null)
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition without end connection.", trans));
             }
             if (trans is SimpleTransition strans && strans.Condition == "" && strans.Timeout == 0)
             {
                 if (strans.StartObject is Origin origin)
                 {
                     if (strans.EndObject is End || strans.EndObject is Abort)
                     {
                         MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "One shot machine Transition should have a condition.", trans));
                     }
                 }
                 else if (!strans.DefaultTransition)
                 {
                     MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition does not have condition or timeout value.", trans));
                 }
             }
             else if (trans is SuperTransition sptrans && sptrans.Links == "")
             {
                 MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition is not linking any object.", trans));
             }
         }