private void EventSinkService_NodeSelected(NNodeEventArgs args) { PauseEventsHandling(); if (view.Selection.AnchorNode is NRoutableConnector) { obstacleGroup.Visible = false; routeGroup.Visible = true; NRoutableConnector routableConnector = (view.Selection.AnchorNode as NRoutableConnector); routeTypeCombo.SelectedIndex = (int)routableConnector.ConnectorType; routeModeCombo.SelectedIndex = (int)routableConnector.RerouteAutomatically; } else if (NFilters.Shape2D.Filter(view.Selection.AnchorNode)) { obstacleGroup.Visible = true; routeGroup.Visible = false; NShape obstacle = (view.Selection.AnchorNode as NShape); obstacleTypeCombo.SelectedIndex = (int)obstacle.RouteObstacleType; } else { obstacleGroup.Visible = false; routeGroup.Visible = false; } ResumeEventsHandling(); }
protected override void InitDiagram() { base.InitDiagram(); const double width = 40; const double height = 40; const double distance = 80; NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NPage activePage = m_DrawingDocument.Content.ActivePage; int[] from = new int[] { 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6 }; int[] to = new int[] { 2, 3, 4, 4, 5, 8, 6, 7, 5, 8, 10, 8, 9, 10 }; NShape[] shapes = new NShape[10]; int vertexCount = shapes.Length; int edgeCount = from.Length; int count = vertexCount + edgeCount; for (int i = 0; i < count; i++) { if (i < vertexCount) { int j = vertexCount % 2 == 0 ? i : i + 1; shapes[i] = basicShapes.CreateShape(ENBasicShape.Rectangle); if (vertexCount % 2 != 0 && i == 0) { shapes[i].SetBounds(new NRectangle( (width + (distance * 1.5)) / 2, distance + (j / 2) * (distance * 1.5), width, height)); } else { shapes[i].SetBounds(new NRectangle( width / 2 + (j % 2) * (distance * 1.5), height + (j / 2) * (distance * 1.5), width, height)); } activePage.Items.Add(shapes[i]); } else { NRoutableConnector edge = new NRoutableConnector(); edge.UserClass = "Connector"; activePage.Items.Add(edge); edge.GlueBeginToShape(shapes[from[i - vertexCount] - 1]); edge.GlueEndToShape(shapes[to[i - vertexCount] - 1]); } } // arrange diagram ArrangeDiagram(); // fit active page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
/// <summary> /// Creates a one to many connector from the member1 of shape1 to /// member2 of shape2. /// </summary> /// <param name="shape1"></param> /// <param name="member1"></param> /// <param name="shape2"></param> /// <param name="member2"></param> private void Connect(NShape shape1, string member1, NShape shape2, string member2) { NRoutableConnector connector = new NRoutableConnector(); connector.UserClass = ConnectorOneToManyClassName; m_DrawingDocument.Content.ActivePage.Items.Add(connector); // Get or create the ports NPort port1 = GetOrCreatePort(shape1, member1); NPort port2 = GetOrCreatePort(shape2, member2); if (port1 == null) { throw new ArgumentException("A member with name '" + member1 + "' not found in shape '" + shape1.Name + "'", "member"); } if (port1 == null) { throw new ArgumentException("A member with name '" + member2 + "' not found in shape '" + shape2.Name + "'", "member"); } // Connect the ports connector.GlueBeginToPort(port1); connector.GlueEndToPort(port2); }
private void Connect(NShape shape1, NShape shape2) { NRoutableConnector connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.StyleSheetName = "Connectors"; connector.FromShape = shape1; connector.ToShape = shape2; }
private void Connect(NPort beginPort, NPort endPort) { NRoutableConnector connector = new NRoutableConnector(); connector.RerouteMode = ENRoutableConnectorRerouteMode.Always; m_DrawingDocument.Content.ActivePage.Items.AddChild(connector); connector.GlueBeginToPort(beginPort); connector.GlueEndToPort(endPort); }
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 ConnectShapes(NShape shape1, NShape shape2) { NGroup group = shape1.OwnerGroup; NRoutableConnector connector = new NRoutableConnector(); connector.UserClass = NDR.StyleSheetNameConnectors; group.Shapes.Add(connector); connector.GlueBeginToShape(shape1); connector.GlueEndToShape(shape2); }
private void SetAnimationsStyle(NShape data, NRoutableConnector link1, NRoutableConnector link2) { NPathAnimator pathAnimator = new NPathAnimator(data); pathAnimator.Animate(link1.Points, true); pathAnimator.SetPause(link1.StartPoint, 1); pathAnimator.SetPause(link2.StartPoint, 1); NPointF[] points = link2.Points; points[points.Length - 1] = data.PinPoint; pathAnimator.Animate(points, false); }
private NRoutableConnector ConnectElements(NGroup from, NGroup to) { NRoutableConnector line = new NRoutableConnector(); document.ActiveLayer.AddChild(line); NPort fromPort = (NPort)from.Ports.GetChildByName("RightPort"); NPort toPort = (NPort)to.Ports.GetChildByName("LeftPort"); line.StartPlug.Connect(fromPort); line.EndPlug.Connect(toPort); return(line); }
private NRoutableConnector CreateSampleLine2() { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); connector.Geometry.Stroke = new NStroke(NColor.Orange); connector.BeginX = 10; connector.BeginY = 75; connector.EndX = 280; connector.EndY = 75; return(connector); }
private NRoutableConnector CreateSampleLine1() { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); connector.Geometry.Stroke = new NStroke(NColor.BlueViolet); connector.BeginX = 10; connector.BeginY = 130; connector.EndX = 250; connector.EndY = 130; return(connector); }
private NRoutableConnector CreateSampleLineDoubleBridge() { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); connector.Geometry.Stroke = new NStroke(NColor.Green); connector.BeginX = 50; connector.BeginY = 300; connector.EndX = 206; connector.EndY = 14; return(connector); }
private void routeModeCombo_SelectedIndexChanged(object sender, System.EventArgs e) { if (EventsHandlingPaused) { return; } NRoutableConnector connector = (view.Selection.AnchorNode as NRoutableConnector); if (connector == null) { return; } connector.RerouteAutomatically = (RerouteAutomatically)routeModeCombo.SelectedIndex; }
private void CreateTree(NGroup group) { NRectangleShape shape1 = new NRectangleShape(50, 0, 40, 40); NRectangleShape shape2 = new NRectangleShape(0, 0, 40, 40); NRectangleShape shape3 = new NRectangleShape(50, 50, 40, 40); NRectangleShape shape4 = new NRectangleShape(100, 0, 40, 40); shape1.Name = "root"; CreateShapePorts(shape1); CreateShapePorts(shape2); CreateShapePorts(shape3); CreateShapePorts(shape4); group.Shapes.AddChild(shape1); group.Shapes.AddChild(shape2); group.Shapes.AddChild(shape3); group.Shapes.AddChild(shape4); shape1.Name = group.Name; shape1.Text = shape1.Name; shape2.Name = group.Name + "1"; shape2.Text = shape2.Name; shape3.Name = group.Name + "2"; shape3.Text = shape3.Name; shape4.Name = group.Name + "3"; shape4.Text = shape4.Name; NRoutableConnector connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); group.Shapes.AddChild(connector); connector.FromShape = shape1; connector.ToShape = shape2; connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); group.Shapes.AddChild(connector); connector.FromShape = shape1; connector.ToShape = shape3; connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); group.Shapes.AddChild(connector); connector.FromShape = shape1; connector.ToShape = shape4; }
private void ConnectShapes(NShape shape1, NShape shape2, NShape winner, int depth) { NPort port = (NPort)winner.Ports.GetChildByName("Left"); NRoutableConnector connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = shape2; connector.EndPlug.Connect(port); SetAnimationsStyle(connector, depth); connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = shape1; connector.EndPlug.Connect(port); SetAnimationsStyle(connector, depth); }
private void rerouteButton_Click(object sender, System.EventArgs e) { if (EventsHandlingPaused) { return; } NRoutableConnector connector = (view.Selection.AnchorNode as NRoutableConnector); if (connector == null) { return; } connector.Reroute(); document.SmartRefreshAllViews(); }
private void CreateDiagram() { const int width = 40, height = 40, distance = 80; NBasicShapesFactory f = new NBasicShapesFactory(document); NRoutableConnector edge; int[] from = new int[] { 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6 }; int[] to = new int[] { 2, 3, 4, 4, 5, 8, 6, 7, 5, 8, 10, 8, 9, 10 }; NShape[] shapes = new NShape[10]; int vertexCount = shapes.Length; int edgeCount = from.Length; int count = vertexCount + edgeCount; for (int i = 0; i < count; i++) { if (i < vertexCount) { int j = vertexCount % 2 == 0 ? i : i + 1; shapes[i] = f.CreateShape((int)BasicShapes.Rectangle); if (vertexCount % 2 != 0 && i == 0) { shapes[i].Bounds = new NRectangleF((int)(width + (distance * 1.5)) / 2, distance + (j / 2) * (int)(distance * 1.5), width, height); } else { shapes[i].Bounds = new NRectangleF(width / 2 + (j % 2) * (int)(distance * 1.5), height + (j / 2) * (int)(distance * 1.5), width, height); } document.ActiveLayer.AddChild(shapes[i]); } else { edge = new NRoutableConnector(); edge.ConnectorType = RoutableConnectorType.DynamicPolyline; edge.StyleSheetName = "CustomConnectors"; document.ActiveLayer.AddChild(edge); edge.FromShape = shapes[from[i - vertexCount] - 1]; edge.ToShape = shapes[to[i - vertexCount] - 1]; } } }
private NRoutableConnector CreateSamplePolyline2() { NPoint[] points = new NPoint[] { new NPoint(212, 250), new NPoint(174, 250), new NPoint(174, 169), new NPoint(242, 169), new NPoint(242, 208), }; NRoutableConnector connector = new NRoutableConnector(); connector.MakePolyline(points); connector.Geometry.Stroke = new NStroke(NColor.OrangeRed); connector.SetBeginPoint(points[0]); connector.SetEndPoint(points[points.Length - 1]); return(connector); }
private NRoutableConnector CreateSamplePolyline1() { NPoint[] points = new NPoint[] { new NPoint(10, 210), new NPoint(75, 10), new NPoint(75, 10), new NPoint(75, 175), new NPoint(145, 175), new NPoint(145, 10), new NPoint(210, 75), new NPoint(210, 210), new NPoint(105, 210), new NPoint(105, 105), }; NRoutableConnector connector = new NRoutableConnector(); connector.MakePolyline(points); connector.SetBeginPoint(points[0]); connector.SetEndPoint(points[points.Length - 1]); return(connector); }
private void InitDocument() { // create the groups Group1 = CreateGroup("A"); Group2 = CreateGroup("B"); // 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)); // create the root shape NShape root = new NRectangleShape(0, 0, 40, 40); root.Name = "treeRoot"; root.Text = "0"; document.ActiveLayer.AddChild(root); CreateShapePorts(root); NRoutableConnector connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); document.ActiveLayer.AddChild(connector); connector.Name = "leftEdge"; connector.FromShape = root; connector.ToShape = Group1; connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); connector.Name = "rightEdge"; document.ActiveLayer.AddChild(connector); connector.FromShape = root; connector.ToShape = Group2; // do layout LayoutGroups(); Group1.UpdateModelBounds(); Group2.UpdateModelBounds(); }
private void InitDocument() { // create a button Button button = CreateButton(); NWinFormControlHostShape buttonShape = new NWinFormControlHostShape(button); buttonShape.DeactiveOnLostFocus = false; document.ActiveLayer.AddChild(buttonShape); // create a check box CheckBox check = CreateCheckBox(); NWinFormControlHostShape checkShape = new NWinFormControlHostShape(check); checkShape.DeactiveOnLostFocus = false; document.ActiveLayer.AddChild(checkShape); // create a combo box ComboBox combo = CreateComboBox(); NWinFormControlHostShape comboShape = new NWinFormControlHostShape(combo); comboShape.DeactiveOnLostFocus = false; document.ActiveLayer.AddChild(comboShape); // create a list box ListBox listBox = CreateListBox(); NWinFormControlHostShape listShape = new NWinFormControlHostShape(listBox); listShape.DeactiveOnLostFocus = false; document.ActiveLayer.AddChild(listShape); // create a tree view TreeView treeView = CreateTreeView(); NWinFormControlHostShape treeViewShape = new NWinFormControlHostShape(treeView); treeViewShape.DeactiveOnLostFocus = false; document.ActiveLayer.AddChild(treeViewShape); // layout the shapes buttonShape.Location = new NPointF(10, 10); comboShape.Location = new NPointF(210, 10); checkShape.Location = new NPointF(410, 10); listShape.Location = new NPointF(10, 210); treeViewShape.Location = new NPointF(210, 210); // create ports on all shapes foreach (NShape shape in document.ActiveLayer.Children(null)) { shape.CreateShapeElements(ShapeElementsMask.Ports); shape.Ports.AddChild(new NDynamicPort(new NContentAlignment(0, 0), DynamicPortGlueMode.GlueToContour)); } // activate all shapes foreach (NShape shape in document.ActiveLayer.Children(null)) { view.StartInplaceEditing(shape); } // link some of the shapes NRoutableConnector connector1 = new NRoutableConnector(); connector1.StyleSheetName = "Connectors"; document.ActiveLayer.AddChild(connector1); connector1.FromShape = buttonShape; connector1.ToShape = comboShape; connector1.Reroute(); NRoutableConnector connector2 = new NRoutableConnector(); connector2.StyleSheetName = "Connectors"; document.ActiveLayer.AddChild(connector2); connector2.FromShape = buttonShape; connector2.ToShape = treeViewShape; connector2.Reroute(); // mimic default control background document.BackgroundStyle.FillStyle = new NColorFillStyle(SystemColors.Control); }
private void InitDocument() { NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; NDrawingView1.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 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; // create the flowcharting shapes factory NFlowChartingShapesFactory factory = new NFlowChartingShapesFactory(NDrawingView1.Document); // modify the connectors style sheet NStyleSheet styleSheet = (NDrawingView1.Document.StyleSheets.GetChildByName(NDR.NameConnectorsStyleSheet, -1) as NStyleSheet); NTextStyle textStyle = new NTextStyle(); textStyle.BackplaneStyle.Visible = true; textStyle.BackplaneStyle.StandardFrameStyle.InnerBorderWidth = new NLength(0); styleSheet.Style.TextStyle = textStyle; styleSheet.Style.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.StartArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.EndArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); // create the begin shape NShape begin = factory.CreateShape((int)FlowChartingShapes.Termination); begin.Bounds = new NRectangleF(100, 100, 100, 100); begin.Text = "BEGIN"; NDrawingView1.Document.ActiveLayer.AddChild(begin); // create the step1 shape NShape step1 = factory.CreateShape((int)FlowChartingShapes.Process); step1.Bounds = new NRectangleF(100, 400, 100, 100); step1.Text = "STEP1"; NDrawingView1.Document.ActiveLayer.AddChild(step1); // connect begin and step1 with bezier link NBezierCurveShape bezier = new NBezierCurveShape(); bezier.StyleSheetName = NDR.NameConnectorsStyleSheet; bezier.Text = "BEZIER"; bezier.SetPointAt(1, new NPointF(100, 300)); bezier.SetPointAt(2, new NPointF(200, 300)); NDrawingView1.Document.ActiveLayer.AddChild(bezier); bezier.FromShape = begin; bezier.ToShape = step1; // create question1 shape NShape question1 = factory.CreateShape((int)FlowChartingShapes.Decision); question1.Bounds = new NRectangleF(300, 400, 100, 100); question1.Text = "QUESTION1"; NDrawingView1.Document.ActiveLayer.AddChild(question1); // connect step1 and question1 with line link NLineShape line = new NLineShape(); line.StyleSheetName = NDR.NameConnectorsStyleSheet; line.Text = "LINE"; NDrawingView1.Document.ActiveLayer.AddChild(line); line.FromShape = step1; line.ToShape = question1; // create the step2 shape NShape step2 = factory.CreateShape((int)FlowChartingShapes.Process); step2.Bounds = new NRectangleF(500, 100, 100, 100); step2.Text = "STEP2"; NDrawingView1.Document.ActiveLayer.AddChild(step2); // connect step2 and question1 with HV link NStep2Connector hv1 = new NStep2Connector(false); hv1.StyleSheetName = NDR.NameConnectorsStyleSheet; hv1.Text = "HV1"; NDrawingView1.Document.ActiveLayer.AddChild(hv1); hv1.FromShape = step2; hv1.ToShape = question1; // connect question1 and step2 and with HV link NStep2Connector hv2 = new NStep2Connector(false); hv2.StyleSheetName = NDR.NameConnectorsStyleSheet; hv2.Text = "HV2"; NDrawingView1.Document.ActiveLayer.AddChild(hv2); hv2.FromShape = question1; hv2.ToShape = step2; // create a self loof as bezier on step2 NBezierCurveShape selfLoop = new NBezierCurveShape(); selfLoop.StyleSheetName = NDR.NameConnectorsStyleSheet; selfLoop.Text = "SELF LOOP"; NDrawingView1.Document.ActiveLayer.AddChild(selfLoop); selfLoop.FromShape = step2; selfLoop.ToShape = step2; selfLoop.Reflex(); // create step3 shape NShape step3 = factory.CreateShape((int)FlowChartingShapes.Process); step3.Bounds = new NRectangleF(700, 600, 100, 100); step3.Text = "STEP3"; NDrawingView1.Document.ActiveLayer.AddChild(step3); // connect question1 and step3 with an HVH link NStep3Connector hvh1 = new NStep3Connector(false, 50, 0, true); hvh1.StyleSheetName = NDR.NameConnectorsStyleSheet; hvh1.Text = "HVH1"; NDrawingView1.Document.ActiveLayer.AddChild(hvh1); hvh1.FromShape = question1; hvh1.ToShape = step3; // create end shape NShape end = factory.CreateShape((int)FlowChartingShapes.Termination); end.Bounds = new NRectangleF(300, 700, 100, 100); end.Text = "END"; NDrawingView1.Document.ActiveLayer.AddChild(end); // connect step3 and end with VH link NStep2Connector vh1 = new NStep2Connector(true); vh1.StyleSheetName = NDR.NameConnectorsStyleSheet; vh1.Text = "VH1"; NDrawingView1.Document.ActiveLayer.AddChild(vh1); vh1.FromShape = step3; vh1.ToShape = end; // connect question1 and end with curve link (uses explicit ports) NRoutableConnector curve = new NRoutableConnector(RoutableConnectorType.DynamicCurve); curve.StyleSheetName = NDR.NameConnectorsStyleSheet; curve.Text = "CURVE"; NDrawingView1.Document.ActiveLayer.AddChild(curve); curve.StartPlug.Connect(question1.Ports.GetChildAt(3) as NPort); curve.EndPlug.Connect(end.Ports.GetChildAt(1) as NPort); curve.InsertPoint(1, new NPointF(500, 600)); // set a shadow to the document. Since styles are inheritable all objects will reuse this shadow NDrawingView1.Document.Style.ShadowStyle = new NShadowStyle( ShadowType.GaussianBlur, Color.Gray, new NPointL(5, 5), 1, new NLength(3)); // shadows must be displayed behind document content NDrawingView1.Document.ShadowsZOrder = ShadowsZOrder.BehindDocument; }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide grid and ports drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; // create a stylesheet for styling the different bricks NStyleSheet styleSheet = new NStyleSheet(); m_DrawingDocument.StyleSheets.AddChild(styleSheet); // the first rule fills brichs with UserClass BRICK1 NRule ruleBrick1 = new NRule(); styleSheet.Add(ruleBrick1); NSelectorBuilder sb = ruleBrick1.GetSelectorBuilder(); sb.Start(); sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("BRICK1"); sb.End(); ruleBrick1.Declarations.Add(new NValueDeclaration <NFill>(NGeometry.FillProperty, new NHatchFill(ENHatchStyle.HorizontalBrick, NColor.DarkOrange, NColor.Gold))); // the second rule fills brichs with UserClass BRICK2 NRule ruleBrick2 = new NRule(); styleSheet.Add(ruleBrick2); sb = ruleBrick2.GetSelectorBuilder(); sb.Start(); sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("BRICK2"); sb.End(); ruleBrick2.Declarations.Add(new NValueDeclaration <NFill>(NGeometry.FillProperty, new NHatchFill(ENHatchStyle.HorizontalBrick, NColor.DarkRed, NColor.Gold))); // create all shapes // create the maze frame CreateBrick(new NRectangle(50, 0, 700, 50), "BRICK1"); CreateBrick(new NRectangle(750, 0, 50, 800), "BRICK1"); CreateBrick(new NRectangle(50, 750, 700, 50), "BRICK1"); CreateBrick(new NRectangle(0, 0, 50, 800), "BRICK1"); // create the maze obstacles CreateBrick(new NRectangle(100, 200, 200, 50), "BRICK2"); CreateBrick(new NRectangle(300, 50, 50, 200), "BRICK2"); CreateBrick(new NRectangle(450, 50, 50, 200), "BRICK2"); CreateBrick(new NRectangle(500, 200, 200, 50), "BRICK2"); CreateBrick(new NRectangle(50, 300, 250, 50), "BRICK2"); CreateBrick(new NRectangle(500, 300, 250, 50), "BRICK2"); CreateBrick(new NRectangle(350, 350, 100, 100), "BRICK2"); CreateBrick(new NRectangle(50, 450, 250, 50), "BRICK2"); CreateBrick(new NRectangle(500, 450, 250, 50), "BRICK2"); CreateBrick(new NRectangle(100, 550, 200, 50), "BRICK2"); CreateBrick(new NRectangle(300, 550, 50, 200), "BRICK2"); CreateBrick(new NRectangle(450, 550, 50, 200), "BRICK2"); CreateBrick(new NRectangle(500, 550, 200, 50), "BRICK2"); // create the first set of start/end shapes NShape start = CreateEllipse(new NRectangle(100, 100, 50, 50), "START"); NShape end = CreateEllipse(new NRectangle(650, 650, 50, 50), "END"); // connect them with a dynamic HV routable connector, // which is rerouted whenever the obstacles have changed NRoutableConnector routableConnector = new NRoutableConnector(); routableConnector.RerouteMode = ENRoutableConnectorRerouteMode.Always; routableConnector.Geometry.Stroke = new NStroke(3, NColor.Black); activePage.Items.Add(routableConnector); // connect the start and end shapes routableConnector.GlueBeginToShape(start); routableConnector.GlueEndToShape(end); // reroute the connector routableConnector.Reroute(); // size document to fit the maze activePage.SizeToContent(); }
protected override void InitDiagram() { base.InitDiagram(); NPage activePage = m_DrawingDocument.Content.ActivePage; // we will be using basic shapes for this example NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); basicShapesFactory.DefaultSize = new NSize(80, 80); NList <NPerson> persons = new NList <NPerson>(); // create persons NPerson personEmil = new NPerson("Emil Moore", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personAndre = new NPerson("Andre Smith", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personRobert = new NPerson("Robert Johnson", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personBob = new NPerson("Bob Williams", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personPeter = new NPerson("Peter Brown", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personSilvia = new NPerson("Silvia Moore", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personEmily = new NPerson("Emily Smith", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personMonica = new NPerson("Monica Johnson", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personSamantha = new NPerson("Samantha Miller", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personIsabella = new NPerson("Isabella Davis", basicShapesFactory.CreateShape(ENBasicShape.Circle)); persons.Add(personEmil); persons.Add(personAndre); persons.Add(personRobert); persons.Add(personBob); persons.Add(personPeter); persons.Add(personSilvia); persons.Add(personEmily); persons.Add(personMonica); persons.Add(personSamantha); persons.Add(personIsabella); // create family relashionships personEmil.m_Family = personSilvia; personAndre.m_Family = personEmily; personRobert.m_Family = personMonica; // create friend relationships personEmily.m_Friends.Add(personBob); personEmily.m_Friends.Add(personMonica); personAndre.m_Friends.Add(personPeter); personAndre.m_Friends.Add(personIsabella); personSilvia.m_Friends.Add(personBob); personSilvia.m_Friends.Add(personSamantha); personSilvia.m_Friends.Add(personIsabella); personEmily.m_Friends.Add(personIsabella); personEmily.m_Friends.Add(personPeter); personPeter.m_Friends.Add(personRobert); // create the person vertices for (int i = 0; i < persons.Count; i++) { activePage.Items.Add(persons[i].m_Shape); } // creeate the family relations for (int i = 0; i < persons.Count; i++) { NPerson currentPerson = persons[i]; if (currentPerson.m_Family != null) { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); activePage.Items.Add(connector); connector.GlueBeginToShape(currentPerson.m_Shape); connector.GlueEndToShape(currentPerson.m_Family.m_Shape); connector.Geometry.Stroke = new NStroke(2, NColor.Coral); connector.LayoutData.SpringStiffness = 2; connector.LayoutData.SpringLength = 100; } } for (int i = 0; i < persons.Count; i++) { NPerson currentPerson = persons[i]; for (int j = 0; j < currentPerson.m_Friends.Count; j++) { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); activePage.Items.Add(connector); connector.GlueBeginToShape(currentPerson.m_Shape); connector.GlueEndToShape(currentPerson.m_Friends[j].m_Shape); connector.Geometry.Stroke = new NStroke(2, NColor.Green); connector.LayoutData.SpringStiffness = 1; connector.LayoutData.SpringLength = 200; } } // arrange diagram ArrangeDiagram(); // fit active page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
/// <summary> /// Creates a connector between the ports of the specified shapes /// </summary> /// <param name="fromShape"></param> /// <param name="fromPortName"></param> /// <param name="toShape"></param> /// <param name="toPortName"></param> /// <param name="connectorType"></param> /// <param name="text"></param> /// <returns></returns> public NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ConnectorType connectorType, string text) { // check input if (fromShape == null) { throw new ArgumentNullException("fromShape"); } if (toShape == null) { throw new ArgumentNullException("toShape"); } NPort fromPort = (fromShape.Ports.GetChildByName(fromPortName, 0) as NPort); if (fromPort == null) { throw new ArgumentException("Was not able to find fromPortName in the ports collection of the fromShape", "fromPortName"); } NPort toPort = (toShape.Ports.GetChildByName(toPortName, 0) as NPort); if (toPort == null) { throw new ArgumentException("Was not able to find toPortName in the ports collection of the toShape", "toPortName"); } // create the connector NShape connector = null; switch (connectorType) { case ConnectorType.Line: connector = new NLineShape(); break; case ConnectorType.Bezier: connector = new NBezierCurveShape(); break; case ConnectorType.SingleArrow: connector = new NArrowShape(ArrowType.SingleArrow); break; case ConnectorType.DoubleArrow: connector = new NArrowShape(ArrowType.DoubleArrow); break; case ConnectorType.SideToTopBottom: connector = new NStep2Connector(false); break; case ConnectorType.TopBottomToSide: connector = new NStep2Connector(true); break; case ConnectorType.SideToSide: connector = new NStep3Connector(false, 50, 0, true); break; case ConnectorType.TopToBottom: connector = new NStep3Connector(true, 50, 0, true); break; case ConnectorType.DynamicHV: connector = new NRoutableConnector(RoutableConnectorType.DynamicHV); break; case ConnectorType.DynamicPolyline: connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); break; case ConnectorType.DynamicCurve: connector = new NRoutableConnector(RoutableConnectorType.DynamicCurve); break; default: Debug.Assert(false, "New graph connector type?"); break; } // the connector must be added to the document prior to connecting it document.ActiveLayer.AddChild(connector); connector.StartPlug.Connect(fromPort); connector.EndPlug.Connect(toPort); connector.Style.TextStyle = (connector.ComposeTextStyle().Clone() as NTextStyle); connector.Style.TextStyle.Offset = new Nevron.GraphicsCore.NPointL(0, -7); connector.Text = text; return(connector); }
protected override void InitDiagram() { base.InitDiagram(); NPage activePage = m_DrawingDocument.Content.ActivePage; // we will be using basic shapes with default size of 120, 60 NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); basicShapesFactory.DefaultSize = new NSize(120, 60); // create the president NShape president = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); president.Text = "President"; activePage.Items.Add(president); // create the VPs. // NOTE: The child nodes of the VPs are layed out in cols NShape vpMarketing = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); vpMarketing.Text = "VP Marketing"; vpMarketing.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(vpMarketing); NShape vpSales = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); vpSales.Text = "VP Sales"; vpSales.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(vpSales); NShape vpProduction = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); vpProduction.Text = "VP Production"; vpProduction.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(vpProduction); // connect president with VP NRoutableConnector connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(president); connector.GlueEndToShape(vpMarketing); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(president); connector.GlueEndToShape(vpSales); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(president); connector.GlueEndToShape(vpProduction); // crete the marketing managers NShape marketingManager1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); marketingManager1.Text = "Manager1"; activePage.Items.Add(marketingManager1); NShape marketingManager2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); marketingManager2.Text = "Manager2"; activePage.Items.Add(marketingManager2); // connect the marketing manager with the marketing VP connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpMarketing); connector.GlueEndToShape(marketingManager1); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpMarketing); connector.GlueEndToShape(marketingManager2); // crete the sales managers NShape salesManager1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); salesManager1.Text = "Manager1"; activePage.Items.Add(salesManager1); NShape salesManager2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); salesManager2.Text = "Manager2"; activePage.Items.Add(salesManager2); // connect the sales manager with the sales VP connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpSales); connector.GlueEndToShape(salesManager1); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpSales); connector.GlueEndToShape(salesManager2); // crete the production managers NShape productionManager1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); productionManager1.Text = "Manager1"; activePage.Items.Add(productionManager1); NShape productionManager2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); productionManager2.Text = "Manager2"; activePage.Items.Add(productionManager2); // connect the production manager with the production VP connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpProduction); connector.GlueEndToShape(productionManager1); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpProduction); connector.GlueEndToShape(productionManager2); // arrange diagram ArrangeDiagram(); // fit active page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
/// <summary> /// Creates a new connector, which connects the specified shapes /// </summary> /// <param name="fromShape"></param> /// <param name="fromPortName"></param> /// <param name="toShape"></param> /// <param name="toPortName"></param> /// <param name="connectorType"></param> /// <param name="text"></param> /// <returns>new 1D shapes</returns> protected NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ConnectorType connectorType, string text) { // check arguments if (fromShape == null) { throw new ArgumentNullException("fromShape"); } if (toShape == null) { throw new ArgumentNullException("toShape"); } NPort fromPort = (fromShape.Ports.GetChildByName(fromPortName, 0) as NPort); if (fromPort == null) { throw new ArgumentException("Was not able to find fromPortName in the ports collection of the fromShape", "fromPortName"); } NPort toPort = (toShape.Ports.GetChildByName(toPortName, 0) as NPort); if (toPort == null) { throw new ArgumentException("Was not able to find toPortName in the ports collection of the toShape", "toPortName"); } // create the connector NShape connector = null; switch (connectorType) { case ConnectorType.Line: connector = new NLineShape(); break; case ConnectorType.Bezier: connector = new NBezierCurveShape(); break; case ConnectorType.SingleArrow: connector = new NArrowShape(ArrowType.SingleArrow); break; case ConnectorType.DoubleArrow: connector = new NArrowShape(ArrowType.DoubleArrow); break; case ConnectorType.SideToTopBottom: connector = new NStep2Connector(false); break; case ConnectorType.TopBottomToSide: connector = new NStep2Connector(true); break; case ConnectorType.SideToSide: connector = new NStep3Connector(false, 50, 0, true); break; case ConnectorType.TopToBottom: connector = new NStep3Connector(true, 50, 0, true); break; case ConnectorType.DynamicHV: connector = new NRoutableConnector(RoutableConnectorType.DynamicHV); break; case ConnectorType.DynamicPolyline: connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); break; case ConnectorType.DynamicCurve: connector = new NRoutableConnector(RoutableConnectorType.DynamicCurve); break; default: Debug.Assert(false, "New graph connector type?"); break; } // the connector must be added to the document prior to connecting it DrawingView.Document.ActiveLayer.AddChild(connector); // change the default label text connector.Text = text; // connectors by default inherit styles from the connectors stylesheet connector.StyleSheetName = NDR.NameConnectorsStyleSheet; // connect the connector to the specified ports connector.StartPlug.Connect(fromPort); connector.EndPlug.Connect(toPort); // modify the connector text style connector.Style.TextStyle = (connector.ComposeTextStyle().Clone() as NTextStyle); connector.Style.TextStyle.Offset = new NPointL(0, -7); return(connector); }
private void CreatePredefinedOrgChart() { // we will be using basic shapes with default size of 120, 60 NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory(); basicShapesFactory.DefaultSize = new NSizeF(120, 60); // create the president NShape president = basicShapesFactory.CreateShape(BasicShapes.Rectangle); president.Text = "President"; document.ActiveLayer.AddChild(president); // create the VPs. // NOTE: The child nodes of the VPs are layed out in cols NShape vpMarketing = basicShapesFactory.CreateShape(BasicShapes.Rectangle); vpMarketing.Text = "VP Marketing"; vpMarketing.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108)); document.ActiveLayer.AddChild(vpMarketing); NShape vpSales = basicShapesFactory.CreateShape(BasicShapes.Rectangle); vpSales.Text = "VP Sales"; vpSales.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108)); document.ActiveLayer.AddChild(vpSales); NShape vpProduction = basicShapesFactory.CreateShape(BasicShapes.Rectangle); vpProduction.Text = "VP Production"; vpProduction.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108)); document.ActiveLayer.AddChild(vpProduction); // connect president with VP NRoutableConnector connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = president; connector.ToShape = vpMarketing; connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = president; connector.ToShape = vpSales; connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = president; connector.ToShape = vpProduction; // crete the marketing managers NShape marketingManager1 = basicShapesFactory.CreateShape(BasicShapes.Rectangle); marketingManager1.Text = "Manager1"; document.ActiveLayer.AddChild(marketingManager1); NShape marketingManager2 = basicShapesFactory.CreateShape(BasicShapes.Rectangle); marketingManager2.Text = "Manager2"; document.ActiveLayer.AddChild(marketingManager2); // connect the marketing manager with the marketing VP connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = vpMarketing; connector.ToShape = marketingManager1; connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = vpMarketing; connector.ToShape = marketingManager2; // crete the sales managers NShape salesManager1 = basicShapesFactory.CreateShape(BasicShapes.Rectangle); salesManager1.Text = "Manager1"; document.ActiveLayer.AddChild(salesManager1); NShape salesManager2 = basicShapesFactory.CreateShape(BasicShapes.Rectangle); salesManager2.Text = "Manager2"; document.ActiveLayer.AddChild(salesManager2); // connect the sales manager with the sales VP connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = vpSales; connector.ToShape = salesManager1; connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = vpSales; connector.ToShape = salesManager2; // crete the production managers NShape productionManager1 = basicShapesFactory.CreateShape(BasicShapes.Rectangle); productionManager1.Text = "Manager1"; document.ActiveLayer.AddChild(productionManager1); NShape productionManager2 = basicShapesFactory.CreateShape(BasicShapes.Rectangle); productionManager2.Text = "Manager2"; document.ActiveLayer.AddChild(productionManager2); // connect the production manager with the production VP connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = vpProduction; connector.ToShape = productionManager1; connector = new NRoutableConnector(); document.ActiveLayer.AddChild(connector); connector.FromShape = vpProduction; connector.ToShape = productionManager2; }
private void InitDocument() { // draw global port for (int i = 0; i < OutmostModel.Ports.Count; i++) { UDNGroup gPort = CreateGlobalPort(OutmostModel.Ports[i].Name, OutmostModel.Ports[i].Type); nDrawingDocument.ActiveLayer.AddChild(gPort); if (OutmostModel.Ports[i].Type == PortType.IN) { inPortList.Add(gPort); } else { outPortList.Add(gPort); } objMDict[OutmostModel.Name, OutmostModel.Ports[i].Name] = gPort; } for (int i = 0; i < OutmostModel.Instances.Count; i++) { string key = OutmostModel.Instances[i].Name; UDNGroup instance = CreateInstance(key, ModulePool[OutmostModel.Instances[i].Type].Ports, OutmostModel.Instances[i].Id); nDrawingDocument.ActiveLayer.AddChild(instance); instanceList.Add(instance); //objDict[key] = instance; for (int j = 0; j < ModulePool[OutmostModel.Instances[i].Type].Ports.Count; j++) { objMDict[key, ModulePool[OutmostModel.Instances[i].Type].Ports[j].Name] = instance; } instance.DoubleClick += new NodeViewEventHandler(instance_DoubleClick); } setInstancesPos(instanceList, inPortList, outPortList); NRoutableConnector routableConnector; for (int i = 0; i < OutmostModel.Instances.Count; i++) { for (int j = 0; j < OutmostModel.Instances[i].Couplings.Count; j++) { routableConnector = new NRoutableConnector(RoutableConnectorType.DynamicHV, RerouteAutomatically.Always); routableConnector.StyleSheetName = NDR.NameConnectorsStyleSheet; routableConnector.Style.StrokeStyle = new NStrokeStyle(1, Color.Blue); nDrawingDocument.ActiveLayer.AddChild(routableConnector); var cou = OutmostModel.Instances[i].Couplings[j]; var sourIns = objMDict[cou.From, cou.FPort]; var destIns = objMDict[cou.To, cou.TPort]; routableConnector.StartPlug.Connect(((NShape)(sourIns.Shapes.GetChildByName(cou.FPort, 0))).Ports.GetChildByName(cou.FPort, 0) as NPort); routableConnector.EndPlug.Connect(((NShape)(destIns.Shapes.GetChildByName(cou.TPort, 0))).Ports.GetChildByName(cou.TPort, 0) as NPort); routableConnector.DoubleClick += new NodeViewEventHandler(routableConnector_DoubleClick); routableConnector.Reroute(); } } nDrawingDocument.SizeToContent(); }
private void Update_instance(Module mod) { Module _module = (Module)mod.ShallowCopy(); inPortList.Clear(); outPortList.Clear(); instanceList.Clear(); objMDict.Clear(); if (_module.Name != OutmostModelName) { _module.Name = string.Copy(ModulePool[_module.Type].Name); } // draw global port for (int i = 0; i < _module.Ports.Count; i++) { UDNGroup gPort = CreateGlobalPort(_module.Ports[i].Name, _module.Ports[i].Type); nDrawingDocument.ActiveLayer.AddChild(gPort); if (_module.Ports[i].Type == PortType.IN) { inPortList.Add(gPort); } else { outPortList.Add(gPort); } objMDict[_module.Name, _module.Ports[i].Name] = gPort; } for (int i = 0; i < _module.Instances.Count; i++) { string key = _module.Instances[i].Name; UDNGroup instance = CreateInstance(key, ModulePool[_module.Instances[i].Type].Ports, _module.Instances[i].Id); // [!@#$] maybe need Deepcopy of ports //instance.UDPorts = ModulePool[_module.Instances[i].Type].Ports; nDrawingDocument.ActiveLayer.AddChild(instance); instanceList.Add(instance); for (int j = 0; j < ModulePool[_module.Instances[i].Type].Ports.Count; j++) { objMDict[key, ModulePool[_module.Instances[i].Type].Ports[j].Name] = instance; } instance.DoubleClick += new NodeViewEventHandler(instance_DoubleClick); } setInstancesPos(instanceList, inPortList, outPortList); NRoutableConnector routableConnector; for (int i = 0; i < _module.Instances.Count; i++) { for (int j = 0; j < _module.Instances[i].Couplings.Count; j++) { routableConnector = new NRoutableConnector(RoutableConnectorType.DynamicHV, RerouteAutomatically.Always); routableConnector.Name = "name"; routableConnector.StyleSheetName = NDR.NameConnectorsStyleSheet; routableConnector.Style.StrokeStyle = new NStrokeStyle(1, Color.Blue); nDrawingDocument.ActiveLayer.AddChild(routableConnector); var cou = _module.Instances[i].Couplings[j]; var sourIns = objMDict[cou.From, cou.FPort]; var destIns = objMDict[cou.To, cou.TPort]; routableConnector.StartPlug.Connect(((NShape)(sourIns.Shapes.GetChildByName(cou.FPort, 0))).Ports.GetChildByName(cou.FPort, 0) as NPort); routableConnector.EndPlug.Connect(((NShape)(destIns.Shapes.GetChildByName(cou.TPort, 0))).Ports.GetChildByName(cou.TPort, 0) as NPort); routableConnector.DoubleClick += new NodeViewEventHandler(routableConnector_DoubleClick); routableConnector.Reroute(); } } nDrawingDocument.SizeToContent(); _module = null; }