void CreateLabeledPolyOutline(NPointF[] points, NPolygonShape polyShape, NNodeList labels, string title) { NNodeList nodes = new NNodeList(); nodes.Add(polyShape); if (labels != null) { nodes.AddRange(labels); } int length = points.Length - 1; int vIndex = 0, hIndex = 0, index = 0; for (int i = 0; i < length; i++) { nodes.Add(ConnectPointsLabeled(points[i], points[i + 1], ref hIndex, ref vIndex, ref index)); } nodes.Add(ConnectPointsLabeled(points[points.Length - 1], points[0], ref hIndex, ref vIndex, ref index)); NGroup g; NBatchGroup batchGroup = new NBatchGroup(document); batchGroup.Build(nodes); batchGroup.Group(document.ActiveLayer, true, out g); g.Name = title + " Group"; }
void CreateLivingRoom(NPointF offset) { NPointF[] points = ApplyOffset(LivingRoom.points, offset); NPolygonShape p = new NPolygonShape(points); p.Text = "Living Room, H=265"; p.Style.TextStyle = txMain; document.ActiveLayer.AddChild(p); NNodeList labels = new NNodeList(); labels.Add(AddLabel(LivingRoom.section1Center, "H=240", false)); labels.Add(AddLabel(LivingRoom.section2Center, "H=240", true)); CreateLabeledPolyOutline(points, p, labels, "Living Room"); }
private void LayoutGroups() { NLayeredTreeLayout layout = new NLayeredTreeLayout(); layout.PlugSpacing.Mode = PlugSpacingMode.None; NNodeList shapes = new NNodeList(); shapes.Add(document.ActiveLayer.GetChildByName("treeRoot")); shapes.Add(document.ActiveLayer.GetChildByName("leftEdge")); shapes.Add(document.ActiveLayer.GetChildByName("rightEdge")); shapes.Add(Group1); shapes.Add(Group2); layout.Layout(shapes, new NDrawingLayoutContext(document, shapes)); Group1.UpdateModelBounds(); Group2.UpdateModelBounds(); }
private void InitDocument() { // create the groups NGroup group1 = CreateAffineScaleGroup(); NGroup group2 = CreateCartesianScaleGroup(); NGroup group3 = CreateReposionGroup(); NGroup group4 = CreateScale1DGroup(); // apply default styles group1.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 204, 0, 0)); group2.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 0, 204, 0)); group3.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 0, 0, 204)); group4.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 255, 255, 0)); // layout the groups in 2 cols NTableLayout layout = new NTableLayout(); // setup table layout layout.Direction = LayoutDirection.LeftToRight; layout.ConstrainMode = CellConstrainMode.Ordinal; layout.MaxOrdinal = 2; layout.VerticalSpacing = 20; layout.HorizontalSpacing = 20; // create a list of shapes to layout NNodeList groups = new NNodeList(); groups.Add(group1); groups.Add(group2); groups.Add(group3); groups.Add(group4); // create a layout context NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document); // do layout layout.Layout(groups, layoutContext); }
private NNodeList GetShapesList(NGraphVertexList vertices, NObjectGraphPartMap map) { NNodeList list = new NNodeList(); int i, vertexCount = vertices.Count; for (i = 0; i < vertexCount; i++) { list.Add((NShape)map.GetObjectFromPart(vertices[i])); } return(list); }
private NNodeList GetShapesList(NGraphEdgeList edges, NObjectGraphPartMap map) { NNodeList list = new NNodeList(); int i, edgeCount = edges.Count; for (i = 0; i < edgeCount; i++) { list.Add((NShape)map.GetObjectFromPart(edges[i])); } return(list); }
protected NNodeList GetAllCells(NStateObject state) { NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject; NNodeList list = new NNodeList(); NGroup cellsGroup = diagramState.Document.ActiveLayer.GetChildByName("cellsGroup", 0) as NGroup; foreach (INNode node in cellsGroup.Shapes) { list.Add(node); } return(list); }
void CreateHallway(NPointF offset) { NPointF[] points = ApplyOffset(Hallway.points, offset); NPolygonShape p = new NPolygonShape(points); p.Text = "Hallway, H=270"; p.Style.TextStyle = txMain.Clone() as NTextStyle; p.Style.TextStyle.Offset = new NPointL(-60, 0); document.ActiveLayer.AddChild(p); NNodeList labels = new NNodeList(); labels.Add(AddLabel(ApplyOffset(Hallway.section1Center, offset), "H=240", false)); CreateLabeledPolyOutline(points, p, labels, "Hallway"); }
private void InitDocument() { // configure the document NDrawingView1.Document.Bounds = new NRectangleF(0, 0, imagePixelWidth, imagePixelHeight); NDrawingView1.Document.ShadowsZOrder = ShadowsZOrder.BehindElement; 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.None; NDrawingView1.Document.MeasurementUnit = NGraphicsUnit.Pixel; NDrawingView1.Document.DrawingScaleMode = DrawingScaleMode.NoScale; NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false; // shapes NRectangleShape backgroundFrame = factory.CreateShape((int)BasicShapes.Rectangle) as NRectangleShape; backgroundFrame.Bounds = new NRectangleF(boardMarginLeft, boardMarginTop, boardPixelWidth, boardPixelHeight); backgroundFrame.Style.StrokeStyle = new NStrokeStyle(new NLength(1f, NGraphicsUnit.Pixel), Color.Black); backgroundFrame.Style.FillStyle = new NColorFillStyle(Color.White); backgroundFrame.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(65, Color.Black), new NPointL(shadowOffset, shadowOffset), 1, new NLength(shadowOffset * 2)); backgroundFrame.Name = "background"; NDrawingView1.Document.ActiveLayer.AddChild(backgroundFrame); NNodeList cells = new NNodeList(); for (int x = 0; x < boardCellCountWidth; x++) { for (int y = 0; y < boardCellCountHeight; y++) { cells.Add(CreateEmptyCell(x, y)); } } NGroup cellsGroup; NBatchGroup batchGroup = new NBatchGroup(NDrawingView1.Document); batchGroup.Build(cells); NTransactionResult result = batchGroup.Group(NDrawingView1.Document.ActiveLayer, true, out cellsGroup); cellsGroup.Name = "cellsGroup"; }
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); }
private void CreateScene(NDrawingDocument document) { document.BackgroundStyle.FrameStyle.Visible = false; // change default document styles document.Style.TextStyle.TextFormat = TextFormat.XML; document.Style.StartArrowheadStyle.Shape = ArrowheadShape.None; document.Style.EndArrowheadStyle.Shape = ArrowheadShape.None; document.Style.FillStyle = new NGradientFillStyle(GradientStyle.DiagonalUp, GradientVariant.Variant1, new NArgbColor(155, 184, 209), new NArgbColor(83, 138, 179)); // the fill style for the cells NStyleSheet transparent = new NStyleSheet("transparent"); NStyle.SetFillStyle(transparent, new NColorFillStyle(KnownArgbColorValue.Transparent)); document.StyleSheets.AddChild(transparent); NNodeList shapes = new NNodeList(); NShape shape1, shape2, winner = null; int i, depth = 0; int count = MATCHES.Length; for (i = 0; i < count; i++) { winner = CreateShape(MATCHES[i]); shapes.Add(winner); if (i >= 8) { if (i < 12) { // The quarter finals depth = 0; shape1 = (NShape)shapes[(i - 8) * 2]; shape2 = (NShape)shapes[(i - 8) * 2 + 1]; } else if (i < 14) { // The semi finals depth = 2; shape1 = (NShape)shapes[8 + (i - 12) * 2]; shape2 = (NShape)shapes[8 + (i - 12) * 2 + 1]; } else { // The final depth = 4; shape1 = (NShape)shapes[12]; shape2 = (NShape)shapes[13]; } SetAnimationsStyle(shape1, depth); SetAnimationsStyle(shape2, depth); ConnectShapes(shape1, shape2, winner, depth + 1); } } SetAnimationsStyle(winner, depth + 2); NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.Direction = LayoutDirection.LeftToRight; layout.Layout(shapes, new NDrawingLayoutContext(document)); // resize document to fit all shapes document.SizeToContent(); }
void InitToolbar() { if (nDrawingViewToolbar.RequiresInitialization) { ActiveCommand = toolbarButtons[0].CommandName; // begin view init nDrawingViewToolbar.ViewLayout = CanvasLayout.Normal; nDrawingViewToolbar.DocumentPadding = new Nevron.Diagram.NMargins(0); // init document nDrawingViewToolbar.Document.BeginInit(); nDrawingViewToolbar.Document.AutoBoundsPadding = new Nevron.Diagram.NMargins(4); nDrawingViewToolbar.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; nDrawingViewToolbar.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; nDrawingViewToolbar.Document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // set up visual formatting nDrawingViewToolbar.Document.Style.FillStyle = new NColorFillStyle(Color.White); nDrawingViewToolbar.Document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); nDrawingViewToolbar.Document.BackgroundStyle.FrameStyle.Visible = false; // set up the shape factories NBasicShapesFactory buttonFactory = new NBasicShapesFactory(nDrawingViewToolbar.Document); buttonFactory.DefaultSize = new NSizeF(24, 24); NBrainstormingShapesFactory iconFactory = new NBrainstormingShapesFactory(nDrawingViewToolbar.Document); iconFactory.DefaultSize = new NSizeF(16, 16); // create a batch layout, which will align shapes NBatchLayout batchLayout = new NBatchLayout(nDrawingViewToolbar.Document); // create buttons int count = toolbarButtons.Length; for (int i = 0; i < count; i++) { ToolbarButton btn = toolbarButtons[i]; bool isActive = (this.ActiveCommand == btn.CommandName); NShape buttonShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle); // create the button shape group NGroup g = new NGroup(); NBatchGroup bgroup = new NBatchGroup(nDrawingViewToolbar.Document); NNodeList shapes = new NNodeList(); if (btn.IsSeparator) { buttonShape.Width /= 2; buttonShape.Style.StrokeStyle = new NStrokeStyle(Color.White); shapes.Add(buttonShape); } else if (!btn.IsColorSelector) { shapes.Add(buttonShape); } else { buttonShape.Style.FillStyle = new NColorFillStyle(btn.Color); shapes.Add(buttonShape); } NRectanglePath imagePath = new NRectanglePath(0f, 0f, btn.IconSize.Width, btn.IconSize.Height); NImageFillStyle fs1 = new NImageFillStyle(this.MapPathSecure(@"..\..\..\Images\FlowChartBuilder\" + btn.IconFile)); NStyle.SetFillStyle(imagePath, fs1); NStyle.SetStrokeStyle(imagePath, new NStrokeStyle(0, Color.White)); NCompositeShape imageShape = new NCompositeShape(); imageShape.Primitives.AddChild(imagePath); imageShape.UpdateModelBounds(); shapes.Add(imageShape); NShape coverShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle); coverShape.Width = buttonShape.Width; coverShape.Name = "coverShape"; shapes.Add(coverShape); if (!isActive && !btn.IsClientSide && !btn.IsSeparator) { if (btn.IsColorSelector) { coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(180, Color.White)); } else { coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(160, Color.White)); } coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(160, Color.White)); } else { coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(0, Color.White)); coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(0, Color.White)); if (!btn.IsSeparator) { coverShape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(70, Color.Black), new NPointL(1, 0)); } } // perform layout batchLayout.Build(shapes); batchLayout.AlignVertically(buttonShape, VertAlign.Center, false); batchLayout.AlignHorizontally(buttonShape, HorzAlign.Center, false); // group shapes bgroup.Build(shapes); bgroup.Group(null, false, out g); // enable interactivity if (!btn.IsSeparator) { g.Style.InteractivityStyle = new NInteractivityStyle(true, btn.CommandName, btn.Title, CursorType.Hand); } // set the command of the button g.Tag = btn.CommandName; nDrawingViewToolbar.Document.ActiveLayer.AddChild(g); } // 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 = toolbarButtons.Length; layout.HorizontalSpacing = 7; // create a layout context NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(nDrawingViewToolbar.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(nDrawingViewToolbar.Document); // layout the shapes layout.Layout(nDrawingViewToolbar.Document.ActiveLayer.Children(null), layoutContext); nDrawingViewToolbar.Document.EndInit(); } }
protected static void InitDocument(NDrawingDocument document, string stateId, int boardCellCount) { // clean up existing layers document.Layers.RemoveAllChildren(); // modify the connectors style sheet document.Style.TextStyle = new NTextStyle(); document.Style.TextStyle.FontStyle = new NFontStyle("Arial", 20f, FontStyle.Bold); document.Style.TextStyle.FillStyle = new NColorFillStyle(Color.SteelBlue); document.Style.TextStyle.BorderStyle = new NStrokeStyle(1f, Color.White); // configure the document document.Bounds = new NRectangleF(0, 0, imagePixelWidth, imagePixelHeight); document.ShadowsZOrder = ShadowsZOrder.BehindLayer; document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None; document.MeasurementUnit = NGraphicsUnit.Pixel; document.DrawingScaleMode = DrawingScaleMode.NoScale; document.BackgroundStyle.FrameStyle.Visible = false; NLayer backgroundLayer = new NLayer(); NLayer gridLayer = new NLayer(); document.Layers.AddChild(gridLayer); document.ActiveLayerUniqueId = gridLayer.UniqueId; // frame NBasicShapesFactory factory = new NBasicShapesFactory(document); // grid ArrayList randomizedNumbers = CreateRandomizedNumbersArray(boardCellCount); Hashtable grid = new Hashtable(); NNodeList cells = new NNodeList(); for (int x = 0; x < boardCellCount; x++) { for (int y = 0; y < boardCellCount; y++) { if (x == boardCellCount - 1 && y == boardCellCount - 1) { break; } NRectangleShape cell = CreateCell(document, x, y, (int)randomizedNumbers[y + x * boardCellCount]); cells.Add(cell); grid[new Point((int)cell.Bounds.X, (int)cell.Bounds.Y)] = new Point(x, y); } } NGroup cellsGroup; NBatchGroup batchGroup = new NBatchGroup(document); batchGroup.Build(cells); NTransactionResult result = batchGroup.Group(document.ActiveLayer, true, out cellsGroup); cellsGroup.Name = "cellsGroup"; // save the default empty cell coordinates Point emptyCellCoords = new Point(boardCellCount - 1, boardCellCount - 1); Point emptyCellPixelCoords = new Point(boardMarginLeft + cellPixelWidth * (boardCellCount - 1) + boardPadding, boardMarginTop + cellPixelWidth * (boardCellCount - 1) + boardPadding); HttpContext.Current.Session[stateId.ToString() + "-emptyCellCoords"] = emptyCellCoords; HttpContext.Current.Session[stateId.ToString() + "-emptyCellPixelCoords"] = emptyCellPixelCoords; // save the default cells grid grid[new Point(emptyCellPixelCoords.X, emptyCellPixelCoords.Y)] = new Point(emptyCellCoords.X, emptyCellCoords.Y); HttpContext.Current.Session[stateId.ToString() + "-grid"] = grid; // clean up any other related session state HttpContext.Current.Session.Remove(stateId.ToString() + "-cellsList"); }
void InitDocument() { // set up visual formatting NDrawingView1.Document.Style.FillStyle = new NColorFillStyle(Color.White); NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false; NCustomToolsData.NBookEntry[] books = NCustomToolsData.CreateBooks(); // set up the shape factories NBasicShapesFactory bookItemsFactory = new NBasicShapesFactory(NDrawingView1.Document); bookItemsFactory.DefaultSize = new NSizeF(150, 100); // create a table layout, which will align te thumbnail and the text within a group NTableLayout bookThumbLayout = new NTableLayout(); bookThumbLayout.Direction = LayoutDirection.LeftToRight; bookThumbLayout.ConstrainMode = CellConstrainMode.Ordinal; bookThumbLayout.MaxOrdinal = 1; // create a table layout, which will align all books in a grid NTableLayout tableLayout = new NTableLayout(); tableLayout.Direction = LayoutDirection.LeftToRight; tableLayout.ConstrainMode = CellConstrainMode.Ordinal; tableLayout.MaxOrdinal = 4; tableLayout.HorizontalSpacing = 7; tableLayout.VerticalSpacing = 7; NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(NDrawingView1.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(NDrawingView1.Document); int length = books.Length; for (int i = 0; i < length; i++) { NCustomToolsData.NBookEntry book = books[i]; NShape bookThumbnailShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); NImageFillStyle fs1 = new NImageFillStyle(this.MapPathSecure(@"..\..\..\..\Images\CustomTools\" + book.ThumbnailFile)); fs1.TextureMappingStyle.MapLayout = MapLayout.Centered; NStyle.SetFillStyle(bookThumbnailShape, fs1); NStyle.SetStrokeStyle(bookThumbnailShape, new NStrokeStyle(0, Color.White)); NShape bookTextShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); NStyle.SetStrokeStyle(bookTextShape, new NStrokeStyle(0, Color.White)); bookTextShape.Text = book.Title; bookTextShape.Height = 50f; bookThumbnailShape.Style.InteractivityStyle = new NInteractivityStyle(true, book.Id.ToString(), null, CursorType.Hand); bookTextShape.Style.InteractivityStyle = new NInteractivityStyle(true, book.Id.ToString(), null, CursorType.Hand); // create the book tumbnail group NGroup g = new NGroup(); NBatchGroup bgroup = new NBatchGroup(NDrawingView1.Document); NNodeList shapes = new NNodeList(); shapes.Add(bookThumbnailShape); shapes.Add(bookTextShape); // perform layout bookThumbLayout.Layout(shapes, layoutContext); // group shapes bgroup.Build(shapes); bgroup.Group(null, false, out g); NDrawingView1.Document.ActiveLayer.AddChild(g); } // layout the books tableLayout.Layout(NDrawingView1.Document.ActiveLayer.Children(null), layoutContext); }
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; }
protected void InitDocument() { NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; NDrawingView1.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; 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; // all shapes will have shadow dropped below document content NDrawingView1.Document.Style.ShadowStyle.Type = ShadowType.GaussianBlur; NDrawingView1.Document.Style.ShadowStyle.Offset = new NPointL(5, 5); NDrawingView1.Document.Style.ShadowStyle.FadeLength = new NLength(5); NDrawingView1.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(NDrawingView1.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(NDrawingView1.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) NDrawingView1.Document.SizeToContent(new NSizeF(100, 100), new Nevron.Diagram.NMargins(20, 20, 100, 20)); // add title spanning the entire document width NTextShape text = new NTextShape("Company Structure", new NRectangleF(5, -50, NDrawingView1.Document.Width - 5, 50)); text.Style.TextStyle = new NTextStyle(new Font("Times New Roman", 23, FontStyle.Bold)); text.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Center; NDrawingView1.Document.ActiveLayer.AddChild(text); }
NDrawingDocument CreateDocument(int bookId) { NDrawingDocument document = new NDrawingDocument(); // setup the document document.AutoBoundsPadding = new Nevron.Diagram.NMargins(0f, 7f, 7f, 7f); document.Style.FillStyle = new NColorFillStyle(Color.White); document.Style.TextStyle.FillStyle = new NColorFillStyle(Color.DarkGray); document.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Left; document.Style.StrokeStyle = new NStrokeStyle(0, Color.White); NStandardFrameStyle frame = document.BackgroundStyle.FrameStyle as NStandardFrameStyle; frame.InnerBorderColor = Color.Gray; document.MeasurementUnit = NGraphicsUnit.Pixel; // set up the shape factories NBasicShapesFactory bookItemsFactory = new NBasicShapesFactory(document); bookItemsFactory.DefaultSize = new NSizeF(320, 200); NCustomToolsData.NBookEntry[] books = NCustomToolsData.CreateBooks(); NCustomToolsData.NBookEntry book = null; int length = books.Length; for (int i = 0; i < length; i++) { if (books[i].Id == bookId) { book = books[i]; break; } } if (bookId == -1 || book == null) { document.Style.StrokeStyle = new NStrokeStyle(1, Color.Red); document.ActiveLayer.AddChild(bookItemsFactory.CreateShape(BasicShapes.Pentagram)); document.SizeToContent(); return(document); } // create a table layout, which will align te thumbnail and the text lines // in two columns NTableLayout mainLayout = new NTableLayout(); mainLayout.Direction = LayoutDirection.LeftToRight; mainLayout.ConstrainMode = CellConstrainMode.Ordinal; mainLayout.MaxOrdinal = 2; mainLayout.VerticalContentPlacement = ContentPlacement.Near; // create a stack layout, which will align the text lines in rows NStackLayout textLayout = new NStackLayout(); textLayout.Direction = LayoutDirection.TopToBottom; textLayout.HorizontalContentPlacement = ContentPlacement.Near; textLayout.VerticalSpacing = 13; // create a stack layout, which will align the stars in 5 columns NStackLayout starsLayout = new NStackLayout(); starsLayout.Direction = LayoutDirection.LeftToRight; starsLayout.VerticalContentPlacement = ContentPlacement.Center; starsLayout.HorizontalSpacing = 1; NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document); // create the shapes for the book image and text lines NShape bookImageShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookImageShape.Width = 240f; bookImageShape.Height = 240f; NImageFillStyle fs1 = new NImageFillStyle(HttpContext.Current.Server.MapPath(@"~\Images\CustomTools\" + book.ImageFile)); fs1.TextureMappingStyle.MapLayout = MapLayout.Centered; NStyle.SetFillStyle(bookImageShape, fs1); NShape bookTitleShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookTitleShape.Text = book.Title; bookTitleShape.Width = 160f; bookTitleShape.Height = 32f; NShape bookAuthorShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookAuthorShape.Text = "by " + book.Author; bookAuthorShape.Width = 160f; bookAuthorShape.Height = 32f; NShape bookPriceShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle); bookPriceShape.Text = "Price: $" + book.Price.ToString(); bookPriceShape.Width = 160f; bookPriceShape.Height = 32f; // create the star shapes NNodeList starShapes = new NNodeList(); for (int i = 0; i < 5; i++) { NShape star = bookItemsFactory.CreateShape(BasicShapes.Pentagram); star.Width = 10f; star.Height = 10f; if (i < book.Rating) { star.Style.FillStyle = new NColorFillStyle(Color.Orange); } else { star.Style.FillStyle = new NColorFillStyle(Color.LightGray); } starShapes.Add(star); } // prepare to layout NBatchGroup bgroup = new NBatchGroup(document); // create the stars group NGroup starsGroup = new NGroup(); // group the star shapes bgroup.Build(starShapes); bgroup.Group(null, false, out starsGroup); // collect the text shapes NNodeList textShapes = new NNodeList(); textShapes.Add(bookTitleShape); textShapes.Add(bookAuthorShape); textShapes.Add(bookPriceShape); textShapes.Add(starsGroup); // create the text group NGroup textGroup = new NGroup(); // group the text shapes bgroup.Build(textShapes); bgroup.Group(null, false, out textGroup); // collect the main layout shapes NNodeList mainElements = new NNodeList(); mainElements.Add(bookImageShape); mainElements.Add(textGroup); // create the main group NGroup mainGroup = new NGroup(); // group the main elements bgroup.Build(mainElements); bgroup.Group(null, false, out mainGroup); document.ActiveLayer.AddChild(mainGroup); // size all text shapes to text bookTitleShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f)); bookAuthorShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f)); bookPriceShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f)); // layout the star shapes starsLayout.Layout(starShapes, layoutContext); starsGroup.UpdateModelBounds(); // perform layout on the text textLayout.Layout(textShapes, layoutContext); textGroup.UpdateModelBounds(); // layout all elements mainLayout.Layout(mainElements, layoutContext); mainGroup.UpdateModelBounds(); // correct the text left padding bookTitleShape.Location = new NPointF(bookTitleShape.Location.X - 6f, bookTitleShape.Location.Y); bookAuthorShape.Location = new NPointF(bookAuthorShape.Location.X - 6f, bookAuthorShape.Location.Y); bookPriceShape.Location = new NPointF(bookPriceShape.Location.X - 6f, bookPriceShape.Location.Y); document.SizeToContent(); return(document); }