private void CreateGroup(int row, int col, AbilitiesMask protection) { // create a group NGroup group = new NGroup(); group.Protection = new NAbilities(protection); // add two rectangle shapes in it group.Shapes.AddChild(new NRectangleShape(new NRectangleF(0, 0, 1, 1))); group.Shapes.AddChild(new NRectangleShape(new NRectangleF(2, 2, 1, 1))); // update the group model bounds to fit the shapes group.UpdateModelBounds(); // transform the group to fit in the specified bounds group.Bounds = base.GetGridCell(row, col); // create the labels shape element group.CreateShapeElements(ShapeElementsMask.Labels); // create the default label NRotatedBoundsLabel label = new NRotatedBoundsLabel("", group.UniqueId, new Nevron.Diagram.NMargins(0)); group.Labels.AddChild(label); group.Labels.DefaultLabelUniqueId = label.UniqueId; // assign text to the group group.Text = "Protected from: " + protection.ToString(); // add the group to the active layer document.ActiveLayer.AddChild(group); }
private void AddShowHideSubtree(NGroup group) { group.CreateShapeElements(ShapeElementsMask.Decorators); NShowHideSubtreeDecorator decorator = new NShowHideSubtreeDecorator(); decorator.Offset = new NSizeF(group.Width - decorator.Size.Width / 2, -group.Height / 2); decorator.Background.Shape = ToggleDecoratorBackgroundShape.Ellipse; group.Decorators.AddChild(decorator); }
private void CreatePorts(NGroup group, NShape anchorShape) { group.CreateShapeElements(ShapeElementsMask.Ports); NDynamicPort leftPort = new NDynamicPort(new NContentAlignment(ContentAlignment.MiddleLeft), DynamicPortGlueMode.GlueToLocation); leftPort.AnchorUniqueId = anchorShape.UniqueId; leftPort.Name = "LeftPort"; group.Ports.AddChild(leftPort); group.CreateShapeElements(ShapeElementsMask.Ports); NDynamicPort rightPort = new NDynamicPort(new NContentAlignment(ContentAlignment.MiddleRight), DynamicPortGlueMode.GlueToLocation); rightPort.AnchorUniqueId = anchorShape.UniqueId; rightPort.Name = "RightPort"; group.Ports.AddChild(rightPort); }
private void CreateGroupPorts(NGroup group) { group.CreateShapeElements(ShapeElementsMask.Ports); // create a dynamic port anchored to the center of the shape NRotatedBoundsPort port = new NRotatedBoundsPort(new NContentAlignment(ContentAlignment.TopCenter)); port.Name = "port"; group.Ports.AddChild(port); }
protected override void LoadExample() { // begin view init view.BeginInit(); view.DocumentPadding = new Nevron.Diagram.NMargins(20); view.Grid.Visible = false; // replace the default drag drop target tool with your own one // to extend the drop capabilities of the view NTool tool = view.Controller.Tools.GetToolByName(NDWFR.ToolDragDropTarget); int index = view.Controller.Tools.IndexOf(tool); view.Controller.Tools.Remove(tool); tool = new NMyDragDropTargetTool(); tool.Enabled = true; view.Controller.Tools.Insert(index, tool); // init document document.BeginInit(); // create and add your own data object adaptor // to extend the default set of supported data object formats document.DataObjectAdaptors.Add(new NMyDataObjectAdaptor()); // create a simple group for demonstration NGroup group = new NGroup(); group.Shapes.AddChild(new NRectangleShape(100, 100, 200, 200)); group.CreateShapeElements(ShapeElementsMask.Labels); NRotatedBoundsLabel label = new NRotatedBoundsLabel("Drop items from the tree view in me", group.UniqueId, new Nevron.Diagram.NMargins(0)); group.Labels.AddChild(label); group.Labels.DefaultLabelUniqueId = label.UniqueId; group.Text = "Drop items from the tree view in me"; group.UpdateModelBounds(); document.ActiveLayer.AddChild(group); document.EndInit(); // init form controls InitFormControls(); // end view init view.EndInit(); }
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); }
protected NGroup CreateNetwork(NPointF location, string labelText) { NGroup group = new NGroup(); document.ActiveLayer.AddChild(group); // create computer1 NCompositeShape computer1 = CreateComputer(); computer1.Location = new NPointF(0, 0); group.Shapes.AddChild(computer1); // create computer2 NCompositeShape computer2 = CreateComputer(); computer2.Location = new NPointF(200, 0); group.Shapes.AddChild(computer2); // create computer3 NCompositeShape computer3 = CreateComputer(); computer3.Location = new NPointF(100, 180); group.Shapes.AddChild(computer3); // connect the computers in the network ConnectComputers(computer1, computer2, group); ConnectComputers(computer2, computer3, group); ConnectComputers(computer3, computer1, group); // update the group model bounds group.UpdateModelBounds(); // insert a frame NRectangleShape frame = new NRectangleShape(group.ModelBounds); frame.Protection = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit); group.Shapes.InsertChild(0, frame); // change group fill style group.Style.FillStyle = new NGradientFillStyle(GradientStyle.FromCenter, GradientVariant.Variant2, Color.Gainsboro, Color.White); // reposition and resize the group group.Location = location; group.Width = 155; group.Height = 155; // add a dynamic port to the group group.CreateShapeElements(ShapeElementsMask.Ports); NDynamicPort port = new NDynamicPort(group.UniqueId, ContentAlignment.MiddleCenter, DynamicPortGlueMode.GlueToContour); group.Ports.AddChild(port); group.Ports.DefaultInwardPortUniqueId = port.UniqueId; // modify the margins and text of the default label group.CreateShapeElements(ShapeElementsMask.Labels); NRotatedBoundsLabel label = new NRotatedBoundsLabel(labelText, group.UniqueId, new Nevron.Diagram.NMargins(0, 0, -10, 100)); group.Labels.AddChild(label); group.Labels.DefaultLabelUniqueId = label.UniqueId; return(group); }
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; }