private void InitDocument() { // get the drawing view document NDrawingDocument document = NDrawingView1.Document; document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; document.Style.FillStyle = new NColorFillStyle(Color.Linen); //document.BackgroundStyle.FrameStyle.Visible = false; // modify the connectors style sheet NStyleSheet styleSheet = (document.StyleSheets.GetChildByName(NDR.NameConnectorsStyleSheet, -1) as NStyleSheet); NTextStyle textStyle = new NTextStyle(); textStyle.BackplaneStyle.Visible = true; textStyle.BackplaneStyle.StandardFrameStyle.InnerBorderWidth = new NLength(0); styleSheet.Style.TextStyle = textStyle; styleSheet.Style.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.StartArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.EndArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); // create a stylesheet for the CPA shapes styleSheet = new NStyleSheet("CPA"); styleSheet.Style.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(102, 204, 255), Color.FromArgb(0, 128, 128)); document.StyleSheets.AddChild(styleSheet); // create a stylesheet for the CLIENT shapes styleSheet = new NStyleSheet("CLIENT"); styleSheet.Style.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(255, 102, 0), Color.FromArgb(255, 204, 0)); document.StyleSheets.AddChild(styleSheet); // create a stylesheet for the stripes styleSheet = new NStyleSheet("STRIPE"); styleSheet.Style.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.FromArgb(221, 221, 221)); styleSheet.Style.StrokeStyle = new NStrokeStyle(0, Color.White); document.StyleSheets.AddChild(styleSheet); // create a stylesheet for the ABC texts styleSheet = new NStyleSheet("ABC"); styleSheet.Style.TextStyle = new NTextStyle(new Font("Ariel", 12), Color.FromArgb(150, 150, 150)); document.StyleSheets.AddChild(styleSheet); float abcWidth = 150; // configure the document base.DefaultGridCellSize = new NSizeF(100, 70); base.DefaultGridSpacing = new NSizeF(30, 30); base.DefaultGridOrigin = new NPointF(60, 30); document.Bounds = new NRectangleF(0, 0, 1000, (6 * base.DefaultGridCellSize.Height) + (7 * base.DefaultGridSpacing.Height)); document.ShadowsZOrder = ShadowsZOrder.BehindLayer; // create the stripes NRectanglePath rect = new NRectanglePath(0, 0, document.Width, document.Height / 3); rect.StyleSheetName = "STRIPE"; document.ActiveLayer.AddChild(rect); rect = new NRectanglePath(0, document.Height / 3, document.Width, document.Height / 3); rect.StyleSheetName = "STRIPE"; document.ActiveLayer.AddChild(rect); rect = new NRectanglePath(0, 2 * document.Height / 3, document.Width, document.Height / 3); rect.StyleSheetName = "STRIPE"; document.ActiveLayer.AddChild(rect); // create A,B,C texts NTextPrimitive text = new NTextPrimitive("A", document.Width - abcWidth, 0, abcWidth, document.Height / 3); text.Mode = BoxTextMode.Stretch; rect.StyleSheetName = "ABC"; document.ActiveLayer.AddChild(text); text = new NTextPrimitive("B", document.Width - abcWidth, document.Height / 3, abcWidth, document.Height / 3); text.Mode = BoxTextMode.Stretch; rect.StyleSheetName = "ABC"; document.ActiveLayer.AddChild(text); text = new NTextPrimitive("C", document.Width - abcWidth, 2 * document.Height / 3, abcWidth, document.Height / 3); text.Mode = BoxTextMode.Stretch; rect.StyleSheetName = "ABC"; document.ActiveLayer.AddChild(text); // add stripe texts text = new NTextPrimitive("Sing up client", document.Width - abcWidth, document.Height / 3 - 50, abcWidth, 50); document.ActiveLayer.AddChild(text); text = new NTextPrimitive("Monthly Accounting Services", document.Width - abcWidth, 2 * document.Height / 3 - 50, abcWidth, 50); document.ActiveLayer.AddChild(text); text = new NTextPrimitive("Additional Services", document.Width - abcWidth, 3 * document.Height / 3 - 50, abcWidth, 50); document.ActiveLayer.AddChild(text); // create a layer for the foreground shapes NLayer layer = new NLayer(); document.Layers.AddChild(layer); document.ActiveLayerUniqueId = layer.UniqueId; // all shapes in the foreground layer have a shadow layer.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.Gray, new NPointL(5, 5), 1, new NLength(10)); // shapes in row 1 NShape newClient = base.CreateFlowChartingShape(document, FlowChartingShapes.Decision, base.GetGridCell(0, 0), "New Client", "CPA"); NShape register = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(0, 1), "Register", "CPA"); NShape clientAccountInfo = base.CreateFlowChartingShape(document, FlowChartingShapes.Data, base.GetGridCell(0, 2), "Client account info", "CPA"); NShape explainDataEntryProcedures = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(0, 3), "Explain data entry procedures", "CPA"); // shapes in row 2 NShape dataEntry = base.CreateFlowChartingShape(document, FlowChartingShapes.ManualInput, base.GetGridCell(2, 0), "Data Entry", "CLIENT"); NShape emailCompleted = base.CreateFlowChartingShape(document, FlowChartingShapes.Document, base.GetGridCell(2, 1), "E-mail Completed", "CLIENT"); NShape review = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(2, 2), "Review", "CPA"); NShape needsRevising = base.CreateFlowChartingShape(document, FlowChartingShapes.Decision, base.GetGridCell(2, 3), "Needs revising", "CPA"); NShape emailRevisions = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(2, 4), "E-mail revisions", "CPA"); NShape evaluateRevisions = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(2, 5), "Evaluate revisions", "CLIENT"); // shapes in row 3 NShape emailApprovedRevisions = base.CreateFlowChartingShape(document, FlowChartingShapes.Document, base.GetGridCell(3, 2), "E-mail Approved Revisions", "CLIENT"); NShape evaluateRevisions2 = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(3, 4), "Evaluate Revisions", "CLIENT"); NShape answerClientEmail = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(3, 5), "Answer Client E-mail", "CPA"); // shapes in row 4 NShape paywoll = base.CreateFlowChartingShape(document, FlowChartingShapes.Document, base.GetGridCell(5, 2), "Payroll", "CLIENT"); NShape taxes = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(5, 3), "Taxes", "CLIENT"); NShape controller = base.CreateFlowChartingShape(document, FlowChartingShapes.Process, base.GetGridCell(5, 4), "Controller", "CPA"); // some shapes need to have extra ports NRotatedBoundsPort port = new NRotatedBoundsPort(evaluateRevisions.UniqueId, new NContentAlignment(-25, 50)); port.Name = "BottomLeft"; evaluateRevisions.Ports.AddChild(port); port = new NRotatedBoundsPort(evaluateRevisions.UniqueId, new NContentAlignment(+25, 50)); port.Name = "BottomRight"; evaluateRevisions.Ports.AddChild(port); port = new NRotatedBoundsPort(answerClientEmail.UniqueId, new NContentAlignment(-25, -50)); port.Name = "TopLeft"; answerClientEmail.Ports.AddChild(port); port = new NRotatedBoundsPort(answerClientEmail.UniqueId, new NContentAlignment(+25, -50)); port.Name = "TopRight"; answerClientEmail.Ports.AddChild(port); // connect shapes in levels base.CreateConnector(document, newClient, "Center", register, "Center", ConnectorType.Line, "YES"); base.CreateConnector(document, register, "Center", clientAccountInfo, "Center", ConnectorType.Line, ""); base.CreateConnector(document, clientAccountInfo, "Center", explainDataEntryProcedures, "Center", ConnectorType.Line, ""); base.CreateConnector(document, dataEntry, "Center", emailCompleted, "Center", ConnectorType.Line, ""); base.CreateConnector(document, emailCompleted, "Center", review, "Center", ConnectorType.Line, ""); base.CreateConnector(document, review, "Center", needsRevising, "Center", ConnectorType.Line, ""); base.CreateConnector(document, needsRevising, "Center", emailRevisions, "Center", ConnectorType.Line, "YES"); base.CreateConnector(document, emailRevisions, "Center", evaluateRevisions, "Center", ConnectorType.Line, ""); base.CreateConnector(document, evaluateRevisions2, "Center", emailApprovedRevisions, "Center", ConnectorType.Line, ""); // connect accross levels NStep3Connector connector = (base.CreateConnector(document, newClient, "Center", dataEntry, "Center", ConnectorType.SideToSide, "NO") as NStep3Connector); connector.UseMiddleControlPointPercent = false; connector.MiddleControlPointOffset = -55; base.CreateConnector(document, explainDataEntryProcedures, "Center", dataEntry, "Center", ConnectorType.TopToBottom, ""); base.CreateConnector(document, emailApprovedRevisions, "Center", review, "Center", ConnectorType.Line, ""); base.CreateConnector(document, emailRevisions, "Center", evaluateRevisions2, "Center", ConnectorType.Line, ""); base.CreateConnector(document, evaluateRevisions, "BottomLeft", answerClientEmail, "TopLeft", ConnectorType.Line, ""); base.CreateConnector(document, answerClientEmail, "TopRight", evaluateRevisions, "BottomRight", ConnectorType.Line, ""); connector = (base.CreateConnector(document, needsRevising, "Center", paywoll, "Center", ConnectorType.TopToBottom, "") as NStep3Connector); connector.MiddleControlPointPercent = 66; connector = (base.CreateConnector(document, needsRevising, "Center", taxes, "Center", ConnectorType.TopToBottom, "") as NStep3Connector); connector.MiddleControlPointPercent = 66; connector = (base.CreateConnector(document, needsRevising, "Center", controller, "Center", ConnectorType.TopToBottom, "") as NStep3Connector); connector.MiddleControlPointPercent = 66; // create the legend as a group NGroup legend = new NGroup(); NRectangleShape legendBackground = new NRectangleShape(0, 0, 1, 3); legendBackground.Style.FillStyle = new NColorFillStyle(Color.White); legend.Shapes.AddChild(legendBackground); NRectangleF bounds = new NRectangleF(0, 1, 1, 1); bounds.Inflate(-0.2f, -0.2f); NRectangleShape cpaItem = new NRectangleShape(bounds); cpaItem.Text = "CPA"; cpaItem.StyleSheetName = "CPA"; legend.Shapes.AddChild(cpaItem); bounds = new NRectangleF(0, 2, 1, 1); bounds.Inflate(-0.2f, -0.2f); NRectangleShape clientItem = new NRectangleShape(bounds); clientItem.Text = "Client"; clientItem.StyleSheetName = "CLIENT"; legend.Shapes.AddChild(clientItem); legend.UpdateModelBounds(); legend.Bounds = base.GetGridCell(4, 0, 1, 1); document.ActiveLayer.AddChild(legend); document.SizeToContent(); }
private void CreateScene(NDrawingDocument document) { document.BackgroundStyle.FrameStyle.Visible = false; NFillStyle cpaFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(102, 204, 255), Color.FromArgb(0, 128, 128)); NFillStyle clientFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(255, 102, 0), Color.FromArgb(255, 204, 0)); NFillStyle stripeFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.FromArgb(221, 221, 221)); NTextStyle abcTextStyle = new NTextStyle(new Font("Arial", 12), Color.FromArgb(150, 150, 150)); float abcWidth = 150; NDrawingDocumentHelper helper = new NDrawingDocumentHelper(document); // configure the document helper.DefaultGridCellSize = new NSizeF(100, 70); helper.DefaultGridSpacing = new NSizeF(30, 30); helper.DefaultGridOrigin = new NPointF(60, 30); document.Bounds = new NRectangleF(0, 0, 1000, (6 * helper.DefaultGridCellSize.Height) + (7 * helper.DefaultGridSpacing.Height)); document.ShadowsZOrder = ShadowsZOrder.BehindLayer; // create the stripes NRectangleShape rect = new NRectangleShape(0, 0, document.Width, document.Height / 3); rect.Style.FillStyle = (NFillStyle)stripeFillStyle.Clone(); rect.Style.StrokeStyle = new NStrokeStyle(0, Color.White); document.ActiveLayer.AddChild(rect); rect = new NRectangleShape(0, document.Height / 3, document.Width, document.Height / 3); rect.Style.FillStyle = (NFillStyle)stripeFillStyle.Clone(); rect.Style.StrokeStyle = new NStrokeStyle(0, Color.White); document.ActiveLayer.AddChild(rect); rect = new NRectangleShape(0, 2 * document.Height / 3, document.Width, document.Height / 3); rect.Style.FillStyle = (NFillStyle)stripeFillStyle.Clone(); rect.Style.StrokeStyle = new NStrokeStyle(0, Color.White); document.ActiveLayer.AddChild(rect); // create A,B,C texts NTextShape text = new NTextShape("A", document.Width - abcWidth, 0, abcWidth, document.Height / 3); text.Mode = BoxTextMode.Stretch; text.Style.TextStyle = (abcTextStyle.Clone() as NTextStyle); document.ActiveLayer.AddChild(text); text = new NTextShape("B", document.Width - abcWidth, document.Height / 3, abcWidth, document.Height / 3); text.Mode = BoxTextMode.Stretch; text.Style.TextStyle = (abcTextStyle.Clone() as NTextStyle); document.ActiveLayer.AddChild(text); text = new NTextShape("C", document.Width - abcWidth, 2 * document.Height / 3, abcWidth, document.Height / 3); text.Mode = BoxTextMode.Stretch; text.Style.TextStyle = (abcTextStyle.Clone() as NTextStyle); document.ActiveLayer.AddChild(text); // add stripe texts text = new NTextShape("Sing up client", document.Width - abcWidth, document.Height / 3 - 50, abcWidth, 50); document.ActiveLayer.AddChild(text); text = new NTextShape("Monthly Accounting Services", document.Width - abcWidth, 2 * document.Height / 3 - 50, abcWidth, 50); document.ActiveLayer.AddChild(text); text = new NTextShape("Additional Services", document.Width - abcWidth, 3 * document.Height / 3 - 50, abcWidth, 50); document.ActiveLayer.AddChild(text); // create a layer for the forground shapes NLayer layer = new NLayer(); document.Layers.AddChild(layer); document.ActiveLayerUniqueId = layer.UniqueId; layer.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.Gray, new Nevron.GraphicsCore.NPointL(5, 5), 1, new NLength(10)); // shapes in row 1 NShape newClient = helper.CreateBasicShape(BasicShapes.Diamond, helper.GetGridCell(0, 0), "New Client", cpaFillStyle); NShape register = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(0, 1), "Register", cpaFillStyle); NShape clientAccountInfo = helper.CreateFlowChartingShape(FlowChartingShapes.Data, helper.GetGridCell(0, 2), "Client account info", cpaFillStyle); NShape explainDataEntryProcedures = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(0, 3), "Explain data entry procedures", cpaFillStyle); // shapes in row 2 NShape dataEntry = helper.CreateFlowChartingShape(FlowChartingShapes.ManualInput, helper.GetGridCell(2, 0), "Data Entry", clientFillStyle); NShape emailCompleted = helper.CreateFlowChartingShape(FlowChartingShapes.Document, helper.GetGridCell(2, 1), "E-mail Completed", clientFillStyle); NShape review = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(2, 2), "Review", cpaFillStyle); NShape needsRevising = helper.CreateBasicShape(BasicShapes.Diamond, helper.GetGridCell(2, 3), "Needs revising", cpaFillStyle); NShape emailRevisions = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(2, 4), "E-mail revisions", cpaFillStyle); NShape evaluateRevisions = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(2, 5), "Evaluate revisions", clientFillStyle); // shapes in row 3 NShape emailApprovedRevisions = helper.CreateFlowChartingShape(FlowChartingShapes.Document, helper.GetGridCell(3, 2), "E-mail Approved Revisions", clientFillStyle); NShape evaluateRevisions2 = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(3, 4), "Evaluate Revisions", clientFillStyle); NShape answerClientEmail = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(3, 5), "Answer Client E-mail", cpaFillStyle); // shapes in row 4 NShape paywoll = helper.CreateFlowChartingShape(FlowChartingShapes.Document, helper.GetGridCell(5, 2), "Payroll", clientFillStyle); NShape taxes = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(5, 3), "Taxes", clientFillStyle); NShape controller = helper.CreateBasicShape(BasicShapes.Rectangle, helper.GetGridCell(5, 4), "Controller", cpaFillStyle); // create the optional ports of the shape evaluateRevisions.CreateShapeElements(ShapeElementsMask.Ports); // some shapes need to have extra ports NRotatedBoundsPort port = new NRotatedBoundsPort(evaluateRevisions.UniqueId, new NContentAlignment(-25, 50)); port.Name = "BottomLeft"; evaluateRevisions.Ports.AddChild(port); port = new NRotatedBoundsPort(evaluateRevisions.UniqueId, new NContentAlignment(+25, 50)); port.Name = "BottomRight"; evaluateRevisions.Ports.AddChild(port); // create the optional ports of the shape answerClientEmail.CreateShapeElements(ShapeElementsMask.Ports); port = new NRotatedBoundsPort(answerClientEmail.UniqueId, new NContentAlignment(-25, -50)); port.Name = "TopLeft"; answerClientEmail.Ports.AddChild(port); port = new NRotatedBoundsPort(answerClientEmail.UniqueId, new NContentAlignment(+25, -50)); port.Name = "TopRight"; answerClientEmail.Ports.AddChild(port); // connect shapes in levels helper.CreateConnector(newClient, "Center", register, "Center", ConnectorType.Line, "YES"); helper.CreateConnector(register, "Center", clientAccountInfo, "Center", ConnectorType.Line, ""); helper.CreateConnector(clientAccountInfo, "Center", explainDataEntryProcedures, "Center", ConnectorType.Line, ""); helper.CreateConnector(dataEntry, "Center", emailCompleted, "Center", ConnectorType.Line, ""); helper.CreateConnector(emailCompleted, "Center", review, "Center", ConnectorType.Line, ""); helper.CreateConnector(review, "Center", needsRevising, "Center", ConnectorType.Line, ""); helper.CreateConnector(needsRevising, "Center", emailRevisions, "Center", ConnectorType.Line, "YES"); helper.CreateConnector(emailRevisions, "Center", evaluateRevisions, "Center", ConnectorType.Line, ""); helper.CreateConnector(evaluateRevisions2, "Center", emailApprovedRevisions, "Center", ConnectorType.Line, ""); // connect accross levels NStep3Connector connector = (helper.CreateConnector(newClient, "Center", dataEntry, "Center", ConnectorType.SideToSide, "NO") as NStep3Connector); connector.UseMiddleControlPointPercent = false; connector.MiddleControlPointOffset = -50; helper.CreateConnector(explainDataEntryProcedures, "Center", dataEntry, "Center", ConnectorType.TopToBottom, ""); helper.CreateConnector(emailApprovedRevisions, "Center", review, "Center", ConnectorType.Line, ""); helper.CreateConnector(emailRevisions, "Center", evaluateRevisions2, "Center", ConnectorType.Line, ""); helper.CreateConnector(evaluateRevisions, "BottomLeft", answerClientEmail, "TopLeft", ConnectorType.Line, ""); helper.CreateConnector(answerClientEmail, "TopRight", evaluateRevisions, "BottomRight", ConnectorType.Line, ""); connector = (helper.CreateConnector(needsRevising, "Center", paywoll, "Center", ConnectorType.TopToBottom, "") as NStep3Connector); connector.MiddleControlPointPercent = 66; connector = (helper.CreateConnector(needsRevising, "Center", taxes, "Center", ConnectorType.TopToBottom, "") as NStep3Connector); connector.MiddleControlPointPercent = 66; connector = (helper.CreateConnector(needsRevising, "Center", controller, "Center", ConnectorType.TopToBottom, "") as NStep3Connector); connector.MiddleControlPointPercent = 66; // create the legend NGroup legend = new NGroup(); NRectangleShape ledendBackground = new NRectangleShape(0, 0, 1, 3); ledendBackground.Style.FillStyle = new NColorFillStyle(Color.White); legend.Shapes.AddChild(ledendBackground); NTextShape legendTitle = new NTextShape("Legend", 0, 0, 1, 1); legend.Shapes.AddChild(legendTitle); NRectangleF bounds = new NRectangleF(0, 1, 1, 1); bounds.Inflate(-0.2f, -0.2f); NShape shape = helper.CreateBasicShape(BasicShapes.Rectangle, bounds, "CPA", (NFillStyle)cpaFillStyle.Clone(), false); legend.Shapes.AddChild(shape); bounds = new NRectangleF(0, 2, 1, 1); bounds.Inflate(-0.2f, -0.2f); shape = helper.CreateBasicShape(BasicShapes.Rectangle, bounds, "Client", (NFillStyle)clientFillStyle.Clone(), false); legend.Shapes.AddChild(shape); legend.UpdateModelBounds(); legend.Bounds = helper.GetGridCell(4, 0, 1, 1); document.ActiveLayer.AddChild(legend); }
protected void InitDocument(NDrawingDocument document, NShapesFactory factory) { NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; NDrawingView1.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; NDrawingView1.Document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // set up visual formatting NDrawingView1.Document.Style.FillStyle = new NColorFillStyle(Color.Linen); NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false; int maxOrdinal = 0; document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); switch (shapeSizeDropDownList.SelectedValue) { case "Small": factory.DefaultSize = new NSizeF(40, 30); maxOrdinal = 7; break; case "Medium": factory.DefaultSize = new NSizeF(80, 60); maxOrdinal = 4; break; case "Large": factory.DefaultSize = new NSizeF(200, 150); maxOrdinal = 1; break; default: throw new NotImplementedException(shapeSizeDropDownList.SelectedValue); } int count = factory.ShapesCount; for (int i = 0; i < count; i++) { // create a basic 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 = maxOrdinal; layout.VerticalSpacing = 20; layout.HorizontalSpacing = 20; layout.HorizontalContentPlacement = ContentPlacement.Center; layout.VerticalContentPlacement = ContentPlacement.Center; // 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(document.ActiveLayer.Children(null), layoutContext); // resize document to fit all shapes document.SizeToContent(); }
/// <summary> /// Creates a tree in the specified document /// </summary> /// <param name="document">document in which to create a tree</param> /// <returns>tree elements</returns> protected virtual NList <NShape> CreateTree(NDrawingDocument document) { NPage page = document.Content.ActivePage; NList <NShape> elements = new NList <NShape>(); NShape cur = null; NShape edge = null; NList <NShape> curRowVertices = null; NList <NShape> prevRowVertices = null; int i, j, level; int childrenCount, levelNodesCount; Random rnd = new Random(); for (level = 1; level <= m_nLevels; level++) { curRowVertices = new NList <NShape>(); if (m_bBalanced) { //Create a balanced tree levelNodesCount = (int)Math.Pow(m_nBranchNodes, level - 1); for (i = 0; i < levelNodesCount; i++) { // create the cur node cur = CreateVertex(m_VerticesShape); cur.SetBounds(new NRectangle(m_Origin, GetSize(rnd))); page.Items.AddChild(cur); elements.Add(cur); // connect with ancestor if (level > 1) { edge = CreateEdge(m_ConnectorShape); page.Items.AddChild(edge); int parentIndex = (int)Math.Floor((double)(i / m_nBranchNodes)); edge.GlueBeginToGeometryIntersection(prevRowVertices[parentIndex]); edge.GlueEndToShape(cur); } curRowVertices.Add(cur); } } else { //Create an unbalanced tree if (level == 1) { // Create the current node cur = CreateVertex(m_VerticesShape); cur.SetBounds(new NRectangle(m_Origin, GetSize(rnd))); page.Items.AddChild(cur); elements.Add(cur); curRowVertices.Add(cur); } else { levelNodesCount = prevRowVertices.Count; do { // Ensure that the desired level depth is reached for (i = 0; i < levelNodesCount; i++) { childrenCount = rnd.Next(0, m_nBranchNodes + 1); for (j = 0; j < childrenCount; j++) { // Create the current node cur = CreateVertex(m_VerticesShape); cur.SetBounds(new NRectangle(m_Origin, GetSize(rnd))); page.Items.AddChild(cur); elements.Add(cur); curRowVertices.Add(cur); // Connect with ancestor edge = CreateEdge(m_ConnectorShape); page.Items.AddChild(edge); edge.GlueBeginToGeometryIntersection(prevRowVertices[i]); edge.GlueEndToShape(cur); } } }while (level < m_nLevels && curRowVertices.Count == 0); } } prevRowVertices = curRowVertices; } return(elements); }
private void InitDocument() { NDrawingDocument document = NDrawingView1.Document; 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; }
private void ImportData() { NDrawingDocument document = NDrawingView1.Document; document.BackgroundStyle.FrameStyle.Visible = false; // create two stylesheets - one for the vertices and one for the edges NStyleSheet vertexStyleSheet = new NStyleSheet(); vertexStyleSheet.Name = "Vertices"; NStyle.SetFillStyle(vertexStyleSheet, new NColorFillStyle(Color.FromArgb(236, 97, 49))); document.StyleSheets.AddChild(vertexStyleSheet); NStyleSheet edgeStyleSheet = new NStyleSheet(); edgeStyleSheet.Name = "Edges"; NStyle.SetStrokeStyle(edgeStyleSheet, new NStrokeStyle(Color.Blue)); NStyle.SetEndArrowheadStyle(edgeStyleSheet, new NArrowheadStyle(ArrowheadShape.OpenedArrow, null, new NSizeL(6, 4), null, new NStrokeStyle(Color.Blue))); NTextStyle textStyle = (NTextStyle)document.ComposeTextStyle().Clone(); textStyle.StringFormatStyle.VertAlign = Nevron.VertAlign.Bottom; NStyle.SetTextStyle(edgeStyleSheet, textStyle); document.StyleSheets.AddChild(edgeStyleSheet); // create the graph data source importer NGraphDataSourceImporter graphImporter = new NGraphDataSourceImporter(); // set the document in the active layer of which the shapes will be imported graphImporter.Document = document; // SET THE DATA SOURCE // the tree data source importer supports the following data sources // DataTable // DataView // OleDbDataAdapter // SqlDataAdapter // OdbcDataAdapter // OleDbCommand // SqlCommand // OdbcCommand // in this example we have created an OleDbDataAdapter, // which selects all columns and records from the Sources and Links tables of the Data.xlsx file string databasePath = Server.MapPath(@"..\Examples\Import\Data.xlsx"); string connectionString = @"Data Source=""" + databasePath + @""";Provider=""Microsoft.ACE.OLEDB.12.0""; Extended Properties=""Excel 12.0 Xml;HDR=YES"";"; graphImporter.VertexDataSource = new OleDbDataAdapter("SELECT * FROM [Sources$]", connectionString); graphImporter.EdgeDataSource = new OleDbDataAdapter("SELECT * FROM [Links$]", connectionString); // vertex records are uniquely identified by their Id (in the Sources table) // edges link the vertices with the Fro and ToPageId (in the Links table) graphImporter.VertexIdColumnName = "Id"; graphImporter.FromVertexIdColumnName = "From"; graphImporter.ToVertexIdColumnName = "To"; // create vertices as group shapes, with default size NShapesFactory shapesFactory = new GroupShapesFactory(); shapesFactory.DefaultSize = VertexSize; graphImporter.VertexShapesFactory = shapesFactory; graphImporter.VertexShapesName = GroupShapes.Group.ToString(); // set stylesheets to be applied to imported vertices and edges graphImporter.VertexStyleSheetName = "Vertices"; graphImporter.EdgeStyleSheetName = "Edges"; // use layered graph layout NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.LayerSpacing = 70; layout.Direction = LayoutDirection.LeftToRight; layout.LayerAlignment = RelativeAlignment.Near; graphImporter.Layout = layout; // subscribe for the vertex and edge imported events, // which are raised when a shape was created for a data source record graphImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported); graphImporter.EdgeImported += new ShapeImportedDelegate(OnEdgeImported); // import graphImporter.Import(); }