/// <summary>
        ///     Handles a click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimeLineControl_Click(object sender, EventArgs e)
        {
            ModelEvent evt = GetEventUnderMouse();

            RuleFired ruleFired = evt as RuleFired;

            if (ruleFired != null)
            {
                EfsSystem.Instance.Context.SelectElement(ruleFired.RuleCondition, this,
                                                         Context.SelectionCriteria.LeftClick);
            }

            VariableUpdate variableUpdate = evt as VariableUpdate;

            if (variableUpdate != null)
            {
                EfsSystem.Instance.Context.SelectElement(variableUpdate.Action, this,
                                                         Context.SelectionCriteria.LeftClick);
            }

            Expect expect = evt as Expect;

            if (expect != null)
            {
                EfsSystem.Instance.Context.SelectElement(expect.Expectation, this, Context.SelectionCriteria.LeftClick);
            }

            ModelInterpretationFailure failure = evt as ModelInterpretationFailure;

            if (failure != null)
            {
                EfsSystem.Instance.Context.SelectElement(failure.Instance as IModelElement, this,
                                                         Context.SelectionCriteria.LeftClick);
            }

            SubStepActivated subStepActivated = evt as SubStepActivated;

            if (subStepActivated != null)
            {
                EfsSystem.Instance.Context.SelectElement(subStepActivated.SubStep, this,
                                                         Context.SelectionCriteria.LeftClick);
            }

            StepActivation stepActivation = evt as StepActivation;

            if (stepActivation != null)
            {
                EfsSystem.Instance.Context.SelectElement(stepActivation.Step, this, Context.SelectionCriteria.LeftClick);
            }
        }
Exemple #2
0
        /// <summary>
        ///     Positions a substep in the time line
        /// </summary>
        /// <param name="currentTime"></param>
        /// <param name="subStep"></param>
        /// <returns></returns>
        private void PositionSubStep(double currentTime, SubStep subStep)
        {
            SubStepActivated subStepActivated = new SubStepActivated(subStep, null)
            {
                Time = currentTime
            };

            PositionHandler.RegisterEvent(subStepActivated);
            foreach (Action action in subStep.Actions)
            {
                VariableUpdate variableUpdate = new VariableUpdate(action, action, null);
                PositionHandler.RegisterEvent(variableUpdate);
            }
            foreach (Expectation expectation in subStep.Expectations)
            {
                Expect expect = new Expect(expectation, null);
                PositionHandler.RegisterEvent(expect);
            }
        }
        /// <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.LeftIconImage != null)
                    {
                        pe.Graphics.DrawImage(attributes.LeftIconImage, bounds.Left + 4,
                                              bounds.Top + 4, 20, 20);
                    }

                    if (attributes.RightIconImage != null)
                    {
                        pe.Graphics.DrawImage(attributes.RightIconImage, bounds.Right - 4 - 20,
                                              bounds.Top + 4, 20, 20);
                    }

                    if (attributes.RightIconImage != null && attributes.RightIconModifierImage != null)
                    {
                        pe.Graphics.DrawImage(attributes.RightIconModifierImage, bounds.Right - 4 - 30, bounds.Top + 10, 16, 16);
                    }

                    int shift = 0;
                    foreach (Image image in attributes.TopRightIconImage)
                    {
                        pe.Graphics.DrawImage(image, bounds.Right - 16 + shift, bounds.Top, 16, 16);
                        shift = shift - 16;
                    }
                }
            }
        }
        /// <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);
        }
            /// <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;
                }
            }