protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (HitConnectionNode != null)
            {
                ConnectionNode sourceConnectionNode = this.sourceConnectionNode;
                ConnectionNode targetConnectionNode = this.HitConnectionNode;
                Connection     newConnection        = new Connection(sourceConnectionNode, targetConnectionNode);

                Canvas.SetZIndex(newConnection, DiagramCanvas.Children.Count);
                this.DiagramCanvas.Children.Add(newConnection);
            }
            if (HitDiagramElement != null)
            {
                this.HitDiagramElement.IsDragConnectionOver = false;
            }

            if (this.IsMouseCaptured)
            {
                this.ReleaseMouseCapture();
            }

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.DiagramCanvas);

            if (adornerLayer != null)
            {
                adornerLayer.Remove(this);
            }
        }
 public Connection(ConnectionNode source, ConnectionNode target)
 {
     this.ID        = Guid.NewGuid();
     this.Source    = source;
     this.Target    = target;
     base.Unloaded += new RoutedEventHandler(Connection_Unloaded);
 }
        private void HitTesting(Point hitPoint)
        {
            bool hitConnectionNodeFlag = false;

            DependencyObject hitObject = DiagramCanvas.InputHitTest(hitPoint) as DependencyObject;

            while (hitObject != null &&
                   hitObject != sourceConnectionNode.ParentDiagramElement &&
                   hitObject.GetType() != typeof(DiagramCanvas))
            {
                if (hitObject is ConnectionNode)
                {
                    HitConnectionNode     = hitObject as ConnectionNode;
                    hitConnectionNodeFlag = true;
                }

                if (hitObject is DiagramElement)
                {
                    HitDiagramElement = hitObject as DiagramElement;
                    if (!hitConnectionNodeFlag)
                    {
                        HitConnectionNode = null;
                    }
                    return;
                }
                hitObject = VisualTreeHelper.GetParent(hitObject);
            }

            HitConnectionNode = null;
            HitDiagramElement = null;
        }
 public ConnectionNodeAdorner(DiagramCanvas designer, ConnectionNode sourceConnectionNode)
     : base(designer)
 {
     this.DiagramCanvas        = designer;
     this.sourceConnectionNode = sourceConnectionNode;
     drawingPen          = new Pen(Brushes.LightSlateGray, 1);
     drawingPen.LineJoin = PenLineJoin.Round;
     this.Cursor         = Cursors.Cross;
 }
Ejemplo n.º 5
0
        void thumbDragControl_DragStarted(object sender, DragStartedEventArgs e)
        {
            this.HitDiagramElement          = null;
            this.HitConnectionNode          = null;
            this.pathGeometry               = null;
            this.Cursor                     = Cursors.Cross;
            this.connection.StrokeDashArray = new DoubleCollection(new double[] { 1, 2 });

            if (sender == sourceDragControl)
            {
                fixConnectionNode  = connection.Target;
                dragConnectionNode = connection.Source;
            }
            else if (sender == targetDragControl)
            {
                dragConnectionNode = connection.Target;
                fixConnectionNode  = connection.Source;
            }
        }
Ejemplo n.º 6
0
        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("DiagramElements").Elements("DiagramElement");

            foreach (XElement itemXML in itemsXML)
            {
                Guid           id   = new Guid(itemXML.Element("ID").Value);
                DiagramElement item = DeserializeDiagramElement(itemXML, id, 0, 0);
                this.Children.Add(item);
                SetConnectionNodeDecoratorTemplate(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 targetID = new Guid(connectionXML.Element("TargetID").Value);

                String sourceConnectionNodeName = connectionXML.Element("SourceConnectionNodeName").Value;
                String targetConnectionNodeName = connectionXML.Element("TargetConnectionNodeName").Value;

                ConnectionNode sourceConnectionNode = GetConnectionNode(sourceID, sourceConnectionNodeName);
                ConnectionNode targetConnectionNode = GetConnectionNode(targetID, targetConnectionNodeName);

                Connection connection = new Connection(sourceConnectionNode, targetConnectionNode);
                Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                this.Children.Add(connection);
            }
        }
Ejemplo n.º 7
0
        private void Paste_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            XElement root = LoadSerializedDataFromClipBoard();

            if (root == null)
            {
                return;
            }

            // create DiagramElements
            Dictionary <Guid, Guid> mappingOldToNewIDs = new Dictionary <Guid, Guid>();
            List <ISelectable>      newItems           = new List <ISelectable>();
            IEnumerable <XElement>  itemsXML           = root.Elements("DiagramElements").Elements("DiagramElement");

            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);
                DiagramElement item = DeserializeDiagramElement(itemXML, newID, offsetX, offsetY);
                this.Children.Add(item);
                SetConnectionNodeDecoratorTemplate(item);
                newItems.Add(item);
            }

            // update group hierarchy
            SelectionService.ClearSelection();
            foreach (DiagramElement el in newItems)
            {
                if (el.ParentID != Guid.Empty)
                {
                    el.ParentID = mappingOldToNewIDs[el.ParentID];
                }
            }


            foreach (DiagramElement 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 oldTargetID = new Guid(connectionXML.Element("TargetID").Value);

                if (mappingOldToNewIDs.ContainsKey(oldSourceID) && mappingOldToNewIDs.ContainsKey(oldTargetID))
                {
                    Guid newSourceID = mappingOldToNewIDs[oldSourceID];
                    Guid newTargetID = mappingOldToNewIDs[oldTargetID];

                    String sourceConnectionNodeName = connectionXML.Element("SourceConnectionNodeName").Value;
                    String targetConnectionNodeName = connectionXML.Element("TargetConnectionNodeName").Value;

                    ConnectionNode sourceConnectionNode = GetConnectionNode(newSourceID, sourceConnectionNodeName);
                    ConnectionNode targetConnectionNode = GetConnectionNode(newTargetID, targetConnectionNodeName);

                    Connection connection = new Connection(sourceConnectionNode, targetConnectionNode);
                    Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                    this.Children.Add(connection);

                    SelectionService.AddToSelection(connection);
                }
            }


            // update paste offset
            root.Attribute("OffsetX").Value = (offsetX + 10).ToString();
            root.Attribute("OffsetY").Value = (offsetY + 10).ToString();
            Clipboard.Clear();
            Clipboard.SetData(DataFormats.Xaml, root);
        }