public Connection(Connector source, Connector sink) { this.ID = Guid.NewGuid(); this.Source = source; this.Sink = sink; base.Unloaded += new RoutedEventHandler(Connection_Unloaded); }
public ConnectorAdorner(DesignerCanvas designer, Connector sourceConnector) : base(designer) { this.designerCanvas = designer; this.sourceConnector = sourceConnector; drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; this.Cursor = Cursors.Cross; }
public Connection(Connector source, Connector sink, PathFinderTypes pathFinder) { this.ID = Guid.NewGuid(); this.Source = source; this.pathFinder = pathFinder; this.Sink = sink; this.MouseDown += Connection_MouseDown; //base.Unloaded += new RoutedEventHandler(Connection_Unloaded); }
void thumbDragThumb_DragStarted(object sender, DragStartedEventArgs e) { this.HitDesignerItem = null; this.HitConnector = null; this.pathGeometry = null; this.Cursor = Cursors.Cross; this.connection.StrokeDashArray = new DoubleCollection(new double[] { 1, 2 }); if (sender == sourceDragThumb) { fixConnector = connection.Sink; dragConnector = connection.Source; } else if (sender == sinkDragThumb) { dragConnector = connection.Sink; fixConnector = connection.Source; } }
private void HitTesting(Point hitPoint) { bool hitConnectorFlag = false; DependencyObject hitObject = designerCanvas.InputHitTest(hitPoint) as DependencyObject; while (hitObject != null && hitObject != sourceConnector.ParentDesignerItem && hitObject.GetType() != typeof(DesignerCanvas)) { if (hitObject is Connector) { HitConnector = hitObject as Connector; hitConnectorFlag = true; } if (hitObject is DesignerItem) { HitDesignerItem = hitObject as DesignerItem; if (!hitConnectorFlag) HitConnector = null; return; } hitObject = VisualTreeHelper.GetParent(hitObject); } HitConnector = null; HitDesignerItem = null; }
private void Paste_Executed(object sender, ExecutedRoutedEventArgs e) { XElement root = LoadSerializedDataFromClipBoard(); if (root == null) { return; } // create DesignerItems Dictionary <Guid, Guid> mappingOldToNewIDs = new Dictionary <Guid, Guid>(); List <ISelectable> newItems = new List <ISelectable>(); IEnumerable <XElement> itemsXML = root.Elements("DesignerItems").Elements("DesignerItem"); double offsetX = Double.Parse(root.Attribute("OffsetX").Value, CultureInfo.InvariantCulture); double offsetY = Double.Parse(root.Attribute("OffsetY").Value, CultureInfo.InvariantCulture); foreach (XElement itemXML in itemsXML) { Guid oldID = new Guid(itemXML.Element("ID").Value); Guid newID = Guid.NewGuid(); mappingOldToNewIDs.Add(oldID, newID); DesignerItem item = DeserializeDesignerItem(itemXML, newID, offsetX, offsetY); this.Children.Add(item); SetConnectorDecoratorTemplate(item); newItems.Add(item); } // update group hierarchy SelectionService.ClearSelection(); foreach (DesignerItem el in newItems) { if (el.ParentID != Guid.Empty) { el.ParentID = mappingOldToNewIDs[el.ParentID]; } } foreach (DesignerItem item in newItems) { if (item.ParentID == Guid.Empty) { SelectionService.AddToSelection(item); } } // create Connections IEnumerable <XElement> connectionsXML = root.Elements("Connections").Elements("Connection"); foreach (XElement connectionXML in connectionsXML) { Guid oldSourceID = new Guid(connectionXML.Element("SourceID").Value); Guid oldSinkID = new Guid(connectionXML.Element("SinkID").Value); if (mappingOldToNewIDs.ContainsKey(oldSourceID) && mappingOldToNewIDs.ContainsKey(oldSinkID)) { Guid newSourceID = mappingOldToNewIDs[oldSourceID]; Guid newSinkID = mappingOldToNewIDs[oldSinkID]; String sourceConnectorName = connectionXML.Element("SourceConnectorName").Value; String sinkConnectorName = connectionXML.Element("SinkConnectorName").Value; Connector sourceConnector = GetConnector(newSourceID, sourceConnectorName); Connector sinkConnector = GetConnector(newSinkID, sinkConnectorName); Connection connection = new Connection(sourceConnector, sinkConnector); Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value)); this.Children.Add(connection); SelectionService.AddToSelection(connection); } } DesignerCanvas.BringToFront.Execute(null, this); // update paste offset root.Attribute("OffsetX").Value = (offsetX + 10).ToString(); root.Attribute("OffsetY").Value = (offsetY + 10).ToString(); Clipboard.Clear(); Clipboard.SetData(DataFormats.Xaml, root); }
protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); Mediator.Instance.NotifyColleagues<bool>("DoneDrawingMessage", true); if (sourceConnector != null) { FullyCreatedConnectorInfo sourceDataItem = sourceConnector.DataContext as FullyCreatedConnectorInfo; if (connectorsHit.Count() == 2) { Connector sinkConnector = connectorsHit.Last(); FullyCreatedConnectorInfo sinkDataItem = sinkConnector.DataContext as FullyCreatedConnectorInfo; int indexOfLastTempConnection = sinkDataItem.DataItem.Parent.Items.Count - 1; sinkDataItem.DataItem.Parent.RemoveItemCommand.Execute( sinkDataItem.DataItem.Parent.Items[indexOfLastTempConnection]); sinkDataItem.DataItem.Parent.AddItemCommand.Execute(new ConnectorViewModel(sourceDataItem, sinkDataItem)); } else { //Need to remove last item as we did not finish drawing the path int indexOfLastTempConnection = sourceDataItem.DataItem.Parent.Items.Count - 1; sourceDataItem.DataItem.Parent.RemoveItemCommand.Execute( sourceDataItem.DataItem.Parent.Items[indexOfLastTempConnection]); } } connectorsHit = new List<Connector>(); sourceConnector = null; }