protected override void OnMouseUp(MouseButtonEventArgs e) { if (HitConnector != null) { Connector sourceConnector = this.sourceConnector; Connector sinkConnector = this.HitConnector; Connection newConnection = new Connection(sourceConnector, sinkConnector); Canvas.SetZIndex(newConnection, designerCanvas.Children.Count); this.designerCanvas.Children.Add(newConnection); } if (HitDesignerItem != null) { this.HitDesignerItem.IsDragConnectionOver = false; } if (this.IsMouseCaptured) this.ReleaseMouseCapture(); AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.designerCanvas); if (adornerLayer != null) { adornerLayer.Remove(this); } }
public static Connection add_Connection(this DesignerCanvas designerCanvas, DesignerItem designerItem1, DesignerItem designerItem2, string position1, string position2) { return((Connection)designerCanvas.wpfInvoke( () => { var connector1 = designerItem1.connector(position1); var connector2 = designerItem2.connector(position2); var connection = new DiagramDesigner.Connection(connector1, connector2); designerCanvas.Children.Add(connection); return connection; })); }
public ConnectionAdorner(DesignerCanvas designer, Connection connection) : base(designer) { this.designerCanvas = designer; adornerCanvas = new Canvas(); this.visualChildren = new VisualCollection(this); this.visualChildren.Add(adornerCanvas); this.connection = connection; this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged); InitializeDragThumbs(); drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; }
protected override void OnMouseUp(MouseButtonEventArgs e) { if (HitConnector != null) { Connector sourceConnector = this.sourceConnector; Connector sinkConnector = this.HitConnector; Connection newConnection = new Connection(sourceConnector, sinkConnector); // connections are added with z-index of zero this.designerCanvas.Children.Insert(0, newConnection); } if (HitDesignerItem != null) { this.HitDesignerItem.IsDragConnectionOver = false; } if (this.IsMouseCaptured) this.ReleaseMouseCapture(); AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.designerCanvas); if (adornerLayer != null) { adornerLayer.Remove(this); } }
private void Open_Executed(object sender, ExecutedRoutedEventArgs e) { XElement root = LoadSerializedDataFromFile(); if (root == null) return; this.Children.Clear(); this.SelectionService.ClearSelection(); IEnumerable<XElement> itemsXML = root.Elements("DesignerItems").Elements("DesignerItem"); foreach (XElement itemXML in itemsXML) { Guid id = new Guid(itemXML.Element("ID").Value); DesignerItem item = DeserializeDesignerItem(itemXML, id, 0, 0); this.Children.Add(item); SetConnectorDecoratorTemplate(item); } this.InvalidateVisual(); IEnumerable<XElement> connectionsXML = root.Elements("Connections").Elements("Connection"); foreach (XElement connectionXML in connectionsXML) { Guid sourceID = new Guid(connectionXML.Element("SourceID").Value); Guid sinkID = new Guid(connectionXML.Element("SinkID").Value); String sourceConnectorName = connectionXML.Element("SourceConnectorName").Value; String sinkConnectorName = connectionXML.Element("SinkConnectorName").Value; Connector sourceConnector = GetConnector(sourceID, sourceConnectorName); Connector sinkConnector = GetConnector(sinkID, sinkConnectorName); Connection connection = new Connection(sourceConnector, sinkConnector); Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value)); this.Children.Add(connection); } }
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); }
public void Open(XElement root) // splitted Open_Executed in two so that we can open an XElement directly { if (root == null) return; this.Children.Clear(); this.SelectionService.ClearSelection(); IEnumerable<XElement> itemsXML = root.Elements("DesignerItems").Elements("DesignerItem"); foreach (XElement itemXML in itemsXML) { Guid id = new Guid(itemXML.Element("ID").Value); DesignerItem item = DeserializeDesignerItem(itemXML, id, 0, 0); this.Children.Add(item); SetConnectorDecoratorTemplate(item); } this.InvalidateVisual(); IEnumerable<XElement> connectionsXML = root.Elements("Connections").Elements("Connection"); foreach (XElement connectionXML in connectionsXML) { Guid sourceID = new Guid(connectionXML.Element("SourceID").Value); Guid sinkID = new Guid(connectionXML.Element("SinkID").Value); String sourceConnectorName = connectionXML.Element("SourceConnectorName").Value; String sinkConnectorName = connectionXML.Element("SinkConnectorName").Value; Connector sourceConnector = GetConnector(sourceID, sourceConnectorName); Connector sinkConnector = GetConnector(sinkID, sinkConnectorName); if (sourceConnector != null && sinkConnector != null) //DC { Connection connection = new Connection(sourceConnector, sinkConnector); Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value)); this.Children.Add(connection); } } }
/*设定连线颜色*/ void SetConnectionColor(Connection connection, Brush colorBrushes) { _diagramControl.UpdateLayout(); var path = connection.Template.FindName("PART_ConnectionPath", connection) as Path; if (path != null) { path.Stroke = colorBrushes; //path.StrokeThickness = 2; } }
public void CreateHelperConnection(DesignerItem newParent, DesignerItem dragItem) { RemoveHelperConnection(); if (newParent == null) return; var source = GetItemConnector(newParent, PARENT_CONNECTOR); var sink = GetItemConnector(dragItem, CHILD_CONNECTOR); var connection = new Connection(source, sink); connection.toNewParent = true; source.Connections.Add(connection); _diagramControl.DesignerCanvas.Children.Add(connection); SetConnectionColor(connection, Brushes.Red); BringToFront(connection); }
void RemoveConnection(Connection connection) { connection.Source.Connections.Remove(connection); connection.Sink.Connections.Remove(connection); connection.Source = null; connection.Sink = null; _diagramControl.DesignerCanvas.Children.Remove(connection); }
/*创建非根节点时,同时创建与父节点之间的连线*/ void DrawChild(DesignerItem parent, DesignerItem childItem) { if (parent == null) return; DrawDesignerItem(childItem);/*创建子节点*/ var source = GetItemConnector(parent, PARENT_CONNECTOR); var sink = GetItemConnector(childItem, "Left"); if (source == null || sink == null) return; #region 创建连线 var connections = GetItemConnections(parent).Where(connection => connection.Source.Equals(source) && connection.Sink.Equals(sink)).ToList(); if (connections.Count == 0 || connections.FirstOrDefault() == null) { var conn = new Connection(source, sink); /*创建连线*/ _diagramControl.DesignerCanvas.Children.Add(conn); /*放到画布上*/ Panel.SetZIndex(conn, -10000); } #endregion childItem.CanCollapsed = true; }
void CreateConnection(DesignerItem newParent, DesignerItem designerItem) { var source = GetItemConnector(newParent, PARENT_CONNECTOR); var sink = GetItemConnector(designerItem, CHILD_CONNECTOR); var connection = new Connection(source, sink); source.Connections.Add(connection); _diagramControl.DesignerCanvas.Children.Add(connection); }