void Connector_ConnectorPointMoved(ConnectorPoint point)
 {
     if (ViewHelper.Points.Count > point.OrderInConnector)
     {
         ViewHelper.Points[point.OrderInConnector].SetPosition(point.Position);
     }
 }
        protected override Geometry GetOrCreateConnectorGeometry(Size renderSize)
        {
            var ellipse = Ellipse.CreateFromSize(renderSize);

            this.SetCurrentValue(EllipseProperty, ellipse);
            if (ellipse.IsZero)
            {
                return(Geometry.Empty);
            }

            var direction   = this.ConnectorOffset;
            var ip          = ellipse.PointOnCircumference(direction);
            var vertexPoint = ip + this.ConnectorOffset;
            var ray         = new Ray(vertexPoint, this.ConnectorOffset.Negated());

            var p1 = ConnectorPoint.Find(ray, this.ConnectorAngle / 2, this.StrokeThickness, ellipse);
            var p2 = ConnectorPoint.Find(ray, -this.ConnectorAngle / 2, this.StrokeThickness, ellipse);

            this.SetCurrentValue(ConnectorVertexPointProperty, vertexPoint);
            this.SetCurrentValue(ConnectorPoint1Property, p1);
            this.SetCurrentValue(ConnectorPoint2Property, p2);
            if (this.ConnectorGeometry is PathGeometry)
            {
                return(this.ConnectorGeometry);
            }

            var figure = this.CreatePathFigureStartingAt(ConnectorPoint1Property);

            figure.Segments.Add(this.CreateLineSegmentTo(ConnectorVertexPointProperty));
            figure.Segments.Add(this.CreateLineSegmentTo(ConnectorPoint2Property));
            var geometry = new PathGeometry();

            geometry.Figures.Add(figure);
            return(geometry);
        }
Exemple #3
0
        internal void InvokeConnectorPointMoved(ConnectorPoint point)
        {
            ConnectorPointEventHandler handler = ConnectorPointMoved;

            if (handler != null)
            {
                handler(point);
            }
        }
Exemple #4
0
 public void StraightenLineAtPoint(ConnectorPoint connectorPoint)
 {
     this.Points.Remove(connectorPoint);
     foreach (ConnectorPoint cp in Points)
     {
         if (cp.OrderInConnector > connectorPoint.OrderInConnector)
         {
             cp.OrderInConnector--;
         }
     }
     ExolutioCanvas.Children.Remove(connectorPoint);
     InvokePointsCountChanged();
     this.InvalidateGeometry();
 }
        protected override Geometry GetOrCreateConnectorGeometry(Size renderSize)
        {
            var rectangle = new Rect(new Point(0, 0), renderSize);

            if (rectangle.Width <= 0 || rectangle.Height <= 0)
            {
                return(Geometry.Empty);
            }

            var fromCenter = new Ray(rectangle.CenterPoint(), this.ConnectorOffset);
            var ip         = fromCenter.FirstIntersectionWith(rectangle);

            if (ip == null)
            {
                Debug.Assert(false, $"Line {fromCenter} does not intersect rectangle {rectangle}");
                // ReSharper disable once HeuristicUnreachableCode
                return(Geometry.Empty);
            }

            var cr          = this.AdjustedCornerRadius();
            var vertexPoint = ip.Value + this.ConnectorOffset;
            var toCenter    = new Ray(vertexPoint, this.ConnectorOffset.Negated());
            var p1          = ConnectorPoint.Find(toCenter, this.ConnectorAngle / 2, this.StrokeThickness, rectangle, cr);
            var p2          = ConnectorPoint.Find(toCenter, -this.ConnectorAngle / 2, this.StrokeThickness, rectangle, cr);

            this.SetValue(ConnectorVertexPointProperty, vertexPoint);
            this.SetValue(ConnectorPoint1Property, p1);
            this.SetValue(ConnectorPoint2Property, p2);
            if (this.ConnectorGeometry is PathGeometry)
            {
                return(this.ConnectorGeometry);
            }

            var figure = this.CreatePathFigureStartingAt(ConnectorPoint1Property);

            figure.Segments.Add(this.CreateLineSegmentTo(ConnectorVertexPointProperty));
            figure.Segments.Add(this.CreateLineSegmentTo(ConnectorPoint2Property));
            var geometry = new PathGeometry();

            geometry.Figures.Add(figure);
            return(geometry);
        }
Exemple #6
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // recycle connectors to avoid having rebinding the model
            var connectorPoints = new List <ConnectorPoint>(_connector.ConnectorPoints);

            if (connectorPoints.Count > _edgePoints.Count)
            {
                var diff = _connector.ConnectorPoints.Count - _edgePoints.Count;
                for (var i = 0; i < diff; i++)
                {
                    var lastIdx = connectorPoints.Count - 1;
                    var cp      = connectorPoints[lastIdx];
                    DeleteEFElementCommand.DeleteInTransaction(cpc, cp);
                    connectorPoints.RemoveAt(lastIdx);
                }
            }
            else if (connectorPoints.Count < _edgePoints.Count)
            {
                var diff = _edgePoints.Count - connectorPoints.Count;
                for (var i = 0; i < diff; i++)
                {
                    var cp = new ConnectorPoint(_connector, null);
                    _connector.AddConnectorPoint(cp);
                    XmlModelHelper.NormalizeAndResolve(cp);
                    connectorPoints.Add(cp);
                }
            }

            Debug.Assert(connectorPoints.Count == _edgePoints.Count, "ConnectorPoints.Count != edgePoints.Count");

            // be safe if the assert above fires, only go through min indices
            var min = Math.Min(_edgePoints.Count, connectorPoints.Count);

            for (var i = 0; i < min; i++)
            {
                var edgePoint      = _edgePoints[i];
                var connectorPoint = connectorPoints[i];
                connectorPoint.PointX.Value = edgePoint.Key;
                connectorPoint.PointY.Value = edgePoint.Value;
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // recycle connectors to avoid having rebinding the model
            var connectorPoints = new List<ConnectorPoint>(_connector.ConnectorPoints);
            if (connectorPoints.Count > _edgePoints.Count)
            {
                var diff = _connector.ConnectorPoints.Count - _edgePoints.Count;
                for (var i = 0; i < diff; i++)
                {
                    var lastIdx = connectorPoints.Count - 1;
                    var cp = connectorPoints[lastIdx];
                    DeleteEFElementCommand.DeleteInTransaction(cpc, cp);
                    connectorPoints.RemoveAt(lastIdx);
                }
            }
            else if (connectorPoints.Count < _edgePoints.Count)
            {
                var diff = _edgePoints.Count - connectorPoints.Count;
                for (var i = 0; i < diff; i++)
                {
                    var cp = new ConnectorPoint(_connector, null);
                    _connector.AddConnectorPoint(cp);
                    XmlModelHelper.NormalizeAndResolve(cp);
                    connectorPoints.Add(cp);
                }
            }

            Debug.Assert(connectorPoints.Count == _edgePoints.Count, "ConnectorPoints.Count != edgePoints.Count");

            // be safe if the assert above fires, only go through min indices
            var min = Math.Min(_edgePoints.Count, connectorPoints.Count);
            for (var i = 0; i < min; i++)
            {
                var edgePoint = _edgePoints[i];
                var connectorPoint = connectorPoints[i];
                connectorPoint.PointX.Value = edgePoint.Key;
                connectorPoint.PointY.Value = edgePoint.Value;
            }
        }
Exemple #8
0
        public ConnectorPoint BreakAtPoint(Point point, int?brokenSegment = null)
        {
            if (brokenSegment == null)
            {
                brokenSegment = GeometryHelper.FindHitSegmentIndex(point, this.Points);
            }
            ConnectorPoint connectorPoint = new ConnectorPoint(ExolutioCanvas);

            connectorPoint.OrderInConnector = brokenSegment.Value + 1;
            connectorPoint.Placement        = EPlacementKind.AbsoluteCanvas;
            connectorPoint.Connector        = this;
            ExolutioCanvas.Children.Add(connectorPoint);
            connectorPoint.SetPreferedPosition(point);
            ExolutioContextMenu exolutioContextMenu = new ExolutioContextMenu();
            ContextMenuItem     cStraighten         = new ContextMenuItem("Straighten line here");

            cStraighten.Tag    = connectorPoint;
            cStraighten.Click += delegate(object sender, RoutedEventArgs e)
            {
                ConnectorPoint clickedPoint = (ConnectorPoint)((ContextMenuItem)sender).Tag;
                StraightenLineAtPoint(clickedPoint);
            };
            exolutioContextMenu.Items.Add(cStraighten);
            connectorPoint.ContextMenu = exolutioContextMenu;

            foreach (ConnectorPoint cp in Points)
            {
                if (cp.OrderInConnector >= connectorPoint.OrderInConnector)
                {
                    cp.OrderInConnector++;
                }
            }
            this.Points.Insert(connectorPoint.OrderInConnector, connectorPoint);
            InvokePointsCountChanged();
            this.InvalidateGeometry();
            return(connectorPoint);
        }
Exemple #9
0
        public static bool AreInBadPosition(Rect r1, Rect r2, ConnectorPoint point1, ConnectorPoint point2)
        {
            bool onBottom = false, onTop = false, onLeft = false, onRight = false;
            bool badPosBottom = false, badPosTop = false, badPosLeft = false, badPosRight = false;

            if (point1.X == r1.Left)
            {
                onLeft = true;
            }
            if (point1.X == r1.Right)
            {
                onRight = true;
            }
            if (point1.Y == r1.Top)
            {
                onTop = true;
            }
            if (point1.Y == r1.Bottom)
            {
                onBottom = true;
            }

            bool result = false;

            if (onBottom && point1.Y > point2.Y)
            {
                badPosBottom = true;
            }

            if (onTop && point1.Y < point2.Y)
            {
                badPosTop = true;
            }

            if (onRight && point1.X > point2.X)
            {
                badPosRight = true;
            }

            if (onLeft && point1.X < point2.X)
            {
                badPosLeft = true;
            }

            if (badPosBottom)
            {
                if (!((!badPosLeft && onLeft) || (!badPosRight && onRight)))
                {
                    result = true;
                }
            }

            if (badPosLeft)
            {
                if (!((!badPosTop && onTop) || (!badPosBottom && onBottom)))
                {
                    result = true;
                }
            }

            if (badPosRight)
            {
                if (!((!badPosTop && onTop) || (!badPosBottom && onBottom)))
                {
                    result = true;
                }
            }

            if (badPosTop)
            {
                if (!((!badPosLeft && onLeft) || (!badPosRight && onRight)))
                {
                    result = true;
                }
            }

            return(result);
        }
Exemple #10
0
        public void AdjustDrag(ref DragDeltaEventArgs deltaEventArgs)
        {
            if (ParentControl != null)
            {
                #region disconnecting points

                Rect bounds = ParentControl.GetBounds();

                Point p = new Point(CanvasPosition.X + deltaEventArgs.HorizontalChange,
                                    CanvasPosition.Y + deltaEventArgs.VerticalChange);
                Point snapped = bounds.SnapPointToRectangle(p);

                if (AllowDisconnect && !Disconnected && dragThumb.DraggingAllone(this))
                {
                    Vector diff = Vector.SubtractPoints(ExolutioCanvas.GetMousePosition(), CanvasPosition);
                    if (diff.Length < 20)
                    {
                        deltaEventArgs = new DragDeltaEventArgs(snapped.X - CanvasPosition.X,
                                                                snapped.Y - CanvasPosition.Y);
                    }
                    else
                    {
                        DisconnectPoint();
                        deltaEventArgs = new DragDeltaEventArgs(0, 0);
                    }
                }
                else if (!Disconnected)
                {
                    deltaEventArgs = new DragDeltaEventArgs(snapped.X - CanvasPosition.X, snapped.Y - CanvasPosition.Y);
                }

                #endregion
            }
            else
            {
                #region snapping of break points

                if (!Disconnected && this.OrderInConnector > 0 && this.OrderInConnector < Connector.Points.Count - 1)
                {
                    ConnectorPoint rightNeighbour = Connector.Points.ElementAtOrDefault(OrderInConnector + 1);
                    ConnectorPoint leftNeighbour  = Connector.Points.ElementAtOrDefault(OrderInConnector - 1);

                    const double SNAP_RATIO = 14;

                    foreach (ConnectorPoint neighbour in new[] { leftNeighbour, rightNeighbour })
                    {
                        bool isEndPoint = neighbour == Connector.StartPoint || neighbour == Connector.EndPoint;
                        if (neighbour != null &&
                            (!isEndPoint || neighbour.Placement == EPlacementKind.AbsoluteSubCanvas))
                        {
                            double nx     = neighbour.CanvasPosition.X;
                            double ny     = neighbour.CanvasPosition.Y;
                            double deltax = deltaEventArgs.HorizontalChange;
                            double deltay = deltaEventArgs.VerticalChange;
                            double diff;
                            if (ShouldSnap(dragThumb.MousePoint.Y, ny, SNAP_RATIO, out diff))
                            {
                                ShouldSnap(CanvasPosition.Y + deltaEventArgs.VerticalChange, ny, SNAP_RATIO, out diff);
                                deltay        += diff;
                                deltaEventArgs = new DragDeltaEventArgs(deltax, deltay);
                            }
                            else if (ShouldSnap(dragThumb.MousePoint.X, nx, SNAP_RATIO, out diff))
                            {
                                ShouldSnap(CanvasPosition.X + deltaEventArgs.HorizontalChange, nx, SNAP_RATIO, out diff);
                                deltax        += diff;
                                deltaEventArgs = new DragDeltaEventArgs(deltax, deltay);
                            }
                        }
                    }
                }

                #endregion
            }
        }
Exemple #11
0
        private Label CreateOrRemoveLabel(ref Label currentLabel, LabelViewHelper viewHelper, string name, string cardinality, Action selectedChanged, Action <DragDeltaEventArgs> positionChanged, ContextMenu contextMenu, ConnectorPoint snapPoint = null, Connector snapConnector = null, EPlacementCenter placementCenter = EPlacementCenter.TopLeftCorner)
        {
            if (string.IsNullOrEmpty(name) && (cardinality == "1" || string.IsNullOrEmpty(cardinality)))
            {
                if (currentLabel != null)
                {
                    if (selectedChanged != null)
                    {
                        currentLabel.SelectedChanged -= selectedChanged;
                    }
                    if (positionChanged != null)
                    {
                        currentLabel.PositionChanged -= positionChanged;
                    }
                    if (snapPoint != null)
                    {
                        currentLabel.UnSnap();
                    }
                    if (snapConnector != null)
                    {
                        currentLabel.UnSnap();
                    }
                    CreatedControls.Remove(currentLabel);
                    DiagramView.ExolutioCanvas.RemoveNode(currentLabel);
                }
                return(null);
            }

            if (currentLabel == null)
            {
                Point tmpPosition = viewHelper.Position;
                currentLabel = new Label();
                CreatedControls.Add(currentLabel);
                DiagramView.ExolutioCanvas.AddNode(currentLabel);
                currentLabel.PlacementCenter = placementCenter;
                if (snapPoint != null)
                {
                    currentLabel.SnapTo(snapPoint, true);
                }
                if (snapConnector != null)
                {
                    snapConnector.SnapNodeToConnector(currentLabel);
                }
                currentLabel.X = viewHelper.X;
                currentLabel.Y = viewHelper.Y;
                if (selectedChanged != null)
                {
                    currentLabel.SelectedChanged += selectedChanged;
                }
                if (positionChanged != null)
                {
                    currentLabel.PositionChanged += positionChanged;
                }
                currentLabel.ContextMenu = contextMenu;
                //UpdateView();
                //viewHelper.SetPositionSilent(tmpPosition.X, tmpPosition.Y);
                //currentLabel.X =
            }
            return(currentLabel);
        }
Exemple #12
0
        public void Connect(Node node1, Node node2)
        {
            if (StartNode != null)
            {
                StartNode.Connectors.Remove(this);
            }
            if (EndNode != null)
            {
                EndNode.Connectors.Remove(this);
            }
            StartNode = node1;
            EndNode   = node2;


            Point[] optimalConnection;
            if (node1 != node2)
            {
                optimalConnection = GeometryHelper.ComputeOptimalConnection(node1, node2);
            }
            else
            {
                optimalConnection = GeometryHelper.ComputePointsForSelfAssociation(node1.GetBounds());
            }

#if SILVERLIGHT
            if (node1.GetBounds().Width == 0)
            {
                sourceMeasureValid = false;
            }
            if (node2.GetBounds().Width == 0)
            {
                targetMeasureValid = false;
            }
#endif

            ConnectorPoint startPoint = new ConnectorPoint(ExolutioCanvas)
            {
                Placement = EPlacementKind.ParentAutoPos, ParentControl = node1, Connector = this, OrderInConnector = 0
            };
            ConnectorPoint endPoint = new ConnectorPoint(ExolutioCanvas)
            {
                Placement = EPlacementKind.ParentAutoPos, ParentControl = node2, Connector = this, OrderInConnector = 1
            };

            startPoint.SetPreferedPosition(optimalConnection.First());
            endPoint.SetPreferedPosition(optimalConnection.Last());

            foreach (ConnectorPoint point in Points)
            {
                if (point.OrderInConnector == 0)
                {
                    point.ParentControl.InnerConnectorControl.Children.Remove(point);
                }
                else if (point.OrderInConnector == Points.Count - 1)
                {
                    point.ParentControl.InnerConnectorControl.Children.Remove(point);
                }
                else
                {
                    ExolutioCanvas.Children.Remove(point);
                }
            }
            points.Clear();
            points.Add(startPoint);
            points.Add(endPoint);
            StartNode.InnerConnectorControl.Children.Add(startPoint);
            EndNode.InnerConnectorControl.Children.Add(endPoint);

            StartNode.Connectors.Add(this);
            // in the case where StartNode == EndNode, the connector is added only once
            EndNode.Connectors.AddIfNotContained(this);

            for (int i = (optimalConnection.Count() - 1) - 1; i >= 1; i--)
            {
                ConnectorPoint newPoint = BreakAtPoint(optimalConnection[i]);
                if (node1 == node2)
                {
                    newPoint.Placement = EPlacementKind.RelativeCanvas;
                    newPoint.SnapTo(node1, false);
                }
            }

            InvalidateGeometry();
        }