Ejemplo n.º 1
0
        void graph_SelectionChanged()
        {
            FunctionsStackPanel.Children.Clear();
            StylesExpander.Visibility    = System.Windows.Visibility.Hidden;
            FunctionsExpander.Visibility = System.Windows.Visibility.Collapsed;

            if (graph.SelectionManager.IsMultipleSelected())
            {
                if (graph.SelectionManager.IsOnlyNodesSelected())
                {
                    FunctionsExpander.Visibility = System.Windows.Visibility.Visible;

                    Button button = new Button();
                    button.Background = Brushes.White;
                    button.Margin     = new Thickness(2);
                    button.Content    = "Remove nodes (Del)";
                    foreach (Node node in graph.SelectionManager.SelectedNodes)
                    {
                        button.Click += node.Remove;
                    }

                    Statics.AddImageToButton(button, "Tango Icons\\edit-delete.png");
                    FunctionsStackPanel.Children.Add(button);

                    StylesExpander.Visibility = System.Windows.Visibility.Visible;
                }
                return;
            }
            else if (graph.SelectionManager.SelectedNodes.Count == 1)
            {
                FunctionsExpander.Visibility = System.Windows.Visibility.Visible;
                WrapPanel nodeButtonsWrapPanel = new WrapPanel()
                {
                    Orientation = Orientation.Horizontal
                };
                FunctionsStackPanel.Children.Add(nodeButtonsWrapPanel);

                Button button = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Node properties (Enter)";
                button.Click     += graph.SelectionManager.SelectedNodes[0].PropertiesWindow;
                Statics.AddImageToButton(button, "Tango Icons\\document-properties.png");
                nodeButtonsWrapPanel.Children.Add(button);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Remove node (Del)";
                button.Click     += graph.SelectionManager.SelectedNodes[0].Remove;
                Statics.AddImageToButton(button, "Tango Icons\\edit-delete.png");
                nodeButtonsWrapPanel.Children.Add(button);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Bring into front";
                button.Click     += graph.SelectionManager.SelectedNodes[0].BringIntoFront;
                Statics.AddImageToButton(button, "Tango Icons\\go-top.png");
                nodeButtonsWrapPanel.Children.Add(button);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Send to back";
                button.Click     += graph.SelectionManager.SelectedNodes[0].SendToBack;
                Statics.AddImageToButton(button, "Tango Icons\\go-bottom.png");
                nodeButtonsWrapPanel.Children.Add(button);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Duplicate (D)";
                button.Click     += graph.SelectionManager.SelectedNodes[0].Duplicate;
                Statics.AddImageToButton(button, "Tango Icons\\edit-copy.png");
                nodeButtonsWrapPanel.Children.Add(button);

                StylesExpander.Visibility = System.Windows.Visibility.Visible;
            }
            else if (graph.SelectionManager.SelectedEdgePart != null)
            {
                FunctionsExpander.Visibility = System.Windows.Visibility.Visible;

                Label label = new Label();
                label.Content = "Whole edge functions :";
                label.Margin  = new Thickness(5);
                FunctionsStackPanel.Children.Add(label);

                StackPanel edgeButtonsStackPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal
                };
                FunctionsStackPanel.Children.Add(edgeButtonsStackPanel);

                Button button = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Edge properties (Space)";
                button.Click     += graph.SelectionManager.SelectedEdgePart.Edge.Properties;
                Statics.AddImageToButton(button, "Tango Icons\\document-properties.png");
                edgeButtonsStackPanel.Children.Add(button);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Remove Edge (Del)";
                button.Click     += graph.SelectionManager.SelectedEdgePart.Edge.Remove;
                Statics.AddImageToButton(button, "Tango Icons\\edit-delete.png");
                edgeButtonsStackPanel.Children.Add(button);

                label         = new Label();
                label.Content = "Edge part functions :";
                label.Margin  = new Thickness(5);
                FunctionsStackPanel.Children.Add(label);

                StackPanel edgePartButtonsStackPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal
                };
                FunctionsStackPanel.Children.Add(edgePartButtonsStackPanel);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Edge part properties (Enter)";
                button.Click     += graph.SelectionManager.SelectedEdgePart.Properties;
                Statics.AddImageToButton(button, "Tango Icons\\document-properties.png");
                edgePartButtonsStackPanel.Children.Add(button);

                button            = new Button();
                button.Background = Brushes.White;
                button.Margin     = new Thickness(2);
                button.Content    = "Break Edge part (B)";
                button.Click     += graph.SelectionManager.SelectedEdgePart.Break;
                Statics.AddImageToButton(button, "Break48.png");
                edgePartButtonsStackPanel.Children.Add(button);
            }
            else if (graph.SelectionManager.SelectedEdgeBreak != null)
            {
                FunctionsExpander.Visibility = System.Windows.Visibility.Visible;
                graph.UICanvas.ContextMenu   = new ContextMenu();

                var edgeBreak = graph.SelectionManager.SelectedEdgeBreak;
                if (edgeBreak.IsRemovable())
                {
                    Button button = new Button();
                    button.Background = Brushes.White;
                    button.Margin     = new Thickness(2);
                    button.Content    = "Remove edge break (Del)";
                    button.Click     += edgeBreak.Remove;
                    Statics.AddImageToButton(button, "Tango Icons\\edit-delete.png");
                    FunctionsStackPanel.Children.Add(button);
                }
                else
                {
                    var textblock = new TextBlock();
                    textblock.Text = "It can't be removed\nTo remove it, remove the edge";
                    FunctionsStackPanel.Children.Add(textblock);
                }
            }
        }
Ejemplo n.º 2
0
        public static double RectangleDistance(Rect r1, Rect r2)
        {
            double X1 = 0, X2 = 0, Y1 = 0, Y2 = 0;

            if (Statics.IsTwoRectCross(r1, r2))
            {
                return(0);
            }

            if (r1.Top > r2.Bottom && r1.Left > r2.Right)
            {
                X1 = r1.Left;
                Y1 = r1.Top;
                X2 = r2.Right;
                Y2 = r2.Bottom;
            }
            else if (r1.Top > r2.Bottom && r1.Right < r2.Left)
            {
                X1 = r1.Right;
                Y1 = r1.Top;
                X2 = r2.Left;
                Y2 = r2.Bottom;
            }
            else if (r2.Top > r1.Bottom && r2.Left > r1.Right)
            {
                X1 = r2.Left;
                Y1 = r2.Top;
                X2 = r1.Right;
                Y2 = r1.Bottom;
            }
            else if (r2.Top > r1.Bottom && r2.Right < r1.Left)
            {
                X1 = r2.Right;
                Y1 = r2.Top;
                X2 = r1.Left;
                Y2 = r1.Bottom;
            }
            else if (r1.Top > r2.Bottom)
            {
                double maxLeft  = Math.Max(r1.Left, r2.Left);
                double minRight = Math.Min(r1.Right, r2.Right);
                double center   = (maxLeft + minRight) / 2;
                X1 = X2 = center;
                Y1 = r1.Top;
                Y2 = r2.Bottom;
            }
            else if (r2.Top > r1.Bottom)
            {
                double maxLeft  = Math.Max(r1.Left, r2.Left);
                double minRight = Math.Min(r1.Right, r2.Right);
                double center   = (maxLeft + minRight) / 2;
                X1 = X2 = center;
                Y1 = r2.Top;
                Y2 = r1.Bottom;
            }
            else if (r1.Left > r2.Right)
            {
                double maxTop    = Math.Max(r1.Top, r2.Top);
                double minButtom = Math.Min(r1.Bottom, r2.Bottom);
                double center    = (maxTop + minButtom) / 2;
                Y1 = Y2 = center;
                X1 = r1.Left;
                X2 = r2.Right;
            }
            else if (r2.Left > r1.Right)
            {
                double maxTop    = Math.Max(r1.Top, r2.Top);
                double minButtom = Math.Min(r1.Bottom, r2.Bottom);
                double center    = (maxTop + minButtom) / 2;
                Y1 = Y2 = center;
                X1 = r2.Left;
                X2 = r1.Right;
            }

            return(Math.Sqrt((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)));
        }