Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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>",
                -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;
        }