Exemplo n.º 1
0
        private void InitDocument()
        {
            document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8));

            NSimpleNetworkShapesFactory factory = new NSimpleNetworkShapesFactory(document);

            factory.DefaultSize = new NSizeF(80, 60);

            int count = factory.ShapesCount;

            for (int i = 0; i < count; i++)
            {
                // create a shape
                NShape shape = factory.CreateShape(i);
                shape.Style.InteractivityStyle = new NInteractivityStyle(shape.Name);

                // add it to the active layer
                document.ActiveLayer.AddChild(shape);
            }

            // layout the shapes in the active layer using a table layout
            NTableLayout layout = new NTableLayout();

            // setup the table layout
            layout.Direction     = LayoutDirection.LeftToRight;
            layout.ConstrainMode = CellConstrainMode.Ordinal;
            layout.MaxOrdinal    = 5;
            layout.HorizontalContentPlacement = ContentPlacement.Center;
            layout.VerticalContentPlacement   = ContentPlacement.Center;
            layout.VerticalSpacing            = 20;
            layout.HorizontalSpacing          = 20;

            // get the shapes to layout
            NNodeList shapes = document.ActiveLayer.Children(NFilters.Shape2D);

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

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

            // layout the shapes
            layout.Layout(shapes, layoutContext);

            // resize document to fit all shapes
            document.SizeToContent();
        }
        private void InitDocument()
        {
            NSimpleNetworkShapesFactory networkShapes = new NSimpleNetworkShapesFactory();

            networkShapes.DefaultSize = new NSizeF(50, 50);
            int i;

            // create computers
            for (i = 0; i < 9; i++)
            {
                NShape computer = networkShapes.CreateShape(SimpleNetworkShapes.Computer);
                switch (i % 3)
                {
                case 0:
                    computer.Location = new NPointF(10, 10);
                    break;

                case 1:
                    computer.Location = new NPointF(110, 10);
                    break;

                case 2:
                    computer.Location = new NPointF(75, 110);
                    break;
                }

                document.ActiveLayer.AddChild(computer);
            }

            // link the computers
            for (i = 0; i < 3; i++)
            {
                NLineShape link = new NLineShape();
                link.StyleSheetName = NDR.NameConnectorsStyleSheet;
                document.ActiveLayer.AddChild(link);

                if (i == 0)
                {
                    link.FromShape = (NShape)document.ActiveLayer.GetChildAt(8);
                    link.ToShape   = (NShape)document.ActiveLayer.GetChildAt(0);
                }
                else
                {
                    link.FromShape = (NShape)document.ActiveLayer.GetChildAt(i * 3 - 1);
                    link.ToShape   = (NShape)document.ActiveLayer.GetChildAt(i * 3);
                }
            }

            // create three groups
            NNodeList   groupNodes1 = new NNodeList();
            NBatchGroup batchGroup1 = new NBatchGroup(document);

            groupNodes1.Add(document.ActiveLayer.GetChildAt(0));
            groupNodes1.Add(document.ActiveLayer.GetChildAt(1));
            groupNodes1.Add(document.ActiveLayer.GetChildAt(2));
            batchGroup1.Build(groupNodes1);

            NNodeList   groupNodes2 = new NNodeList();
            NBatchGroup batchGroup2 = new NBatchGroup(document);

            groupNodes2.Add(document.ActiveLayer.GetChildAt(3));
            groupNodes2.Add(document.ActiveLayer.GetChildAt(4));
            groupNodes2.Add(document.ActiveLayer.GetChildAt(5));
            batchGroup2.Build(groupNodes2);

            NNodeList   groupNodes3 = new NNodeList();
            NBatchGroup batchGroup3 = new NBatchGroup(document);

            groupNodes3.Add(document.ActiveLayer.GetChildAt(6));
            groupNodes3.Add(document.ActiveLayer.GetChildAt(7));
            groupNodes3.Add(document.ActiveLayer.GetChildAt(8));
            batchGroup3.Build(groupNodes3);

            NGroup[] groups = new NGroup[3];
            batchGroup1.Group(document.ActiveLayer, false, out groups[0]);
            batchGroup2.Group(document.ActiveLayer, false, out groups[1]);
            batchGroup3.Group(document.ActiveLayer, false, out groups[2]);

            // add expand-collapse decorator and frame decorator to each group
            for (i = 0; i < groups.Length; i++)
            {
                NGroup group = groups[i];

                // because groups are created after the link we want to ensure
                // that they are behind so that the links are not obscured
                group.SendToBack();

                // create the decorators collection
                group.CreateShapeElements(ShapeElementsMask.Decorators);

                // create a frame decorator
                // we want the user to be able to select the shape when the frame is hit
                NFrameDecorator frameDecorator = new NFrameDecorator();
                frameDecorator.ShapeHitTestable = true;
                frameDecorator.Header.Text      = "Network " + i.ToString();
                group.Decorators.AddChild(frameDecorator);

                // create an expand collapse decorator
                NExpandCollapseDecorator expandCollapseDecorator = new NExpandCollapseDecorator();
                group.Decorators.AddChild(expandCollapseDecorator);

                // update the model bounds so that the computeres
                // are inside the specified padding
                group.Padding = new Nevron.Diagram.NMargins(5, 5, 30, 5);
                group.UpdateModelBounds();
                group.AutoUpdateModelBounds = true;
            }

            // layout them with a table layout
            NLayoutContext context = new NLayoutContext();

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

            NTableLayout layout = new NTableLayout();

            layout.ConstrainMode     = CellConstrainMode.Ordinal;
            layout.MaxOrdinal        = 2;
            layout.HorizontalSpacing = 50;
            layout.VerticalSpacing   = 50;
            layout.Layout(document.ActiveLayer.Children(null), context);

            document.SizeToContent(NSizeF.Empty, document.AutoBoundsPadding);
            document.AutoBoundsMode = AutoBoundsMode.AutoSizeToContent;
        }