IfcDoc.FormEdit.toolStripMenuItemDiagramFormatTree_Click C# (CSharp) Method

toolStripMenuItemDiagramFormatTree_Click() private method

private toolStripMenuItemDiagramFormatTree_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void toolStripMenuItemDiagramFormatTree_Click(object sender, EventArgs e)
        {
            IDocTreeHost docDefinition = (IDocTreeHost)this.treeView.SelectedNode.Tag;
            List<DocLine> list = docDefinition.Tree;

            // add/remove tree
            if (list != null)
            {
                if (list.Count > 0 && list[0].Definition == null)
                {
                    // remove tree(s)
                    for (int iTree = list.Count - 1; iTree >= 0; iTree--)
                    {
                        DocLine docTree = list[0];
                        for(int iNode = docTree.Tree.Count-1; iNode >= 0; iNode--)
                        {
                            DocLine docNode = docTree.Tree[iNode];
                            docTree.Tree.RemoveAt(iNode);
                            list.Add(docNode);
                        }

                        list.RemoveAt(iTree);
                        docTree.Delete();
                    }

                    this.ctlExpressG.LayoutDefinition((DocDefinition)docDefinition);
                }
                else if(list.Count > 0)
                {
                    // add tree -- make node half-way along first link

                    // clean up any page refs
                    for(int i = 0; i < list.Count; i++)
                    {
                        if(list[i].Definition is DocPageSource)
                        {
                            DocPageSource docPageSource = (DocPageSource)list[i].Definition;

                            // does page source still exist
                            bool exists = false;
                            foreach(DocPageTarget docPageTarget in this.ctlExpressG.Schema.PageTargets)
                            {
                                if(docPageTarget.Sources.Contains(docPageSource))
                                {
                                    exists = true;
                                    break;
                                }
                            }

                            if(!exists)
                            {
                                string[] parts = docPageSource.Name.Split();
                                if (parts.Length == 2)
                                {
                                    DocDefinition docDef = this.ctlExpressG.Schema.GetDefinition(parts[1]);
                                    if (docDef != null)
                                    {
                                        list[i].Definition.Delete();
                                        list[i].Definition = docDef;
                                    }
                                }
                            }
                        }
                    }

                    DocLine docNode = list[0];
                    DocPoint docPos = new DocPoint(
                        (docNode.DiagramLine[0].X + docNode.DiagramLine[docNode.DiagramLine.Count - 1].X) * 0.5,
                        (docNode.DiagramLine[0].Y + docNode.DiagramLine[docNode.DiagramLine.Count - 1].Y) * 0.5);

                    DocLine docTree = new DocLine();
                    docTree.DiagramLine.Add(new DocPoint()); // will get positioned upon layout
                    docTree.DiagramLine.Add(new DocPoint()); // will get positioned upon layout
                    docTree.DiagramLine.Add(docPos);

                    for(int iNode = list.Count-1; iNode >= 0; iNode--)
                    {
                        docTree.Tree.Add(list[iNode]);
                        list.RemoveAt(iNode);
                    }

                    list.Add(docTree);

                    this.ctlExpressG.LayoutDefinition((DocDefinition)docDefinition);
                    foreach(DocLine docLine in docTree.Tree)
                    {
                        this.ctlExpressG.LayoutDefinition(docLine.Definition);
                    }
                }
            }

            this.ctlExpressG.Redraw();
        }
FormEdit