private void LayoutButton_Click(object sender, EventArgs e) { // 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); NDrawingBodyContainerAdapter adapter = new NDrawingBodyContainerAdapter(document); adapter.SetLayoutArea(new NRectangleF(0, 0, 800, 800)); layoutContext.BodyContainerAdapter = adapter; // layout the shapes if (m_Layout != null) { m_Layout.Layout(shapes, layoutContext); } // resize document to fit all shapes document.SizeToContent(); }
protected override void InitDiagram() { base.InitDiagram(); m_DrawingDocument.HistoryService.Pause(); try { NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // Hide grid and ports drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; // Create all shapes NBrainstormingShapeFactory factory = new NBrainstormingShapeFactory(); factory.DefaultSize = new NSize(60, 60); for (int i = 0; i < factory.ShapeCount; i++) { NShape shape = factory.CreateShape(i); shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; shape.Text = factory.GetShapeInfo(i).Name; MoveTextBelowShape(shape); activePage.Items.Add(shape); } // Arrange them NList <NShape> shapes = activePage.GetShapes(false); NLayoutContext layoutContext = new NLayoutContext(); layoutContext.BodyAdapter = new NShapeBodyAdapter(m_DrawingDocument); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.LayoutArea = activePage.GetContentEdge(); NTableFlowLayout tableLayout = new NTableFlowLayout(); tableLayout.HorizontalSpacing = 30; tableLayout.VerticalSpacing = 50; tableLayout.Direction = ENHVDirection.LeftToRight; tableLayout.MaxOrdinal = 5; tableLayout.Arrange(shapes.CastAll <object>(), layoutContext); // size page to content activePage.Layout.ContentPadding = new NMargins(40); activePage.SizeToContent(); } finally { m_DrawingDocument.HistoryService.Resume(); } }
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 DoLayout() { // layout with a layered tree layout NLayoutContext context = new NLayoutContext(); context.GraphAdapter = new NShapeGraphAdapter(true); context.BodyAdapter = new NShapeBodyAdapter(document); context.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document); NLayeredTreeLayout layout = new NLayeredTreeLayout(); layout.VertexSpacing = 50; layout.LayerSpacing = 50; layout.Layout(document.ActiveLayer.Children(null), context); // size to visible shapes document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding, NFilters.Visible); }
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 void DoLayout() { NLayoutContext context = new NLayoutContext(); context.GraphAdapter = new NShapeGraphAdapter(true); context.BodyAdapter = new NShapeBodyAdapter(document); context.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document); NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.Direction = LayoutDirection.LeftToRight; layout.EdgeRouting = LayeredLayoutEdgeRouting.Polyline; layout.PlugSpacing.Mode = PlugSpacingMode.None; NNodeList shapesToLayout = document.ActiveLayer.Children(NFilters.Shape2D); layout.Layout(shapesToLayout, context); // size to visible shapes document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding, NFilters.Visible); }
private void LayoutButton_Click(object sender, EventArgs e) { // 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); if (m_Layout != null) { // update the desired size NSizeF desiredSize = m_Layout.GetDesiredLayoutSize(shapes, layoutContext); NRectangleF desiredLayoutArea = new NRectangleF(layoutContext.BodyContainerAdapter.GetLayoutArea().Location, desiredSize); m_DesiredSizeShape.Bounds = desiredLayoutArea; // layout the shapes m_Layout.Layout(shapes, layoutContext); } }
private void PerformLayout(Hashtable args) { // create a layout NSymmetricalLayout layout = new NSymmetricalLayout(); // configure the optional forces layout.BounceBackForce.Padding = 100f; layout.GravityForce.AttractionCoefficient = 0.2f; layout.MagneticFieldForce.DistancePower = 0.6f; layout.MagneticFieldForce.FieldDirection = MagneticFieldDirection.OrthogonalLeftwardDownward; layout.MagneticFieldForce.MagnetizationType = MagnetizationType.Unidirectional; layout.MagneticFieldForce.TorsionCoefficient = 2f; // create a layout context NLayoutContext layoutContext = new NLayoutContext(); layoutContext.GraphAdapter = new NShapeGraphAdapter(); layoutContext.BodyAdapter = new NShapeBodyAdapter(NDrawingView1.Document); layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(NDrawingView1.Document); // configure layout if (args != null) { layout.BounceBackForce.Enabled = Boolean.Parse(args["BounceBackForce"].ToString()); layout.GravityForce.Enabled = Boolean.Parse(args["GravityForce"].ToString()); layout.MagneticFieldForce.Enabled = Boolean.Parse(args["MagneticFieldForce"].ToString()); } // get the shapes to layout NNodeList shapes = NDrawingView1.Document.ActiveLayer.Children(NFilters.Shape2D); // layout the shapes layout.Layout(shapes, new NDrawingLayoutContext(NDrawingView1.Document)); // resize document to fit all shapes NDrawingView1.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() { 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); }
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); }
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(); }
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 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(); } }
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(); } }
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 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; }