/// <summary> /// Accepts drop of a tree node, in a drag & drop operation /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { base.AcceptDrop(SourceNode); if (SourceNode is RangeTreeNode) { RangeTreeNode rangeTreeNode = SourceNode as RangeTreeNode; DataDictionary.Types.Range range = rangeTreeNode.Item; rangeTreeNode.Delete(); AddRange(range); } else if (SourceNode is SpecificationView.ParagraphTreeNode) { SpecificationView.ParagraphTreeNode node = SourceNode as SpecificationView.ParagraphTreeNode; DataDictionary.Specification.Paragraph paragaph = node.Item; DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange(); range.Name = paragaph.Name; DataDictionary.ReqRef reqRef = (DataDictionary.ReqRef)DataDictionary.Generated.acceptor.getFactory().createReqRef(); reqRef.Name = paragaph.FullId; range.appendRequirements(reqRef); AddRange(range); } }
/// <summary> /// Provides the graph of this function if it has been statically defined /// </summary> /// <param name="context">the context used to create the graph</param> /// <param name="parameter"></param> /// <param name="explain"></param> /// <returns></returns> public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain) { Graph retVal = null; Graph graph = createGraphForValue(context, context.FindOnStack(Function).Value, explain, parameter); if (graph != null) { double speed = GetDoubleValue(context.FindOnStack(Speed).Value); double solutionX = graph.SolutionX(speed); if (solutionX == double.MaxValue) { // No value found, return Unknown Range distanceType = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance"); EnumValue unknownDistance = distanceType.findEnumValue("Unknown"); retVal = Graph.createGraph(distanceType.getValueAsDouble(unknownDistance)); } else { // Create the graph for this solution retVal = Graph.createGraph(solutionX); } } else { Function.AddError("Cannot create graph for " + Function); } return(retVal); }
/// <summary> /// Constructor /// </summary> /// <param name="subSequence"></param> /// <param name="explain"></param> /// <param name="ensureCompilation">Indicates that the runner should make sure that the system is compiled</param> /// <param name="checkForCompatibleChanges">Indicates that the runner should check that no variables are accessed twice during the same cycle</param> public Runner(SubSequence subSequence, bool explain, bool ensureCompilation, bool checkForCompatibleChanges = false) { EventTimeLine = new EventTimeLine(this); SubSequence = subSequence; CompletedSubStep = new HashSet <SubStep>(); EfsSystem.Instance.Runner = this; Explain = explain; CheckForCompatibleChanges = checkForCompatibleChanges; if (ensureCompilation) { // Compile everything EfsSystem.Instance.Compiler.Compile_Synchronous(EfsSystem.Instance.ShouldRebuild); EfsSystem.Instance.ShouldRebuild = false; } Setup(); PleaseWait = true; Expression expression = new Parser().Expression(subSequence.Dictionary, "Kernel.DateAndTime.CurrentTime"); TimeInModel = expression.GetVariable(new InterpretationContext()); Range range = TimeInModel.Type as Range; if (range == null || range.getPrecision() != acceptor.PrecisionEnum.aDoublePrecision) { TimeInModel = null; } }
private void displayType(int indent, Type type) { Structure structureType = type as Structure; if (structureType != null) { foreach (StructureElement element in structureType.Elements) { displayIndent(indent); Type subType = element.Type; Writer.WriteLine(element.Name + " : " + subType.FullName); displayType(indent + 1, subType); } } Range rangeType = type as Range; if (rangeType != null) { displayIndent(indent); Writer.WriteLine("RANGE " + rangeType.MinValueAsDouble + ".." + rangeType.MaxValueAsDouble + " DEFAULT VALUE = " + rangeType.DefaultValue.LiteralName); } Collection collectionType = type as Collection; if (collectionType != null) { displayIndent(indent); Type subType = collectionType.Type; Writer.WriteLine("COLLECTION [" + collectionType.getMaxSize() + "] OF " + subType.FullName); displayType(indent + 1, subType); } }
public void AddHandler(object sender, EventArgs args) { DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange(); range.Name = "<Range" + (GetNodeCount(false) + 1) + ">"; range.MinValue = "0"; range.MaxValue = "1"; AddRange(range); }
/// <summary> /// Constructor /// </summary> /// <param name="item"></param> public RangeValuesTreeNode(DataDictionary.Types.Range item) : base(item, "Special values", true, false) { foreach (DataDictionary.Constants.EnumValue value in item.SpecialValues) { Nodes.Add(new EnumerationValueTreeNode(value)); } SortSubNodes(); }
/// <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> /// Updates the system to setup next cycle /// </summary> private void NextCycle() { if (TimeInModel != null) { // Use the time in the model for checking deadlines Range range = TimeInModel.Type as Range; if (range != null) { Time = range.getValueAsDouble(TimeInModel.Value); } } else { // Increase time if it is not taken into account in the model Time += 0.1; } }
/// <summary> /// Ensures that the length of the section is consistent with EFS's length scale /// </summary> /// <param name="length"></param> /// <returns></returns> private IValue SegmentLength(double length) { IValue retVal = new DoubleValue(EFSSystem.DoubleType, length); NameSpace defaultNameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"); Range LengthType = defaultNameSpace.findTypeByName("Length") as Range; EnumValue infinity = LengthType.findEnumValue("Infinity"); if (!LengthType.Less(retVal, infinity)) { retVal = infinity; } return(retVal); }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="context"></param> /// <param name="actuals">the actual parameters values</param> /// <param name="explain"></param> /// <returns>The value for the function application</returns> public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals, ExplanationPart explain) { IValue retVal = null; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Function function = context.FindOnStack(Function).Value as Function; if (function != null) { double speed = GetDoubleValue(context.FindOnStack(Speed).Value); Parameter parameter = (Parameter)function.FormalParameters[0]; int token2 = context.LocalScope.PushContext(); context.LocalScope.SetGraphParameter(parameter); Graph graph = function.CreateGraph(context, (Parameter)function.FormalParameters[0], explain); context.LocalScope.PopContext(token2); if (graph != null) { double solutionX = graph.SolutionX(speed); if (solutionX == double.MaxValue) { Range distanceType = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance"); retVal = distanceType.findEnumValue("Unknown"); } else { retVal = new DoubleValue(EFSSystem.DoubleType, solutionX); } } else { Function.AddError("Cannot evaluate graph for function while computing the distance for the given speed"); } } else { Function.AddError("Cannot get function for " + Function); } context.LocalScope.PopContext(token); return(retVal); }
/// <summary> /// Constructor /// </summary> /// <param name="item"></param> /// <param name="buildSubNodes"></param> public RangeValuesTreeNode(Range item, bool buildSubNodes) : base(item, buildSubNodes, "Special values", true, false) { }
public static void HandleCellEditStarting(object sender, CellEditEventArgs e) { IVariable variable = e.RowObject as IVariable; if (variable != null) { Enum enumType = variable.Type as Enum; if (enumType != null) { ComboBox control = new ComboBox { Bounds = e.CellBounds, Font = ((ObjectListView)sender).Font, DropDownStyle = ComboBoxStyle.DropDownList, Text = (string)e.Value, DrawMode = DrawMode.OwnerDrawFixed }; foreach (EnumValue enumValue in enumType.Values) { control.Items.Add(enumValue.Name); } control.Items.Add(DefaultConst); control.Text = variable.Value.Name; control.DrawItem += cbb_DrawItem; e.Control = control; } Range rangeType = variable.Type as Range; if (rangeType != null) { ComboBox control = new ComboBox { Bounds = e.CellBounds, Font = ((ObjectListView)sender).Font, DropDownStyle = ComboBoxStyle.DropDown, Text = (string)e.Value, DrawMode = DrawMode.OwnerDrawFixed }; foreach (EnumValue enumValue in rangeType.SpecialValues) { control.Items.Add(enumValue.Name); } control.Items.Add(DefaultConst); control.Text = variable.Value.Name; control.DrawItem += cbb_DrawItem; e.Control = control; } Structure structure = variable.Type as Structure; if (structure != null) { e.Cancel = true; } Collection collection = variable.Type as Collection; if (collection != null) { e.Cancel = true; } } else { e.Cancel = true; } }
/// <summary> /// Adds a new range type /// </summary> /// <param name="range"></param> public void AddRangeType(DataDictionary.Types.Range range) { ranges.AddRange(range); }
/// <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); }
/// <summary> /// Adds a range /// </summary> /// <param name="range"></param> public void AddRange(DataDictionary.Types.Range range) { Item.appendRanges(range); Nodes.Add(new RangeTreeNode(range)); SortSubNodes(); }