protected override void LoadExample() { // init layout m_Layout = new NTableLayout(); // cells flow from left to right m_Layout.Direction = LayoutDirection.LeftToRight; // show layout properties in the property grid propertyGrid1.SelectedObject = m_Layout; // init view view.BeginInit(); view.Grid.Visible = false; view.GlobalVisibility.ShowPorts = false; view.ViewLayout = ViewLayout.Fit; // init document document.BeginInit(); document.Style.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(129, 133, 133), Color.FromArgb(192, 194, 194)); document.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108)); InitDocument(); document.EndInit(); // init form controls InitFormControls(); // end view init view.EndInit(); }
private void InitDocument() { document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); NBasicShapesFactory factory = new NBasicShapesFactory(document); factory.DefaultSize = new NSizeF(80, 60); int count = factory.ShapesCount; NShape shape = null; for (int i = 0; i < count; i++) { // create a basic shape shape = factory.CreateShape(i); shape.Text = shape.Name; // add it to the active layer document.ActiveLayer.AddChild(shape); } // Add some content to the table shape NTableShape table = (NTableShape)shape; table.InitTable(2, 2); table.BeginUpdate(); table.CellMargins = new Nevron.Diagram.NMargins(8); table[0, 0].Text = "Cell 1"; table[1, 0].Text = "Cell 2"; table[0, 1].Text = "Cell 3"; table[1, 1].Text = "Cell 4"; table.PortDistributionMode = TablePortDistributionMode.CellBased; table.EndUpdate(); // 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); // layout the shapes layout.Layout(shapes, new NDrawingLayoutContext(document)); // resize document to fit all shapes document.SizeToContent(); }
private void InitDocument() { document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); // IMPORTANT: the floor plan shapes are defined with they real size in millimeters // that is why we must use drawing scale to display the content of this library document.DrawingScaleMode = DrawingScaleMode.CustomScale; document.MeasurementUnit = NGraphicsUnit.Millimeter; document.CustomWorldMeasurementUnit = NGraphicsUnit.Millimeter; document.CustomScale = 0.01f; NFloorPlanShapesFactory factory = new NFloorPlanShapesFactory(); 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 = 200; layout.HorizontalSpacing = 200; // 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() { // make a gray background document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.Gray); NFlagsShapesFactory factory = new NFlagsShapesFactory(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() { NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory(); basicShapesFactory.DefaultSize = new NSizeF(100, 100); // create groups and apply a frame decorator to each one of them for (int i = 0; i < 4; i++) { NShape shape1 = basicShapesFactory.CreateShape(BasicShapes.Octagon); shape1.Bounds = new NRectangleF(0, 0, 80, 80); NShape shape2 = basicShapesFactory.CreateShape(BasicShapes.Ellipse); shape2.Bounds = new NRectangleF(100, 100, 80, 80); NGroup group = new NGroup(); group.Shapes.AddChild(shape1); group.Shapes.AddChild(shape2); group.Padding = new Nevron.Diagram.NMargins(30); group.UpdateModelBounds(); NFrameDecorator frameDecorator = new NFrameDecorator(); frameDecorator.StyleSheetName = "Decorators"; frameDecorator.ShapeHitTestable = true; frameDecorator.Header.Text = "Header"; group.CreateShapeElements(ShapeElementsMask.Decorators); group.Decorators.AddChild(frameDecorator); document.ActiveLayer.AddChild(group); } // layout them with a table layout NTableLayout layout = new NTableLayout(); layout.ConstrainMode = CellConstrainMode.Ordinal; layout.MaxOrdinal = 2; layout.HorizontalSpacing = 20; layout.VerticalSpacing = 20; layout.Layout(document.ActiveLayer.Children(null), new NDrawingLayoutContext(document)); // size document to content document.SizeToContent(NSizeF.Empty, document.AutoBoundsPadding); }
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); }
protected void InitDocument() { NDrawingDocument document = NDrawingView1.Document; // Import the Visio stencil NLibraryDocument libDocument = new NLibraryDocument(); NVisioImporter importer = new NVisioImporter(libDocument); importer.Import(Server.MapPath(@"~\Examples\Import\Computers.vsx")); // Set drawing preferences document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; document.BackgroundStyle.FrameStyle.Visible = false; // Determine the shape size int maxOrdinal = 0; int scale = 1; switch (shapeSizeDropDownList.SelectedValue) { case "Small": scale = 1; maxOrdinal = 5; break; case "Medium": scale = 2; maxOrdinal = 3; break; case "Large": scale = 4; maxOrdinal = 1; break; default: throw new NotImplementedException(shapeSizeDropDownList.SelectedValue); } // Determine the shapes size and layout options NNodeList masters = libDocument.Children(NFilters.TypeNMaster); for (int i = 0, count = masters.Count; i < count; i++) { NMaster master = (NMaster)masters[i]; NNodeList shapes = master.CreateInstance(document, new NPointF(0, 0)); NShape shape = (NShape)shapes[0]; shape.Width *= scale; shape.Height *= scale; NStyle.SetInteractivityStyle(shape, new NInteractivityStyle(master.Name)); } // Layout the shapes in the active layer using a table layout NTableLayout layout = new NTableLayout(); 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; layout.Layout(document.ActiveLayer.Children(null), new NDrawingLayoutContext(document)); // Resize document to fit all shapes document.SizeToContent(); }
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; NDrawingView1.Document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.FromArgb(0xca, 0xca, 0xca)); 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(); }
protected void InitDocument() { NDrawingDocument document = NDrawingView1.Document; // set drawing preferences document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; document.Style.FillStyle = new NColorFillStyle(Color.Linen); document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); document.BackgroundStyle.FrameStyle.Visible = false; // determine the shapes size and layout options NBasicShapesFactory factory = new NBasicShapesFactory(document); int maxOrdinal = 0; 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); } // create the basic shapes in the active layer int count = factory.ShapesCount; NShape shape = null; for (int i = 0; i < count; i++) { // create a basic shape shape = factory.CreateShape(i); shape.Text = shape.Name; // add it to the active layer document.ActiveLayer.AddChild(shape); } // Add some content to the table shape NTableShape table = (NTableShape)shape; table.InitTable(2, 2); table.BeginUpdate(); table.CellMargins = new Nevron.Diagram.NMargins(8); table[0, 0].Text = "Cell 1"; table[1, 0].Text = "Cell 2"; table[0, 1].Text = "Cell 3"; table[1, 1].Text = "Cell 4"; table.PortDistributionMode = TablePortDistributionMode.CellBased; table.EndUpdate(); // layout the shapes in the active layer using a table layout NTableLayout layout = new NTableLayout(); 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; NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document); layout.Layout(document.ActiveLayer.Children(null), layoutContext); // 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(); } }
void InitLibrary() { nDrawingViewLibrary.HttpHandlerCallback = new LibraryHttpHandlerCallback(); if (nDrawingViewLibrary.RequiresInitialization) { // begin view init nDrawingViewLibrary.ViewLayout = CanvasLayout.Normal; nDrawingViewLibrary.DocumentPadding = new Nevron.Diagram.NMargins(10); // init document nDrawingViewLibrary.Document.BeginInit(); nDrawingViewLibrary.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; nDrawingViewLibrary.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; nDrawingViewLibrary.Document.GraphicsSettings.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // set up visual formatting nDrawingViewLibrary.Document.BackgroundStyle.FillStyle = new NColorFillStyle(documentBackgroundColor); nDrawingViewLibrary.Document.Style.FillStyle = new NColorFillStyle(libraryFillColor); nDrawingViewLibrary.Document.Style.StrokeStyle = new NStrokeStyle(libraryBorderColor); nDrawingViewLibrary.Document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); nDrawingViewLibrary.Document.BackgroundStyle.FrameStyle.Visible = false; NFlowChartingShapesFactory factory = new NFlowChartingShapesFactory(nDrawingViewLibrary.Document); factory.DefaultSize = new NSizeF(76, 51); int count = factory.ShapesCount; for (int i = 0; i < count; i++) { // create a basic shape NShape shape = factory.CreateShape(i); // enable interactivity shape.Style.InteractivityStyle = new NInteractivityStyle(true, i.ToString(), shape.Name, CursorType.Hand); // add it to the active layer nDrawingViewLibrary.Document.ActiveLayer.AddChild(shape); // select the first shape if (i == 0) { shape.Style.FillStyle = new NColorFillStyle(libraryHighlightFillColor); shape.Style.StrokeStyle = new NStrokeStyle(libraryHighlightBorderColor); shape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(90, Color.Black), new NPointL(2, 1)); shape.Tag = "selected"; } } // 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 = 1; layout.VerticalSpacing = 20; // create a layout context NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(nDrawingViewLibrary.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(nDrawingViewLibrary.Document); // layout the shapes layout.Layout(nDrawingViewLibrary.Document.ActiveLayer.Children(null), layoutContext); // resize document to fit all shapes nDrawingViewLibrary.SizeToContent(); nDrawingViewLibrary.Document.EndInit(); } }
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); }
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; }