Exemple #1
0
 private void NodeSelected(DiagramNode sender, RoutedEventArgs eventArguments)
 {
     if (Selected != null)
     {
         Selected(sender, eventArguments);
     }
 }
Exemple #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void OnSelected(DiagramNode sender, RoutedEventArgs e)
 {
     if (Selected != null)
     {
         Selected(sender, e);
     }
 }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="eventArguments"></param>
 protected void OnSelected(DiagramNode sender, RoutedEventArgs eventArguments)
 {
     if (Selected != null)
     {
         Selected(sender, eventArguments);
     }
 }
Exemple #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="eventArguments"></param>
 protected void OnCollapsed(DiagramNode sender, RoutedEventArgs eventArguments)
 {
     OnSelected(sender, eventArguments);
     if (Collapsed != null)
     {
         Collapsed(this, eventArguments);
     }
 }
Exemple #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="eventArguments"></param>
 protected void OnExpanded(DiagramNode sender, RoutedEventArgs eventArguments)
 {
     OnSelected(sender, eventArguments);
     if (Expanded != null)
     {
         Expanded(this, eventArguments);
     }
 }
Exemple #6
0
        private void NodeExpanded(DiagramNode sender, RoutedEventArgs eventArguments)
        {
            mRootNode.Location = new Point(
                (double)GetValue(ActualWidthProperty) / 2.0,
                (double)GetValue(ActualHeightProperty) / 2.0);

            MakeChildrenVisible(sender);

            if (sender.DiagramParent != null)
            {
                sender.DiagramParent.Visibility = Visibility.Visible;
                foreach (DiagramNode sibling in sender.DiagramParent.DiagramChildren)
                {
                    if (sibling != sender)
                    {
                        sibling.Visibility = Visibility.Collapsed;
                    }
                }
                if (sender.DiagramParent.DiagramParent != null)
                {
                    sender.DiagramParent.DiagramParent.Visibility = Visibility.Collapsed;
                }
            }

            if (sender.DiagramChildren.Count > 0)
            {
                double startAngle           = CalculateStartAngle(sender);
                double angleBetweenChildren = (sender == mRootNode ? Math.PI * 2.0 : Math.PI) / ((double)sender.DiagramChildren.Count - 0);

                double legDistance = CalculateLegDistance(sender, angleBetweenChildren);

                for (int i = 0; i < sender.DiagramChildren.Count; ++i)
                {
                    DiagramNode child = sender.DiagramChildren[i];
                    child.Selected  += NodeSelected;
                    child.Expanded  += NodeExpanded;
                    child.Collapsed += NodeCollapsed;

                    Point parentLocation = sender.Location;

                    child.Location = new Point(
                        parentLocation.X + Math.Cos(startAngle + angleBetweenChildren * i) * legDistance,
                        parentLocation.Y + Math.Sin(startAngle + angleBetweenChildren * i) * legDistance);

                    foreach (DiagramNode childsChild in child.DiagramChildren)
                    {
                        childsChild.Visibility = Visibility.Collapsed;
                    }
                }
            }
            if (mBaseCanvas != null)
            {
                mBaseCanvas.InvalidateArrange();
                mBaseCanvas.UpdateLayout();
                mBaseCanvas.InvalidateVisual();
            }
        }
Exemple #7
0
 private void NodeCollapsed(DiagramNode sender, RoutedEventArgs eventArguments)
 {
     foreach (DiagramNode child in sender.DiagramChildren)
     {
         child.Visibility = Visibility.Collapsed;
         foreach (DiagramNode grandChildren in child.DiagramChildren)
         {
             grandChildren.Visibility = Visibility.Collapsed;
         }
     }
     if (mBaseCanvas != null)
     {
         mBaseCanvas.InvalidateArrange();
         mBaseCanvas.UpdateLayout();
         mBaseCanvas.InvalidateVisual();
     }
 }
Exemple #8
0
 private void MakeChildrenVisible(DiagramNode sender)
 {
     foreach (DiagramNode child in sender.DiagramChildren)
     {
         if (mBaseCanvas != null && !mBaseCanvas.Children.Contains(child))
         {
             mBaseCanvas.Children.Add(child);
         }
         child.Visibility = Visibility.Visible;
     }
     if (mBaseCanvas != null)
     {
         mBaseCanvas.InvalidateArrange();
         mBaseCanvas.UpdateLayout();
         mBaseCanvas.InvalidateVisual();
     }
 }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodeName"></param>
        /// <param name="treeParent"></param>
        /// <param name="imageUrl"></param>
        /// <param name="itemDescription"></param>
        public DiagramNode(string nodeName, DiagramNode treeParent,
                           string imageUrl, string itemDescription)
        {
            CommandBindings.Add(new CommandBinding(ExpandCommand, ExpandCommand_Executed, ExpandCommand_CanExecute));
            CommandBindings.Add(new CommandBinding(CollapseCommand, CollapseCommand_Executed, CollapseCommand_CanExecute));

            ToolTip        = itemDescription;
            mDiagramParent = treeParent;
            NodeName       = nodeName;
            if (treeParent != null)
            {
                mDiagramParent.mDiagramChildren.Add(this);
            }
            BitmapImage image = new BitmapImage();

            image.BeginInit();
            image.UriSource = new Uri(imageUrl, UriKind.RelativeOrAbsolute);
            image.EndInit();
            Icon = image;
        }
Exemple #10
0
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);
            foreach (UIElement uiElement in Children)
            {
                if (uiElement is DiagramNode)
                {
                    DiagramNode node = (DiagramNode)uiElement;

                    if (node.Visibility == Visibility.Visible)
                    {
                        if (node.DiagramParent != null &&
                            node.DiagramParent.Visibility == Visibility.Visible)
                        {
                            dc.DrawLine(new Pen(Brushes.Black, 2.0),
                                        node.Location, node.DiagramParent.Location);
                        }
                    }
                }
            }
        }
Exemple #11
0
        private static double CalculateLegDistance(DiagramNode sender, double angleBetweenChildren)
        {
            double legDistance             = 1.0;
            double childToChildMinDistance = 1.0;

            foreach (DiagramNode child in sender.DiagramChildren)
            {
                legDistance = Math.Max(legDistance, sender.BoundingCircle + child.BoundingCircle);
                foreach (DiagramNode otherChild in sender.DiagramChildren)
                {
                    if (otherChild != child)
                    {
                        childToChildMinDistance = Math.Max(childToChildMinDistance, child.BoundingCircle + otherChild.BoundingCircle);
                    }
                }
            }

            legDistance = Math.Max(
                legDistance,
                (childToChildMinDistance / 2.0) / Math.Sin(angleBetweenChildren / 2.0));
            return(legDistance);
        }
Exemple #12
0
        private double CalculateStartAngle(DiagramNode node)
        {
            if (node == mRootNode)
            {
                return(0.0);
            }
            Vector parentToNode = node.Location - node.DiagramParent.Location;

            parentToNode.Normalize();
            Vector leftToRight = new Vector(1.0, 0.0);
            double angle       = Vector.AngleBetween(parentToNode, leftToRight);

            if (angle < 0)
            {
                angle = 360 - angle;
            }

            if (node.DiagramChildren.Count > 1)
            {
                if (node.Location.Y < node.DiagramParent.Location.Y)
                {
                    if (node.Location.X > node.DiagramParent.Location.X)
                    {
                        angle -= 180;
                    }
                    else
                    {
                        angle -= 270;
                    }
                }
                else
                {
                    angle -= 90;
                }
            }

            return(Math.PI * angle / 180.0);
        }