/// <summary>
        /// Import the file in the corresponding nameSpace
        /// </summary>
        /// <param name="nameSpace"></param>
        public void Import(DataDictionary.Types.NameSpace nameSpace)
        {
            foreach (KeyValuePair <string, ErtmsSolutions.CodecNT.Type> pair in MessageDefinitions.types)
            {
                AppendType(nameSpace, pair.Key, pair.Value);
            }

            foreach (KeyValuePair <string, ErtmsSolutions.CodecNT.FieldGroup> pair in MessageDefinitions.field_groups)
            {
                AppendFieldGroup(nameSpace, pair.Key, pair.Value);
            }

            /* Do not append the Get function */
            if (false)
            {
                DataDictionary.Types.NameSpace packet = GetNameSpaceBasedOnName(nameSpace, "PACKET");
                DataDictionary.Types.NameSpace packet_track_to_train = GetNameSpaceBasedOnName(packet, "TRACK_TO_TRAIN");
                foreach (DataDictionary.Types.Structure structure in packet_track_to_train.Structures)
                {
                    AppendGetFunction(packet_track_to_train, structure, "NID_PACKET", "BaseTypes.IdentityNumber");
                }
            }
        }
        /// <summary>
        ///     Creates a namespace in the dictionary/namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected NameSpace CreateNameSpace(ModelElement enclosing, string name)
        {
            NameSpace retVal = (NameSpace)Factory.createNameSpace();

            Dictionary dictionary = enclosing as Dictionary;
            NameSpace  nameSpace  = enclosing as NameSpace;

            if (dictionary != null)
            {
                dictionary.appendNameSpaces(retVal);
            }
            else if (nameSpace != null)
            {
                nameSpace.appendNameSpaces(retVal);
            }
            else
            {
                Assert.Fail();
            }
            retVal.Name = name;

            return(retVal);
        }
        /// <summary>
        ///     Creates a rule and a rule condition in the namespace
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected RuleCondition CreateRuleAndCondition(NameSpace enclosing, string name)
        {
            Rule rule = (Rule) Factory.createRule();
            enclosing.appendRules(rule);
            rule.Name = name;

            return CreateRuleCondition(rule, name);
        }
        /// <summary>
        ///     Creates an range in the namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <param name="precision"></param>
        /// <param name="minValue"></param>
        /// <param name="maxValue"></param>
        /// <returns></returns>
        protected Range CreateRange(NameSpace enclosing, string name, acceptor.PrecisionEnum precision, string minValue,
            string maxValue)
        {
            Range retVal = (Range) Factory.createRange();

            enclosing.appendRanges(retVal);
            retVal.Name = name;
            retVal.setPrecision(precision);
            retVal.MinValue = minValue;
            retVal.MaxValue = maxValue;

            return retVal;
        }
        /// <summary>
        ///     Creates a function in the enclosing namespace
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected Procedure CreateProcedure(NameSpace enclosing, string name)
        {
            Procedure retVal = (Procedure) Factory.createProcedure();
            enclosing.appendProcedures(retVal);
            retVal.Name = name;

            return retVal;
        }
        /// <summary>
        ///     Creates a function in the enclosing namespace
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        protected Function CreateFunction(NameSpace enclosing, string name, string typeName)
        {
            Function retVal = (Function) Factory.createFunction();
            enclosing.appendFunctions(retVal);
            retVal.Name = name;
            retVal.TypeName = typeName;

            return retVal;
        }
        /// <summary>
        ///     Creates an enum in the namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected Enum CreateEnum(NameSpace enclosing, string name)
        {
            Enum retVal = (Enum) Factory.createEnum();

            enclosing.appendEnumerations(retVal);
            retVal.Name = name;

            return retVal;
        }
        /// <summary>
        ///     Performs a refactor
        /// </summary>
        /// <param name="element"></param>
        /// <param name="target"></param>
        protected void MoveToNameSpace(ModelElement element, NameSpace target)
        {
            Compiler.Compile_Synchronous(true);

            target.AddModelElement(element);
            Compiler.RefactorAndRelocate(element);
        }
        /// <summary>
        ///     Determines the set of rules in a specific namespace to be applied.
        /// </summary>
        /// <param name="priority">The priority for which this activation is requested</param>
        /// <param name="activations">The set of activations to be filled</param>
        /// <param name="nameSpace">The namespace to consider</param>
        /// <returns></returns>
        protected void SetupNameSpaceActivations(acceptor.RulePriority priority, HashSet<Activation> activations,
            NameSpace nameSpace)
        {
            // Finds all activations in sub namespaces
            foreach (NameSpace subNameSpace in nameSpace.NameSpaces)
            {
                SetupNameSpaceActivations(priority, activations, subNameSpace);
            }

            foreach (Rules.Rule rule in nameSpace.Rules)
            {
                // We only apply rules that have not been updated
                ExplanationPart explanation = new ExplanationPart(rule, "Rule evaluation");
                rule.Evaluate(this, priority, rule, activations, explanation);
            }

            foreach (IVariable variable in nameSpace.Variables)
            {
                EvaluateVariable(priority, activations, variable,
                    new ExplanationPart(variable as ModelElement, "Evaluating variable"));
            }
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="item"></param>
 /// <param name="buildSubNodes"></param>
 public NameSpaceSubNameSpacesTreeNode(NameSpace item, bool buildSubNodes)
     : base(item, buildSubNodes, "Namespaces", true)
 {
 }
        /// <summary>
        /// Creates a section for all the (implemented) structures of the given namespace
        /// </summary>
        /// <param name="aNameSpace">The namespace</param>
        /// <param name="addDetails">Add details or simply enumerate the structures</param>
        /// <returns></returns>
        public void CreateStructuresSection(DataDictionary.Types.NameSpace aNameSpace, bool addDetails)
        {
            if (countDisplayedReqRelated(aNameSpace.Structures) > 0)
            {
                AddSubParagraph("Structures");
                foreach (DataDictionary.Types.Structure structure in aNameSpace.Structures)
                {
                    if (structure.ImplementationPartiallyCompleted == true)
                    {
                        if (addDetails)
                        {
                            AddSubParagraph(structure.Name);
                            if (structure.Comment != "")
                            {
                                AddParagraph(structure.Comment);
                            }

                            AddTable(new string[] { "Structure " + structure.Name }, new int[] { 30, 20, 40, 50 });
                            AddTableHeader("Sub element name", "Mode", "Type", "Comment");
                            foreach (DataDictionary.Types.StructureElement element in structure.Elements)
                            {
                                AddRow(element.Name, element.getMode_AsString(), element.TypeName, element.Comment);
                            }

                            if (countDisplayedReqRelated(structure.Rules) > 0)
                            {
                                AddTableHeader("Rules");
                                foreach (DataDictionary.Rules.Rule rule in structure.Rules)
                                {
                                    AddRuleRow(rule, addDetails);
                                }
                            }

                            if (countDisplayedReqRelated(structure.Procedures) > 0)
                            {
                                AddSubParagraph("Procedures");
                                foreach (DataDictionary.Functions.Procedure procedure in structure.Procedures)
                                {
                                    if (procedure.ImplementationPartiallyCompleted == true)
                                    {
                                        AddSubParagraph(procedure.Name);
                                        CreateParameters("Procedure " + procedure.Name, procedure.Comment, procedure.FormalParameters, null);

                                        if (procedure.Rules.Count > 0)
                                        {
                                            AddTableHeader("Behaviour");
                                            foreach (DataDictionary.Rules.Rule rule in procedure.Rules)
                                            {
                                                AddRuleRow(rule, true);
                                            }
                                        }

                                        if (procedure.StateMachine != null && procedure.StateMachine.States.Count > 0)
                                        {
                                            if (procedure.StateMachine.ImplementationPartiallyCompleted)
                                            {
                                                AddSubParagraph("State machines of " + procedure.Name);
                                                AddStateMachineSection(procedure.StateMachine);
                                                CloseSubParagraph();
                                            }
                                        }
                                        CreateStatusTable(procedure);
                                        CloseSubParagraph();
                                    }
                                }
                                CloseSubParagraph();
                            }

                            CreateStatusTable(structure);
                            CloseSubParagraph();
                        }
                        else
                        {
                            AddParagraph(structure.Name + " (" + GetRequirementsAsString(structure.Requirements) + ")");
                        }
                    }
                }
                CloseSubParagraph();
            }
        }
        /// <summary>
        ///     Provides the display attributes for a model event
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        private EventDisplayAttributes GetDisplayAttributes(ModelEvent evt)
        {
            EventDisplayAttributes retVal = new EventDisplayAttributes(Color.White, new Pen(Color.Black), "<undefined>",
                                                                       null, null, null);

            ModelElement.DontRaiseError(() =>
            {
                Expect expect = evt as Expect;
                if (expect != null)
                {
                    string name = GuiUtils.AdjustForDisplay(ShortName(expect.Expectation.Name),
                                                            _eventSize.Width - 4, BottomFont);

                    switch (expect.State)
                    {
                    case Expect.EventState.Active:
                        retVal = new EventDisplayAttributes(Color.Violet, new Pen(Color.Black), name,
                                                            Images.Images[QuestionMarkImageIndex], NameSpaceImages.Instance.GetImage(expect.Expectation), null);
                        break;

                    case Expect.EventState.Fullfilled:
                        retVal = new EventDisplayAttributes(Color.LightGreen, new Pen(Color.Green), name,
                                                            Images.Images[SuccessImageIndex], NameSpaceImages.Instance.GetImage(expect.Expectation), null);
                        break;

                    case Expect.EventState.TimeOut:
                        retVal = new EventDisplayAttributes(Color.Red, new Pen(Color.DarkRed), name, Images.Images[ErrorImageIndex],
                                                            NameSpaceImages.Instance.GetImage(expect.Expectation), null);
                        break;
                    }

                    if (expect.Expectation.getKind() == acceptor.ExpectationKind.aContinuous)
                    {
                        retVal.TopRightIconImage.Add(Images.Images[CircularArrowIndex]);
                    }
                    if (expect.Expectation.Blocking)
                    {
                        retVal.TopRightIconImage.Add(Images.Images[DownArrowIndex]);
                    }
                }

                ModelInterpretationFailure modelInterpretationFailure = evt as ModelInterpretationFailure;
                if (modelInterpretationFailure != null)
                {
                    string name = GuiUtils.AdjustForDisplay(modelInterpretationFailure.Message,
                                                            _eventSize.Width - 4, BottomFont);

                    retVal = new EventDisplayAttributes(Color.Red, new Pen(Color.DarkRed), name, Images.Images[ErrorImageIndex],
                                                        NameSpaceImages.Instance.GetImage(modelInterpretationFailure.Instance as ModelElement), null);
                }

                RuleFired ruleFired = evt as RuleFired;
                if (ruleFired != null)
                {
                    string name = GuiUtils.AdjustForDisplay(ShortName(ruleFired.RuleCondition.Name),
                                                            _eventSize.Width - 4, BottomFont);

                    retVal = new EventDisplayAttributes(Color.LightBlue, new Pen(Color.Blue), name, null,
                                                        NameSpaceImages.Instance.GetImage(ruleFired.RuleCondition), Images.Images[ToolsImageIndex]);
                }

                VariableUpdate variableUpdate = evt as VariableUpdate;
                if (variableUpdate != null)
                {
                    string name         = variableUpdate.Action.ExpressionText;
                    Image rightIcon     = null;
                    Image rightModifier = null;
                    if (variableUpdate.Action.Statement != null)
                    {
                        name      = variableUpdate.Action.Statement.ShortShortDescription();
                        rightIcon = NameSpaceImages.Instance.GetImage(variableUpdate.Action.Statement.AffectedElement());

                        switch (variableUpdate.Action.Statement.UsageDescription())
                        {
                        case Statement.ModeEnum.Call:
                            rightModifier = Images.Images[CallImageIndex];
                            break;

                        case Statement.ModeEnum.In:
                            rightModifier = Images.Images[InImageIndex];
                            break;

                        case Statement.ModeEnum.InOut:
                            rightModifier = Images.Images[InOutImageIndex];
                            break;

                        case Statement.ModeEnum.Internal:
                            rightModifier = Images.Images[InternalImageIndex];
                            break;

                        case Statement.ModeEnum.Out:
                            rightModifier = Images.Images[OutImageIndex];
                            break;
                        }
                    }
                    name = GuiUtils.AdjustForDisplay(ShortName(name), _eventSize.Width - 4, BottomFont);

                    NameSpace nameSpace = EnclosingFinder <NameSpace> .find(variableUpdate.Action);
                    if (nameSpace == null)
                    {
                        retVal = new EventDisplayAttributes(Color.LightGray, new Pen(Color.Black), name, null, rightIcon,
                                                            rightModifier);
                    }
                    else
                    {
                        retVal = new EventDisplayAttributes(Color.BlanchedAlmond, new Pen(Color.Black), name, null,
                                                            rightIcon, rightModifier);
                    }
                }

                SubStepActivated subStepActivated = evt as SubStepActivated;
                if (subStepActivated != null)
                {
                    retVal = new EventDisplayAttributes(Color.LightGray, new Pen(Color.Black), "SubStep", null, null, null);
                }
            });

            return(retVal);
        }
Exemple #13
0
 public void AddHandler(object sender, EventArgs args)
 {
     DataDictionary.Types.NameSpace nameSpace = (DataDictionary.Types.NameSpace)DataDictionary.Generated.acceptor.getFactory().createNameSpace();
     nameSpace.Name = "<NameSpace" + (GetNodeCount(false) + 1) + ">";
     AddNameSpace(nameSpace);
 }
        /// <summary>
        ///     Creates a structure in the namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected Structure CreateStructure(NameSpace enclosing, string name)
        {
            Structure retVal = (Structure) Factory.createStructure();

            enclosing.appendStructures(retVal);
            retVal.Name = name;

            return retVal;
        }
        /// <summary>
        ///     Creates a colleciton in the namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name">The name of the collection</param>
        /// <param name="typeName">The name of the type of the elements in the collection</param>
        /// <param name="maxSize">The maximum collection size</param>
        /// <returns></returns>
        protected Collection CreateCollection(NameSpace enclosing, string name, string typeName, int maxSize)
        {
            Collection retVal = (Collection)Factory.createCollection();

            enclosing.appendCollections(retVal);
            retVal.Name = name;
            retVal.TypeName = typeName;
            retVal.setMaxSize(maxSize);

            return retVal;
        }
        /// <summary>
        ///     Creates a variable in the namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        protected Variable CreateVariable(NameSpace enclosing, string name, string typeName)
        {
            Variable retVal = (Variable) Factory.createVariable();

            enclosing.appendVariables(retVal);
            retVal.Name = name;
            retVal.TypeName = typeName;

            return retVal;
        }
        /// <summary>
        ///     Creates a rule and a rule condition in the namespace
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected RuleCondition CreateRuleAndCondition(NameSpace enclosing, string name)
        {
            Rule rule = (Rule) Factory.createRule();
            enclosing.appendRules(rule);
            rule.Name = name;
            rule.setPriority(acceptor.RulePriority.aProcessing);

            return CreateRuleCondition(rule, name);
        }
Exemple #18
0
        private string format_eurobalise_message(DBElements.DBMessage message)
        {
            DataDictionary.Types.NameSpace nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages");
            Types.Structure       structureType      = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.Message");
            Values.StructureValue structure          = new Values.StructureValue(structureType, nameSpace);

            int index = 0;

            FillStructure(nameSpace, message.Fields, ref index, structure); // fills the message fields


            // then we fill the packets
            KeyValuePair <string, Variables.IVariable> subSequencePair = structure.SubVariables.ElementAt(structure.SubVariables.Count - 1);

            Variables.IVariable subSequenceVariable = subSequencePair.Value;

            Types.Collection collectionType = (Types.Collection)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.Collection1");
            Values.ListValue collection     = new Values.ListValue(collectionType, new List <Values.IValue>());

            Types.Structure       subStructure1Type = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.SubStructure1");
            Values.StructureValue subStructure1     = new Values.StructureValue(subStructure1Type, nameSpace);

            Types.Structure       packetStructure = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.PACKET.TRACK_TO_TRAIN.Message");
            Values.StructureValue packetValue     = new Values.StructureValue(packetStructure, nameSpace);

            // will contain the list of all packets of the message and then be added to the structure packetValue
            ArrayList subStructures = new ArrayList();

            foreach (DBElements.DBPacket packet in message.Packets)
            {
                Tests.DBElements.DBField nidPacketField = packet.Fields[0] as Tests.DBElements.DBField;

                if (nidPacketField.Value != 255)  // 255 means "end of information"
                {
                    Values.StructureValue subStructure = FindStructure(nidPacketField.Value);

                    index = 0;
                    FillStructure(nameSpace, packet.Fields, ref index, subStructure);

                    subStructures.Add(subStructure);
                }
            }

            // the collection of the message packets is copied to the structure packetValue
            int i = 0;

            foreach (KeyValuePair <string, Variables.IVariable> pair in packetValue.SubVariables)
            {
                if (i == subStructures.Count)
                {
                    break;
                }
                string variableName = pair.Key;
                Values.StructureValue structureValue = subStructures[i] as Values.StructureValue;
                if (structureValue.Structure.FullName.Contains(variableName))
                {
                    Variables.IVariable variable = pair.Value;
                    variable.Value = structureValue;
                    i++;
                }
            }

            subStructure1.SubVariables.ElementAt(0).Value.Value = packetValue;
            collection.Val.Add(subStructure1);
            subSequenceVariable.Value = collection;

            return(structure.Name);
        }
        /// <summary>
        /// Appends the corresponding type to the name space
        /// </summary>
        /// <param name="nameSpace">The namespace in which the type must be added</param>
        /// <param name="name">the name of the type</param>
        /// <param name="type">the type to convert</param>
        private DataDictionary.Types.Type AppendType(DataDictionary.Types.NameSpace nameSpace, string name, ErtmsSolutions.CodecNT.Type type)
        {
            DataDictionary.Types.Type retVal = null;

            if (EFSType(type) == null)
            {
                if (type.value is UiValue)
                {
                    UiValue uiValue = type.value as UiValue;

                    List <DataDictionary.Constants.EnumValue> values = getSpecialValues(uiValue.special_or_reserved_values);

                    Decimal maxValue = twoPow(type.length) - 1;
                    if (IsEnumeration(values, maxValue))
                    {
                        DataDictionary.Types.Enum enumeration = (DataDictionary.Types.Enum)DataDictionary.Generated.acceptor.getFactory().createEnum();
                        enumeration.Name    = type.id;
                        enumeration.Default = values[0].Name;
                        foreach (DataDictionary.Constants.EnumValue value in values)
                        {
                            enumeration.appendValues(value);
                        }

                        nameSpace.appendEnumerations(enumeration);
                        retVal = enumeration;
                    }
                    else
                    {
                        DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange();
                        range.Name = type.id;

                        double factor = 1.0;

                        System.Globalization.CultureInfo info = System.Globalization.CultureInfo.InvariantCulture;
                        ResolutionFormula resolutionFormula   = uiValue.resolution_formula;
                        if (resolutionFormula != null && resolutionFormula.Value != null)
                        {
                            factor = double.Parse(resolutionFormula.Value, info);

                            // In that case the precision is integer
                            range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aIntegerPrecision);
                            range.MinValue = "0";
                            range.MaxValue = "" + maxValue;
                            range.Default  = "0";
                        }

                        else
                        {
                            if (Math.Round(factor) == factor)
                            {
                                // Integer precision
                                range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aIntegerPrecision);
                                range.MinValue = "0";
                                range.MaxValue = "" + maxValue * new Decimal(factor);
                                range.Default  = "0";
                            }
                            else
                            {
                                // Double precision
                                range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aDoublePrecision);
                                range.MinValue = "0.0";
                                range.MaxValue = (maxValue * new Decimal(factor)).ToString(info);
                                range.Default  = "0.0";
                            }
                        }

                        foreach (DataDictionary.Constants.EnumValue value in values)
                        {
                            range.appendSpecialValues(value);
                        }

                        nameSpace.appendRanges(range);
                        retVal = range;
                    }
                }
                else if (type.value is CharValue)
                {
                    CharValue charValue = type.value as CharValue;

                    // Nothing to do : translated into string
                }
                else if (type.value is BcdValue)
                {
                    BcdValue bcdValue = type.value as BcdValue;

                    DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange();
                    range.Name     = type.id;
                    range.MinValue = "0";
                    range.MaxValue = "" + (twoPow(type.length) - 1);
                    range.Default  = "0";

                    nameSpace.appendRanges(range);
                    retVal = range;
                }

                if (retVal != null)
                {
                    retVal.Comment = type.short_description;
                    if (type.description != null)
                    {
                        retVal.Comment = retVal.Comment + "\n" + type.description;
                    }
                }
            }

            return(retVal);
        }