private string LayoutShapes() { string result = String.Empty; try { this.Cursor = Cursors.WaitCursor; document.BeginInit(); NNodeList nodes = document.ActiveLayer.Children(NFilters.Shape2D); NLayoutContext layoutContext = new NDrawingLayoutContext(document); NLayout layout = (NLayout)cbLayout.SelectedItem; layout.Layout(nodes, layoutContext); document.SizeToContent(); document.EndInit(); result = layout.PerformanceInfo; } finally { this.Cursor = Cursors.Default; } return(result); }
protected override void InitDiagram() { base.InitDiagram(); // Create a group NGroup group = new NGroup(); m_DrawingDocument.Content.ActivePage.Items.Add(group); group.PinX = 300; group.PinY = 300; // Create some shapes and add them to the group NBasicShapeFactory factory = new NBasicShapeFactory(); NShape root = factory.CreateShape(ENBasicShape.Rectangle); root.Text = "Root"; group.Shapes.Add(root); NShape shape1 = factory.CreateShape(ENBasicShape.Circle); shape1.Text = "Circle 1"; group.Shapes.Add(shape1); NShape shape2 = factory.CreateShape(ENBasicShape.Circle); shape2.Text = "Circle 2"; group.Shapes.Add(shape2); NShape shape3 = factory.CreateShape(ENBasicShape.Circle); shape3.Text = "Circle 3"; group.Shapes.Add(shape3); // Connect the shapes ConnectShapes(root, shape1); ConnectShapes(root, shape2); ConnectShapes(root, shape3); // Update group bounds group.UpdateBounds(); // Create a layout context and configure the area you want the group to be arranged in. // The layout area is in page coordinates NDrawingLayoutContext layoutContext = new NDrawingLayoutContext(m_DrawingDocument, group); layoutContext.LayoutArea = new NRectangle(100, 100, 200, 200); // Layout the shapes in the group NRadialGraphLayout layout = new NRadialGraphLayout(); layout.Arrange(group.Shapes.ToArray(), layoutContext); // Update the group bounds group.UpdateBounds(); }
/// <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(); }
protected override void InitDiagram() { base.InitDiagram(); m_DrawingDocument.HistoryService.Pause(); try { NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; activePage.BackgroundFill = new NColorFill(NColor.LightGray); // Hide grid and ports drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; // Create all shapes NFlagShapeFactory factory = new NFlagShapeFactory(); 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.Text = factory.GetShapeInfo(i).Name; MoveTextBelowShape(shape); activePage.Items.Add(shape); } // Arrange them NList <NShape> shapes = activePage.GetShapes(false); NLayoutContext layoutContext = new NDrawingLayoutContext(m_DrawingDocument, activePage); NTableFlowLayout tableLayout = new NTableFlowLayout(); tableLayout.HorizontalSpacing = 70; 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(50); activePage.SizeToContent(); } finally { m_DrawingDocument.HistoryService.Resume(); } }
/// <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(); }
/// <summary> /// Overriden to create the tree template /// </summary> /// <param name="document">document in which to create the template</param> protected override void CreateTemplate(NDrawingDocument document) { // create the tree NList <NShape> elements = CreateTree(document); if (m_LayoutType == ENTreeLayoutType.None) { return; } // layout the tree NLayeredTreeLayout layout = new NLayeredTreeLayout(); // sync measurement unit layout.OrthogonalEdgeRouting = false; switch (m_LayoutType) { case ENTreeLayoutType.Layered: layout.VertexSpacing = m_fHorizontalSpacing; layout.LayerSpacing = m_fVerticalSpacing; break; case ENTreeLayoutType.LayeredLeftAligned: layout.VertexSpacing = m_fHorizontalSpacing; layout.LayerSpacing = m_fVerticalSpacing; layout.ParentPlacement.Anchor = ENParentAnchor.SubtreeNear; layout.ParentPlacement.Alignment = ENRelativeAlignment.Near; break; case ENTreeLayoutType.LayeredRightAligned: layout.VertexSpacing = m_fHorizontalSpacing; layout.LayerSpacing = m_fVerticalSpacing; layout.ParentPlacement.Anchor = ENParentAnchor.SubtreeFar; layout.ParentPlacement.Alignment = ENRelativeAlignment.Far; break; } // apply layout NDrawingLayoutContext context = new NDrawingLayoutContext(document, new NRectangle(Origin, NSize.Zero)); layout.Arrange(elements.CastAll <object>(), context); }
/// <summary> /// Overriden to create a random graph template in the specified document. /// </summary> /// <param name="document">The document to create a graph in.</param> protected override void CreateTemplate(NDrawingDocument document) { if (m_nEdgeCount < m_nVertexCount - 1) { throw new Exception("##The number of edges must be greater than or equal to the (number of vertices - 1) in order to generate a connected graph"); } if (m_nEdgeCount > MaxEdgeCount(m_nVertexCount)) { throw new Exception("##Too many edges wanted for the graph"); } int i; Random random = new Random(); NPage activePage = document.Content.ActivePage; NShape[] vertices = new NShape[m_nVertexCount]; NList <NPointI> edges = GetRandomMST(m_nVertexCount); NPointI edgeInfo; NSizeI minSize = m_MinVerticesSize.Round(); NSizeI maxSize = m_MaxVerticesSize.Round(); maxSize.Width++; maxSize.Height++; // Create the vertices for (i = 0; i < m_nVertexCount; i++) { vertices[i] = CreateVertex(m_VerticesShape); double width = random.Next(minSize.Width, maxSize.Width); double height = random.Next(minSize.Height, maxSize.Height); vertices[i].SetBounds(new NRectangle(0, 0, width, height)); activePage.Items.AddChild(vertices[i]); } // Generate the edges for (i = m_nVertexCount - 1; i < m_nEdgeCount; i++) { do { // Generate a new edge edgeInfo = new NPointI(random.Next(m_nVertexCount), random.Next(m_nVertexCount)); }while (edgeInfo.X == edgeInfo.Y || edges.Contains(edgeInfo) || edges.Contains(new NPointI(edgeInfo.Y, edgeInfo.X))); edges.Add(edgeInfo); } // Create the edges for (i = 0; i < m_nEdgeCount; i++) { edgeInfo = edges[i]; NShape edge = CreateEdge(ENConnectorShape.RoutableConnector); activePage.Items.AddChild(edge); edge.GlueBeginToGeometryIntersection(vertices[edgeInfo.X]); edge.GlueEndToShape(vertices[edgeInfo.Y]); } // Apply a table layout to the generated graph NTableFlowLayout tableLayout = new NTableFlowLayout(); tableLayout.MaxOrdinal = (int)Math.Sqrt(m_nVertexCount) + 1; tableLayout.HorizontalSpacing = m_VerticesSize.Width / 5; tableLayout.VerticalSpacing = m_VerticesSize.Width / 5; NDrawingLayoutContext context = new NDrawingLayoutContext(document, activePage); tableLayout.Arrange(new NList <object>(NArrayHelpers <NShape> .CastAll <object>(vertices)), context); }