/// <summary> /// Adds new internal point to the junction. /// </summary> /// <param name="position">position where new point is added</param> /// <param name="index">index where new point is inserted in <see cref="Points"/> collection</param> public void BreakLine(Point position, int index) { if (AutoPosModeOnly) { return; } JunctionPoint newPoint = new JunctionPoint(XCaseCanvas) { Junction = this, OrderInJunction = index }; XCaseCanvas.Children.Add(newPoint); if (SourceElement == TargetElement) { newPoint.SnapTo(SourceElement as DragThumb, true); } //newPoint.SetPreferedPosition(position.X - (newPoint.ReferentialElement != null ? newPoint.ReferentialElement.CanvasPosition.X : 0), position.Y - (newPoint.ReferentialElement != null ? newPoint.ReferentialElement.CanvasPosition.Y : 0)); newPoint.SetPreferedPosition(position.X, position.Y); Canvas.SetZIndex(newPoint, Canvas.GetZIndex(this) + 1); for (int i = index; i < Points.Count; i++) { Points[i].OrderInJunction++; } Points.Insert(newPoint.OrderInJunction, newPoint); //only re-rendering is not enough, whole geometry must be invalidated... InvalidateGeometry(); UpdateLayout(); }
/// <summary> /// Creates <see cref="JunctionPoint"/> on a specific position. /// </summary> /// <param name="preferedPosition">The prefered position for a new JunctionPoint</param> /// <returns>new <see cref="JunctionPoint"/></returns> public virtual JunctionPoint CreateJunctionEnd(Point preferedPosition) { JunctionPoint junctionEnd = CreateJunctionEnd(); junctionEnd.SetPreferedPosition(preferedPosition); createdJunctionEnds.Add(junctionEnd); return(junctionEnd); }
/// <summary> /// Dragging beggins, the <paramref name="item"/> will be the source of the connection. /// </summary> /// <param name="item">item clicked</param> /// <param name="e">event arguments</param> public override void SelectableItemPreviewMouseDown(ISelectable item, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Right) { Canvas.State = ECanvasState.Normal; e.Handled = true; return; } base.SelectableItemPreviewMouseDown(item, e); if (item is IConnectable && e.ChangedButton == MouseButton.Left) { Canvas.CaptureMouse(); foreach (ISelectable i in Canvas.SelectedItems) { i.IsSelected = false; } Canvas.SelectedItems.Clear(); draggedPoint = new JunctionPoint(Canvas) { Width = 0, Height = 0 }; Canvas.Children.Add(draggedPoint); draggedPoint.SetPreferedPosition(e.GetPosition(Canvas)); SetZIndex(draggedPoint, -5); draggedPoint.Visibility = Visibility.Visible; //throw new NotImplementedException("Method or operation is not implemented."); draggedConnection = new XCaseJunction(Canvas); draggedPoint.Junction = draggedConnection; (item as IConnectable).Highlight(); InConnectionDrag = true; draggedConnection.DragConnection(item as IConnectable, draggedPoint, Canvas); Canvas.Children.Add(draggedConnection); draggedConnection.EndCapStyle = JunctionGeometryHelper.GetCap(DraggedConnectionType); e.Handled = true; draggedConnection.InvalidateGeometry(); ConnectableItemMouseEnter((IConnectable)item); } }
/// <summary> /// If the mouse cursor is over a <see cref="IConnectable">connectable item</see> a connection is /// drawng between the item and the item where drag started. Otherwise a connection is drawn /// between the item where drag started and current mouse position on the canvas /// </summary> /// <param name="e"></param> public override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); //if (InConnectionDrag) { Point p = e.GetPosition(Canvas); if (InConnectionDrag) { draggedPoint.SetPreferedPosition(p.X - draggedPoint.Width / 2, p.Y - draggedPoint.Height / 2); } foreach (KeyValuePair <Rect, IConnectable> pair in selectableItemsBounds) { if (pair.Key.Contains(p)) { if (InConnectionDrag) { ConnectableItemMouseEnter(pair.Value); } else { Mouse.SetCursor(Cursors.Hand); } return; } } // not over any element if (InConnectionDrag && ItemDraggedOver != null) { if (InConnectionDrag) { ConnectableItemMouseLeave(ItemDraggedOver); } else { Mouse.SetCursor(Cursors.Arrow); } } } }