private void CreateScene(NDrawingDocument document) { document.BackgroundStyle.FrameStyle.Visible = false; document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); NNetworkShapesFactory factory = new NNetworkShapesFactory(document); factory.DefaultSize = new NSizeF(240, 180); NShape server = factory.CreateShape(NetworkShapes.Server); NShape computer = factory.CreateShape(NetworkShapes.Computer); NShape laptop = factory.CreateShape(NetworkShapes.Laptop); document.ActiveLayer.AddChild(server); document.ActiveLayer.AddChild(computer); document.ActiveLayer.AddChild(laptop); NRoutableConnector link1 = new NRoutableConnector(); document.ActiveLayer.AddChild(link1); link1.FromShape = server; link1.ToShape = computer; NRoutableConnector link2 = new NRoutableConnector(); document.ActiveLayer.AddChild(link2); link2.FromShape = server; link2.ToShape = laptop; // layout the shapes in the active layer using a table layout NLayeredGraphLayout layout = new NLayeredGraphLayout(); // 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(); // add the data shape const float shapeSize = 10; NEllipseShape data = new NEllipseShape(link2.EndPoint.X - shapeSize / 2, link2.EndPoint.Y - shapeSize, shapeSize, shapeSize); document.ActiveLayer.AddChild(data); NStyle.SetStrokeStyle(data, new NStrokeStyle(0, KnownArgbColorValue.Transparent)); NStyle.SetFillStyle(data, new NColorFillStyle(KnownArgbColorValue.Red)); // set the animations style SetAnimationsStyle(data, link1, link2); // resize document to fit all shapes document.SizeToContent(); }
private void InitDocument() { document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8)); NNetworkShapesFactory factory = new NNetworkShapesFactory(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(); }