/// <summary> /// Initializes a new instance of the <see cref="PIM_AssociationEnd"/> class. /// </summary> /// <param name="xCaseCanvas">canvas where the control is placed</param> /// <param name="viewHelper">ViewHelper of the control, stores visualization information.</param> /// <param name="associationEnd">reprsented association end.</param> public PIM_AssociationEnd(XCaseCanvas xCaseCanvas, AssociationEndViewHelper viewHelper, AssociationEnd associationEnd) : base(xCaseCanvas) { PositionChanged += AdjustLabelsPositions; AssociationEnd = associationEnd; ViewHelper = viewHelper; if (multiplicityLabel != null) { multiplicityLabel.ViewHelper = ViewHelper.MultiplicityLabelViewHelper; } }
/// <summary> /// Creates visualization for an association end. /// </summary> /// <param name="preferedPosition">The prefered position of the created point.</param> /// <param name="viewHelper">association end's view helper.</param> /// <param name="associationEnd">model association end.</param> /// <returns>new control representing association end</returns> public PIM_AssociationEnd CreateAssociationEnd(Point preferedPosition, AssociationEndViewHelper viewHelper, AssociationEnd associationEnd) { PIM_AssociationEnd xend = new PIM_AssociationEnd(XCaseCanvas, viewHelper, associationEnd) { OwnerControl = this, Placement = EPlacementKind.ParentAutoPos, ParentControl = this }; ((Canvas)connectorDecorator.Template.FindName("ConnectorDecoratorGrid", connectorDecorator)).Children.Add(xend); xend.Visibility = Visibility.Visible; xend.SetPreferedPosition(preferedPosition); createdJunctionEnds.Add(xend); return(xend); }
/// <summary> /// News the connection. /// </summary> /// <param name="sourceElement">source element</param> /// <param name="sourceViewHelper">view helper for the association end that is related to <paramref name="sourceElement"/>, /// can be set to null if <paramref name="sourceElement"/> has not an association end for this connection.</param> /// <param name="targetElement">target element</param> /// <param name="targetViewHelper">view helper for the association end that is related to <paramref name="targetElement"/>, /// can be set to null if <paramref name="targetElement"/> has not an association end for this connection.</param> /// <param name="points">collection of points for the junction (usually part of some ViewHelper), the junction reflects /// all changes in the collection</param> public void NewConnection( IConnectable sourceElement, AssociationEndViewHelper sourceViewHelper, IConnectable targetElement, AssociationEndViewHelper targetViewHelper, ObservablePointCollection points) { foreach (JunctionPoint point in Points) { point.DeleteFromCanvas(); } Points.Clear(); if (points == null) { throw new ArgumentNullException("points"); } if (points.Count < 2) { throw new ArgumentException("There must be at last two points to set a connection.", "points"); } SourceElement = (Control)sourceElement; TargetElement = (Control)targetElement; JunctionPoint startPoint; if (sourceViewHelper != null) { startPoint = ((ICreatesAssociationEnd)sourceElement).CreateAssociationEnd(points.First(), sourceViewHelper, sourceViewHelper.AssociationEnd); ((PIM_AssociationEnd)startPoint).Association = Association; } else { startPoint = (sourceElement).CreateJunctionEnd(points.First()); } startPoint.ContextMenu = null; startPoint.Junction = this; startPoint.OrderInJunction = 0; Points.Add(startPoint); JunctionPoint endPoint; if (targetViewHelper != null) { endPoint = ((ICreatesAssociationEnd)targetElement).CreateAssociationEnd(points.Last(), targetViewHelper, targetViewHelper.AssociationEnd); ((PIM_AssociationEnd)endPoint).Association = Association; } else { endPoint = targetElement.CreateJunctionEnd(points.Last()); } endPoint.ContextMenu = null; endPoint.Junction = this; endPoint.OrderInJunction = 1; Points.Add(endPoint); if (startPoint is PIM_AssociationEnd) { ((PIM_AssociationEnd)startPoint).StartBindings(); } if (endPoint is PIM_AssociationEnd) { ((PIM_AssociationEnd)endPoint).StartBindings(); } int zindex = Math.Min(Panel.GetZIndex(SourceElement), Panel.GetZIndex(TargetElement)); zindex--; Canvas.SetZIndex(this, zindex - 1); UpdateLayout(); for (int i = 1; i < points.Count - 1; i++) { Point point = points[i]; BreakLine(point, i); } SourceElement.SizeChanged += SourceElement_SizeChanged; TargetElement.SizeChanged += TargetElement_SizeChanged; AutoPosModeOnly = AutoPosModeOnly; InvalidateGeometry(); }