public void TestStep() { IActivation step = new StepActivation(); foreach (Tuple <double, double> tup in stepTestCases) { Assert.AreEqual(tup.Item2, step.Calc(tup.Item1), EPSILON); } }
/// <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); } }
/// <summary> /// Update the information stored in the position handler according to the test case /// </summary> protected override void UpdatePositionHandler() { Util.DontNotify(() => { PositionHandler.CleanPositions(); if ((TestCase != null) || SubSequence != null) { double currentTime = 0.0; foreach (Step step in Steps) { if (step.SubSteps.Count > 0) { foreach (SubStep subStep in step.SubSteps) { PositionSubStep(currentTime, subStep); currentTime += 1; } } else { StepActivation stepActivated = new StepActivation(step) { Time = currentTime }; PositionHandler.RegisterEvent(stepActivated); currentTime += 1; } } } else if (Translation != null) { double currentTime = 0.0; if (Translation.SubSteps.Count > 0) { foreach (SubStep subStep in Translation.SubSteps) { PositionSubStep(currentTime, subStep); currentTime += 1; } } } }); base.UpdatePositionHandler(); }
/// <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> /// 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> /// Update the information stored in the position handler according to the test case /// </summary> protected override void UpdatePositionHandler() { Util.DontNotify(() => { PositionHandler.CleanPositions(); if ((TestCase != null) || SubSequence != null) { double currentTime = 0.0; foreach (Step step in Steps) { if (step.SubSteps.Count > 0) { foreach (SubStep subStep in step.SubSteps) { PositionSubStep(currentTime, subStep); currentTime += 1; } } else { StepActivation stepActivated = new StepActivation(step) {Time = currentTime}; PositionHandler.RegisterEvent(stepActivated); currentTime += 1; } } } else if (Translation != null) { double currentTime = 0.0; if (Translation.SubSteps.Count > 0) { foreach (SubStep subStep in Translation.SubSteps) { PositionSubStep(currentTime, subStep); currentTime += 1; } } } }); base.UpdatePositionHandler(); }
/// <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; } }