private void DeleteCurrentSelection()
        {
            foreach (Connection connection in SelectionService.CurrentSelection.OfType <Connection>())
            {
                this.Children.Remove(connection);
            }

            foreach (DesignerItem item in SelectionService.CurrentSelection.OfType <DesignerItem>())
            {
                Control cd = item.Template.FindName("PART_ConnectorDecorator", item) as Control;

                List <Connector> connectors = new List <Connector>();
                GetConnectors(cd, connectors);

                foreach (Connector connector in connectors)
                {
                    foreach (Connection con in connector.Connections)
                    {
                        this.Children.Remove(con);
                    }
                }
                this.Children.Remove(item);
            }

            SelectionService.ClearSelection();
            UpdateZIndex();
        }
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Source == this)
            {
                // in case that this click is the start of a
                // drag operation we cache the start point
                this._rubberbandSelectionStartPoint = new Point?(e.GetPosition(this));

                if (parent == null)
                {
                    parent = this.Parent as ScrollViewer;
                }
                this._canvasDraggingStartPoint = new Point?(e.GetPosition(parent));

                // if you click directly on the canvas, and you are not holding Ctrl or Shift
                // all selected items are 'de-selected'
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) == ModifierKeys.None)
                {
                    SelectionService.ClearSelection();
                }

                Focus();
                e.Handled = true;
            }
        }
Example #3
0
        private void DeleteCurrentSelection()
        {
            foreach (Connection connection in SelectionService.CurrentSelection.OfType <Connection>())
            {
                this.Children.Remove(connection);
            }

            foreach (DiagramElement item in SelectionService.CurrentSelection.OfType <DiagramElement>())
            {
                Control cd = item.Template.FindName("ConnectionNodeDecorator", item) as Control;

                List <ConnectionNode> ConnectionNodes = new List <ConnectionNode>();
                GetConnectionNodes(cd, ConnectionNodes);

                foreach (ConnectionNode ConnectionNode in ConnectionNodes)
                {
                    foreach (Connection con in ConnectionNode.Connections)
                    {
                        this.Children.Remove(con);
                    }
                }
                this.Children.Remove(item);
            }

            SelectionService.ClearSelection();
            UpdateZIndex();
        }
        private void Print_Executed(object sender, RoutedEventArgs e)
        {
            SelectionService.ClearSelection();

            PrintDialog printDialog = new PrintDialog();

            if (true == printDialog.ShowDialog())
            {
                printDialog.PrintVisual(this, "WPF Diagram");
            }
        }
Example #5
0
        public void DeleteCurrentSelection()
        {
            foreach (Connection connection in SelectionService.CurrentSelection.OfType <Connection>())
            {
                DeleteChild(connection);
            }

            foreach (DesignerItem item in SelectionService.CurrentSelection.OfType <DesignerItem>())
            {
                DeleteChild(item);
            }

            SelectionService.ClearSelection();
        }
Example #6
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Source == this)
            {
                // in case that this click is the start of a
                // drag operation we cache the start point
                this.rubberbandSelectionStartPoint = new Point?(e.GetPosition(this));
                Focus();
                // if you click directly on the canvas all
                // selected items are 'de-selected'
                SelectionService.ClearSelection();

                e.Handled = true;
            }
        }
        protected virtual void DeleteCurrentSelection()
        {
            foreach (Connection connection in SelectionService.CurrentSelection.OfType <Connection>())
            {
                this.Children.Remove(connection);
                if (DeleteLink != null)
                {
                    DeleteLink(connection.Source.ParentDesignerItem, connection.Sink.ParentDesignerItem);
                }
                if (Changed != null)
                {
                    Changed();
                }
            }

            foreach (DesignerItem item in SelectionService.CurrentSelection.OfType <DesignerItem>())
            {
                Control cd = item.Template.FindName("PART_ConnectorDecorator", item) as Control;

                List <Connector> connectors = new List <Connector>();
                GetConnectors(cd, connectors);

                foreach (Connector connector in connectors)
                {
                    foreach (Connection con in connector.Connections)
                    {
                        this.Children.Remove(con);
                    }
                }
                this.Children.Remove(item);
                if (DeleteBlock != null)
                {
                    DeleteBlock(item);
                }
                if (Changed != null)
                {
                    Changed();
                }
            }

            SelectionService.ClearSelection();
            UpdateZIndex();
        }
Example #8
0
        private void DeleteCurrentSelection()
        {
            foreach (Connection connection in SelectionService.CurrentSelection.OfType <Connection>())
            {
                connection.Source.Connections.Remove(connection);
                connection.Sink.Connections.Remove(connection);

                this.Children.Remove(connection);

                raiseDesignerItemRemoved(connection, null);
            }

            foreach (DesignerItem item in SelectionService.CurrentSelection.OfType <DesignerItem>())
            {
                Control cd = item.Template.FindName("PART_ConnectorDecorator", item) as Control;

                List <Connector> connectors = new List <Connector>();
                GetConnectors(cd, connectors);

                foreach (Connector connector in connectors)
                {
                    foreach (Connection con in connector.Connections.ToList())
                    {
                        con.Source.Connections.Remove(con);
                        con.Sink.Connections.Remove(con);
                        this.Children.Remove(con);
                    }
                }

                if (!item.IsUndeleteable)
                {
                    this.Children.Remove(item);

                    raiseDesignerItemRemoved(item.Content, item);
                }
            }

            SelectionService.ClearSelection();
            UpdateZIndex();
        }
 public void ClearSelection()
 {
     selectionService.ClearSelection();
 }
        private void Paste_Executed(object sender, RoutedEventArgs 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);
                SetCopyOfTag(item);
                this.Children.Add(item);
                SetConnectorDecoratorTemplate(item);
                newItems.Add(item);
                notifyAddBlock(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);
        }
        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);

                raiseDesignerItemAdded(item.Content, item);

                mappingOldToNewIDs.Add(oldID, item.ID);
                //mappingOldToNewIDs[oldID] = item.ID;
            }

            // 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);
                }
            }

            SelectionService.RaiseSelectionChanged();

            // 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;
                    PathFinderTypes pathFinder          = (PathFinderTypes)Enum.Parse(typeof(PathFinderTypes), connectionXML.Element("PathFinder").Value);
                    SolidColorBrush color           = (SolidColorBrush) new BrushConverter().ConvertFromString(connectionXML.Element("Color").Value);
                    double          strokeThickness = Double.Parse(connectionXML.Element("StrokeThickness")?.Value);

                    Connector sourceConnector = GetConnector(newSourceID, sourceConnectorName);
                    Connector sinkConnector   = GetConnector(newSinkID, sinkConnectorName);

                    Connection connection = ConnectionGenerator(sourceConnector, sinkConnector, pathFinder);
                    //Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                    connection.ZIndex          = Int32.Parse(connectionXML.Element("zIndex").Value);
                    connection.Color           = color;
                    connection.StrokeThickness = strokeThickness;
                    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);
        }