IfcDoc.FormEdit.ctlExpressG_LinkOperation C# (CSharp) Method

ctlExpressG_LinkOperation() private method

private ctlExpressG_LinkOperation ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void ctlExpressG_LinkOperation(object sender, EventArgs e)
        {
            if (this.ctlExpressG.Highlight is DocDefinition)
            {
                DocDefinition docDefinition = (DocDefinition)this.ctlExpressG.Highlight;
                if(e == null && docDefinition is DocEntity)
                {
                    DocEntity docEntity = (DocEntity)docDefinition;

                    // link subtype (either from entity or entity reference)
                    docEntity.BaseDefinition = this.ctlExpressG.Selection.Name;

                    DocLine docLine = new DocLine();
                    docLine.DiagramLine.Add(new DocPoint());
                    docLine.DiagramLine.Add(new DocPoint());
                    docLine.DiagramLine.Add(new DocPoint());
                    docLine.Definition = docDefinition;

                    List<DocLine> tree = null;
                    if (this.ctlExpressG.Selection is DocEntity)
                    {
                        DocEntity docSuper = (DocEntity)this.ctlExpressG.Selection;
                        DocSubtype docSub = new DocSubtype();
                        docSub.DefinedType = docEntity.Name;
                        docSuper.Subtypes.Add(docSub);

                        tree = docSuper.Tree;
                    }
                    else if (this.ctlExpressG.Selection is DocDefinitionRef)
                    {
                        tree = ((DocDefinitionRef)this.ctlExpressG.Selection).Tree;
                    }

                    if(tree != null)
                    {
                        if (tree.Count > 0 && tree[0].Definition == null)
                        {
                            // existing tree structure
                            tree[0].Tree.Add(docLine);
                        }
                        else
                        {
                            // no tree structure
                            tree.Add(docLine);
                        }
                    }

                    this.ctlExpressG.LayoutDefinition((DocDefinition)this.ctlExpressG.Selection);
                    this.ctlExpressG.LayoutDefinition(docDefinition);
                    this.ctlExpressG.Redraw();
                }
                else if (this.ctlExpressG.Selection is DocEntity)
                {
                    // create an attribute

                    DocEntity docEntity = (DocEntity)this.ctlExpressG.Selection;

                    DocAttribute docAttr = new DocAttribute();
                    docAttr.Name = "Attribute";
                    docAttr.Definition = docDefinition;
                    docAttr.DefinedType = docAttr.Definition.Name;
                    CtlExpressG.LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);

                    docAttr.DiagramLabel = new DocRectangle();
                    docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                    docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y;
                    docAttr.DiagramLabel.Width = 400.0;
                    docAttr.DiagramLabel.Height = 100.0;

                    docEntity.Attributes.Add(docAttr);

                    TreeNode tnParent = this.treeView.SelectedNode;
                    this.treeView.SelectedNode = this.LoadNode(tnParent, docAttr, docAttr.ToString(), false);
                    toolStripMenuItemEditRename_Click(this, e);
                }
                else if (this.ctlExpressG.Selection is DocSelect)
                {
                    // link select
                    DocSelect docSelect = (DocSelect)this.ctlExpressG.Selection;

                    // link definition
                    DocSelectItem docItem = new DocSelectItem();
                    //docItem.Definition = docDefinition;
                    docItem.Name = docDefinition.Name;
                    //CtlExpressG.LayoutLine(docSelect, docItem.Definition, docItem.DiagramLine);
                    docSelect.Selects.Add(docItem);

                    // link lines
                    DocLine docLine = new DocLine();
                    docLine.Definition = docDefinition;
                    CtlExpressG.LayoutLine(docSelect, docDefinition, docLine.DiagramLine);
                    docSelect.Tree.Add(docLine);

                    TreeNode tnParent = this.treeView.SelectedNode;
                    this.treeView.SelectedNode = this.LoadNode(tnParent, docItem, docItem.ToString(), false);
                }
                else if (this.ctlExpressG.Selection is DocDefined)
                {
                    // link defined
                    DocDefined docDefined = (DocDefined)this.ctlExpressG.Selection;
                    docDefined.Definition = docDefinition;
                    docDefined.DefinedType = docDefined.Definition.Name;
                    CtlExpressG.LayoutLine(docDefined, docDefined.Definition, docDefined.DiagramLine);
                }
            }
        }
FormEdit