private void ConnectShapes(NExpandableShape fromShape, NExpandableShape toShape)
        {
            NLineShape connector = new NLineShape();

            connector.StyleSheetName = NDR.NameConnectorsStyleSheet;

            document.ActiveLayer.AddChild(connector);
            connector.FromShape = fromShape;
            connector.ToShape   = toShape;
        }
        protected NExpandableShape CreateVertex(string text)
        {
            NExpandableShape vertex = new NExpandableShape();

            vertex.Width  = 75;
            vertex.Height = 75;
            vertex.Text   = text;
            document.ActiveLayer.AddChild(vertex);
            return(vertex);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="expandState"></param>
        public void Expand(bool expandState)
        {
            // expand or collapse in a single transation
            StartTransaction(expandState? "Expand Tree": "Collapse Tree");

            // mark shape as expanded
            Expanded = expandState;

            // show/hide the plus or minus
            NExpandCollapseCheck check = GetExpandCollapseCheck();

            ((NPathPrimitive)check.Primitives.GetChildAt(1)).Visible = !expandState;
            ((NPathPrimitive)check.Primitives.GetChildAt(2)).Visible = expandState;

            // show/hide all outgoing shapes
            NNodeList nodes = GetOutgoingShapes();

            for (int i = 0; i < nodes.Count; i++)
            {
                NShape shape = (nodes[i] as NShape);
                shape.Visible = expandState;
            }

            // show/hide all destination shapes
            nodes = GetDestinationShapes();
            for (int i = 0; i < nodes.Count; i++)
            {
                NShape shape = (nodes[i] as NShape);
                shape.Visible = expandState;
            }

            // expand/collapse the destination shapes
            for (int i = 0; i < nodes.Count; i++)
            {
                NExpandableShape expandableShape = (nodes[i] as NExpandableShape);
                if (expandableShape != null)
                {
                    expandableShape.Expand(expandState);
                }
            }

            // commit the transaction
            Commit();
        }
        private void InitDocument()
        {
            // all shapes will have shadow dropped below document content
            document.Style.ShadowStyle.Type       = ShadowType.GaussianBlur;
            document.Style.ShadowStyle.Offset     = new NPointL(5, 5);
            document.Style.ShadowStyle.FadeLength = new NLength(5);
            document.ShadowsZOrder = ShadowsZOrder.BehindDocument;

            // root
            NExpandableShape company = CreateVertex("The Company");

            // products branch
            NExpandableShape products = CreateVertex("Products and Services");

            ConnectShapes(company, products);

            NExpandableShape product1 = this.CreateVertex("Product1");

            ConnectShapes(products, product1);

            NExpandableShape product2 = this.CreateVertex("Product2");

            ConnectShapes(products, product2);

            // how to reach
            NExpandableShape reach = CreateVertex("How to reach");

            ConnectShapes(company, reach);

            NExpandableShape phone = this.CreateVertex("Phone");

            ConnectShapes(reach, phone);

            NExpandableShape fax = this.CreateVertex("Fax");

            ConnectShapes(reach, fax);

            NExpandableShape website = this.CreateVertex("Website");

            ConnectShapes(reach, website);

            // research
            NExpandableShape research = CreateVertex("Research");

            ConnectShapes(company, research);

            NExpandableShape tech = this.CreateVertex("Techinical");

            ConnectShapes(research, tech);

            NExpandableShape marketing = this.CreateVertex("Marketing");

            ConnectShapes(research, marketing);

            NExpandableShape newTech = this.CreateVertex("New Tech");

            ConnectShapes(research, newTech);

            NNodeList nodes = new NNodeList();

            nodes.Add(company);

            // create a layout context
            NLayoutContext layoutContext = new NLayoutContext();

            layoutContext.BodyAdapter          = new NShapeBodyAdapter(document);
            layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document);
            layoutContext.GraphAdapter         = new NShapeGraphAdapter();

            // first apply a layered tree layout
            // to set a start position of the shapes as a simple tree
            NTreeLayout treeLayout = new NLayeredTreeLayout();

            treeLayout.Layout(nodes, layoutContext);

            // then apply a symmetrical layout to layout them in a ring fasion
            NSymmetricalLayout symmetricalLayout = new NSymmetricalLayout();

            symmetricalLayout.DesiredDistanceForce.DesiredDistance = 100;
            symmetricalLayout.Layout(nodes, layoutContext);

            // size the document to the content (note that we use irregular margins)
            document.SizeToContent(new NSizeF(100, 100), new Nevron.Diagram.NMargins(20, 20, 50, 20));

            // add title spanning the entire document width
            NTextShape text = new NTextShape("Company Structure", new NRectangleF(document.Bounds.X + 5, document.Bounds.Y + 5, document.Width - 10, 50));

            text.Style.TextStyle = new NTextStyle(new Font("Times New Roman", 23, FontStyle.Bold));
            document.ActiveLayer.AddChild(text);
        }