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); }
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 allowDownwardCheck2_CheckedChanged(object sender, EventArgs e) { if (EventsHandlingPaused) { return; } // get the selected label NRotatedBoundsLabel label = labelsCombo.SelectedItem as NRotatedBoundsLabel; if (label == null) { return; } // specify whether the rotated bounds label can have downward orientation label.AllowDownwardOrientation = allowDownwardCheck2.Checked; document.SmartRefreshAllViews(); }
public NExpandableShape() { // add a rectangle shape as base NRectangleShape rect = new NRectangleShape(new NRectangleF(0, 0, 75, 75)); rect.DestroyShapeElements(ShapeElementsMask.All); rect.Protection = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit); Shapes.AddChild(rect); // add an expand collapse shape NExpandCollapseCheck check = new NExpandCollapseCheck(); check.Bounds = new NRectangleF(80, 0, 12, 12); check.Protection = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit); check.ResizeInAggregate = ResizeInAggregate.RepositionOnly; Shapes.AddChild(check); // update the model bounds with the rectangle bounds UpdateModelBounds(rect.Transform.TransformBounds(rect.ModelBounds)); // initially it is expanded m_bExpanded = true; // by default the group has one dynamic port anchored to the rectangle CreateShapeElements(ShapeElementsMask.Ports); NDynamicPort port = new NDynamicPort(rect.UniqueId, ContentAlignment.MiddleCenter, DynamicPortGlueMode.GlueToContour); Ports.AddChild(port); Ports.DefaultInwardPortUniqueId = port.UniqueId; // by default the group has one rotated bounds port anchored to the rectangle CreateShapeElements(ShapeElementsMask.Labels); NRotatedBoundsLabel label = new NRotatedBoundsLabel("", rect.UniqueId, new Nevron.Diagram.NMargins(10)); Labels.AddChild(label); Labels.DefaultLabelUniqueId = label.UniqueId; }
private void InitDocument(NDrawingDocument document) { // setup default NDrawingView1.Document. fill style, background style and shadow style Color color1 = Color.FromArgb(225, 232, 232); Color color2 = Color.FromArgb(32, 136, 178); NLightingImageFilter lightingFilter = new NLightingImageFilter(); lightingFilter.SpecularColor = Color.Black; lightingFilter.DiffuseColor = Color.White; lightingFilter.LightSourceType = LightSourceType.Positional; lightingFilter.Position = new NVector3DF(1, 1, 1); lightingFilter.BevelDepth = new NLength(8, NGraphicsUnit.Pixel); document.Style.FillStyle = new NColorFillStyle(color1); document.Style.FillStyle.ImageFiltersStyle.Filters.Add(lightingFilter); document.BackgroundStyle.FillStyle = new NGradientFillStyle(GradientStyle.DiagonalUp, GradientVariant.Variant1, Color.LightBlue, color2); document.Style.ShadowStyle.Type = ShadowType.GaussianBlur; document.Style.ShadowStyle.Offset = new NPointL(5, 5); document.ShadowsZOrder = ShadowsZOrder.BehindDocument; // create title NTextShape title = new NTextShape("Bubble Sort", GetGridCell(0, 1, 2, 1)); title.Style.TextStyle = new NTextStyle(); title.Style.TextStyle.FillStyle = (document.Style.FillStyle.Clone() as NFillStyle); title.Style.TextStyle.ShadowStyle = new NShadowStyle(); title.Style.TextStyle.ShadowStyle.Type = ShadowType.GaussianBlur; title.Style.TextStyle.FontStyle = new NFontStyle(new Font("Arial", 40, FontStyle.Bold)); document.ActiveLayer.AddChild(title); // begin shape NShape shapeBegin = CreateFlowChartingShape(document, FlowChartingShapes.Termination, GetGridCell(0, 0), "BEGIN", ""); // get array item shape NShape shapeGetItem = CreateFlowChartingShape(document, FlowChartingShapes.Data, GetGridCell(1, 0), "Get array item [1...n]", ""); NRotatedBoundsLabel rotatedBoundsLabel = (NRotatedBoundsLabel)shapeGetItem.Labels.DefaultLabel; rotatedBoundsLabel.Margins = new Nevron.Diagram.NMargins(20, 20, 0, 0); // i = 1 shape NShape shapeI1 = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(2, 0), "i = 1", ""); // j = n shape NShape shapeJEN = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(3, 0), "j = n", ""); // less comparison shape NShape shapeLess = CreateFlowChartingShape(document, FlowChartingShapes.Decision, GetGridCell(4, 0), "item[i] < item[j - 1]?", ""); rotatedBoundsLabel = (NRotatedBoundsLabel)shapeLess.Labels.DefaultLabel; rotatedBoundsLabel.Margins = new Nevron.Diagram.NMargins(15, 15, 0, 0); // swap shape NShape shapeSwap = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(4, 1), "Swap item[i] and item[j-1]", ""); // j > i + 1? shape NShape shapeJQ = CreateFlowChartingShape(document, FlowChartingShapes.Decision, GetGridCell(5, 0), "j = (i + 1)?", ""); // dec j shape NShape shapeDecJ = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(5, 1), "j = j - 1", ""); // i > n - 1? shape NShape shapeIQ = CreateFlowChartingShape(document, FlowChartingShapes.Decision, GetGridCell(6, 0), "i = (n - 1)?", ""); // inc i shape NShape shapeIncI = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(6, 1), "i = i + 1", ""); // end shape NShape shapeEnd = CreateFlowChartingShape(document, FlowChartingShapes.Termination, GetGridCell(7, 0), "END", ""); // connect begin with get array item NLineShape connector1 = new NLineShape(); connector1.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector1); connector1.FromShape = shapeBegin; connector1.ToShape = shapeGetItem; // connect get array item with i = 1 NLineShape connector2 = new NLineShape(); connector2.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector2); connector2.FromShape = shapeGetItem; connector2.ToShape = shapeI1; // connect i = 1 and j = n NLineShape connector3 = new NLineShape(); connector3.StyleSheetName = NDR.NameConnectorsStyleSheet; connector3.CreateShapeElements(ShapeElementsMask.Ports); connector3.Ports.AddChild(new NLogicalLinePort(connector3.UniqueId, 50)); connector3.Ports.DefaultInwardPortUniqueId = (connector3.Ports.GetChildAt(0) as INDiagramElement).UniqueId; document.ActiveLayer.AddChild(connector3); connector3.FromShape = shapeI1; connector3.ToShape = shapeJEN; // connect j = n and item[i] < item[j-1]? NLineShape connector4 = new NLineShape(); connector4.StyleSheetName = NDR.NameConnectorsStyleSheet; connector4.CreateShapeElements(ShapeElementsMask.Ports); connector4.Ports.AddChild(new NLogicalLinePort(connector4.UniqueId, 50)); connector4.Ports.DefaultInwardPortUniqueId = (connector4.Ports.GetChildAt(0) as INDiagramElement).UniqueId; document.ActiveLayer.AddChild(connector4); connector4.FromShape = shapeJEN; connector4.ToShape = shapeLess; // connect item[i] < item[j-1]? and j = (i + 1)? NLineShape connector5 = new NLineShape(); connector5.StyleSheetName = NDR.NameConnectorsStyleSheet; connector5.Text = "No"; connector5.Style.TextStyle = new NTextStyle(); connector5.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Top; connector5.CreateShapeElements(ShapeElementsMask.Ports); connector5.Ports.AddChild(new NLogicalLinePort(connector5.UniqueId, 50)); connector5.Ports.DefaultInwardPortUniqueId = (connector5.Ports.GetChildAt(0) as INDiagramElement).UniqueId; document.ActiveLayer.AddChild(connector5); connector5.FromShape = shapeLess; connector5.ToShape = shapeJQ; // connect j = (i + 1)? and i = (n - 1)? NLineShape connector6 = new NLineShape(); connector6.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector6); connector6.FromShape = shapeJQ; connector6.ToShape = shapeIQ; // connect i = (n - 1) and END NLineShape connector7 = new NLineShape(); connector7.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector7); connector7.FromShape = shapeIQ; connector7.ToShape = shapeEnd; // connect item[i] < item[j-1]? and Swap NLineShape connector8 = new NLineShape(); connector8.StyleSheetName = NDR.NameConnectorsStyleSheet; connector8.Text = "Yes"; connector8.Style.TextStyle = new NTextStyle(); connector8.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Bottom; document.ActiveLayer.AddChild(connector8); connector8.FromShape = shapeLess; connector8.ToShape = shapeSwap; // connect j = (i + 1)? and j = (j - 1) NLineShape connector9 = new NLineShape(); connector9.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector9); connector9.FromShape = shapeJQ; connector9.ToShape = shapeDecJ; // connect i = (n - 1)? and i = (i + 1) NLineShape connector10 = new NLineShape(); connector10.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector10); connector10.FromShape = shapeIQ; connector10.ToShape = shapeIncI; // connect Swap to No connector NStep2Connector connector11 = new NStep2Connector(true); connector11.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector11); connector11.FromShape = shapeSwap; connector11.ToShape = connector5; // connect i = i + 1 to connector3 NStep3Connector connector12 = new NStep3Connector(false, 50, 60, false); connector12.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector12); connector12.StartPlug.Connect(shapeIncI.Ports.GetChildByName("Right", 0) as NPort); connector12.EndPlug.Connect(connector3.Ports.DefaultInwardPort); // connect j = j - 1 to connector4 NStep3Connector connector13 = new NStep3Connector(false, 50, 30, false); connector13.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector13); connector13.StartPlug.Connect(shapeDecJ.Ports.GetChildByName("Right", 0) as NPort); connector13.EndPlug.Connect(connector4.Ports.DefaultInwardPort); }
protected NCompositeShape CreateOrgChartShape(NPersonalInfo info) { NRectangleF bounds = info.Bounds; float bottomPortAlignment = info.BottomPortAlignment; Bitmap photo = new Bitmap(this.MapPathSecure(info.Picture)); // compose a new graph vertex from a frame and an image NRectanglePath frame = new NRectanglePath(bounds); NRectanglePath image = new NRectanglePath(new NPointF(bounds.X + 5, bounds.Y + 5), new NSizeF(photo.Size)); NImageFillStyle imgageFillStyle = new NImageFillStyle(photo, 0xff); NStyle.SetFillStyle(image, imgageFillStyle); NCompositeShape shape = new NCompositeShape(); shape.Primitives.AddChild(frame); shape.Primitives.AddChild(image); shape.UpdateModelBounds(); Document.ActiveLayer.AddChild(shape); // set the vertex fill style NColorFillStyle fillStyle = null; switch (info.Level) { case 0: fillStyle = new NColorFillStyle(Color.FromArgb(241, 100, 34)); break; case 1: fillStyle = new NColorFillStyle(Color.FromArgb(249, 167, 26)); break; case 2: fillStyle = new NColorFillStyle(Color.FromArgb(255, 247, 151)); break; } fillStyle.ImageFiltersStyle.Filters.Add(new NLightingImageFilter()); shape.Style.FillStyle = fillStyle; NInteractivityStyle interactivityStyle = new NInteractivityStyle(); interactivityStyle.Tooltip.Text = "Click to show " + info.Name + " personal information"; interactivityStyle.UrlLink.Url = "../Examples/WebControl/GettingStarted/NPersonalInfoPage.aspx?" + info.Id.ToString(); shape.Style.InteractivityStyle = interactivityStyle; // add a new label for the person name NRotatedBoundsLabel nameLabel = new NRotatedBoundsLabel(info.Name, shape.UniqueId, new Nevron.Diagram.NMargins(40, 1, 50, 1)); shape.Labels.AddChild(nameLabel); NStyle.SetTextStyle(nameLabel, nameLabel.ComposeTextStyle().Clone() as NTextStyle); nameLabel.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; nameLabel.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Top; // configure default label (used for the person position) NRotatedBoundsLabel positionLabel = shape.Labels.DefaultLabel as NRotatedBoundsLabel; NStyle.SetTextStyle(positionLabel, positionLabel.ComposeTextStyle().Clone() as NTextStyle); positionLabel.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial", 10, FontStyle.Bold)); positionLabel.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; positionLabel.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Bottom; positionLabel.Margins = new Nevron.Diagram.NMargins(40, 5, 1, 50); positionLabel.Text = info.Position; // create the optional ports of the shape shape.CreateShapeElements(ShapeElementsMask.Ports); // add rotated bounds ports NPort leftPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.MiddleLeft)); leftPort.Name = "Left"; shape.Ports.AddChild(leftPort); NPort rightPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.MiddleRight)); rightPort.Name = "Right"; shape.Ports.AddChild(rightPort); NPort topPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.TopCenter)); topPort.Name = "Top"; shape.Ports.AddChild(topPort); NRotatedBoundsPort bottomPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(bottomPortAlignment, 50)); bottomPort.Name = "Bottom"; shape.Ports.AddChild(bottomPort); return(shape); }
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() { // create a rectangle shape with a 2 bounds label NShape shape = new NRectangleShape(base.GetGridCell(0, 0)); shape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 0xcc, 0, 0)); shape.Labels.RemoveAllChildren(); NBoundsLabel boundsLabel = new NBoundsLabel("Label 1, Wrapped", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 0, 50)); shape.Labels.AddChild(boundsLabel); shape.Labels.DefaultLabelUniqueId = boundsLabel.UniqueId; boundsLabel = new NBoundsLabel("Label 2, Stretched", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 50, 0)); boundsLabel.Mode = BoxTextMode.Stretch; shape.Labels.AddChild(boundsLabel); document.ActiveLayer.AddChild(shape); // create a rectangle shape with a 2 rotated bounds labels shape = new NRectangleShape(base.GetGridCell(0, 1)); shape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 0, 0, 0xcc)); shape.Labels.RemoveAllChildren(); NRotatedBoundsLabel rotatedLabel = new NRotatedBoundsLabel("Rotated Label 1, Wrapped", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 0, 50)); shape.Labels.AddChild(rotatedLabel); shape.Labels.DefaultLabelUniqueId = rotatedLabel.UniqueId; rotatedLabel = new NRotatedBoundsLabel("Rotated Label 2, Stretched", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 50, 0)); rotatedLabel.Mode = BoxTextMode.Stretch; shape.Labels.AddChild(rotatedLabel); document.ActiveLayer.AddChild(shape); // create a polyline shape with two logical line labels NRectangleF cell = base.GetGridCell(1, 0, 0, 1); shape = new NPolylineShape(new NPointF[] { cell.Location, cell.RightBottom }); shape.Labels.RemoveAllChildren(); NLogicalLineLabel lineLabel = new NLogicalLineLabel("Line label - start", shape.UniqueId, 0, true, true); shape.Labels.AddChild(lineLabel); shape.Labels.DefaultLabelUniqueId = lineLabel.UniqueId; // alter the start label text style NTextStyle textStyle = document.Style.TextStyle.Clone() as NTextStyle; textStyle.StringFormatStyle.HorzAlign = HorzAlign.Left; textStyle.Offset = new NPointL(0, -7); NStyle.SetTextStyle(lineLabel, textStyle); // add the end label lineLabel = new NLogicalLineLabel("Line label - end", shape.UniqueId, 100, true, true); shape.Labels.AddChild(lineLabel); // alter the end label text style textStyle = document.Style.TextStyle.Clone() as NTextStyle; textStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; textStyle.Offset = new NPointL(0, -7); NStyle.SetTextStyle(lineLabel, textStyle); document.ActiveLayer.AddChild(shape); }