Exemplo n.º 1
0
        protected override void InitDiagram()
        {
            base.InitDiagram();

            m_DrawingDocument.HistoryService.Pause();
            try
            {
                NDrawing drawing    = m_DrawingDocument.Content;
                NPage    activePage = drawing.ActivePage;

                // Hide grid and ports
                drawing.ScreenVisibility.ShowGrid  = false;
                drawing.ScreenVisibility.ShowPorts = false;

                // Create all shapes
                NBrainstormingShapeFactory factory = new NBrainstormingShapeFactory();
                factory.DefaultSize = new NSize(60, 60);

                for (int i = 0; i < factory.ShapeCount; i++)
                {
                    NShape shape = factory.CreateShape(i);
                    shape.HorizontalPlacement = ENHorizontalPlacement.Center;
                    shape.VerticalPlacement   = ENVerticalPlacement.Center;
                    shape.HorizontalPlacement = ENHorizontalPlacement.Center;
                    shape.VerticalPlacement   = ENVerticalPlacement.Center;
                    shape.Text = factory.GetShapeInfo(i).Name;
                    MoveTextBelowShape(shape);
                    activePage.Items.Add(shape);
                }

                // Arrange them
                NList <NShape> shapes        = activePage.GetShapes(false);
                NLayoutContext layoutContext = new NLayoutContext();
                layoutContext.BodyAdapter  = new NShapeBodyAdapter(m_DrawingDocument);
                layoutContext.GraphAdapter = new NShapeGraphAdapter();
                layoutContext.LayoutArea   = activePage.GetContentEdge();

                NTableFlowLayout tableLayout = new NTableFlowLayout();
                tableLayout.HorizontalSpacing = 30;
                tableLayout.VerticalSpacing   = 50;
                tableLayout.Direction         = ENHVDirection.LeftToRight;
                tableLayout.MaxOrdinal        = 5;

                tableLayout.Arrange(shapes.CastAll <object>(), layoutContext);

                // size page to content
                activePage.Layout.ContentPadding = new NMargins(40);
                activePage.SizeToContent();
            }
            finally
            {
                m_DrawingDocument.HistoryService.Resume();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Arranges the shapes in the active page.
        /// </summary>
        protected virtual void ArrangeDiagram()
        {
            // get all top-level shapes that reside in the active page
            NPage          activePage = m_DrawingDocument.Content.ActivePage;
            NList <NShape> shapes     = activePage.GetShapes(false);

            // create a layout context and use it to arrange the shapes using the current layout
            NDrawingLayoutContext layoutContext = new NDrawingLayoutContext(m_DrawingDocument, activePage);

            m_Layout.Arrange(shapes.CastAll <object>(), layoutContext);

            // size the page to the content size
            activePage.SizeToContent();
        }
        /// <summary>
        /// Arranges the shapes in the active page.
        /// </summary>
        private void ArrangeDiagram()
        {
            // Create and configure a layout
            NLayeredGraphLayout layout = new NLayeredGraphLayout();

            // Get all top-level shapes that reside in the active page
            NPage          activePage = m_DrawingDocument.Content.ActivePage;
            NList <NShape> shapes     = activePage.GetShapes(false);

            // Create a layout context and use it to arrange the shapes using the current layout
            NDrawingLayoutContext layoutContext = new NDrawingLayoutContext(m_DrawingDocument, activePage);

            layout.Arrange(shapes.CastAll <object>(), layoutContext);

            // Size the page to the content size
            activePage.SizeToContent();
        }
Exemplo n.º 4
0
        protected NGroup CreateNetwork(NPoint location, string labelText)
        {
            bool       rectValid  = false;
            NRectangle rect       = NRectangle.Zero;
            NPage      activePage = m_DrawingDocument.Content.ActivePage;

            NList <NShape> shapes = activePage.GetShapes(false);

            for (int i = 0; i < shapes.Count; i++)
            {
                NRectangle bounds = shapes[i].GetAlignBoxInPage();
                if (rectValid)
                {
                    rect = NRectangle.Union(rect, bounds);
                }
                else
                {
                    rect      = bounds;
                    rectValid = true;
                }
            }

            if (rectValid)
            {
                // determine how much is out of layout area
            }

            // create computer1
            NShape computer1 = CreateComputer();

            computer1.SetBounds(0, 0, computer1.Width, computer1.Height);

            // create computer2
            NShape computer2 = CreateComputer();

            computer2.SetBounds(150, 0, computer2.Width, computer2.Height);

            // create computer3
            NShape computer3 = CreateComputer();

            computer3.SetBounds(75, 120, computer3.Width, computer3.Height);

            // create the group that contains the comptures
            NGroup      group      = new NGroup();
            NBatchGroup batchGroup = new NBatchGroup(m_DrawingDocument);

            batchGroup.Build(computer1, computer2, computer3);
            batchGroup.Group(m_DrawingDocument.Content.ActivePage, out group);

            // connect the computers in the network
            ConnectComputers(computer1, computer2, group);
            ConnectComputers(computer2, computer3, group);
            ConnectComputers(computer3, computer1, group);

            // insert a frame
            NDrawRectangle drawRect = new NDrawRectangle(0, 0, 1, 1);

            drawRect.Relative = true;
            group.Geometry.Add(drawRect);

            // change group fill style
            group.Geometry.Fill = new NStockGradientFill(ENGradientStyle.FromCenter, ENGradientVariant.Variant2, NColor.Gainsboro, NColor.White);

            // reposition and resize the group
            group.SetBounds(location.X, location.Y, group.Width, group.Height);

            // set label text
            group.TextBlock.Text = labelText;



            return(group);
        }
        /// <summary>
        /// Creates a triangular grid diagram with the specified count of levels
        /// </summary>
        /// <param name="levels"></param>
        private void CreateTriangularGridDiagram(int levels)
        {
            // clean up the active page
            NPage activePage = m_DrawingDocument.Content.ActivePage;

            activePage.Items.Clear();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory();

            basicShapesFactory.DefaultSize = new NSize(30, 30);

            NConnectorShapeFactory connectorShapesFactory = new NConnectorShapeFactory();

            NShape             cur = null, prev = null;
            NRoutableConnector edge          = null;
            NList <NShape>     curRowShapes  = null;
            NList <NShape>     prevRowShapes = null;

            for (int level = 1; level < levels; level++)
            {
                curRowShapes = new NList <NShape>();

                for (int i = 0; i < level; i++)
                {
                    cur = basicShapesFactory.CreateShape(ENBasicShape.Circle);
                    cur.Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(192, 194, 194), new NColor(129, 133, 133));
                    cur.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));
                    activePage.Items.Add(cur);

                    // connect with prev
                    if (i > 0)
                    {
                        edge = new NRoutableConnector();
                        edge.MakeLine();
                        activePage.Items.Add(edge);

                        edge.GlueBeginToShape(prev);
                        edge.GlueEndToShape(cur);
                    }

                    // connect with ancestors
                    if (level > 1)
                    {
                        if (i < prevRowShapes.Count)
                        {
                            edge = new NRoutableConnector();
                            edge.MakeLine();
                            activePage.Items.Add(edge);

                            edge.GlueBeginToShape(prevRowShapes[i]);
                            edge.GlueEndToShape(cur);
                        }

                        if (i > 0)
                        {
                            edge = new NRoutableConnector();
                            edge.MakeLine();
                            activePage.Items.Add(edge);

                            edge.GlueBeginToShape(prevRowShapes[i - 1]);
                            edge.GlueEndToShape(cur);
                        }
                    }

                    // fix the three corner vertices
                    if (level == 1 || (level == levels - 1 && (i == 0 || i == level - 1)))
                    {
                        NForceDirectedGraphLayout.SetXMoveable(cur, false);
                        NForceDirectedGraphLayout.SetYMoveable(cur, false);

                        cur.Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(251, 203, 156), new NColor(247, 150, 56));
                        cur.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));
                    }

                    curRowShapes.Add(cur);
                    prev = cur;
                }

                prevRowShapes = curRowShapes;
            }

            // send all edges to back
            NBatchReorder batchReorder = new NBatchReorder(m_DrawingDocument);

            batchReorder.Build(activePage.GetShapes(false, NDiagramFilters.ShapeType1D).CastAll <NDiagramItem>());
            batchReorder.SendToBack(activePage);

            // arrange the elements
            ArrangeDiagram();
        }
        /// <summary>
        /// Creates a random barycenter diagram with the specified settings
        /// </summary>
        /// <param name="fixedCount">number of fixed vertices (must be larger than 3)</param>
        /// <param name="freeCount">number of free vertices</param>
        private void CreateRandomBarycenterDiagram(int fixedCount, int freeCount)
        {
            if (fixedCount < 3)
            {
                throw new ArgumentException("Needs at least three fixed vertices");
            }

            // clean up the active page
            NPage activePage = m_DrawingDocument.Content.ActivePage;

            activePage.Items.Clear();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory();

            basicShapesFactory.DefaultSize = new NSize(30, 30);

            NConnectorShapeFactory connectorsShapesFactory = new NConnectorShapeFactory();

            // create the fixed vertices
            NShape[] fixedShapes = new NShape[fixedCount];

            for (int i = 0; i < fixedCount; i++)
            {
                fixedShapes[i] = basicShapesFactory.CreateShape(ENBasicShape.Circle);

                //((NDynamicPort)fixedShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                fixedShapes[i].Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(251, 203, 156), new NColor(247, 150, 56));
                fixedShapes[i].Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));

                // setting the ForceXMoveable and ForceYMoveable properties to false
                // specifies that the layout cannot move the shape in both X and Y directions
                NForceDirectedGraphLayout.SetXMoveable(fixedShapes[i], false);
                NForceDirectedGraphLayout.SetYMoveable(fixedShapes[i], false);

                activePage.Items.AddChild(fixedShapes[i]);
            }

            // create the free vertices
            NShape[] freeShapes = new NShape[freeCount];
            for (int i = 0; i < freeCount; i++)
            {
                freeShapes[i] = basicShapesFactory.CreateShape(ENBasicShape.Circle);
                freeShapes[i].Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(192, 194, 194), new NColor(129, 133, 133));
                freeShapes[i].Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));
                activePage.Items.AddChild(freeShapes[i]);
            }

            // link the fixed shapes in a circle
            for (int i = 0; i < fixedCount; i++)
            {
                NRoutableConnector connector = new NRoutableConnector();
                connector.MakeLine();
                activePage.Items.AddChild(connector);

                if (i == 0)
                {
                    connector.GlueBeginToShape(fixedShapes[fixedCount - 1]);
                    connector.GlueEndToShape(fixedShapes[0]);
                }
                else
                {
                    connector.GlueBeginToShape(fixedShapes[i - 1]);
                    connector.GlueEndToShape(fixedShapes[i]);
                }
            }

            // link each free shape with two different random fixed shapes
            Random rnd = new Random();

            for (int i = 0; i < freeCount; i++)
            {
                int firstFixed  = rnd.Next(fixedCount);
                int secondFixed = (firstFixed + rnd.Next(fixedCount / 3) + 1) % fixedCount;

                // link with first fixed
                NRoutableConnector lineShape = new NRoutableConnector();
                lineShape.MakeLine();
                activePage.Items.AddChild(lineShape);

                lineShape.GlueBeginToShape(freeShapes[i]);
                lineShape.GlueEndToShape(fixedShapes[firstFixed]);

                // link with second fixed
                lineShape = new NRoutableConnector();
                lineShape.MakeLine();
                activePage.Items.AddChild(lineShape);

                lineShape.GlueBeginToShape(freeShapes[i]);
                lineShape.GlueEndToShape(fixedShapes[secondFixed]);
            }

            // link each free shape with another free shape
            for (int i = 1; i < freeCount; i++)
            {
                NRoutableConnector connector = new NRoutableConnector();
                connector.MakeLine();
                activePage.Items.AddChild(connector);

                connector.GlueBeginToShape(freeShapes[i - 1]);
                connector.GlueEndToShape(freeShapes[i]);
            }

            // send all edges to back
            NBatchReorder batchReorder = new NBatchReorder(m_DrawingDocument);

            batchReorder.Build(activePage.GetShapes(false, NDiagramFilters.ShapeType1D).CastAll <NDiagramItem>());
            batchReorder.SendToBack(activePage);

            // arrange the elements
            ArrangeDiagram();
        }