Пример #1
0
        //Refresh Layout
        /// <summary>
        /// RefreshLayout
        /// Description:
        /// When there are changes in content of the page like  new nodes or connectors added,
        /// the layout has to be refreshed to get the page’s content aligned again to give space for new contents
        /// </summary>
        /// ReturnType:Void
        /// <param name="Null"></param>
        /// <param name="e"></param>

        //Refreshing the Layout
        private void refreshLayout(TreeOrientation treeorientation)
        {
            HierarchicalTreeLayout tree = new HierarchicalTreeLayout(diagramModel, diagramView);

            diagramModel.Orientation = treeorientation;
            tree.RefreshLayout();
            (diagramView.Page as DiagramPage).InvalidateMeasure();
            (diagramView.Page as DiagramPage).InvalidateArrange();
        }
Пример #2
0
        //To change the Spacing properties
        /// <summary>
        /// HorizontalSpacing ,VerticalSpacing and SpaceBetweenSubTrees
        /// Description:
        /// Provide the spaces between the edges of the adjacent nodes (Siblings)[HorizontalSpacing].
        /// Provide  spaces between the nodes that lie at the next levels of the layout[VerticalSpacing].
        /// Provide the sthe spaces between adjacent Subtrees[SpaceBetweenSubTrees].
        /// Property of DiagramModel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Hspace_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (this.IsLoaded)
            {
                TextBox box = (sender as TextBox);
                HierarchicalTreeLayout htreelayout = new HierarchicalTreeLayout(diagramModel, diagramView);
                if (diagramModel != null)
                {
                    if (box.Text != string.Empty)
                    {
                        try
                        {
                            switch (box.Name)
                            {
                            case "Hspace":
                                diagramModel.HorizontalSpacing = double.Parse(box.Text);
                                htreelayout.RefreshLayout();
                                break;

                            case "Vspace":
                                diagramModel.VerticalSpacing = double.Parse(box.Text);
                                htreelayout.RefreshLayout();
                                break;

                            case "Sspace":
                                diagramModel.SpaceBetweenSubTrees = double.Parse(box.Text);
                                htreelayout.RefreshLayout();
                                break;

                            case "LeftBounds":
                                diagramView.LayoutBounds = new Rect(double.Parse(box.Text), diagramView.LayoutBounds.Y, diagramView.LayoutBounds.Width, diagramView.LayoutBounds.Height);
                                htreelayout.RefreshLayout();
                                break;

                            case "TopBounds":
                                diagramView.LayoutBounds = new Rect(diagramView.LayoutBounds.X, double.Parse(box.Text), diagramView.LayoutBounds.Width, diagramView.LayoutBounds.Height);
                                htreelayout.RefreshLayout();
                                break;

                            case "WidthBounds":
                                diagramView.LayoutBounds = new Rect(diagramView.LayoutBounds.X, diagramView.LayoutBounds.Y, double.Parse(box.Text), diagramView.LayoutBounds.Height);
                                htreelayout.RefreshLayout();
                                break;

                            case "HeightBounds":
                                diagramView.LayoutBounds = new Rect(diagramView.LayoutBounds.X, diagramView.LayoutBounds.Y, diagramView.LayoutBounds.Width, double.Parse(box.Text));
                                htreelayout.RefreshLayout();
                                break;
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Invalid Input. Enter digits (0-9) only", "Invalid input", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// updates the Diagram completely
        /// </summary>
        /// <param name="advanced"></param>
        public void UpdateDiagram(bool advanced = false)
        {
            if (advanced)
            {
                Model.Connections.Clear();
                Model.Nodes.Clear();
                CreateDiagram();
            }

            var layout = new HierarchicalTreeLayout(Model, View);

            layout.RefreshLayout();
        }
Пример #4
0
        //Refreshing the Layout after adding the Node
        private void AddNodeasChild(NodeContent cnt, Node n1, Node head)
        {
            n1.Style = this.Resources["newtemp"] as Style;
            n1.Content = cnt;
            n1.Width = 75;
            n1.Height = 75;
            n1.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            n1.VerticalContentAlignment = VerticalAlignment.Stretch;
            if (n1.ChildCount == 0)
            {
                cnt.Expander = null;
            }
            else
            {
                cnt.Expander = App.Current.Resources["Plus"] as DrawingImage;
            }
            if (head != null)
            {
                if (head.ChildCount == 0)
                {
                    if ((this.FindNameFromContentTemplate(head, "Expander") as Image) != null)
                    {
                        (this.FindNameFromContentTemplate(head, "Expander") as Image).Source = App.Current.Resources["Minus"] as DrawingImage;
                    }
                }
            }
            LineConnector lc = new LineConnector();
            lc.HeadNode = head;
            lc.TailNode = n1;
            lc.TailDecoratorShape = DecoratorShape.Arrow;

            if ((this.FindNameFromContentTemplate(head, "Expander") as Image).Name == "P")
            {
                n1.Visibility = Visibility.Hidden;
                lc.Visibility = Visibility.Hidden;
            }
            else
            {
                Show(n1);
            }

            diagramModel.Nodes.Add(n1);
            n1.AllowSelect = false;
            n1.IsSelected = false;
            n1.MouseRightButtonDown += new MouseButtonEventHandler(newNode_MouseRightButtonDown);
            diagramModel.Connections.Add(lc);
            HierarchicalTreeLayout layout = new HierarchicalTreeLayout(diagramModel, diagramView);
            layout.RefreshLayout();
        }
Пример #5
0
        //Menu For adding the Node
        void AddMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Node n = selectedNode;
            if (n != null)
            {
                Node n1 = addNode("Employee", true, false);
                Node n2 = addNode("Boy", true, false);
                Connect(n, n1, null);
                Connect(n, n2, null);
            }

            if ((this.FindNameFromContentTemplate(n, "Expander") as Image) != null)
            {
                (this.FindNameFromContentTemplate(n, "Expander") as Image).Source = App.Current.Resources["Minus"] as DrawingImage;
            }

            HierarchicalTreeLayout layout = new HierarchicalTreeLayout(diagramModel, diagramView);
            layout.RefreshLayout();
        }
Пример #6
0
        private void VerticalLayout_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as ComboBox).SelectedIndex == 0)
            {
                diagramModel.LayoutVerticalAlignment = LayoutVerticalAlignment.Center;
            }
            else if ((sender as ComboBox).SelectedIndex == 1)
            {
                diagramModel.LayoutVerticalAlignment = LayoutVerticalAlignment.Top;
            }
            else
            {
                diagramModel.LayoutVerticalAlignment = LayoutVerticalAlignment.Bottom;
            }
            HierarchicalTreeLayout tree = new HierarchicalTreeLayout(diagramModel, diagramView);

            tree.RefreshLayout();
            (diagramView.Page as DiagramPage).InvalidateMeasure();
            (diagramView.Page as DiagramPage).InvalidateArrange();
        }