/// <summary>
 /// Adds a new event in the list of events
 /// </summary>
 /// <param name="modelEvent"></param>
 public void AddModelEvent(ModelEvent modelEvent)
 {
     modelEvent.Time     = CurrentTime;
     modelEvent.TimeLine = this;
     modelEvents.Add(modelEvent);
     modelEvent.Apply();
 }
Example #2
0
 /// <summary>
 ///     Adds a new event in the list of events
 /// </summary>
 /// <param name="modelEvent"></param>
 /// <param name="apply">indicates whether the event should be applied on the model</param>
 public void AddModelEvent(ModelEvent modelEvent, bool apply)
 {
     modelEvent.Time     = CurrentTime;
     modelEvent.TimeLine = this;
     Events.Add(modelEvent);
     Changed = true;
     if (apply)
     {
         modelEvent.Apply(Runner);
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="modelEvent"></param>
        public EventControl(TimeLineControl controller, ModelEvent modelEvent)
        {
            Parent = controller;
            ModelEvent = modelEvent;
            Size = SIZE;
            Font = new System.Drawing.Font(FontFamily.GenericMonospace, 5);
            SetColor();
            SetText();

            Click += new EventHandler(EventControl_Click);
        }
Example #4
0
        /// <summary>
        ///     Indicates whether we need to keep this event during garbage collection
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        private bool KeepEvent(ModelEvent evt)
        {
            bool retVal = evt is Expect ||
                          evt is ModelInterpretationFailure ||
                          evt is SubStepActivated;

            VariableUpdate update = evt as VariableUpdate;

            if (update != null)
            {
                retVal = EnclosingFinder <NameSpace> .find(update.Action) == null;
            }

            return(retVal);
        }
Example #5
0
        /// <summary>
        ///     Steps one step backward
        /// </summary>
        public void StepBack()
        {
            Changed = true;
            while (Events.Count > 0)
            {
                ModelEvent evt = Events.Last();
                if (evt.Time < CurrentTime)
                {
                    CurrentTime = evt.Time;
                    break;
                }

                evt.RollBack(Runner);
                Events.Remove(evt);
            }

            if (Events.Count == 0)
            {
                CurrentTime = 0.0;
            }
        }
        /// <summary>
        /// Steps one step backward
        /// </summary>
        /// <param name="time">the time to step back</param>
        public void StepBack(double time)
        {
            currentTime = currentTime - time;
            if (currentTime < 0)
            {
                currentTime = 0;
            }

            while (Events.Count > 0)
            {
                ModelEvent evt = Events.Last();
                if (evt.Time < currentTime)
                {
                    break;
                }
                else
                {
                    evt.RollBack();
                    Events.Remove(evt);
                }
            }
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="timeLineControl"></param>
 /// <param name="modelEvent"></param>
 public DeleteMenuItem(StaticTimeLineControl timeLineControl, ModelEvent modelEvent)
     : base(timeLineControl, modelEvent, "Delete")
 {
     Enabled = modelEvent != null;
 }
 /// <summary>
 ///     Adds a new event in the list of events
 /// </summary>
 /// <param name="modelEvent"></param>
 /// <param name="runner"></param>
 /// <param name="apply">indicates whether the event should be applied on the model</param>
 public void AddModelEvent(ModelEvent modelEvent, Runner runner, bool apply)
 {
     modelEvent.Time = CurrentTime;
     modelEvent.TimeLine = this;
     Events.Add(modelEvent);
     Changed = true;
     if (apply)
     {
         modelEvent.Apply(runner);
     }
 }
 /// <summary>
 /// Indicates whether the time line holds the specific model event
 /// </summary>
 /// <param name="modelEvent"></param>
 /// <returns></returns>
 public bool Contains(ModelEvent modelEvent)
 {
     return Events.Contains(modelEvent);
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="timeLineControl"></param>
 /// <param name="modelEvent"></param>
 public AddChangeMenuItem(StaticTimeLineControl timeLineControl, ModelEvent modelEvent)
     : base(timeLineControl, modelEvent, "Add change")
 {
     Enabled = SubStep != null;
 }
            /// <summary>
            ///     Registers an event according to its column
            /// </summary>
            /// <param name="evt"></param>
            public void RegisterEvent(ModelEvent evt)
            {
                SubStepActivated currentSubStepActivation = evt as SubStepActivated;
                if (evt.Time > LastActivationTime || currentSubStepActivation != null)
                {
                    LastActivationTime = evt.Time;
                    AllocatedPositions.Add(new List<ModelEvent>());
                    NextY = 0;

                    if (LastSubStepActivation != null)
                    {
                        if (currentSubStepActivation == null)
                        {
                            AllocatedPositions[AllocatedPositions.Count - 1].Add(LastSubStepActivation);
                        }
                    }
                }

                List<ModelEvent> events = AllocatedPositions[AllocatedPositions.Count - 1];
                if (!events.Contains(evt))
                {
                    if (currentSubStepActivation != null)
                    {
                        if (currentSubStepActivation.SubStep.Step != null)
                        {
                            if (LastSubStepActivation != null &&
                                LastSubStepActivation.SubStep.Step == currentSubStepActivation.SubStep.Step)
                            {
                                // Extends the step size
                                Rectangle lastRectangle = EventPositions[LastStepActivation];
                                lastRectangle.Width = lastRectangle.Width + _eventMarging.Width + _stepSize.Width;
                                EventPositions[LastStepActivation] = lastRectangle;
                            }
                            else
                            {
                                // Create a new step activation
                                LastStepActivation = new StepActivation(currentSubStepActivation.SubStep.Step);
                                Point location =
                                    new Point((AllocatedPositions.Count - 1)*(_stepSize.Width + _eventMarging.Width),
                                        NextY);
                                events.Add(LastStepActivation);
                                EventPositions.Add(LastStepActivation, new Rectangle(location, _stepSize));
                            }
                            NextY += _stepSize.Height;
                        }

                        // Setup the substep activation size
                        if (LastSubStepActivation != null &&
                            LastSubStepActivation.SubStep.Step == currentSubStepActivation.SubStep.Step)
                        {
                            // Increase the previous sub step activation size as it belongs to the same step
                            // This is used to remove gaps between substeps of the same step
                            Rectangle lastRectangle = EventPositions[LastSubStepActivation];
                            lastRectangle.Width = lastRectangle.Width + (_eventMarging.Width + 1)/2;
                            EventPositions[LastSubStepActivation] = lastRectangle;

                            events.Add(evt);
                            Point location =
                                new Point(
                                    (AllocatedPositions.Count - 1)*(_eventSize.Width + _eventMarging.Width) -
                                    (_eventMarging.Width/2), NextY);
                            EventPositions.Add(evt,
                                new Rectangle(location,
                                    new Size(_substepSize.Width + _eventMarging.Width/2, _substepSize.Height)));
                        }
                        else
                        {
                            events.Add(evt);
                            Point location =
                                new Point((AllocatedPositions.Count - 1)*(_substepSize.Width + _eventMarging.Width),
                                    NextY);
                            EventPositions.Add(evt, new Rectangle(location, _substepSize));
                        }
                        NextY += _substepSize.Height + _eventMarging.Height;
                    }
                    else
                    {
                        // Create the sub step activation
                        {
                            events.Add(evt);
                            Point location =
                                new Point((AllocatedPositions.Count - 1)*(_eventSize.Width + _eventMarging.Width), NextY);
                            EventPositions.Add(evt, new Rectangle(location, _eventSize));
                            NextY += _eventSize.Height + _eventMarging.Height;
                        }
                    }
                }
                else
                {
                    if (evt == LastSubStepActivation)
                    {
                        // Extent the sub step activation
                        Rectangle lastRectangle = EventPositions[evt];
                        lastRectangle.Width = lastRectangle.Width + _eventSize.Width + _eventMarging.Width;
                        EventPositions[evt] = lastRectangle;
                    }
                }

                if (evt is SubStepActivated)
                {
                    LastSubStepActivation = evt as SubStepActivated;
                }
            }
        /// <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>",
                -1, -1, -1);

            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,
                                QuestionMarkImageIndex, GetImageIndex(expect.Expectation), -1);
                            break;
                        case Expect.EventState.Fullfilled:
                            retVal = new EventDisplayAttributes(Color.LightGreen, new Pen(Color.Green), name,
                                SuccessImageIndex, GetImageIndex(expect.Expectation), -1);
                            break;
                        case Expect.EventState.TimeOut:
                            retVal = new EventDisplayAttributes(Color.Red, new Pen(Color.DarkRed), name, ErrorImageIndex,
                                GetImageIndex(expect.Expectation), -1);
                            break;
                    }

                    if (expect.Expectation.getKind() == acceptor.ExpectationKind.aContinuous)
                    {
                        retVal.TopRightIconImageIndex.Add(CircularArrowIndex);
                    }
                    if (expect.Expectation.Blocking)
                    {
                        retVal.TopRightIconImageIndex.Add(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, ErrorImageIndex,
                        GetImageIndex(modelInterpretationFailure.Instance as ModelElement), -1);
                }

                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, -1,
                        GetImageIndex(ruleFired.RuleCondition), ToolsImageIndex);
                }

                VariableUpdate variableUpdate = evt as VariableUpdate;
                if (variableUpdate != null)
                {
                    string name = variableUpdate.Action.ExpressionText;
                    int rightIcon = -1;
                    int rightModifier = -1;
                    if (variableUpdate.Action.Statement != null)
                    {
                        name = variableUpdate.Action.Statement.ShortShortDescription();
                        rightIcon = GetImageIndex(variableUpdate.Action.Statement.AffectedElement());

                        switch (variableUpdate.Action.Statement.UsageDescription())
                        {
                            case Statement.ModeEnum.Call:
                                rightModifier = CallImageIndex;
                                break;
                            case Statement.ModeEnum.In:
                                rightModifier = InImageIndex;
                                break;

                            case Statement.ModeEnum.InOut:
                                rightModifier = InOutImageIndex;
                                break;

                            case Statement.ModeEnum.Internal:
                                rightModifier = InternalImageIndex;
                                break;

                            case Statement.ModeEnum.Out:
                                rightModifier = 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, -1, rightIcon,
                            rightModifier);
                    }
                    else
                    {
                        retVal = new EventDisplayAttributes(Color.BlanchedAlmond, new Pen(Color.Black), name, -1,
                            rightIcon, rightModifier);
                    }
                }

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

            return retVal;
        }
        /// <summary>
        ///     Draws a single event
        /// </summary>
        /// <param name="pe"></param>
        /// <param name="evt"></param>
        /// <param name="bounds">The location where the event should be displayed</param>
        private void DrawEvent(PaintEventArgs pe, ModelEvent evt, Rectangle bounds)
        {
            Rectangle displayRectangle = pe.ClipRectangle;
            if (!displayRectangle.IntersectsWith(bounds))
            {
                return;
            }

            EventDisplayAttributes attributes = GetDisplayAttributes(evt);
            const int cornerRadius = 5;

            StepActivation stepActivation = evt as StepActivation;
            if (stepActivation != null)
            {
                string name = GuiUtils.AdjustForDisplay(stepActivation.Step.Name, bounds.Width - 4, TopFont);
                pe.Graphics.FillRectangle(StepBoxPen, bounds);
                pe.Graphics.DrawString(
                    name,
                    TopFont,
                    new SolidBrush(StepBoxColor),
                    new Rectangle(new Point(bounds.Left + 2, bounds.Top + 2),
                        new Size(bounds.Width - 4, Bounds.Height - 4)));
                pe.Graphics.DrawLine(new Pen(StepBoxColor), bounds.Left, bounds.Bottom - 1, bounds.Right - 1,
                    bounds.Bottom - 1);
            }
            else
            {
                SubStepActivated subStepActivation = evt as SubStepActivated;
                if (subStepActivation != null)
                {
                    pe.Graphics.FillRectangle(new SolidBrush(attributes.FillColor), bounds);
                    if (subStepActivation.SubStep.EnclosingCollection != null)
                    {
                        int index = subStepActivation.SubStep.EnclosingCollection.IndexOf(subStepActivation.SubStep) + 1;
                        if (index == 1)
                        {
                            pe.Graphics.DrawString("Substep", BottomFont, new SolidBrush(attributes.DrawPen.Color),
                                new Point(bounds.Left + 2, bounds.Top + 2));
                        }
                        pe.Graphics.DrawString("" + index, BottomFont, new SolidBrush(attributes.DrawPen.Color),
                            new Point(bounds.Left + bounds.Width/2, bounds.Bottom - 2 - BottomFont.Height));
                    }
                }
                else
                {
                    int strokeOffset = Convert.ToInt32(Math.Ceiling(attributes.DrawPen.Width));
                    bounds = Rectangle.Inflate(bounds, -strokeOffset, -strokeOffset);

                    attributes.DrawPen.EndCap = attributes.DrawPen.StartCap = LineCap.Round;

                    GraphicsPath gfxPath = new GraphicsPath();
                    gfxPath.AddArc(bounds.X, bounds.Y, cornerRadius, cornerRadius, 180, 90);
                    gfxPath.AddArc(bounds.X + bounds.Width - cornerRadius, bounds.Y, cornerRadius, cornerRadius, 270, 90);
                    gfxPath.AddArc(bounds.X + bounds.Width - cornerRadius, bounds.Y + bounds.Height - cornerRadius,
                        cornerRadius, cornerRadius, 0, 90);
                    gfxPath.AddArc(bounds.X, bounds.Y + bounds.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90);
                    gfxPath.CloseAllFigures();

                    pe.Graphics.FillPath(new SolidBrush(attributes.FillColor), gfxPath);
                    pe.Graphics.DrawPath(attributes.DrawPen, gfxPath);

                    pe.Graphics.DrawString(attributes.BottomText, BottomFont, new SolidBrush(attributes.DrawPen.Color),
                        new Point(bounds.Left + 2, bounds.Bottom - 2 - BottomFont.Height));

                    if (attributes.LeftIconImageIndex >= 0)
                    {
                        pe.Graphics.DrawImage(Images.Images[attributes.LeftIconImageIndex], bounds.Left + 4,
                            bounds.Top + 4, 20, 20);
                    }

                    if (attributes.RightIconImageIndex >= 0)
                    {
                        pe.Graphics.DrawImage(Images.Images[attributes.RightIconImageIndex], bounds.Right - 4 - 20,
                            bounds.Top + 4, 20, 20);
                    }

                    if (attributes.RightIconImageIndex >= 0 && attributes.RightIconModifierImageIndex >= 0)
                    {
                        pe.Graphics.DrawImage(Images.Images[attributes.RightIconModifierImageIndex],
                            bounds.Right - 4 - 30, bounds.Top + 10, 16, 16);
                    }

                    int shift = 0;
                    foreach (int index in attributes.TopRightIconImageIndex)
                    {
                        pe.Graphics.DrawImage(Images.Images[index], bounds.Right - 16 + shift, bounds.Top, 16, 16);
                        shift = shift - 16;
                    }
                }
            }
        }
        /// <summary>
        /// The top position of the button
        /// </summary>
        private int EventTop(ModelEvent modelEvent)
        {
            int retVal = 0;

            if (!EventsAtTime.ContainsKey(modelEvent.Time))
            {
                EventsAtTime[modelEvent.Time] = 0;
            }

            int eventCount = EventsAtTime[modelEvent.Time];

            retVal = TIMELINE_HEIGHT + (3 * MARGIN_OFFSET) / 2 + eventCount * (EventControl.SIZE.Height);

            return retVal;
        }
        /// <summary>
        /// The right position of the button
        /// </summary>
        /// <param name="modelEvent"></param>
        /// <returns></returns>
        private int EventLeft(ModelEvent modelEvent)
        {
            int retVal = 0;

            retVal = LEGEND_WIDTH + (3 * MARGIN_OFFSET) / 2 + 1 + (int)Math.Round(modelEvent.Time / Runner.Step) * (EventControl.SIZE.Width + BUTTON_MARGIN_SIZE) - HorizontalScroll.Value;

            return retVal;
        }
        /// <summary>
        ///     Indicates whether we need to keep this event during garbage collection
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        private bool KeepEvent(ModelEvent evt)
        {
            bool retVal = evt is Expect
                          || evt is ModelInterpretationFailure
                          || evt is SubStepActivated;

            VariableUpdate update = evt as VariableUpdate;
            if (update != null)
            {
                retVal = EnclosingFinder<NameSpace>.find(update.Action) == null;
            }

            return retVal;
        }
 /// <summary>
 /// Adds a new event in the list of events
 /// </summary>
 /// <param name="modelEvent"></param>
 public void AddModelEvent(ModelEvent modelEvent)
 {
     modelEvent.Time = CurrentTime;
     modelEvent.TimeLine = this;
     modelEvents.Add(modelEvent);
     modelEvent.Apply();
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="timeLineControl"></param>
 /// <param name="modelEvent"></param>
 public AddExpectationMenuItem(StaticTimeLineControl timeLineControl, ModelEvent modelEvent)
     : base(timeLineControl, modelEvent, "Add expectation")
 {
     Enabled = SubStep != null;
 }
        /// <summary>
        ///     Indicates that an event should be shown
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public bool VisibleEvent(ModelEvent evt)
        {
            bool retVal = true;

            // Check event type
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            retVal = retVal && (!(evt is Expect) || Expect);
            retVal = retVal && (!(evt is RuleFired) || RuleFired);

            // Ignore the following internal events
            retVal = retVal && (!(evt is ExpectationStateChange));
            retVal = retVal && (!(evt is SubStepActivated));

            if (retVal)
            {
                // Checks the variable update
                VariableUpdate variableUpdate = evt as VariableUpdate;
                if (variableUpdate != null)
                {
                    if (VariableUpdate)
                    {
                        // Do not filter out variables updates for which the rule is not available
                        // because these updates are related to test steps or external input (using EFS service)
                        if (variableUpdate.Action.RuleCondition != null)
                        {
                            retVal = false;
                            foreach (Variable variable in Variables)
                            {
                                retVal = variableUpdate.Changes.ImpactVariable(variable);
                                if (retVal)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        retVal = false;
                    }
                }
                else
                {
                    // Check event namespace
                    if (evt.NameSpace != null)
                    {
                        retVal = NameSpaces.Contains(evt.NameSpace);
                    }
                }
            }

            // Keep messages that match the regular expression
            if (!Util.isEmpty(RegExp))
            {
                Regex regularExpression = new Regex(RegExp);
                retVal = retVal || regularExpression.IsMatch(evt.Message);
            }

            return retVal;
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="timeLineControl"></param>
 /// <param name="modelEvent"></param>
 public AddStepMenuItem(StaticTimeLineControl timeLineControl, ModelEvent modelEvent)
     : base(timeLineControl, modelEvent, "Add step")
 {
     Enabled = GetTestCase() != null;
 }
 /// <summary>
 /// Indicates whether the time line holds the specific model event
 /// </summary>
 /// <param name="modelEvent"></param>
 /// <returns></returns>
 public bool Contains(ModelEvent modelEvent)
 {
     return(Events.Contains(modelEvent));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="timeLineControl"></param>
 /// <param name="modelEvent"></param>
 public AddSubStepMenuItem(StaticTimeLineControl timeLineControl, ModelEvent modelEvent)
     : base(timeLineControl, modelEvent, "Add substep")
 {
     Enabled = Step != null || TimeLineControl.Translation != null;
 }
        /// <summary>
        /// Indicates that an event should be shown
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public bool VisibleEvent(ModelEvent evt)
        {
            bool retVal = true;

            // Check event type
            retVal = retVal && (!(evt is Expect) || Expect);
            retVal = retVal && (!(evt is RuleFired) || RuleFired);
            retVal = retVal && (!(evt is VariableUpdate) || VariableUpdate);

            // Check event namespace
            if (retVal)
            {
                if (evt.NameSpace != null)
                {
                    retVal = NameSpaces.Contains(evt.NameSpace);
                }
            }

            // Keep messages that match the regular expression
            if (!Utils.Utils.isEmpty(RegExp))
            {
                Regex regularExpression = new Regex(RegExp);
                retVal = retVal || regularExpression.IsMatch(evt.Message);
            }

            // Ignore those internal events
            retVal = retVal && (!(evt is ExpectationStateChange));
            retVal = retVal && (!(evt is SubStepActivated));

            return retVal;
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="timeLineControl"></param>
 /// <param name="modelEvent"></param>
 /// <param name="caption"></param>
 protected BaseToolStripButton(StaticTimeLineControl timeLineControl, ModelEvent modelEvent, string caption)
     : base(caption)
 {
     TimeLineControl = timeLineControl;
     Selected = modelEvent;
 }