Exemplo n.º 1
0
        /// <summary>
        /// Changes the <see cref="TargetElement"/> from current target element to
        /// <paramref name="targetElement"/>
        /// </summary>
        /// <param name="targetElement">new target element.</param>
        internal void ReconnectTargetElement(IConnectable targetElement)
        {
            if (targetElement == TargetElement)
            {
                return;
            }
            if (Points.Count < 2 /*|| EndPoint.Parent == null*/)
            {
                return;
            }
            if (TargetElement != null)
            {
                TargetElement.SizeChanged -= TargetElement_SizeChanged;
                ((IConnectable)TargetElement).UnHighlight();
                TargetElement = null;
            }

            Points.RemoveAt(Points.Count - 1);
            TargetElement = (Control)targetElement;
            ((IConnectable)TargetElement).Highlight();
            JunctionPoint endPoint = targetElement.CreateJunctionEnd();

            endPoint.Junction        = this;
            endPoint.OrderInJunction = 1;
            endPoint.ContextMenu     = null;
            Points.Add(endPoint);
            //TargetElement.SizeChanged += TargetElement_SizeChanged;
            Cursor = Cursors.Hand;
            InvalidateGeometry();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws junction between <paramref name="c1"/> and <paramref name="endPoint"/>. This method is supposed
        /// to be used when connection is dragged between two elements (one of them is <paramref name="c1"/>)
        /// and <paramref name="endPoint"/> is being dragged "on the way" to the second element.
        /// </summary>
        /// <param name="c1">connected element</param>
        /// <param name="endPoint">dragged point</param>
        /// <param name="canvas">canvas where the junction is created</param>
        internal void DragConnection(IConnectable c1, JunctionPoint endPoint, XCaseCanvas canvas)
        {
            SourceElement = c1 as Control;

            JunctionPoint startPoint = c1.CreateJunctionEnd();

            startPoint.Junction        = this;
            startPoint.OrderInJunction = 0;
            endPoint.Junction          = this;
            endPoint.OrderInJunction   = 1;
            Points.Add(startPoint);
            Points.Add(endPoint);
            TargetElement = null;
        }
Exemplo n.º 3
0
        /// <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();
        }