Exemple #1
0
        // Initializes most of the MindMapData for nodes created by doubleclick and right click
        private MindMapData SetUpChild(MindMapData childdata, MindMapData parentdata)
        {
            childdata.Text      = "New Node";
            childdata.Color     = "White";
            childdata.ParentKey = parentdata.Key;

            if (parentdata.LinkColor == "LightGray")
            {
                Random r = new Random();
                childdata.LinkColor = myColors[r.Next(myColors.Count())];
            }
            else
            {
                childdata.LinkColor = parentdata.LinkColor;
            }
            // we need the root's location to set the direction of the layout
            MindMapData rootData = (MindMapData)myDiagram.Model.FindNodeByKey("/");

            if (rootData.Location.X < childdata.Location.X)
            {
                childdata.LayoutId = "Right";
                childdata.ToSpot   = "MiddleLeft";
                childdata.FromSpot = "MiddleRight";
            }
            else
            {
                childdata.LayoutId = "Left";
                childdata.ToSpot   = "MiddleRight";
                childdata.FromSpot = "MiddleLeft";
            }

            return(childdata);
        }
Exemple #2
0
        // Used when a node is created by right clicking
        private void CreateChild(object sender, RoutedEventArgs e)
        {
            FrameworkElement elt = myDiagram.Panel.FindElementAt <FrameworkElement>(myDiagram.LastMousePointInModel,
                                                                                    x => x as FrameworkElement, x => true, SearchLayers.Nodes);
            Node n = null;

            if (e.OriginalSource is Button)
            {
                Adornment ad = Part.FindAncestor <Adornment>(e.OriginalSource as UIElement);
                if (ad == null)
                {
                    return;
                }
                n = ad.AdornedPart as Node;
            }
            else
            {
                n = Part.FindAncestor <Node>(elt);
            }
            if (n != null && ((MindMapData)n.Data).Key != "/")
            {
                // always make changes within a transaction
                myDiagram.StartTransaction("CreateNode");
                MindMapData childdata  = new MindMapData();
                MindMapData parentdata = (MindMapData)n.Data;
                childdata.Location = new Point(parentdata.Location.X, parentdata.Location.Y);
                childdata.Key      = parentdata.Key + "/";
                SetUpChild(childdata, parentdata);
                myDiagram.Model.AddNode(childdata);
                myDiagram.CommitTransaction("CreateNode");
            }
        }
Exemple #3
0
        private void FlipChildren(Node n, String direction)
        {
            n.LayoutId = direction;
            IEnumerable <Node> collectedNodes = n.FindTreeParts(EffectiveCollectionInclusions.SubTree).OfType <Node>();
            IEnumerable <Link> collectedLinks = n.FindTreeParts(EffectiveCollectionInclusions.SubTree).OfType <Link>();

            foreach (Node child in collectedNodes)
            {
                MindMapData d = (MindMapData)child.Data;
                child.LayoutId = direction;
                if (direction == "Left")
                {
                    d.ToSpot   = "MiddleRight";
                    d.FromSpot = "MiddleLeft";
                }
                else
                {
                    d.ToSpot   = "MiddleLeft";
                    d.FromSpot = "MiddleRight";
                }
            }

            //select the layout to use, either Right or Left
            var layout =
                (from x in ((MultiLayout)myDiagram.Layout).Layouts.OfType <TreeLayout>()
                 where ((TreeLayout)x).Id == direction
                 select x).FirstOrDefault();

            if (layout != null)
            {
                layout.DoLayout(collectedNodes, collectedLinks);
            }
        }
Exemple #4
0
        // When a node is created with ClickCreatingTool we must do some additional layout
        void myDiagram_NodeCreated(object sender, DiagramEventArgs e)
        {
            Node        n          = (Node)e.Part;
            MindMapData data       = (MindMapData)n.Data;
            MindMapData parentData = (MindMapData)myDiagram.Model.FindNodeByKey("/");

            n.Data = SetUpChild(data, parentData);
        }
Exemple #5
0
        // if a node next to root moves to the other side, change its layout
        private void myDiagram_SelectionMoved(object sender, DiagramEventArgs e)
        {
            // find all nodes in the selection that are children of the root
            var rootChildren = myDiagram.SelectedParts.OfType <Node>().Where(n => ((MindMapData)n.Data).ParentKey == "/");

            foreach (Node n in rootChildren)
            {
                MindMapData root  = (MindMapData)myDiagram.Model.FindNodeByKey("/");
                double      rootX = root.Location.X;
                double      nodeX = n.Location.X;
                if (rootX < nodeX && n.LayoutId != "Right")
                {
                    FlipChildren(n, "Right");
                }
                else if (rootX > nodeX && n.LayoutId != "Left")
                {
                    FlipChildren(n, "Left");
                }
            }
        }